2006-06-06 18:43:26 +02:00
|
|
|
import pygtk
|
|
|
|
pygtk.require('2.0')
|
|
|
|
import gtk
|
|
|
|
import gobject
|
|
|
|
|
2006-06-13 00:31:26 +02:00
|
|
|
from sugar.presence.PresenceService import PresenceService
|
2006-06-06 18:43:26 +02:00
|
|
|
|
|
|
|
class PresenceWindow(gtk.Window):
|
|
|
|
_MODEL_COL_NICK = 0
|
|
|
|
_MODEL_COL_ICON = 1
|
|
|
|
_MODEL_COL_BUDDY = 2
|
2006-06-16 21:13:39 +02:00
|
|
|
_MODEL_COL_VISIBLE = 3
|
|
|
|
|
2006-06-13 20:49:01 +02:00
|
|
|
def __init__(self, activity_container):
|
2006-06-15 23:42:35 +02:00
|
|
|
gtk.Window.__init__(self, gtk.WINDOW_POPUP)
|
2006-06-15 01:00:56 +02:00
|
|
|
|
2006-06-13 20:49:01 +02:00
|
|
|
self._activity_container = activity_container
|
2006-06-06 18:43:26 +02:00
|
|
|
|
2006-06-13 00:31:26 +02:00
|
|
|
self._pservice = PresenceService.get_instance()
|
|
|
|
self._pservice.connect("buddy-appeared", self._on_buddy_appeared_cb)
|
|
|
|
self._pservice.connect("buddy-disappeared", self._on_buddy_disappeared_cb)
|
|
|
|
self._pservice.set_debug(True)
|
|
|
|
self._pservice.start()
|
2006-06-06 18:43:26 +02:00
|
|
|
|
|
|
|
self._setup_ui()
|
|
|
|
|
2006-06-16 21:13:39 +02:00
|
|
|
def _is_buddy_visible(self, buddy):
|
|
|
|
activity_type = self._activity.get_default_type()
|
|
|
|
buddy.get_service_of_type(activity, activity_type)
|
|
|
|
|
|
|
|
def _update_buddies_visibility(self):
|
|
|
|
for row in self._buddy_store:
|
|
|
|
row[_MODEL_COL_VISIBLE] = self._is_buddy_visible(row[_MODEL_COL_BUDDY])
|
|
|
|
|
|
|
|
def set_activity(self, activity):
|
|
|
|
self._activity = activity
|
|
|
|
self._update_buddies_visibility()
|
|
|
|
|
2006-06-06 18:43:26 +02:00
|
|
|
def _setup_ui(self):
|
|
|
|
vbox = gtk.VBox(False, 6)
|
2006-06-15 04:20:28 +02:00
|
|
|
vbox.set_border_width(12)
|
2006-06-06 18:43:26 +02:00
|
|
|
|
|
|
|
label = gtk.Label("Who's around:")
|
|
|
|
label.set_alignment(0.0, 0.5)
|
|
|
|
vbox.pack_start(label, False)
|
|
|
|
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)
|
|
|
|
self._buddy_list_model = self._buddy_store.filter_new()
|
|
|
|
self._buddy_list_model.set_visible_column(self._MODEL_COL_VISIBLE)
|
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)
|
|
|
|
|
|
|
|
self._buddy_list_view = gtk.TreeView(self._buddy_list_model)
|
|
|
|
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)
|
|
|
|
|
|
|
|
vbox.pack_start(sw)
|
|
|
|
sw.show()
|
|
|
|
|
2006-06-15 04:20:28 +02:00
|
|
|
button_box = gtk.HButtonBox()
|
|
|
|
|
2006-06-13 20:49:01 +02:00
|
|
|
share_button = gtk.Button('Share')
|
|
|
|
share_button.connect('clicked', self._share_button_clicked_cb)
|
2006-06-15 04:20:28 +02:00
|
|
|
button_box.pack_start(share_button)
|
2006-06-13 20:49:01 +02:00
|
|
|
share_button.show()
|
|
|
|
|
2006-06-15 04:20:28 +02:00
|
|
|
vbox.pack_start(button_box, False)
|
|
|
|
button_box.show()
|
|
|
|
|
2006-06-06 18:43:26 +02:00
|
|
|
self.add(vbox)
|
|
|
|
vbox.show()
|
|
|
|
|
2006-06-13 20:49:01 +02:00
|
|
|
def _share_button_clicked_cb(self, button):
|
|
|
|
self._activity_container.current_activity.publish()
|
|
|
|
|
2006-06-06 18:43:26 +02:00
|
|
|
def _on_buddyList_buddy_selected(self, widget, *args):
|
|
|
|
(model, aniter) = widget.get_selection().get_selected()
|
|
|
|
name = self._buddy_list_model.get(aniter, self._MODEL_COL_NICK)
|
|
|
|
|
|
|
|
def _on_buddyList_buddy_double_clicked(self, widget, *args):
|
|
|
|
""" Select the chat for this buddy or group """
|
|
|
|
(model, aniter) = widget.get_selection().get_selected()
|
|
|
|
chat = None
|
|
|
|
buddy = self._buddy_list_model.get_value(aniter, self._MODEL_COL_BUDDY)
|
|
|
|
if buddy and not self._chats.has_key(buddy):
|
2006-06-15 17:18:33 +02:00
|
|
|
#chat = BuddyChat(self, buddy)
|
|
|
|
#self._chats[buddy] = chat
|
|
|
|
#chat.connect_to_shell()
|
|
|
|
pass
|
2006-06-06 18:43:26 +02:00
|
|
|
|
|
|
|
def __buddy_icon_changed_cb(self, buddy):
|
|
|
|
it = self._get_iter_for_buddy(buddy)
|
|
|
|
self._buddy_list_model.set(it, self._MODEL_COL_ICON, buddy.get_icon_pixbuf())
|
|
|
|
|
2006-06-13 00:31:26 +02:00
|
|
|
def _on_buddy_appeared_cb(self, pservice, buddy):
|
|
|
|
if buddy.is_owner():
|
2006-06-06 18:43:26 +02:00
|
|
|
# Do not show ourself in the buddy list
|
2006-06-13 00:31:26 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
aniter = self._buddy_list_model.append(None)
|
|
|
|
self._buddy_list_model.set(aniter,
|
|
|
|
self._MODEL_COL_NICK, buddy.get_nick_name(),
|
2006-06-16 21:13:39 +02:00
|
|
|
self._MODEL_COL_BUDDY, buddy,
|
|
|
|
self._MODEL_COL_VISIBLE, self._is_buddy_visible(buddy))
|
2006-06-13 00:31:26 +02:00
|
|
|
buddy.connect('icon-changed', self.__buddy_icon_changed_cb)
|
|
|
|
|
|
|
|
def _on_buddy_disappeared_cb(self, pservice, buddy):
|
|
|
|
aniter = self._get_iter_for_buddy(buddy)
|
|
|
|
if aniter:
|
|
|
|
self._buddy_list_model.remove(aniter)
|
2006-06-06 18:43:26 +02:00
|
|
|
|
|
|
|
def _get_iter_for_buddy(self, buddy):
|
|
|
|
aniter = self._buddy_list_model.get_iter_first()
|
|
|
|
while aniter:
|
|
|
|
list_buddy = self._buddy_list_model.get_value(aniter, self._MODEL_COL_BUDDY)
|
|
|
|
if buddy == list_buddy:
|
|
|
|
return aniter
|
|
|
|
aniter = self._buddy_list_model.iter_next(aniter)
|