Merge lp:~carlos-mazieri/ubuntu-filemanager-app/new-protocols-support-04 into lp:ubuntu-filemanager-app

Proposed by Carlos Jose Mazieri on 2015-12-12
Status: Merged
Approved by: Arto Jalkanen on 2016-01-10
Approved revision: 515
Merged at revision: 517
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/new-protocols-support-04
Merge into: lp:ubuntu-filemanager-app
Prerequisite: lp:~carlos-mazieri/ubuntu-filemanager-app/new-protocols-support-03
Diff against target: 391 lines (+272/-17)
8 files modified
src/plugin/folderlistmodel/CMakeLists.txt (+4/-0)
src/plugin/folderlistmodel/folderlistmodel.pri (+6/-3)
src/plugin/folderlistmodel/networklistworker.cpp (+74/-0)
src/plugin/folderlistmodel/networklistworker.h (+54/-0)
src/plugin/folderlistmodel/networklocation.cpp (+41/-0)
src/plugin/folderlistmodel/networklocation.h (+89/-0)
src/plugin/folderlistmodel/smb/smblocation.cpp (+1/-8)
src/plugin/folderlistmodel/smb/smblocation.h (+3/-6)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/new-protocols-support-04
Reviewer Review Type Date Requested Status
Arto Jalkanen 2015-12-12 Approve on 2016-01-10
Jenkins Bot continuous-integration Approve on 2015-12-12
Review via email: mp+280390@code.launchpad.net

Commit message

* Created new and generic classes: NetworkLocation and NetworkListWorker
* SmbLocation now inherits from the generic NetworkLocation instead of Location
* SmbListWorker class is no longer used and it will be removed
* NetworkListWorker really performs the loading on a secondary thread

Description of the change

* Created new and generic classes: NetworkLocation and NetworkListWorker
* SmbLocation now inherits from the generic NetworkLocation instead of Location
* SmbListWorker class is no longer used and it will be removed
* NetworkListWorker really performs the loading on a secondary thread

To post a comment you must log in.
review: Approve (continuous-integration)
Arto Jalkanen (ajalkane) wrote :

Some trivial code style comments

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-08-25 15:42:01 +0000
3+++ src/plugin/folderlistmodel/CMakeLists.txt 2015-12-12 15:47:20 +0000
4@@ -35,6 +35,8 @@
5 iorequestworker.h
6 ioworkerthread.cpp
7 ioworkerthread.h
8+ networklistworker.cpp
9+ networklistworker.h
10 plugin.cpp
11 plugin.h
12 location.cpp
13@@ -43,6 +45,8 @@
14 locationsfactory.h
15 locationurl.cpp
16 locationurl.h
17+ networklocation.cpp
18+ networklocation.h
19 locationitemdir.cpp
20 locationitemdir.h
21 locationitemdiriterator.cpp
22
23=== modified file 'src/plugin/folderlistmodel/folderlistmodel.pri'
24--- src/plugin/folderlistmodel/folderlistmodel.pri 2015-07-15 17:42:37 +0000
25+++ src/plugin/folderlistmodel/folderlistmodel.pri 2015-12-12 15:47:20 +0000
26@@ -16,8 +16,9 @@
27 $$PWD/locationitemdiriterator.cpp \
28 $$PWD/cleanurl.cpp \
29 $$PWD/locationitemfile.cpp \
30- $$PWD/locationitemdir.cpp
31-
32+ $$PWD/locationitemdir.cpp \
33+ $$PWD/networklocation.cpp \
34+ $$PWD/networklistworker.cpp
35
36 HEADERS += $$PWD/dirmodel.h \
37 $$PWD/iorequest.h \
38@@ -38,7 +39,9 @@
39 $$PWD/locationitemdiriterator.h \
40 $$PWD/cleanurl.h \
41 $$PWD/locationitemfile.h \
42- $$PWD/locationitemdir.h
43+ $$PWD/locationitemdir.h \
44+ $$PWD/networklocation.h \
45+ $$PWD/networklistworker.h
46
47
48 SOURCES += $$PWD/disk/disklocation.cpp \
49
50=== added file 'src/plugin/folderlistmodel/networklistworker.cpp'
51--- src/plugin/folderlistmodel/networklistworker.cpp 1970-01-01 00:00:00 +0000
52+++ src/plugin/folderlistmodel/networklistworker.cpp 2015-12-12 15:47:20 +0000
53@@ -0,0 +1,74 @@
54+/**************************************************************************
55+ *
56+ * Copyright 2015 Canonical Ltd.
57+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
58+ *
59+ * This program is free software; you can redistribute it and/or modify
60+ * it under the terms of the GNU Lesser General Public License as published by
61+ * the Free Software Foundation; version 3.
62+ *
63+ * This program is distributed in the hope that it will be useful,
64+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
65+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66+ * GNU Lesser General Public License for more details.
67+ *
68+ * You should have received a copy of the GNU Lesser General Public License
69+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
70+ *
71+ * File: networklistworker.cpp
72+ * Date: 06/12/2015
73+ */
74+
75+#include "networklistworker.h"
76+#include "locationitemdiriterator.h"
77+#include "locationurl.h"
78+
79+NetworkListWorker::NetworkListWorker(LocationItemDirIterator * dirIterator,
80+ DirItemInfo * mainItemInfo, const DirItemInfo *parent) :
81+ DirListWorker(dirIterator->path(),
82+ dirIterator->filters(),
83+ dirIterator->flags() == QDirIterator::Subdirectories ? true : false),
84+ m_dirIterator(dirIterator),
85+ m_mainItemInfo(mainItemInfo),
86+ m_parent(parent)
87+{
88+ mLoaderType = NetworkLoader;
89+}
90+
91+
92+NetworkListWorker::~NetworkListWorker()
93+{
94+ delete m_dirIterator;
95+ delete m_mainItemInfo;
96+}
97+
98+
99+DirItemInfoList NetworkListWorker::getNetworkContent()
100+{
101+ DirItemInfoList netContent;
102+ m_dirIterator->load();
103+ bool is_parent_of_smb_url = m_parent != 0 && m_parent->urlPath().startsWith(LocationUrl::SmbURL);
104+ while (m_dirIterator->hasNext())
105+ {
106+ m_mainItemInfo->setFile(m_dirIterator->next());
107+ if (is_parent_of_smb_url)
108+ {
109+ setSmbItemAttributes();
110+ }
111+ netContent.append(*m_mainItemInfo);
112+ }
113+ return netContent;
114+}
115+
116+/*!
117+ * \brief NetworkListWorker::setSmbItemAttributes()
118+ *
119+ * This original implementation regards only to Samba (smb:// protocol),
120+ * it will not hurt other protocols implementation.
121+ */
122+void NetworkListWorker::setSmbItemAttributes()
123+{
124+ if (m_parent->isHost()) { m_mainItemInfo->setAsShare(); }
125+ else
126+ if (m_parent->isWorkGroup()) { m_mainItemInfo->setAsHost(); }
127+}
128
129=== added file 'src/plugin/folderlistmodel/networklistworker.h'
130--- src/plugin/folderlistmodel/networklistworker.h 1970-01-01 00:00:00 +0000
131+++ src/plugin/folderlistmodel/networklistworker.h 2015-12-12 15:47:20 +0000
132@@ -0,0 +1,54 @@
133+/**************************************************************************
134+ *
135+ * Copyright 2015 Canonical Ltd.
136+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
137+ *
138+ * This program is free software; you can redistribute it and/or modify
139+ * it under the terms of the GNU Lesser General Public License as published by
140+ * the Free Software Foundation; version 3.
141+ *
142+ * This program is distributed in the hope that it will be useful,
143+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
144+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
145+ * GNU Lesser General Public License for more details.
146+ *
147+ * You should have received a copy of the GNU Lesser General Public License
148+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
149+ *
150+ * File: networklistworker.h
151+ * Date: 06/12/2015
152+ */
153+
154+#ifndef NETWORKLISTWORKER_H
155+#define NETWORKLISTWORKER_H
156+
157+#include "iorequestworker.h"
158+
159+class LocationItemDirIterator;
160+class DirItemInfo;
161+
162+/*!
163+ * \brief The NetworkListWorker class intends to be a generic Network directory loader.
164+ *.
165+ * It trusts on \ref LocationItemDirIterator and \ref DirItemInfo classes
166+ *
167+ * The LocationItemDirIterator::load() must bring the list of items.
168+ */
169+class NetworkListWorker : public DirListWorker
170+{
171+ Q_OBJECT
172+public:
173+ NetworkListWorker(LocationItemDirIterator * dirIterator,
174+ DirItemInfo * mainItemInfo,
175+ const DirItemInfo * parent = 0);
176+ ~NetworkListWorker();
177+protected:
178+ virtual DirItemInfoList getNetworkContent();
179+ void setSmbItemAttributes();
180+protected:
181+ LocationItemDirIterator * m_dirIterator;
182+ DirItemInfo * m_mainItemInfo;
183+ const DirItemInfo * m_parent;
184+};
185+
186+#endif // NETWORKLISTWORKER_H
187
188=== added file 'src/plugin/folderlistmodel/networklocation.cpp'
189--- src/plugin/folderlistmodel/networklocation.cpp 1970-01-01 00:00:00 +0000
190+++ src/plugin/folderlistmodel/networklocation.cpp 2015-12-12 15:47:20 +0000
191@@ -0,0 +1,41 @@
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: networklocation.cpp
210+ * Date: 08/12/2015
211+ */
212+
213+#include "networklocation.h"
214+#include "networklistworker.h"
215+#include "locationitemdiriterator.h"
216+#include "diriteminfo.h"
217+
218+NetworkLocation::NetworkLocation(int type, QObject *parent): Location(type, parent)
219+{
220+}
221+
222+
223+
224+DirListWorker * NetworkLocation::newListWorker(const QString &urlPath, QDir::Filters filter, const bool isRecursive)
225+{
226+ QDirIterator::IteratorFlags flags = isRecursive ? QDirIterator::Subdirectories : QDirIterator::NoIteratorFlags;
227+
228+ LocationItemDirIterator *dirIterator = newDirIterator(urlPath,filter,flags,LocationItemDirIterator::LoadLater);
229+ DirItemInfo *baseitemInfo = newItemInfo(QLatin1String(0));
230+
231+ return new NetworkListWorker(dirIterator, baseitemInfo, m_info);
232+}
233
234=== added file 'src/plugin/folderlistmodel/networklocation.h'
235--- src/plugin/folderlistmodel/networklocation.h 1970-01-01 00:00:00 +0000
236+++ src/plugin/folderlistmodel/networklocation.h 2015-12-12 15:47:20 +0000
237@@ -0,0 +1,89 @@
238+/**************************************************************************
239+ *
240+ * Copyright 2015 Canonical Ltd.
241+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
242+ *
243+ * This program is free software; you can redistribute it and/or modify
244+ * it under the terms of the GNU Lesser General Public License as published by
245+ * the Free Software Foundation; version 3.
246+ *
247+ * This program is distributed in the hope that it will be useful,
248+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
249+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
250+ * GNU Lesser General Public License for more details.
251+ *
252+ * You should have received a copy of the GNU Lesser General Public License
253+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
254+ *
255+ * File: networklocation.h
256+ * Date: 08/12/2015
257+ */
258+
259+#ifndef NETWORKLOCATION_H
260+#define NETWORKLOCATION_H
261+
262+#include "location.h"
263+
264+/*!
265+ * \brief The NetworkLocation class is an Abstract class suitable for Network protocols easy browsing implementation
266+ *
267+ * Support to new protocols can have its browsing provided by this class and for the generic class \ref NetworkListWorker.
268+ *
269+ * To get the browsing working on a network protocol just create a new \ref Location class inherited from NetworkLocation,
270+ * then provide both suitable classes \ref DirItemInfo and \ref descendant classes for this new \ref Location.
271+ *
272+ * The browsing itself will be performed inside a secondary thread using the \ref NetworkListWorker class.
273+ *
274+ *\note For this new \ref Location class it is also necessary:
275+ * \li an enumerator item (the type) needs be added into Location::Locations
276+ * \li the corresponding protocol URL need be registered in \ref LocationUrl
277+ * \li an instance of this class needs to be created in the \ref LocationsFactory creator
278+ *
279+ * Minimal example of adding a new Location class the adds support to a new protocol in the File Manager:
280+ *\code
281+ *
282+ * class NewLocation : public NetworkLocation
283+ * {
284+ * public:
285+ * explicit NewLocation(int type, QObject *parent=0) : NetworkLocation(type, parent) {}
286+ * ~NewLocation() {}
287+ *
288+ * public:
289+ * virtual DirItemInfo * newItemInfo(const QString& urlPath)
290+ * {
291+ * //provide the suitable DirItemInfo inherited class here
292+ * }
293+ *
294+ * virtual LocationItemDirIterator * newDirIterator(const QString & path,
295+ * QDir::Filters filters,
296+ * QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags,
297+ * LocationItemDirIterator::LoadMode loadmode = LocationItemDirIterator::LoadOnConstructor)
298+ * {
299+ * //provide the suitable LocationItemDirIterator object for the new protocol here
300+ * }
301+ *
302+ * virtual LocationItemFile * newFile(const QString & path) { return 0; } //used only in Actions, browsing does not use it
303+ * virtual LocationItemDir * newDir(const QString & dir = QLatin1String(0)) { return 0; } //used only in Actions, browsing does not use it
304+ *
305+ * virtual QString urlBelongsToLocation(const QString& urlPath, int indexOfColonAndSlash)
306+ * {
307+ * // provide some kind of URL parsing for the new protocol, see other implementations
308+ * }
309+ * };
310+ *\endcode
311+ *
312+ * \sa \ref SmbLocation, \ref SmbItemInfo, \ref SmbLocationDirIterator, \ref SmbLocationItemFile, \ref SmbLocationItemDir,
313+ * \ref SmbLocationAuthentication , \ref NetAuthenticationData and \ref NetAuthenticationDataList
314+ */
315+
316+class NetworkLocation: public Location
317+{
318+protected:
319+ explicit NetworkLocation(int type, QObject *parent=0);
320+public:
321+ virtual DirListWorker * newListWorker(const QString &urlPath,
322+ QDir::Filters filter,
323+ const bool isRecursive);
324+};
325+
326+#endif // NETWORKLOCATION_H
327
328=== modified file 'src/plugin/folderlistmodel/smb/smblocation.cpp'
329--- src/plugin/folderlistmodel/smb/smblocation.cpp 2015-12-12 15:47:20 +0000
330+++ src/plugin/folderlistmodel/smb/smblocation.cpp 2015-12-12 15:47:20 +0000
331@@ -22,7 +22,6 @@
332 #include "smblocation.h"
333 #include "smbutil.h"
334 #include "smbiteminfo.h"
335-#include "smblistworker.h"
336 #include "smblocationdiriterator.h"
337 #include "iorequest.h"
338 #include "ioworkerthread.h"
339@@ -38,7 +37,7 @@
340 #endif
341
342 SmbLocation::SmbLocation(int type, QObject *parent)
343- : Location(type, parent)
344+ : NetworkLocation(type, parent)
345 , SmbLocationAuthentication()
346 {
347 m_smb = new SmbUtil(suitableAuthenticationFunction());
348@@ -89,12 +88,6 @@
349 }
350
351
352-DirListWorker * SmbLocation::newListWorker(const QString &urlPath, QDir::Filters filter, const bool isRecursive)
353-{
354- return new SmbListWorker(urlPath,filter,isRecursive, m_info, m_smb);
355-}
356-
357-
358 QString SmbLocation::urlBelongsToLocation(const QString &urlPath, int indexOfColonAndSlash)
359 {
360 QString ret;
361
362=== modified file 'src/plugin/folderlistmodel/smb/smblocation.h'
363--- src/plugin/folderlistmodel/smb/smblocation.h 2015-12-12 15:47:20 +0000
364+++ src/plugin/folderlistmodel/smb/smblocation.h 2015-12-12 15:47:20 +0000
365@@ -22,12 +22,12 @@
366 #ifndef SMBLOCATION_H
367 #define SMBLOCATION_H
368
369-#include "location.h"
370+#include "networklocation.h"
371 #include "smblocationauthentication.h"
372 #include "smbobject.h"
373
374
375-class SmbLocation : public Location, public SmbLocationAuthentication
376+class SmbLocation : public NetworkLocation, public SmbLocationAuthentication
377 {
378 Q_OBJECT
379 public:
380@@ -36,10 +36,7 @@
381
382 public:
383 virtual DirItemInfo * newItemInfo(const QString& urlPath);
384- virtual DirListWorker * newListWorker(const QString &urlPath,
385- QDir::Filters filter,
386- const bool isRecursive);
387- virtual LocationItemDirIterator * newDirIterator(const QString & path,
388+ virtual LocationItemDirIterator * newDirIterator(const QString & path,
389 QDir::Filters filters,
390 QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags,
391 LocationItemDirIterator::LoadMode loadmode = LocationItemDirIterator::LoadOnConstructor);

Subscribers

People subscribed via source and target branches