Merge lp:~3v1n0/ubuntuone-client/sync-menu-use-gappinfo-launch-4.2 into lp:ubuntuone-client/stable-4-2

Proposed by Marco Trevisan (Treviño)
Status: Superseded
Proposed branch: lp:~3v1n0/ubuntuone-client/sync-menu-use-gappinfo-launch-4.2
Merge into: lp:ubuntuone-client/stable-4-2
Diff against target: 136 lines (+62/-28)
1 file modified
ubuntuone/platform/sync_menu/linux.py (+62/-28)
To merge this branch: bzr merge lp:~3v1n0/ubuntuone-client/sync-menu-use-gappinfo-launch-4.2
Reviewer Review Type Date Requested Status
dobey (community) Disapprove
Diego Sarmentero (community) Needs Fixing
Review via email: mp+158565@code.launchpad.net

This proposal has been superseded by a proposal from 2013-04-16.

Commit message

UbuntuOneSyncMenuLinux: use GAppInfo with proper context to launch URIs

This allows to correctly open the application with proper startup notify.

Description of the change

To post a comment you must log in.
1368. By Marco Trevisan (Treviño)

UbuntuOneSyncMenuLinux: protect the commandline-app-creation from error too

Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

Tests are failing, and there isn't new tests for the new code.

review: Needs Fixing
Revision history for this message
dobey (dobey) wrote :

I'm just rejecting this, because it's not necessary to have to deal with 2 proposals at the moment. Only the branch against truck is needed for this, as there's no conflicting difference between it and stable-4-2 that would break this branch.

review: Disapprove
1369. By Marco Trevisan (Treviño)

UbuntuOneSyncMenuLinux: merge with trunk branch changes

Unmerged revisions

1369. By Marco Trevisan (Treviño)

UbuntuOneSyncMenuLinux: merge with trunk branch changes

1368. By Marco Trevisan (Treviño)

UbuntuOneSyncMenuLinux: protect the commandline-app-creation from error too

1367. By Marco Trevisan (Treviño)

UbuntuOneSyncMenuLinux: use GAppInfo with proper context to launch URIs

