#!/usr/bin/env python # # Empathy Link Share 0.1 - Share web links with IM contacts # # Copyright (C) 2007. Senko Rasic # This file is licensed under GNU GPL v2. # # You need to have telepathy framework installed (minimum required # version of Empathy is 0.12) is set-up and that your account is # online in order to use this. Copy this file to your # $HOME/.gnome2/epiphany/extensions directory, restart Epiphany, # and enable the extension in Tools->Extensions. # # To use it, right-click on a link, select 'Share with a friend', # select contact (only online contacts are displayed), and click # the Ok button. import epiphany import gtk import empathy import empathygtk def contact_chooser(): store = empathygtk.ContactListStore(contact_manager) view = empathygtk.ContactListView(store) window = gtk.Dialog() window.set_title('Select a contact') frame = gtk.Frame() frame.set_shadow_type(gtk.SHADOW_IN) window.get_child().add(frame) frame.add(view) window.add_button(gtk.STOCK_CANCEL, 0) window.add_button(gtk.STOCK_OK, 1) window.show_all() return (window, view) def message_box(title, text): window = gtk.Dialog() window.set_title(title) window.get_child().add(gtk.Label(text)) window.add_button(gtk.STOCK_OK, 0) window.show_all() window.run() window.hide() window.destroy() def share_cb(foo, window): url = window.get_active_embed().get_link_message() (window, view) = contact_chooser() success = window.run() names = None if success: (model, rows) = view.get_selection().get_selected_rows() names = [] for row in rows: # TODO - find the proper way of doing it contact = model[row[0]][6] name = model[row[0]][3] names.append(name) chat = empathy.empathy_tp_chat_new_with_contact(contact) chat.send(empathy.Message(url)) window.hide() window.destroy() if names is not None: message_box('Link sent', 'Link sent to %s' % ', '.join(names)) def attach_tab(window, tab): # TODO - make command be disabled if we're not online ui_manager = window.get_ui_manager() groups = ui_manager.get_action_groups() group = [ x for x in groups if x.get_name() == 'PopupsActions' ][0] action = gtk.Action('EmpathyShare', 'Share with a friend', 'Share this link with a friend via Instant Messaging', None) action.connect('activate', share_cb, window) group.add_action(action) ui_manager.add_ui(ui_manager.new_merge_id(), '/EphyLinkPopup', 'empathy', 'EmpathyShare', gtk.UI_MANAGER_MENUITEM, False) def detach_tab(window, tab): # FIXME - clean up pass contact_manager = empathy.ContactManager() contact_manager.setup()