Merge lp:~alecu/ubuntuone-client/use-libunity into lp:ubuntuone-client
- use-libunity
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Alejandro J. Cura |
Approved revision: | 884 |
Merged at revision: | 884 |
Proposed branch: | lp:~alecu/ubuntuone-client/use-libunity |
Merge into: | lp:ubuntuone-client |
Diff against target: |
591 lines (+315/-32) 4 files modified
tests/platform/linux/test_unity.py (+108/-0) tests/status/test_aggregator.py (+92/-22) ubuntuone/platform/linux/unity.py (+83/-0) ubuntuone/status/aggregator.py (+32/-10) |
To merge this branch: | bzr merge lp:~alecu/ubuntuone-client/use-libunity |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Manuel de la Peña (community) | Approve | ||
Roberto Alsina (community) | Approve | ||
Review via email: mp+50632@code.launchpad.net |
Commit message
Show/update/hide the progressbar, and show/hide the emblem in the Unity icon launcher (Bug #702116)
Description of the change
Show/update/hide the progressbar, and show/hide the emblem in the Unity icon launcher (Bug #702116)
- 884. By Alejandro J. Cura
-
do not use libunity if not installed.
Manuel de la Peña (mandel) wrote : | # |
I do not know if this is related with my system, but when running make check I get the following:
Making check in data
make[1]: Entering directory `/home/
make[1]: Nothing to be done for `check'.
make[1]: Leaving directory `/home/
Making check in libsyncdaemon
make[1]: Entering directory `/home/
make[1]: Leaving directory `/home/
Making check in nautilus
make[1]: Entering directory `/home/
make[1]: Nothing to be done for `check'.
make[1]: Leaving directory `/home/
Making check in po
make[1]: Entering directory `/home/
rm -f missing notexist
srcdir=. /usr/bin/
if [ -r missing -o -r notexist ]; then \
exit 1; \
fi
make[1]: Leaving directory `/home/
Making check in gsd-plugin
make[1]: Entering directory `/home/
make[1]: Nothing to be done for `check'.
make[1]: Leaving directory `/home/
Making check in docs
make[1]: Entering directory `/home/
Making check in reference
make[2]: Entering directory `/home/
make[2]: Nothing to be done for `check'.
make[2]: Leaving directory `/home/
make[2]: Entering directory `/home/
make[2]: Nothing to be done for `check-am'.
make[2]: Leaving directory `/home/
make[1]: Leaving directory `/home/
make[1]: Entering directory `/home/
sed -e 's|\@localedir\
-e 's|\@libexecdir
-e 's|\@GETTEXT_
-e 's|\@SSO_
-e 's|\@SSO_TC_URL\@|https:/
-e 's|\@SSO_
-e 's|\@VERSION\
if test "x." != "x."; then \
if [ ! -e pylintrc -a ! -h pylintrc ]; then \
ln -s ./pylintrc; \
fi; \
fi
make -C data logging.conf
make[2]: Entering directory `/home/
make[2]: `logging.conf' is up to date.
make[2]: Leaving directory `/home/
make[1]: Leaving directory `/home/
if test "x." != "x."; then \
if [ ! -e pylintrc -a ! -h pylintrc ]; then \
ln -s ./pylintrc; \
fi; \
fi
PYTHONPATH=
make -C data logging.conf
make[1]: Entering directory `/home/mandel/Pr...
Manuel de la Peña (mandel) wrote : | # |
Approved as discussed on irc.
Preview Diff
1 | === added file 'tests/platform/linux/test_unity.py' |
2 | --- tests/platform/linux/test_unity.py 1970-01-01 00:00:00 +0000 |
3 | +++ tests/platform/linux/test_unity.py 2011-02-21 22:33:34 +0000 |
4 | @@ -0,0 +1,108 @@ |
5 | +# tests.platform.linux.test_unity |
6 | +# |
7 | +# Author: Alejandro J. Cura <alecu@canonical.com> |
8 | +# |
9 | +# Copyright 2011 Canonical Ltd. |
10 | +# |
11 | +# This program is free software: you can redistribute it and/or modify it |
12 | +# under the terms of the GNU General Public License version 3, as published |
13 | +# by the Free Software Foundation. |
14 | +# |
15 | +# This program is distributed in the hope that it will be useful, but |
16 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
17 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
18 | +# PURPOSE. See the GNU General Public License for more details. |
19 | +# |
20 | +# You should have received a copy of the GNU General Public License along |
21 | +# with this program. If not, see <http://www.gnu.org/licenses/>. |
22 | + |
23 | +"""Tests for the libunity interface.""" |
24 | + |
25 | +from twisted.trial.unittest import TestCase |
26 | + |
27 | +from ubuntuone.platform.linux import unity |
28 | + |
29 | + |
30 | +class FakeLauncherEntryProps(object): |
31 | + """A fake Unity.LauncherEntry.props""" |
32 | + |
33 | + progress = 0.0 |
34 | + progress_visible = False |
35 | + emblem = None |
36 | + emblem_visible = False |
37 | + |
38 | + |
39 | +class FakeLauncherEntry(object): |
40 | + """A fake Unity.LauncherEntry""" |
41 | + |
42 | + @staticmethod |
43 | + def get_for_desktop_id(dotdesktop): |
44 | + """Find the LauncherEntry for a given dotdesktop.""" |
45 | + return FakeLauncherEntry() |
46 | + |
47 | + def __init__(self): |
48 | + """Initialize this fake instance.""" |
49 | + self.props = FakeLauncherEntryProps() |
50 | + |
51 | + |
52 | +class FakeThemedIcon(object): |
53 | + """A fake gio.ThemedIcon.""" |
54 | + |
55 | + def __init__(self, name): |
56 | + """Initialize this fake instance.""" |
57 | + self.name = name |
58 | + |
59 | + |
60 | +class LauncherProgressbarEmblemTestCase(TestCase): |
61 | + """Test the Launcher progressbar and emblem.""" |
62 | + |
63 | + skip = None if unity.use_libunity else "libunity not installed." |
64 | + |
65 | + def setUp(self): |
66 | + """Initialize this test instance.""" |
67 | + self.patch(unity.Unity, "LauncherEntry", FakeLauncherEntry) |
68 | + self.patch(unity.gio, "ThemedIcon", FakeThemedIcon) |
69 | + self.launcher = unity.UbuntuOneLauncher() |
70 | + |
71 | + def test_progress_starts_hidden(self): |
72 | + """The progressbar starts hidden.""" |
73 | + self.assertFalse(self.launcher.entry.props.progress_visible, |
74 | + "The progressbar starts hidden.") |
75 | + |
76 | + def test_progress_shown(self): |
77 | + """The progressbar is shown.""" |
78 | + self.launcher.show_progressbar() |
79 | + self.assertTrue(self.launcher.entry.props.progress_visible, |
80 | + "The progressbar is shown.") |
81 | + |
82 | + def test_progress_hidden_after_shown(self): |
83 | + """The progressbar is hidden after being shown.""" |
84 | + self.launcher.show_progressbar() |
85 | + self.launcher.hide_progressbar() |
86 | + self.assertFalse(self.launcher.entry.props.progress_visible, |
87 | + "The progressbar is hidden.") |
88 | + |
89 | + def test_progress_is_updated(self): |
90 | + """The progress value is updated.""" |
91 | + value = 0.5 |
92 | + self.launcher.set_progress(value) |
93 | + self.assertEqual(self.launcher.entry.props.progress, value) |
94 | + |
95 | + def test_warning_emblem_made_visible(self): |
96 | + """The emblem is made visible.""" |
97 | + self.launcher.show_warning_emblem() |
98 | + self.assertTrue(self.launcher.entry.props.emblem_visible, |
99 | + "The emblem is made visible.") |
100 | + |
101 | + def test_right_emblem_displayed(self): |
102 | + """The right emblem is displayed.""" |
103 | + emblem_name = unity.EMBLEM_IMPORTANT |
104 | + self.launcher.show_warning_emblem() |
105 | + self.assertEqual(self.launcher.entry.props.emblem.name, emblem_name) |
106 | + |
107 | + def test_emblem_hidden_after_shown(self): |
108 | + """The emblem is hidden after being shown.""" |
109 | + self.launcher.show_warning_emblem() |
110 | + self.launcher.hide_emblem() |
111 | + self.assertFalse(self.launcher.entry.props.emblem_visible, |
112 | + "The emblem is hidden.") |
113 | |
114 | === modified file 'tests/status/test_aggregator.py' |
115 | --- tests/status/test_aggregator.py 2011-02-17 13:11:11 +0000 |
116 | +++ tests/status/test_aggregator.py 2011-02-21 22:33:34 +0000 |
117 | @@ -606,11 +606,41 @@ |
118 | self.assertEqual(1, len(self.bubble.notification.notifications_shown)) |
119 | |
120 | |
121 | +class FakeLauncher(object): |
122 | + """A fake UbuntuOneLauncher.""" |
123 | + |
124 | + progress_visible = False |
125 | + progress = 0.0 |
126 | + emblem_visible = False |
127 | + emblem = None |
128 | + |
129 | + def show_progressbar(self): |
130 | + """The progressbar is shown.""" |
131 | + self.progress_visible = True |
132 | + |
133 | + def hide_progressbar(self): |
134 | + """The progressbar is hidden.""" |
135 | + self.progress_visible = False |
136 | + |
137 | + def set_progress(self, value): |
138 | + """The progressbar value is changed.""" |
139 | + self.progress = value |
140 | + |
141 | + def show_warning_emblem(self): |
142 | + """Show a warning emblem.""" |
143 | + self.emblem_visible = True |
144 | + |
145 | + def hide_emblem(self): |
146 | + """Hide the current emblem.""" |
147 | + self.emblem_visible = False |
148 | + |
149 | + |
150 | class ProgressBarTestCase(TestCase): |
151 | """Tests for the progress bar.""" |
152 | |
153 | def setUp(self): |
154 | """Initialize this test instance.""" |
155 | + self.patch(aggregator, "UbuntuOneLauncher", FakeLauncher) |
156 | self.clock = PatchedClock() |
157 | self.bar = aggregator.ProgressBar(clock=self.clock) |
158 | self.addCleanup(self.bar.cleanup) |
159 | @@ -619,7 +649,7 @@ |
160 | |
161 | def fake_timeout(result): |
162 | """A fake _timeout method.""" |
163 | - self.timeout_calls.append(self.bar.percentage) |
164 | + self.timeout_calls.append(self.bar.progress) |
165 | original_timeout(result) |
166 | |
167 | self.patch(self.bar, "_timeout", fake_timeout) |
168 | @@ -628,11 +658,12 @@ |
169 | """The progress bar is shown when progress is made.""" |
170 | self.bar.progress_made(50, 100) |
171 | self.assertTrue(self.bar.visible) |
172 | + self.assertTrue(self.bar.launcher.progress_visible) |
173 | |
174 | def test_progress_made_updates_counter(self): |
175 | """Progress made updates the counter.""" |
176 | self.bar.progress_made(50, 100) |
177 | - self.assertEqual(self.bar.percentage, 50.0) |
178 | + self.assertEqual(self.bar.progress, 0.5) |
179 | |
180 | def test_no_timer_set_initially(self): |
181 | """There's no timer set initially.""" |
182 | @@ -643,16 +674,24 @@ |
183 | self.bar.progress_made(50, 100) |
184 | self.assertNotEqual(self.bar.timer, None) |
185 | |
186 | + def test_cleanup_resets_timer(self): |
187 | + """The cleanup method resets the timer.""" |
188 | + self.bar.progress_made(50, 100) |
189 | + self.bar.cleanup() |
190 | + self.assertEqual(self.bar.timer, None) |
191 | + |
192 | def test_progress_made_not_updated_initially(self): |
193 | """Progress made is not updated initially.""" |
194 | self.bar.progress_made(50, 100) |
195 | self.assertEqual(0, len(self.timeout_calls)) |
196 | + self.assertEqual(0.0, self.bar.launcher.progress) |
197 | |
198 | def test_progress_made_updated_after_a_delay(self): |
199 | """The progressbar is updated after a delay.""" |
200 | self.bar.progress_made(50, 100) |
201 | self.clock.advance(aggregator.ProgressBar.updates_delay) |
202 | - self.assertIn(50.0, self.timeout_calls) |
203 | + self.assertIn(0.5, self.timeout_calls) |
204 | + self.assertEqual(0.5, self.bar.launcher.progress) |
205 | |
206 | def test_progress_updates_are_aggregated(self): |
207 | """The progressbar is updated after a delay.""" |
208 | @@ -666,8 +705,10 @@ |
209 | """The progressbar updates are continuous.""" |
210 | self.bar.progress_made(50, 100) |
211 | self.clock.advance(aggregator.ProgressBar.updates_delay) |
212 | + self.assertEqual(0.5, self.bar.launcher.progress) |
213 | self.bar.progress_made(60, 100) |
214 | self.clock.advance(aggregator.ProgressBar.updates_delay) |
215 | + self.assertEqual(0.6, self.bar.launcher.progress) |
216 | self.assertEqual(2, len(self.timeout_calls)) |
217 | |
218 | def test_hidden_when_completed(self): |
219 | @@ -675,18 +716,21 @@ |
220 | self.bar.progress_made(50, 100) |
221 | self.bar.completed() |
222 | self.assertFalse(self.bar.visible) |
223 | - |
224 | - def test_disable(self): |
225 | - """The bar pulse is disabled.""" |
226 | - self.bar.enable() |
227 | - self.bar.disable() |
228 | - self.assertFalse(self.bar.pulsating) |
229 | - |
230 | - def test_enable(self): |
231 | - """The bar pulse is enabled.""" |
232 | - self.bar.disable() |
233 | - self.bar.enable() |
234 | - self.assertTrue(self.bar.pulsating) |
235 | + self.assertFalse(self.bar.launcher.progress_visible) |
236 | + |
237 | + def test_show_warning_emblem(self): |
238 | + """The warning emblem is shown.""" |
239 | + self.bar.hide_emblem() |
240 | + self.bar.show_warning_emblem() |
241 | + self.assertTrue(self.bar.emblem_visible) |
242 | + self.assertTrue(self.bar.launcher.emblem_visible) |
243 | + |
244 | + def test_hide_emblem(self): |
245 | + """The emblem is hidden.""" |
246 | + self.bar.show_warning_emblem() |
247 | + self.bar.hide_emblem() |
248 | + self.assertFalse(self.bar.emblem_visible) |
249 | + self.assertFalse(self.bar.launcher.emblem_visible) |
250 | |
251 | |
252 | class FakeDelayedBuffer(object): |
253 | @@ -734,6 +778,7 @@ |
254 | """Initialize this fake instance.""" |
255 | self.queued_commands = set() |
256 | self.notification_switch = aggregator.NotificationSwitch() |
257 | + self.connected = False |
258 | |
259 | def queue_done(self): |
260 | """The queue completed all operations.""" |
261 | @@ -756,6 +801,14 @@ |
262 | upload_started = misc_command_queued |
263 | upload_finished = misc_command_unqueued |
264 | |
265 | + def connection_made(self): |
266 | + """The client made the connection to the server.""" |
267 | + self.connected = True |
268 | + |
269 | + def connection_lost(self): |
270 | + """The client lost the connection to the server.""" |
271 | + self.connected = False |
272 | + |
273 | |
274 | class StatusFrontendTestCase(BaseTwistedTestCase): |
275 | """Test the status frontend.""" |
276 | @@ -937,6 +990,7 @@ |
277 | |
278 | def test_server_connection_lost(self): |
279 | """The client connected to the server.""" |
280 | + self.status_frontend.aggregator.connected = True |
281 | self.listener.handle_SYS_CONNECTION_LOST() |
282 | self.assertEqual( |
283 | 1, len(self.status_frontend.notification.notifications_shown)) |
284 | @@ -944,9 +998,11 @@ |
285 | (aggregator.UBUNTUONE_TITLE, |
286 | aggregator.ConnectionLostStatus.MESSAGE_ONE, None, False), |
287 | self.status_frontend.notification.notifications_shown[0]) |
288 | + self.assertFalse(self.status_frontend.aggregator.connected) |
289 | |
290 | def test_server_connection_made(self): |
291 | """The client connected to the server.""" |
292 | + self.status_frontend.aggregator.connected = False |
293 | self.listener.handle_SYS_CONNECTION_MADE() |
294 | self.assertEqual( |
295 | 1, len(self.status_frontend.notification.notifications_shown)) |
296 | @@ -954,6 +1010,7 @@ |
297 | (aggregator.UBUNTUONE_TITLE, |
298 | aggregator.ConnectionMadeStatus.MESSAGE_ONE, None, False), |
299 | self.status_frontend.notification.notifications_shown[0]) |
300 | + self.assertTrue(self.status_frontend.aggregator.connected) |
301 | |
302 | def test_set_show_all_notifications(self): |
303 | """Test the set_show_all_notifications method.""" |
304 | @@ -1148,6 +1205,9 @@ |
305 | FakeProgressBubble) |
306 | self.patch(aggregator, "FinalStatusBubble", |
307 | FakeFinalBubble) |
308 | + self.patch(aggregator, "ToggleableNotification", |
309 | + FakeNotificationSingleton()) |
310 | + self.patch(aggregator, "UbuntuOneLauncher", FakeLauncher) |
311 | self.status_frontend = aggregator.StatusFrontend() |
312 | self.aggregator = self.status_frontend.aggregator |
313 | self.fake_bubble = self.aggregator.file_discovery_bubble |
314 | @@ -1192,7 +1252,7 @@ |
315 | fc = FakeCommand() |
316 | self.status_frontend.queue_added(fc) |
317 | self.assertMiscCommandQueued(fc) |
318 | - self.assertEqual(0, self.aggregator.progress_bar.percentage) |
319 | + self.assertEqual(0, self.aggregator.progress_bar.progress) |
320 | |
321 | def test_misc_command_unqueue(self): |
322 | """Test that a misc command was unqueued.""" |
323 | @@ -1200,7 +1260,7 @@ |
324 | self.status_frontend.queue_added(fc) |
325 | self.status_frontend.queue_removed(fc) |
326 | self.assertMiscCommandUnqueued(fc) |
327 | - self.assertEqual(100.0, self.aggregator.progress_bar.percentage) |
328 | + self.assertEqual(1.0, self.aggregator.progress_bar.progress) |
329 | |
330 | def test_file_download_started(self): |
331 | """Test that a file has started download.""" |
332 | @@ -1355,9 +1415,19 @@ |
333 | self.status_frontend.upload_started(fc) |
334 | self.aggregator.queue_done() |
335 | self.assertStatusReset() |
336 | - self.assertEqual(0.0, self.aggregator.progress_bar.percentage) |
337 | + self.assertEqual(0.0, self.aggregator.progress_bar.progress) |
338 | self.assertFalse(self.aggregator.progress_bar.visible) |
339 | |
340 | + def test_connection_lost(self): |
341 | + """The connection to the server was lost.""" |
342 | + self.status_frontend.server_connection_lost() |
343 | + self.assertTrue(self.aggregator.progress_bar.emblem_visible) |
344 | + |
345 | + def test_connection_made(self): |
346 | + """The connection to the server was made.""" |
347 | + self.status_frontend.server_connection_made() |
348 | + self.assertFalse(self.aggregator.progress_bar.emblem_visible) |
349 | + |
350 | |
351 | class StatusGrouperTestCase(TestCase): |
352 | """Tests for the group_statuses function.""" |
353 | @@ -1411,7 +1481,7 @@ |
354 | sf.download_started(download) |
355 | self.assertEqual(1, len(notifications_shown)) |
356 | # the progress still is zero |
357 | - self.assertEqual(0.0, sf.aggregator.progress_bar.percentage) |
358 | + self.assertEqual(0.0, sf.aggregator.progress_bar.progress) |
359 | clock.advance(aggregator.FileDiscoveryUpdateState.updates_delay) |
360 | # files count update |
361 | self.assertEqual(2, len(notifications_shown)) |
362 | @@ -1425,7 +1495,7 @@ |
363 | self.assertEqual(3, len(notifications_shown)) |
364 | sf.upload_finished(download) |
365 | # the progress still is now 100% |
366 | - self.assertEqual(100.0, sf.aggregator.progress_bar.percentage) |
367 | + self.assertEqual(1.0, sf.aggregator.progress_bar.progress) |
368 | # progress, but the progress bubble is not updated immediately |
369 | self.assertEqual(3, len(notifications_shown)) |
370 | clock.advance(aggregator.ProgressBubble.sleep_delay) |
371 | @@ -1463,7 +1533,7 @@ |
372 | sf.download_started(download) |
373 | self.assertEqual(0, len(notifications_shown)) |
374 | # the progress still is zero |
375 | - self.assertEqual(0.0, sf.aggregator.progress_bar.percentage) |
376 | + self.assertEqual(0.0, sf.aggregator.progress_bar.progress) |
377 | clock.advance(aggregator.FileDiscoveryUpdateState.updates_delay) |
378 | self.assertEqual(0, len(notifications_shown)) |
379 | clock.advance(aggregator.FileDiscoveryUpdateState.updates_timeout - |
380 | @@ -1475,7 +1545,7 @@ |
381 | self.assertEqual(0, len(notifications_shown)) |
382 | sf.upload_finished(download) |
383 | # the progress still is now 100% |
384 | - self.assertEqual(100.0, sf.aggregator.progress_bar.percentage) |
385 | + self.assertEqual(1.0, sf.aggregator.progress_bar.progress) |
386 | self.assertEqual(0, len(notifications_shown)) |
387 | clock.advance(aggregator.ProgressBubble.sleep_delay) |
388 | self.assertEqual(0, len(notifications_shown)) |
389 | |
390 | === added file 'ubuntuone/platform/linux/unity.py' |
391 | --- ubuntuone/platform/linux/unity.py 1970-01-01 00:00:00 +0000 |
392 | +++ ubuntuone/platform/linux/unity.py 2011-02-21 22:33:34 +0000 |
393 | @@ -0,0 +1,83 @@ |
394 | +# ubuntuone.platform.linux.unity |
395 | +# |
396 | +# Author: Alejandro J. Cura <alecu@canonical.com> |
397 | +# |
398 | +# Copyright 2011 Canonical Ltd. |
399 | +# |
400 | +# This program is free software: you can redistribute it and/or modify it |
401 | +# under the terms of the GNU General Public License version 3, as published |
402 | +# by the Free Software Foundation. |
403 | +# |
404 | +# This program is distributed in the hope that it will be useful, but |
405 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
406 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
407 | +# PURPOSE. See the GNU General Public License for more details. |
408 | +# |
409 | +# You should have received a copy of the GNU General Public License along |
410 | +# with this program. If not, see <http://www.gnu.org/licenses/>. |
411 | +"""Use libunity to show a progressbar and emblems on the launcher icon.""" |
412 | + |
413 | +import gio |
414 | + |
415 | +try: |
416 | + from gi.repository import Unity |
417 | + use_libunity = True |
418 | +except ImportError: |
419 | + use_libunity = False |
420 | + |
421 | +U1_DOTDESKTOP = "ubuntuone-control-panel-gtk.desktop" |
422 | +EMBLEM_IMPORTANT = "emblem-important" |
423 | + |
424 | + |
425 | +class UbuntuOneLauncherUnity(object): |
426 | + """The Ubuntu One launcher icon.""" |
427 | + |
428 | + def __init__(self): |
429 | + """Initialize this instance.""" |
430 | + self.entry = Unity.LauncherEntry.get_for_desktop_id(U1_DOTDESKTOP) |
431 | + |
432 | + def show_progressbar(self): |
433 | + """The progressbar is shown.""" |
434 | + self.entry.props.progress_visible = True |
435 | + |
436 | + def hide_progressbar(self): |
437 | + """The progressbar is hidden.""" |
438 | + self.entry.props.progress_visible = False |
439 | + |
440 | + def set_progress(self, value): |
441 | + """The progressbar value is changed.""" |
442 | + self.entry.props.progress = value |
443 | + |
444 | + def show_warning_emblem(self): |
445 | + """Show a warning emblem.""" |
446 | + self.entry.props.emblem = gio.ThemedIcon(EMBLEM_IMPORTANT) |
447 | + self.entry.props.emblem_visible = True |
448 | + |
449 | + def hide_emblem(self): |
450 | + """Hide the current emblem.""" |
451 | + self.entry.props.emblem_visible = False |
452 | + |
453 | + |
454 | +class DummyLauncher(object): |
455 | + """A dummy launcher icon.""" |
456 | + |
457 | + def __init__(self): |
458 | + """Initialize this instance.""" |
459 | + |
460 | + def show_progressbar(self): |
461 | + """The progressbar is shown.""" |
462 | + |
463 | + def hide_progressbar(self): |
464 | + """The progressbar is hidden.""" |
465 | + |
466 | + def set_progress(self, value): |
467 | + """The progressbar value is changed.""" |
468 | + |
469 | + def show_warning_emblem(self): |
470 | + """Show a warning emblem.""" |
471 | + |
472 | + def hide_emblem(self): |
473 | + """Hide the current emblem.""" |
474 | + |
475 | + |
476 | +UbuntuOneLauncher = UbuntuOneLauncherUnity if use_libunity else DummyLauncher |
477 | |
478 | === modified file 'ubuntuone/status/aggregator.py' |
479 | --- ubuntuone/status/aggregator.py 2011-02-17 13:11:11 +0000 |
480 | +++ ubuntuone/status/aggregator.py 2011-02-21 22:33:34 +0000 |
481 | @@ -27,6 +27,7 @@ |
482 | from ubuntuone.logger import basic_formatter, logging |
483 | from ubuntuone.platform.notification import Notification |
484 | from ubuntuone.platform.messaging import Messaging, open_volumes |
485 | +from ubuntuone.platform.unity import UbuntuOneLauncher |
486 | |
487 | LOG_LEVEL = logging.DEBUG |
488 | logger = logging.getLogger('ubuntuone.status') |
489 | @@ -48,6 +49,7 @@ |
490 | PROGRESS_UPLOADED = "Uploaded %d/%d file(s)." |
491 | PROGRESS_COMPLETED = "%d%% completed." |
492 | |
493 | + |
494 | class ToggleableNotification(object): |
495 | """A controller for notifications that can be turned off.""" |
496 | |
497 | @@ -434,37 +436,45 @@ |
498 | """Update a progressbar no more than 10 times a second.""" |
499 | pulsating = True |
500 | visible = False |
501 | - percentage = 0.0 |
502 | + progress = 0.0 |
503 | updates_delay = 0.1 |
504 | timer = None |
505 | |
506 | def __init__(self, clock=reactor): |
507 | """Initialize this instance.""" |
508 | self.clock = clock |
509 | + self.launcher = UbuntuOneLauncher() |
510 | |
511 | def cleanup(self): |
512 | """Cleanup this instance.""" |
513 | if self.timer: |
514 | self.timer.cleanup() |
515 | - |
516 | - def enable(self): |
517 | - """Enable the pulse on the progressbar.""" |
518 | - self.pulsating = True |
519 | - |
520 | - def disable(self): |
521 | - """Disable the pulse on the progressbar.""" |
522 | - self.pulsating = False |
523 | + self.timer = None |
524 | + |
525 | + def hide_emblem(self): |
526 | + """Hide the emblem on the launcher icon.""" |
527 | + self.emblem_visible = False |
528 | + self.launcher.hide_emblem() |
529 | + |
530 | + def show_warning_emblem(self): |
531 | + """Show the warning emblem on the launcher icon.""" |
532 | + self.emblem_visible = True |
533 | + self.launcher.show_warning_emblem() |
534 | |
535 | def _timeout(self, result): |
536 | """The aggregating timer has expired, so update the UI.""" |
537 | self.timer = None |
538 | + self.launcher.set_progress(self.progress) |
539 | + logger.debug("progressbar updated: %f", self.progress) |
540 | |
541 | def progress_made(self, steps_done, steps_total): |
542 | """Steps amount changed. Set up a timer if one not ticking.""" |
543 | assert steps_total > 0 |
544 | - self.percentage = 100.0 * float(steps_done) / float(steps_total) |
545 | + self.progress = float(steps_done) / float(steps_total) |
546 | if not self.visible: |
547 | self.visible = True |
548 | + self.launcher.show_progressbar() |
549 | + logger.debug("progressbar shown") |
550 | if not self.timer: |
551 | self.timer = Timer(self.updates_delay, clock=self.clock) |
552 | self.timer.addCallback(self._timeout) |
553 | @@ -473,6 +483,8 @@ |
554 | """All has completed.""" |
555 | self.cleanup() |
556 | self.visible = False |
557 | + self.launcher.hide_progressbar() |
558 | + logger.debug("progressbar hidden") |
559 | |
560 | |
561 | class FinalStatusBubble(object): |
562 | @@ -636,6 +648,14 @@ |
563 | self.upload_done += 1 |
564 | self.misc_command_unqueued(command) |
565 | |
566 | + def connection_lost(self): |
567 | + """The connection to the server was lost.""" |
568 | + self.progress_bar.show_warning_emblem() |
569 | + |
570 | + def connection_made(self): |
571 | + """The connection to the server was made.""" |
572 | + self.progress_bar.hide_emblem() |
573 | + |
574 | |
575 | class StatusFrontend(object): |
576 | """Frontend for the status aggregator, used by the StatusListener.""" |
577 | @@ -712,12 +732,14 @@ |
578 | logger.debug("server connection lost") |
579 | self.notification.send_notification( |
580 | UBUNTUONE_TITLE, ConnectionLostStatus().one()) |
581 | + self.aggregator.connection_lost() |
582 | |
583 | def server_connection_made(self): |
584 | """The client made the connection to the server.""" |
585 | logger.debug("server connection made") |
586 | self.notification.send_notification( |
587 | UBUNTUONE_TITLE, ConnectionMadeStatus().one()) |
588 | + self.aggregator.connection_made() |
589 | |
590 | def set_show_all_notifications(self, value): |
591 | """Set the flag to show all notifications.""" |
+1