Merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-02 into lp:ubuntu-filemanager-app

Proposed by Carlos Jose Mazieri
Status: Merged
Approved by: Arto Jalkanen
Approved revision: 432
Merged at revision: 437
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-02
Merge into: lp:ubuntu-filemanager-app
Prerequisite: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-01
Diff against target: 413 lines (+118/-52)
7 files modified
src/plugin/folderlistmodel/diriteminfo.cpp (+3/-3)
src/plugin/folderlistmodel/dirmodel.cpp (+9/-9)
src/plugin/folderlistmodel/location.cpp (+24/-1)
src/plugin/folderlistmodel/location.h (+41/-0)
src/plugin/folderlistmodel/locationsfactory.cpp (+21/-15)
src/plugin/folderlistmodel/locationsfactory.h (+12/-16)
src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp (+8/-8)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-02
Reviewer Review Type Date Requested Status
Arto Jalkanen Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+265193@code.launchpad.net

Commit message

Enumerator Locations moved from class LocationsFactory to class Location
Created Location::isThereDiskSpace() which by default returns true, all locations can reimplement this method.
Created Location::isRemote(), Location::isLocalDisk() and Location::isTrashDisk() to handle more locations

Description of the change

Location class is improved:
   * Some methods from FileSystemAction will migrate to Location class
   * Added methods to identify if a Location object is Local/Remote

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Arto Jalkanen (ajalkane) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/plugin/folderlistmodel/diriteminfo.cpp'
2--- src/plugin/folderlistmodel/diriteminfo.cpp 2015-06-28 18:07:28 +0000
3+++ src/plugin/folderlistmodel/diriteminfo.cpp 2015-07-18 21:23:48 +0000
4@@ -457,15 +457,15 @@
5 //owner permissions
6 if (statBuffer.st_mode & S_IRUSR)
7 {
8- readPermission |= QFile::ReadOwner;
9+ readPermission |= QFile::ReadOwner | QFile::ReadUser;
10 }
11 if (statBuffer.st_mode & S_IWUSR)
12 {
13- writePermission |= QFile::WriteOwner;
14+ writePermission |= QFile::WriteOwner | QFile::WriteUser;
15 }
16 if (statBuffer.st_mode & S_IXUSR)
17 {
18- execPermission |= QFile::ExeOwner;
19+ execPermission |= QFile::ExeOwner | QFile::ExeUser;
20 }
21 //group permissions
22 if (statBuffer.st_mode & S_IRGRP)
23
24=== modified file 'src/plugin/folderlistmodel/dirmodel.cpp'
25--- src/plugin/folderlistmodel/dirmodel.cpp 2015-07-18 21:23:48 +0000
26+++ src/plugin/folderlistmodel/dirmodel.cpp 2015-07-18 21:23:48 +0000
27@@ -76,7 +76,7 @@
28
29 #define IS_FILE_MANAGER_IDLE() (!mAwaitingResults)
30
31-#define IS_BROWSING_TRASH_ROOTDIR() (mCurLocation && mCurLocation->type() == LocationsFactory::TrashDisk && mCurLocation->isRoot())
32+#define IS_BROWSING_TRASH_ROOTDIR() (mCurLocation && mCurLocation->isTrashDisk() && mCurLocation->isRoot())
33
34 namespace {
35 QHash<QByteArray, int> roleMapping;
36@@ -412,7 +412,7 @@
37 return fi.isBrowsable();
38 case IsSharingAllowedRole:
39 return fi.isDir() && !fi.isSymLink() && !fi.isSharedDir()
40- && mCurLocation->type() == LocationsFactory::LocalDisk
41+ && mCurLocation->isLocalDisk()
42 && fi.isWritable() && fi.isExecutable() && fi.isReadable();
43 case IsSharedDirRole:
44 return fi.isSharedDir();
45@@ -591,7 +591,7 @@
46 }
47
48 //if current location is Trash only in the root is allowed to remove Items
49- if (mCurLocation->type() == LocationsFactory::TrashDisk)
50+ if (mCurLocation->isTrashDisk())
51 {
52 if (IS_BROWSING_TRASH_ROOTDIR())
53 {
54@@ -788,8 +788,8 @@
55 }
56 ExternalFSWatcher * DirModel::getExternalFSWatcher() const
57 {
58- const Location *l = mLocationFactory->availableLocations().at(LocationsFactory::LocalDisk);
59- const DiskLocation *disk = static_cast<const DiskLocation*> (l);
60+ Location *l = mLocationFactory->getDiskLocation();
61+ DiskLocation *disk = static_cast<DiskLocation*> (l);
62 return disk->getExternalFSWatcher();
63 }
64 #endif
65@@ -885,8 +885,8 @@
66
67 void DirModel::paste()
68 {
69- // Restrict pasting if in restricted directory
70- if (!allowAccess(mCurrentDir)) {
71+ // Restrict pasting if in restricted directory when pasting on a local file system
72+ if (!mCurLocation->isRemote() && !allowAccess(mCurrentDir)) {
73 qDebug() << Q_FUNC_INFO << "access not allowed, pasting not done" << mCurrentDir;
74 return;
75 }
76@@ -1682,10 +1682,10 @@
77
78 void DirModel:: moveIndexesToTrash(const QList<int>& items)
79 {
80- if (mCurLocation->type() == LocationsFactory::LocalDisk)
81+ if (mCurLocation->isLocalDisk())
82 {
83 const TrashLocation *trashLocation = static_cast<const TrashLocation*>
84- (mLocationFactory->getLocation(LocationsFactory::TrashDisk));
85+ (mLocationFactory->getTrashLocation());
86 ActionPathList itemsAndTrashPath;
87 int index = 0;
88 for (int counter=0; counter < items.count(); ++counter)
89
90=== modified file 'src/plugin/folderlistmodel/location.cpp'
91--- src/plugin/folderlistmodel/location.cpp 2015-03-01 19:02:31 +0000
92+++ src/plugin/folderlistmodel/location.cpp 2015-07-18 21:23:48 +0000
93@@ -305,4 +305,27 @@
94 }
95 }
96
97-
98+/*
99+ * Each Location should have its implementation if it is possible
100+ */
101+bool Location::isThereDiskSpace(const QString &pathname, qint64 requiredSize)
102+{
103+ Q_UNUSED(pathname);
104+ Q_UNUSED(requiredSize);
105+ return true;
106+}
107+
108+
109+/*!
110+ * \brief Location::currentInfo()
111+ * \return the updated information about the current path
112+ */
113+const DirItemInfo *Location::currentInfo()
114+{
115+ if (m_info == 0)
116+ {
117+ m_info = new DirItemInfo();
118+ }
119+ refreshInfo(); //update information
120+ return m_info;
121+}
122
123=== modified file 'src/plugin/folderlistmodel/location.h'
124--- src/plugin/folderlistmodel/location.h 2015-03-01 15:32:42 +0000
125+++ src/plugin/folderlistmodel/location.h 2015-07-18 21:23:48 +0000
126@@ -47,6 +47,24 @@
127 {
128 Q_OBJECT
129 public:
130+
131+ Q_ENUMS(Locations)
132+ /*!
133+ * \brief The Locations enum defines which Locations are supported
134+ *
135+ * \note Items also work as indexes for \a m_locations, they must be 0..(n-1)
136+ */
137+ enum Locations
138+ {
139+ LocalDisk=0, //<! any mounted file system
140+ TrashDisk, //<! special trash location in the disk
141+ NetSambaShare //<! SAMBA or CIFS shares
142+#if 0
143+ NetFishShare //<! FISH protocol over ssh that provides file sharing
144+#endif
145+ };
146+
147+public:
148 virtual ~Location();
149 protected:
150 explicit Location( int type, QObject *parent=0);
151@@ -93,6 +111,21 @@
152
153 public:
154 /*!
155+ * \brief isThereDiskSpace() Check if the filesystem has enough space to put a file with size \a requiredSize
156+ *
157+ *
158+ * \param pathname is the full pathname of the new file that is going to be created
159+ *
160+ * \param requiredSize the size required
161+ *
162+ *
163+ * \note For remote locations if not is possible to get this value this function MUST return true
164+ *
165+ * The default implementation just returns true and let the copy fail if there is enough space
166+ */
167+ virtual bool isThereDiskSpace(const QString& pathname, qint64 requiredSize);
168+
169+ /*!
170 * \brief fetchItems() gets the content of the Location
171 *
172 * \param dirFilter current Filter
173@@ -131,6 +164,13 @@
174 */
175 virtual DirItemInfo * validateUrlPath(const QString& urlPath);
176
177+ /*!
178+ * \brief isRemote() It must return TRUE when type() is greater than Location::TrashDisk
179+ * \return
180+ */
181+ inline bool isRemote() const { return m_type > TrashDisk; }
182+ inline bool isLocalDisk() const { return m_type == LocalDisk;}
183+ inline bool isTrashDisk() const { return m_type == TrashDisk; }
184
185 public: //virtual
186 virtual void fetchExternalChanges(const QString& urlPath,
187@@ -153,6 +193,7 @@
188
189 inline const DirItemInfo* info() const { return m_info; }
190 inline int type() const { return m_type; }
191+ const DirItemInfo* currentInfo(); //updated information about the current path
192
193 protected:
194 DirItemInfo * m_info;
195
196=== modified file 'src/plugin/folderlistmodel/locationsfactory.cpp'
197--- src/plugin/folderlistmodel/locationsfactory.cpp 2015-06-28 18:07:28 +0000
198+++ src/plugin/folderlistmodel/locationsfactory.cpp 2015-07-18 21:23:48 +0000
199@@ -50,16 +50,9 @@
200 , m_authDataStore(NetAuthenticationDataList::getInstance(this))
201 , m_lastUrlNeedsAuthentication(false)
202 {
203- m_locations.append(new DiskLocation(LocalDisk));
204- m_locations.append(new TrashLocation(TrashDisk));
205- SmbLocation * smblocation = new SmbLocation(NetSambaShare);
206- m_locations.append(smblocation);
207-
208- // Qt::DirectConnection is used here
209- // it allows lastUrlNeedsAuthencation() to have the right flag
210- connect(smblocation, SIGNAL(needsAuthentication(QString,QString)),
211- this, SLOT(onUrlNeedsAuthentication(QString,QString)),
212- Qt::DirectConnection);
213+ addLocation(new DiskLocation(Location::LocalDisk));
214+ addLocation(new TrashLocation(Location::TrashDisk));
215+ addLocation(new SmbLocation(Location::NetSambaShare));
216 }
217
218 LocationsFactory::~LocationsFactory()
219@@ -92,7 +85,7 @@
220 #if defined(Q_OS_UNIX)
221 if (uPath.startsWith(LocationUrl::TrashRootURL.midRef(0,6)))
222 {
223- type = TrashDisk;
224+ type = Location::TrashDisk;
225 m_tmpPath = LocationUrl::TrashRootURL + DirItemInfo::removeExtraSlashes(uPath, index+1);
226 }
227 else
228@@ -100,7 +93,7 @@
229 #endif
230 if (uPath.startsWith(LocationUrl::DiskRootURL.midRef(0,5)))
231 {
232- type = LocalDisk;
233+ type = Location::LocalDisk;
234 m_tmpPath = QDir::rootPath() + DirItemInfo::removeExtraSlashes(uPath, index+1);
235 }
236 else
237@@ -108,14 +101,14 @@
238 uPath.startsWith(LocationUrl::CifsURL.midRef(0,5))
239 )
240 {
241- type = NetSambaShare;
242+ type = Location::NetSambaShare;
243 m_tmpPath = LocationUrl::SmbURL + DirItemInfo::removeExtraSlashes(uPath, index+1);
244 }
245 }
246 else
247 {
248 m_tmpPath = DirItemInfo::removeExtraSlashes(uPath, -1);
249- type = LocalDisk;
250+ type = Location::LocalDisk;
251 if (!m_tmpPath.startsWith(QDir::rootPath()) && m_curLoc)
252 {
253 //it can be any, check current location
254@@ -127,7 +120,7 @@
255 location = m_locations.at(type);
256 }
257 #if DEBUG_MESSAGES
258- qDebug() << Q_FUNC_INFO << "input path:" << uPath << "location result:" << location;
259+ qDebug() << Q_FUNC_INFO << "input path:" << uPath << "location:" << location << "type:" << type;
260 #endif
261 return location;
262 }
263@@ -246,3 +239,16 @@
264 }
265 return item;
266 }
267+
268+
269+void LocationsFactory::addLocation(Location *location)
270+{
271+ m_locations.append(location);
272+
273+ // Qt::DirectConnection is used here
274+ // it allows lastUrlNeedsAuthencation() to have the right flag
275+ connect(location, SIGNAL(needsAuthentication(QString,QString)),
276+ this, SLOT(onUrlNeedsAuthentication(QString,QString)),
277+ Qt::DirectConnection);
278+}
279+
280
281=== modified file 'src/plugin/folderlistmodel/locationsfactory.h'
282--- src/plugin/folderlistmodel/locationsfactory.h 2015-06-03 11:54:36 +0000
283+++ src/plugin/folderlistmodel/locationsfactory.h 2015-07-18 21:23:48 +0000
284@@ -22,11 +22,11 @@
285 #ifndef LOCATIONSFACTORY_H
286 #define LOCATIONSFACTORY_H
287
288+#include "location.h"
289+
290 #include <QObject>
291 #include <QList>
292
293-
294-class Location;
295 class DirItemInfo;
296 class NetAuthenticationDataList;
297 class NetAuthenticationData;
298@@ -57,19 +57,9 @@
299 explicit LocationsFactory(QObject *parent = 0);
300 ~LocationsFactory();
301
302- Q_ENUMS(Locations)
303- enum Locations
304- {
305- LocalDisk, //<! any mounted file system
306- TrashDisk, //<! special trash location in the disk
307- NetSambaShare //<! SAMBA or CIFS shares
308-#if 0
309- NetFishShare //<! FISH protocol over ssh that provides file sharing
310-#endif
311- };
312-
313- inline const Location * getLocation(Locations index) const {return m_locations.at(index);}
314-
315+ inline Location * getLocation(int index) const {return m_locations.at(index);}
316+ inline Location * getDiskLocation() const { return getLocation(Location::LocalDisk); }
317+ inline Location * getTrashLocation() const { return getLocation(Location::TrashDisk); }
318
319 /*!
320 * \brief parse() Just parses (does not set/change the current location) according to \a urlPath
321@@ -100,7 +90,7 @@
322 * \brief location()
323 * \return The current location
324 */
325- Location * location() const { return m_curLoc; }
326+ Location * currentLocation() const { return m_curLoc; }
327
328 /*!
329 * \brief availableLocations()
330@@ -155,6 +145,12 @@
331 */
332 DirItemInfo *validateCurrentUrl(Location *location, const NetAuthenticationData&);
333
334+ /*!
335+ * \brief addLocation() just appends the location in the list \ref m_locations and connect signals
336+ * \param location
337+ */
338+ void addLocation(Location * location);
339+
340 signals:
341 void locationChanged(const Location *old, const Location *current);
342
343
344=== modified file 'src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp'
345--- src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp 2015-06-28 18:07:28 +0000
346+++ src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp 2015-07-18 21:23:48 +0000
347@@ -2520,7 +2520,7 @@
348 #if 0 // "sheme:/" (single slash) is no longer supported
349 location = factoryLocations.setNewPath("trash:/");
350 QVERIFY(location);
351- QVERIFY(location->type() == LocationsFactory::TrashDisk);
352+ QVERIFY(location->isTrashDisk());
353 QCOMPARE(location->info()->absoluteFilePath(), validTrashURL);
354 QCOMPARE(location->urlPath(), validTrashURL);
355 QCOMPARE(location->isRoot(), true);
356@@ -2528,21 +2528,21 @@
357
358 location = factoryLocations.setNewPath("trash://");
359 QVERIFY(location);
360- QVERIFY(location->type() == LocationsFactory::TrashDisk);
361+ QVERIFY(location->isTrashDisk());
362 QCOMPARE(location->info()->absoluteFilePath(), validTrashURL);
363 QCOMPARE(location->urlPath(), validTrashURL);
364 QCOMPARE(location->isRoot(), true);
365
366 location = factoryLocations.setNewPath("trash:///");
367 QVERIFY(location);
368- QVERIFY(location->type() == LocationsFactory::TrashDisk);
369+ QVERIFY(location->isTrashDisk());
370 QCOMPARE(location->info()->absoluteFilePath(), validTrashURL);
371 QCOMPARE(location->urlPath(), validTrashURL);
372 QCOMPARE(location->isRoot(), true);
373
374 location = factoryLocations.setNewPath("trash://////");
375 QVERIFY(location);
376- QVERIFY(location->type() == LocationsFactory::TrashDisk);
377+ QVERIFY(location->isTrashDisk());
378 QCOMPARE(location->info()->absoluteFilePath(), validTrashURL);
379 QCOMPARE(location->urlPath(), validTrashURL);
380 QCOMPARE(location->isRoot(), true);
381@@ -2555,28 +2555,28 @@
382
383 location = factoryLocations.setNewPath("file://////");
384 QVERIFY(location);
385- QVERIFY(location->type() == LocationsFactory::LocalDisk);
386+ QVERIFY(location->isLocalDisk());
387 QCOMPARE(location->info()->absoluteFilePath(), QDir::rootPath());
388 QCOMPARE(location->urlPath(), QDir::rootPath());
389 QCOMPARE(location->isRoot(), true);
390
391 location = factoryLocations.setNewPath("/");
392 QVERIFY(location);
393- QVERIFY(location->type() == LocationsFactory::LocalDisk);
394+ QVERIFY(location->isLocalDisk());
395 QCOMPARE(location->info()->absoluteFilePath(), QDir::rootPath());
396 QCOMPARE(location->urlPath(), QDir::rootPath());
397 QCOMPARE(location->isRoot(), true);
398
399 location = factoryLocations.setNewPath("//");
400 QVERIFY(location);
401- QVERIFY(location->type() == LocationsFactory::LocalDisk);
402+ QVERIFY(location->isLocalDisk());
403 QCOMPARE(location->info()->absoluteFilePath(), QDir::rootPath());
404 QCOMPARE(location->urlPath(), QDir::rootPath());
405 QCOMPARE(location->isRoot(), true);
406
407 location = factoryLocations.setNewPath("//bin");
408 QVERIFY(location);
409- QVERIFY(location->type() == LocationsFactory::LocalDisk);
410+ QVERIFY(location->isLocalDisk());
411 QCOMPARE(location->info()->absoluteFilePath(), QLatin1String("/bin"));
412 QCOMPARE(location->urlPath(), QLatin1String("/bin"));
413 QCOMPARE(location->isRoot(), false);

Subscribers

People subscribed via source and target branches