Merge lp:~ralsina/ubuntuone-control-panel/minus-one-is-the-loneliest-number into lp:ubuntuone-control-panel

Proposed by Roberto Alsina
Status: Merged
Approved by: Brian Curtin
Approved revision: 326
Merged at revision: 325
Proposed branch: lp:~ralsina/ubuntuone-control-panel/minus-one-is-the-loneliest-number
Merge into: lp:ubuntuone-control-panel
Diff against target: 380 lines (+88/-144)
5 files modified
data/qt/preferences.ui (+43/-17)
data/qt/ubuntuone.qss (+7/-0)
ubuntuone/controlpanel/gui/__init__.py (+0/-2)
ubuntuone/controlpanel/gui/qt/preferences.py (+14/-50)
ubuntuone/controlpanel/gui/qt/tests/test_preferences.py (+24/-75)
To merge this branch: bzr merge lp:~ralsina/ubuntuone-control-panel/minus-one-is-the-loneliest-number
Reviewer Review Type Date Requested Status
Brian Curtin (community) Approve
Diego Sarmentero (community) Approve
Review via email: mp+105869@code.launchpad.net

Commit message

 - Improved the UX for the bandwidth settings (Fixes lp:847227).

Description of the change

* Removed the warning 'Please note that your files will not sync if you set your bandwidth to 0' which was not even true
* Enable/disable the spinboxes when you check/uncheck the matching checkbox
* Made the minimum bandwidth value 1, removing the bogus -1 and 0 (it still saves -1 to mean disabled)

 - Improved the UX for the bandwidth settings (Fixes lp:847227).

