diff options
author | Ajay Garg <ajay@activitycentral.com> | 2012-12-25 14:17:48 (GMT) |
---|---|---|
committer | Ajay Garg <ajay@activitycentral.com> | 2012-12-26 18:09:30 (GMT) |
commit | 3c9643d2e05e41117bcc18da98b07810f4817b0a (patch) | |
tree | 538fefc9e2d4dc1c7f6a812663a23b88e75c107d | |
parent | db124b3869b404c41a267ac24b8a0c9f3413354b (diff) |
sdxo#2572: Now, a notification has the provision of containing a URL, which when clicked will open itself in "Browse" activity.
-rw-r--r-- | src/jarabe/frame/frame.py | 4 | ||||
-rw-r--r-- | src/jarabe/frame/notification.py | 63 | ||||
-rw-r--r-- | src/jarabe/model/shell.py | 11 |
3 files changed, 73 insertions, 5 deletions
diff --git a/src/jarabe/frame/frame.py b/src/jarabe/frame/frame.py index ec9e9fe..bad64ac 100644 --- a/src/jarabe/frame/frame.py +++ b/src/jarabe/frame/frame.py @@ -302,7 +302,7 @@ class Frame(object): window.destroy() del self._notif_by_icon[icon] - def add_message(self, body, summary='', icon_name=_DEFAULT_ICON, + def add_message(self, body, summary='', link=None, link_text=None, icon_name=_DEFAULT_ICON, xo_color=None, corner=Gtk.CornerType.TOP_LEFT, duration=_NOTIFICATION_DURATION): @@ -326,7 +326,7 @@ class Frame(object): button.start_pulsing() - palette.push_message(body, summary, icon_name, xo_color) + palette.push_message(body, summary, link, link_text, icon_name, xo_color) if not self.visible: self._launch_notification_icon(_DEFAULT_ICON, xo_color, corner, duration) diff --git a/src/jarabe/frame/notification.py b/src/jarabe/frame/notification.py index a0ac403..c9e3779 100644 --- a/src/jarabe/frame/notification.py +++ b/src/jarabe/frame/notification.py @@ -20,6 +20,9 @@ from gi.repository import Gdk import re import os +import dbus +import logging +import subprocess from gettext import gettext as _ @@ -30,6 +33,7 @@ from sugar3.graphics.toolbutton import ToolButton from sugar3.graphics.palettemenu import PaletteMenuItem from sugar3 import profile +from jarabe.journal import misc from jarabe.frame.frameinvoker import FrameWidgetInvoker from jarabe.view.pulsingicon import PulsingIcon @@ -120,7 +124,7 @@ class _MessagesHistoryBox(Gtk.VBox): ''' % (link_color, visited_link_color) Gtk.rc_parse_string(links_style) - def push_message(self, body, summary, icon_name, xo_color): + def push_message(self, body, summary, link, link_text, icon_name, xo_color): entry = Gtk.HBox() icon_widget = _HistoryIconWidget(icon_name, xo_color) @@ -140,6 +144,19 @@ class _MessagesHistoryBox(Gtk.VBox): body_widget = _HistoryBodyWidget(body) message.pack_start(body_widget, True, True, 0) + if link: + if link_text: + widget_link_text = link_text + else: + widget_link_text = link + + link_widget = Gtk.LinkButton(link, + '<span color="white">%s</span>' % widget_link_text) + link_widget.get_child().set_use_markup(True) + link_widget.connect('clicked', self.__connect_to_uri, link) + + message.pack_start(link_widget, True, True, 0) + entry.show_all() self.pack_start(entry, True, True, 0) self.reorder_child(entry, 0) @@ -150,6 +167,46 @@ class _MessagesHistoryBox(Gtk.VBox): (len(self.get_children()) > 1): self.remove(self.get_children()[-1]) + def __connect_to_uri(self, link_widget, link): + from jarabe.model.bundleregistry import get_registry + registry = get_registry() + from jarabe.model.shell import get_model + shell_model = get_model() + + browse_activity_id = 'org.laptop.WebActivity' + browse_acivity_bundle = \ + registry.get_bundle(browse_activity_id) + + current_activity_running = \ + shell_model.get_activity_by_bundle_id(browse_activity_id) + + # If there is no instance of "Browse" running, launch a new + # instance, and load the URL. + # + # Else, switch to the window of the + # already-running-"Browse"-instance, and load the URL. + if current_activity_running is None: + misc.launch(browse_acivity_bundle, None, None, link) + else: + current_activity_running.get_window().activate(Gtk.get_current_event_time()) + + # Now, send the signal to "Browse" activity, which is + # running in a different process. + environment = os.environ.copy() + try: + process = subprocess.Popen(['dbus-send ' + '--session ' + '/org/laptop/WebActivity ' + 'org.laptop.WebActivity.Load_URI ' + 'string:\'%s\'' % link], + stdout=subprocess.PIPE, + env=environment, + shell=True) + process.wait() + except Exception, e: + logging.exception(e) + + class HistoryPalette(Palette): __gtype_name__ = 'SugarHistoryPalette' @@ -190,8 +247,8 @@ class HistoryPalette(Palette): def __notice_messages_cb(self, palette): self.emit('notice-messages') - def push_message(self, body, summary, icon_name, xo_color): - self._messages_box.push_message(body, summary, icon_name, xo_color) + def push_message(self, body, summary, link, link_text, icon_name, xo_color): + self._messages_box.push_message(body, summary, link, link_text, icon_name, xo_color) class NotificationButton(ToolButton): diff --git a/src/jarabe/model/shell.py b/src/jarabe/model/shell.py index 437ff90..d70514b 100644 --- a/src/jarabe/model/shell.py +++ b/src/jarabe/model/shell.py @@ -170,6 +170,11 @@ class Activity(GObject.GObject): """ return self._activity_id + def get_bundle_id(self): + if self._activity_info: + return self._activity_info.get_bundle_id() + return None + def get_xid(self): """Retrieve the X-windows ID of our root window""" if self._windows: @@ -591,6 +596,12 @@ class ShellModel(GObject.GObject): return home_activity return None + def get_activity_by_bundle_id(self, bundle_id): + for home_activity in self._activities: + if home_activity.get_bundle_id() == bundle_id: + return home_activity + return None + def _active_window_changed_cb(self, screen, previous_window=None): window = screen.get_active_window() if window is None: |