2006-06-06 18:43:26 +02:00
|
|
|
import gtk
|
|
|
|
import gobject
|
2006-06-23 00:07:54 +02:00
|
|
|
import dbus
|
2006-06-06 18:43:26 +02:00
|
|
|
|
2006-06-13 00:31:26 +02:00
|
|
|
from sugar.presence.PresenceService import PresenceService
|
2006-06-23 00:07:54 +02:00
|
|
|
from sugar.presence.Service import Service
|
2006-06-22 21:59:38 +02:00
|
|
|
from sugar.chat.BuddyChat import BuddyChat
|
2006-06-06 18:43:26 +02:00
|
|
|
|
2006-07-05 17:00:11 +02:00
|
|
|
from gettext import gettext as _
|
|
|
|
|
2006-07-13 10:47:36 +02:00
|
|
|
class PresenceView(gtk.VBox):
|
2006-06-06 18:43:26 +02:00
|
|
|
_MODEL_COL_NICK = 0
|
|
|
|
_MODEL_COL_ICON = 1
|
|
|
|
_MODEL_COL_BUDDY = 2
|
2006-06-16 21:13:39 +02:00
|
|
|
|
2006-07-26 11:44:54 +02:00
|
|
|
def __init__(self, shell, activity):
|
2006-07-13 10:47:36 +02:00
|
|
|
gtk.VBox.__init__(self, False, 6)
|
2006-06-15 01:00:56 +02:00
|
|
|
|
2006-07-26 11:44:54 +02:00
|
|
|
self._activity = activity
|
|
|
|
self._activity_ps = None
|
2006-07-09 17:37:54 +02:00
|
|
|
self._shell = shell
|
2006-06-06 18:43:26 +02:00
|
|
|
|
2006-07-20 11:34:06 +02:00
|
|
|
self._pservice = PresenceService()
|
2006-07-26 11:44:54 +02:00
|
|
|
self._pservice.connect("activity-appeared", self._activity_appeared_cb)
|
2006-06-23 00:07:54 +02:00
|
|
|
|
2006-06-06 18:43:26 +02:00
|
|
|
self._setup_ui()
|
|
|
|
|
2006-07-26 11:44:54 +02:00
|
|
|
activity_ps = self._pservice.get_activity(activity.get_id())
|
|
|
|
if activity_ps:
|
|
|
|
self._set_activity_ps(activity_ps)
|
2006-06-16 21:13:39 +02:00
|
|
|
|
2006-06-23 04:42:29 +02:00
|
|
|
if activity:
|
|
|
|
if self._activity.get_shared():
|
|
|
|
self._share_button.set_sensitive(False)
|
|
|
|
else:
|
|
|
|
self._share_button.set_sensitive(True)
|
2006-06-23 18:23:44 +02:00
|
|
|
else:
|
|
|
|
self._share_button.set_sensitive(False)
|
2006-06-16 21:13:39 +02:00
|
|
|
|
2006-07-26 11:44:54 +02:00
|
|
|
def _set_activity_ps(self, activity_ps):
|
|
|
|
self._activity_ps = activity_ps
|
|
|
|
self._activity_ps.connect('buddy-joined', self._buddy_joined_cb)
|
|
|
|
self._activity_ps.connect('buddy-left', self._buddy_left_cb)
|
|
|
|
for buddy in activity_ps.get_joined_buddies():
|
|
|
|
self._add_buddy(buddy)
|
|
|
|
|
2006-06-06 18:43:26 +02:00
|
|
|
def _setup_ui(self):
|
2006-07-13 10:47:36 +02:00
|
|
|
self.set_size_request(120, -1)
|
|
|
|
|
2006-07-05 17:00:11 +02:00
|
|
|
label = gtk.Label(_("Who's around:"))
|
2006-06-06 18:43:26 +02:00
|
|
|
label.set_alignment(0.0, 0.5)
|
2006-07-13 10:47:36 +02:00
|
|
|
self.pack_start(label, False)
|
2006-06-06 18:43:26 +02:00
|
|
|
label.show()
|
|
|
|
|
2006-06-16 21:13:39 +02:00
|
|
|
self._buddy_store = gtk.ListStore(gobject.TYPE_STRING,
|
|
|
|
gtk.gdk.Pixbuf,
|
|
|
|
gobject.TYPE_PYOBJECT,
|
|
|
|
bool)
|
2006-06-06 18:43:26 +02:00
|
|
|
|
|
|
|
sw = gtk.ScrolledWindow()
|
|
|
|
sw.set_shadow_type(gtk.SHADOW_IN)
|
|
|
|
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
|
|
|
|
2006-07-26 11:44:54 +02:00
|
|
|
self._buddy_list_view = gtk.TreeView(self._buddy_store)
|
2006-06-06 18:43:26 +02:00
|
|
|
self._buddy_list_view.set_headers_visible(False)
|
|
|
|
self._buddy_list_view.connect("cursor-changed", self._on_buddyList_buddy_selected)
|
|
|
|
self._buddy_list_view.connect("row-activated", self._on_buddyList_buddy_double_clicked)
|
|
|
|
|
|
|
|
sw.add(self._buddy_list_view)
|
|
|
|
self._buddy_list_view.show()
|
|
|
|
|
|
|
|
renderer = gtk.CellRendererPixbuf()
|
|
|
|
column = gtk.TreeViewColumn("", renderer, pixbuf=self._MODEL_COL_ICON)
|
|
|
|
column.set_resizable(False)
|
|
|
|
column.set_expand(False);
|
|
|
|
self._buddy_list_view.append_column(column)
|
|
|
|
|
|
|
|
renderer = gtk.CellRendererText()
|
|
|
|
column = gtk.TreeViewColumn("", renderer, text=self._MODEL_COL_NICK)
|
|
|
|
column.set_resizable(True)
|
|
|
|
column.set_sizing("GTK_TREE_VIEW_COLUMN_GROW_ONLY");
|
|
|
|
column.set_expand(True);
|
|
|
|
self._buddy_list_view.append_column(column)
|
|
|
|
|
2006-07-13 10:47:36 +02:00
|
|
|
self.pack_start(sw)
|
2006-06-06 18:43:26 +02:00
|
|
|
sw.show()
|
|
|
|
|
2006-06-15 04:20:28 +02:00
|
|
|
button_box = gtk.HButtonBox()
|
|
|
|
|
2006-07-05 17:00:11 +02:00
|
|
|
self._share_button = gtk.Button(_('Share'))
|
2006-06-23 04:42:29 +02:00
|
|
|
self._share_button.connect('clicked', self._share_button_clicked_cb)
|
|
|
|
button_box.pack_start(self._share_button)
|
|
|
|
self._share_button.show()
|
2006-06-13 20:49:01 +02:00
|
|
|
|
2006-07-13 10:47:36 +02:00
|
|
|
self.pack_start(button_box, False)
|
2006-06-15 04:20:28 +02:00
|
|
|
button_box.show()
|
2006-06-06 18:43:26 +02:00
|
|
|
|
2006-06-13 20:49:01 +02:00
|
|
|
def _share_button_clicked_cb(self, button):
|
2006-07-26 00:17:05 +02:00
|
|
|
self._activity.share()
|
2006-07-26 07:19:05 +02:00
|
|
|
self._share_button.set_sensitive(False)
|
|
|
|
|
2006-06-16 22:07:14 +02:00
|
|
|
def _on_buddyList_buddy_selected(self, view, *args):
|
|
|
|
(model, aniter) = view.get_selection().get_selected()
|
|
|
|
name = model.get(aniter, self._MODEL_COL_NICK)
|
2006-06-06 18:43:26 +02:00
|
|
|
|
2006-06-16 22:07:14 +02:00
|
|
|
def _on_buddyList_buddy_double_clicked(self, view, *args):
|
2006-06-06 18:43:26 +02:00
|
|
|
""" Select the chat for this buddy or group """
|
2006-06-20 15:39:36 +02:00
|
|
|
(model, aniter) = view.get_selection().get_selected()
|
2006-06-06 18:43:26 +02:00
|
|
|
chat = None
|
2006-06-16 22:07:14 +02:00
|
|
|
buddy = view.get_model().get_value(aniter, self._MODEL_COL_BUDDY)
|
2006-06-22 21:59:38 +02:00
|
|
|
if buddy:
|
|
|
|
chat_service = buddy.get_service_of_type(BuddyChat.SERVICE_TYPE)
|
2006-07-26 15:38:54 +02:00
|
|
|
print chat_service
|
2006-06-22 21:59:38 +02:00
|
|
|
if chat_service:
|
|
|
|
bus = dbus.SessionBus()
|
|
|
|
proxy_obj = bus.get_object('com.redhat.Sugar.Chat', '/com/redhat/Sugar/Chat')
|
|
|
|
chat_shell = dbus.Interface(proxy_obj, 'com.redhat.Sugar.ChatShell')
|
2006-07-26 15:38:54 +02:00
|
|
|
chat_shell.open_chat(chat_service.object_path())
|
2006-06-22 21:59:38 +02:00
|
|
|
else:
|
|
|
|
print 'Could not find buddy chat'
|
2006-06-06 18:43:26 +02:00
|
|
|
|
|
|
|
def __buddy_icon_changed_cb(self, buddy):
|
|
|
|
it = self._get_iter_for_buddy(buddy)
|
2006-06-16 22:07:14 +02:00
|
|
|
self._buddy_store.set(it, self._MODEL_COL_ICON, buddy.get_icon_pixbuf())
|
2006-06-06 18:43:26 +02:00
|
|
|
|
2006-07-26 11:44:54 +02:00
|
|
|
def _activity_appeared_cb(self, pservice, activity):
|
|
|
|
if self._activity_ps:
|
2006-06-13 00:31:26 +02:00
|
|
|
return
|
2006-07-26 11:44:54 +02:00
|
|
|
if activity.get_id() == self._activity.get_id():
|
|
|
|
self._set_activity_ps(activity)
|
|
|
|
|
|
|
|
def _buddy_joined_cb(self, pservice, buddy):
|
|
|
|
self._add_buddy(buddy)
|
|
|
|
|
|
|
|
def _add_buddy(self, buddy):
|
2006-07-26 12:57:54 +02:00
|
|
|
if buddy.is_owner():
|
2006-07-26 11:44:54 +02:00
|
|
|
# Do not show ourself in the buddy list
|
2006-07-26 12:57:54 +02:00
|
|
|
return
|
2006-06-13 00:31:26 +02:00
|
|
|
|
2006-06-16 21:58:47 +02:00
|
|
|
aniter = self._buddy_store.append(None)
|
|
|
|
self._buddy_store.set(aniter,
|
2006-07-24 17:57:21 +02:00
|
|
|
self._MODEL_COL_NICK, buddy.get_name(),
|
2006-07-26 11:44:54 +02:00
|
|
|
self._MODEL_COL_BUDDY, buddy)
|
2006-06-13 00:31:26 +02:00
|
|
|
buddy.connect('icon-changed', self.__buddy_icon_changed_cb)
|
|
|
|
|
2006-07-26 11:44:54 +02:00
|
|
|
def _buddy_left_cb(self, pservice, buddy):
|
2006-06-13 00:31:26 +02:00
|
|
|
aniter = self._get_iter_for_buddy(buddy)
|
|
|
|
if aniter:
|
2006-06-16 21:58:47 +02:00
|
|
|
self._buddy_store.remove(aniter)
|
2006-06-06 18:43:26 +02:00
|
|
|
|
|
|
|
def _get_iter_for_buddy(self, buddy):
|
2006-06-16 22:07:14 +02:00
|
|
|
aniter = self._buddy_store.get_iter_first()
|
2006-06-06 18:43:26 +02:00
|
|
|
while aniter:
|
2006-06-16 22:07:14 +02:00
|
|
|
list_buddy = self._buddy_store.get_value(aniter, self._MODEL_COL_BUDDY)
|
2006-06-06 18:43:26 +02:00
|
|
|
if buddy == list_buddy:
|
|
|
|
return aniter
|
2006-06-16 22:07:14 +02:00
|
|
|
aniter = self._buddy_store.iter_next(aniter)
|