Merge lp:~diegosarmentero/ubuntuone-control-panel/not-share-again into lp:ubuntuone-control-panel

Proposed by Diego Sarmentero on 2012-09-26
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
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) 2012-09-26 Needs Fixing on 2012-09-26
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).

To post a comment you must log in.
361. By Diego Sarmentero on 2012-09-26

adding missing docstring

Alejandro J. Cura (alecu) wrote :

Please use a replacement for os.path.expanduser that gracefuly handles unicode paths.

review: Needs Fixing
362. By Diego Sarmentero on 2012-09-28

Fixed tests

363. By Diego Sarmentero on 2012-09-28

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
6 from PyQt4 import QtGui, QtCore
7
8+from ubuntuone.platform import expand_user
9+
10 from ubuntuone.controlpanel import cache
11 from ubuntuone.controlpanel.gui.qt.share_links_search import (
12 get_system_icon_for_filename,
13@@ -40,11 +42,12 @@
14 super(ShareFileWidget, self).__init__(*args, **kwargs)
15 self.ui = share_file_ui.Ui_Form()
16 self.ui.setupUi(self)
17- self.file_path = file_path
18+ full_path = expand_user(file_path.encode('utf-8'))
19+ self.file_path = full_path.decode('utf-8')
20
21 self.ui.lbl_filename.setText(os.path.basename(file_path))
22 self.ui.lbl_path.setText(file_path)
23- icon = get_system_icon_for_filename(os.path.expanduser(file_path))
24+ icon = get_system_icon_for_filename(full_path)
25 pixmap = icon.pixmap(24)
26 self.ui.lbl_icon.setPixmap(pixmap)
27
28@@ -53,11 +56,10 @@
29
30 def open_file(self):
31 """Open the specified file."""
32- path = u'file://%s' % self.file_path
33+ path = 'file://%s' % self.file_path
34 QtGui.QDesktopServices.openUrl(QtCore.QUrl(path))
35
36 def disable_link(self, val):
37 """Change the access of the file to Not Public."""
38- self.backend.change_public_access(
39- os.path.expanduser(self.file_path), False)
40+ self.backend.change_public_access(self.file_path, False)
41 self.linkDisabled.emit()
42
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 from PyQt4 import QtGui, QtCore
48 from twisted.internet.defer import inlineCallbacks
49
50+from ubuntuone.platform import expand_user
51+
52 from ubuntuone.controlpanel.logger import setup_logging
53 from ubuntuone.controlpanel.gui import (
54 COPY_LINK,
55@@ -57,6 +59,7 @@
56 logger = logger
57 _enhanced_line = None
58 home_dir = ''
59+ _shared_files = {}
60
61 def _setup(self):
62 """Do some extra setupping for the UI."""
63@@ -91,17 +94,26 @@
64 @inlineCallbacks
65 def share_file(self, file_path):
66 """Clean the previous file share details and publish file_path."""
67+ file_path = unicode(file_path)
68 if self.ui.hbox_share_file.count() > 0:
69 widget = self.ui.hbox_share_file.takeAt(0).widget()
70 widget.close()
71- self.is_processing = True
72- file_path = unicode(file_path)
73- share_file_widget = ShareFileWidget(file_path)
74- self.ui.hbox_share_file.addWidget(share_file_widget)
75- share_file_widget.linkDisabled.connect(
76- lambda: self.ui.line_copy_link.setText(''))
77- yield self.backend.change_public_access(
78- os.path.expanduser(file_path), True)
79+ full_path = expand_user(file_path.encode('utf-8')).decode('utf-8')
80+ if full_path not in self._shared_files:
81+ self.is_processing = True
82+ share_file_widget = ShareFileWidget(file_path)
83+ self.ui.hbox_share_file.addWidget(share_file_widget)
84+ share_file_widget.linkDisabled.connect(
85+ lambda: self.ui.line_copy_link.setText(''))
86+ yield self.backend.change_public_access(
87+ full_path, True)
88+ else:
89+ share_file_widget = ShareFileWidget(file_path)
90+ self.ui.hbox_share_file.addWidget(share_file_widget)
91+ share_file_widget.linkDisabled.connect(
92+ lambda: self.ui.line_copy_link.setText(''))
93+ self.ui.line_copy_link.setText(self._shared_files[full_path])
94+ self.ui.stacked_widget.setCurrentIndex(1)
95
96 def _file_shared(self, info):
97 """Receive the notification that the file has been published."""
98@@ -135,17 +147,19 @@
99 def _load_public_files(self, publicfiles):
100 """Load the list of public files."""
101 self.ui.tree_shared_files.clear()
102+ self._shared_files = {}
103 for pfile in publicfiles:
104 item = QtGui.QTreeWidgetItem()
105 path = pfile['path']
106 public_url = pfile['public_url']
107+ self._shared_files[path] = public_url
108 name = os.path.basename(path)
109 item.setText(FILE_NAME_COL, name)
110 tooltip = path
111 if tooltip.startswith(self.home_dir):
112 tooltip = tooltip.replace(self.home_dir, '~', 1)
113 item.setToolTip(FILE_NAME_COL, tooltip)
114- icon = get_system_icon_for_filename(path)
115+ icon = get_system_icon_for_filename(path.encode('utf-8'))
116 item.setIcon(FILE_NAME_COL, icon)
117
118 self.ui.tree_shared_files.setColumnWidth(PUBLIC_LINK_COL, 300)
119
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 from PyQt4 import QtGui, QtCore
125 from twisted.internet.defer import inlineCallbacks
126
127+from ubuntuone.platform import expand_user
128+
129 from ubuntuone.controlpanel import cache
130 from ubuntuone.controlpanel.logger import setup_logging
131
132@@ -29,7 +31,7 @@
133
134 def get_system_icon_for_filename(file_path):
135 """Return the icon used for the system to represent this file."""
136- fileinfo = QtCore.QFileInfo(os.path.expanduser(file_path))
137+ fileinfo = QtCore.QFileInfo(expand_user(file_path))
138 icon_provider = QtGui.QFileIconProvider()
139 icon = icon_provider.icon(fileinfo)
140 return icon
141@@ -260,7 +262,7 @@
142 file_widget = FileItem(file_)
143 self.list_widget.addItem(item)
144 self.list_widget.setItemWidget(item, file_widget)
145- icon = get_system_icon_for_filename(file_)
146+ icon = get_system_icon_for_filename(file_.encode('utf-8'))
147 item.setIcon(icon)
148 if file_items:
149 self.list_widget.setCurrentRow(0)
150@@ -272,7 +274,7 @@
151 file_widget = FileItem(file_)
152 self.list_widget.addItem(item)
153 self.list_widget.setItemWidget(item, file_widget)
154- icon = get_system_icon_for_filename(file_)
155+ icon = get_system_icon_for_filename(file_.encode('utf-8'))
156 item.setIcon(icon)
157
158 def showEvent(self, event):
159
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
165 from PyQt4 import QtGui, QtCore
166
167+from ubuntuone.platform import expand_user
168+
169 from ubuntuone.controlpanel.gui.qt import share_file as gui
170 from ubuntuone.controlpanel.gui.qt.tests import (
171 BaseTestCase,
172@@ -54,7 +56,7 @@
173 self.patch(QtGui, "QDesktopServices", fake_desktop_service)
174 self.ui.ui.btn_open.click()
175
176- expected = QtCore.QUrl(u'file://%s' % self.file_path)
177+ expected = QtCore.QUrl('file://%s' % self.file_path)
178 self.assertEqual(expected, fake_desktop_service.opened_url)
179
180 def test_disable_link(self):
181@@ -71,6 +73,7 @@
182 fake_change_access)
183 self.ui.ui.btn_disable.click()
184
185- expected = [os.path.expanduser(self.file_path), False]
186+ expected = [expand_user(
187+ self.file_path.encode('utf-8')).decode('utf-8'), False]
188 self.assertEqual(data, expected)
189 self.assertEqual(self._called, ((), {}))
190
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 self.assertEqual(self.ui.ui.stacked_widget.currentIndex(), 1)
196 self.assertFalse(self.ui.is_processing)
197
198+ def test_file_already_shared(self):
199+ """Check the behavior of the widgets when there is a shared file."""
200+ data = []
201+
202+ def fake_method(self, *args):
203+ """Fake callback."""
204+ data.append((args))
205+
206+ self.patch(self.ui.backend, "change_public_access", fake_method)
207+ path = '/home/user/Ubuntu One/file1.txt'
208+ shared = {
209+ '/home/user/Ubuntu One/file1.txt': 'http://ubuntuone.com/asd123'}
210+ self.ui._shared_files = shared
211+ self.ui.share_file(path)
212+ self.assertEqual(self.ui.ui.line_copy_link.text(), shared[path])
213+ self.assertEqual(self.ui.ui.stacked_widget.currentIndex(), 1)
214+ self.assertEqual(data, [])
215+
216 def test_open_in_browser(self):
217 """Test the execution of open_in_browser."""
218 fake_desktop_service = FakeDesktopService()
219
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
225 import os
226
227+from dirspec import utils
228 from twisted.internet import defer
229
230 from ubuntuone.controlpanel.gui.tests import USER_HOME
231@@ -27,6 +28,7 @@
232
233 # pylint: disable=W0212
234
235+
236 class SearchBoxTestCase(BaseTestCase):
237 """Test the qt control panel."""
238
239@@ -36,6 +38,7 @@
240 def setUp(self):
241 yield super(SearchBoxTestCase, self).setUp()
242
243+ self.patch(utils, "user_home", USER_HOME)
244 self.patch(self.ui._thread_explore, "get_folder_info",
245 self.fake_get_folder_info)
246 self.patch(self.ui._thread_explore, "start",

Subscribers

People subscribed via source and target branches