Merge lp:~diegosarmentero/ubuntuone-control-panel/new-share-design into lp:ubuntuone-control-panel

Proposed by Diego Sarmentero
Status: Merged
Approved by: dobey
Approved revision: 382
Merged at revision: 376
Proposed branch: lp:~diegosarmentero/ubuntuone-control-panel/new-share-design
Merge into: lp:ubuntuone-control-panel
Prerequisite: lp:~diegosarmentero/ubuntuone-control-panel/search-shared-files
Diff against target: 943 lines (+418/-114)
8 files modified
data/qt/images.qrc (+1/-0)
data/qt/share_links.ui (+175/-20)
data/qt/ubuntuone.qss (+1/-1)
ubuntuone/controlpanel/gui/__init__.py (+7/-1)
ubuntuone/controlpanel/gui/qt/share_links.py (+84/-15)
ubuntuone/controlpanel/gui/qt/share_links_search.py (+52/-32)
ubuntuone/controlpanel/gui/qt/tests/test_share_links.py (+51/-4)
ubuntuone/controlpanel/gui/qt/tests/test_share_links_search.py (+47/-41)
To merge this branch: bzr merge lp:~diegosarmentero/ubuntuone-control-panel/new-share-design
Reviewer Review Type Date Requested Status
dobey (community) Approve
Brian Curtin (community) Approve
Michał Karnicki (community) Approve
Review via email: mp+131397@code.launchpad.net

Commit message