To post a comment you must log in.
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve
Revision history for this message
Brian Curtin (brian.curtin) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/qt/preferences.ui'
2--- data/qt/preferences.ui 2012-05-15 13:53:50 +0000
3+++ data/qt/preferences.ui 2012-05-15 18:48:18 +0000
4@@ -38,18 +38,21 @@
5 </item>
6 <item row="0" column="1">
7 <widget class="QSpinBox" name="upload_speed_spinbox">
8+ <property name="enabled">
9+ <bool>false</bool>
10+ </property>
11 <property name="alignment">
12 <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
13 </property>
14 <property name="minimum">
15- <number>-1</number>
16+ <number>1</number>
17 </property>
18 <property name="maximum">
19 <number>999999999</number>
20 </property>
21 </widget>
22 </item>
23- <item row="0" column="3">
24+ <item row="0" column="2">
25 <spacer name="horizontalSpacer_2">
26 <property name="orientation">
27 <enum>Qt::Horizontal</enum>
28@@ -71,11 +74,14 @@
29 </item>
30 <item row="1" column="1">
31 <widget class="QSpinBox" name="download_speed_spinbox">
32+ <property name="enabled">
33+ <bool>false</bool>
34+ </property>
35 <property name="alignment">
36 <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
37 </property>
38 <property name="minimum">
39- <number>-1</number>
40+ <number>1</number>
41 </property>
42 <property name="maximum">
43 <number>999999999</number>
44@@ -98,19 +104,6 @@
45 </property>
46 </spacer>
47 </item>
48- <item row="3" column="0" colspan="3">
49- <widget class="QLabel" name="label_2">
50- <property name="text">
51- <string notr="true">Please note that your files will not sync if you set bandwidth to 0</string>
52- </property>
53- <property name="scaledContents">
54- <bool>false</bool>
55- </property>
56- <property name="wordWrap">
57- <bool>false</bool>
58- </property>
59- </widget>
60- </item>
61 </layout>
62 </widget>
63 </item>
64@@ -223,5 +216,38 @@
65 </layout>
66 </widget>
67 <resources/>
68- <connections/>
69+ <connections>
70+ <connection>
71+ <sender>limit_uploads_checkbox</sender>
72+ <signal>toggled(bool)</signal>
73+ <receiver>upload_speed_spinbox</receiver>
74+ <slot>setEnabled(bool)</slot>
75+ <hints>
76+ <hint type="sourcelabel">
77+ <x>94</x>
78+ <y>24</y>
79+ </hint>
80+ <hint type="destinationlabel">
81+ <x>256</x>
82+ <y>28</y>
83+ </hint>
84+ </hints>
85+ </connection>
86+ <connection>
87+ <sender>limit_downloads_checkbox</sender>
88+ <signal>toggled(bool)</signal>
89+ <receiver>download_speed_spinbox</receiver>
90+ <slot>setEnabled(bool)</slot>
91+ <hints>
92+ <hint type="sourcelabel">
93+ <x>212</x>
94+ <y>70</y>
95+ </hint>
96+ <hint type="destinationlabel">
97+ <x>242</x>
98+ <y>66</y>
99+ </hint>
100+ </hints>
101+ </connection>
102+ </connections>
103 </ui>
104
105=== modified file 'data/qt/ubuntuone.qss'
106--- data/qt/ubuntuone.qss 2012-05-15 02:05:41 +0000
107+++ data/qt/ubuntuone.qss 2012-05-15 18:48:18 +0000
108@@ -338,6 +338,13 @@
109 background-color: white;
110 }
111
112+QSpinBox:disabled {
113+ padding: 3px;
114+ background-color: transparent;
115+ color: darkgrey;
116+}
117+
118+
119 QTreeWidget::item:selected {
120 background: #fcece7;
121 color: black;
122
123=== modified file 'ubuntuone/controlpanel/gui/__init__.py'
124--- ubuntuone/controlpanel/gui/__init__.py 2012-05-15 13:53:50 +0000
125+++ ubuntuone/controlpanel/gui/__init__.py 2012-05-15 18:48:18 +0000
126@@ -224,8 +224,6 @@
127 SETTINGS_ALLOW_NOTIFICATIONS = _('Allow all notifications to this device')
128 SETTINGS_AUTO_CONNECT = _('Connect automatically when computer starts')
129 SETTINGS_BANDWIDTH = _('Bandwidth Settings')
130-SETTINGS_BANDWIDTH_ZERO_WARNING = _('Please note that your files will not '
131- 'sync if you set bandwidth to 0')
132 SETTINGS_BUTTON_APPLY = _('Apply these settings')
133 SETTINGS_BUTTON_DEFAULT = _('Default settings')
134 SETTINGS_CHANGE_ERROR = _('The settings could not be changed,\n'
135
136=== modified file 'ubuntuone/controlpanel/gui/qt/preferences.py'
137--- ubuntuone/controlpanel/gui/qt/preferences.py 2012-05-15 13:53:50 +0000
138+++ ubuntuone/controlpanel/gui/qt/preferences.py 2012-05-15 18:48:18 +0000
139@@ -29,7 +29,6 @@
140 SETTINGS_ALLOW_NOTIFICATIONS,
141 SETTINGS_AUTO_CONNECT,
142 SETTINGS_BANDWIDTH,
143- SETTINGS_BANDWIDTH_ZERO_WARNING,
144 SETTINGS_BUTTON_APPLY,
145 SETTINGS_BUTTON_DEFAULT,
146 SETTINGS_FILE_SYNC,
147@@ -55,22 +54,6 @@
148 return CHECKED if checked else UNCHECKED
149
150
151-def tweak_speed(speed):
152- """Return the proper speed in kilobytes.
153-
154- If speed < 0, return -1.
155- If speed == 0, return 1 (almost nothing, the backed won't accept 0.
156- If speed > 0, return the kilobytes presentation of that.
157-
158- """
159- result = -1
160- if speed > 0:
161- result = speed * KILOBYTES
162- elif speed == 0:
163- result = 1
164- return result
165-
166-
167 class PreferencesPanel(UbuntuOneBin):
168 """The Preferences Tab Panel widget"""
169
170@@ -87,7 +70,6 @@
171 SETTINGS_KILOBITS_PER_SECOND)
172 self.ui.download_speed_spinbox.setSuffix(" " +
173 SETTINGS_KILOBITS_PER_SECOND)
174- self.ui.label_2.setText(SETTINGS_BANDWIDTH_ZERO_WARNING)
175 self.ui.restore_defaults_button.setText(SETTINGS_BUTTON_DEFAULT)
176
177 # pylint: disable=E0202
178@@ -119,40 +101,18 @@
179 # signal handlers
180 self.ui.download_speed_spinbox.setValue(download_speed)
181 self.ui.upload_speed_spinbox.setValue(upload_speed)
182+ if upload_speed > 0:
183+ self.ui.limit_uploads_checkbox.setCheckState(CHECKED)
184+ else:
185+ self.ui.limit_uploads_checkbox.setCheckState(UNCHECKED)
186+ if download_speed > 0:
187+ self.ui.limit_downloads_checkbox.setCheckState(CHECKED)
188+ else:
189+ self.ui.limit_downloads_checkbox.setCheckState(UNCHECKED)
190 self.is_processing = False
191
192- def process_speed_settings(self, new_value, checkbox):
193- """A new speed limit was set."""
194- if new_value < 0:
195- checkbox.setCheckState(UNCHECKED)
196- else:
197- checkbox.setCheckState(CHECKED)
198-
199- # Invalid name "on_{down, up}load_speed_spinbox_valueChanged"
200 # pylint: disable=C0103
201
202- @QtCore.pyqtSlot(int)
203- def on_download_speed_spinbox_valueChanged(self, new_value):
204- """A new download speed was set."""
205- self.process_speed_settings(new_value,
206- self.ui.limit_downloads_checkbox)
207-
208- @QtCore.pyqtSlot(int)
209- def on_upload_speed_spinbox_valueChanged(self, new_value):
210- """A new upload speed was set."""
211- self.process_speed_settings(new_value,
212- self.ui.limit_uploads_checkbox)
213-
214- def on_limit_downloads_checkbox_stateChanged(self, new_state):
215- """Limit download speed checkbox changed."""
216- if new_state == UNCHECKED:
217- self.ui.download_speed_spinbox.setValue(-1)
218-
219- def on_limit_uploads_checkbox_stateChanged(self, new_state):
220- """Limit upload speed checkbox changed."""
221- if new_state == UNCHECKED:
222- self.ui.upload_speed_spinbox.setValue(-1)
223-
224 @QtCore.pyqtSlot()
225 @defer.inlineCallbacks
226 def on_apply_changes_button_clicked(self):
227@@ -161,8 +121,12 @@
228 notifications = self.ui.show_all_notifications_checkbox.checkState()
229 share_autosubscribe = self.ui.share_autosubscribe_checkbox.checkState()
230 udf_autosubscribe = self.ui.udf_autosubscribe_checkbox.checkState()
231- download_speed = tweak_speed(self.ui.download_speed_spinbox.value())
232- upload_speed = tweak_speed(self.ui.upload_speed_spinbox.value())
233+ download_speed = self.ui.download_speed_spinbox.value() * KILOBYTES
234+ if self.ui.limit_uploads_checkbox.checkState() == UNCHECKED:
235+ upload_speed = -1
236+ upload_speed = self.ui.upload_speed_spinbox.value() * KILOBYTES
237+ if self.ui.limit_downloads_checkbox.checkState() == UNCHECKED:
238+ download_speed = -1
239
240 settings = {
241 backend.AUTOCONNECT_KEY: autoconnect == CHECKED,
242
243=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_preferences.py'
244--- ubuntuone/controlpanel/gui/qt/tests/test_preferences.py 2012-05-15 13:53:50 +0000
245+++ ubuntuone/controlpanel/gui/qt/tests/test_preferences.py 2012-05-15 18:48:18 +0000
246@@ -55,8 +55,8 @@
247 gui.backend.SHOW_ALL_NOTIFICATIONS_KEY: notifs == gui.CHECKED,
248 gui.backend.SHARE_AUTOSUBSCRIBE_KEY: share_auto == gui.CHECKED,
249 gui.backend.UDF_AUTOSUBSCRIBE_KEY: udf_auto == gui.CHECKED,
250- gui.backend.DOWNLOAD_KEY: gui.tweak_speed(download_speed),
251- gui.backend.UPLOAD_KEY: gui.tweak_speed(upload_speed),
252+ gui.backend.DOWNLOAD_KEY: download_speed * gui.KILOBYTES,
253+ gui.backend.UPLOAD_KEY: upload_speed * gui.KILOBYTES,
254 }
255 return result
256
257@@ -120,18 +120,20 @@
258 speed = settings[gui.backend.DOWNLOAD_KEY]
259 if speed > 0:
260 speed = settings[gui.backend.DOWNLOAD_KEY] // gui.KILOBYTES
261- download_speed = self.ui.ui.download_speed_spinbox.value()
262- self.assertEqual(speed, download_speed)
263+ download_speed = self.ui.ui.download_speed_spinbox.value()
264+ self.assertEqual(speed, download_speed)
265 limit_downloads = self.ui.ui.limit_downloads_checkbox.checkState()
266- self.assertEqual(speed > 0, limit_downloads == gui.CHECKED)
267+ self.assertEqual(self.ui.ui.download_speed_spinbox.isEnabled(),
268+ limit_downloads == gui.CHECKED)
269
270 speed = settings[gui.backend.UPLOAD_KEY]
271 if speed > 0:
272 speed = settings[gui.backend.UPLOAD_KEY] // gui.KILOBYTES
273- upload_speed = self.ui.ui.upload_speed_spinbox.value()
274- self.assertEqual(speed, upload_speed)
275+ upload_speed = self.ui.ui.upload_speed_spinbox.value()
276+ self.assertEqual(speed, upload_speed)
277 limit_uploads = self.ui.ui.limit_uploads_checkbox.checkState()
278- self.assertEqual(speed > 0, limit_uploads == gui.CHECKED)
279+ self.assertEqual(self.ui.ui.upload_speed_spinbox.isEnabled(),
280+ limit_uploads == gui.CHECKED)
281
282 def test_update_ui_from_backed_info(self):
283 """The ui is correctly updated when the backend info is received."""
284@@ -153,63 +155,22 @@
285 self.ui.process_info(settings)
286 self._test_update_ui_from_settings_info(settings)
287
288- def _test_speed_checkbox_value_changed_to_positive(self, speed_spinbox,
289- limit_checkbox):
290- """When the speed is set to a positive value, enable the checkbox."""
291- limit_checkbox.setCheckState(gui.UNCHECKED)
292- speed_spinbox.setValue(33)
293-
294- self.assertEqual(gui.CHECKED, limit_checkbox.checkState())
295-
296- def _test_speed_checkbox_value_changed_to_negative(self, speed_spinbox,
297- limit_checkbox):
298- """When the speed is set to a negative value, disable the checkbox."""
299- limit_checkbox.setCheckState(gui.UNCHECKED)
300- speed_spinbox.setValue(-1)
301-
302- self.assertEqual(gui.UNCHECKED, limit_checkbox.checkState())
303-
304- def _test_speed_checkbox_unchecked(self, speed_spinbox, limit_checkbox):
305- """When the speed checkbox is unchecked, reset speed to -1."""
306+ def _test_speed_checkbox_toggled(self, speed_spinbox, limit_checkbox):
307+ """The checkbox is checked if and only if the spinbox is enabled."""
308 limit_checkbox.setCheckState(gui.CHECKED)
309- speed_spinbox.setValue(33)
310+ self.assertTrue(speed_spinbox.isEnabled())
311 limit_checkbox.setCheckState(gui.UNCHECKED)
312-
313- self.assertEqual(-1, speed_spinbox.value())
314-
315- def test_download_speed_checkbox_value_changed_to_positive(self):
316- """When the download speed is set, enable the checkbox."""
317- self._test_speed_checkbox_value_changed_to_positive(
318- self.ui.ui.download_speed_spinbox,
319- self.ui.ui.limit_downloads_checkbox)
320-
321- def test_download_speed_checkbox_value_changed_to_negative(self):
322- """When the download speed is set, enable the checkbox."""
323- self._test_speed_checkbox_value_changed_to_negative(
324- self.ui.ui.download_speed_spinbox,
325- self.ui.ui.limit_downloads_checkbox)
326-
327- def test_download_speed_checkbox_unchecked(self):
328- """Reset the speed to -1 when the checkbox is disabled."""
329- self._test_speed_checkbox_unchecked(
330- self.ui.ui.download_speed_spinbox,
331- self.ui.ui.limit_downloads_checkbox)
332-
333- def test_upload_speed_checkbox_value_changed_to_positive(self):
334- """When the upload speed is set, enable the checkbox."""
335- self._test_speed_checkbox_value_changed_to_positive(
336- self.ui.ui.upload_speed_spinbox,
337- self.ui.ui.limit_uploads_checkbox)
338-
339- def test_upload_speed_checkbox_value_changed_to_negative(self):
340- """When the upload speed is set, enable the checkbox."""
341- self._test_speed_checkbox_value_changed_to_negative(
342- self.ui.ui.upload_speed_spinbox,
343- self.ui.ui.limit_uploads_checkbox)
344-
345- def test_upload_speed_checkbox_unchecked(self):
346- """Reset the speed to -1 when the checkbox is disabled."""
347- self._test_speed_checkbox_unchecked(
348+ self.assertFalse(speed_spinbox.isEnabled())
349+
350+ def test_download_speed_checkbox_connections(self):
351+ """Check connections for download_speed_checkbox."""
352+ self._test_speed_checkbox_toggled(
353+ self.ui.ui.download_speed_spinbox,
354+ self.ui.ui.limit_downloads_checkbox)
355+
356+ def test_upload_speed_checkbox_connections(self):
357+ """Check connections for upload_speed_checkbox."""
358+ self._test_speed_checkbox_toggled(
359 self.ui.ui.upload_speed_spinbox,
360 self.ui.ui.limit_uploads_checkbox)
361
362@@ -288,18 +249,6 @@
363
364 yield self.ui.ui.restore_defaults_button.click()
365
366- def test_tweak_speed_negative(self):
367- """Tweak speed properly: if param is negative, return -1."""
368- self.assertEqual(-1, gui.tweak_speed(-5))
369-
370- def test_tweak_speed_zero(self):
371- """Tweak speed properly: if param is zero, return 1."""
372- self.assertEqual(1, gui.tweak_speed(0))
373-
374- def test_tweak_speed_positive(self):
375- """Tweak speed properly: if param is positive, return kilobytes."""
376- self.assertEqual(123456 * gui.KILOBYTES, gui.tweak_speed(123456))
377-
378 def test_resize_event(self):
379 """Check that the QCheckBox widgets receive the proper texts."""
380 wrap_calls = {}

Subscribers

People subscribed via source and target branches