Merge lp:~thisfred/ubuntuone-client/filenames-in-notifications into lp:ubuntuone-client
- filenames-in-notifications
- Merge into trunk
Proposed by
Eric Casteleijn
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Eric Casteleijn | ||||
Approved revision: | 916 | ||||
Merged at revision: | 915 | ||||
Proposed branch: | lp:~thisfred/ubuntuone-client/filenames-in-notifications | ||||
Merge into: | lp:ubuntuone-client | ||||
Diff against target: |
505 lines (+183/-98) 2 files modified
tests/status/test_aggregator.py (+101/-59) ubuntuone/status/aggregator.py (+82/-39) |
||||
To merge this branch: | bzr merge lp:~thisfred/ubuntuone-client/filenames-in-notifications | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alejandro J. Cura (community) | Approve | ||
Manuel de la Peña (community) | Approve | ||
Review via email: mp+52483@code.launchpad.net |
Commit message
Added a filename in the downloading/
Description of the change
Added a filename in the downloading/
Looks like:
"'foo.bar' was downloaded to your computer."
or:
"'baz.qux' and 796 other files are uploading to your personal cloud."
To post a comment you must log in.
Revision history for this message
Eric Casteleijn (thisfred) wrote : | # |
yeah, everything that is not under platform should be agnostic, so let's fix that.
- 914. By Eric Casteleijn
-
keep state in the right place
- 915. By Eric Casteleijn
-
move property settings outside of __init__ and escape warnings
- 916. By Eric Casteleijn
-
added assertions for the filenames being set
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'tests/status/test_aggregator.py' | |||
2 | --- tests/status/test_aggregator.py 2011-03-03 23:29:37 +0000 | |||
3 | +++ tests/status/test_aggregator.py 2011-03-09 20:40:33 +0000 | |||
4 | @@ -31,6 +31,9 @@ | |||
5 | 31 | from ubuntuone.syncdaemon import status_listener | 31 | from ubuntuone.syncdaemon import status_listener |
6 | 32 | from ubuntuone.syncdaemon.volume_manager import Share, UDF | 32 | from ubuntuone.syncdaemon.volume_manager import Share, UDF |
7 | 33 | 33 | ||
8 | 34 | FILENAME = 'example.txt' | ||
9 | 35 | FILENAME2 = 'another_example.mp3' | ||
10 | 36 | |||
11 | 34 | 37 | ||
12 | 35 | class PatchedClock(Clock): | 38 | class PatchedClock(Clock): |
13 | 36 | """Patch the clock to fix twisted bug #4823.""" | 39 | """Patch the clock to fix twisted bug #4823.""" |
14 | @@ -746,6 +749,9 @@ | |||
15 | 746 | class FakeCommand(object): | 749 | class FakeCommand(object): |
16 | 747 | """A fake command.""" | 750 | """A fake command.""" |
17 | 748 | 751 | ||
18 | 752 | def __init__(self, path=''): | ||
19 | 753 | self.path = path | ||
20 | 754 | |||
21 | 749 | 755 | ||
22 | 750 | class FakeVolumeManager(object): | 756 | class FakeVolumeManager(object): |
23 | 751 | """A fake vm.""" | 757 | """A fake vm.""" |
24 | @@ -767,6 +773,8 @@ | |||
25 | 767 | self.queued_commands = set() | 773 | self.queued_commands = set() |
26 | 768 | self.notification_switch = aggregator.NotificationSwitch() | 774 | self.notification_switch = aggregator.NotificationSwitch() |
27 | 769 | self.connected = False | 775 | self.connected = False |
28 | 776 | self.files_uploading = [] | ||
29 | 777 | self.files_downloading = [] | ||
30 | 770 | 778 | ||
31 | 771 | def queue_done(self): | 779 | def queue_done(self): |
32 | 772 | """The queue completed all operations.""" | 780 | """The queue completed all operations.""" |
33 | @@ -784,18 +792,35 @@ | |||
34 | 784 | """Create a new toggleable notification object.""" | 792 | """Create a new toggleable notification object.""" |
35 | 785 | return self.notification_switch.build_notification() | 793 | return self.notification_switch.build_notification() |
36 | 786 | 794 | ||
41 | 787 | download_started = misc_command_queued | 795 | def download_started(self, command): |
42 | 788 | download_finished = misc_command_unqueued | 796 | """A download just started.""" |
43 | 789 | upload_started = misc_command_queued | 797 | self.files_downloading.append(command) |
44 | 790 | upload_finished = misc_command_unqueued | 798 | self.misc_command_queued(command) |
45 | 799 | |||
46 | 800 | def download_finished(self, command): | ||
47 | 801 | """A download just finished.""" | ||
48 | 802 | if command in self.files_downloading: | ||
49 | 803 | self.files_downloading.remove(command) | ||
50 | 804 | self.misc_command_unqueued(command) | ||
51 | 805 | |||
52 | 806 | def upload_started(self, command): | ||
53 | 807 | """An upload just started.""" | ||
54 | 808 | self.files_uploading.append(command) | ||
55 | 809 | self.misc_command_queued(command) | ||
56 | 810 | |||
57 | 811 | def upload_finished(self, command): | ||
58 | 812 | """An upload just finished.""" | ||
59 | 813 | if command in self.files_uploading: | ||
60 | 814 | self.files_uploading.remove(command) | ||
61 | 815 | self.misc_command_unqueued(command) | ||
62 | 791 | 816 | ||
63 | 792 | def connection_made(self): | 817 | def connection_made(self): |
66 | 793 | """The client made the connection to the server.""" | 818 | """The client made the connection to the server.""" |
67 | 794 | self.connected = True | 819 | self.connected = True |
68 | 795 | 820 | ||
69 | 796 | def connection_lost(self): | 821 | def connection_lost(self): |
72 | 797 | """The client lost the connection to the server.""" | 822 | """The client lost the connection to the server.""" |
73 | 798 | self.connected = False | 823 | self.connected = False |
74 | 799 | 824 | ||
75 | 800 | 825 | ||
76 | 801 | class StatusFrontendTestCase(BaseTwistedTestCase): | 826 | class StatusFrontendTestCase(BaseTwistedTestCase): |
77 | @@ -1255,9 +1280,11 @@ | |||
78 | 1255 | 1280 | ||
79 | 1256 | def test_file_download_started(self): | 1281 | def test_file_download_started(self): |
80 | 1257 | """Test that a file has started download.""" | 1282 | """Test that a file has started download.""" |
82 | 1258 | fc = FakeCommand() | 1283 | fc = FakeCommand(path='testfile.txt') |
83 | 1284 | self.assertEqual('', self.aggregator.downloading_filename) | ||
84 | 1259 | self.status_frontend.download_started(fc) | 1285 | self.status_frontend.download_started(fc) |
86 | 1260 | self.assertEqual(self.aggregator.download_total, 1) | 1286 | self.assertEqual(1, self.aggregator.download_total) |
87 | 1287 | self.assertEqual('testfile.txt', self.aggregator.downloading_filename) | ||
88 | 1261 | self.assertMiscCommandQueued(fc) | 1288 | self.assertMiscCommandQueued(fc) |
89 | 1262 | self.assertEqual(1, self.fake_bubble.count) | 1289 | self.assertEqual(1, self.fake_bubble.count) |
90 | 1263 | 1290 | ||
91 | @@ -1271,9 +1298,11 @@ | |||
92 | 1271 | 1298 | ||
93 | 1272 | def test_file_upload_started(self): | 1299 | def test_file_upload_started(self): |
94 | 1273 | """Test that a file has started upload.""" | 1300 | """Test that a file has started upload.""" |
96 | 1274 | fc = FakeCommand() | 1301 | fc = FakeCommand(path='testfile.txt') |
97 | 1302 | self.assertEqual('', self.aggregator.uploading_filename) | ||
98 | 1275 | self.status_frontend.upload_started(fc) | 1303 | self.status_frontend.upload_started(fc) |
100 | 1276 | self.assertEqual(self.aggregator.upload_total, 1) | 1304 | self.assertEqual(1, self.aggregator.upload_total) |
101 | 1305 | self.assertEqual('testfile.txt', self.aggregator.uploading_filename) | ||
102 | 1277 | self.assertMiscCommandQueued(fc) | 1306 | self.assertMiscCommandQueued(fc) |
103 | 1278 | self.assertEqual(1, self.fake_bubble.count) | 1307 | self.assertEqual(1, self.fake_bubble.count) |
104 | 1279 | 1308 | ||
105 | @@ -1289,10 +1318,18 @@ | |||
106 | 1289 | """Test the message that's shown on the discovery bubble.""" | 1318 | """Test the message that's shown on the discovery bubble.""" |
107 | 1290 | uploading = 10 | 1319 | uploading = 10 |
108 | 1291 | downloading = 8 | 1320 | downloading = 8 |
113 | 1292 | self.aggregator.files_uploading.extend(range(uploading)) | 1321 | filename = 'upfile0.ext' |
114 | 1293 | self.aggregator.files_downloading.extend(range(downloading)) | 1322 | filename2 = 'downfile0.ext' |
115 | 1294 | expected = (aggregator.files_being_uploaded(uploading) + | 1323 | self.aggregator.files_uploading.extend([ |
116 | 1295 | "\n" + aggregator.files_being_downloaded(downloading)) | 1324 | FakeCommand(path='upfile%d.ext' % n) for n in range(uploading)]) |
117 | 1325 | self.aggregator.uploading_filename = filename | ||
118 | 1326 | self.aggregator.files_downloading.extend([ | ||
119 | 1327 | FakeCommand(path='downfile%d.ext' % n) for n in | ||
120 | 1328 | range(downloading)]) | ||
121 | 1329 | self.aggregator.downloading_filename = filename2 | ||
122 | 1330 | expected = ( | ||
123 | 1331 | aggregator.files_being_uploaded(filename, uploading) + "\n" + | ||
124 | 1332 | aggregator.files_being_downloaded(filename2, downloading)) | ||
125 | 1296 | result = self.aggregator.get_discovery_message() | 1333 | result = self.aggregator.get_discovery_message() |
126 | 1297 | self.assertEqual(expected, result) | 1334 | self.assertEqual(expected, result) |
127 | 1298 | 1335 | ||
128 | @@ -1300,44 +1337,44 @@ | |||
129 | 1300 | """Test the message that's shown on the progress bubble.""" | 1337 | """Test the message that's shown on the progress bubble.""" |
130 | 1301 | self.aggregator.upload_done = 5 | 1338 | self.aggregator.upload_done = 5 |
131 | 1302 | self.aggregator.upload_total = 10 | 1339 | self.aggregator.upload_total = 10 |
132 | 1340 | self.aggregator.uploading_filename = FILENAME | ||
133 | 1303 | self.aggregator.download_done = 3 | 1341 | self.aggregator.download_done = 3 |
134 | 1304 | self.aggregator.download_total = 8 | 1342 | self.aggregator.download_total = 8 |
135 | 1343 | self.aggregator.downloading_filename = FILENAME2 | ||
136 | 1305 | self.aggregator.done_counter = 9 | 1344 | self.aggregator.done_counter = 9 |
137 | 1306 | self.aggregator.total_counter = 20 | 1345 | self.aggregator.total_counter = 20 |
138 | 1307 | percentage = int(100.0 * self.aggregator.done_counter / | 1346 | percentage = int(100.0 * self.aggregator.done_counter / |
139 | 1308 | self.aggregator.total_counter) | 1347 | self.aggregator.total_counter) |
151 | 1309 | format_args = { | 1348 | |
152 | 1310 | "percentage_completed": percentage, | 1349 | expected = ( |
153 | 1311 | } | 1350 | aggregator.files_being_uploaded( |
154 | 1312 | 1351 | FILENAME, self.aggregator.upload_total) + "\n" + | |
155 | 1313 | format_string = ( | 1352 | aggregator.files_being_downloaded( |
156 | 1314 | aggregator.files_being_uploaded(self.aggregator.upload_total) + | 1353 | FILENAME2, self.aggregator.download_total) + "\n" + |
157 | 1315 | "\n" + | 1354 | aggregator.PROGRESS_COMPLETED) % { |
158 | 1316 | aggregator.files_being_downloaded(self.aggregator.download_total) + | 1355 | 'percentage_completed': percentage} |
159 | 1317 | "\n" + aggregator.PROGRESS_COMPLETED) | 1356 | |
149 | 1318 | |||
150 | 1319 | expected = format_string % format_args | ||
160 | 1320 | result = self.aggregator.get_progress_message() | 1357 | result = self.aggregator.get_progress_message() |
161 | 1321 | self.assertEqual(expected, result) | 1358 | self.assertEqual(expected, result) |
162 | 1322 | 1359 | ||
163 | 1323 | def test_get_progress_message_no_uploads(self): | 1360 | def test_get_progress_message_no_uploads(self): |
164 | 1324 | """The progress message when no uploads are going on.""" | 1361 | """The progress message when no uploads are going on.""" |
165 | 1362 | |||
166 | 1325 | self.aggregator.upload_done = 0 | 1363 | self.aggregator.upload_done = 0 |
167 | 1326 | self.aggregator.upload_total = 0 | 1364 | self.aggregator.upload_total = 0 |
168 | 1365 | self.aggregator.downloading_filename = FILENAME | ||
169 | 1327 | self.aggregator.download_done = 3 | 1366 | self.aggregator.download_done = 3 |
170 | 1328 | self.aggregator.download_total = 8 | 1367 | self.aggregator.download_total = 8 |
171 | 1329 | self.aggregator.done_counter = 9 | 1368 | self.aggregator.done_counter = 9 |
172 | 1330 | self.aggregator.total_counter = 20 | 1369 | self.aggregator.total_counter = 20 |
173 | 1331 | percentage = int(100.0 * self.aggregator.done_counter / | 1370 | percentage = int(100.0 * self.aggregator.done_counter / |
174 | 1332 | self.aggregator.total_counter) | 1371 | self.aggregator.total_counter) |
183 | 1333 | format_args = { | 1372 | expected = ( |
184 | 1334 | "percentage_completed": percentage} | 1373 | aggregator.files_being_downloaded( |
185 | 1335 | 1374 | FILENAME, self.aggregator.download_total) + "\n" + | |
186 | 1336 | format_string = ( | 1375 | aggregator.PROGRESS_COMPLETED) % { |
187 | 1337 | aggregator.files_being_downloaded(self.aggregator.download_total) + | 1376 | 'percentage_completed': percentage} |
188 | 1338 | "\n" + aggregator.PROGRESS_COMPLETED) | 1377 | |
181 | 1339 | |||
182 | 1340 | expected = format_string % format_args | ||
189 | 1341 | result = self.aggregator.get_progress_message() | 1378 | result = self.aggregator.get_progress_message() |
190 | 1342 | self.assertEqual(expected, result) | 1379 | self.assertEqual(expected, result) |
191 | 1343 | 1380 | ||
192 | @@ -1345,21 +1382,19 @@ | |||
193 | 1345 | """The progress message when no downloads are going on.""" | 1382 | """The progress message when no downloads are going on.""" |
194 | 1346 | self.aggregator.upload_done = 5 | 1383 | self.aggregator.upload_done = 5 |
195 | 1347 | self.aggregator.upload_total = 10 | 1384 | self.aggregator.upload_total = 10 |
196 | 1385 | self.aggregator.uploading_filename = FILENAME | ||
197 | 1348 | self.aggregator.download_done = 0 | 1386 | self.aggregator.download_done = 0 |
198 | 1349 | self.aggregator.download_total = 0 | 1387 | self.aggregator.download_total = 0 |
199 | 1350 | self.aggregator.done_counter = 9 | 1388 | self.aggregator.done_counter = 9 |
200 | 1351 | self.aggregator.total_counter = 20 | 1389 | self.aggregator.total_counter = 20 |
201 | 1352 | percentage = int(100.0 * self.aggregator.done_counter / | 1390 | percentage = int(100.0 * self.aggregator.done_counter / |
202 | 1353 | self.aggregator.total_counter) | 1391 | self.aggregator.total_counter) |
212 | 1354 | format_args = { | 1392 | expected = ( |
213 | 1355 | "percentage_completed": percentage, | 1393 | aggregator.files_being_uploaded( |
214 | 1356 | } | 1394 | FILENAME, self.aggregator.upload_total) + |
215 | 1357 | 1395 | "\n" + aggregator.PROGRESS_COMPLETED) % { | |
216 | 1358 | format_string = ( | 1396 | 'percentage_completed': percentage} |
217 | 1359 | aggregator.files_being_uploaded(self.aggregator.upload_total) + | 1397 | |
209 | 1360 | "\n" + aggregator.PROGRESS_COMPLETED) | ||
210 | 1361 | |||
211 | 1362 | expected = format_string % format_args | ||
218 | 1363 | result = self.aggregator.get_progress_message() | 1398 | result = self.aggregator.get_progress_message() |
219 | 1364 | self.assertEqual(expected, result) | 1399 | self.assertEqual(expected, result) |
220 | 1365 | 1400 | ||
221 | @@ -1371,40 +1406,47 @@ | |||
222 | 1371 | def test_get_final_status_message(self): | 1406 | def test_get_final_status_message(self): |
223 | 1372 | """The final status message.""" | 1407 | """The final status message.""" |
224 | 1373 | done = (5, 10) | 1408 | done = (5, 10) |
225 | 1409 | self.aggregator.uploading_filename = FILENAME | ||
226 | 1410 | self.aggregator.downloading_filename = FILENAME2 | ||
227 | 1374 | self.aggregator.upload_done, self.aggregator.download_done = done | 1411 | self.aggregator.upload_done, self.aggregator.download_done = done |
228 | 1375 | 1412 | ||
230 | 1376 | format_string = ( | 1413 | expected = ( |
231 | 1377 | aggregator.FINAL_COMPLETED + "\n" + | 1414 | aggregator.FINAL_COMPLETED + "\n" + |
235 | 1378 | aggregator.files_were_uploaded(self.aggregator.upload_done) + | 1415 | aggregator.files_were_uploaded( |
236 | 1379 | "\n" + | 1416 | FILENAME, self.aggregator.upload_done) + "\n" + |
237 | 1380 | aggregator.files_were_downloaded(self.aggregator.download_done)) | 1417 | aggregator.files_were_downloaded( |
238 | 1418 | FILENAME2, self.aggregator.download_done)) | ||
239 | 1381 | 1419 | ||
240 | 1382 | result = self.aggregator.get_final_status_message() | 1420 | result = self.aggregator.get_final_status_message() |
242 | 1383 | self.assertEqual(format_string, result) | 1421 | self.assertEqual(expected, result) |
243 | 1384 | 1422 | ||
244 | 1385 | def test_get_final_status_message_no_uploads(self): | 1423 | def test_get_final_status_message_no_uploads(self): |
245 | 1386 | """The final status message when there were no uploads.""" | 1424 | """The final status message when there were no uploads.""" |
246 | 1387 | done = (0, 12) | 1425 | done = (0, 12) |
247 | 1388 | self.aggregator.upload_done, self.aggregator.download_done = done | 1426 | self.aggregator.upload_done, self.aggregator.download_done = done |
248 | 1427 | self.aggregator.downloading_filename = FILENAME2 | ||
249 | 1389 | 1428 | ||
253 | 1390 | format_string = (aggregator.FINAL_COMPLETED + "\n" + | 1429 | expected = ( |
254 | 1391 | aggregator.files_were_downloaded( | 1430 | aggregator.FINAL_COMPLETED + "\n" + |
255 | 1392 | self.aggregator.download_done)) | 1431 | aggregator.files_were_downloaded( |
256 | 1432 | FILENAME2, self.aggregator.download_done)) | ||
257 | 1393 | 1433 | ||
258 | 1394 | result = self.aggregator.get_final_status_message() | 1434 | result = self.aggregator.get_final_status_message() |
260 | 1395 | self.assertEqual(format_string, result) | 1435 | self.assertEqual(expected, result) |
261 | 1396 | 1436 | ||
262 | 1397 | def test_get_final_status_message_no_downloads(self): | 1437 | def test_get_final_status_message_no_downloads(self): |
263 | 1398 | """The final status message when there were no downloads.""" | 1438 | """The final status message when there were no downloads.""" |
264 | 1399 | done = (8, 0) | 1439 | done = (8, 0) |
265 | 1400 | self.aggregator.upload_done, self.aggregator.download_done = done | 1440 | self.aggregator.upload_done, self.aggregator.download_done = done |
266 | 1441 | self.aggregator.uploading_filename = FILENAME | ||
267 | 1401 | 1442 | ||
271 | 1402 | format_string = (aggregator.FINAL_COMPLETED + "\n" + | 1443 | expected = ( |
272 | 1403 | aggregator.files_were_uploaded( | 1444 | aggregator.FINAL_COMPLETED + "\n" + |
273 | 1404 | self.aggregator.upload_done)) | 1445 | aggregator.files_were_uploaded( |
274 | 1446 | FILENAME, self.aggregator.upload_done)) | ||
275 | 1405 | 1447 | ||
276 | 1406 | result = self.aggregator.get_final_status_message() | 1448 | result = self.aggregator.get_final_status_message() |
278 | 1407 | self.assertEqual(format_string, result) | 1449 | self.assertEqual(expected, result) |
279 | 1408 | 1450 | ||
280 | 1409 | def test_started_progress_bubble(self): | 1451 | def test_started_progress_bubble(self): |
281 | 1410 | """The progress bubble is started.""" | 1452 | """The progress bubble is started.""" |
282 | @@ -1490,7 +1532,7 @@ | |||
283 | 1490 | self.patch(aggregator, "UbuntuOneLauncher", FakeLauncher) | 1532 | self.patch(aggregator, "UbuntuOneLauncher", FakeLauncher) |
284 | 1491 | self.patch(aggregator.session, "Inhibitor", FakeInhibitor) | 1533 | self.patch(aggregator.session, "Inhibitor", FakeInhibitor) |
285 | 1492 | clock = PatchedClock() | 1534 | clock = PatchedClock() |
287 | 1493 | upload = FakeCommand() | 1535 | upload = FakeCommand(path='upload.foo') |
288 | 1494 | sf = aggregator.StatusFrontend(clock=clock) | 1536 | sf = aggregator.StatusFrontend(clock=clock) |
289 | 1495 | sf.set_show_all_notifications(True) | 1537 | sf.set_show_all_notifications(True) |
290 | 1496 | 1538 | ||
291 | @@ -1507,7 +1549,7 @@ | |||
292 | 1507 | clock.advance(aggregator.FileDiscoveryGatheringState.initial_delay) | 1549 | clock.advance(aggregator.FileDiscoveryGatheringState.initial_delay) |
293 | 1508 | # files found notification | 1550 | # files found notification |
294 | 1509 | self.assertEqual(1, len(notifications_shown)) | 1551 | self.assertEqual(1, len(notifications_shown)) |
296 | 1510 | download = FakeCommand() | 1552 | download = FakeCommand('download.bar') |
297 | 1511 | sf.download_started(download) | 1553 | sf.download_started(download) |
298 | 1512 | self.assertEqual(1, len(notifications_shown)) | 1554 | self.assertEqual(1, len(notifications_shown)) |
299 | 1513 | # the progress still is zero | 1555 | # the progress still is zero |
300 | 1514 | 1556 | ||
301 | === modified file 'ubuntuone/status/aggregator.py' | |||
302 | --- ubuntuone/status/aggregator.py 2011-03-03 23:29:37 +0000 | |||
303 | +++ ubuntuone/status/aggregator.py 2011-03-09 20:40:33 +0000 | |||
304 | @@ -53,50 +53,72 @@ | |||
305 | 53 | FILE_SYNC_IN_PROGRESS = Q_("File synchronization in progress") | 53 | FILE_SYNC_IN_PROGRESS = Q_("File synchronization in progress") |
306 | 54 | 54 | ||
307 | 55 | 55 | ||
309 | 56 | def files_being_uploaded(files_uploading): | 56 | def files_being_uploaded(filename, files_uploading): |
310 | 57 | """Get the i18n string for files being uploaded.""" | 57 | """Get the i18n string for files being uploaded.""" |
312 | 58 | format_args = {"total_uploading_files": files_uploading} | 58 | other_files = files_uploading - 1 |
313 | 59 | if other_files < 1: | ||
314 | 60 | return Q_( | ||
315 | 61 | "'%(filename)s' is being uploaded to your personal cloud.") % { | ||
316 | 62 | 'filename': filename} | ||
317 | 63 | format_args = { | ||
318 | 64 | "filename": filename, "other_files": other_files} | ||
319 | 59 | return gettext.dngettext( | 65 | return gettext.dngettext( |
320 | 60 | GETTEXT_PACKAGE, | 66 | GETTEXT_PACKAGE, |
329 | 61 | "%(total_uploading_files)d file is being uploaded to your personal " | 67 | "'%(filename)s' and %(other_files)d other file is being " |
330 | 62 | "cloud.", | 68 | "uploaded to your personal cloud.", |
331 | 63 | "%(total_uploading_files)d files are being uploaded to your personal " | 69 | "'%(filename)s' and %(other_files)d other files are being " |
332 | 64 | "cloud.", | 70 | "uploaded to your personal cloud.", other_files) % format_args |
333 | 65 | files_uploading) % format_args | 71 | |
334 | 66 | 72 | ||
335 | 67 | 73 | def files_being_downloaded(filename, files_downloading): | |
328 | 68 | def files_being_downloaded(files_downloading): | ||
336 | 69 | """Get the i18n string for files being downloaded.""" | 74 | """Get the i18n string for files being downloaded.""" |
338 | 70 | format_args = {"total_downloading_files": files_downloading} | 75 | other_files = files_downloading - 1 |
339 | 76 | if other_files < 1: | ||
340 | 77 | return Q_( | ||
341 | 78 | "'%(filename)s' is being downloaded to your computer.") % { | ||
342 | 79 | 'filename': filename} | ||
343 | 80 | format_args = { | ||
344 | 81 | "filename": filename, "other_files": other_files} | ||
345 | 71 | return gettext.dngettext( | 82 | return gettext.dngettext( |
346 | 72 | GETTEXT_PACKAGE, | 83 | GETTEXT_PACKAGE, |
355 | 73 | "%(total_downloading_files)d file is being downloaded to your " | 84 | "'%(filename)s' and %(other_files)d other file is being " |
356 | 74 | "computer.", | 85 | "downloaded to your computer.", |
357 | 75 | "%(total_downloading_files)d files are being downloaded to " | 86 | "'%(filename)s' and %(other_files)d other files are being " |
358 | 76 | "your computer.", | 87 | "downloaded to your computer.", other_files) % format_args |
359 | 77 | files_downloading) % format_args | 88 | |
360 | 78 | 89 | ||
361 | 79 | 90 | def files_were_uploaded(filename, upload_done): | |
354 | 80 | def files_were_uploaded(upload_done): | ||
362 | 81 | """Get the i18n string for files that were uploaded.""" | 91 | """Get the i18n string for files that were uploaded.""" |
364 | 82 | format_args = {'total_uploaded_files': upload_done} | 92 | other_files = upload_done - 1 |
365 | 93 | if other_files < 1: | ||
366 | 94 | return Q_( | ||
367 | 95 | "'%(filename)s' was uploaded to your personal cloud.") % { | ||
368 | 96 | 'filename': filename} | ||
369 | 97 | format_args = { | ||
370 | 98 | 'filename': filename, 'other_files': other_files} | ||
371 | 83 | return gettext.dngettext( | 99 | return gettext.dngettext( |
372 | 84 | GETTEXT_PACKAGE, | 100 | GETTEXT_PACKAGE, |
380 | 85 | "%(total_uploaded_files)d file was uploaded to your personal " | 101 | "'%(filename)s' and %(other_files)d other file was uploaded to " |
381 | 86 | "cloud.", | 102 | "your personal cloud.", |
382 | 87 | "%(total_uploaded_files)d files were uploaded to your " | 103 | "'%(filename)s' and %(other_files)d other files were uploaded " |
383 | 88 | "personal cloud.", upload_done) % format_args | 104 | "to your personal cloud.", other_files) % format_args |
384 | 89 | 105 | ||
385 | 90 | 106 | ||
386 | 91 | def files_were_downloaded(download_done): | 107 | def files_were_downloaded(filename, download_done): |
387 | 92 | """Get the i18n string for files that were downloaded.""" | 108 | """Get the i18n string for files that were downloaded.""" |
389 | 93 | format_args = {'total_downloaded_files': download_done} | 109 | other_files = download_done - 1 |
390 | 110 | if other_files < 1: | ||
391 | 111 | return Q_( | ||
392 | 112 | "'%(filename)s' was downloaded to your computer.") % { | ||
393 | 113 | 'filename': filename} | ||
394 | 114 | format_args = { | ||
395 | 115 | 'filename': filename, 'other_files': other_files} | ||
396 | 94 | return gettext.dngettext( | 116 | return gettext.dngettext( |
397 | 95 | GETTEXT_PACKAGE, | 117 | GETTEXT_PACKAGE, |
402 | 96 | "%(total_downloaded_files)d file was downloaded to your " | 118 | "'%(filename)s' and %(other_files)d other file was " |
403 | 97 | "computer.", | 119 | "downloaded to your computer.", |
404 | 98 | "%(total_downloaded_files)d files were downloaded to your " | 120 | "'%(filename)s' and %(other_files)d other files were " |
405 | 99 | "computer.", download_done) % format_args | 121 | "downloaded to your computer.", other_files) % format_args |
406 | 100 | 122 | ||
407 | 101 | 123 | ||
408 | 102 | class ToggleableNotification(object): | 124 | class ToggleableNotification(object): |
409 | @@ -592,6 +614,7 @@ | |||
410 | 592 | """Create a new toggleable notification object.""" | 614 | """Create a new toggleable notification object.""" |
411 | 593 | return self.notification_switch.build_notification() | 615 | return self.notification_switch.build_notification() |
412 | 594 | 616 | ||
413 | 617 | # pylint: disable=W0201 | ||
414 | 595 | def reset(self): | 618 | def reset(self): |
415 | 596 | """Reset all counters and notifications.""" | 619 | """Reset all counters and notifications.""" |
416 | 597 | self.total_counter = 0 | 620 | self.total_counter = 0 |
417 | @@ -601,7 +624,9 @@ | |||
418 | 601 | self.upload_total = 0 | 624 | self.upload_total = 0 |
419 | 602 | self.upload_done = 0 | 625 | self.upload_done = 0 |
420 | 603 | self.files_uploading = [] | 626 | self.files_uploading = [] |
421 | 627 | self.uploading_filename = '' | ||
422 | 604 | self.files_downloading = [] | 628 | self.files_downloading = [] |
423 | 629 | self.downloading_filename = '' | ||
424 | 605 | 630 | ||
425 | 606 | if self.file_discovery_bubble: | 631 | if self.file_discovery_bubble: |
426 | 607 | self.file_discovery_bubble.cleanup() | 632 | self.file_discovery_bubble.cleanup() |
427 | @@ -615,17 +640,21 @@ | |||
428 | 615 | if self.final_status_bubble: | 640 | if self.final_status_bubble: |
429 | 616 | self.final_status_bubble.cleanup() | 641 | self.final_status_bubble.cleanup() |
430 | 617 | self.final_status_bubble = FinalStatusBubble(self) | 642 | self.final_status_bubble = FinalStatusBubble(self) |
431 | 643 | # pylint: enable=W0201 | ||
432 | 618 | 644 | ||
433 | 619 | def get_discovery_message(self): | 645 | def get_discovery_message(self): |
434 | 620 | """Get the text for the discovery bubble.""" | 646 | """Get the text for the discovery bubble.""" |
435 | 621 | lines = [] | 647 | lines = [] |
436 | 622 | files_uploading = len(self.files_uploading) | 648 | files_uploading = len(self.files_uploading) |
437 | 623 | if files_uploading > 0: | 649 | if files_uploading > 0: |
440 | 624 | lines.append(files_being_uploaded(files_uploading)) | 650 | lines.append(files_being_uploaded( |
441 | 625 | 651 | self.uploading_filename, files_uploading)) | |
442 | 626 | files_downloading = len(self.files_downloading) | 652 | files_downloading = len(self.files_downloading) |
443 | 627 | if files_downloading > 0: | 653 | if files_downloading > 0: |
445 | 628 | lines.append(files_being_downloaded(files_downloading)) | 654 | self.downloading_filename = self.files_downloading[0].path.split( |
446 | 655 | os.path.sep)[-1] | ||
447 | 656 | lines.append(files_being_downloaded( | ||
448 | 657 | self.downloading_filename, files_downloading)) | ||
449 | 629 | return "\n".join(lines) | 658 | return "\n".join(lines) |
450 | 630 | 659 | ||
451 | 631 | def get_progress_message(self): | 660 | def get_progress_message(self): |
452 | @@ -634,10 +663,12 @@ | |||
453 | 634 | parts = [] | 663 | parts = [] |
454 | 635 | upload_total = self.upload_total | 664 | upload_total = self.upload_total |
455 | 636 | if upload_total: | 665 | if upload_total: |
457 | 637 | parts.append(files_being_uploaded(upload_total)) | 666 | parts.append(files_being_uploaded( |
458 | 667 | self.uploading_filename, upload_total)) | ||
459 | 638 | download_total = self.download_total | 668 | download_total = self.download_total |
460 | 639 | if download_total: | 669 | if download_total: |
462 | 640 | parts.append(files_being_downloaded(download_total)) | 670 | parts.append(files_being_downloaded( |
463 | 671 | self.downloading_filename, download_total)) | ||
464 | 641 | progress_percentage = 100.0 * self.done_counter / self.total_counter | 672 | progress_percentage = 100.0 * self.done_counter / self.total_counter |
465 | 642 | format_args = {"percentage_completed": int(progress_percentage)} | 673 | format_args = {"percentage_completed": int(progress_percentage)} |
466 | 643 | parts.append(PROGRESS_COMPLETED % format_args) | 674 | parts.append(PROGRESS_COMPLETED % format_args) |
467 | @@ -649,11 +680,13 @@ | |||
468 | 649 | parts.append(FINAL_COMPLETED) | 680 | parts.append(FINAL_COMPLETED) |
469 | 650 | upload_done = self.upload_done | 681 | upload_done = self.upload_done |
470 | 651 | if upload_done: | 682 | if upload_done: |
472 | 652 | parts.append(files_were_uploaded(upload_done)) | 683 | parts.append(files_were_uploaded( |
473 | 684 | self.uploading_filename, upload_done)) | ||
474 | 653 | 685 | ||
475 | 654 | download_done = self.download_done | 686 | download_done = self.download_done |
476 | 655 | if download_done: | 687 | if download_done: |
478 | 656 | parts.append(files_were_downloaded(download_done)) | 688 | parts.append(files_were_downloaded( |
479 | 689 | self.downloading_filename, download_done)) | ||
480 | 657 | return "\n".join(parts) | 690 | return "\n".join(parts) |
481 | 658 | 691 | ||
482 | 659 | def restart_progress_bubble(self): | 692 | def restart_progress_bubble(self): |
483 | @@ -689,6 +722,11 @@ | |||
484 | 689 | """A download just started.""" | 722 | """A download just started.""" |
485 | 690 | self.files_downloading.append(command) | 723 | self.files_downloading.append(command) |
486 | 691 | self.download_total += 1 | 724 | self.download_total += 1 |
487 | 725 | # pylint: disable=W0201 | ||
488 | 726 | if not self.downloading_filename: | ||
489 | 727 | self.downloading_filename = self.files_downloading[0].path.split( | ||
490 | 728 | os.path.sep)[-1] | ||
491 | 729 | # pylint: enable=W0201 | ||
492 | 692 | self.misc_command_queued(command) | 730 | self.misc_command_queued(command) |
493 | 693 | self.file_discovery_bubble.new_file_found() | 731 | self.file_discovery_bubble.new_file_found() |
494 | 694 | 732 | ||
495 | @@ -703,6 +741,11 @@ | |||
496 | 703 | """An upload just started.""" | 741 | """An upload just started.""" |
497 | 704 | self.files_uploading.append(command) | 742 | self.files_uploading.append(command) |
498 | 705 | self.upload_total += 1 | 743 | self.upload_total += 1 |
499 | 744 | # pylint: disable=W0201 | ||
500 | 745 | if not self.uploading_filename: | ||
501 | 746 | self.uploading_filename = self.files_uploading[0].path.split( | ||
502 | 747 | os.path.sep)[-1] | ||
503 | 748 | # pylint: enable=W0201 | ||
504 | 706 | self.misc_command_queued(command) | 749 | self.misc_command_queued(command) |
505 | 707 | self.file_discovery_bubble.new_file_found() | 750 | self.file_discovery_bubble.new_file_found() |
506 | 708 | 751 |
AFAIK most of the code from the notification is platform anostic, which means that we can reuse the logic when doing the port (and use something else instead of libnotify, is this right? if that is the case, we might have to remove the /n with os.sep. Since the /n were already in the code, I'll approve and will fix it in the windows branch whenever needed.