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

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
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).

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

adding missing docstring

Revision history for this message
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

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
=== 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:28:23 +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:28:23 +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:28:23 +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
@@ -260,7 +262,7 @@
260 file_widget = FileItem(file_)262 file_widget = FileItem(file_)
261 self.list_widget.addItem(item)263 self.list_widget.addItem(item)
262 self.list_widget.setItemWidget(item, file_widget)264 self.list_widget.setItemWidget(item, file_widget)
263 icon = get_system_icon_for_filename(file_)265 icon = get_system_icon_for_filename(file_.encode('utf-8'))
264 item.setIcon(icon)266 item.setIcon(icon)
265 if file_items:267 if file_items:
266 self.list_widget.setCurrentRow(0)268 self.list_widget.setCurrentRow(0)
@@ -272,7 +274,7 @@
272 file_widget = FileItem(file_)274 file_widget = FileItem(file_)
273 self.list_widget.addItem(item)275 self.list_widget.addItem(item)
274 self.list_widget.setItemWidget(item, file_widget)276 self.list_widget.setItemWidget(item, file_widget)
275 icon = get_system_icon_for_filename(file_)277 icon = get_system_icon_for_filename(file_.encode('utf-8'))
276 item.setIcon(icon)278 item.setIcon(icon)
277279
278 def showEvent(self, event):280 def showEvent(self, event):
279281
=== 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:28:23 +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:28:23 +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:28:23 +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",

Subscribers

People subscribed via source and target branches