Merge lp:~nataliabidart/ubuntuone-control-panel/stable-3-0-update-2.99.1 into lp:ubuntuone-control-panel/stable-3-0

Proposed by Natalia Bidart
Status: Merged
Approved by: Natalia Bidart
Approved revision: 243
Merged at revision: 243
Proposed branch: lp:~nataliabidart/ubuntuone-control-panel/stable-3-0-update-2.99.1
Merge into: lp:ubuntuone-control-panel/stable-3-0
Diff against target: 300 lines (+143/-107)
4 files modified
ubuntuone/controlpanel/gui/qt/addfolder.py (+2/-1)
ubuntuone/controlpanel/gui/qt/systray.py (+14/-3)
ubuntuone/controlpanel/gui/qt/tests/test_addfolder.py (+1/-0)
ubuntuone/controlpanel/gui/qt/tests/test_systray.py (+126/-103)
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-control-panel/stable-3-0-update-2.99.1
Reviewer Review Type Date Requested Status
dobey (community) Approve
Review via email: mp+87379@code.launchpad.net

Commit message

[ Diego Sarmentero <email address hidden> ]
  - Fix dirty reactor.
[ Roberto Alsina <email address hidden> ]
  - When selecting "Quit Ubuntu One" from the tray context menu,
    shutdown syncdaemon (LP: #908888).
  - Make addfolder open the file dialog in $HOME instead of in the
    working directory (LP: #906541).

To post a comment you must log in.
Revision history for this message
dobey (dobey) :
review: Approve
Revision history for this message
dobey (dobey) wrote :

Please fix the commit message to not say "ralsina" :)

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/controlpanel/gui/qt/addfolder.py'
2--- ubuntuone/controlpanel/gui/qt/addfolder.py 2011-09-07 16:56:39 +0000
3+++ ubuntuone/controlpanel/gui/qt/addfolder.py 2012-01-03 16:24:14 +0000
4@@ -57,7 +57,8 @@
5 """The 'Sync another folder' button was clicked."""
6 # The options argument is because of LP: #835013
7 folder = QtGui.QFileDialog.getExistingDirectory(
8- parent=self, options=QtGui.QFileDialog.DontUseNativeDialog)
9+ parent=self, directory=os.path.expanduser('~'),
10+ options=QtGui.QFileDialog.DontUseNativeDialog)
11 folder = unicode(QtCore.QDir.toNativeSeparators(folder))
12 logger.debug('on_add_folder_button_clicked: user requested folder '
13 'creation for path %r', folder)
14
15=== modified file 'ubuntuone/controlpanel/gui/qt/systray.py'
16--- ubuntuone/controlpanel/gui/qt/systray.py 2011-09-14 20:25:55 +0000
17+++ ubuntuone/controlpanel/gui/qt/systray.py 2012-01-03 16:24:14 +0000
18@@ -1,6 +1,4 @@
19 # -*- coding: utf-8 -*-
20-
21-# Authors: Roberto Alsina <roberto.alsina@canonical.com>
22 #
23 # Copyright 2011 Canonical Ltd.
24 #
25@@ -18,6 +16,9 @@
26 """System notification area icon."""
27
28 from PyQt4 import QtGui
29+from twisted.internet.defer import inlineCallbacks
30+
31+from ubuntuone.platform.tools import SyncDaemonTool
32
33
34 class TrayIcon(QtGui.QSystemTrayIcon):
35@@ -60,8 +61,18 @@
36 self.window.close()
37 self.window = None
38
39- def stop(self):
40+ @inlineCallbacks
41+ def stop(self, *args, **kwargs):
42 """Stop the application."""
43+ # Stop syncdaemon
44+ # pylint: disable=W0702
45+ # Really, if it fails we can't do anything about it.
46+ try:
47+ st = SyncDaemonTool()
48+ yield st.quit()
49+ except:
50+ # Maybe it was not running?
51+ pass
52 # pylint: disable=W0404
53 from twisted.internet import reactor
54 # pylint: enable=W0404
55
56=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_addfolder.py'
57--- ubuntuone/controlpanel/gui/qt/tests/test_addfolder.py 2011-10-05 16:35:59 +0000
58+++ ubuntuone/controlpanel/gui/qt/tests/test_addfolder.py 2012-01-03 16:24:14 +0000
59@@ -83,6 +83,7 @@
60 self.assertEqual(FakedFileDialog.args, ())
61 self.assertEqual(FakedFileDialog.kwargs, {
62 'options': gui.QtGui.QFileDialog.DontUseNativeDialog,
63+ 'directory': os.path.expanduser('~'),
64 'parent': self.ui,
65 })
66
67
68=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_systray.py'
69--- ubuntuone/controlpanel/gui/qt/tests/test_systray.py 2011-09-07 17:33:09 +0000
70+++ ubuntuone/controlpanel/gui/qt/tests/test_systray.py 2012-01-03 16:24:14 +0000
71@@ -1,103 +1,126 @@
72-# -*- coding: utf-8 -*-
73-
74-# Author: Roberto Alsina <roberto.alsina@canonical.com>
75-#
76-# Copyright 2011 Canonical Ltd.
77-#
78-# This program is free software: you can redistribute it and/or modify it
79-# under the terms of the GNU General Public License version 3, as published
80-# by the Free Software Foundation.
81-#
82-# This program is distributed in the hope that it will be useful, but
83-# WITHOUT ANY WARRANTY; without even the implied warranties of
84-# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
85-# PURPOSE. See the GNU General Public License for more details.
86-#
87-# You should have received a copy of the GNU General Public License along
88-# with this program. If not, see <http://www.gnu.org/licenses/>.
89-
90-"""Tests for the notification area icon."""
91-
92-from PyQt4 import QtGui
93-
94-from ubuntuone.controlpanel.gui.qt.systray import TrayIcon
95-from ubuntuone.controlpanel.tests import TestCase
96-import ubuntuone.controlpanel.gui.qt.gui
97-
98-
99-class FakeMainWindow(QtGui.QWidget):
100-
101- """Fake Main Window."""
102-
103- def __init__(self, *args, **kwargs):
104- self.args = (args, kwargs)
105- super(FakeMainWindow, self).__init__()
106-
107-
108-class SystrayTestCase(TestCase):
109-
110- """Test the notification area icon."""
111-
112- def test_quit(self):
113- """Test the quit option in the menu."""
114- # Not done on setup, because if I patch stop
115- # after instantiation, it doesn't get called.
116- self.patch(TrayIcon, "stop", self._set_called)
117- tray = TrayIcon()
118- tray.quit.trigger()
119- self.assertEqual(self._called, ((False,), {}))
120-
121- def test_restore_no_window(self):
122- """Test the restore window option in the menu, with no window."""
123- self.patch(ubuntuone.controlpanel.gui.qt.gui,
124- "MainWindow", FakeMainWindow)
125- tray = TrayIcon()
126- self.assertEqual(tray.window, None)
127- tray.restore.trigger()
128- self.assertIsInstance(tray.window, FakeMainWindow)
129- self.assertTrue(tray.window.isVisible())
130- self.assertEqual(tray.window.args, ((),
131- {'close_callback': tray.delete_window}))
132-
133- def test_activate(self):
134- """Test the icon activation."""
135- tray = TrayIcon()
136- window = FakeMainWindow()
137- tray.window = window
138- self.assertFalse(tray.window.isVisible())
139- tray.activated.emit(tray.Trigger)
140- self.assertEqual(tray.window, window)
141- self.assertTrue(tray.window.isVisible())
142-
143- def test_restore_window(self):
144- """Test the restore window option in the menu, with a window."""
145- tray = TrayIcon()
146- window = FakeMainWindow()
147- tray.window = window
148- self.assertFalse(tray.window.isVisible())
149- tray.restore.trigger()
150- self.assertEqual(tray.window, window)
151- self.assertTrue(tray.window.isVisible())
152-
153- def test_delete_window(self):
154- """Test deleting an existing window."""
155- tray = TrayIcon()
156- window = FakeMainWindow()
157- tray.window = window
158- tray.delete_window()
159- self.assertEqual(tray.window, None)
160- self.assertFalse(window.isVisible())
161-
162- def test_delete_no_window(self):
163- """Test deleting without an existing window."""
164- tray = TrayIcon()
165- tray.delete_window()
166- self.assertEqual(tray.window, None)
167-
168- def test_initialization(self):
169- """Test that everything initializes correctly."""
170- tray = TrayIcon()
171- self.assertTrue(tray.isVisible())
172- self.assertEqual(tray.window, None)
173- self.assertIsInstance(tray.context_menu, QtGui.QMenu)
174- self.assertFalse(tray.icon() == None)
175+# -*- coding: utf-8 -*-
176+
177+# Author: Roberto Alsina <roberto.alsina@canonical.com>
178+#
179+# Copyright 2011 Canonical Ltd.
180+#
181+# This program is free software: you can redistribute it and/or modify it
182+# under the terms of the GNU General Public License version 3, as published
183+# by the Free Software Foundation.
184+#
185+# This program is distributed in the hope that it will be useful, but
186+# WITHOUT ANY WARRANTY; without even the implied warranties of
187+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
188+# PURPOSE. See the GNU General Public License for more details.
189+#
190+# You should have received a copy of the GNU General Public License along
191+# with this program. If not, see <http://www.gnu.org/licenses/>.
192+
193+"""Tests for the notification area icon."""
194+
195+from PyQt4 import QtGui
196+from twisted.internet import reactor
197+from twisted.internet.defer import inlineCallbacks
198+
199+from ubuntuone.controlpanel.gui.qt import systray
200+from ubuntuone.controlpanel.tests import TestCase
201+import ubuntuone.controlpanel.gui.qt.gui
202+
203+
204+class FakeSDTool(object):
205+
206+ """Fake SyncDaemonTool."""
207+
208+ called = False
209+
210+ def quit(self):
211+ """Fake quit."""
212+ self.called = True
213+
214+
215+class FakeMainWindow(QtGui.QWidget):
216+
217+ """Fake Main Window."""
218+
219+ def __init__(self, *args, **kwargs):
220+ self.args = (args, kwargs)
221+ super(FakeMainWindow, self).__init__()
222+
223+
224+class SystrayTestCase(TestCase):
225+
226+ """Test the notification area icon."""
227+
228+ def test_quit(self):
229+ """Test the quit option in the menu."""
230+ # Not done on setup, because if I patch stop
231+ # after instantiation, it doesn't get called.
232+ self.patch(systray.TrayIcon, "stop", self._set_called)
233+ tray = systray.TrayIcon()
234+ tray.quit.trigger()
235+ self.assertEqual(self._called, ((False,), {}))
236+
237+ @inlineCallbacks
238+ def test_stop_sd(self):
239+ """Quit should call SyncDaemonTool.quit()."""
240+ st = FakeSDTool()
241+ self.patch(systray, "SyncDaemonTool", lambda: st)
242+ self.patch(reactor, "stop", lambda: None)
243+ tray = systray.TrayIcon()
244+ yield tray.stop()
245+ self.assertTrue(st.called)
246+
247+ def test_restore_no_window(self):
248+ """Test the restore window option in the menu, with no window."""
249+ self.patch(ubuntuone.controlpanel.gui.qt.gui,
250+ "MainWindow", FakeMainWindow)
251+ tray = systray.TrayIcon()
252+ self.assertEqual(tray.window, None)
253+ tray.restore.trigger()
254+ self.assertIsInstance(tray.window, FakeMainWindow)
255+ self.assertTrue(tray.window.isVisible())
256+ self.assertEqual(tray.window.args, ((),
257+ {'close_callback': tray.delete_window}))
258+
259+ def test_activate(self):
260+ """Test the icon activation."""
261+ tray = systray.TrayIcon()
262+ window = FakeMainWindow()
263+ tray.window = window
264+ self.assertFalse(tray.window.isVisible())
265+ tray.activated.emit(tray.Trigger)
266+ self.assertEqual(tray.window, window)
267+ self.assertTrue(tray.window.isVisible())
268+
269+ def test_restore_window(self):
270+ """Test the restore window option in the menu, with a window."""
271+ tray = systray.TrayIcon()
272+ window = FakeMainWindow()
273+ tray.window = window
274+ self.assertFalse(tray.window.isVisible())
275+ tray.restore.trigger()
276+ self.assertEqual(tray.window, window)
277+ self.assertTrue(tray.window.isVisible())
278+
279+ def test_delete_window(self):
280+ """Test deleting an existing window."""
281+ tray = systray.TrayIcon()
282+ window = FakeMainWindow()
283+ tray.window = window
284+ tray.delete_window()
285+ self.assertEqual(tray.window, None)
286+ self.assertFalse(window.isVisible())
287+
288+ def test_delete_no_window(self):
289+ """Test deleting without an existing window."""
290+ tray = systray.TrayIcon()
291+ tray.delete_window()
292+ self.assertEqual(tray.window, None)
293+
294+ def test_initialization(self):
295+ """Test that everything initializes correctly."""
296+ tray = systray.TrayIcon()
297+ self.assertTrue(tray.isVisible())
298+ self.assertEqual(tray.window, None)
299+ self.assertIsInstance(tray.context_menu, QtGui.QMenu)
300+ self.assertFalse(tray.icon() == None)

Subscribers

People subscribed via source and target branches