Split ActivityHost in model/view. Refactor accordingly.
This commit is contained in:
@@ -20,6 +20,7 @@ from sugar.presence import PresenceService
|
||||
from sugar.activity.bundleregistry import BundleRegistry
|
||||
from model.Friends import Friends
|
||||
from model.MeshModel import MeshModel
|
||||
from model.homemodel import HomeModel
|
||||
from model.Owner import ShellOwner
|
||||
from sugar import env
|
||||
|
||||
@@ -37,6 +38,7 @@ class ShellModel:
|
||||
|
||||
self._friends = Friends()
|
||||
self._mesh = MeshModel(self._bundle_registry)
|
||||
self._home = HomeModel(self._bundle_registry)
|
||||
|
||||
path = os.path.expanduser('~/Activities')
|
||||
self._bundle_registry.add_search_path(path)
|
||||
@@ -57,6 +59,9 @@ class ShellModel:
|
||||
def get_invites(self):
|
||||
return self._owner.get_invites()
|
||||
|
||||
def get_home(self):
|
||||
return self._home
|
||||
|
||||
def get_owner(self):
|
||||
return self._owner
|
||||
|
||||
|
||||
@@ -14,19 +14,42 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
from sugar.graphics.canvasicon import CanvasIcon
|
||||
from sugar.presence import PresenceService
|
||||
from sugar.activity import Activity
|
||||
from sugar import profile
|
||||
|
||||
class HomeActivity:
|
||||
def __init__(self, activity):
|
||||
self._icon_name = activity.get_icon_name()
|
||||
self._icon_color = activity.get_icon_color()
|
||||
self._id = activity.get_id()
|
||||
|
||||
def __init__(self, registry, window):
|
||||
self._window = window
|
||||
|
||||
self._service = Activity.get_service(window.get_xid())
|
||||
self._id = self._service.get_id()
|
||||
self._type = self._service.get_type()
|
||||
|
||||
info = registry.get_bundle(self._type)
|
||||
self._icon_name = info.get_icon()
|
||||
|
||||
def get_title(self):
|
||||
return self._window.get_name()
|
||||
|
||||
def get_icon_name(self):
|
||||
return self._icon_name
|
||||
|
||||
def get_icon_color(self):
|
||||
return self._icon_color
|
||||
activity = PresenceService.get_instance().get_activity(self._id)
|
||||
if activity != None:
|
||||
return IconColor(activity.get_color())
|
||||
else:
|
||||
return profile.get_color()
|
||||
|
||||
def get_id(self):
|
||||
return self._id
|
||||
|
||||
def get_window(self):
|
||||
return self._window
|
||||
|
||||
def get_type(self):
|
||||
return self._type
|
||||
|
||||
def get_shared(self):
|
||||
return self._service.get_shared()
|
||||
|
||||
+25
-26
@@ -15,9 +15,8 @@
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
import gobject
|
||||
import wnck
|
||||
|
||||
from sugar.graphics.canvasicon import CanvasIcon
|
||||
from sugar.graphics import style
|
||||
from model.homeactivity import HomeActivity
|
||||
|
||||
class HomeModel(gobject.GObject):
|
||||
@@ -31,13 +30,15 @@ class HomeModel(gobject.GObject):
|
||||
([gobject.TYPE_PYOBJECT]))
|
||||
}
|
||||
|
||||
def __init__(self, shell):
|
||||
def __init__(self, bundle_registry):
|
||||
gobject.GObject.__init__(self)
|
||||
self._activities = []
|
||||
self._shell = shell
|
||||
|
||||
shell.connect('activity-opened', self.__activity_opened_cb)
|
||||
shell.connect('activity-closed', self.__activity_closed_cb)
|
||||
|
||||
self._activities = {}
|
||||
self._bundle_registry = bundle_registry
|
||||
|
||||
screen = wnck.screen_get_default()
|
||||
screen.connect('window-opened', self._window_opened_cb)
|
||||
screen.connect('window-closed', self._window_closed_cb)
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self._activities)
|
||||
@@ -47,23 +48,21 @@ class HomeModel(gobject.GObject):
|
||||
|
||||
def __getitem__(self, i):
|
||||
return self._activities[i]
|
||||
|
||||
def __activity_opened_cb(self, model, activity):
|
||||
self._add_activity(activity)
|
||||
|
||||
def __activity_closed_cb(self, model, activity):
|
||||
self._remove_activity(activity)
|
||||
|
||||
def _add_activity(self, activity):
|
||||
h_activity = HomeActivity(activity)
|
||||
self._activities.append(h_activity)
|
||||
self.emit('activity-added', h_activity)
|
||||
def _window_opened_cb(self, screen, window):
|
||||
if window.get_window_type() == wnck.WINDOW_NORMAL:
|
||||
self._add_activity(window)
|
||||
|
||||
def _remove_activity(self, activity):
|
||||
i = 0
|
||||
for h_activity in self._activities:
|
||||
if h_activity.get_id() == activity.get_id():
|
||||
self.emit('activity-removed', self._activities[i])
|
||||
del self._activities[i]
|
||||
return
|
||||
i += 1
|
||||
def _window_closed_cb(self, screen, window):
|
||||
if window.get_window_type() == wnck.WINDOW_NORMAL:
|
||||
self._remove_activity(window.get_xid())
|
||||
|
||||
def _add_activity(self, window):
|
||||
activity = HomeActivity(self._bundle_registry, window)
|
||||
self._activities[window.get_xid()] = activity
|
||||
self.emit('activity-added', activity)
|
||||
|
||||
def _remove_activity(self, xid):
|
||||
if self._activities.has_key(xid):
|
||||
self.emit('activity-removed', self._activities[xid])
|
||||
del self._activities[xid]
|
||||
|
||||
Reference in New Issue
Block a user