This allows to correctly open the application with proper startup notify.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/platform/sync_menu/linux.py'
2--- ubuntuone/platform/sync_menu/linux.py 2013-02-20 22:41:12 +0000
3+++ ubuntuone/platform/sync_menu/linux.py 2013-04-12 12:36:39 +0000
4@@ -31,7 +31,6 @@
5 import gettext
6 import logging
7 import time
8-import webbrowser
9 from twisted.python.util import OrderedDict
10 from operator import itemgetter
11
12@@ -39,6 +38,8 @@
13 from gi.repository import GLib as glib
14 from gi.repository import (
15 Dbusmenu,
16+ Gdk,
17+ Gio,
18 SyncMenu,
19 )
20 use_syncmenu = True
21@@ -69,6 +70,9 @@
22 DASHBOARD = UBUNTUONE_LINK + u'dashboard/'
23 HELP_LINK = UBUNTUONE_LINK + u'support/'
24 GET_STORAGE_LINK = UBUNTUONE_LINK + u'services/add-storage/'
25+CLIENT_COMMAND_LINE = 'ubuntuone-control-panel-qt'
26+CLIENT_DESKTOP_ID = 'ubuntuone-control-panel-qt-gnome.desktop'
27+INSTALLER_DESKTOP_ID = 'ubuntuone-installer.desktop'
28
29
30 class UbuntuOneSyncMenuLinux(object):
31@@ -133,7 +137,7 @@
32
33 self.server = Dbusmenu.Server()
34 self.server.set_root(self.root_menu)
35- self.app = SyncMenu.App.new("ubuntuone-installer.desktop")
36+ self.app = SyncMenu.App.new(INSTALLER_DESKTOP_ID)
37 self.app.set_menu(self.server)
38 self.app.connect("notify::paused", self.change_sync_status)
39
40@@ -155,36 +159,65 @@
41 self._syncdaemon_service.connect()
42 self._connected = True
43
44- def open_control_panel(self, *args):
45+ def _get_launch_context(self, timestamp):
46+ """Returns the launch context for the current display"""
47+ context = Gdk.Display.get_default().get_app_launch_context()
48+ context.set_timestamp(timestamp)
49+ return context
50+
51+ def _open_uri(self, uri, timestamp = 0):
52+ """Open an uri Using the default handler and the action timestamp"""
53+ try:
54+ Gio.AppInfo.launch_default_for_uri(uri, self._get_launch_context(timestamp))
55+ except glib.GError as e:
56+ logger.warning('Failed to open the uri %s: %s.' % (uri, e))
57+
58+ def _open_control_panel_by_command_line(self, timestamp, args = ''):
59+ """Open the control panel by command line"""
60+ flags = Gio.AppInfoCreateFlags.SUPPORTS_STARTUP_NOTIFICATION
61+ command_line = CLIENT_COMMAND_LINE
62+ if len(args):
63+ command_line += ' ' + args
64+
65+ try:
66+ app = Gio.AppInfo.create_from_commandline(command_line, 'Ubuntu One', flags)
67+
68+ if app:
69+ app.launch([], self._get_launch_context(timestamp))
70+ except glib.GError as e:
71+ logger.warning('Failed to open the control panel: %s.' % e)
72+
73+ def open_control_panel(self, menuitem, timestamp):
74 """Open the Ubuntu One Control Panel."""
75- try:
76- glib.spawn_command_line_async('ubuntuone-control-panel-qt')
77- except glib.GError as e:
78- logger.warning('Failed to open the control panel: %s.' % e)
79-
80- def open_ubuntu_one_folder(self, *args):
81+ app = Gio.DesktopAppInfo.new(CLIENT_DESKTOP_ID)
82+
83+ if app:
84+ try:
85+ app.launch([], self._get_launch_context(timestamp))
86+ except glib.GError as e:
87+ logger.warning('Failed to open the control panel: %s.' % e)
88+ else:
89+ self._open_control_panel_by_command_line(timestamp)
90+
91+ def open_ubuntu_one_folder(self, menuitem, timestamp):
92 """Open the Ubuntu One folder."""
93- webbrowser.open(self._syncdaemon_service.get_rootdir())
94+ self._open_uri("file://" + self._syncdaemon_service.get_rootdir(), timestamp)
95
96- def open_share_file_tab(self, *args):
97+ def open_share_file_tab(self, menuitem, timestamp):
98 """Open the Control Panel in the Share Tab."""
99- try:
100- glib.spawn_command_line_async('ubuntuone-control-panel-qt '
101- '--switch-to share_links')
102- except glib.GError as e:
103- logger.warning('Failed to open the control panel: %s.' % e)
104-
105- def open_go_to_web(self, *args):
106- """Open the Ubunto One Help Page"""
107- webbrowser.open(DASHBOARD)
108-
109- def open_web_help(self, *args):
110- """Open the Ubunto One Help Page"""
111- webbrowser.open(HELP_LINK)
112-
113- def open_get_more_storage(self, *args):
114- """Open the Ubunto One Help Page"""
115- webbrowser.open(GET_STORAGE_LINK)
116+ self._open_control_panel_by_command_line(timestamp, "--switch-to share_links")
117+
118+ def open_go_to_web(self, menuitem, timestamp):
119+ """Open the Ubuntu One Help Page"""
120+ self._open_uri(DASHBOARD, timestamp)
121+
122+ def open_web_help(self, menuitem, timestamp):
123+ """Open the Ubuntu One Help Page"""
124+ self._open_uri(HELP_LINK, timestamp)
125+
126+ def open_get_more_storage(self, menuitem, timestamp):
127+ """Open the Ubuntu One Help Page"""
128+ self._open_uri(GET_STORAGE_LINK, timestamp)
129
130 def _timeout(self, result):
131 """The aggregating timer has expired, so update the UI."""
132@@ -284,3 +317,4 @@
133 UbuntuOneSyncMenu = UbuntuOneSyncMenuLinux
134 else:
135 UbuntuOneSyncMenu = DummySyncMenu
136+

Subscribers

People subscribed via source and target branches

to status/vote changes: