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

Proposed by Carlos Jose Mazieri on 2015-07-18
Status: Merged
Approved by: Arto Jalkanen on 2015-08-07
Approved revision: 439
Merged at revision: 444
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-08
Merge into: lp:ubuntu-filemanager-app
Prerequisite: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-07
Diff against target: 497 lines (+304/-32)
13 files modified
src/plugin/folderlistmodel/CMakeLists.txt (+2/-0)
src/plugin/folderlistmodel/disk/disklocation.cpp (+41/-0)
src/plugin/folderlistmodel/disk/disklocation.h (+5/-0)
src/plugin/folderlistmodel/disk/disklocationitemdiriterator.cpp (+94/-0)
src/plugin/folderlistmodel/disk/disklocationitemdiriterator.h (+50/-0)
src/plugin/folderlistmodel/folderlistmodel.pri (+7/-2)
src/plugin/folderlistmodel/location.h (+38/-0)
src/plugin/folderlistmodel/locationsfactory.cpp (+9/-23)
src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.cpp (+2/-0)
src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationdiriterator.cpp (+1/-1)
src/plugin/folderlistmodel/smb/smblocation.cpp (+46/-0)
src/plugin/folderlistmodel/smb/smblocation.h (+5/-0)
src/plugin/folderlistmodel/smb/smblocationauthentication.cpp (+4/-6)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-08
Reviewer Review Type Date Requested Status
Arto Jalkanen 2015-07-18 Approve on 2015-08-07
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve on 2015-07-19
Review via email: mp+265199@code.launchpad.net

Commit message

Object LocationItemDirIterator is created by Location classes, it will replace Qt Object QDirIterator in Actions.

Description of the change

Location class improved:

  * Created Location::urlBelongsToLocation() to be used in LocationsFactory::parse()
    It avoids big changes in the LocationsFactory when adding new protocols to File Manager
  * Added creation of LocationItemDirIterator object which is similar to Qt QDirIterator object

To post a comment you must log in.
Arto Jalkanen (ajalkane) wrote :

Some comments to consider for fixing, but approving:

39: Spelling mistake: indexOfColonAndSlashe -> indexOfColonAndSlashes

42: Instead of hardcoding the location of startOf "://" in DiskRootUrl here with midRef(0,5) it would be better to use a constant defined in LocationUrl, or have a static method to determine this in LocationUrl. It can be error prone to distribute this logic across classes.

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/CMakeLists.txt'
2--- src/plugin/folderlistmodel/CMakeLists.txt 2015-06-20 15:15:44 +0000
3+++ src/plugin/folderlistmodel/CMakeLists.txt 2015-07-18 22:03:45 +0000
4@@ -51,6 +51,8 @@
5 urliteminfo.h
6 disk/disklocation.cpp
7 disk/disklocation.h
8+ disk/disklocationitemdiriterator.cpp
9+ disk/disklocationitemdiriterator.h
10 trash/qtrashdir.cpp
11 trash/qtrashdir.h
12 trash/qtrashutilinfo.cpp
13
14=== modified file 'src/plugin/folderlistmodel/disk/disklocation.cpp'
15--- src/plugin/folderlistmodel/disk/disklocation.cpp 2015-03-01 15:32:42 +0000
16+++ src/plugin/folderlistmodel/disk/disklocation.cpp 2015-07-18 22:03:45 +0000
17@@ -20,9 +20,16 @@
18 */
19
20 #include "disklocation.h"
21+#include "disklocationitemdiriterator.h"
22 #include "iorequest.h"
23 #include "ioworkerthread.h"
24 #include "externalfswatcher.h"
25+#include "locationurl.h"
26+
27+
28+#if defined(Q_OS_UNIX)
29+#include <sys/statvfs.h>
30+#endif
31
32 #include <QDebug>
33
34@@ -168,3 +175,37 @@
35 return new DirListWorker(urlPath,filter,isRecursive);
36 }
37
38+
39+QString DiskLocation::urlBelongsToLocation(const QString &urlPath, int indexOfColonAndSlashe)
40+{
41+ QString ret;
42+ if (urlPath.startsWith(LocationUrl::DiskRootURL.midRef(0,5)))
43+ {
44+ ret = QDir::rootPath() + DirItemInfo::removeExtraSlashes(urlPath, indexOfColonAndSlashe+1);
45+ }
46+ return ret;
47+}
48+
49+
50+LocationItemDirIterator *
51+DiskLocation::newDirIterator(const QString &path,
52+ QDir::Filters filters,
53+ QDirIterator::IteratorFlags flags)
54+{
55+ return new DiskLocationItemDirIterator(path, filters, flags);
56+}
57+
58+
59+bool DiskLocation::isThereDiskSpace(const QString &pathname, qint64 requiredSize)
60+{
61+ bool ret = true;
62+#if defined(Q_OS_UNIX)
63+ struct statvfs vfs;
64+ if ( ::statvfs( QFile::encodeName(pathname).constData(), &vfs) == 0 )
65+ {
66+ qint64 free = vfs.f_bsize * vfs.f_bfree;
67+ ret = free > requiredSize;
68+ }
69+#endif
70+ return ret;
71+}
72
73=== modified file 'src/plugin/folderlistmodel/disk/disklocation.h'
74--- src/plugin/folderlistmodel/disk/disklocation.h 2015-03-01 15:32:42 +0000
75+++ src/plugin/folderlistmodel/disk/disklocation.h 2015-07-18 22:03:45 +0000
76@@ -63,6 +63,11 @@
77 virtual DirListWorker * newListWorker(const QString &urlPath,
78 QDir::Filter filter,
79 const bool isRecursive);
80+ virtual LocationItemDirIterator * newDirIterator(const QString & path,
81+ QDir::Filters filters,
82+ QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
83+ virtual bool isThereDiskSpace(const QString& pathname, qint64 requiredSize);
84+ virtual QString urlBelongsToLocation(const QString& urlPath, int indexOfColonAndSlashe);
85
86 protected:
87 void addExternalFsWorkerRequest(ExternalFileSystemChangesWorker *);
88
89=== added file 'src/plugin/folderlistmodel/disk/disklocationitemdiriterator.cpp'
90--- src/plugin/folderlistmodel/disk/disklocationitemdiriterator.cpp 1970-01-01 00:00:00 +0000
91+++ src/plugin/folderlistmodel/disk/disklocationitemdiriterator.cpp 2015-07-18 22:03:45 +0000
92@@ -0,0 +1,94 @@
93+/**************************************************************************
94+ *
95+ * Copyright 2015 Canonical Ltd.
96+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
97+ *
98+ * This program is free software; you can redistribute it and/or modify
99+ * it under the terms of the GNU Lesser General Public License as published by
100+ * the Free Software Foundation; version 3.
101+ *
102+ * This program is distributed in the hope that it will be useful,
103+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
104+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
105+ * GNU Lesser General Public License for more details.
106+ *
107+ * You should have received a copy of the GNU Lesser General Public License
108+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
109+ *
110+ * File: disklocationitemdiriterator.cpp
111+ * Date: 29/03/2015
112+ */
113+
114+#include "disklocationitemdiriterator.h"
115+
116+#include <QDirIterator>
117+
118+DiskLocationItemDirIterator::DiskLocationItemDirIterator(const QString &path,
119+ const QStringList &nameFilters,
120+ QDir::Filters filters,
121+ QDirIterator::IteratorFlags flags)
122+ : LocationItemDirIterator(path,nameFilters,filters,flags)
123+ , m_qtDirIterator(new QDirIterator(path, nameFilters, filters, flags))
124+{
125+
126+}
127+
128+DiskLocationItemDirIterator::DiskLocationItemDirIterator(const QString &path,
129+ QDir::Filters filters,
130+ QDirIterator::IteratorFlags flags)
131+
132+ : LocationItemDirIterator(path,filters,flags)
133+ , m_qtDirIterator(new QDirIterator(path,filters, flags))
134+{
135+
136+}
137+
138+DiskLocationItemDirIterator::DiskLocationItemDirIterator(const QString &path,
139+ QDirIterator::IteratorFlags flags)
140+ : LocationItemDirIterator(path,flags)
141+ , m_qtDirIterator(new QDirIterator(path, flags))
142+{
143+
144+}
145+
146+DiskLocationItemDirIterator::~DiskLocationItemDirIterator()
147+{
148+ delete m_qtDirIterator;
149+}
150+
151+
152+DirItemInfo DiskLocationItemDirIterator::fileInfo() const
153+{
154+ DirItemInfo itemInfo (m_qtDirIterator->fileInfo());
155+ return itemInfo;
156+}
157+
158+
159+QString DiskLocationItemDirIterator::fileName() const
160+{
161+ return m_qtDirIterator->fileName();
162+}
163+
164+
165+QString DiskLocationItemDirIterator::filePath() const
166+{
167+ return m_qtDirIterator->filePath();
168+}
169+
170+
171+bool DiskLocationItemDirIterator::hasNext() const
172+{
173+ return m_qtDirIterator->hasNext();
174+}
175+
176+
177+QString DiskLocationItemDirIterator::next()
178+{
179+ return m_qtDirIterator->next();
180+}
181+
182+
183+QString DiskLocationItemDirIterator::path() const
184+{
185+ return m_qtDirIterator->path();
186+}
187
188=== added file 'src/plugin/folderlistmodel/disk/disklocationitemdiriterator.h'
189--- src/plugin/folderlistmodel/disk/disklocationitemdiriterator.h 1970-01-01 00:00:00 +0000
190+++ src/plugin/folderlistmodel/disk/disklocationitemdiriterator.h 2015-07-18 22:03:45 +0000
191@@ -0,0 +1,50 @@
192+/**************************************************************************
193+ *
194+ * Copyright 2015 Canonical Ltd.
195+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
196+ *
197+ * This program is free software; you can redistribute it and/or modify
198+ * it under the terms of the GNU Lesser General Public License as published by
199+ * the Free Software Foundation; version 3.
200+ *
201+ * This program is distributed in the hope that it will be useful,
202+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
203+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
204+ * GNU Lesser General Public License for more details.
205+ *
206+ * You should have received a copy of the GNU Lesser General Public License
207+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
208+ *
209+ * File: disklocationitemdiriterator.h
210+ * Date: 29/03/2015
211+ */
212+
213+#ifndef DISKLOCATIONITEMDIRITERATOR_H
214+#define DISKLOCATIONITEMDIRITERATOR_H
215+
216+#include "locationitemdiriterator.h"
217+
218+class QDirIterator;
219+
220+class DiskLocationItemDirIterator : public LocationItemDirIterator
221+{
222+public:
223+ explicit DiskLocationItemDirIterator(QObject *parent = 0);
224+ ~DiskLocationItemDirIterator();
225+public:
226+ virtual DirItemInfo fileInfo() const;
227+ virtual QString fileName() const;
228+ virtual QString filePath() const;
229+ virtual bool hasNext() const;
230+ virtual QString next() ;
231+ virtual QString path() const;
232+public:
233+ DiskLocationItemDirIterator(const QString & path, QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
234+ DiskLocationItemDirIterator(const QString & path, QDir::Filters filters, QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
235+ DiskLocationItemDirIterator(const QString & path, const QStringList & nameFilters, QDir::Filters filters = QDir::NoFilter, QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
236+private:
237+ QDirIterator * m_qtDirIterator;
238+
239+};
240+
241+#endif // DISKLOCATIONITEMDIRITERATOR_H
242
243=== modified file 'src/plugin/folderlistmodel/folderlistmodel.pri'
244--- src/plugin/folderlistmodel/folderlistmodel.pri 2015-06-03 11:54:36 +0000
245+++ src/plugin/folderlistmodel/folderlistmodel.pri 2015-07-18 22:03:45 +0000
246@@ -14,7 +14,10 @@
247 $$PWD/locationsfactory.cpp \
248 $$PWD/locationurl.cpp \
249 $$PWD/locationitemdiriterator.cpp \
250- $$PWD/cleanurl.cpp
251+ $$PWD/cleanurl.cpp \
252+ $$PWD/disk/disklocationitemdiriterator.cpp \
253+
254+
255
256 HEADERS += $$PWD/dirmodel.h \
257 $$PWD/iorequest.h \
258@@ -33,7 +36,9 @@
259 $$PWD/locationsfactory.h \
260 $$PWD/locationurl.h \
261 $$PWD/locationitemdiriterator.h \
262- $$PWD/cleanurl.h
263+ $$PWD/cleanurl.h \
264+ $$PWD/disk/disklocationitemdiriterator.h \
265+
266
267 SOURCES += $$PWD/disk/disklocation.cpp
268 HEADERS += $$PWD/disk/disklocation.h
269
270=== modified file 'src/plugin/folderlistmodel/location.h'
271--- src/plugin/folderlistmodel/location.h 2015-07-18 22:03:45 +0000
272+++ src/plugin/folderlistmodel/location.h 2015-07-18 22:03:45 +0000
273@@ -25,9 +25,12 @@
274 #include "diriteminfo.h"
275
276 #include <QObject>
277+#include <QDirIterator>
278
279 class IOWorkerThread;
280 class DirListWorker;
281+class LocationItemDirIterator;
282+
283
284 /*!
285 * \brief The Location class represents any location (full path) where there are items to browse: directories, shares, from Disk and from Network.
286@@ -109,6 +112,41 @@
287 */
288 virtual DirListWorker * newListWorker(const QString &urlPath, QDir::Filter filter, const bool isRecursive) = 0;
289
290+ /*!
291+ * \brief newDirIterator() creates a LocationItemDirIterator object which is similar to Qt QDirIterator object
292+ *
293+ * It will be used to create a recursive list of items in copy/cut/paste/remove Actions
294+ * It can used in DirListWorker as well
295+ * \param path
296+ * \param flags
297+ * \return
298+ */
299+ virtual LocationItemDirIterator * newDirIterator(const QString & path,
300+ QDir::Filters filters,
301+ QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags) = 0;
302+
303+
304+ /*!
305+ * \brief urlBelongsToLocation() Returns a good url if the \a urlPath is valid URL that belongs to its location
306+ *
307+ * If the URL or Path in \a urlPath is valid and belongs to its location
308+ *
309+ * \param urlPath The input URL that is going to be parsed
310+ * \param indexOfColonAndSlashe The index of ":/"
311+ * \return The good URL (parsed with extra slashes removed)
312+ * or an empty string if \a urlPath does not belong to its location
313+ *
314+ *Example regarding samba where both "cifs://" and "smb://" urls are supported
315+ * \code"
316+ * For a urlPath like: "cifs://localhost/share/"
317+ * The return will be: "smb://localhost/share" -> "cifs" changed by "smb" and last slash removed
318+ *
319+ * For a urlPath like: "trash:///"
320+ * The return will be: an empty string meaning that this URL is not related to Samba
321+ *\endcode
322+ */
323+ virtual QString urlBelongsToLocation(const QString& urlPath, int indexOfColonAndSlashe) = 0;
324+
325 public:
326 /*!
327 * \brief isThereDiskSpace() Check if the filesystem has enough space to put a file with size \a requiredSize
328
329=== modified file 'src/plugin/folderlistmodel/locationsfactory.cpp'
330--- src/plugin/folderlistmodel/locationsfactory.cpp 2015-07-18 22:03:45 +0000
331+++ src/plugin/folderlistmodel/locationsfactory.cpp 2015-07-18 22:03:45 +0000
332@@ -80,29 +80,15 @@
333 Location * location = 0;
334 if ( (index = uPath.indexOf(LocationUrl::UrlIndicator)) != -1 )
335 {
336-#if defined(Q_OS_WIN)
337-#else
338-#if defined(Q_OS_UNIX)
339- if (uPath.startsWith(LocationUrl::TrashRootURL.midRef(0,6)))
340- {
341- type = Location::TrashDisk;
342- m_tmpPath = LocationUrl::TrashRootURL + DirItemInfo::removeExtraSlashes(uPath, index+1);
343- }
344- else
345-#endif //Q_OS_UNIX
346-#endif
347- if (uPath.startsWith(LocationUrl::DiskRootURL.midRef(0,5)))
348- {
349- type = Location::LocalDisk;
350- m_tmpPath = QDir::rootPath() + DirItemInfo::removeExtraSlashes(uPath, index+1);
351- }
352- else
353- if ( uPath.startsWith(LocationUrl::SmbURL.midRef(0,4)) ||
354- uPath.startsWith(LocationUrl::CifsURL.midRef(0,5))
355- )
356- {
357- type = Location::NetSambaShare;
358- m_tmpPath = LocationUrl::SmbURL + DirItemInfo::removeExtraSlashes(uPath, index+1);
359+ int counter = m_locations.count();
360+ while (counter--)
361+ {
362+ m_tmpPath = m_locations.at(counter)->urlBelongsToLocation(uPath, index);
363+ if (!m_tmpPath.isEmpty())
364+ {
365+ type = m_locations.at(counter)->type();
366+ break;
367+ }
368 }
369 }
370 else
371
372=== modified file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.cpp'
373--- src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.cpp 2015-03-14 17:38:50 +0000
374+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.cpp 2015-07-18 22:03:45 +0000
375@@ -50,7 +50,9 @@
376 void SmbItemInfo::setInfo(const QString& smb_path)
377 {
378 SmbUtil *smb = const_cast<SmbUtil*> (m_smb);
379+ //getStatInfo() is supposed to clear the struct stat unless the item does not exist
380 struct stat st;
381+ ::memset(&st, 0, sizeof(struct stat));
382 int ret = smb->getStatInfo(smb_path, &st);
383 //lets start with true
384 d_ptr->_exists = d_ptr->_isReadable = true;
385
386=== modified file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationdiriterator.cpp'
387--- src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationdiriterator.cpp 2015-05-20 16:18:07 +0000
388+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationdiriterator.cpp 2015-07-18 22:03:45 +0000
389@@ -60,7 +60,7 @@
390 , INIT_ATTR(path, smb)
391 {
392 bool recursive = flags == QDirIterator::Subdirectories ? true : false;
393- m_urlItems = smbObj()->listContent(path, recursive);
394+ m_urlItems = smbObj()->listContent(path, recursive, QDir::NoFilter);
395 }
396
397
398
399=== modified file 'src/plugin/folderlistmodel/smb/smblocation.cpp'
400--- src/plugin/folderlistmodel/smb/smblocation.cpp 2015-03-14 18:20:15 +0000
401+++ src/plugin/folderlistmodel/smb/smblocation.cpp 2015-07-18 22:03:45 +0000
402@@ -23,8 +23,16 @@
403 #include "smbutil.h"
404 #include "smbiteminfo.h"
405 #include "smblistworker.h"
406+#include "smblocationdiriterator.h"
407 #include "iorequest.h"
408 #include "ioworkerthread.h"
409+#include "locationurl.h"
410+
411+
412+
413+#if defined(Q_OS_UNIX)
414+#include <sys/statvfs.h>
415+#endif
416
417 SmbLocation::SmbLocation(int type, QObject *parent)
418 : Location(type, parent)
419@@ -82,3 +90,41 @@
420 return new SmbListWorker(urlPath,filter,isRecursive, m_info ? m_info->isHost() : false, m_smb);
421 }
422
423+
424+QString SmbLocation::urlBelongsToLocation(const QString &urlPath, int indexOfColonAndSlashe)
425+{
426+ QString ret;
427+ if ( urlPath.startsWith(LocationUrl::SmbURL.midRef(0,4)) ||
428+ urlPath.startsWith(LocationUrl::CifsURL.midRef(0,5))
429+ )
430+ {
431+ ret = LocationUrl::SmbURL + DirItemInfo::removeExtraSlashes(urlPath, indexOfColonAndSlashe+1);
432+ }
433+ return ret;
434+}
435+
436+
437+LocationItemDirIterator *
438+SmbLocation::newDirIterator(const QString &path,
439+ QDir::Filters filters,
440+ QDirIterator::IteratorFlags flags)
441+{
442+ return new SmbLocationDirIterator(path, filters, flags, m_smb);
443+}
444+
445+
446+bool SmbLocation::isThereDiskSpace(const QString &pathname, qint64 requiredSize)
447+{
448+ bool ret = false;
449+#if defined(Q_OS_UNIX)
450+ struct statvfs st;
451+ if (m_smb->getStatvfsInfo(pathname, &st) == SmbUtil::StatDone)
452+ {
453+ qint64 free = st.f_bsize * st.f_bfree;
454+ ret = free > requiredSize;
455+ }
456+#else
457+ ret = true;
458+#endif
459+ return ret;
460+}
461
462=== modified file 'src/plugin/folderlistmodel/smb/smblocation.h'
463--- src/plugin/folderlistmodel/smb/smblocation.h 2015-03-14 18:20:15 +0000
464+++ src/plugin/folderlistmodel/smb/smblocation.h 2015-07-18 22:03:45 +0000
465@@ -39,6 +39,11 @@
466 virtual DirListWorker * newListWorker(const QString &urlPath,
467 QDir::Filter filter,
468 const bool isRecursive);
469+ virtual LocationItemDirIterator * newDirIterator(const QString & path,
470+ QDir::Filters filters,
471+ QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
472+ virtual bool isThereDiskSpace(const QString& pathname, qint64 requiredSize);
473+ virtual QString urlBelongsToLocation(const QString& urlPath, int indexOfColonAndSlashe);
474 virtual QString currentAuthenticationUser();
475 virtual QString currentAuthenticationPassword();
476
477
478=== modified file 'src/plugin/folderlistmodel/smb/smblocationauthentication.cpp'
479--- src/plugin/folderlistmodel/smb/smblocationauthentication.cpp 2015-04-29 23:23:31 +0000
480+++ src/plugin/folderlistmodel/smb/smblocationauthentication.cpp 2015-07-18 22:03:45 +0000
481@@ -30,12 +30,10 @@
482 # define DEBUG_AUTHENTICATION() /**/
483 #endif
484
485-namespace
486-{
487- QByteArray m_AuthUser[MAX_AUTH_INSTANCES];
488- QByteArray m_AuthPass[MAX_AUTH_INSTANCES];
489- void * m_instances[MAX_AUTH_INSTANCES];
490-}
491+
492+static QByteArray m_AuthUser[MAX_AUTH_INSTANCES];
493+static QByteArray m_AuthPass[MAX_AUTH_INSTANCES];
494+static void * m_instances[MAX_AUTH_INSTANCES];
495
496 SmbLocationAuthentication::SmbLocationAuthentication() : m_infoIndex(-1)
497 {

Subscribers

People subscribed via source and target branches