- Implementing new share tab design (LP: #1065194, #1056194).

Description of the change

As this branch has as prerequisite: p:~diegosarmentero/ubuntuone-control-panel/search-shared-files

You will need to have ubuntuone-client up to date (with this change: https://code.launchpad.net/~diegosarmentero/ubuntuone-client/search-filter/+merge/130862) to test it IRL.

And now this works like this (with a few ui improves that are not included in the video):
http://youtu.be/x7b3Z2r7SRQ

If you see the following lint issue:
== Python Lint Notices ==

ubuntuone/controlpanel/sd_client/__init__.py:
    235: [E1101, SyncDaemonClient.search_files] Instance of 'SyncDaemonTool' has no 'search_files' member

You will need to add the u1-client branch mentioned to the path when running the tests.

To post a comment you must log in.
Revision history for this message
Michał Karnicki (karni) wrote :

Hardcoded value at
386 + self.ui.stacked_widget.setCurrentIndex(2)
could be replaced by a constant, that tells its meaning.

Hardcoded values at
515 + increment = 2 if current == 0 else 1
tell me little about what they mean. Unless this is obvious for Qt developers, fix with constants.

Quite a few constants in the tests make me think they are very sensitive to test data set changes.

Other than that, looks good.

review: Approve
Revision history for this message
Michał Karnicki (karni) :
review: Approve
Revision history for this message
Brian Curtin (brian.curtin) wrote :

420 + if len(results) > 0:

I think this if/else should go above the result iteration, not after it. If we have no results, do the hide, otherwise iterate over the results and then show them. It doesn't change the operation, it just reads a bit better IMO.

439 + def __init__(self, path, link, both_buttons=True, parent=None):

If we're adding an argument (both_buttons), shouldn't the new one go at the end?

I'm running IRL and tests on Windows right now.

review: Needs Fixing
Revision history for this message
Mike McCracken (mikemc) wrote :

This is a big improvement! I'd like to suggest that the string PUBLISH_THESE_FILES should be singular - you can only select one file to publish, right?
So "Publish these files" seems strange - maybe a better call to action is "Select a file to publish:" or something like that.

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

I reported https://bugs.launchpad.net/ubuntuone-control-panel/+bug/1073660 while testing this, but it's unrelated to the functionality here.

Approved. Tests and IRL pass on Windows.

review: Approve
Revision history for this message
dobey (dobey) wrote :

I'm wondering if we should land this yet, as the changes in wording and such do present similar concerns as the ones I've raised on your other 2 related branches.

review: Needs Information
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :

Voting does not meet specified criteria. Required: Approve >= 1, Disapprove == 0, Needs Fixing == 0, Needs Information == 0, Resubmit == 0, Pending == 0. Got: 2 Approve, 1 Needs Information.

Revision history for this message
dobey (dobey) wrote :

21 + <string>Search and Share files</string>
281 +SEARCH_FILES = _('Search and Share files')

These need to be sentence case ('share' should be lowercase). http://developer.gnome.org/hig-book/stable/design-text-labels.html.en#layout-capitalization

274 +PUBLISH_FILE = _('Publish file')
275 +PUBLISH_THESE_FILES = _('Select a file to publish:"')

Presumably we should not use the term 'publish' here.

684 + publicfiles = [
685 + {'path': '/home/file1', 'public_url': 'http:ubuntuone.com/asd123'},
686 + {'path': '/home/file2', 'public_url': 'http:ubuntuone.com/qwe456'},
687 + ]

744 + results = ['/home/file1', '/home/file2']

934 + items = [
935 + '/home/tester/file1',
936 + '/home/tester/file2',
937 + '/home/tester/file3',
938 + ]

Should these 3 sets of filenames in tests not be created with os.path.join() instead, for cross-platform happiness? Should it also not use the $HOME (the user_home from dirspec), here?

review: Needs Fixing
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

> 21 + <string>Search and Share files</string>
> 281 +SEARCH_FILES = _('Search and Share files')
>
> These need to be sentence case ('share' should be lowercase).
> http://developer.gnome.org/hig-book/stable/design-text-labels.html.en#layout-
> capitalization

Fixed

>
> 274 +PUBLISH_FILE = _('Publish file')
> 275 +PUBLISH_THESE_FILES = _('Select a file to publish:"')
>
> Presumably we should not use the term 'publish' here.

Fixed

>
> 684 + publicfiles = [
> 685 + {'path': '/home/file1', 'public_url': 'http:ubuntuone.com/asd123'},
> 686 + {'path': '/home/file2', 'public_url': 'http:ubuntuone.com/qwe456'},
> 687 + ]
>
> 744 + results = ['/home/file1', '/home/file2']
>
> 934 + items = [
> 935 + '/home/tester/file1',
> 936 + '/home/tester/file2',
> 937 + '/home/tester/file3',
> 938 + ]
>
> Should these 3 sets of filenames in tests not be created with os.path.join()
> instead, for cross-platform happiness? Should it also not use the $HOME (the
> user_home from dirspec), here?

I don't see the need, they are just dummy values to see that the ui is loaded properly when that data structure is received.

Revision history for this message
dobey (dobey) :
review: Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :
Download full text (164.2 KiB)

The attempt to merge lp:~diegosarmentero/ubuntuone-control-panel/new-share-design into lp:ubuntuone-control-panel failed. Below is the output from the failed tests.

*** Running DBus test suite ***
ubuntuone.controlpanel.dbustests.test_dbus_service
  BaseTestCase
    runTest ... [OK]
  DBusServiceMainTestCase
    test_dbus_service_cant_register ... Control panel backend already running.
                                   [OK]
    test_dbus_service_main ... [OK]
  DBusServiceTestCase
    test_cant_register_twice ... [SKIPPED]
    test_dbus_busname_created ... [OK]
    test_error_handler_default ... [OK]
    test_error_handler_with_exception ... [OK]
    test_error_handler_with_failure ... [OK]
    test_error_handler_with_non_string_dict ... [OK]
    test_error_handler_with_string_dict ... [OK]
    test_register_service ... [OK]
  FileSyncTestCase
    test_file_sync_status_changed ... [OK]
    test_file_sync_status_disabled ... [OK]
    test_file_sync_status_disconnected ... [OK]
    test_file_sync_status_error ... [OK]
    test_file_sync_status_idle ... [OK]
    test_file_sync_status_starting ... [OK]
    test_file_sync_status_stopped ... [OK]
    test_file_sync_status_syncing ... [OK]
    test_file_sync_status_unknown ... [OK]
    test_status_changed_handler ... [OK]
    test_status_changed_handler_after_status_requested ... [OK]
    test_status_changed_handler_after_status_requested_twice ... [OK]
  OperationsAuthErrorTestCase
    test_account_info_returned ... [OK]
    test_change_device_settings ... [OK]
    test_change_replication_settings ... [OK]
    test_change_volume_settings ... [OK]
    test_connect_files ... [OK]
    test_devices_info_returned ... [OK]
    test_disable_files ... [OK]
    test_disconnect_files ... [OK]
    test_enable_files ... [OK]
    test_remove_device ... [OK]
    test_replications_info ... [OK]
    test_restart_files ... [OK]
...

Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :
Download full text (168.4 KiB)

The attempt to merge lp:~diegosarmentero/ubuntuone-control-panel/new-share-design into lp:ubuntuone-control-panel failed. Below is the output from the failed tests.

*** Running DBus test suite ***
ubuntuone.controlpanel.dbustests.test_dbus_service
  BaseTestCase
    runTest ... [OK]
  DBusServiceMainTestCase
    test_dbus_service_cant_register ... Control panel backend already running.
                                   [OK]
    test_dbus_service_main ... [OK]
  DBusServiceTestCase
    test_cant_register_twice ... [SKIPPED]
    test_dbus_busname_created ... [OK]
    test_error_handler_default ... [OK]
    test_error_handler_with_exception ... [OK]
    test_error_handler_with_failure ... [OK]
    test_error_handler_with_non_string_dict ... [OK]
    test_error_handler_with_string_dict ... [OK]
    test_register_service ... [OK]
  FileSyncTestCase
    test_file_sync_status_changed ... [OK]
    test_file_sync_status_disabled ... [OK]
    test_file_sync_status_disconnected ... [OK]
    test_file_sync_status_error ... [OK]
    test_file_sync_status_idle ... [OK]
    test_file_sync_status_starting ... [OK]
    test_file_sync_status_stopped ... [OK]
    test_file_sync_status_syncing ... [OK]
    test_file_sync_status_unknown ... [OK]
    test_status_changed_handler ... [OK]
    test_status_changed_handler_after_status_requested ... [OK]
    test_status_changed_handler_after_status_requested_twice ... [OK]
  OperationsAuthErrorTestCase
    test_account_info_returned ... [OK]
    test_change_device_settings ... [OK]
    test_change_replication_settings ... [OK]
    test_change_volume_settings ... [OK]
    test_connect_files ... [OK]
    test_devices_info_returned ... [OK]
    test_disable_files ... [OK]
    test_disconnect_files ... [OK]
    test_enable_files ... [OK]
    test_remove_device ... [OK]
    test_replications_info ... [OK]
    test_restart_files ... [OK]
...

381. By Diego Sarmentero

merge

Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

Fixed merge problem.

382. By Diego Sarmentero

fixing pep8 issues

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'data/qt/images.qrc'
--- data/qt/images.qrc 2012-08-23 19:01:10 +0000
+++ data/qt/images.qrc 2012-11-02 13:27:26 +0000
@@ -26,6 +26,7 @@
26 <file>../twitter.png</file>26 <file>../twitter.png</file>
27 <file>../facebook.png</file>27 <file>../facebook.png</file>
28 <file>../delete_search.png</file>28 <file>../delete_search.png</file>
29 <file>../search.png</file>
29 <file>../Ubuntu-R.ttf</file>30 <file>../Ubuntu-R.ttf</file>
30 <file>../Ubuntu-B.ttf</file>31 <file>../Ubuntu-B.ttf</file>
31 <file>ubuntuone.qss</file>32 <file>ubuntuone.qss</file>
3233
=== modified file 'data/qt/share_links.ui'
--- data/qt/share_links.ui 2012-08-23 19:01:10 +0000
+++ data/qt/share_links.ui 2012-11-02 13:27:26 +0000
@@ -59,28 +59,73 @@
59 </font>59 </font>
60 </property>60 </property>
61 <property name="text">61 <property name="text">
62 <string>Search files</string>62 <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Search and share files&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
63 </property>63 </property>
64 </widget>64 </widget>
65 </item>65 </item>
66 <item>66 <item>
67 <widget class="SearchBox" name="line_search">67 <layout class="QHBoxLayout" name="horizontalLayout_5">
68 <property name="sizePolicy">68 <property name="spacing">
69 <sizepolicy hsizetype="Fixed" vsizetype="Fixed">69 <number>0</number>
70 <horstretch>0</horstretch>70 </property>
71 <verstretch>0</verstretch>71 <item>
72 </sizepolicy>72 <widget class="SearchBox" name="line_search">
73 </property>73 <property name="sizePolicy">
74 <property name="maximumSize">74 <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
75 <size>75 <horstretch>0</horstretch>
76 <width>400</width>76 <verstretch>0</verstretch>
77 <height>16777215</height>77 </sizepolicy>
78 </size>78 </property>
79 </property>79 <property name="minimumSize">
80 <property name="frame">80 <size>
81 <bool>true</bool>81 <width>450</width>
82 </property>82 <height>0</height>
83 </widget>83 </size>
84 </property>
85 <property name="maximumSize">
86 <size>
87 <width>400</width>
88 <height>16777215</height>
89 </size>
90 </property>
91 <property name="frame">
92 <bool>true</bool>
93 </property>
94 </widget>
95 </item>
96 <item>
97 <widget class="QPushButton" name="btn_search">
98 <property name="sizePolicy">
99 <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
100 <horstretch>0</horstretch>
101 <verstretch>0</verstretch>
102 </sizepolicy>
103 </property>
104 <property name="maximumSize">
105 <size>
106 <width>24</width>
107 <height>24</height>
108 </size>
109 </property>
110 <property name="text">
111 <string/>
112 </property>
113 </widget>
114 </item>
115 <item>
116 <spacer name="horizontalSpacer_3">
117 <property name="orientation">
118 <enum>Qt::Horizontal</enum>
119 </property>
120 <property name="sizeHint" stdset="0">
121 <size>
122 <width>40</width>
123 <height>20</height>
124 </size>
125 </property>
126 </spacer>
127 </item>
128 </layout>
84 </item>129 </item>
85 </layout>130 </layout>
86 </item>131 </item>
@@ -89,7 +134,7 @@
89 <property name="currentIndex">134 <property name="currentIndex">
90 <number>0</number>135 <number>0</number>
91 </property>136 </property>
92 <widget class="QWidget" name="page">137 <widget class="QWidget" name="page_public">
93 <layout class="QVBoxLayout" name="verticalLayout_4">138 <layout class="QVBoxLayout" name="verticalLayout_4">
94 <property name="spacing">139 <property name="spacing">
95 <number>0</number>140 <number>0</number>
@@ -154,7 +199,7 @@
154 </item>199 </item>
155 </layout>200 </layout>
156 </widget>201 </widget>
157 <widget class="QWidget" name="page_2">202 <widget class="QWidget" name="page_details">
158 <layout class="QVBoxLayout" name="verticalLayout_5">203 <layout class="QVBoxLayout" name="verticalLayout_5">
159 <property name="spacing">204 <property name="spacing">
160 <number>0</number>205 <number>0</number>
@@ -303,6 +348,116 @@
303 </item>348 </item>
304 </layout>349 </layout>
305 </widget>350 </widget>
351 <widget class="QWidget" name="page_search">
352 <layout class="QVBoxLayout" name="verticalLayout_8">
353 <property name="spacing">
354 <number>0</number>
355 </property>
356 <property name="margin">
357 <number>0</number>
358 </property>
359 <item>
360 <layout class="QHBoxLayout" name="horizontalLayout_2">
361 <property name="spacing">
362 <number>0</number>
363 </property>
364 <property name="leftMargin">
365 <number>15</number>
366 </property>
367 <item>
368 <widget class="QLabel" name="label_search_results">
369 <property name="sizePolicy">
370 <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
371 <horstretch>0</horstretch>
372 <verstretch>0</verstretch>
373 </sizepolicy>
374 </property>
375 <property name="font">
376 <font>
377 <weight>75</weight>
378 <bold>true</bold>
379 </font>
380 </property>
381 <property name="text">
382 <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Search Results&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
383 </property>
384 </widget>
385 </item>
386 <item>
387 <spacer name="horizontalSpacer_2">
388 <property name="orientation">
389 <enum>Qt::Horizontal</enum>
390 </property>
391 <property name="sizeType">
392 <enum>QSizePolicy::Expanding</enum>
393 </property>
394 <property name="sizeHint" stdset="0">
395 <size>
396 <width>40</width>
397 <height>0</height>
398 </size>
399 </property>
400 </spacer>
401 </item>
402 <item>
403 <widget class="QPushButton" name="back_to_file_list_2">
404 <property name="text">
405 <string>Back to file list</string>
406 </property>
407 </widget>
408 </item>
409 </layout>
410 </item>
411 <item>
412 <widget class="QTreeWidget" name="tree_search_results">
413 <property name="alternatingRowColors">
414 <bool>true</bool>
415 </property>
416 <property name="indentation">
417 <number>15</number>
418 </property>
419 <property name="rootIsDecorated">
420 <bool>false</bool>
421 </property>
422 <attribute name="headerVisible">
423 <bool>false</bool>
424 </attribute>
425 <attribute name="headerDefaultSectionSize">
426 <number>250</number>
427 </attribute>
428 <attribute name="headerStretchLastSection">
429 <bool>true</bool>
430 </attribute>
431 <column>
432 <property name="text">
433 <string notr="true">Filename</string>
434 </property>
435 </column>
436 <column>
437 <property name="text">
438 <string notr="true">Actions</string>
439 </property>
440 </column>
441 </widget>
442 </item>
443 <item>
444 <widget class="QLabel" name="label_no_results">
445 <property name="sizePolicy">
446 <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
447 <horstretch>0</horstretch>
448 <verstretch>0</verstretch>
449 </sizepolicy>
450 </property>
451 <property name="text">
452 <string>You have no files with this name.</string>
453 </property>
454 <property name="indent">
455 <number>20</number>
456 </property>
457 </widget>
458 </item>
459 </layout>
460 </widget>
306 </widget>461 </widget>
307 </item>462 </item>
308 </layout>463 </layout>
309464
=== modified file 'data/qt/ubuntuone.qss'
--- data/qt/ubuntuone.qss 2012-10-12 19:38:02 +0000
+++ data/qt/ubuntuone.qss 2012-11-02 13:27:26 +0000
@@ -402,7 +402,7 @@
402 background-origin: margin;402 background-origin: margin;
403}403}
404404
405QPushButton#back_to_file_list {405QPushButton#back_to_file_list, QPushButton#back_to_file_list_2 {
406 background: transparent;406 background: transparent;
407 border: none;407 border: none;
408 color: #dd4814;408 color: #dd4814;
409409
=== added file 'data/search.png'
410Binary files data/search.png 1970-01-01 00:00:00 +0000 and data/search.png 2012-11-02 13:27:26 +0000 differ410Binary files data/search.png 1970-01-01 00:00:00 +0000 and data/search.png 2012-11-02 13:27:26 +0000 differ
=== modified file 'ubuntuone/controlpanel/gui/__init__.py'
--- ubuntuone/controlpanel/gui/__init__.py 2012-10-23 19:26:30 +0000
+++ ubuntuone/controlpanel/gui/__init__.py 2012-11-02 13:27:26 +0000
@@ -232,18 +232,24 @@
232NO_DEVICES = _('No devices to show.')232NO_DEVICES = _('No devices to show.')
233NO_FOLDERS = _('No folders to show.')233NO_FOLDERS = _('No folders to show.')
234NO_PAIRING_RECORD = _('There is no Ubuntu One pairing record.')234NO_PAIRING_RECORD = _('There is no Ubuntu One pairing record.')
235NO_RESULTS = _('No results')
236NO_RESULTS_LABEL = _('You have no files with this name.')
235OPEN = _('Open')237OPEN = _('Open')
236OPEN_UBUNTU_ONE = _('Open Ubuntu One')238OPEN_UBUNTU_ONE = _('Open Ubuntu One')
237OPEN_UBUNTU_ONE_FOLDER = _('Open the Ubuntu One Folder')239OPEN_UBUNTU_ONE_FOLDER = _('Open the Ubuntu One Folder')
238PERCENTAGE_LABEL = _('%(percentage)s used')240PERCENTAGE_LABEL = _('%(percentage)s used')
239PLEASE_WAIT = _('Please wait')241PLEASE_WAIT = _('Please wait')
240PROFILE_LABEL = _('Personal details')242PROFILE_LABEL = _('Personal details')
243SHARE_FILE = _('Share file')
244SHARE_THESE_FILES = _('Select a file to share:')
241QUOTA_LABEL = _('Using %(used)s of %(total)s (%(percentage).0f%%)')245QUOTA_LABEL = _('Using %(used)s of %(total)s (%(percentage).0f%%)')
242REMOVE_BUTTON = _('Remove')246REMOVE_BUTTON = _('Remove')
243RECENT_TRANSFERS = _('Recent Transfers')247RECENT_TRANSFERS = _('Recent Transfers')
244RESTORE_LABEL = _('Restore')248RESTORE_LABEL = _('Restore')
245SEARCH_FILES = _('Search files')249SEARCH_FILES = _('Search and share files')
246SELECT_FOLDERS = _('Select sync folders')250SELECT_FOLDERS = _('Select sync folders')
251SEARCH_FOR = _('Search for: %s')
252SEARCH_RESULTS = _('Search Results for "%s"')
247SERVICES_BUTTON_TOOLTIP = _('Manage the sync services')253SERVICES_BUTTON_TOOLTIP = _('Manage the sync services')
248SERVICES_TITLE = _('Enable the sync services for this computer.')254SERVICES_TITLE = _('Enable the sync services for this computer.')
249SETTINGS_ALLOW_NOTIFICATIONS = _('Allow all notifications to this device')255SETTINGS_ALLOW_NOTIFICATIONS = _('Allow all notifications to this device')
250256
=== modified file 'ubuntuone/controlpanel/gui/qt/share_links.py'
--- ubuntuone/controlpanel/gui/qt/share_links.py 2012-10-23 19:26:30 +0000
+++ ubuntuone/controlpanel/gui/qt/share_links.py 2012-11-02 13:27:26 +0000
@@ -27,7 +27,10 @@
27from ubuntuone.controlpanel.gui import (27from ubuntuone.controlpanel.gui import (
28 COPY_LINK,28 COPY_LINK,
29 OPEN,29 OPEN,
30 SHARE_FILE,
31 NO_RESULTS_LABEL,
30 SEARCH_FILES,32 SEARCH_FILES,
33 SEARCH_RESULTS,
31 SHARED_FILES,34 SHARED_FILES,
32)35)
3336
@@ -47,9 +50,14 @@
47logger = setup_logging('qt.share_links')50logger = setup_logging('qt.share_links')
4851
4952
53# Table items index
50FILE_NAME_COL = 054FILE_NAME_COL = 0
51PUBLIC_LINK_COL = 155PUBLIC_LINK_COL = 1
52ACTIONS_COL = 256ACTIONS_COL = 2
57# StackedLayout widgets index
58SHARED_FILES_INDEX = 0
59FILE_DETAILS_INDEX = 1
60SEARCH_RESULTS_INDEX = 2
5361
5462
55class ShareLinksPanel(UbuntuOneBin):63class ShareLinksPanel(UbuntuOneBin):
@@ -67,12 +75,15 @@
67 self.home_dir = ''75 self.home_dir = ''
68 self.ui.search_files_lbl.setText(SEARCH_FILES)76 self.ui.search_files_lbl.setText(SEARCH_FILES)
69 self.ui.shared_group.setTitle(SHARED_FILES)77 self.ui.shared_group.setTitle(SHARED_FILES)
78 self.ui.btn_search.setIcon(QtGui.QIcon(":/search.png"))
79 self.ui.label_no_results.setText(NO_RESULTS_LABEL)
80 self.ui.label_no_results.hide()
81 self.ui.page_search.layout().setAlignment(QtCore.Qt.AlignTop)
7082
71 # Set enhanced line edits83 # Set enhanced line edits
72 self._enhanced_line = EnhancedLineEdit(self.ui.line_search,84 self._enhanced_line = EnhancedLineEdit(self.ui.line_search,
73 self._line_close_btn, icon=":/delete_search.png",85 self._line_close_btn, icon=":/delete_search.png",
74 style='enhanced_borderless')86 style='enhanced_borderless')
75 self._enhanced_line.btn_operation.hide()
76 self.ui.line_search.popup.popupHidden.connect(87 self.ui.line_search.popup.popupHidden.connect(
77 self._hide_line_btn_close_hide)88 self._hide_line_btn_close_hide)
78 self.ui.line_search.popup.popupShown.connect(89 self.ui.line_search.popup.popupShown.connect(
@@ -82,15 +93,19 @@
8293
83 # Set cursor type94 # Set cursor type
84 self.ui.back_to_file_list.setCursor(QtCore.Qt.PointingHandCursor)95 self.ui.back_to_file_list.setCursor(QtCore.Qt.PointingHandCursor)
96 self.ui.back_to_file_list_2.setCursor(QtCore.Qt.PointingHandCursor)
85 self.ui.open_in_browser.setCursor(QtCore.Qt.PointingHandCursor)97 self.ui.open_in_browser.setCursor(QtCore.Qt.PointingHandCursor)
8698
87 self.ui.line_search.itemSelected.connect(self.share_file)99 self.ui.line_search.itemSelected.connect(self.share_file)
100 self.ui.line_search.filesFound.connect(self._load_search_results)
88 self.ui.back_to_file_list.clicked.connect(self._move_to_main_list)101 self.ui.back_to_file_list.clicked.connect(self._move_to_main_list)
102 self.ui.back_to_file_list_2.clicked.connect(self._move_to_main_list)
89 self.ui.open_in_browser.clicked.connect(self._open_in_browser)103 self.ui.open_in_browser.clicked.connect(self._open_in_browser)
90 self.ui.tree_shared_files.itemDoubleClicked.connect(104 self.ui.tree_shared_files.itemDoubleClicked.connect(
91 self._open_properties_selected_file)105 self._open_properties_selected_file)
92106
93 self.get_public_files()107 self.get_public_files()
108 self._enhanced_line.btn_operation.hide()
94109
95 @inlineCallbacks110 @inlineCallbacks
96 def share_file(self, file_path):111 def share_file(self, file_path):
@@ -118,6 +133,9 @@
118 """Open the file properties on double click."""133 """Open the file properties on double click."""
119 file_path = unicode(item.toolTip(FILE_NAME_COL))134 file_path = unicode(item.toolTip(FILE_NAME_COL))
120 full_path = expand_user(file_path.encode('utf-8')).decode('utf-8')135 full_path = expand_user(file_path.encode('utf-8')).decode('utf-8')
136 if self.ui.hbox_share_file.count() > 0:
137 widget = self.ui.hbox_share_file.takeAt(0).widget()
138 widget.close()
121 self.open_file_properties(file_path, full_path)139 self.open_file_properties(file_path, full_path)
122140
123 def open_file_properties(self, file_path, full_path):141 def open_file_properties(self, file_path, full_path):
@@ -127,13 +145,13 @@
127 share_file_widget.linkDisabled.connect(145 share_file_widget.linkDisabled.connect(
128 lambda: self.ui.line_copy_link.setText(''))146 lambda: self.ui.line_copy_link.setText(''))
129 self.ui.line_copy_link.setText(self._shared_files[full_path])147 self.ui.line_copy_link.setText(self._shared_files[full_path])
130 self.ui.stacked_widget.setCurrentIndex(1)148 self.ui.stacked_widget.setCurrentIndex(FILE_DETAILS_INDEX)
131149
132 def _file_shared(self, info):150 def _file_shared(self, info):
133 """Receive the notification that the file has been published."""151 """Receive the notification that the file has been published."""
134 url = info.get("public_url")152 url = info.get("public_url")
135 self.ui.line_copy_link.setText(url)153 self.ui.line_copy_link.setText(url)
136 self.ui.stacked_widget.setCurrentIndex(1)154 self.ui.stacked_widget.setCurrentIndex(FILE_DETAILS_INDEX)
137 self.is_processing = False155 self.is_processing = False
138156
139 def _open_in_browser(self):157 def _open_in_browser(self):
@@ -148,7 +166,7 @@
148166
149 def _move_to_main_list(self):167 def _move_to_main_list(self):
150 """Set the share files list as current widget."""168 """Set the share files list as current widget."""
151 self.ui.stacked_widget.setCurrentIndex(0)169 self.ui.stacked_widget.setCurrentIndex(SHARED_FILES_INDEX)
152 self.get_public_files()170 self.get_public_files()
153171
154 @inlineCallbacks172 @inlineCallbacks
@@ -190,12 +208,44 @@
190 label)208 label)
191209
192 actions = ActionsButtons(path, public_url,210 actions = ActionsButtons(path, public_url,
193 self.ui.tree_shared_files)211 parent=self.ui.tree_shared_files)
194 self.ui.tree_shared_files.setItemWidget(item, ACTIONS_COL, actions)212 self.ui.tree_shared_files.setItemWidget(item, ACTIONS_COL, actions)
195 self.is_processing = False213 self.is_processing = False
196214
215 def _load_search_results(self, results, prefix):
216 """Load the search results from the search box."""
217 self.ui.tree_search_results.clear()
218 self.ui.label_search_results.setText(SEARCH_RESULTS % prefix)
219 if len(results) > 0:
220 for result in results:
221 item = QtGui.QTreeWidgetItem()
222 name = os.path.basename(result)
223 item.setText(FILE_NAME_COL, name)
224 tooltip = result
225 if tooltip.startswith(self.home_dir):
226 tooltip = tooltip.replace(self.home_dir, '~', 1)
227 item.setToolTip(FILE_NAME_COL, tooltip)
228 icon = get_system_icon_for_filename(result.encode('utf-8'))
229 item.setIcon(FILE_NAME_COL, icon)
230 self.ui.tree_search_results.setColumnWidth(FILE_NAME_COL, 300)
231
232 item.setSizeHint(FILE_NAME_COL, QtCore.QSize(-1, 35))
233 self.ui.tree_search_results.addTopLevelItem(item)
234
235 actions = ActionsResultsButtons(result, self.share_file,
236 self.ui.tree_search_results)
237 self.ui.tree_search_results.setItemWidget(item,
238 PUBLIC_LINK_COL, actions)
239 self.ui.tree_search_results.show()
240 self.ui.label_no_results.hide()
241 else:
242 self.ui.tree_search_results.hide()
243 self.ui.label_no_results.show()
244 self.ui.stacked_widget.setCurrentIndex(SEARCH_RESULTS_INDEX)
245
197 def _line_close_btn(self):246 def _line_close_btn(self):
198 """Close button in the line edit was pressed, hide the popup."""247 """Close button in the line edit was pressed, hide the popup."""
248 self.ui.line_search.setText('')
199 self.ui.line_search.popup.hide()249 self.ui.line_search.popup.hide()
200 self.ui.line_search.setFocus()250 self.ui.line_search.setFocus()
201251
@@ -211,23 +261,24 @@
211class ActionsButtons(QtGui.QWidget):261class ActionsButtons(QtGui.QWidget):
212 """Widget that contains the open and copy link actions on the list."""262 """Widget that contains the open and copy link actions on the list."""
213263
214 def __init__(self, path, link, parent=None):264 def __init__(self, path, link, parent=None, both_buttons=True):
215 super(ActionsButtons, self).__init__(parent)265 super(ActionsButtons, self).__init__(parent)
216 self.path = path266 self.path = path
217 self.link = link267 self.link = link
218268
219 hbox = QtGui.QHBoxLayout(self)269 self.hbox = QtGui.QHBoxLayout(self)
270 self.hbox.addSpacerItem(QtGui.QSpacerItem(1, 0,
271 QtGui.QSizePolicy.Expanding))
272
220 btn_open = QtGui.QPushButton(OPEN)273 btn_open = QtGui.QPushButton(OPEN)
221 btn_copy = QtGui.QPushButton(COPY_LINK)
222 btn_open.setObjectName('action_button')274 btn_open.setObjectName('action_button')
223 btn_copy.setObjectName('action_button')275 self.hbox.addWidget(btn_open)
224 hbox.addSpacerItem(QtGui.QSpacerItem(1, 0,
225 QtGui.QSizePolicy.Expanding))
226 hbox.addWidget(btn_open)
227 hbox.addWidget(btn_copy)
228
229 btn_open.clicked.connect(self.open)276 btn_open.clicked.connect(self.open)
230 btn_copy.clicked.connect(self.copy)277 if both_buttons:
278 btn_copy = QtGui.QPushButton(COPY_LINK)
279 btn_copy.setObjectName('action_button')
280 self.hbox.addWidget(btn_copy)
281 btn_copy.clicked.connect(self.copy)
231282
232 def open(self):283 def open(self):
233 """Open the file."""284 """Open the file."""
@@ -240,6 +291,24 @@
240 app.clipboard().setText(self.link)291 app.clipboard().setText(self.link)
241292
242293
294class ActionsResultsButtons(ActionsButtons):
295 """Widget that contains: open and publish actions on the results list."""
296
297 def __init__(self, path, publish_function=None, parent=None):
298 super(ActionsResultsButtons, self).__init__(path, '', parent, False)
299 self.publish_function = publish_function
300
301 btn_publish = QtGui.QPushButton(SHARE_FILE)
302 btn_publish.setObjectName('action_button')
303 self.hbox.addWidget(btn_publish)
304 btn_publish.clicked.connect(self.publish_file)
305
306 def publish_file(self):
307 """Publish the file specified."""
308 if self.publish_function is not None:
309 self.publish_function(self.path)
310
311
243class EnhancedLineEdit(object):312class EnhancedLineEdit(object):
244 """Add a button inside the QLineEdit received."""313 """Add a button inside the QLineEdit received."""
245314
246315
=== modified file 'ubuntuone/controlpanel/gui/qt/share_links_search.py'
--- ubuntuone/controlpanel/gui/qt/share_links_search.py 2012-10-29 14:00:16 +0000
+++ ubuntuone/controlpanel/gui/qt/share_links_search.py 2012-11-02 13:27:26 +0000
@@ -25,10 +25,17 @@
2525
26from ubuntuone.controlpanel import cache26from ubuntuone.controlpanel import cache
27from ubuntuone.controlpanel.logger import setup_logging27from ubuntuone.controlpanel.logger import setup_logging
28from ubuntuone.controlpanel.gui import (
29 NO_RESULTS,
30 SEARCH_FOR,
31 SHARE_THESE_FILES,
32)
2833
29logger = setup_logging('qt.share_links_search')34logger = setup_logging('qt.share_links_search')
3035
31HOME_DIR = ''36HOME_DIR = ''
37AVOID_SECOND_ITEM = 2
38NORMAL_INCREMENT = 1
3239
3340
34def get_system_icon_for_filename(file_path):41def get_system_icon_for_filename(file_path):
@@ -45,6 +52,7 @@
45 """Search widget for the synced files."""52 """Search widget for the synced files."""
4653
47 itemSelected = QtCore.pyqtSignal(unicode)54 itemSelected = QtCore.pyqtSignal(unicode)
55 filesFound = QtCore.pyqtSignal(list, unicode)
4856
49 def __init__(self, parent=None):57 def __init__(self, parent=None):
50 super(SearchBox, self).__init__(parent)58 super(SearchBox, self).__init__(parent)
@@ -56,9 +64,6 @@
56 self.items_step = 2064 self.items_step = 20
57 self.prefix = ''65 self.prefix = ''
58 self._thread_explore = None66 self._thread_explore = None
59 self._pre_key_event = {
60 QtCore.Qt.Key_Space: self._key_space_pressed,
61 }
62 self._post_key_event = {67 self._post_key_event = {
63 QtCore.Qt.Key_Escape: lambda *args: self.popup.hide(),68 QtCore.Qt.Key_Escape: lambda *args: self.popup.hide(),
64 QtCore.Qt.Key_Down: self._key_down_pressed,69 QtCore.Qt.Key_Down: self._key_down_pressed,
@@ -112,7 +117,7 @@
112 self.temp_u1_files = [filename for filename in self.temp_u1_files117 self.temp_u1_files = [filename for filename in self.temp_u1_files
113 if os.path.basename(filename).find(self.prefix) > -1]118 if os.path.basename(filename).find(self.prefix) > -1]
114 files = self._get_filtered_list(self.temp_u1_files)119 files = self._get_filtered_list(self.temp_u1_files)
115 self.popup.load_items(files)120 self.popup.load_items(files, self.prefix)
116121
117 def _get_filtered_list(self, filenames):122 def _get_filtered_list(self, filenames):
118 """Get pages of results."""123 """Get pages of results."""
@@ -121,34 +126,28 @@
121 files = [filename for filename in filenames[begin:self.items_per_page]]126 files = [filename for filename in filenames[begin:self.items_per_page]]
122 return files127 return files
123128
124 def _key_space_pressed(self):129 def _key_down_pressed(self, focus_index):
125 """The user pressed the space key."""
126 item = self.popup.list_widget.currentItem()
127 if item is None:
128 return False
129 widget = self.popup.list_widget.itemWidget(item)
130 self.setText(widget.name)
131 self.popup.hide()
132 return True
133
134 def _key_down_pressed(self, current):
135 """The user pressed the down key."""130 """The user pressed the down key."""
136 #While the current position is lower that the list size go to next131 #While the current position is lower that the list size go to next
137 if current != self.popup.list_widget.count() - 1:132 if focus_index != self.popup.list_widget.count() - 1:
133 list_offset = (AVOID_SECOND_ITEM if focus_index == 0 else
134 NORMAL_INCREMENT)
138 self.popup.list_widget.setCurrentRow(135 self.popup.list_widget.setCurrentRow(
139 self.popup.list_widget.currentRow() + 1)136 self.popup.list_widget.currentRow() + list_offset)
140 #If the current position is greater than the amount of items in137 #If the current position is greater than the amount of items in
141 #the list - 6, then try to fetch more items in the list.138 #the list - 6, then try to fetch more items in the list.
142 if current >= (self.popup.list_widget.count() - 6):139 if focus_index >= (self.popup.list_widget.count() - 6):
143 filenames = self._get_filtered_list(self.temp_u1_files)140 filenames = self._get_filtered_list(self.temp_u1_files)
144 self.popup.fetch_more(filenames)141 self.popup.fetch_more(filenames)
145142
146 def _key_up_pressed(self, current):143 def _key_up_pressed(self, focus_index):
147 """The user pressed the up key."""144 """The user pressed the up key."""
148 #while the current position is greater than 0, go to previous145 #while the current position is greater than 0, go to previous
149 if current > 0:146 if focus_index > 0:
147 list_offset = (AVOID_SECOND_ITEM if focus_index == 2 else
148 NORMAL_INCREMENT)
150 self.popup.list_widget.setCurrentRow(149 self.popup.list_widget.setCurrentRow(
151 self.popup.list_widget.currentRow() - 1)150 self.popup.list_widget.currentRow() - list_offset)
152151
153 def _key_return_pressed(self, current):152 def _key_return_pressed(self, current):
154 """The user pressed the return key."""153 """The user pressed the return key."""
@@ -158,9 +157,6 @@
158157
159 def keyPressEvent(self, event):158 def keyPressEvent(self, event):
160 """Process the different behaviour for the keyPress event."""159 """Process the different behaviour for the keyPress event."""
161 if self._pre_key_event.get(event.key(), lambda: False)():
162 return
163
164 super(SearchBox, self).keyPressEvent(event)160 super(SearchBox, self).keyPressEvent(event)
165 current = self.popup.list_widget.currentRow()161 current = self.popup.list_widget.currentRow()
166 self._post_key_event.get(event.key(), lambda *args: None)(current)162 self._post_key_event.get(event.key(), lambda *args: None)(current)
@@ -173,8 +169,11 @@
173 def _set_selected_item(self, item):169 def _set_selected_item(self, item):
174 """Notify of the selected item."""170 """Notify of the selected item."""
175 widget = self.popup.list_widget.itemWidget(item)171 widget = self.popup.list_widget.itemWidget(item)
176 self.itemSelected.emit(widget.file_path)172 if widget is not None:
177 self.setText('')173 self.itemSelected.emit(widget.file_path)
174 self.setText('')
175 else:
176 self.filesFound.emit(self.temp_u1_files, self.prefix)
178 self.popup.hide()177 self.popup.hide()
179178
180 def moveEvent(self, event):179 def moveEvent(self, event):
@@ -242,14 +241,36 @@
242 """Set the proper style for the current and previous items."""241 """Set the proper style for the current and previous items."""
243 if current is not None:242 if current is not None:
244 widget = self.list_widget.itemWidget(current)243 widget = self.list_widget.itemWidget(current)
245 widget.set_selected()244 if widget is not None:
245 widget.set_selected()
246 if previous is not None:246 if previous is not None:
247 widget = self.list_widget.itemWidget(previous)247 widget = self.list_widget.itemWidget(previous)
248 widget.set_not_selected()248 if widget is not None:
249249 widget.set_not_selected()
250 def load_items(self, file_items):250
251 def _add_special_item(self, text):
252 """Add special items to the popup."""
253 item = QtGui.QListWidgetItem(text)
254 font = item.font()
255 font.setBold(True)
256 item.setSizeHint(QtCore.QSize(20, 30))
257 item.setBackground(QtGui.QBrush(QtCore.Qt.lightGray))
258 item.setForeground(QtGui.QBrush(QtCore.Qt.black))
259 item.setFont(font)
260 return item
261
262 def load_items(self, file_items, search_text):
251 """Load the initial items."""263 """Load the initial items."""
252 self.list_widget.clear()264 self.list_widget.clear()
265 # Search item
266 self.list_widget.addItem(self._add_special_item(
267 SEARCH_FOR % search_text))
268 # Message item
269 if len(file_items) > 0:
270 message_publish = self._add_special_item(SHARE_THESE_FILES)
271 else:
272 message_publish = self._add_special_item(NO_RESULTS)
273 self.list_widget.addItem(message_publish)
253 for file_ in file_items:274 for file_ in file_items:
254 item = QtGui.QListWidgetItem("\n")275 item = QtGui.QListWidgetItem("\n")
255 file_widget = FileItem(file_)276 file_widget = FileItem(file_)
@@ -257,8 +278,7 @@
257 self.list_widget.setItemWidget(item, file_widget)278 self.list_widget.setItemWidget(item, file_widget)
258 icon = get_system_icon_for_filename(file_.encode('utf-8'))279 icon = get_system_icon_for_filename(file_.encode('utf-8'))
259 item.setIcon(icon)280 item.setIcon(icon)
260 if file_items:281 self.list_widget.setCurrentRow(0)
261 self.list_widget.setCurrentRow(0)
262282
263 def fetch_more(self, file_items):283 def fetch_more(self, file_items):
264 """Add more items to the list on user scroll."""284 """Add more items to the list on user scroll."""
265285
=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_share_links.py'
--- ubuntuone/controlpanel/gui/qt/tests/test_share_links.py 2012-10-23 14:24:16 +0000
+++ ubuntuone/controlpanel/gui/qt/tests/test_share_links.py 2012-11-02 13:27:26 +0000
@@ -57,6 +57,7 @@
57 QtCore.Qt.PointingHandCursor)57 QtCore.Qt.PointingHandCursor)
58 self.assertEqual(self.ui.ui.back_to_file_list.cursor().shape(),58 self.assertEqual(self.ui.ui.back_to_file_list.cursor().shape(),
59 QtCore.Qt.PointingHandCursor)59 QtCore.Qt.PointingHandCursor)
60 self.assertFalse(self.ui._enhanced_line.btn_operation.isVisible())
6061
61 def test_share_file(self):62 def test_share_file(self):
62 """Check that the state of the widgets on share_file."""63 """Check that the state of the widgets on share_file."""
@@ -76,6 +77,19 @@
76 self.assertEqual(len(data), 2)77 self.assertEqual(len(data), 2)
77 self.assertEqual(data[0], self.ui._file_shared)78 self.assertEqual(data[0], self.ui._file_shared)
7879
80 def test_open_file_properties(self):
81 """Check that we clean the Details Page before adding a new item."""
82 publicfiles = [
83 {'path': '/home/file1', 'public_url': 'http:ubuntuone.com/asd123'},
84 {'path': '/home/file2', 'public_url': 'http:ubuntuone.com/qwe456'},
85 ]
86 self.ui._load_public_files(publicfiles)
87 item = self.ui.ui.tree_shared_files.topLevelItem(0)
88 self.ui.ui.tree_shared_files.itemDoubleClicked.emit(item, 0)
89 self.assertEqual(self.ui.ui.hbox_share_file.count(), 1)
90 self.ui.ui.tree_shared_files.itemDoubleClicked.emit(item, 0)
91 self.assertEqual(self.ui.ui.hbox_share_file.count(), 1)
92
79 def test_share_file_actions(self):93 def test_share_file_actions(self):
80 """Check the behaviour of share_file buttons."""94 """Check the behaviour of share_file buttons."""
81 path = '/home/user/Ubuntu One/file1.txt'95 path = '/home/user/Ubuntu One/file1.txt'
@@ -91,7 +105,8 @@
91 info = {'public_url': 'http://ubuntuone.com/asd123'}105 info = {'public_url': 'http://ubuntuone.com/asd123'}
92 self.ui._file_shared(info)106 self.ui._file_shared(info)
93 self.assertEqual(self.ui.ui.line_copy_link.text(), info['public_url'])107 self.assertEqual(self.ui.ui.line_copy_link.text(), info['public_url'])
94 self.assertEqual(self.ui.ui.stacked_widget.currentIndex(), 1)108 self.assertEqual(self.ui.ui.stacked_widget.currentIndex(),
109 gui.FILE_DETAILS_INDEX)
95 self.assertFalse(self.ui.is_processing)110 self.assertFalse(self.ui.is_processing)
96111
97 def test_file_already_shared(self):112 def test_file_already_shared(self):
@@ -109,7 +124,8 @@
109 self.ui._shared_files = shared124 self.ui._shared_files = shared
110 self.ui.share_file(path)125 self.ui.share_file(path)
111 self.assertEqual(self.ui.ui.line_copy_link.text(), shared[path])126 self.assertEqual(self.ui.ui.line_copy_link.text(), shared[path])
112 self.assertEqual(self.ui.ui.stacked_widget.currentIndex(), 1)127 self.assertEqual(self.ui.ui.stacked_widget.currentIndex(),
128 gui.FILE_DETAILS_INDEX)
113 self.assertEqual(data, [])129 self.assertEqual(data, [])
114130
115 def test_open_in_browser(self):131 def test_open_in_browser(self):
@@ -133,7 +149,8 @@
133 def test_move_to_main_list(self):149 def test_move_to_main_list(self):
134 """Test that the stacked widget shows the proper index."""150 """Test that the stacked widget shows the proper index."""
135 self.ui._move_to_main_list()151 self.ui._move_to_main_list()
136 self.assertEqual(self.ui.ui.stacked_widget.currentIndex(), 0)152 self.assertEqual(self.ui.ui.stacked_widget.currentIndex(),
153 gui.SHARED_FILES_INDEX)
137154
138 def test_get_public_files(self):155 def test_get_public_files(self):
139 """Test that the proper actions are executed on files requested.."""156 """Test that the proper actions are executed on files requested.."""
@@ -142,7 +159,8 @@
142 data.append)159 data.append)
143 self.ui.get_public_files()160 self.ui.get_public_files()
144 self.assertTrue(self.ui.is_processing)161 self.assertTrue(self.ui.is_processing)
145 self.assertEqual(self.ui.ui.stacked_widget.currentIndex(), 0)162 self.assertEqual(self.ui.ui.stacked_widget.currentIndex(),
163 gui.SHARED_FILES_INDEX)
146 self.assertEqual(self.ui.home_dir, USER_HOME)164 self.assertEqual(self.ui.home_dir, USER_HOME)
147 self.assertEqual(len(data), 1)165 self.assertEqual(len(data), 1)
148 self.assertEqual(data[0], self.ui._load_public_files)166 self.assertEqual(data[0], self.ui._load_public_files)
@@ -194,6 +212,35 @@
194 actions = self.ui.ui.tree_shared_files.itemWidget(item, 2)212 actions = self.ui.ui.tree_shared_files.itemWidget(item, 2)
195 self.assertIsInstance(actions, gui.ActionsButtons)213 self.assertIsInstance(actions, gui.ActionsButtons)
196214
215 def test_load_search_results(self):
216 """Test if the list of public files is loaded properly."""
217 results = ['/home/file1', '/home/file2']
218 self.ui._load_search_results(results, 'file')
219 item = self.ui.ui.tree_search_results.topLevelItem(0)
220 self.assertEqual(item.text(0), os.path.basename('/home/file1'))
221 self.assertEqual(item.toolTip(0), '/home/file1')
222 actions = self.ui.ui.tree_search_results.itemWidget(item, 1)
223 self.assertIsInstance(actions, gui.ActionsResultsButtons)
224
225 item = self.ui.ui.tree_search_results.topLevelItem(1)
226 self.assertEqual(item.text(0), os.path.basename('/home/file2'))
227 self.assertEqual(item.toolTip(0), '/home/file2')
228 actions = self.ui.ui.tree_search_results.itemWidget(item, 1)
229 self.assertIsInstance(actions, gui.ActionsResultsButtons)
230
231 self.assertEqual(self.ui.ui.label_search_results.text(),
232 gui.SEARCH_RESULTS % 'file')
233 self.assertTrue(self.ui.ui.tree_search_results.isVisible())
234 self.assertFalse(self.ui.ui.label_no_results.isVisible())
235
236 def test_load_search_results_empty_list(self):
237 """Test if the list of public files is loaded properly."""
238 self.ui._load_search_results([], 'file')
239 self.assertEqual(self.ui.ui.label_search_results.text(),
240 gui.SEARCH_RESULTS % 'file')
241 self.assertFalse(self.ui.ui.tree_search_results.isVisible())
242 self.assertTrue(self.ui.ui.label_no_results.isVisible())
243
197 def test_tree_item_clicked(self):244 def test_tree_item_clicked(self):
198 """Check if the proper info is displayed when the item is clicked."""245 """Check if the proper info is displayed when the item is clicked."""
199 publicfiles = [246 publicfiles = [
200247
=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_share_links_search.py'
--- ubuntuone/controlpanel/gui/qt/tests/test_share_links_search.py 2012-10-29 18:30:31 +0000
+++ ubuntuone/controlpanel/gui/qt/tests/test_share_links_search.py 2012-11-02 13:27:26 +0000
@@ -87,7 +87,7 @@
87 self.ui.temp_u1_files = self.ui.backend.search_files('')87 self.ui.temp_u1_files = self.ui.backend.search_files('')
88 self.ui.temp_u1_files = self.ui.temp_u1_files * 488 self.ui.temp_u1_files = self.ui.temp_u1_files * 4
89 self.ui._load_items()89 self.ui._load_items()
90 self.assertEqual(self.ui.popup.list_widget.count(), 20)90 self.assertEqual(self.ui.popup.list_widget.count(), 22)
91 self.ui.popup.list_widget.setCurrentRow(91 self.ui.popup.list_widget.setCurrentRow(
92 self.ui.popup.list_widget.count() - 5)92 self.ui.popup.list_widget.count() - 5)
93 current = self.ui.popup.list_widget.currentRow()93 current = self.ui.popup.list_widget.currentRow()
@@ -120,7 +120,7 @@
120 self.ui.popup.setVisible(True)120 self.ui.popup.setVisible(True)
121 self.ui.temp_u1_files = self.ui.backend.search_files('')121 self.ui.temp_u1_files = self.ui.backend.search_files('')
122 self.ui._load_items()122 self.ui._load_items()
123 self.ui.popup.list_widget.setCurrentRow(1)123 self.ui.popup.list_widget.setCurrentRow(3)
124 current = self.ui.popup.list_widget.currentRow()124 current = self.ui.popup.list_widget.currentRow()
125 self.ui.itemSelected.connect(self.fake_slot)125 self.ui.itemSelected.connect(self.fake_slot)
126 self.ui._key_return_pressed(current)126 self.ui._key_return_pressed(current)
@@ -132,7 +132,7 @@
132 self.ui.temp_u1_files = self.ui.backend.search_files('')132 self.ui.temp_u1_files = self.ui.backend.search_files('')
133 self.ui.popup.setVisible(True)133 self.ui.popup.setVisible(True)
134 self.ui._load_items()134 self.ui._load_items()
135 self.ui.popup.list_widget.setCurrentRow(1)135 self.ui.popup.list_widget.setCurrentRow(3)
136 current = self.ui.popup.list_widget.currentItem()136 current = self.ui.popup.list_widget.currentItem()
137 self.ui.itemSelected.connect(self.fake_slot)137 self.ui.itemSelected.connect(self.fake_slot)
138 self.ui.popup.list_widget.itemPressed.emit(current)138 self.ui.popup.list_widget.itemPressed.emit(current)
@@ -150,29 +150,6 @@
150 expected = (([],), {})150 expected = (([],), {})
151 self.assertEqual(expected, self._called)151 self.assertEqual(expected, self._called)
152152
153 def test_key_space_pressed(self):
154 """Check the proper actions are executed on key space pressed."""
155 data = []
156
157 def fake_set_text(text):
158 """fake setText."""
159 data.append(text)
160
161 self.patch(self.ui, "setText", fake_set_text)
162 self.ui.popup.setVisible(True)
163 self.ui.temp_u1_files = self.ui.backend.search_files('')
164 self.ui._load_items()
165 self.ui.popup.list_widget.setCurrentRow(2)
166
167 self.ui._key_space_pressed()
168 expected = [os.path.basename(self.files[2])]
169 self.assertEqual(expected, data)
170
171 def test_key_space_pressed_without_selection(self):
172 """Check the proper actions are executed on key space pressed."""
173 self.ui.popup.list_widget.setCurrentItem(None)
174 self.assertFalse(self.ui._key_space_pressed())
175
176 def test_process_volumes_info(self):153 def test_process_volumes_info(self):
177 """Check that _process_volumes_info obtain the proper info."""154 """Check that _process_volumes_info obtain the proper info."""
178 self.ui.temp_u1_files = self.ui.backend.search_files('')155 self.ui.temp_u1_files = self.ui.backend.search_files('')
@@ -182,7 +159,7 @@
182 expected = self.files159 expected = self.files
183 expected.sort()160 expected.sort()
184 self.assertEqual(self.ui.temp_u1_files, expected)161 self.assertEqual(self.ui.temp_u1_files, expected)
185 self.assertEqual(self.ui.popup.list_widget.count(), 6)162 self.assertEqual(self.ui.popup.list_widget.count(), 8)
186163
187 def test_filter(self):164 def test_filter(self):
188 """Check the results of the filter."""165 """Check the results of the filter."""
@@ -212,7 +189,7 @@
212 self.patch(self.ui.popup, "isVisible", lambda: True)189 self.patch(self.ui.popup, "isVisible", lambda: True)
213 self.ui.temp_u1_files = self.ui.backend.search_files('')190 self.ui.temp_u1_files = self.ui.backend.search_files('')
214 self.ui._load_items()191 self.ui._load_items()
215 self.ui.popup.list_widget.setCurrentRow(0)192 self.ui.popup.list_widget.setCurrentRow(2)
216 item = self.ui.popup.list_widget.currentItem()193 item = self.ui.popup.list_widget.currentItem()
217 self.ui._set_selected_item(item)194 self.ui._set_selected_item(item)
218 self.assertEqual(self._called,195 self.assertEqual(self._called,
@@ -280,11 +257,11 @@
280 ]257 ]
281258
282 self.assertEqual(self.ui.list_widget.count(), 0)259 self.assertEqual(self.ui.list_widget.count(), 0)
283 self.ui.load_items(items)260 self.ui.load_items(items, '')
284 self.assertEqual(self.ui.list_widget.count(), 3)261 self.assertEqual(self.ui.list_widget.count(), 5)
285 # Check that we erase the list on reload262 # Check that we erase the list on reload
286 self.ui.load_items(items)263 self.ui.load_items(items, '')
287 self.assertEqual(self.ui.list_widget.count(), 3)264 self.assertEqual(self.ui.list_widget.count(), 5)
288265
289 def test_fetch_more(self):266 def test_fetch_more(self):
290 """Tests that the items are loaded properly."""267 """Tests that the items are loaded properly."""
@@ -295,10 +272,10 @@
295 ]272 ]
296273
297 self.assertEqual(self.ui.list_widget.count(), 0)274 self.assertEqual(self.ui.list_widget.count(), 0)
298 self.ui.load_items(items)275 self.ui.load_items(items, '')
299 self.assertEqual(self.ui.list_widget.count(), 3)276 self.assertEqual(self.ui.list_widget.count(), 5)
300 self.ui.fetch_more(items)277 self.ui.fetch_more(items)
301 self.assertEqual(self.ui.list_widget.count(), 6)278 self.assertEqual(self.ui.list_widget.count(), 8)
302279
303 def test_repaint_items(self):280 def test_repaint_items(self):
304 """Check the style of the items change acording to the selection."""281 """Check the style of the items change acording to the selection."""
@@ -308,10 +285,11 @@
308 '/home/tester/file3',285 '/home/tester/file3',
309 ]286 ]
310287
311 self.ui.load_items(items)288 self.ui.load_items(items, '')
312 current = self.ui.list_widget.item(0)289 self.ui.list_widget.setCurrentRow(2)
290 current = self.ui.list_widget.item(2)
313 widget = self.ui.list_widget.itemWidget(current)291 widget = self.ui.list_widget.itemWidget(current)
314 next_ = self.ui.list_widget.item(1)292 next_ = self.ui.list_widget.item(3)
315 widget2 = self.ui.list_widget.itemWidget(next_)293 widget2 = self.ui.list_widget.itemWidget(next_)
316 name = os.path.basename('/home/tester/file1')294 name = os.path.basename('/home/tester/file1')
317 style = self.text_style.format(name, '/home/tester/file1',295 style = self.text_style.format(name, '/home/tester/file1',
@@ -322,10 +300,10 @@
322 self.assertEqual(widget.text(), style)300 self.assertEqual(widget.text(), style)
323 self.assertEqual(widget2.text(), style2)301 self.assertEqual(widget2.text(), style2)
324302
325 self.ui.list_widget.setCurrentRow(1)303 self.ui.list_widget.setCurrentRow(3)
326 current = self.ui.list_widget.item(1)304 current = self.ui.list_widget.item(3)
327 widget = self.ui.list_widget.itemWidget(current)305 widget = self.ui.list_widget.itemWidget(current)
328 previous = self.ui.list_widget.item(0)306 previous = self.ui.list_widget.item(2)
329 widget2 = self.ui.list_widget.itemWidget(previous)307 widget2 = self.ui.list_widget.itemWidget(previous)
330 name = os.path.basename('/home/tester/file2')308 name = os.path.basename('/home/tester/file2')
331 style = self.text_style.format(name, '/home/tester/file2',309 style = self.text_style.format(name, '/home/tester/file2',
@@ -335,3 +313,31 @@
335 '#333333', 'grey')313 '#333333', 'grey')
336 self.assertEqual(widget.text(), style)314 self.assertEqual(widget.text(), style)
337 self.assertEqual(widget2.text(), style2)315 self.assertEqual(widget2.text(), style2)
316
317 def test_first_list_item(self):
318 """Check that the first item in the popup has the proper string."""
319 self.ui.load_items([], 'file')
320 current = self.ui.list_widget.item(0)
321 text = current.text()
322 expected = gui.SEARCH_FOR % 'file'
323 self.assertEqual(expected, text)
324
325 def test_second_list_item_for_empty_list(self):
326 """Check that the second item in the popup has the proper string."""
327 self.ui.load_items([], 'file')
328 current = self.ui.list_widget.item(1)
329 text = current.text()
330 self.assertEqual(gui.NO_RESULTS, text)
331
332 def test_second_list_item(self):
333 """Check that the second item in the popup has the proper string."""
334 items = [
335 '/home/tester/file1',
336 '/home/tester/file2',
337 '/home/tester/file3',
338 ]
339
340 self.ui.load_items(items, 'file')
341 current = self.ui.list_widget.item(1)
342 text = current.text()
343 self.assertEqual(gui.SHARE_THESE_FILES, text)

Subscribers

People subscribed via source and target branches