Merge lp:~ralsina/ubuntuone-control-panel/alerted into lp:ubuntuone-control-panel

Proposed by Roberto Alsina
Status: Merged
Approved by: Natalia Bidart
Approved revision: 288
Merged at revision: 278
Proposed branch: lp:~ralsina/ubuntuone-control-panel/alerted
Merge into: lp:ubuntuone-control-panel
Diff against target: 234 lines (+117/-13)
5 files modified
docs/ubuntuone-control-panel-qt.1 (+1/-4)
ubuntuone/controlpanel/gui/qt/gui.py (+32/-1)
ubuntuone/controlpanel/gui/qt/main/__init__.py (+3/-7)
ubuntuone/controlpanel/gui/qt/main/tests/test_main.py (+24/-1)
ubuntuone/controlpanel/gui/qt/tests/test_gui.py (+57/-0)
To merge this branch: bzr merge lp:~ralsina/ubuntuone-control-panel/alerted
Reviewer Review Type Date Requested Status
Natalia Bidart Approve
Eric Casteleijn (community) Approve
Review via email: mp+96253@code.launchpad.net

Commit message

- Fixed --alert and --switch-to tabname and updated --help and manpage accordingly
  (LP: #940465).

Description of the change

* Implemented --alert option: Starts with the "urgent" flag set on launcher.
* Remove the "urgent" flag when u1cp gets focus.
* Implemented --switch-to tabname
* Fixed --help
* Updated manpage

To post a comment you must log in.
284. By Roberto Alsina

merged trunk

Revision history for this message
Eric Casteleijn (thisfred) wrote :

Looks great!

review: Approve
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Question, why would you patch self.patch(self.ui, "focusInEvent", lambda ev: False) in the set_urgent test?

Also, can we change this code:

        self.ui.switch_to("devices")
        self.assertEqual(
            self.ui.ui.control_panel.ui.tab_widget.currentIndex(),
            2)

to use something like:

        self.ui.switch_to("devices")
        self.assertEqual(
            self.ui.ui.control_panel.ui.tab_widget.currentIndex(),
            self.ui.ui.control_panel.ui.tab_widget.indexOf(self.ui.ui.control_panel.ui.devices))

which in turn allows us to do something like:

        for tab_name in self.ui.tabs:
            tab = getattr(self.ui.ui.control_panel.ui, tab_name)
            self.ui.switch_to(tab_name)
            self.assertEqual(
                self.ui.ui.control_panel.ui.tab_widget.currentIndex(),
                self.ui.ui.control_panel.ui.tab_widget.indexOf(tab))

What do you think?

review: Needs Information
Revision history for this message
Roberto Alsina (ralsina) wrote :

> Question, why would you patch self.patch(self.ui, "focusInEvent", lambda ev:
> False) in the set_urgent test?

Doesn't seem necessary anymore. In a previous version of this, when you create the window, that widget got focus and focusInEvent removed the urgent flag. Will remove.

> Also, can we change this code:
>
> self.ui.switch_to("devices")
> self.assertEqual(
> self.ui.ui.control_panel.ui.tab_widget.currentIndex(),
> 2)
>
> to use something like:
>
> self.ui.switch_to("devices")
> self.assertEqual(
> self.ui.ui.control_panel.ui.tab_widget.currentIndex(),
> self.ui.ui.control_panel.ui.tab_widget.indexOf(self.ui.ui.control_
> panel.ui.devices))
>
> which in turn allows us to do something like:
>
> for tab_name in self.ui.tabs:
> tab = getattr(self.ui.ui.control_panel.ui, tab_name)
> self.ui.switch_to(tab_name)
> self.assertEqual(
> self.ui.ui.control_panel.ui.tab_widget.currentIndex(),
> self.ui.ui.control_panel.ui.tab_widget.indexOf(tab))
>
> What do you think?

It's a bit verbose, and it has a problem in that we don't want to test the tab switching in order, but something similar is doable.

285. By Roberto Alsina

use widget indexes instead of magic numbers

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Can you please remove this debug line?

        print "CALLED:", args, kwargs

Also, after the IRC talk about the --alert not working, can you please remove that altogether? Thanks!

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

We should drop --alert, but keep the unsetting of urgency on focusInEvent.

286. By Roberto Alsina

kill --alert since it's not all that useful.

287. By Roberto Alsina

remove debug print

Revision history for this message
Roberto Alsina (ralsina) wrote :

> We should drop --alert, but keep the unsetting of urgency on focusInEvent.

Done!

288. By Roberto Alsina

fix docstring

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'docs/ubuntuone-control-panel-qt.1'
2--- docs/ubuntuone-control-panel-qt.1 2012-03-07 14:24:40 +0000
3+++ docs/ubuntuone-control-panel-qt.1 2012-03-09 01:08:17 +0000
4@@ -12,10 +12,7 @@
5 .TP
6 \fB\-\-switch\-to\fR PANEL_NAME
7 Start Ubuntu One in the PANEL_NAME tab. Possible
8-values are: dashboard, volumes, devices, applications
9-.TP
10-\fB\-a\fR, \fB\-\-alert\fR
11-Start Ubuntu One alerting the user to its presence.
12+values are: folders, devices, settings, account
13 .TP
14 \fB\-\-minimized\fR
15 Start Ubuntu One only in the notification area, with
16
17=== modified file 'ubuntuone/controlpanel/gui/qt/gui.py'
18--- ubuntuone/controlpanel/gui/qt/gui.py 2012-02-29 21:33:02 +0000
19+++ ubuntuone/controlpanel/gui/qt/gui.py 2012-03-09 01:08:17 +0000
20@@ -21,6 +21,16 @@
21 from ubuntuone.controlpanel.gui.qt.systray import TrayIcon
22 from ubuntuone.controlpanel.gui.qt.ui import mainwindow_ui
23
24+# pylint: disable=E0611
25+try:
26+ from gi.repository import Unity
27+ USE_LIBUNITY = True
28+except ImportError:
29+ USE_LIBUNITY = False
30+# pylint: enable=E0611
31+
32+U1_DOTDESKTOP = "ubuntuone-installer.desktop"
33+
34
35 class MainWindow(QtGui.QMainWindow):
36 """The Main Window of the Control Panel."""
37@@ -36,12 +46,23 @@
38 triggered=self.close)
39 self.quit_action.setShortcuts(["Ctrl+q", "Ctrl+w"])
40 self.addAction(self.quit_action)
41+ if USE_LIBUNITY:
42+ self.entry = Unity.LauncherEntry.get_for_desktop_id(U1_DOTDESKTOP)
43+ else:
44+ self.entry = None
45
46 def _setup(self):
47 """Do some extra setupping for the UI."""
48 self.ui.control_panel.finished.connect(self.close)
49
50- # Invalid name "closeEvent"
51+ def switch_to(self, tabname="folders"):
52+ """Switch control panel to the required tab."""
53+ tabnames = ["folders", "devices", "settings", "account"]
54+ if tabname in tabnames:
55+ self.ui.control_panel.ui.tab_widget.setCurrentIndex(
56+ tabnames.index(tabname))
57+
58+ # Invalid names "closeEvent" "focusInEvent"
59 # pylint: disable=C0103
60
61 def closeEvent(self, event):
62@@ -50,6 +71,16 @@
63 self.close_callback()
64 event.accept()
65
66+ def set_urgent(self, value):
67+ """Set the urgent attribute in the launcher to value."""
68+ if self.entry:
69+ self.entry.set_property('urgent', value)
70+
71+ def focusInEvent(self, event):
72+ """The main window got focus, remove urgent bit."""
73+ self.set_urgent(False)
74+ return super(MainWindow, self).focusInEvent(event)
75+
76 # pylint: enable=C0103
77
78
79
80=== modified file 'ubuntuone/controlpanel/gui/qt/main/__init__.py'
81--- ubuntuone/controlpanel/gui/qt/main/__init__.py 2012-02-28 14:39:43 +0000
82+++ ubuntuone/controlpanel/gui/qt/main/__init__.py 2012-03-09 01:08:17 +0000
83@@ -45,11 +45,7 @@
84 metavar="PANEL_NAME", default="",
85 help="Start Ubuntu One in the "
86 "PANEL_NAME tab. Possible values are: "
87- "dashboard, volumes, devices, applications")
88- result.add_argument("-a", "--alert", dest="alert", action="store_true",
89- default=False,
90- help="Start Ubuntu One "
91- "alerting the user to its presence.")
92+ "folders, devices, settings, account")
93 result.add_argument("--minimized", dest="minimized", action="store_true",
94 default=False,
95 help="Start Ubuntu One "
96@@ -72,8 +68,7 @@
97 parser = parser_options()
98 # Use only the arguments that are not recognized by Qt
99 args = parser.parse_args(args=[unicode(x) for x in app.arguments()[1:]])
100- _ = args.switch_to
101- _ = args.alert
102+ switch_to = args.switch_to
103 minimized = args.minimized
104 with_icon = args.with_icon
105 source.main(app)
106@@ -84,6 +79,7 @@
107 # Unused variable 'window', 'icon', pylint: disable=W0612
108 icon, window = start(lambda: source.main_quit(app),
109 minimized=minimized, with_icon=with_icon)
110+ window.switch_to(switch_to)
111 # pylint: enable=W0612
112 if icon:
113 app.new_instance.connect(icon.restore_window)
114
115=== modified file 'ubuntuone/controlpanel/gui/qt/main/tests/test_main.py'
116--- ubuntuone/controlpanel/gui/qt/main/tests/test_main.py 2012-02-24 18:16:50 +0000
117+++ ubuntuone/controlpanel/gui/qt/main/tests/test_main.py 2012-03-09 01:08:17 +0000
118@@ -52,16 +52,34 @@
119 pass
120
121
122+class FakeMainWindow(object):
123+
124+ """A fake MainWindow."""
125+
126+ tabname = None
127+ urgent = None
128+
129+ def switch_to(self, tabname):
130+ """Fake switch_to."""
131+ self.tabname = tabname
132+
133+ def set_urgent(self, value):
134+ """Fake set_urgent."""
135+ self.urgent = value
136+
137+
138 class FakeStart(object):
139
140 """Fake start function."""
141
142 def __init__(self):
143 self.args = None
144+ self.window = None
145
146 def __call__(self, *args, **kwargs):
147 self.args = (args, kwargs)
148- return None, None
149+ self.window = FakeMainWindow()
150+ return None, self.window
151
152
153 class MainTestCase(TestCase):
154@@ -103,3 +121,8 @@
155 """Ensure the stylesheet is loaded."""
156 main.main([])
157 self.assertTrue(self.app.style)
158+
159+ def test_switch_to_option(self):
160+ """Ensure the --switch-to option is parsed and passed correctly."""
161+ main.main(["foobar", "--switch-to", "folders"])
162+ self.assertEqual(self.start.window.tabname, "folders")
163
164=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_gui.py'
165--- ubuntuone/controlpanel/gui/qt/tests/test_gui.py 2012-03-02 16:56:10 +0000
166+++ ubuntuone/controlpanel/gui/qt/tests/test_gui.py 2012-03-09 01:08:17 +0000
167@@ -22,6 +22,17 @@
168 from ubuntuone.controlpanel.gui.qt.tests import BaseTestCase
169
170
171+class FakeEntry(object):
172+
173+ """A fake unity launcher entry."""
174+
175+ called = None
176+
177+ def set_property(self, *args, **kwargs):
178+ """Fake set_property."""
179+ self.called = (args, kwargs)
180+
181+
182 class MainWindowTestCase(BaseTestCase):
183 """Test the qt main window."""
184
185@@ -58,3 +69,49 @@
186 self.assertFalse(self.ui.isVisible())
187 self.assertEqual(self._called,
188 ((), {}), 'close_callback called.')
189+
190+ def test_switch_to(self):
191+ """Check that switch_to changes the current tab"""
192+ self.assertEqual(
193+ self.ui.ui.control_panel.ui.tab_widget.currentIndex(),
194+ self.ui.ui.control_panel.ui.tab_widget.indexOf(
195+ self.ui.ui.control_panel.ui.folders_tab))
196+ self.ui.switch_to("foobar")
197+ self.assertEqual(
198+ self.ui.ui.control_panel.ui.tab_widget.currentIndex(),
199+ self.ui.ui.control_panel.ui.tab_widget.indexOf(
200+ self.ui.ui.control_panel.ui.folders_tab))
201+ self.ui.switch_to("devices")
202+ self.assertEqual(
203+ self.ui.ui.control_panel.ui.tab_widget.currentIndex(),
204+ self.ui.ui.control_panel.ui.tab_widget.indexOf(
205+ self.ui.ui.control_panel.ui.devices_tab))
206+ self.ui.switch_to("settings")
207+ self.assertEqual(
208+ self.ui.ui.control_panel.ui.tab_widget.currentIndex(),
209+ self.ui.ui.control_panel.ui.tab_widget.indexOf(
210+ self.ui.ui.control_panel.ui.preferences_tab))
211+ self.ui.switch_to("account")
212+ self.assertEqual(
213+ self.ui.ui.control_panel.ui.tab_widget.currentIndex(),
214+ self.ui.ui.control_panel.ui.tab_widget.indexOf(
215+ self.ui.ui.control_panel.ui.account_tab))
216+ self.ui.switch_to("folders")
217+ self.assertEqual(
218+ self.ui.ui.control_panel.ui.tab_widget.currentIndex(),
219+ self.ui.ui.control_panel.ui.tab_widget.indexOf(
220+ self.ui.ui.control_panel.ui.folders_tab))
221+
222+ def test_focus_in(self):
223+ """Test that focusing removes urgent bit from launcher entry."""
224+ entry = FakeEntry()
225+ self.patch(self.ui, "entry", entry)
226+ self.ui.focusInEvent(None)
227+ self.assertEqual(entry.called, (('urgent', False), {}))
228+
229+ def test_set_urgent(self):
230+ """Test that set_urgent calls with the right arguments."""
231+ entry = FakeEntry()
232+ self.patch(self.ui, "entry", entry)
233+ self.ui.set_urgent("foo")
234+ self.assertEqual(entry.called, (('urgent', "foo"), {}))

Subscribers

People subscribed via source and target branches