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
=== modified file 'src/plugin/folderlistmodel/CMakeLists.txt'
--- src/plugin/folderlistmodel/CMakeLists.txt 2015-08-25 15:42:01 +0000
+++ src/plugin/folderlistmodel/CMakeLists.txt 2015-12-12 15:47:20 +0000
@@ -35,6 +35,8 @@
35 iorequestworker.h35 iorequestworker.h
36 ioworkerthread.cpp36 ioworkerthread.cpp
37 ioworkerthread.h37 ioworkerthread.h
38 networklistworker.cpp
39 networklistworker.h
38 plugin.cpp40 plugin.cpp
39 plugin.h41 plugin.h
40 location.cpp42 location.cpp
@@ -43,6 +45,8 @@
43 locationsfactory.h45 locationsfactory.h
44 locationurl.cpp46 locationurl.cpp
45 locationurl.h47 locationurl.h
48 networklocation.cpp
49 networklocation.h
46 locationitemdir.cpp50 locationitemdir.cpp
47 locationitemdir.h51 locationitemdir.h
48 locationitemdiriterator.cpp52 locationitemdiriterator.cpp
4953
=== modified file 'src/plugin/folderlistmodel/folderlistmodel.pri'
--- src/plugin/folderlistmodel/folderlistmodel.pri 2015-07-15 17:42:37 +0000
+++ src/plugin/folderlistmodel/folderlistmodel.pri 2015-12-12 15:47:20 +0000
@@ -16,8 +16,9 @@
16 $$PWD/locationitemdiriterator.cpp \16 $$PWD/locationitemdiriterator.cpp \
17 $$PWD/cleanurl.cpp \ 17 $$PWD/cleanurl.cpp \
18 $$PWD/locationitemfile.cpp \18 $$PWD/locationitemfile.cpp \
19 $$PWD/locationitemdir.cpp19 $$PWD/locationitemdir.cpp \
2020 $$PWD/networklocation.cpp \
21 $$PWD/networklistworker.cpp
2122
22HEADERS += $$PWD/dirmodel.h \23HEADERS += $$PWD/dirmodel.h \
23 $$PWD/iorequest.h \24 $$PWD/iorequest.h \
@@ -38,7 +39,9 @@
38 $$PWD/locationitemdiriterator.h \39 $$PWD/locationitemdiriterator.h \
39 $$PWD/cleanurl.h \ 40 $$PWD/cleanurl.h \
40 $$PWD/locationitemfile.h \41 $$PWD/locationitemfile.h \
41 $$PWD/locationitemdir.h42 $$PWD/locationitemdir.h \
43 $$PWD/networklocation.h \
44 $$PWD/networklistworker.h
4245
4346
44SOURCES += $$PWD/disk/disklocation.cpp \47SOURCES += $$PWD/disk/disklocation.cpp \
4548
=== added file 'src/plugin/folderlistmodel/networklistworker.cpp'
--- src/plugin/folderlistmodel/networklistworker.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/networklistworker.cpp 2015-12-12 15:47:20 +0000
@@ -0,0 +1,74 @@
1/**************************************************************************
2 *
3 * Copyright 2015 Canonical Ltd.
4 * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * File: networklistworker.cpp
19 * Date: 06/12/2015
20 */
21
22#include "networklistworker.h"
23#include "locationitemdiriterator.h"
24#include "locationurl.h"
25
26NetworkListWorker::NetworkListWorker(LocationItemDirIterator * dirIterator,
27 DirItemInfo * mainItemInfo, const DirItemInfo *parent) :
28 DirListWorker(dirIterator->path(),
29 dirIterator->filters(),
30 dirIterator->flags() == QDirIterator::Subdirectories ? true : false),
31 m_dirIterator(dirIterator),
32 m_mainItemInfo(mainItemInfo),
33 m_parent(parent)
34{
35 mLoaderType = NetworkLoader;
36}
37
38
39NetworkListWorker::~NetworkListWorker()
40{
41 delete m_dirIterator;
42 delete m_mainItemInfo;
43}
44
45
46DirItemInfoList NetworkListWorker::getNetworkContent()
47{
48 DirItemInfoList netContent;
49 m_dirIterator->load();
50 bool is_parent_of_smb_url = m_parent != 0 && m_parent->urlPath().startsWith(LocationUrl::SmbURL);
51 while (m_dirIterator->hasNext())
52 {
53 m_mainItemInfo->setFile(m_dirIterator->next());
54 if (is_parent_of_smb_url)
55 {
56 setSmbItemAttributes();
57 }
58 netContent.append(*m_mainItemInfo);
59 }
60 return netContent;
61}
62
63/*!
64 * \brief NetworkListWorker::setSmbItemAttributes()
65 *
66 * This original implementation regards only to Samba (smb:// protocol),
67 * it will not hurt other protocols implementation.
68 */
69void NetworkListWorker::setSmbItemAttributes()
70{
71 if (m_parent->isHost()) { m_mainItemInfo->setAsShare(); }
72 else
73 if (m_parent->isWorkGroup()) { m_mainItemInfo->setAsHost(); }
74}
075
=== added file 'src/plugin/folderlistmodel/networklistworker.h'
--- src/plugin/folderlistmodel/networklistworker.h 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/networklistworker.h 2015-12-12 15:47:20 +0000
@@ -0,0 +1,54 @@
1/**************************************************************************
2 *
3 * Copyright 2015 Canonical Ltd.
4 * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * File: networklistworker.h
19 * Date: 06/12/2015
20 */
21
22#ifndef NETWORKLISTWORKER_H
23#define NETWORKLISTWORKER_H
24
25#include "iorequestworker.h"
26
27class LocationItemDirIterator;
28class DirItemInfo;
29
30/*!
31 * \brief The NetworkListWorker class intends to be a generic Network directory loader.
32 *.
33 * It trusts on \ref LocationItemDirIterator and \ref DirItemInfo classes
34 *
35 * The LocationItemDirIterator::load() must bring the list of items.
36 */
37class NetworkListWorker : public DirListWorker
38{
39 Q_OBJECT
40public:
41 NetworkListWorker(LocationItemDirIterator * dirIterator,
42 DirItemInfo * mainItemInfo,
43 const DirItemInfo * parent = 0);
44 ~NetworkListWorker();
45protected:
46 virtual DirItemInfoList getNetworkContent();
47 void setSmbItemAttributes();
48protected:
49 LocationItemDirIterator * m_dirIterator;
50 DirItemInfo * m_mainItemInfo;
51 const DirItemInfo * m_parent;
52};
53
54#endif // NETWORKLISTWORKER_H
055
=== added file 'src/plugin/folderlistmodel/networklocation.cpp'
--- src/plugin/folderlistmodel/networklocation.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/networklocation.cpp 2015-12-12 15:47:20 +0000
@@ -0,0 +1,41 @@
1/**************************************************************************
2 *
3 * Copyright 2015 Canonical Ltd.
4 * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * File: networklocation.cpp
19 * Date: 08/12/2015
20 */
21
22#include "networklocation.h"
23#include "networklistworker.h"
24#include "locationitemdiriterator.h"
25#include "diriteminfo.h"
26
27NetworkLocation::NetworkLocation(int type, QObject *parent): Location(type, parent)
28{
29}
30
31
32
33DirListWorker * NetworkLocation::newListWorker(const QString &urlPath, QDir::Filters filter, const bool isRecursive)
34{
35 QDirIterator::IteratorFlags flags = isRecursive ? QDirIterator::Subdirectories : QDirIterator::NoIteratorFlags;
36
37 LocationItemDirIterator *dirIterator = newDirIterator(urlPath,filter,flags,LocationItemDirIterator::LoadLater);
38 DirItemInfo *baseitemInfo = newItemInfo(QLatin1String(0));
39
40 return new NetworkListWorker(dirIterator, baseitemInfo, m_info);
41}
042
=== added file 'src/plugin/folderlistmodel/networklocation.h'
--- src/plugin/folderlistmodel/networklocation.h 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/networklocation.h 2015-12-12 15:47:20 +0000
@@ -0,0 +1,89 @@
1/**************************************************************************
2 *
3 * Copyright 2015 Canonical Ltd.
4 * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * File: networklocation.h
19 * Date: 08/12/2015
20 */
21
22#ifndef NETWORKLOCATION_H
23#define NETWORKLOCATION_H
24
25#include "location.h"
26
27/*!
28 * \brief The NetworkLocation class is an Abstract class suitable for Network protocols easy browsing implementation
29 *
30 * Support to new protocols can have its browsing provided by this class and for the generic class \ref NetworkListWorker.
31 *
32 * To get the browsing working on a network protocol just create a new \ref Location class inherited from NetworkLocation,
33 * then provide both suitable classes \ref DirItemInfo and \ref descendant classes for this new \ref Location.
34 *
35 * The browsing itself will be performed inside a secondary thread using the \ref NetworkListWorker class.
36 *
37 *\note For this new \ref Location class it is also necessary:
38 * \li an enumerator item (the type) needs be added into Location::Locations
39 * \li the corresponding protocol URL need be registered in \ref LocationUrl
40 * \li an instance of this class needs to be created in the \ref LocationsFactory creator
41 *
42 * Minimal example of adding a new Location class the adds support to a new protocol in the File Manager:
43 *\code
44 *
45 * class NewLocation : public NetworkLocation
46 * {
47 * public:
48 * explicit NewLocation(int type, QObject *parent=0) : NetworkLocation(type, parent) {}
49 * ~NewLocation() {}
50 *
51 * public:
52 * virtual DirItemInfo * newItemInfo(const QString& urlPath)
53 * {
54 * //provide the suitable DirItemInfo inherited class here
55 * }
56 *
57 * virtual LocationItemDirIterator * newDirIterator(const QString & path,
58 * QDir::Filters filters,
59 * QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags,
60 * LocationItemDirIterator::LoadMode loadmode = LocationItemDirIterator::LoadOnConstructor)
61 * {
62 * //provide the suitable LocationItemDirIterator object for the new protocol here
63 * }
64 *
65 * virtual LocationItemFile * newFile(const QString & path) { return 0; } //used only in Actions, browsing does not use it
66 * virtual LocationItemDir * newDir(const QString & dir = QLatin1String(0)) { return 0; } //used only in Actions, browsing does not use it
67 *
68 * virtual QString urlBelongsToLocation(const QString& urlPath, int indexOfColonAndSlash)
69 * {
70 * // provide some kind of URL parsing for the new protocol, see other implementations
71 * }
72 * };
73 *\endcode
74 *
75 * \sa \ref SmbLocation, \ref SmbItemInfo, \ref SmbLocationDirIterator, \ref SmbLocationItemFile, \ref SmbLocationItemDir,
76 * \ref SmbLocationAuthentication , \ref NetAuthenticationData and \ref NetAuthenticationDataList
77 */
78
79class NetworkLocation: public Location
80{
81protected:
82 explicit NetworkLocation(int type, QObject *parent=0);
83public:
84 virtual DirListWorker * newListWorker(const QString &urlPath,
85 QDir::Filters filter,
86 const bool isRecursive);
87};
88
89#endif // NETWORKLOCATION_H
090
=== modified file 'src/plugin/folderlistmodel/smb/smblocation.cpp'
--- src/plugin/folderlistmodel/smb/smblocation.cpp 2015-12-12 15:47:20 +0000
+++ src/plugin/folderlistmodel/smb/smblocation.cpp 2015-12-12 15:47:20 +0000
@@ -22,7 +22,6 @@
22#include "smblocation.h"22#include "smblocation.h"
23#include "smbutil.h"23#include "smbutil.h"
24#include "smbiteminfo.h"24#include "smbiteminfo.h"
25#include "smblistworker.h"
26#include "smblocationdiriterator.h"25#include "smblocationdiriterator.h"
27#include "iorequest.h"26#include "iorequest.h"
28#include "ioworkerthread.h"27#include "ioworkerthread.h"
@@ -38,7 +37,7 @@
38#endif37#endif
3938
40SmbLocation::SmbLocation(int type, QObject *parent)39SmbLocation::SmbLocation(int type, QObject *parent)
41 : Location(type, parent)40 : NetworkLocation(type, parent)
42 , SmbLocationAuthentication()41 , SmbLocationAuthentication()
43{42{
44 m_smb = new SmbUtil(suitableAuthenticationFunction());43 m_smb = new SmbUtil(suitableAuthenticationFunction());
@@ -89,12 +88,6 @@
89}88}
9089
9190
92DirListWorker * SmbLocation::newListWorker(const QString &urlPath, QDir::Filters filter, const bool isRecursive)
93{
94 return new SmbListWorker(urlPath,filter,isRecursive, m_info, m_smb);
95}
96
97
98QString SmbLocation::urlBelongsToLocation(const QString &urlPath, int indexOfColonAndSlash)91QString SmbLocation::urlBelongsToLocation(const QString &urlPath, int indexOfColonAndSlash)
99{92{
100 QString ret;93 QString ret;
10194
=== modified file 'src/plugin/folderlistmodel/smb/smblocation.h'
--- src/plugin/folderlistmodel/smb/smblocation.h 2015-12-12 15:47:20 +0000
+++ src/plugin/folderlistmodel/smb/smblocation.h 2015-12-12 15:47:20 +0000
@@ -22,12 +22,12 @@
22#ifndef SMBLOCATION_H22#ifndef SMBLOCATION_H
23#define SMBLOCATION_H23#define SMBLOCATION_H
2424
25#include "location.h"25#include "networklocation.h"
26#include "smblocationauthentication.h"26#include "smblocationauthentication.h"
27#include "smbobject.h"27#include "smbobject.h"
2828
2929
30class SmbLocation : public Location, public SmbLocationAuthentication30class SmbLocation : public NetworkLocation, public SmbLocationAuthentication
31{31{
32 Q_OBJECT32 Q_OBJECT
33public:33public:
@@ -36,10 +36,7 @@
3636
37public: 37public:
38 virtual DirItemInfo * newItemInfo(const QString& urlPath);38 virtual DirItemInfo * newItemInfo(const QString& urlPath);
39 virtual DirListWorker * newListWorker(const QString &urlPath,39 virtual LocationItemDirIterator * newDirIterator(const QString & path,
40 QDir::Filters filter,
41 const bool isRecursive);
42 virtual LocationItemDirIterator * newDirIterator(const QString & path,
43 QDir::Filters filters,40 QDir::Filters filters,
44 QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags,41 QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags,
45 LocationItemDirIterator::LoadMode loadmode = LocationItemDirIterator::LoadOnConstructor);42 LocationItemDirIterator::LoadMode loadmode = LocationItemDirIterator::LoadOnConstructor);

Subscribers

People subscribed via source and target branches