Merge lp:~chipaca/indicator-ubuntuone/xfer-progress into lp:~rye/indicator-ubuntuone/indicator-python

Proposed by John Lenton
Status: Merged
Approved by: Roman Yepishev
Approved revision: 42
Merged at revision: 41
Proposed branch: lp:~chipaca/indicator-ubuntuone/xfer-progress
Merge into: lp:~rye/indicator-ubuntuone/indicator-python
Diff against target: 127 lines (+57/-2)
2 files modified
ubuntuone-indicator (+36/-1)
ubuntuone_indicator/__init__.py (+21/-1)
To merge this branch: bzr merge lp:~chipaca/indicator-ubuntuone/xfer-progress
Reviewer Review Type Date Requested Status
Roman Yepishev fieldtest Approve
Review via email: mp+43912@code.launchpad.net

Description of the change

A first approach at showing the file xfer progress in the menu.

To post a comment you must log in.
Revision history for this message
Roman Yepishev (rye) wrote :

Awesome!

review: Approve (fieldtest)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone-indicator'
2--- ubuntuone-indicator 2010-12-01 12:00:45 +0000
3+++ ubuntuone-indicator 2010-12-16 15:23:07 +0000
4@@ -19,6 +19,7 @@
5 import dbus
6 import time
7 import gobject
8+import glib
9 import os
10 import sys
11 import gettext
12@@ -94,6 +95,8 @@
13 self.content_estimate = 0
14 self.content_size = 0
15
16+ self.xfer_timer = None
17+
18 def is_already_running(self):
19 """Checks whether our indicator is already running"""
20 if self.bus.name_has_owner(INDICATOR_BUS_NAME):
21@@ -112,7 +115,10 @@
22 source)
23 return
24
25- shutil.copyfile(source, destination)
26+ if not os.path.exists(os.path.dirname(destination)):
27+ os.makedirs(os.path.dirname(destination))
28+
29+ #shutil.copyfile(source, destination)
30
31 def main(self):
32 """Application entry point"""
33@@ -399,11 +405,40 @@
34 self.content_size = self.get_content_queue_size()
35 self.update_estimates()
36 cur_time = time.time()
37+ if count:
38+ if self.xfer_timer is None:
39+ self.xfer_timer = glib.timeout_add_seconds(1, self.update_xfer)
40+ else:
41+ glib.source_remove(self.xfer_timer)
42+ self.xfer_timer = None
43+ self.indicator.xfer_item.hide()
44 if cur_time - self.last_content_size_update >= \
45 Application.CONTENT_QUEUE_UPDATE_INTERVAL:
46 self.last_content_size_update = cur_time
47 self.update_quota_info()
48
49+ def update_xfer(self):
50+ xfer = self.client.get_current_xfer()
51+ if xfer is not None and 'deflated_size' in xfer:
52+ fname = os.path.basename(xfer['path'])
53+ if len(fname) > 30:
54+ fname = fname[:29] + u"\N{HORIZONTAL ELLIPSIS}"
55+
56+ # the indicator menus always use_underlines, so I've got to double
57+ # them up rather than setting use_underline=False
58+ fname = fname.replace('_', '__')
59+
60+ progress = (100*int(xfer.get('n_bytes_written',
61+ xfer.get('n_bytes_read', 0)))
62+ /int(xfer['deflated_size']))
63+
64+ label = u"%s %-30s %s%%" % (xfer['op'], fname, progress)
65+
66+ self.indicator.xfer_item.set_label(label)
67+ self.indicator.xfer_item.show()
68+ return True
69+
70+
71 def format_data(value):
72 """Utility function to present user-friendly bytes"""
73 units = (Application.BYTES_UNIT_LABEL,
74
75=== modified file 'ubuntuone_indicator/__init__.py'
76--- ubuntuone_indicator/__init__.py 2010-10-16 11:33:14 +0000
77+++ ubuntuone_indicator/__init__.py 2010-12-16 15:23:07 +0000
78@@ -221,7 +221,7 @@
79 """Handler for UploadStarted signal"""
80 pass
81
82- def content_queue_changed_handler(self, data):
83+ def content_queue_changed_handler(self, data=None):
84 """Handler for ContentQueueChanged signal"""
85 self.content_queue_changed_cb(data)
86
87@@ -311,6 +311,23 @@
88 info['name'] = 'UNKNOWN'
89 return info
90
91+ def get_current_xfer(self):
92+ if self.is_dbus_ready():
93+ xfer = None
94+ uploads = self.status_if.current_uploads()
95+ if uploads:
96+ xfer = uploads[0]
97+ xfer['op'] = u'\N{UPWARDS WHITE ARROW}'
98+ else:
99+ downloads = self.status_if.current_downloads()
100+ if downloads:
101+ xfer = downloads[0]
102+ xfer['op'] = u'\N{DOWNWARDS WHITE ARROW}'
103+
104+ return xfer
105+ else:
106+ raise DaemonNotRunningError()
107+
108 def connect_daemon(self):
109 """Asks SyncDaemon to connect"""
110 if not self.dbus_handlers_installed:
111@@ -368,6 +385,8 @@
112 self.status_toggle_item_handler)
113 self.status_toggle_item.show()
114
115+ self.xfer_item = gtk.MenuItem()
116+
117 separator = gtk.MenuItem()
118 separator.show()
119
120@@ -395,6 +414,7 @@
121
122 menu.append(self.state_name_item)
123 menu.append(self.estimate_item)
124+ menu.append(self.xfer_item)
125
126 # Separator
127 menu.append(separator)

Subscribers

People subscribed via source and target branches