Merge lp:~diegosarmentero/ubuntuone-control-panel/not-share-again into lp:ubuntuone-control-panel
- not-share-again
- Merge into trunk
Proposed by
Diego Sarmentero
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 361 | ||||
Proposed branch: | lp:~diegosarmentero/ubuntuone-control-panel/not-share-again | ||||
Merge into: | lp:ubuntuone-control-panel | ||||
Diff against target: |
246 lines (+61/-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 (+5/-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 (+3/-0) |
||||
To merge this branch: | bzr merge lp:~diegosarmentero/ubuntuone-control-panel/not-share-again | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alejandro J. Cura (community) | Needs Fixing | ||
Review via email: mp+126474@code.launchpad.net |
Commit message
- Check if the file was already shared, and use that info instead resharing the file (LP: #1056201).
Description of the change
To post a comment you must log in.
- 361. By Diego Sarmentero
-
adding missing docstring
- 362. By Diego Sarmentero
-
Fixed tests
- 363. By Diego Sarmentero
-
encoding problems fixed
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'ubuntuone/controlpanel/gui/qt/share_file.py' | |||
2 | --- ubuntuone/controlpanel/gui/qt/share_file.py 2012-08-27 15:00:01 +0000 | |||
3 | +++ ubuntuone/controlpanel/gui/qt/share_file.py 2012-09-28 20:28:23 +0000 | |||
4 | @@ -20,6 +20,8 @@ | |||
5 | 20 | 20 | ||
6 | 21 | from PyQt4 import QtGui, QtCore | 21 | from PyQt4 import QtGui, QtCore |
7 | 22 | 22 | ||
8 | 23 | from ubuntuone.platform import expand_user | ||
9 | 24 | |||
10 | 23 | from ubuntuone.controlpanel import cache | 25 | from ubuntuone.controlpanel import cache |
11 | 24 | from ubuntuone.controlpanel.gui.qt.share_links_search import ( | 26 | from ubuntuone.controlpanel.gui.qt.share_links_search import ( |
12 | 25 | get_system_icon_for_filename, | 27 | get_system_icon_for_filename, |
13 | @@ -40,11 +42,12 @@ | |||
14 | 40 | super(ShareFileWidget, self).__init__(*args, **kwargs) | 42 | super(ShareFileWidget, self).__init__(*args, **kwargs) |
15 | 41 | self.ui = share_file_ui.Ui_Form() | 43 | self.ui = share_file_ui.Ui_Form() |
16 | 42 | self.ui.setupUi(self) | 44 | self.ui.setupUi(self) |
18 | 43 | self.file_path = file_path | 45 | full_path = expand_user(file_path.encode('utf-8')) |
19 | 46 | self.file_path = full_path.decode('utf-8') | ||
20 | 44 | 47 | ||
21 | 45 | self.ui.lbl_filename.setText(os.path.basename(file_path)) | 48 | self.ui.lbl_filename.setText(os.path.basename(file_path)) |
22 | 46 | self.ui.lbl_path.setText(file_path) | 49 | self.ui.lbl_path.setText(file_path) |
24 | 47 | icon = get_system_icon_for_filename(os.path.expanduser(file_path)) | 50 | icon = get_system_icon_for_filename(full_path) |
25 | 48 | pixmap = icon.pixmap(24) | 51 | pixmap = icon.pixmap(24) |
26 | 49 | self.ui.lbl_icon.setPixmap(pixmap) | 52 | self.ui.lbl_icon.setPixmap(pixmap) |
27 | 50 | 53 | ||
28 | @@ -53,11 +56,10 @@ | |||
29 | 53 | 56 | ||
30 | 54 | def open_file(self): | 57 | def open_file(self): |
31 | 55 | """Open the specified file.""" | 58 | """Open the specified file.""" |
33 | 56 | path = u'file://%s' % self.file_path | 59 | path = 'file://%s' % self.file_path |
34 | 57 | QtGui.QDesktopServices.openUrl(QtCore.QUrl(path)) | 60 | QtGui.QDesktopServices.openUrl(QtCore.QUrl(path)) |
35 | 58 | 61 | ||
36 | 59 | def disable_link(self, val): | 62 | def disable_link(self, val): |
37 | 60 | """Change the access of the file to Not Public.""" | 63 | """Change the access of the file to Not Public.""" |
40 | 61 | self.backend.change_public_access( | 64 | self.backend.change_public_access(self.file_path, False) |
39 | 62 | os.path.expanduser(self.file_path), False) | ||
41 | 63 | self.linkDisabled.emit() | 65 | self.linkDisabled.emit() |
42 | 64 | 66 | ||
43 | === modified file 'ubuntuone/controlpanel/gui/qt/share_links.py' | |||
44 | --- ubuntuone/controlpanel/gui/qt/share_links.py 2012-08-27 15:00:01 +0000 | |||
45 | +++ ubuntuone/controlpanel/gui/qt/share_links.py 2012-09-28 20:28:23 +0000 | |||
46 | @@ -21,6 +21,8 @@ | |||
47 | 21 | from PyQt4 import QtGui, QtCore | 21 | from PyQt4 import QtGui, QtCore |
48 | 22 | from twisted.internet.defer import inlineCallbacks | 22 | from twisted.internet.defer import inlineCallbacks |
49 | 23 | 23 | ||
50 | 24 | from ubuntuone.platform import expand_user | ||
51 | 25 | |||
52 | 24 | from ubuntuone.controlpanel.logger import setup_logging | 26 | from ubuntuone.controlpanel.logger import setup_logging |
53 | 25 | from ubuntuone.controlpanel.gui import ( | 27 | from ubuntuone.controlpanel.gui import ( |
54 | 26 | COPY_LINK, | 28 | COPY_LINK, |
55 | @@ -57,6 +59,7 @@ | |||
56 | 57 | logger = logger | 59 | logger = logger |
57 | 58 | _enhanced_line = None | 60 | _enhanced_line = None |
58 | 59 | home_dir = '' | 61 | home_dir = '' |
59 | 62 | _shared_files = {} | ||
60 | 60 | 63 | ||
61 | 61 | def _setup(self): | 64 | def _setup(self): |
62 | 62 | """Do some extra setupping for the UI.""" | 65 | """Do some extra setupping for the UI.""" |
63 | @@ -91,17 +94,26 @@ | |||
64 | 91 | @inlineCallbacks | 94 | @inlineCallbacks |
65 | 92 | def share_file(self, file_path): | 95 | def share_file(self, file_path): |
66 | 93 | """Clean the previous file share details and publish file_path.""" | 96 | """Clean the previous file share details and publish file_path.""" |
67 | 97 | file_path = unicode(file_path) | ||
68 | 94 | if self.ui.hbox_share_file.count() > 0: | 98 | if self.ui.hbox_share_file.count() > 0: |
69 | 95 | widget = self.ui.hbox_share_file.takeAt(0).widget() | 99 | widget = self.ui.hbox_share_file.takeAt(0).widget() |
70 | 96 | widget.close() | 100 | widget.close() |
79 | 97 | self.is_processing = True | 101 | full_path = expand_user(file_path.encode('utf-8')).decode('utf-8') |
80 | 98 | file_path = unicode(file_path) | 102 | if full_path not in self._shared_files: |
81 | 99 | share_file_widget = ShareFileWidget(file_path) | 103 | self.is_processing = True |
82 | 100 | self.ui.hbox_share_file.addWidget(share_file_widget) | 104 | share_file_widget = ShareFileWidget(file_path) |
83 | 101 | share_file_widget.linkDisabled.connect( | 105 | self.ui.hbox_share_file.addWidget(share_file_widget) |
84 | 102 | lambda: self.ui.line_copy_link.setText('')) | 106 | share_file_widget.linkDisabled.connect( |
85 | 103 | yield self.backend.change_public_access( | 107 | lambda: self.ui.line_copy_link.setText('')) |
86 | 104 | os.path.expanduser(file_path), True) | 108 | yield self.backend.change_public_access( |
87 | 109 | full_path, True) | ||
88 | 110 | else: | ||
89 | 111 | share_file_widget = ShareFileWidget(file_path) | ||
90 | 112 | self.ui.hbox_share_file.addWidget(share_file_widget) | ||
91 | 113 | share_file_widget.linkDisabled.connect( | ||
92 | 114 | lambda: self.ui.line_copy_link.setText('')) | ||
93 | 115 | self.ui.line_copy_link.setText(self._shared_files[full_path]) | ||
94 | 116 | self.ui.stacked_widget.setCurrentIndex(1) | ||
95 | 105 | 117 | ||
96 | 106 | def _file_shared(self, info): | 118 | def _file_shared(self, info): |
97 | 107 | """Receive the notification that the file has been published.""" | 119 | """Receive the notification that the file has been published.""" |
98 | @@ -135,17 +147,19 @@ | |||
99 | 135 | def _load_public_files(self, publicfiles): | 147 | def _load_public_files(self, publicfiles): |
100 | 136 | """Load the list of public files.""" | 148 | """Load the list of public files.""" |
101 | 137 | self.ui.tree_shared_files.clear() | 149 | self.ui.tree_shared_files.clear() |
102 | 150 | self._shared_files = {} | ||
103 | 138 | for pfile in publicfiles: | 151 | for pfile in publicfiles: |
104 | 139 | item = QtGui.QTreeWidgetItem() | 152 | item = QtGui.QTreeWidgetItem() |
105 | 140 | path = pfile['path'] | 153 | path = pfile['path'] |
106 | 141 | public_url = pfile['public_url'] | 154 | public_url = pfile['public_url'] |
107 | 155 | self._shared_files[path] = public_url | ||
108 | 142 | name = os.path.basename(path) | 156 | name = os.path.basename(path) |
109 | 143 | item.setText(FILE_NAME_COL, name) | 157 | item.setText(FILE_NAME_COL, name) |
110 | 144 | tooltip = path | 158 | tooltip = path |
111 | 145 | if tooltip.startswith(self.home_dir): | 159 | if tooltip.startswith(self.home_dir): |
112 | 146 | tooltip = tooltip.replace(self.home_dir, '~', 1) | 160 | tooltip = tooltip.replace(self.home_dir, '~', 1) |
113 | 147 | item.setToolTip(FILE_NAME_COL, tooltip) | 161 | item.setToolTip(FILE_NAME_COL, tooltip) |
115 | 148 | icon = get_system_icon_for_filename(path) | 162 | icon = get_system_icon_for_filename(path.encode('utf-8')) |
116 | 149 | item.setIcon(FILE_NAME_COL, icon) | 163 | item.setIcon(FILE_NAME_COL, icon) |
117 | 150 | 164 | ||
118 | 151 | self.ui.tree_shared_files.setColumnWidth(PUBLIC_LINK_COL, 300) | 165 | self.ui.tree_shared_files.setColumnWidth(PUBLIC_LINK_COL, 300) |
119 | 152 | 166 | ||
120 | === modified file 'ubuntuone/controlpanel/gui/qt/share_links_search.py' | |||
121 | --- ubuntuone/controlpanel/gui/qt/share_links_search.py 2012-09-14 20:23:13 +0000 | |||
122 | +++ ubuntuone/controlpanel/gui/qt/share_links_search.py 2012-09-28 20:28:23 +0000 | |||
123 | @@ -21,6 +21,8 @@ | |||
124 | 21 | from PyQt4 import QtGui, QtCore | 21 | from PyQt4 import QtGui, QtCore |
125 | 22 | from twisted.internet.defer import inlineCallbacks | 22 | from twisted.internet.defer import inlineCallbacks |
126 | 23 | 23 | ||
127 | 24 | from ubuntuone.platform import expand_user | ||
128 | 25 | |||
129 | 24 | from ubuntuone.controlpanel import cache | 26 | from ubuntuone.controlpanel import cache |
130 | 25 | from ubuntuone.controlpanel.logger import setup_logging | 27 | from ubuntuone.controlpanel.logger import setup_logging |
131 | 26 | 28 | ||
132 | @@ -29,7 +31,7 @@ | |||
133 | 29 | 31 | ||
134 | 30 | def get_system_icon_for_filename(file_path): | 32 | def get_system_icon_for_filename(file_path): |
135 | 31 | """Return the icon used for the system to represent this file.""" | 33 | """Return the icon used for the system to represent this file.""" |
137 | 32 | fileinfo = QtCore.QFileInfo(os.path.expanduser(file_path)) | 34 | fileinfo = QtCore.QFileInfo(expand_user(file_path)) |
138 | 33 | icon_provider = QtGui.QFileIconProvider() | 35 | icon_provider = QtGui.QFileIconProvider() |
139 | 34 | icon = icon_provider.icon(fileinfo) | 36 | icon = icon_provider.icon(fileinfo) |
140 | 35 | return icon | 37 | return icon |
141 | @@ -260,7 +262,7 @@ | |||
142 | 260 | file_widget = FileItem(file_) | 262 | file_widget = FileItem(file_) |
143 | 261 | self.list_widget.addItem(item) | 263 | self.list_widget.addItem(item) |
144 | 262 | self.list_widget.setItemWidget(item, file_widget) | 264 | self.list_widget.setItemWidget(item, file_widget) |
146 | 263 | icon = get_system_icon_for_filename(file_) | 265 | icon = get_system_icon_for_filename(file_.encode('utf-8')) |
147 | 264 | item.setIcon(icon) | 266 | item.setIcon(icon) |
148 | 265 | if file_items: | 267 | if file_items: |
149 | 266 | self.list_widget.setCurrentRow(0) | 268 | self.list_widget.setCurrentRow(0) |
150 | @@ -272,7 +274,7 @@ | |||
151 | 272 | file_widget = FileItem(file_) | 274 | file_widget = FileItem(file_) |
152 | 273 | self.list_widget.addItem(item) | 275 | self.list_widget.addItem(item) |
153 | 274 | self.list_widget.setItemWidget(item, file_widget) | 276 | self.list_widget.setItemWidget(item, file_widget) |
155 | 275 | icon = get_system_icon_for_filename(file_) | 277 | icon = get_system_icon_for_filename(file_.encode('utf-8')) |
156 | 276 | item.setIcon(icon) | 278 | item.setIcon(icon) |
157 | 277 | 279 | ||
158 | 278 | def showEvent(self, event): | 280 | def showEvent(self, event): |
159 | 279 | 281 | ||
160 | === modified file 'ubuntuone/controlpanel/gui/qt/tests/test_share_file.py' | |||
161 | --- ubuntuone/controlpanel/gui/qt/tests/test_share_file.py 2012-08-28 00:32:41 +0000 | |||
162 | +++ ubuntuone/controlpanel/gui/qt/tests/test_share_file.py 2012-09-28 20:28:23 +0000 | |||
163 | @@ -20,6 +20,8 @@ | |||
164 | 20 | 20 | ||
165 | 21 | from PyQt4 import QtGui, QtCore | 21 | from PyQt4 import QtGui, QtCore |
166 | 22 | 22 | ||
167 | 23 | from ubuntuone.platform import expand_user | ||
168 | 24 | |||
169 | 23 | from ubuntuone.controlpanel.gui.qt import share_file as gui | 25 | from ubuntuone.controlpanel.gui.qt import share_file as gui |
170 | 24 | from ubuntuone.controlpanel.gui.qt.tests import ( | 26 | from ubuntuone.controlpanel.gui.qt.tests import ( |
171 | 25 | BaseTestCase, | 27 | BaseTestCase, |
172 | @@ -54,7 +56,7 @@ | |||
173 | 54 | self.patch(QtGui, "QDesktopServices", fake_desktop_service) | 56 | self.patch(QtGui, "QDesktopServices", fake_desktop_service) |
174 | 55 | self.ui.ui.btn_open.click() | 57 | self.ui.ui.btn_open.click() |
175 | 56 | 58 | ||
177 | 57 | expected = QtCore.QUrl(u'file://%s' % self.file_path) | 59 | expected = QtCore.QUrl('file://%s' % self.file_path) |
178 | 58 | self.assertEqual(expected, fake_desktop_service.opened_url) | 60 | self.assertEqual(expected, fake_desktop_service.opened_url) |
179 | 59 | 61 | ||
180 | 60 | def test_disable_link(self): | 62 | def test_disable_link(self): |
181 | @@ -71,6 +73,7 @@ | |||
182 | 71 | fake_change_access) | 73 | fake_change_access) |
183 | 72 | self.ui.ui.btn_disable.click() | 74 | self.ui.ui.btn_disable.click() |
184 | 73 | 75 | ||
186 | 74 | expected = [os.path.expanduser(self.file_path), False] | 76 | expected = [expand_user( |
187 | 77 | self.file_path.encode('utf-8')).decode('utf-8'), False] | ||
188 | 75 | self.assertEqual(data, expected) | 78 | self.assertEqual(data, expected) |
189 | 76 | self.assertEqual(self._called, ((), {})) | 79 | self.assertEqual(self._called, ((), {})) |
190 | 77 | 80 | ||
191 | === modified file 'ubuntuone/controlpanel/gui/qt/tests/test_share_links.py' | |||
192 | --- ubuntuone/controlpanel/gui/qt/tests/test_share_links.py 2012-08-28 00:32:41 +0000 | |||
193 | +++ ubuntuone/controlpanel/gui/qt/tests/test_share_links.py 2012-09-28 20:28:23 +0000 | |||
194 | @@ -78,6 +78,24 @@ | |||
195 | 78 | self.assertEqual(self.ui.ui.stacked_widget.currentIndex(), 1) | 78 | self.assertEqual(self.ui.ui.stacked_widget.currentIndex(), 1) |
196 | 79 | self.assertFalse(self.ui.is_processing) | 79 | self.assertFalse(self.ui.is_processing) |
197 | 80 | 80 | ||
198 | 81 | def test_file_already_shared(self): | ||
199 | 82 | """Check the behavior of the widgets when there is a shared file.""" | ||
200 | 83 | data = [] | ||
201 | 84 | |||
202 | 85 | def fake_method(self, *args): | ||
203 | 86 | """Fake callback.""" | ||
204 | 87 | data.append((args)) | ||
205 | 88 | |||
206 | 89 | self.patch(self.ui.backend, "change_public_access", fake_method) | ||
207 | 90 | path = '/home/user/Ubuntu One/file1.txt' | ||
208 | 91 | shared = { | ||
209 | 92 | '/home/user/Ubuntu One/file1.txt': 'http://ubuntuone.com/asd123'} | ||
210 | 93 | self.ui._shared_files = shared | ||
211 | 94 | self.ui.share_file(path) | ||
212 | 95 | self.assertEqual(self.ui.ui.line_copy_link.text(), shared[path]) | ||
213 | 96 | self.assertEqual(self.ui.ui.stacked_widget.currentIndex(), 1) | ||
214 | 97 | self.assertEqual(data, []) | ||
215 | 98 | |||
216 | 81 | def test_open_in_browser(self): | 99 | def test_open_in_browser(self): |
217 | 82 | """Test the execution of open_in_browser.""" | 100 | """Test the execution of open_in_browser.""" |
218 | 83 | fake_desktop_service = FakeDesktopService() | 101 | fake_desktop_service = FakeDesktopService() |
219 | 84 | 102 | ||
220 | === modified file 'ubuntuone/controlpanel/gui/qt/tests/test_share_links_search.py' | |||
221 | --- ubuntuone/controlpanel/gui/qt/tests/test_share_links_search.py 2012-09-24 17:56:23 +0000 | |||
222 | +++ ubuntuone/controlpanel/gui/qt/tests/test_share_links_search.py 2012-09-28 20:28:23 +0000 | |||
223 | @@ -18,6 +18,7 @@ | |||
224 | 18 | 18 | ||
225 | 19 | import os | 19 | import os |
226 | 20 | 20 | ||
227 | 21 | from dirspec import utils | ||
228 | 21 | from twisted.internet import defer | 22 | from twisted.internet import defer |
229 | 22 | 23 | ||
230 | 23 | from ubuntuone.controlpanel.gui.tests import USER_HOME | 24 | from ubuntuone.controlpanel.gui.tests import USER_HOME |
231 | @@ -27,6 +28,7 @@ | |||
232 | 27 | 28 | ||
233 | 28 | # pylint: disable=W0212 | 29 | # pylint: disable=W0212 |
234 | 29 | 30 | ||
235 | 31 | |||
236 | 30 | class SearchBoxTestCase(BaseTestCase): | 32 | class SearchBoxTestCase(BaseTestCase): |
237 | 31 | """Test the qt control panel.""" | 33 | """Test the qt control panel.""" |
238 | 32 | 34 | ||
239 | @@ -36,6 +38,7 @@ | |||
240 | 36 | def setUp(self): | 38 | def setUp(self): |
241 | 37 | yield super(SearchBoxTestCase, self).setUp() | 39 | yield super(SearchBoxTestCase, self).setUp() |
242 | 38 | 40 | ||
243 | 41 | self.patch(utils, "user_home", USER_HOME) | ||
244 | 39 | self.patch(self.ui._thread_explore, "get_folder_info", | 42 | self.patch(self.ui._thread_explore, "get_folder_info", |
245 | 40 | self.fake_get_folder_info) | 43 | self.fake_get_folder_info) |
246 | 41 | self.patch(self.ui._thread_explore, "start", | 44 | self.patch(self.ui._thread_explore, "start", |
Please use a replacement for os.path.expanduser that gracefuly handles unicode paths.