Bunch of fixes, sharing should be back to work

This commit is contained in:
Marco Pesenti Gritti
2006-07-15 12:31:06 +02:00
parent db08c3795f
commit 21b46a0022
6 changed files with 35 additions and 21 deletions
+14 -3
View File
@@ -1,3 +1,5 @@
import xml.sax.saxutils
import gobject
from sugar.presence.PresenceService import PresenceService
@@ -7,11 +9,18 @@ class ActivityInfo:
self._service = service
def get_id(self):
activity_id = service.get_one_property('activity_id')
activity_id = self._service.get_one_property('activity_id')
def get_type(self):
return self._service.get_type()
def get_title(self):
escaped_title = service.get_one_property('Title')
escaped_title = self._service.get_one_property('Title')
title = xml.sax.saxutils.unescape(escaped_title)
return title
def get_service(self):
return self._service
class ActivitiesModel(gobject.GObject):
__gsignals__ = {
@@ -44,4 +53,6 @@ class ActivitiesModel(gobject.GObject):
self._pservice.track_service_type(short_stype)
def _on_activity_announced_cb(self, pservice, service, buddy):
self.add_activity(buddy, service)
# FIXME We should not hard code activity types here
if service.get_type() == "_web_olpc._udp":
self.add_activity(service)
+7
View File
@@ -44,6 +44,13 @@ class ActivityRegistry:
def __init__(self):
self._activities = []
def get_activity(self, default_type):
"""Returns an activity given his default type"""
for activity in self._activities:
if activity.get_default_type() == default_type:
return activity
return None
def scan_directory(self, path):
"""Scan a directory for activities and add them to the registry."""
if os.path.isdir(path):
+9 -7
View File
@@ -39,9 +39,10 @@ class Toolbar(gtk.Toolbar):
new_activity_button.show()
class ActivitiesGrid(gtk.VBox):
def __init__(self, model):
gtk.VBox.__init__(self)
def __init__(self, shell, model):
gtk.VBox.__init__(self, shell)
self._shell = shell
self._buttons = {}
for activity in model:
@@ -60,15 +61,16 @@ class ActivitiesGrid(gtk.VBox):
self.remove(button)
def _add(self, activity):
button = gtk.Button(window.get_title())
button.connect('clicked', self.__button_clicked_cb, window)
button = gtk.Button(activity.get_title())
button.connect('clicked', self.__button_clicked_cb, activity)
self.pack_start(button, False)
button.show()
self._buttons[activity.get_id()] = button
def __button_clicked_cb(self, button, window):
self._home.activate(window)
def __button_clicked_cb(self, button, info):
activity = self._shell.get_registry().get_activity(info.get_type())
Activity.create(activity.get_id(), info.get_service())
class TasksGrid(gtk.VBox):
def __init__(self, home):
@@ -137,7 +139,7 @@ class HomeWindow(gtk.Window):
label.show()
model = ActivitiesModel()
grid = ActivitiesGrid(model)
grid = ActivitiesGrid(shell, model)
vbox.pack_start(grid)
grid.show()