2006-10-15 01:24:45 +02:00
|
|
|
# Copyright (C) 2006, Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
2006-10-02 01:50:43 +02:00
|
|
|
import hippo
|
2006-09-04 21:34:54 +02:00
|
|
|
import logging
|
2006-08-23 11:52:18 +02:00
|
|
|
|
2007-02-20 14:57:50 +01:00
|
|
|
from sugar.graphics import units
|
2007-02-23 13:09:33 +01:00
|
|
|
from sugar.graphics.xocolor import XoColor
|
2007-02-21 13:01:20 +01:00
|
|
|
from sugar.graphics.iconbutton import IconButton
|
2007-01-09 21:25:51 +01:00
|
|
|
from sugar import profile
|
2006-08-23 11:52:18 +02:00
|
|
|
|
2007-05-27 20:24:10 +02:00
|
|
|
from model import bundleregistry
|
|
|
|
|
2007-02-21 13:01:20 +01:00
|
|
|
class ActivityButton(IconButton):
|
2007-02-22 22:51:24 +01:00
|
|
|
def __init__(self, activity, popup_context):
|
|
|
|
IconButton.__init__(self, icon_name=activity.get_icon(),
|
|
|
|
tooltip=activity.get_name())
|
2006-12-04 20:12:24 +01:00
|
|
|
self._activity = activity
|
2007-02-22 22:51:24 +01:00
|
|
|
self._popup_context = popup_context
|
2007-01-09 21:25:51 +01:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def get_bundle_id(self):
|
|
|
|
return self._activity.get_service_name()
|
2007-02-22 22:51:24 +01:00
|
|
|
|
|
|
|
def get_popup_context(self):
|
|
|
|
return self._popup_context
|
2006-08-23 11:52:18 +02:00
|
|
|
|
2007-02-21 13:01:20 +01:00
|
|
|
class InviteButton(IconButton):
|
2006-12-04 20:12:24 +01:00
|
|
|
def __init__(self, activity, invite):
|
2007-02-21 13:01:20 +01:00
|
|
|
IconButton.__init__(self, icon_name=activity.get_icon())
|
2006-10-23 21:28:19 +02:00
|
|
|
|
2007-02-23 17:08:37 +01:00
|
|
|
self.props.xo_color = activity.get_color()
|
2006-12-04 20:12:24 +01:00
|
|
|
self._invite = invite
|
2006-09-04 17:00:45 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def get_activity_id(self):
|
|
|
|
return self._invite.get_activity_id()
|
2006-09-04 17:00:45 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def get_bundle_id(self):
|
|
|
|
return self._invite.get_bundle_id()
|
2006-09-04 17:00:45 +02:00
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def get_invite(self):
|
|
|
|
return self._invite
|
2006-09-09 14:37:11 +02:00
|
|
|
|
2006-10-02 01:50:43 +02:00
|
|
|
class ActivitiesBox(hippo.CanvasBox):
|
2007-02-22 22:51:24 +01:00
|
|
|
def __init__(self, shell, popup_context):
|
2006-12-04 20:12:24 +01:00
|
|
|
hippo.CanvasBox.__init__(self, orientation=hippo.ORIENTATION_HORIZONTAL)
|
|
|
|
|
|
|
|
self._shell = shell
|
|
|
|
self._shell_model = self._shell.get_model()
|
|
|
|
self._invite_to_item = {}
|
|
|
|
self._invites = self._shell_model.get_invites()
|
2007-02-22 22:51:24 +01:00
|
|
|
self._popup_context = popup_context
|
2006-12-04 20:12:24 +01:00
|
|
|
|
2007-02-21 17:53:44 +01:00
|
|
|
bundle_registry = bundleregistry.get_registry()
|
2007-01-27 12:54:56 +01:00
|
|
|
for bundle in bundle_registry:
|
2006-12-04 20:12:24 +01:00
|
|
|
if bundle.get_show_launcher():
|
|
|
|
self.add_activity(bundle)
|
|
|
|
|
2007-01-27 12:54:56 +01:00
|
|
|
bundle_registry.connect('bundle-added', self._bundle_added_cb)
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
for invite in self._invites:
|
|
|
|
self.add_invite(invite)
|
|
|
|
self._invites.connect('invite-added', self._invite_added_cb)
|
|
|
|
self._invites.connect('invite-removed', self._invite_removed_cb)
|
|
|
|
|
|
|
|
def _activity_clicked_cb(self, icon):
|
|
|
|
self._shell.start_activity(icon.get_bundle_id())
|
|
|
|
|
|
|
|
def _invite_clicked_cb(self, icon):
|
|
|
|
self._invites.remove_invite(icon.get_invite())
|
|
|
|
self._shell.join_activity(icon.get_bundle_id(),
|
|
|
|
icon.get_activity_id())
|
|
|
|
|
|
|
|
def _invite_added_cb(self, invites, invite):
|
|
|
|
self.add_invite(invite)
|
|
|
|
|
|
|
|
def _invite_removed_cb(self, invites, invite):
|
|
|
|
self.remove_invite(invite)
|
|
|
|
|
2007-01-27 12:54:56 +01:00
|
|
|
def _bundle_added_cb(self, bundle_registry, bundle):
|
|
|
|
self.add_activity(bundle)
|
|
|
|
|
2006-12-04 20:12:24 +01:00
|
|
|
def add_activity(self, activity):
|
2007-02-22 22:51:24 +01:00
|
|
|
item = ActivityButton(activity, self._popup_context)
|
2006-12-04 20:12:24 +01:00
|
|
|
item.connect('activated', self._activity_clicked_cb)
|
|
|
|
self.append(item, 0)
|
|
|
|
|
|
|
|
def add_invite(self, invite):
|
|
|
|
mesh = self._shell_model.get_mesh()
|
|
|
|
activity = mesh.get_activity(invite.get_activity_id())
|
|
|
|
if activity:
|
2007-02-20 16:38:25 +01:00
|
|
|
item = InviteButton(activity, invite)
|
2006-12-04 20:12:24 +01:00
|
|
|
item.connect('activated', self._invite_clicked_cb)
|
|
|
|
self.append(item, 0)
|
|
|
|
|
|
|
|
self._invite_to_item[invite] = item
|
|
|
|
|
|
|
|
def remove_invite(self, invite):
|
|
|
|
self.remove(self._invite_to_item[invite])
|
|
|
|
del self._invite_to_item[invite]
|