From 178fbb712834b1d82b8cfe27cf559671130fa146 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Wed, 14 Aug 2013 12:56:44 +0000 Subject: add check in case activity has been updated since favorites were last saved --- diff --git a/ShareFavorites.py b/ShareFavorites.py index 0c44199..93276f2 100644 --- a/ShareFavorites.py +++ b/ShareFavorites.py @@ -41,6 +41,7 @@ _logger = logging.getLogger("share-favorites") import json +import dbus import telepathy from dbus.service import signal from dbus.gobject_service import ExportedGObject @@ -76,6 +77,9 @@ class ShareFavorites(activity.Activity): self._vbox.pack_end(self._icon, True, True, 0) self._vbox.show() + bus = dbus.SessionBus() + self._proxy = bus.get_object('org.laptop.Shell', '/org/laptop/Shell') + def _setup_canvas(self): ''' Create a canvas ''' sw = Gtk.ScrolledWindow() @@ -101,11 +105,7 @@ class ShareFavorites(activity.Activity): 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')) + # TODO: Exit activity after animation return else: self._show_bundle_icon(icon_paths[-1]) @@ -175,41 +175,8 @@ class ShareFavorites(activity.Activity): self._old_cursor = self.get_window().get_cursor() self.get_window().set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH)) - 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: @@ -243,11 +210,17 @@ class ShareFavorites(activity.Activity): 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) + logging.debug('removing %s %s' % (bundle_id, version)) + try: + dbus.Interface(self._proxy, + 'org.laptop.Shell').SetBundleFavorite( + bundle_id, version, False) + except ValueError: + logging.debug('Could not find %s %s in favorites' % + (bundle_ide, version)) def _set_favorites(self, data): - # data is coming over tube, so it needs to be decoded + # Data is coming over tube, so it needs to be decoded favorites_data = json.loads(data) favorites = favorites_data['favorites'] keys = favorites.keys() @@ -256,13 +229,16 @@ class ShareFavorites(activity.Activity): for bundle in keys: bundle = bundle.encode('ascii', 'replace') bundle_id, version = bundle.split(' ') + logging.debug('adding %s' % (bundle_id)) try: - logging.debug('adding %s' % (bundle_id)) - registry.set_bundle_favorite(bundle_id, version, True) + dbus.Interface(self._proxy, + 'org.laptop.Shell').SetBundleFavorite( + 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: + except ValueError: logging.debug('bundle %s version %s not available' % (bundle_id, version)) @@ -382,7 +358,7 @@ class ShareFavorites(activity.Activity): self._restore_cursor() def _share_favorites(self, data=None): - logging.debug('SHARE FAVORITES %s' % (str(self.initiating))) + logging.debug('share favorites %s' % (str(self.initiating))) if self.initiating: favorites = self._read_favorites() self._send_event('F:%s' % (json.dumps(favorites))) -- cgit v0.9.1