Merge lp:~diegosarmentero/ubuntuone-control-panel/mouse-events into lp:ubuntuone-control-panel

Proposed by Diego Sarmentero
Status: Merged
Approved by: dobey
Approved revision: 362
Merged at revision: 361
Proposed branch: lp:~diegosarmentero/ubuntuone-control-panel/mouse-events
Merge into: lp:ubuntuone-control-panel
Diff against target: 312 lines (+101/-19)
6 files modified
ubuntuone/controlpanel/gui/qt/share_file.py (+7/-5)
ubuntuone/controlpanel/gui/qt/share_links.py (+23/-9)
ubuntuone/controlpanel/gui/qt/share_links_search.py (+14/-3)
ubuntuone/controlpanel/gui/qt/tests/test_share_file.py (+5/-2)
ubuntuone/controlpanel/gui/qt/tests/test_share_links.py (+18/-0)
ubuntuone/controlpanel/gui/qt/tests/test_share_links_search.py (+34/-0)
To merge this branch: bzr merge lp:~diegosarmentero/ubuntuone-control-panel/mouse-events
Reviewer Review Type Date Requested Status
dobey (community) Approve
Roberto Alsina (community) Approve
Review via email: mp+126544@code.launchpad.net

Commit message

- Popup list accept mouse events (LP: #1056192).

To post a comment you must log in.
361. By Diego Sarmentero

merge

Revision history for this message
Roberto Alsina (ralsina) wrote :

looks good!

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

I am getting a lot of WARNING output to console, and some other debug info, along with a couple of AssertionErrors, when running this from your branch. Running the installed version of control-panel I have, doesn't do this.

review: Needs Fixing
362. By Diego Sarmentero

merge

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ubuntuone/controlpanel/gui/qt/share_file.py'
--- ubuntuone/controlpanel/gui/qt/share_file.py 2012-08-27 15:00:01 +0000
+++ ubuntuone/controlpanel/gui/qt/share_file.py 2012-09-28 20:31:21 +0000
@@ -20,6 +20,8 @@
2020
21from PyQt4 import QtGui, QtCore21from PyQt4 import QtGui, QtCore
2222
23from ubuntuone.platform import expand_user
24
23from ubuntuone.controlpanel import cache25from ubuntuone.controlpanel import cache
24from ubuntuone.controlpanel.gui.qt.share_links_search import (26from ubuntuone.controlpanel.gui.qt.share_links_search import (
25 get_system_icon_for_filename,27 get_system_icon_for_filename,
@@ -40,11 +42,12 @@
40 super(ShareFileWidget, self).__init__(*args, **kwargs)42 super(ShareFileWidget, self).__init__(*args, **kwargs)
41 self.ui = share_file_ui.Ui_Form()43 self.ui = share_file_ui.Ui_Form()
42 self.ui.setupUi(self)44 self.ui.setupUi(self)
43 self.file_path = file_path45 full_path = expand_user(file_path.encode('utf-8'))
46 self.file_path = full_path.decode('utf-8')
4447
45 self.ui.lbl_filename.setText(os.path.basename(file_path))48 self.ui.lbl_filename.setText(os.path.basename(file_path))
46 self.ui.lbl_path.setText(file_path)49 self.ui.lbl_path.setText(file_path)
47 icon = get_system_icon_for_filename(os.path.expanduser(file_path))50 icon = get_system_icon_for_filename(full_path)
48 pixmap = icon.pixmap(24)51 pixmap = icon.pixmap(24)
49 self.ui.lbl_icon.setPixmap(pixmap)52 self.ui.lbl_icon.setPixmap(pixmap)
5053
@@ -53,11 +56,10 @@
5356
54 def open_file(self):57 def open_file(self):
55 """Open the specified file."""58 """Open the specified file."""
56 path = u'file://%s' % self.file_path59 path = 'file://%s' % self.file_path
57 QtGui.QDesktopServices.openUrl(QtCore.QUrl(path))60 QtGui.QDesktopServices.openUrl(QtCore.QUrl(path))
5861
59 def disable_link(self, val):62 def disable_link(self, val):
60 """Change the access of the file to Not Public."""63 """Change the access of the file to Not Public."""
61 self.backend.change_public_access(64 self.backend.change_public_access(self.file_path, False)
62 os.path.expanduser(self.file_path), False)
63 self.linkDisabled.emit()65 self.linkDisabled.emit()
6466
=== modified file 'ubuntuone/controlpanel/gui/qt/share_links.py'
--- ubuntuone/controlpanel/gui/qt/share_links.py 2012-08-27 15:00:01 +0000
+++ ubuntuone/controlpanel/gui/qt/share_links.py 2012-09-28 20:31:21 +0000
@@ -21,6 +21,8 @@
21from PyQt4 import QtGui, QtCore21from PyQt4 import QtGui, QtCore
22from twisted.internet.defer import inlineCallbacks22from twisted.internet.defer import inlineCallbacks
2323
24from ubuntuone.platform import expand_user
25
24from ubuntuone.controlpanel.logger import setup_logging26from ubuntuone.controlpanel.logger import setup_logging
25from ubuntuone.controlpanel.gui import (27from ubuntuone.controlpanel.gui import (
26 COPY_LINK,28 COPY_LINK,
@@ -57,6 +59,7 @@
57 logger = logger59 logger = logger
58 _enhanced_line = None60 _enhanced_line = None
59 home_dir = ''61 home_dir = ''
62 _shared_files = {}
6063
61 def _setup(self):64 def _setup(self):
62 """Do some extra setupping for the UI."""65 """Do some extra setupping for the UI."""
@@ -91,17 +94,26 @@
91 @inlineCallbacks94 @inlineCallbacks
92 def share_file(self, file_path):95 def share_file(self, file_path):
93 """Clean the previous file share details and publish file_path."""96 """Clean the previous file share details and publish file_path."""
97 file_path = unicode(file_path)
94 if self.ui.hbox_share_file.count() > 0:98 if self.ui.hbox_share_file.count() > 0:
95 widget = self.ui.hbox_share_file.takeAt(0).widget()99 widget = self.ui.hbox_share_file.takeAt(0).widget()
96 widget.close()100 widget.close()
97 self.is_processing = True101 full_path = expand_user(file_path.encode('utf-8')).decode('utf-8')
98 file_path = unicode(file_path)102 if full_path not in self._shared_files:
99 share_file_widget = ShareFileWidget(file_path)103 self.is_processing = True
100 self.ui.hbox_share_file.addWidget(share_file_widget)104 share_file_widget = ShareFileWidget(file_path)
101 share_file_widget.linkDisabled.connect(105 self.ui.hbox_share_file.addWidget(share_file_widget)
102 lambda: self.ui.line_copy_link.setText(''))106 share_file_widget.linkDisabled.connect(
103 yield self.backend.change_public_access(107 lambda: self.ui.line_copy_link.setText(''))
104 os.path.expanduser(file_path), True)108 yield self.backend.change_public_access(
109 full_path, True)
110 else:
111 share_file_widget = ShareFileWidget(file_path)
112 self.ui.hbox_share_file.addWidget(share_file_widget)
113 share_file_widget.linkDisabled.connect(
114 lambda: self.ui.line_copy_link.setText(''))
115 self.ui.line_copy_link.setText(self._shared_files[full_path])
116 self.ui.stacked_widget.setCurrentIndex(1)
105117
106 def _file_shared(self, info):118 def _file_shared(self, info):
107 """Receive the notification that the file has been published."""119 """Receive the notification that the file has been published."""
@@ -135,17 +147,19 @@
135 def _load_public_files(self, publicfiles):147 def _load_public_files(self, publicfiles):
136 """Load the list of public files."""148 """Load the list of public files."""
137 self.ui.tree_shared_files.clear()149 self.ui.tree_shared_files.clear()
150 self._shared_files = {}
138 for pfile in publicfiles:151 for pfile in publicfiles:
139 item = QtGui.QTreeWidgetItem()152 item = QtGui.QTreeWidgetItem()
140 path = pfile['path']153 path = pfile['path']
141 public_url = pfile['public_url']154 public_url = pfile['public_url']
155 self._shared_files[path] = public_url
142 name = os.path.basename(path)156 name = os.path.basename(path)
143 item.setText(FILE_NAME_COL, name)157 item.setText(FILE_NAME_COL, name)
144 tooltip = path158 tooltip = path
145 if tooltip.startswith(self.home_dir):159 if tooltip.startswith(self.home_dir):
146 tooltip = tooltip.replace(self.home_dir, '~', 1)160 tooltip = tooltip.replace(self.home_dir, '~', 1)
147 item.setToolTip(FILE_NAME_COL, tooltip)161 item.setToolTip(FILE_NAME_COL, tooltip)
148 icon = get_system_icon_for_filename(path)162 icon = get_system_icon_for_filename(path.encode('utf-8'))
149 item.setIcon(FILE_NAME_COL, icon)163 item.setIcon(FILE_NAME_COL, icon)
150164
151 self.ui.tree_shared_files.setColumnWidth(PUBLIC_LINK_COL, 300)165 self.ui.tree_shared_files.setColumnWidth(PUBLIC_LINK_COL, 300)
152166
=== modified file 'ubuntuone/controlpanel/gui/qt/share_links_search.py'
--- ubuntuone/controlpanel/gui/qt/share_links_search.py 2012-09-14 20:23:13 +0000
+++ ubuntuone/controlpanel/gui/qt/share_links_search.py 2012-09-28 20:31:21 +0000
@@ -21,6 +21,8 @@
21from PyQt4 import QtGui, QtCore21from PyQt4 import QtGui, QtCore
22from twisted.internet.defer import inlineCallbacks22from twisted.internet.defer import inlineCallbacks
2323
24from ubuntuone.platform import expand_user
25
24from ubuntuone.controlpanel import cache26from ubuntuone.controlpanel import cache
25from ubuntuone.controlpanel.logger import setup_logging27from ubuntuone.controlpanel.logger import setup_logging
2628
@@ -29,7 +31,7 @@
2931
30def get_system_icon_for_filename(file_path):32def get_system_icon_for_filename(file_path):
31 """Return the icon used for the system to represent this file."""33 """Return the icon used for the system to represent this file."""
32 fileinfo = QtCore.QFileInfo(os.path.expanduser(file_path))34 fileinfo = QtCore.QFileInfo(expand_user(file_path))
33 icon_provider = QtGui.QFileIconProvider()35 icon_provider = QtGui.QFileIconProvider()
34 icon = icon_provider.icon(fileinfo)36 icon = icon_provider.icon(fileinfo)
35 return icon37 return icon
@@ -65,10 +67,19 @@
65 QtCore.Qt.Key_Enter: self._key_return_pressed,67 QtCore.Qt.Key_Enter: self._key_return_pressed,
66 }68 }
6769
70 self.popup.list_widget.itemPressed.connect(self._set_selected_item)
71 self.popup.list_widget.verticalScrollBar().valueChanged.connect(
72 self._scroll_fetch_more)
68 self.textChanged.connect(self.filter)73 self.textChanged.connect(self.filter)
6974
70 self._get_volumes_info()75 self._get_volumes_info()
7176
77 def _scroll_fetch_more(self, value):
78 """Fetch more items into the list on scroll."""
79 if self.popup.list_widget.verticalScrollBar().maximum() == value:
80 filenames = self._get_filtered_list(self.temp_u1_files)
81 self.popup.fetch_more(filenames)
82
72 @inlineCallbacks83 @inlineCallbacks
73 def _get_volumes_info(self):84 def _get_volumes_info(self):
74 """Get the volumes info."""85 """Get the volumes info."""
@@ -260,7 +271,7 @@
260 file_widget = FileItem(file_)271 file_widget = FileItem(file_)
261 self.list_widget.addItem(item)272 self.list_widget.addItem(item)
262 self.list_widget.setItemWidget(item, file_widget)273 self.list_widget.setItemWidget(item, file_widget)
263 icon = get_system_icon_for_filename(file_)274 icon = get_system_icon_for_filename(file_.encode('utf-8'))
264 item.setIcon(icon)275 item.setIcon(icon)
265 if file_items:276 if file_items:
266 self.list_widget.setCurrentRow(0)277 self.list_widget.setCurrentRow(0)
@@ -272,7 +283,7 @@
272 file_widget = FileItem(file_)283 file_widget = FileItem(file_)
273 self.list_widget.addItem(item)284 self.list_widget.addItem(item)
274 self.list_widget.setItemWidget(item, file_widget)285 self.list_widget.setItemWidget(item, file_widget)
275 icon = get_system_icon_for_filename(file_)286 icon = get_system_icon_for_filename(file_.encode('utf-8'))
276 item.setIcon(icon)287 item.setIcon(icon)
277288
278 def showEvent(self, event):289 def showEvent(self, event):
279290
=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_share_file.py'
--- ubuntuone/controlpanel/gui/qt/tests/test_share_file.py 2012-08-28 00:32:41 +0000
+++ ubuntuone/controlpanel/gui/qt/tests/test_share_file.py 2012-09-28 20:31:21 +0000
@@ -20,6 +20,8 @@
2020
21from PyQt4 import QtGui, QtCore21from PyQt4 import QtGui, QtCore
2222
23from ubuntuone.platform import expand_user
24
23from ubuntuone.controlpanel.gui.qt import share_file as gui25from ubuntuone.controlpanel.gui.qt import share_file as gui
24from ubuntuone.controlpanel.gui.qt.tests import (26from ubuntuone.controlpanel.gui.qt.tests import (
25 BaseTestCase,27 BaseTestCase,
@@ -54,7 +56,7 @@
54 self.patch(QtGui, "QDesktopServices", fake_desktop_service)56 self.patch(QtGui, "QDesktopServices", fake_desktop_service)
55 self.ui.ui.btn_open.click()57 self.ui.ui.btn_open.click()
5658
57 expected = QtCore.QUrl(u'file://%s' % self.file_path)59 expected = QtCore.QUrl('file://%s' % self.file_path)
58 self.assertEqual(expected, fake_desktop_service.opened_url)60 self.assertEqual(expected, fake_desktop_service.opened_url)
5961
60 def test_disable_link(self):62 def test_disable_link(self):
@@ -71,6 +73,7 @@
71 fake_change_access)73 fake_change_access)
72 self.ui.ui.btn_disable.click()74 self.ui.ui.btn_disable.click()
7375
74 expected = [os.path.expanduser(self.file_path), False]76 expected = [expand_user(
77 self.file_path.encode('utf-8')).decode('utf-8'), False]
75 self.assertEqual(data, expected)78 self.assertEqual(data, expected)
76 self.assertEqual(self._called, ((), {}))79 self.assertEqual(self._called, ((), {}))
7780
=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_share_links.py'
--- ubuntuone/controlpanel/gui/qt/tests/test_share_links.py 2012-08-28 00:32:41 +0000
+++ ubuntuone/controlpanel/gui/qt/tests/test_share_links.py 2012-09-28 20:31:21 +0000
@@ -78,6 +78,24 @@
78 self.assertEqual(self.ui.ui.stacked_widget.currentIndex(), 1)78 self.assertEqual(self.ui.ui.stacked_widget.currentIndex(), 1)
79 self.assertFalse(self.ui.is_processing)79 self.assertFalse(self.ui.is_processing)
8080
81 def test_file_already_shared(self):
82 """Check the behavior of the widgets when there is a shared file."""
83 data = []
84
85 def fake_method(self, *args):
86 """Fake callback."""
87 data.append((args))
88
89 self.patch(self.ui.backend, "change_public_access", fake_method)
90 path = '/home/user/Ubuntu One/file1.txt'
91 shared = {
92 '/home/user/Ubuntu One/file1.txt': 'http://ubuntuone.com/asd123'}
93 self.ui._shared_files = shared
94 self.ui.share_file(path)
95 self.assertEqual(self.ui.ui.line_copy_link.text(), shared[path])
96 self.assertEqual(self.ui.ui.stacked_widget.currentIndex(), 1)
97 self.assertEqual(data, [])
98
81 def test_open_in_browser(self):99 def test_open_in_browser(self):
82 """Test the execution of open_in_browser."""100 """Test the execution of open_in_browser."""
83 fake_desktop_service = FakeDesktopService()101 fake_desktop_service = FakeDesktopService()
84102
=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_share_links_search.py'
--- ubuntuone/controlpanel/gui/qt/tests/test_share_links_search.py 2012-09-24 17:56:23 +0000
+++ ubuntuone/controlpanel/gui/qt/tests/test_share_links_search.py 2012-09-28 20:31:21 +0000
@@ -18,6 +18,7 @@
1818
19import os19import os
2020
21from dirspec import utils
21from twisted.internet import defer22from twisted.internet import defer
2223
23from ubuntuone.controlpanel.gui.tests import USER_HOME24from ubuntuone.controlpanel.gui.tests import USER_HOME
@@ -27,6 +28,7 @@
2728
28# pylint: disable=W021229# pylint: disable=W0212
2930
31
30class SearchBoxTestCase(BaseTestCase):32class SearchBoxTestCase(BaseTestCase):
31 """Test the qt control panel."""33 """Test the qt control panel."""
3234
@@ -36,6 +38,7 @@
36 def setUp(self):38 def setUp(self):
37 yield super(SearchBoxTestCase, self).setUp()39 yield super(SearchBoxTestCase, self).setUp()
3840
41 self.patch(utils, "user_home", USER_HOME)
39 self.patch(self.ui._thread_explore, "get_folder_info",42 self.patch(self.ui._thread_explore, "get_folder_info",
40 self.fake_get_folder_info)43 self.fake_get_folder_info)
41 self.patch(self.ui._thread_explore, "start",44 self.patch(self.ui._thread_explore, "start",
@@ -52,6 +55,11 @@
52 os.path.join(USER_HOME, 'blabla', 'iop'),55 os.path.join(USER_HOME, 'blabla', 'iop'),
53 ]56 ]
54 }57 }
58 self._slot_item = None
59
60 def fake_slot(self, item):
61 """Fake function to be called when itemSelected is emitted."""
62 self._slot_item = item
5563
56 def fake_get_folder_info(self, folder):64 def fake_get_folder_info(self, folder):
57 """Fake get_folder_info."""65 """Fake get_folder_info."""
@@ -132,7 +140,33 @@
132 self.ui._process_volumes_info([(0, 0, data1), (0, 0, data2)])140 self.ui._process_volumes_info([(0, 0, data1), (0, 0, data2)])
133 self.ui.popup.list_widget.setCurrentRow(1)141 self.ui.popup.list_widget.setCurrentRow(1)
134 current = self.ui.popup.list_widget.currentRow()142 current = self.ui.popup.list_widget.currentRow()
143 self.ui.itemSelected.connect(self.fake_slot)
135 self.ui._key_return_pressed(current)144 self.ui._key_return_pressed(current)
145 expected = unicode(self._slot_item).replace('~', USER_HOME)
146 self.assertEqual(expected, self.folder_info['folder2'][2])
147
148 def test_mouse_click_pressed(self):
149 """Check the proper actions are executed when click is pressed."""
150 data1 = [{'path': 'folder1'}]
151 data2 = [{'realpath': 'folder2'}]
152 self.ui._process_volumes_info([(0, 0, data1), (0, 0, data2)])
153 self.ui.popup.list_widget.setCurrentRow(1)
154 current = self.ui.popup.list_widget.currentItem()
155 self.ui.itemSelected.connect(self.fake_slot)
156 self.ui.popup.list_widget.itemPressed.emit(current)
157 expected = unicode(self._slot_item).replace('~', USER_HOME)
158 self.assertEqual(expected, self.folder_info['folder2'][2])
159
160 def test_mouse_scroll(self):
161 """Check that fetch_more is called when we reach the end of scroll."""
162 data1 = [{'path': 'folder1'}]
163 data2 = [{'realpath': 'folder2'}]
164 self.ui._process_volumes_info([(0, 0, data1), (0, 0, data2)])
165 self.patch(self.ui.popup, "fetch_more", self._set_called)
166 self.ui._scroll_fetch_more(
167 self.ui.popup.list_widget.verticalScrollBar().maximum())
168 expected = (([],), {})
169 self.assertEqual(expected, self._called)
136170
137 def test_key_space_pressed(self):171 def test_key_space_pressed(self):
138 """Check the proper actions are executed on key space pressed."""172 """Check the proper actions are executed on key space pressed."""

Subscribers

People subscribed via source and target branches