Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2013-08-02 21:12:37 (GMT)
committer Walter Bender <walter@sugarlabs.org>2013-08-02 21:12:37 (GMT)
commit5e310647c219ed297247207f759f2aa92e1a8be2 (patch)
tree12d4bc5ed48fe6a4b6c5424b6b7a2babc57b326d
parent8021f952a62885e6fa3a581aa96a217789649d82 (diff)
clean up
-rw-r--r--ShareFavorites.py268
-rw-r--r--activity/activity-favorites.svg16
-rw-r--r--po/ShareFavorites.pot28
3 files changed, 234 insertions, 78 deletions
diff --git a/ShareFavorites.py b/ShareFavorites.py
index 10d65c8..0c44199 100644
--- a/ShareFavorites.py
+++ b/ShareFavorites.py
@@ -13,22 +13,27 @@
from gi.repository import Gtk
from gi.repository import Gdk
-from gi.repository import GdkPixbuf
from gi.repository import GObject
-import subprocess
import os
from sugar3.activity import activity
from sugar3 import profile
from sugar3 import env
-from sugar3.graphics.toolbarbox import ToolbarBox
from sugar3.activity.widgets import ActivityToolbarButton
from sugar3.activity.widgets import StopButton
-from sugar3.graphics.alert import Alert
-from toolbar_utils import (button_factory, separator_factory)
+from sugar3.graphics.toolbarbox import ToolbarBox
+from sugar3.graphics.alert import NotifyAlert, Alert
+from sugar3.graphics.icon import Icon, CanvasIcon
+from sugar3.graphics import style
+from sugar3.graphics.xocolor import XoColor
+
+from jarabe.model import bundleregistry
+from jarabe.model.session import get_session_manager
+
+from toolbar_utils import separator_factory
from gettext import gettext as _
import logging
@@ -55,42 +60,86 @@ class ShareFavorites(activity.Activity):
''' Initialize the toolbars and the work surface '''
super(ShareFavorites, self).__init__(handle)
- self._buddies = [profile.get_nick_name()]
- self._colors = profile.get_color().to_string().split(',')
- self._my_colors = self._colors[:] # Save original colors
self.initiating = None # sharing (True) or joining (False)
-
- self._first_time = True
-
- self.old_cursor = self.get_window().get_cursor()
+ self._old_cursor = self.get_window().get_cursor()
+ self._buddy_count = 0
+ self._hboxes = []
self._setup_toolbars()
self._setup_canvas()
-
self._setup_presence_service()
+ # Start with the Neighborhood View icon in the center of the screen
+ self._icon = self._create_icon('#FFFFFF,#000000',
+ name='zoom-neighborhood')
+ self._icon.show()
+ self._vbox.pack_end(self._icon, True, True, 0)
+ self._vbox.show()
+
def _setup_canvas(self):
''' Create a canvas '''
- self.fixed = Gtk.Fixed()
- self.fixed.show()
- self.set_canvas(self.fixed)
-
- self.vbox = Gtk.VBox(False, 0)
- self.vbox.set_size_request(Gdk.Screen.width(), Gdk.Screen.height())
- self.fixed.put(self.vbox, 0, 0)
- self.vbox.show()
-
- self._canvas = Gtk.DrawingArea()
- self._canvas.set_size_request(int(Gdk.Screen.width()),
- int(Gdk.Screen.height()))
- self._canvas.show()
- self.show_all()
- self.vbox.pack_end(self._canvas, True, True, 0)
- self.vbox.show()
+ sw = Gtk.ScrolledWindow()
+ sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
+ sw.show()
+
+ self.set_canvas(sw)
+
+ self._vbox = Gtk.VBox(False, 0)
+ self._vbox.set_size_request(Gdk.Screen.width(),
+ Gdk.Screen.height() - style.GRID_CELL_SIZE)
+ sw.add(self._vbox)
+ self._vbox.show()
+
+ def _show_bundle_icon(self, icon_path):
+ if self._icon in self._vbox:
+ self._vbox.remove(self._icon)
+ self._icon = CanvasIcon(file_name=icon_path,
+ xo_color=XoColor('#000000,#FFFFFF'),
+ pixel_size=style.LARGE_ICON_SIZE)
+ self._vbox.pack_end(self._icon, True, True, 0)
+ self._icon.show()
+
+ def _animate_icons(self, icon_paths):
+ if len(icon_paths) == 0:
+ # Until we set up a dbus method to update the views, we need
+ # to restart
+ # self._restart_alert()
+ self._notify_alert(title=_('Warning'),
+ msg=_('Changes require restart'))
+ return
+ else:
+ self._show_bundle_icon(icon_paths[-1])
+ icon_paths.remove(icon_paths[-1])
+ GObject.timeout_add(500, self._animate_icons, icon_paths)
+
+ def _create_icon(self, color, name='computer-xo'):
+ return CanvasIcon(icon_name=name,
+ xo_color=XoColor(color),
+ pixel_size=style.STANDARD_ICON_SIZE)
+
+ def _add_buddy(self, icon, nick):
+ ''' Add buddies to sharer's canavs to show whom has shared data '''
+
+ n = int(Gdk.Screen.width() / (3 * style.STANDARD_ICON_SIZE))
+ if self._buddy_count % n == 0:
+ self._hboxes.append(Gtk.HBox(False, 0))
+ self._hboxes[-1].show()
+ self._vbox.pack_end(self._hboxes[-1], True, False, 0)
+
+ self._buddy_count += 1
+
+ vbox = Gtk.VBox(False, 0)
+ label = Gtk.Label(nick)
+ vbox.pack_start(icon, False, False, 0)
+ vbox.pack_start(label, False, False, 10)
+ icon.show()
+ label.show()
+ vbox.show()
+ self._hboxes[-1].pack_end(vbox, True, False, 0)
def _setup_toolbars(self):
''' Setup the toolbars. '''
- self.max_participants = 25 # sharing
+ self.max_participants = 5
toolbox = ToolbarBox()
@@ -117,42 +166,107 @@ class ShareFavorites(activity.Activity):
''' No longer waiting, so restore standard cursor. '''
if not hasattr(self, 'get_window'):
return
- self.get_window().set_cursor(self.old_cursor)
+ self.get_window().set_cursor(self._old_cursor)
def _waiting_cursor(self):
''' Waiting, so set watch cursor. '''
if not hasattr(self, 'get_window'):
return
- self.old_cursor = self.get_window().get_cursor()
+ self._old_cursor = self.get_window().get_cursor()
self.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH))
- def _dump(self, favorites):
- ''' Dump favorites for sharing. '''
- _logger.debug('dumping %s' % (json.dumps(favorites)))
- return json.dumps(favorites)
-
- def _load(self, data):
- ''' Load favorites from a sharer. '''
- favorites = json.loads(data)
+ def _restart_alert(self):
+ alert = Alert()
+ alert.props.title = _('Warning')
+ alert.props.msg = _('Changes require restart')
+
+ icon = Icon(icon_name='dialog-cancel')
+ alert.add_button(Gtk.ResponseType.CANCEL, _('Cancel changes'), icon)
+ icon.show()
+
+ icon = Icon(icon_name='dialog-ok')
+ alert.add_button(Gtk.ResponseType.ACCEPT, _('Later'), icon)
+ icon.show()
+
+ icon = Icon(icon_name='system-restart')
+ alert.add_button(Gtk.ResponseType.APPLY, _('Restart now'), icon)
+ icon.show()
+
+ alert.connect('response', self.__response_cb)
+ self.add_alert(alert)
+ alert.show()
+
+ def __response_cb(self, alert, response_id):
+ self.remove_alert(alert)
+
+ if response_id is Gtk.ResponseType.CANCEL:
+ pass
+ elif response_id is Gtk.ResponseType.ACCEPT:
+ pass
+ elif response_id is Gtk.ResponseType.APPLY:
+ session_manager = get_session_manager()
+ session_manager.logout()
+
+ def _notify_alert(self, title='', msg='', action=None):
+ ''' Notify user when xfer is completed '''
+
+ def _notification_alert_response_cb(alert, response_id, self, action):
+ self.remove_alert(alert)
+ if action is not None:
+ action()
+
+ alert = NotifyAlert()
+ alert.props.title = title
+ alert.connect('response', _notification_alert_response_cb, self,
+ action)
+ alert.props.msg = msg
+ self.add_alert(alert)
+ alert.show()
# When favorites are shared, the sharer sends out list; joiners
# receive the list.
def _read_favorites(self):
favorites_path = os.path.join(env.get_profile_path(),
'favorite_activities')
- logging.debug('read favorities: %s' % (favorites_path))
- fd = open(favorites_path, 'r')
- data = fd.read()
- fd.close()
- return self._dump(data)
+ favorites = json.load(open(favorites_path))
+ return favorites
def _save_favorites(self, favorites):
favorites_path = os.path.join(env.get_profile_path(),
'favorite_activities')
- logging.debug('save favorities: %s' % (favorites_path))
- fd = open(favorites_path, 'w')
- fd.write(favorites)
- fd.close()
+ json.dump(favorites, open(favorites_path, 'w'), indent=1)
+
+ def _unset_favorites(self, favorites_data):
+ favorites = favorites_data['favorites']
+ keys = favorites.keys()
+ registry = bundleregistry.get_registry()
+ for bundle in keys:
+ bundle = bundle.encode('ascii', 'replace')
+ bundle_id, version = bundle.split(' ')
+ logging.debug('removing %s' % (bundle_id))
+ registry.set_bundle_favorite(bundle_id, version, False)
+
+ def _set_favorites(self, data):
+ # data is coming over tube, so it needs to be decoded
+ favorites_data = json.loads(data)
+ favorites = favorites_data['favorites']
+ keys = favorites.keys()
+ registry = bundleregistry.get_registry()
+ icon_paths = []
+ for bundle in keys:
+ bundle = bundle.encode('ascii', 'replace')
+ bundle_id, version = bundle.split(' ')
+ try:
+ logging.debug('adding %s' % (bundle_id))
+ registry.set_bundle_favorite(bundle_id, version, True)
+ icon_path = registry.get_bundle(bundle_id).get_icon()
+ if os.path.exists(icon_path):
+ icon_paths.append(icon_path)
+ except:
+ logging.debug('bundle %s version %s not available' %
+ (bundle_id, version))
+
+ self._animate_icons(icon_paths)
def _setup_presence_service(self):
''' Setup the Presence Service. '''
@@ -184,10 +298,11 @@ class ShareFavorites(activity.Activity):
'NewTube', self._new_tube_cb)
_logger.debug('This is my activity: making a tube...')
- id = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].OfferDBusTube(
+ self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].OfferDBusTube(
SERVICE, {})
- self._share_favorites() # delete me
+ if self._icon in self._vbox:
+ self._vbox.remove(self._icon)
def _joined_cb(self, activity):
''' ...or join an exisiting share. '''
@@ -203,7 +318,7 @@ class ShareFavorites(activity.Activity):
self.tubes_chan = self.shared_activity.telepathy_tubes_chan
self.text_chan = self.shared_activity.telepathy_text_chan
- self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].connect_to_signal(\
+ self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].connect_to_signal(
'NewTube', self._new_tube_cb)
_logger.debug('I am joining an activity: waiting for a tube...')
@@ -214,6 +329,13 @@ class ShareFavorites(activity.Activity):
self.waiting = True
self._waiting_cursor()
+ if self._icon in self._vbox:
+ self._vbox.remove(self._icon)
+
+ self._notify_alert(title=_('Share Favorites'),
+ msg=_('Downloading favorites... please wait.'),
+ action=self._share_favorites)
+
def _list_tubes_reply_cb(self, tubes):
''' Reply to a list request. '''
for tube_info in tubes:
@@ -226,20 +348,22 @@ class ShareFavorites(activity.Activity):
def _new_tube_cb(self, id, initiator, type, service, params, state):
''' Create a new tube. '''
_logger.debug('New tube: ID=%d initator=%d type=%d service=%s '
- 'params=%r state=%d', id, initiator, type, service,
- params, state)
+ 'params=%r state=%d', id, initiator, type, service,
+ params, state)
if (type == telepathy.TUBE_TYPE_DBUS and service == SERVICE):
if state == telepathy.TUBE_STATE_LOCAL_PENDING:
- self.tubes_chan[ \
- telepathy.CHANNEL_TYPE_TUBES].AcceptDBusTube(id)
+ self.tubes_chan[
+ telepathy.CHANNEL_TYPE_TUBES].AcceptDBusTube(id)
- tube_conn = TubeConnection(self.conn,
- self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES], id, \
+ tube_conn = TubeConnection(
+ self.conn,
+ self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES],
+ id,
group_iface=self.text_chan[telepathy.CHANNEL_INTERFACE_GROUP])
- self.chattube = ChatTube(tube_conn, self.initiating, \
- self.event_received_cb)
+ self.chattube = ChatTube(tube_conn, self.initiating,
+ self.event_received_cb)
def event_received_cb(self, text):
''' Data is passed as tuples: cmd:text '''
@@ -253,16 +377,26 @@ class ShareFavorites(activity.Activity):
if self.initiating:
self._share_favorites()
- def _update_favorites(self, data):
- favorites = self._dump(data)
- self._save_favorites(favorities)
+ def _update_favorites(self, favorites):
+ self._set_favorites(favorites)
self._restore_cursor()
- # TODO: Update homeview
- def _share_favorites(self):
+ def _share_favorites(self, data=None):
+ logging.debug('SHARE FAVORITES %s' % (str(self.initiating)))
if self.initiating:
- _logger.debug('sharing favorites')
- self._send_event('F:%s' % (self._read_favorites()))
+ favorites = self._read_favorites()
+ self._send_event('F:%s' % (json.dumps(favorites)))
+ data_array = json.loads(data)
+ nick = data_array[0]
+ colors = data_array[1].encode('ascii', 'replace')
+ icon = self._create_icon(colors)
+ self._add_buddy(icon, nick)
+ else:
+ favorites_data = self._read_favorites()
+ self._unset_favorites(favorites_data)
+ nick = profile.get_nick_name()
+ colors = profile.get_color().to_string()
+ self._send_event('f:%s' % (json.dumps([nick, colors])))
def _send_event(self, text):
''' Send event through the tube. '''
diff --git a/activity/activity-favorites.svg b/activity/activity-favorites.svg
index f2bceb0..a143617 100644
--- a/activity/activity-favorites.svg
+++ b/activity/activity-favorites.svg
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
- <!ENTITY fill_color "#FFFFFF">
+ <!ENTITY fill_color "#A0A0A0">
<!ENTITY stroke_color "#010101">
]>
<svg
@@ -12,13 +12,11 @@
id="svg3059"
style="fill:&fill_color;;stroke:&stroke_color;;stroke-width:3.5;stroke-linecap:round;stroke-linejoin:round">
<path
- d="m 16.080509,21.440678 c 0.946469,0.350544 -0.0056,1.448767 -0.582627,1.573093 -1.563784,0.336916 -2.62701,-1.375865 -2.563559,-2.738348 0.113499,-2.437162 2.651828,-3.882824 4.894068,-3.554025 3.290578,0.482527 5.164561,3.941017 4.544491,7.049789 -0.826456,4.143503 -5.234367,6.456664 -9.205509,5.534956 C 8.1700954,28.146268 5.4133808,22.776575 6.6419506,17.944914 8.1299133,12.093125 14.467737,8.8905938 20.1589,10.429026 c 6.706839,1.812989 10.356528,9.122635 8.506354,15.67267 C 26.529155,33.66397 18.24535,37.761685 10.836864,35.598515 2.418871,33.140584 -2.1274659,23.881046 0.34957828,15.614405 3.1284475,6.3404832 13.364831,1.3450968 22.489409,4.1366536 32.61942,7.2358109 38.064175,18.449854 34.957626,28.432205"
- transform="matrix(1.2095957,0,0,1.3328409,6.0268108,1.1504485)"
- id="path2990"
- style="fill:none;stroke:&stroke_color;;stroke-width:2.75650501;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
- <path
- d="m 28.199153,29.597459 -8.224173,-2.326684 -6.579076,5.455845 -0.328602,-8.540638 -7.221863,-4.571125 8.021086,-2.951721 2.115719,-8.2809549 5.285906,6.7163739 8.529449,-0.546787 -4.754217,7.102669 z"
- transform="matrix(1.2237865,0,0,1.2297536,5.6902655,2.2231521)"
+ d="M 49.163253,45.936044 31.995338,41.055422 18.261553,52.5 17.575598,34.584535 2.5,24.99581 19.243972,18.804065 23.660524,1.4333304 34.694823,15.522086 52.5,14.375106 42.575598,29.274182 z"
id="path3760"
- style="fill:&fill_color;;fill-opacity:1;stroke:none" />
+ style="fill:&fill_color;;fill-opacity:1" />
+ <path
+ d="m 25.359133,29.858086 c 1.211982,0.494619 -0.0072,2.044214 -0.746071,2.219639 -2.002473,0.475389 -3.363966,-1.941349 -3.282715,-3.863817 0.145339,-3.438842 3.395746,-5.478675 6.267001,-5.014738 4.213684,0.680847 6.613375,5.560785 5.819357,9.947271 -1.058302,5.846493 -6.702764,9.11037 -11.78793,7.809837 -6.399164,-1.636587 -9.92922,-9.213238 -8.355999,-16.030724 1.905381,-8.25689 10.021154,-12.77567 17.308859,-10.604938 8.588308,2.558132 13.261844,12.872062 10.892641,22.114179 C 38.738937,47.105184 28.131277,52.88707 18.644488,49.834832 7.8649962,46.366685 2.0432755,33.301452 5.2152048,21.6372 8.7736303,8.5516717 21.881626,1.5031683 33.565921,5.4420623 46.537704,9.8149815 53.509876,25.638026 49.531847,39.723149"
+ id="path2990"
+ style="fill:none;stroke:&stroke_color;;stroke-width:3.7052505;stroke-linecap:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
</svg>
diff --git a/po/ShareFavorites.pot b/po/ShareFavorites.pot
index 62c8eb9..e549720 100644
--- a/po/ShareFavorites.pot
+++ b/po/ShareFavorites.pot
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-07-31 14:45-0400\n"
+"POT-Creation-Date: 2013-08-01 10:20-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -17,10 +17,34 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
-#: activity/activity.info:2
+#: activity/activity.info:2 ShareFavorites.py:282
msgid "Share Favorites"
msgstr ""
#: activity/activity.info:3
msgid "share your favorite activities"
msgstr ""
+
+#: ShareFavorites.py:132 ShareFavorites.py:221
+msgid "Warning"
+msgstr ""
+
+#: ShareFavorites.py:133 ShareFavorites.py:222
+msgid "Changes require restart"
+msgstr ""
+
+#: ShareFavorites.py:137
+msgid "Cancel changes"
+msgstr ""
+
+#: ShareFavorites.py:141
+msgid "Later"
+msgstr ""
+
+#: ShareFavorites.py:145
+msgid "Restart now"
+msgstr ""
+
+#: ShareFavorites.py:283
+msgid "Downloading favorites... please wait."
+msgstr ""