Merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-03 into lp:ubuntu-filemanager-app

Proposed by Carlos Jose Mazieri
Status: Merged
Approved by: Arto Jalkanen
Approved revision: 388
Merged at revision: 397
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-03
Merge into: lp:ubuntu-filemanager-app
Prerequisite: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-02
Diff against target: 1628 lines (+1015/-172)
20 files modified
src/plugin/folderlistmodel/CMakeLists.txt (+10/-2)
src/plugin/folderlistmodel/cleanurl.cpp (+73/-0)
src/plugin/folderlistmodel/cleanurl.h (+47/-0)
src/plugin/folderlistmodel/dirmodel.cpp (+7/-4)
src/plugin/folderlistmodel/dirmodel.h (+1/-0)
src/plugin/folderlistmodel/disk/disklocation.cpp (+18/-70)
src/plugin/folderlistmodel/disk/disklocation.h (+4/-4)
src/plugin/folderlistmodel/folderlistmodel.pri (+23/-21)
src/plugin/folderlistmodel/iorequest.cpp (+17/-5)
src/plugin/folderlistmodel/iorequest.h (+3/-1)
src/plugin/folderlistmodel/location.cpp (+174/-8)
src/plugin/folderlistmodel/location.h (+44/-9)
src/plugin/folderlistmodel/locationitemdiriterator.cpp (+44/-0)
src/plugin/folderlistmodel/locationitemdiriterator.h (+68/-0)
src/plugin/folderlistmodel/locationsfactory.cpp (+85/-42)
src/plugin/folderlistmodel/locationsfactory.h (+46/-4)
src/plugin/folderlistmodel/net/netauthenticationdata.cpp (+219/-0)
src/plugin/folderlistmodel/net/netauthenticationdata.h (+97/-0)
src/plugin/folderlistmodel/trash/trashlocation.cpp (+30/-2)
src/plugin/folderlistmodel/trash/trashlocation.h (+5/-0)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-03
Reviewer Review Type Date Requested Status
Arto Jalkanen Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+252219@code.launchpad.net

Commit message

Refactoring in the Location class to be more suitable for new protocols browsing implementation

Description of the change

Refactoring in the Location class to be more suitable for new protocols browsing implementation

Some pure methods from Location class now have a default implementatation.
Location class now is responsable to create other objects, added 2 pure methods:
 DirItemInfo * newItemInfo()
 DirListWorkder * newListWorker()

Added signal Location::needsAuthentication()

Added class NetAuthenticationDataList to store user/password for URLs.

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) wrote :

Small typo in method name, otherwise fine.

review: Approve
Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

> Small typo in method name, otherwise fine.

Let me know where so I can fix that.

Revision history for this message
Arto Jalkanen (ajalkane) wrote :

> > Small typo in method name, otherwise fine.
>
> Let me know where so I can fix that.

Yeah sorry, those inlined comments are really hard to find. It's this:

bool LocationsFactory::lastUrlNeedsAuthencation() const
->
bool LocationsFactory::lastUrlNeedsAuthentication() const

Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

Thanks,

That has been changed on MP 09 -> https://code.launchpad.net/~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-09/+merge/252979 which finishes authentication stuff.

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 2014-05-02 12:22:11 +0000
+++ src/plugin/folderlistmodel/CMakeLists.txt 2015-03-08 12:31:26 +0000
@@ -1,7 +1,8 @@
1include_directories(1include_directories(
2 ${CMAKE_CURRENT_SOURCE_DIR}2 ${CMAKE_CURRENT_SOURCE_DIR}
3 disk3 disk
4 trash4 trash
5 net
5)6)
67
7set(PLUGIN_DIR org/nemomobile/folderlistmodel)8set(PLUGIN_DIR org/nemomobile/folderlistmodel)
@@ -40,6 +41,10 @@
40 locationsfactory.h41 locationsfactory.h
41 locationurl.cpp42 locationurl.cpp
42 locationurl.h43 locationurl.h
44 locationitemdiriterator.cpp
45 locationitemdiriterator.h
46 cleanurl.cpp
47 cleanurl.h
43 disk/disklocation.cpp48 disk/disklocation.cpp
44 disk/disklocation.h49 disk/disklocation.h
45 trash/qtrashdir.cpp50 trash/qtrashdir.cpp
@@ -49,7 +54,9 @@
49 trash/trashiteminfo.cpp54 trash/trashiteminfo.cpp
50 trash/trashiteminfo.h55 trash/trashiteminfo.h
51 trash/trashlocation.cpp56 trash/trashlocation.cpp
52 trash/trashlocation.h57 trash/trashlocation.h
58 net/netauthenticationdata.cpp
59 net/netauthenticationdata.h
53)60)
5461
55add_library(nemofolderlistmodel MODULE62add_library(nemofolderlistmodel MODULE
@@ -58,6 +65,7 @@
5865
59qt5_use_modules(nemofolderlistmodel Gui Qml Quick Widgets)66qt5_use_modules(nemofolderlistmodel Gui Qml Quick Widgets)
6067
68
61# Copy the plugin, the qmldir file and other assets to the build dir for running in QtCreator69# Copy the plugin, the qmldir file and other assets to the build dir for running in QtCreator
62if(NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")70if(NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
63 add_custom_command(TARGET nemofolderlistmodel POST_BUILD71 add_custom_command(TARGET nemofolderlistmodel POST_BUILD
6472
=== added file 'src/plugin/folderlistmodel/cleanurl.cpp'
--- src/plugin/folderlistmodel/cleanurl.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/cleanurl.cpp 2015-03-08 12:31:26 +0000
@@ -0,0 +1,73 @@
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: cleanurl.cpp
19 * Date: 04/02/2015
20 */
21
22#include "cleanurl.h"
23
24#include <QUrl>
25
26CleanUrl::CleanUrl(const QString &urlPath) : m_user(0), m_password(0)
27{
28 QUrl url(urlPath);
29 if (url.isValid())
30 {
31 QString user = url.userName();
32 if (!user.isEmpty())
33 {
34 m_user = new QString(user);
35 m_password = new QString(url.password());
36 url.setPassword(QLatin1String(0));
37 url.setUserName(QLatin1String(0));
38 }
39 m_url = url.toString();
40 }
41 else
42 {
43 m_url = urlPath;
44 }
45}
46
47
48CleanUrl::~CleanUrl()
49{
50 if (m_user) { delete m_user; }
51 if (m_password) { delete m_password;}
52}
53
54
55bool CleanUrl::hasAuthenticationData() const
56{
57 return m_user ? true : false;
58}
59
60QString CleanUrl::user() const
61{
62 return m_user ? *m_user : QString();
63}
64
65QString CleanUrl::password() const
66{
67 return m_password ? *m_password : QString();
68}
69
70QString CleanUrl::cleanUrl() const
71{
72 return m_url;
73}
074
=== added file 'src/plugin/folderlistmodel/cleanurl.h'
--- src/plugin/folderlistmodel/cleanurl.h 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/cleanurl.h 2015-03-08 12:31:26 +0000
@@ -0,0 +1,47 @@
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: cleanurl.h
19 * Date: 04/02/2015
20 */
21
22#ifndef CLEANURL_H
23#define CLEANURL_H
24
25#include <QString>
26
27/*!
28 * \brief The CleanUrl class
29 *
30 * Just returns a URL without user/password if exists
31 */
32class CleanUrl
33{
34public:
35 CleanUrl(const QString &urlPath);
36 ~CleanUrl();
37 bool hasAuthenticationData() const;
38 QString cleanUrl() const;
39 QString user() const;
40 QString password() const;
41private:
42 QString m_url; //!< keeps the url without user/password
43 QString * m_user;
44 QString * m_password;
45};
46
47#endif // CLEANURL_H
048
=== modified file 'src/plugin/folderlistmodel/dirmodel.cpp'
--- src/plugin/folderlistmodel/dirmodel.cpp 2015-03-08 12:31:26 +0000
+++ src/plugin/folderlistmodel/dirmodel.cpp 2015-03-08 12:31:26 +0000
@@ -218,10 +218,11 @@
218 roles.insert(FilePathRole, QByteArray("filePath"));218 roles.insert(FilePathRole, QByteArray("filePath"));
219 roles.insert(IsDirRole, QByteArray("isDir")); 219 roles.insert(IsDirRole, QByteArray("isDir"));
220 roles.insert(IsHostRole, QByteArray("isHost"));220 roles.insert(IsHostRole, QByteArray("isHost"));
221 roles.insert(IsSmbWorkgroupRole, QByteArray("IsSmbWorkgroup"));221 roles.insert(IsSmbWorkgroupRole, QByteArray("isSmbWorkgroup"));
222 roles.insert(IsSmbShareRole, QByteArray("IsSmbShare"));222 roles.insert(IsSmbShareRole, QByteArray("isSmbShare"));
223 roles.insert(IsSharedDirRole, QByteArray("IsSharedDir"));223 roles.insert(IsSharedDirRole, QByteArray("isSharedDir"));
224 roles.insert(IsSharingAllowedRole, QByteArray("IsSharingAllowed"));224 roles.insert(IsSharingAllowedRole, QByteArray("isSharingAllowed"));
225 roles.insert(IsBrowsableRole, QByteArray("isBrowsable"));
225 roles.insert(IsFileRole, QByteArray("isFile"));226 roles.insert(IsFileRole, QByteArray("isFile"));
226 roles.insert(IsReadableRole, QByteArray("isReadable"));227 roles.insert(IsReadableRole, QByteArray("isReadable"));
227 roles.insert(IsWritableRole, QByteArray("isWritable"));228 roles.insert(IsWritableRole, QByteArray("isWritable"));
@@ -383,6 +384,8 @@
383 return fi.isWorkGroup();384 return fi.isWorkGroup();
384 case IsSmbShareRole:385 case IsSmbShareRole:
385 return fi.isShare();386 return fi.isShare();
387 case IsBrowsableRole:
388 return fi.isBrowsable();
386 case IsSharingAllowedRole:389 case IsSharingAllowedRole:
387 return fi.isDir() && !fi.isSymLink() && !fi.isSharedDir()390 return fi.isDir() && !fi.isSymLink() && !fi.isSharedDir()
388 && mCurLocation->type() == LocationsFactory::LocalDisk391 && mCurLocation->type() == LocationsFactory::LocalDisk
389392
=== modified file 'src/plugin/folderlistmodel/dirmodel.h'
--- src/plugin/folderlistmodel/dirmodel.h 2015-03-08 12:31:26 +0000
+++ src/plugin/folderlistmodel/dirmodel.h 2015-03-08 12:31:26 +0000
@@ -67,6 +67,7 @@
67 IsSmbShareRole,67 IsSmbShareRole,
68 IsSharedDirRole, //!< it can also be used for other protocols than smb/cifs68 IsSharedDirRole, //!< it can also be used for other protocols than smb/cifs
69 IsSharingAllowedRole,//!< true for local directories (not in Trash) and not IsSharedDirRole69 IsSharingAllowedRole,//!< true for local directories (not in Trash) and not IsSharedDirRole
70 IsBrowsableRole, //!< any Dir, Host, WorkGroup or Share
70 IsFileRole,71 IsFileRole,
71 IsReadableRole,72 IsReadableRole,
72 IsWritableRole,73 IsWritableRole,
7374
=== modified file 'src/plugin/folderlistmodel/disk/disklocation.cpp'
--- src/plugin/folderlistmodel/disk/disklocation.cpp 2014-05-14 22:51:47 +0000
+++ src/plugin/folderlistmodel/disk/disklocation.cpp 2015-03-08 12:31:26 +0000
@@ -46,49 +46,6 @@
46}46}
4747
4848
49void DiskLocation::fetchItems(QDir::Filter dirFilter, bool recursive)
50{
51 DirListWorker *dlw = new DirListWorker(m_info->absoluteFilePath(), dirFilter, recursive);
52 connect(dlw, SIGNAL(itemsAdded(DirItemInfoList)),
53 this, SIGNAL(itemsAdded(DirItemInfoList)));
54 connect(dlw, SIGNAL(workerFinished()),
55 this, SLOT(onItemsFetched()));
56 workerThread()->addRequest(dlw);
57}
58
59
60bool DiskLocation::becomeParent()
61{
62 bool ret = false;
63 if (m_info && !m_info->isRoot())
64 {
65 DirItemInfo *other = new DirItemInfo(m_info->absolutePath());
66 if (other->isValid())
67 {
68 delete m_info;
69 m_info = other;
70 ret = true;
71 }
72 else
73 {
74 delete other;
75 }
76 }
77 return ret;
78}
79
80
81void DiskLocation::refreshInfo()
82{
83 if (m_info)
84 {
85 DirItemInfo *item = new DirItemInfo(m_info->absoluteFilePath());
86 delete m_info;
87 m_info = item;
88 }
89}
90
91
92/*!49/*!
93 * \brief DiskLocation::stopExternalFsWatcher() stops the External File System Watcher50 * \brief DiskLocation::stopExternalFsWatcher() stops the External File System Watcher
94 */51 */
@@ -115,11 +72,12 @@
115 m_extWatcher->setIntervalToNotifyChanges(EX_FS_WATCHER_TIMER_INTERVAL);72 m_extWatcher->setIntervalToNotifyChanges(EX_FS_WATCHER_TIMER_INTERVAL);
11673
117 connect(m_extWatcher, SIGNAL(pathModified(QString)),74 connect(m_extWatcher, SIGNAL(pathModified(QString)),
118 this, SIGNAL(extWatcherPathChanged(QString))); 75 this, SIGNAL(extWatcherPathChanged(QString)));
119 if (m_info)76 }
120 { //setCurrentPath() checks for empty paths77 if (m_extWatcher && m_info)
78 {
79 //setCurrentPath() checks for empty paths
121 m_extWatcher->setCurrentPath(m_info->absoluteFilePath());80 m_extWatcher->setCurrentPath(m_info->absoluteFilePath());
122 }
123 }81 }
124}82}
12583
@@ -187,9 +145,8 @@
187145
188146
189void DiskLocation::setUsingExternalWatcher(bool use)147void DiskLocation::setUsingExternalWatcher(bool use)
190{148{
191 Location::setUsingExternalWatcher(use);149 if ((m_usingExternalWatcher = use))
192 if (m_usingExternalWatcher)
193 {150 {
194 startExternalFsWatcher();151 startExternalFsWatcher();
195 }152 }
@@ -200,23 +157,14 @@
200}157}
201158
202159
203DirItemInfo * DiskLocation::validateUrlPath(const QString& uPath)160DirItemInfo * DiskLocation::newItemInfo(const QString &urlPath)
204{161{
205 QString myPath(uPath);162 return new DirItemInfo(urlPath);
206 QFileInfo tmpUrl(uPath);163}
207 if (tmpUrl.isRelative() && m_info)164
208 {165
209 tmpUrl.setFile(m_info->absoluteFilePath(), uPath);166DirListWorker * DiskLocation::newListWorker(const QString &urlPath, QDir::Filter filter, const bool isRecursive)
210 myPath = tmpUrl.absoluteFilePath();167{
211 }168 return new DirListWorker(urlPath,filter,isRecursive);
212#if DEBUG_MESSAGES169}
213 qDebug() << Q_FUNC_INFO << "path:" << myPath;170
214#endif
215 DirItemInfo * item = new DirItemInfo(myPath);
216 if (!item->isValid() || !item->exists() || !item->isContentReadable())
217 {
218 delete item;
219 item = 0;
220 }
221 return item;
222}
223171
=== modified file 'src/plugin/folderlistmodel/disk/disklocation.h'
--- src/plugin/folderlistmodel/disk/disklocation.h 2014-05-14 22:51:47 +0000
+++ src/plugin/folderlistmodel/disk/disklocation.h 2015-03-08 12:31:26 +0000
@@ -49,12 +49,9 @@
4949
50 ExternalFSWatcher * getExternalFSWatcher() const;50 ExternalFSWatcher * getExternalFSWatcher() const;
5151
52 virtual void fetchItems(QDir::Filter dirFilter, bool recursive = false) ;
53 virtual void fetchExternalChanges(const QString& urlPath,52 virtual void fetchExternalChanges(const QString& urlPath,
54 const DirItemInfoList& list,53 const DirItemInfoList& list,
55 QDir::Filter dirFilter) ;54 QDir::Filter dirFilter) ;
56 virtual bool becomeParent();
57 virtual void refreshInfo();
5855
59 virtual void startExternalFsWatcher();56 virtual void startExternalFsWatcher();
60 virtual void stopExternalFsWatcher();57 virtual void stopExternalFsWatcher();
@@ -62,7 +59,10 @@
62 virtual void startWorking();59 virtual void startWorking();
63 virtual void stopWorking();60 virtual void stopWorking();
6461
65 virtual DirItemInfo *validateUrlPath(const QString& urlPath);62 virtual DirItemInfo * newItemInfo(const QString& urlPath);
63 virtual DirListWorker * newListWorker(const QString &urlPath,
64 QDir::Filter filter,
65 const bool isRecursive);
6666
67protected:67protected:
68 void addExternalFsWorkerRequest(ExternalFileSystemChangesWorker *);68 void addExternalFsWorkerRequest(ExternalFileSystemChangesWorker *);
6969
=== modified file 'src/plugin/folderlistmodel/folderlistmodel.pri'
--- src/plugin/folderlistmodel/folderlistmodel.pri 2014-05-02 12:22:11 +0000
+++ src/plugin/folderlistmodel/folderlistmodel.pri 2015-03-08 12:31:26 +0000
@@ -8,16 +8,12 @@
8 $$PWD/clipboard.cpp \8 $$PWD/clipboard.cpp \
9 $$PWD/fmutil.cpp \9 $$PWD/fmutil.cpp \
10 $$PWD/dirselection.cpp \10 $$PWD/dirselection.cpp \
11 $$PWD/diriteminfo.cpp \11 $$PWD/diriteminfo.cpp \
12 $$PWD/trash/qtrashdir.cpp \
13 $$PWD/trash/trashiteminfo.cpp \
14 $$PWD/location.cpp \12 $$PWD/location.cpp \
15 $$PWD/locationsfactory.cpp \13 $$PWD/locationsfactory.cpp \
16 $$PWD/disk/disklocation.cpp \14 $$PWD/locationurl.cpp \
17 $$PWD/trash/trashlocation.cpp \15 $$PWD/locationitemdiriterator.cpp \
18 $$PWD/locationurl.cpp \16 $$PWD/cleanurl.cpp
19 $$PWD/trash/qtrashutilinfo.cpp
20
2117
22HEADERS += $$PWD/dirmodel.h \18HEADERS += $$PWD/dirmodel.h \
23 $$PWD/iorequest.h \19 $$PWD/iorequest.h \
@@ -29,19 +25,25 @@
29 $$PWD/clipboard.h \25 $$PWD/clipboard.h \
30 $$PWD/fmutil.h \26 $$PWD/fmutil.h \
31 $$PWD/dirselection.h \ 27 $$PWD/dirselection.h \
32 $$PWD/diritemabstractlistmodel.h \28 $$PWD/diritemabstractlistmodel.h \
33 $$PWD/diriteminfo.h \
34 $$PWD/trash/qtrashdir.h \
35 $$PWD/trash/trashiteminfo.h \
36 $$PWD/location.h \29 $$PWD/location.h \
37 $$PWD/locationsfactory.h \30 $$PWD/locationsfactory.h \
38 $$PWD/disk/disklocation.h \31 $$PWD/locationurl.h \
39 $$PWD/trash/trashlocation.h \32 $$PWD/locationitemdiriterator.h \
40 $$PWD/locationurl.h \33 $$PWD/cleanurl.h
41 $$PWD/trash/qtrashutilinfo.h34
4235SOURCES += $$PWD/disk/disklocation.cpp
4336HEADERS += $$PWD/disk/disklocation.h
44INCLUDEPATH += $$PWD $$PWD/trash $$PWD/disk37
38SOURCES += $$PWD/trash/qtrashdir.cpp $$PWD/trash/trashiteminfo.cpp \
39 $$PWD/trash/qtrashutilinfo.cpp $$PWD/trash/trashlocation.cpp
40HEADERS += $$PWD/trash/qtrashdir.h $$PWD/trash/trashiteminfo.h \
41 $$PWD/trash/qtrashutilinfo.h $$PWD/trash/trashlocation.h
42
43SOURCES += $$PWD/net/netauthenticationdata.cpp
44HEADERS += $$PWD/net/netauthenticationdata.h
45
46INCLUDEPATH += $$PWD $$PWD/trash $$PWD/disk $$PWD/net
4547
46greaterThan(QT_MAJOR_VERSION, 4) {48greaterThan(QT_MAJOR_VERSION, 4) {
47 QT += qml49 QT += qml
4850
=== modified file 'src/plugin/folderlistmodel/iorequest.cpp'
--- src/plugin/folderlistmodel/iorequest.cpp 2014-12-30 18:23:15 +0000
+++ src/plugin/folderlistmodel/iorequest.cpp 2015-03-08 12:31:26 +0000
@@ -89,9 +89,14 @@
8989
90DirItemInfoList IORequestLoader::getContents()90DirItemInfoList IORequestLoader::getContents()
91{91{
92 return mLoaderType == NormalLoader ?92 DirItemInfoList list;
93 getNormalContent() :93 switch(mLoaderType)
94 getTrashContent();94 {
95 case NormalLoader: list = getNormalContent(); break;
96 case TrashLoader: list = getTrashContent(); break;
97 case NetworkLoader: list = getNetworkContent(); break;
98 }
99 return list;
95}100}
96101
97DirItemInfoList IORequestLoader::getNormalContent()102DirItemInfoList IORequestLoader::getNormalContent()
@@ -112,8 +117,7 @@
112{117{
113 QDir tmpDir = QDir(pathName, QString(), QDir::NoSort, filter);118 QDir tmpDir = QDir(pathName, QString(), QDir::NoSort, filter);
114 QDirIterator it(tmpDir);119 QDirIterator it(tmpDir);
115 while (it.hasNext())120 while (it.hasNext()) {
116 {
117 it.next();121 it.next();
118 if(it.fileInfo().isDir() && isRecursive) {122 if(it.fileInfo().isDir() && isRecursive) {
119 directoryContents = add(it.fileInfo().filePath(),123 directoryContents = add(it.fileInfo().filePath(),
@@ -150,6 +154,14 @@
150}154}
151155
152156
157DirItemInfoList IORequestLoader::getNetworkContent()
158{
159 DirItemInfoList emptyContent;
160 return emptyContent;
161}
162
163
164
153//-----------------------------------------------------------------------------------------------165//-----------------------------------------------------------------------------------------------
154DirListWorker::DirListWorker(const QString &pathName, QDir::Filter filter, const bool isRecursive)166DirListWorker::DirListWorker(const QString &pathName, QDir::Filter filter, const bool isRecursive)
155 : IORequestLoader(pathName, filter, isRecursive)167 : IORequestLoader(pathName, filter, isRecursive)
156168
=== modified file 'src/plugin/folderlistmodel/iorequest.h'
--- src/plugin/folderlistmodel/iorequest.h 2014-05-15 00:18:54 +0000
+++ src/plugin/folderlistmodel/iorequest.h 2015-03-08 12:31:26 +0000
@@ -70,7 +70,8 @@
70 enum LoaderType70 enum LoaderType
71 {71 {
72 NormalLoader,72 NormalLoader,
73 TrashLoader73 TrashLoader,
74 NetworkLoader
74 };75 };
7576
76 IORequestLoader( const QString &pathName,77 IORequestLoader( const QString &pathName,
@@ -91,6 +92,7 @@
91private:92private:
92 DirItemInfoList getNormalContent();93 DirItemInfoList getNormalContent();
93 DirItemInfoList getTrashContent();94 DirItemInfoList getTrashContent();
95 virtual DirItemInfoList getNetworkContent();
94 DirItemInfoList add(const QString &pathName, QDir::Filter filter,96 DirItemInfoList add(const QString &pathName, QDir::Filter filter,
95 bool isRecursive, DirItemInfoList directoryContents);97 bool isRecursive, DirItemInfoList directoryContents);
96protected:98protected:
9799
=== modified file 'src/plugin/folderlistmodel/location.cpp'
--- src/plugin/folderlistmodel/location.cpp 2014-05-14 22:51:47 +0000
+++ src/plugin/folderlistmodel/location.cpp 2015-03-08 12:31:26 +0000
@@ -41,6 +41,7 @@
4141
42#include "location.h"42#include "location.h"
43#include "ioworkerthread.h"43#include "ioworkerthread.h"
44#include "netauthenticationdata.h"
4445
45Q_GLOBAL_STATIC(IOWorkerThread, ioWorkerThread)46Q_GLOBAL_STATIC(IOWorkerThread, ioWorkerThread)
4647
@@ -72,7 +73,7 @@
7273
73bool Location::isWritable() const74bool Location::isWritable() const
74{75{
75 return m_info->isWritable();76 return m_info ? m_info->isWritable() : false;
76}77}
7778
7879
@@ -112,10 +113,6 @@
112113
113}114}
114115
115bool Location::becomeParent()
116{
117 return false;
118}
119116
120IOWorkerThread * Location::workerThread() const117IOWorkerThread * Location::workerThread() const
121{118{
@@ -133,8 +130,177 @@
133 Q_UNUSED(dirFilter);130 Q_UNUSED(dirFilter);
134}131}
135132
136133//======================================================================================================
134/*!
135 * \brief Location::setUsingExternalWatcher() Default implementation sets nothing
136 *
137 * It considers that there is no external Watcher
138 * \param use
139 */
137void Location::setUsingExternalWatcher(bool use)140void Location::setUsingExternalWatcher(bool use)
138{141{
139 m_usingExternalWatcher = use;142 Q_UNUSED(use)
140}143 m_usingExternalWatcher = false;
144}
145
146
147/*!
148 * \brief Location::setAuthentication()
149 *
150 * Default implementation does nothing as local disk does not need it
151 *
152 * Network Locations need to reimplement this
153 *
154 * \param user
155 * \param password
156 */
157void Location::setAuthentication(const QString &user,
158 const QString &password)
159
160{
161 Q_UNUSED(user);
162 Q_UNUSED(password);
163}
164
165/*!
166 * \brief Location::currentAuthenticationUser()
167 *
168 * Default implementation returns current user
169 *
170 * \return
171 */
172QString Location::currentAuthenticationUser()
173{
174 return QString(::qgetenv("USER"));
175}
176
177/*!
178 * \brief Location::currentAuthenticationPassword()
179 *
180 * Default implementation returns empty string
181 *
182 * \return
183 */
184QString Location::currentAuthenticationPassword()
185{
186 return QString();
187}
188
189/*!
190 * \brief Location::notifyItemNeedsAuthentication()
191 * \param item
192 *
193 * \note
194 * The connection between Location objects and the \class DirModel is Qt::QueuedConnection
195 * It allows a UI to continuosly show dialogs asking the user to provide User and Password
196 * to authenticate the current URL
197 */
198void Location::notifyItemNeedsAuthentication(const DirItemInfo *item)
199{
200 if (item == 0)
201 {
202 item = m_info;
203 }
204 if (item != 0)
205 {
206 emit needsAuthentication(currentAuthenticationUser(), item->urlPath());
207 }
208}
209
210
211
212bool Location::useAuthenticationDataIfExists(const DirItemInfo& item)
213{
214 NetAuthenticationDataList *authData = NetAuthenticationDataList::getInstance(this);
215 const NetAuthenticationData *auth = authData->get(item.authenticationPath());
216 bool ret = false;
217 if (auth && !( auth->user == currentAuthenticationUser()
218 && auth->password == currentAuthenticationPassword()
219 )
220 )
221 {
222 setAuthentication(auth->user, auth->password);
223 ret = true;
224 }
225 NetAuthenticationDataList::releaseInstance(this);
226 return ret;
227}
228
229
230
231void Location::refreshInfo()
232{
233 if (m_info)
234 {
235 DirItemInfo *item = newItemInfo(m_info->absoluteFilePath());
236 delete m_info;
237 m_info = item;
238 }
239}
240
241
242bool Location::becomeParent()
243{
244 bool ret = false;
245 if (m_info && !m_info->isRoot())
246 {
247 DirItemInfo *other = newItemInfo(m_info->absolutePath());
248 if (other->isValid())
249 {
250 delete m_info;
251 m_info = other;
252 ret = true;
253 }
254 else
255 {
256 delete other;
257 }
258 }
259 return ret;
260}
261
262
263DirItemInfo * Location::validateUrlPath(const QString & uPath)
264{
265 QString myPath(uPath);
266 DirItemInfo * item = newItemInfo(myPath);
267 if (item->isRelative() && m_info)
268 {
269 item->setFile(m_info->urlPath(), uPath);
270 myPath = item->urlPath();
271 }
272
273#if DEBUG_MESSAGES
274 qDebug() << Q_FUNC_INFO << "path:" << myPath << "needsAuthentication:" << item->needsAuthentication();
275#endif
276
277 // the isContentReadable() is not checked here
278 // because it will be false when authentication is required
279 if (!item->isValid() || !item->exists())
280 {
281 delete item;
282 item = 0;
283 }
284 return item;
285}
286
287
288void Location::fetchItems(QDir::Filter dirFilter, bool recursive)
289{
290 //it should never happen here
291 if (m_info->needsAuthentication())
292 {
293 emit needsAuthentication(currentAuthenticationUser(), m_info->absoluteFilePath());
294 }
295 else
296 {
297 DirListWorker *dlw = newListWorker(m_info->absoluteFilePath(), dirFilter, recursive);
298 connect(dlw, SIGNAL(itemsAdded(DirItemInfoList)),
299 this, SIGNAL(itemsAdded(DirItemInfoList)));
300 connect(dlw, SIGNAL(workerFinished()),
301 this, SIGNAL(itemsFetched()));
302 workerThread()->addRequest(dlw);
303 }
304}
305
306
141307
=== modified file 'src/plugin/folderlistmodel/location.h'
--- src/plugin/folderlistmodel/location.h 2014-05-14 22:51:47 +0000
+++ src/plugin/folderlistmodel/location.h 2015-03-08 12:31:26 +0000
@@ -27,6 +27,7 @@
27#include <QObject>27#include <QObject>
2828
29class IOWorkerThread;29class IOWorkerThread;
30class DirListWorker;
3031
31/*!32/*!
32 * \brief The Location class represents any location (full path) where there are items to browse: directories, shares, from Disk and from Network.33 * \brief The Location class represents any location (full path) where there are items to browse: directories, shares, from Disk and from Network.
@@ -45,9 +46,10 @@
45class Location : public QObject46class Location : public QObject
46{47{
47 Q_OBJECT48 Q_OBJECT
48public:49public:
50 virtual ~Location();
51protected:
49 explicit Location( int type, QObject *parent=0);52 explicit Location( int type, QObject *parent=0);
50 virtual ~Location();
5153
52 IOWorkerThread * workerThread() const;54 IOWorkerThread * workerThread() const;
5355
@@ -59,18 +61,44 @@
59 void extWatcherItemChanged(const DirItemInfo&);61 void extWatcherItemChanged(const DirItemInfo&);
60 void extWatcherItemAdded(const DirItemInfo&);62 void extWatcherItemAdded(const DirItemInfo&);
61 void extWatcherChangesFetched(int);63 void extWatcherChangesFetched(int);
64 void needsAuthentication(const QString& user, const QString& urlPath);
6265
63public slots:66public slots:
64 virtual void setUsingExternalWatcher(bool use);67 virtual void setUsingExternalWatcher(bool use);
68 virtual void setAuthentication(const QString& user,
69 const QString& password);
70
6571
66public: //pure functions72public: //pure functions
67 /*!73 /*!
74 * \brief newItemInfo() returns a Location suitable DirItemInfo object
75 *
76 * Every Locations must create its own DirItemInfo object with all the information set
77 * \param urlPath it can also contain User and Password when in the form of an URL
78 * \return the object created
79 */
80 virtual DirItemInfo * newItemInfo(const QString& urlPath) = 0;
81
82 /*!
83 * \brief newListWorker() creates a Location suitable DirListWorker object which will create a new \ref DirItemInfoList for browsing items
84 *
85 * The DirListWorker object will be used in \ref fetchItems()
86 *
87 * \param urlPath urlPath it can also contain User and Password when in the form of an URL
88 * \param filter
89 * \param isRecursive
90 * \return the object which will fill a new \ref DirItemInfoList for browsing items
91 */
92 virtual DirListWorker * newListWorker(const QString &urlPath, QDir::Filter filter, const bool isRecursive) = 0;
93
94public:
95 /*!
68 * \brief fetchItems() gets the content of the Location96 * \brief fetchItems() gets the content of the Location
69 *97 *
70 * \param dirFilter current Filter98 * \param dirFilter current Filter
71 * \param recursive should get the content all sub dirs or not, (hardly ever it is true)99 * \param recursive should get the content all sub dirs or not, (hardly ever it is true)
72 */100 */
73 virtual void fetchItems(QDir::Filter dirFilter, bool recursive=0) = 0;101 virtual void fetchItems(QDir::Filter dirFilter, bool recursive=false);
74102
75 /*!103 /*!
76 * \brief refreshInfo() It must refresh the DirItemInfo104 * \brief refreshInfo() It must refresh the DirItemInfo
@@ -78,9 +106,9 @@
78 * It can be used for example after receiving the signal about external disk file system changes106 * It can be used for example after receiving the signal about external disk file system changes
79 * due to the current path permissions might have changed.107 * due to the current path permissions might have changed.
80 */108 */
81 virtual void refreshInfo() = 0;109 virtual void refreshInfo();
82110
83 /*!111 /*!
84 * \brief becomeParent() The current path location becomes the parent Location112 * \brief becomeParent() The current path location becomes the parent Location
85 *113 *
86 * When \ref isRoot() returns false the current path location becomes the parent path location114 * When \ref isRoot() returns false the current path location becomes the parent path location
@@ -91,7 +119,7 @@
91 *119 *
92 * \return true if it is possible to do like a cdUp.120 * \return true if it is possible to do like a cdUp.
93 */121 */
94 virtual bool becomeParent() = 0;122 virtual bool becomeParent();
95123
96 /*!124 /*!
97 * \brief validateUrlPath() Validates the urlPath (file or Directory) and creates a new Obeject from this path125 * \brief validateUrlPath() Validates the urlPath (file or Directory) and creates a new Obeject from this path
@@ -101,9 +129,10 @@
101 * \param urlPath129 * \param urlPath
102 * \return a valid pointer to DirItemInfo object or NULL indicating something wrong with the path130 * \return a valid pointer to DirItemInfo object or NULL indicating something wrong with the path
103 */131 */
104 virtual DirItemInfo * validateUrlPath(const QString& urlPath) = 0;132 virtual DirItemInfo * validateUrlPath(const QString& urlPath);
105133
106public:134
135public: //virtual
107 virtual void fetchExternalChanges(const QString& urlPath,136 virtual void fetchExternalChanges(const QString& urlPath,
108 const DirItemInfoList& list,137 const DirItemInfoList& list,
109 QDir::Filter dirFilter) ;138 QDir::Filter dirFilter) ;
@@ -115,6 +144,12 @@
115 virtual QString urlPath() const;144 virtual QString urlPath() const;
116 virtual void startWorking();145 virtual void startWorking();
117 virtual void stopWorking();146 virtual void stopWorking();
147 virtual QString currentAuthenticationUser();
148 virtual QString currentAuthenticationPassword();
149
150public: //non virtual
151 void notifyItemNeedsAuthentication(const DirItemInfo *item = 0);
152 bool useAuthenticationDataIfExists(const DirItemInfo &item);
118153
119 inline const DirItemInfo* info() const { return m_info; }154 inline const DirItemInfo* info() const { return m_info; }
120 inline int type() const { return m_type; }155 inline int type() const { return m_type; }
121156
=== added file 'src/plugin/folderlistmodel/locationitemdiriterator.cpp'
--- src/plugin/folderlistmodel/locationitemdiriterator.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/locationitemdiriterator.cpp 2015-03-08 12:31:26 +0000
@@ -0,0 +1,44 @@
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: locationitemdiriterator.cpp
19 * Date: 10/01/2015
20 */
21
22#include "locationitemdiriterator.h"
23
24LocationItemDirIterator::LocationItemDirIterator(const QString &, const QStringList &, QDir::Filters, QDirIterator::IteratorFlags )
25{
26}
27
28
29LocationItemDirIterator::LocationItemDirIterator(const QString &, QDir::Filters , QDirIterator::IteratorFlags)
30{
31
32}
33
34LocationItemDirIterator::LocationItemDirIterator(const QString &, QDirIterator::IteratorFlags )
35{
36
37}
38
39LocationItemDirIterator::~LocationItemDirIterator()
40{
41
42}
43
44
045
=== added file 'src/plugin/folderlistmodel/locationitemdiriterator.h'
--- src/plugin/folderlistmodel/locationitemdiriterator.h 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/locationitemdiriterator.h 2015-03-08 12:31:26 +0000
@@ -0,0 +1,68 @@
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: locationitemdiriterator.h
19 * Date: 10/01/2015
20 */
21
22#ifndef LOCATIONITEMDIRITERATOR_H
23#define LOCATIONITEMDIRITERATOR_H
24
25#include <QDirIterator>
26#include "diriteminfo.h"
27
28/*!
29 * \brief The LocationItemDirIterator class is an abstract similar to Qt QDirIterator
30 *
31 * Different protocols supported by filemanager (different Locations) must provide a class like that.
32 */
33
34class LocationItemDirIterator
35{
36public:
37 virtual ~LocationItemDirIterator();
38public:
39 virtual bool hasNext() const = 0;
40 virtual QString next() = 0;
41
42 virtual DirItemInfo fileInfo() const = 0;
43 /*!
44 * \brief fileName()
45 * \return the file name for the current directory entry, without the path prepended.
46 */
47 virtual QString fileName() const = 0;
48
49 /*!
50 * \brief filePath()
51 * \return the full pathname of the current item
52 */
53 virtual QString filePath() const = 0;
54
55 /*!
56 * \brief path()
57 * \return the base directory of the iterator path (not the current item)
58 */
59 virtual QString path() const = 0;
60
61protected:
62 LocationItemDirIterator(const QString & path, QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
63 LocationItemDirIterator(const QString & path, QDir::Filters filters, QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
64 LocationItemDirIterator(const QString & path, const QStringList & nameFilters, QDir::Filters filters = QDir::NoFilter, QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
65};
66
67
68#endif // LOCATIONITEMDIRITERATOR_H
069
=== modified file 'src/plugin/folderlistmodel/locationsfactory.cpp'
--- src/plugin/folderlistmodel/locationsfactory.cpp 2014-06-25 22:54:59 +0000
+++ src/plugin/folderlistmodel/locationsfactory.cpp 2015-03-08 12:31:26 +0000
@@ -26,22 +26,33 @@
26#include "disklocation.h"26#include "disklocation.h"
27#include "trashlocation.h"27#include "trashlocation.h"
28#include "trashiteminfo.h"28#include "trashiteminfo.h"
29#include "cleanurl.h"
30#include "netauthenticationdata.h"
2931
30#include <QDir>32#include <QDir>
31#include <QDebug>33#include <QDebug>
3234
3335
3436/*!
37 * \brief LocationsFactory::LocationsFactory()
38 * \param parent
39 *
40 * Locations emit needsAuthentication() signal, the connection
41 * with LocationsFactory is Direct, but the connection between
42 * the Location and the \ref DirModel is Queued
43 * \sa Location::notifyItemNeedsAuthentication()
44 */
35LocationsFactory::LocationsFactory(QObject *parent)45LocationsFactory::LocationsFactory(QObject *parent)
36 : QObject(parent)46 : QObject(parent)
37 , m_curLoc(0)47 , m_curLoc(0)
38 , m_lastValidFileInfo(0)48 , m_lastValidFileInfo(0)
49 , m_authDataStore(NetAuthenticationDataList::getInstance(this))
50 , m_lastUrlNeedsAuthentication(false)
39{51{
40 m_locations.append(new DiskLocation(LocalDisk));52 m_locations.append(new DiskLocation(LocalDisk));
41 m_locations.append(new TrashLocation(TrashDisk));53 m_locations.append(new TrashLocation(TrashDisk));
42}54}
4355
44
45LocationsFactory::~LocationsFactory()56LocationsFactory::~LocationsFactory()
46{57{
47 ::qDeleteAll(m_locations);58 ::qDeleteAll(m_locations);
@@ -50,6 +61,7 @@
50 {61 {
51 delete m_lastValidFileInfo;62 delete m_lastValidFileInfo;
52 }63 }
64 NetAuthenticationDataList::releaseInstance(this);
53}65}
5466
5567
@@ -72,20 +84,20 @@
72 if (uPath.startsWith(LocationUrl::TrashRootURL.midRef(0,6)))84 if (uPath.startsWith(LocationUrl::TrashRootURL.midRef(0,6)))
73 {85 {
74 type = TrashDisk;86 type = TrashDisk;
75 m_tmpPath = LocationUrl::TrashRootURL + stringAfterSlashes(uPath, index+1);87 m_tmpPath = LocationUrl::TrashRootURL + DirItemInfo::removeExtraSlashes(uPath, index+1);
76 }88 }
77 else89 else
78#endif //Q_OS_UNIX90#endif //Q_OS_UNIX
79#endif //Q_OS_UNIX91#endif
80 if (uPath.startsWith(LocationUrl::DiskRootURL.midRef(0,5)))92 if (uPath.startsWith(LocationUrl::DiskRootURL.midRef(0,5)))
81 {93 {
82 type = LocalDisk;94 type = LocalDisk;
83 m_tmpPath = QDir::rootPath() + stringAfterSlashes(uPath, index+1);95 m_tmpPath = QDir::rootPath() + DirItemInfo::removeExtraSlashes(uPath, index+1);
84 }96 }
85 }97 }
86 else98 else
87 {99 {
88 m_tmpPath = stringAfterSlashes(uPath, -1);100 m_tmpPath = DirItemInfo::removeExtraSlashes(uPath, -1);
89 type = LocalDisk;101 type = LocalDisk;
90 if (!m_tmpPath.startsWith(QDir::rootPath()) && m_curLoc)102 if (!m_tmpPath.startsWith(QDir::rootPath()) && m_curLoc)
91 {103 {
@@ -104,17 +116,34 @@
104}116}
105117
106118
107Location * LocationsFactory::setNewPath(const QString& uPath)119Location * LocationsFactory::setNewPath(const QString& uPath, const QString& authUser, const QString& passwd, bool savePassword)
108{120{
109 storeValidFileInfo(0);121 storeValidFileInfo(0);
110 Location *location = parse(uPath);122 CleanUrl url(uPath);
123 m_lastUrlNeedsAuthentication = false;
124 NetAuthenticationData authData(authUser, passwd);
125 if (authData.isEmpty() && url.hasAuthenticationData())
126 {
127 authData.user = url.user();
128 authData.password = url.password();
129 }
130 Location *location = parse(url.cleanUrl());
111 if (location)131 if (location)
112 {132 {
113 DirItemInfo *item = location->validateUrlPath(m_tmpPath);133 DirItemInfo *item = validateCurrentUrl(location,authData);
114 if (item)134 if (item)
115 {135 {
136 //now if there is Authentication Data
137 //at this point item is ready and authentication if necessary worked
138 if (item && !authData.isEmpty())
139 {
140 m_authDataStore->store(item->authenticationPath(),
141 authData.user,
142 authData.password,
143 savePassword);
144 }
116 //isContentReadable() must already carry execution permission145 //isContentReadable() must already carry execution permission
117 if (item->isValid() && item->isDir() && item->isContentReadable())146 if (item->isValid() && item->isBrowsable() && item->isContentReadable())
118 {147 {
119 location->setInfoItem(item);148 location->setInfoItem(item);
120 if (location != m_curLoc)149 if (location != m_curLoc)
@@ -146,38 +175,6 @@
146}175}
147176
148177
149QString LocationsFactory::stringAfterSlashes(const QString &url, int firstSlashIndex) const
150{
151 QString ret;
152 if (firstSlashIndex >=0)
153 {
154 while ( firstSlashIndex < url.length() && url.at(firstSlashIndex) == QDir::separator())
155 {
156 ++firstSlashIndex;
157 }
158 if (firstSlashIndex < url.length())
159 {
160 ret = url.mid(firstSlashIndex);
161 }
162 }
163 else
164 {
165 ret = url;
166 firstSlashIndex = 0;
167 }
168 //replace any double slashes by just one
169 for(int charCounter = ret.size() -1; charCounter > 0; --charCounter)
170 {
171 if (ret.at(charCounter) == QDir::separator() &&
172 ret.at(charCounter-1) == QDir::separator())
173 {
174 ret.remove(charCounter,1);
175 }
176 }
177 return ret;
178}
179
180
181void LocationsFactory::storeValidFileInfo(DirItemInfo *item)178void LocationsFactory::storeValidFileInfo(DirItemInfo *item)
182{179{
183 if (m_lastValidFileInfo)180 if (m_lastValidFileInfo)
@@ -186,3 +183,49 @@
186 }183 }
187 m_lastValidFileInfo = item;184 m_lastValidFileInfo = item;
188}185}
186
187
188void LocationsFactory::onUrlNeedsAuthentication(QString, QString)
189{
190 m_lastUrlNeedsAuthentication = true;
191}
192
193
194bool LocationsFactory::lastUrlNeedsAuthencation() const
195{
196 return m_lastUrlNeedsAuthentication;
197}
198
199
200DirItemInfo * LocationsFactory::validateCurrentUrl(Location *location, const NetAuthenticationData &authData)
201{
202 //when there is authentication data, set the authentication before validating an item
203 if (!authData.isEmpty())
204 {
205 location->setAuthentication(authData.user, authData.password);
206 }
207
208 DirItemInfo *item = location->validateUrlPath(m_tmpPath);
209
210 //for remote locations, authentication might have failed
211 //if so try to use a stored authentication data and authenticate it again
212 if ( item && item->needsAuthentication()
213 && location->useAuthenticationDataIfExists(*item))
214 {
215 delete item;
216 item = location->validateUrlPath(m_tmpPath);
217 }
218 //if failed it is necessary to ask the user to provide user/password
219 if ( item && item->needsAuthentication() )
220 {
221 location->notifyItemNeedsAuthentication(item);
222 delete item;
223 item = 0;
224 }
225 if (item && !item->isContentReadable())
226 {
227 delete item;
228 item = 0;
229 }
230 return item;
231}
189232
=== modified file 'src/plugin/folderlistmodel/locationsfactory.h'
--- src/plugin/folderlistmodel/locationsfactory.h 2014-05-24 01:40:01 +0000
+++ src/plugin/folderlistmodel/locationsfactory.h 2015-03-08 12:31:26 +0000
@@ -28,6 +28,8 @@
2828
29class Location;29class Location;
30class DirItemInfo;30class DirItemInfo;
31class NetAuthenticationDataList;
32class NetAuthenticationData;
3133
32/*!34/*!
33 * \brief The LocationsFactory class represents the set of main35 * \brief The LocationsFactory class represents the set of main
@@ -82,11 +84,17 @@
82 * When the location changes, the signal \ref locationChanged() is fired.84 * When the location changes, the signal \ref locationChanged() is fired.
83 *85 *
84 * \param urlPath the url like: file:///Item trash:///item /item, it MUST point to a valid Directory86 * \param urlPath the url like: file:///Item trash:///item /item, it MUST point to a valid Directory
87 * \param user an user when the URL requires authentication [optional]
88 * \param password when the URL requires authentication [optional]
89 *
85 * \return the location that supports the urlPath or NULL when \a urlPath is NOT a valid url or it is not a valid Directory90 * \return the location that supports the urlPath or NULL when \a urlPath is NOT a valid url or it is not a valid Directory
86 *91 *
87 * \sa \ref parse() \ref location()92 * \sa \ref parse() \ref location()
88 */93 */
89 Location * setNewPath(const QString& urlPath);94 Location * setNewPath(const QString& urlPath,
95 const QString& user = QString(),
96 const QString& password = QString(),
97 bool savePassword = false);
9098
91 /*!99 /*!
92 * \brief location()100 * \brief location()
@@ -113,19 +121,53 @@
113 */121 */
114 const DirItemInfo* lastValidFileInfo() const { return m_lastValidFileInfo; }122 const DirItemInfo* lastValidFileInfo() const { return m_lastValidFileInfo; }
115123
124 /*!
125 * \brief lastUrlNeedsAuthencation()
126 * \return true when last URL used in setNewPath() needs authentication
127 *
128 * It can be used to show a dialog to the user asking for user/password
129 * instead of showing a message saying that url does not exist
130 */
131 bool lastUrlNeedsAuthencation() const;
132
133private:
134 /*!
135 * \brief storeValidFileInfo() saves an item created by \ref setNewPath() when
136 * the item is not Browsable.
137 *
138 * It happens for example when the \a urlPath entered
139 * in \ref setNewPath() is a file (not a DIR nor other Browsable item)
140 *
141 * \param item
142 */
116 void storeValidFileInfo(DirItemInfo *item);143 void storeValidFileInfo(DirItemInfo *item);
117144
145 /*!
146 * \brief validateCurrentUrl() it attempts to validate the current URL being parsed
147 *
148 * The validation includes authentication, if a Authentication Data is already avaialable
149 * it is set to the location being parsed.
150 * When authentication fails the signal Location::needsAuthentication() is emitted
151 *
152 * \param location current Location for the current urlPath entered in \ref setNewPath()
153 *
154 * \return new Item validated (authenticated when remote authentication is required), otherwise NULL
155 */
156 DirItemInfo *validateCurrentUrl(Location *location, const NetAuthenticationData&);
157
118signals:158signals:
119 void locationChanged(const Location *old, const Location *current);159 void locationChanged(const Location *old, const Location *current);
120160
121private:161private slots:
122 QString stringAfterSlashes(const QString& url, int firstSlashIndex) const;162 void onUrlNeedsAuthentication(QString, QString);
123163
124private:164private:
125 Location * m_curLoc;165 Location * m_curLoc;
126 QList<Location*> m_locations;166 QList<Location*> m_locations;
127 QString m_tmpPath;167 QString m_tmpPath;
128 DirItemInfo * m_lastValidFileInfo;168 DirItemInfo * m_lastValidFileInfo;
169 NetAuthenticationDataList * m_authDataStore;
170 bool m_lastUrlNeedsAuthentication;
129171
130#if defined(REGRESSION_TEST_FOLDERLISTMODEL)172#if defined(REGRESSION_TEST_FOLDERLISTMODEL)
131 friend class TestDirModel;173 friend class TestDirModel;
132174
=== added directory 'src/plugin/folderlistmodel/net'
=== added file 'src/plugin/folderlistmodel/net/netauthenticationdata.cpp'
--- src/plugin/folderlistmodel/net/netauthenticationdata.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/net/netauthenticationdata.cpp 2015-03-08 12:31:26 +0000
@@ -0,0 +1,219 @@
1/**************************************************************************
2 *
3 * Copyright 2014 Canonical Ltd.
4 * Copyright 2014 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: netauthenticationdata.cpp
19 * Date: 29/11/2014
20 */
21
22#include "netauthenticationdata.h"
23
24#include <QStandardPaths>
25#include <QDir>
26#include <QSettings>
27#include <QCoreApplication>
28#include <QDebug>
29
30#define CHAR_CRYPT_OFFSET 31
31
32NetAuthenticationDataList * NetAuthenticationDataList::m_instance = 0;
33void * NetAuthenticationDataList::m_parent = 0;
34
35
36NetAuthenticationDataList::NetAuthenticationDataList(): m_savedAuths(0)
37{
38 //settings file does not need to open all the time
39 loadSavedAuthenticationData();
40}
41
42
43NetAuthenticationDataList::~NetAuthenticationDataList()
44{
45 qDeleteAll(m_urlEntries);
46 m_urlEntries.clear();
47 m_parent = 0;
48 m_instance = 0;
49 closeAuthenticationStore();
50}
51
52
53NetAuthenticationDataList * NetAuthenticationDataList::getInstance(void *parent)
54{
55 if (m_instance == 0)
56 {
57 m_instance = new NetAuthenticationDataList();
58 m_parent = parent;
59 }
60 return m_instance;
61}
62
63
64void NetAuthenticationDataList::releaseInstance(void *parent)
65{
66 if (parent == m_parent && m_instance != 0)
67 {
68 delete m_instance;
69 m_instance = 0;
70 m_parent = 0;
71 }
72}
73
74
75const NetAuthenticationData * NetAuthenticationDataList::get(const QString& url) const
76{
77 const NetAuthenticationData * ret = 0;
78 if (!url.isEmpty())
79 {
80 ret = m_urlEntries.value(url);
81 }
82 return ret;
83}
84
85bool NetAuthenticationDataList::store(const QString &url, const QString &u, const QString &p, bool save)
86{
87 bool ret = false;
88 if (!url.isEmpty())
89 {
90 ret = true;
91 NetAuthenticationData * data = 0;
92 if ( (data = const_cast<NetAuthenticationData*> (get(url))) == 0)
93 {
94 data = new NetAuthenticationData();
95 m_urlEntries.insert(url, data);
96 }
97 data->user = u;
98 data->password = p;
99 if (save )
100 {
101 ret = saveAuthenticationData(url, data);
102 }
103 }
104 return ret;
105}
106
107
108
109bool NetAuthenticationDataList::store(const QUrl &url, bool save)
110{
111 QString user = url.userName();
112 QString passwd = url.password();
113
114 QUrl url2(url);
115 url2.setUserName(QLatin1String(0));
116 url2.setPassword(QLatin1String(0));
117
118 return store(url2.toString(), user,passwd, save);
119}
120
121
122void NetAuthenticationDataList::loadSavedAuthenticationData()
123{
124 QLatin1Char slash('/');
125 QLatin1String userKey("user");
126 QLatin1String passKey("password");
127 openAuthenticationStore();
128 QStringList urls = m_savedAuths->childGroups();
129 int counter = urls.count();
130 while(counter--)
131 {
132 m_savedAuths->beginGroup(urls.at(counter));
133 QString cleanUrl = urls.at(counter);
134 cleanUrl.replace(QLatin1Char('}'), slash);
135 QString user = m_savedAuths->value(userKey).toString();
136 QString pass = m_savedAuths->value(passKey).toString();
137 store(cleanUrl, user, decryptPassword(pass));
138 m_savedAuths->endGroup();
139 }
140 closeAuthenticationStore();
141}
142
143bool NetAuthenticationDataList::saveAuthenticationData(const QString& url, const NetAuthenticationData *d)
144{
145 QLatin1Char slash('/');
146 QLatin1String userKey("user");
147 QLatin1String passKey("password");
148 QString keyUrl(url);
149 keyUrl.replace(slash, QLatin1Char('}'));
150
151 openAuthenticationStore();
152 m_savedAuths->setValue(keyUrl + slash + userKey, d->user);
153 m_savedAuths->setValue(keyUrl + slash + passKey, encryptPassord(d->password));
154 m_savedAuths->sync();
155 bool ret = m_savedAuths->status() == QSettings::NoError;
156 if (!ret)
157 {
158 qDebug() << Q_FUNC_INFO << "ERROR: could not save settings:" << m_savedAuths->fileName();
159 }
160 closeAuthenticationStore();
161 return ret;
162}
163
164/*!
165 * \brief NetAuthenticationDataList::encryptPassord() simple crypt function hide the user password
166 *
167 * \param p the ascii password
168 * \return
169 */
170QString NetAuthenticationDataList::encryptPassord(const QString &p)
171{
172 QString crypted;
173 short unicode = 0;
174 for (int counter=0; counter < p.size(); ++counter)
175 {
176 unicode = p.at(counter).unicode() - CHAR_CRYPT_OFFSET + counter;
177 crypted.append( QChar(unicode) );
178 }
179 return crypted.toLocal8Bit().toHex();
180}
181
182
183QString NetAuthenticationDataList::decryptPassword(const QString &p)
184{
185 QString crypted( QByteArray::fromHex(p.toLocal8Bit()) );
186 QString decrypted;
187 short unicode = 0;
188 for (int counter=0; counter < crypted.size(); ++counter)
189 {
190 unicode = crypted.at(counter).unicode() + CHAR_CRYPT_OFFSET - counter;
191 decrypted.append( QChar(unicode) );
192 }
193 return decrypted;
194}
195
196void NetAuthenticationDataList::openAuthenticationStore()
197{
198 if (m_savedAuths == 0)
199 {
200 QString settingsLocation =
201 QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).first()
202 + QLatin1Char('/') + QCoreApplication::applicationName()
203 + QLatin1Char('/') + QLatin1String("authentication.conf");
204 m_savedAuths = new QSettings(settingsLocation, QSettings::IniFormat);
205#if DEBUG_MESSAGES
206 qDebug() << Q_FUNC_INFO << "auth file:" << m_savedAuths->fileName();
207#endif
208 }
209}
210
211
212void NetAuthenticationDataList::closeAuthenticationStore()
213{
214 if (m_savedAuths != 0)
215 {
216 delete m_savedAuths;
217 m_savedAuths = 0;
218 }
219}
0220
=== added file 'src/plugin/folderlistmodel/net/netauthenticationdata.h'
--- src/plugin/folderlistmodel/net/netauthenticationdata.h 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/net/netauthenticationdata.h 2015-03-08 12:31:26 +0000
@@ -0,0 +1,97 @@
1/**************************************************************************
2 *
3 * Copyright 2014 Canonical Ltd.
4 * Copyright 2014 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: netauthenticationdata.h
19 * Date: 29/11/2014
20 */
21
22#ifndef NETAUTHENTICATIONDATA_H
23#define NETAUTHENTICATIONDATA_H
24
25#include <QHash>
26#include <QUrl>
27
28class QSettings;
29
30/*!
31 * \brief The NetAuthenticationData struct
32 *
33 * Just keeps data for Network authentication (protocol independent)
34 */
35
36struct NetAuthenticationData
37{
38public:
39 NetAuthenticationData() {}
40 NetAuthenticationData(const QString&u, const QString& p) :
41 user(u), password(p) {}
42 inline bool isEmpty() const { return user.isEmpty(); }
43 QString user;
44 QString password;
45};
46
47
48/*!
49 * \brief The NetAuthenticationDataList class
50 *
51 * It keeps a list of the current URLs being used and their Authentication data
52 *
53 * This information may be required for every connection (e.g. Samba shares).
54 *
55 * It implements a singleton design pattern to keep a unique Authentication Data list per application
56 * \sa \ref getInstance() and \ref releaseInstance()
57 *
58 * The authentication data can be saved for NOT always asking the user
59 *
60 * \note It is intended to be used for any protocol.
61 * The URL being stored must be the part or prefix which requires authentication
62 * Example for Samba: if a user enters with a url like smb://localhost/any_share/folder1/folder2
63 * only the share part requires authentication with is smb://localhost/any_share
64 * The same authentication data can be used for any smb://localhost/any_share sub-items
65 *
66 */
67class NetAuthenticationDataList
68{
69public:
70 static NetAuthenticationDataList * getInstance(void *parent);
71 static void releaseInstance(void *parent);
72 ~NetAuthenticationDataList();
73
74public:
75 bool store(const QUrl& url, bool save = false);
76 bool store(const QString& url, const QString& u, const QString& p, bool save =false);
77 const NetAuthenticationData * get(const QString&) const;
78
79private:
80 NetAuthenticationDataList();
81
82private:
83 void openAuthenticationStore();
84 void closeAuthenticationStore();
85 QString encryptPassord(const QString& p);
86 QString decryptPassword(const QString& p);
87 void loadSavedAuthenticationData();
88 bool saveAuthenticationData(const QString& url, const NetAuthenticationData * );
89
90private: //url authentication data
91 QHash <QString , NetAuthenticationData*> m_urlEntries;
92 static NetAuthenticationDataList * m_instance;
93 static void * m_parent;
94 QSettings * m_savedAuths;
95};
96
97#endif // NETAUTHENTICATIONDATA_H
098
=== modified file 'src/plugin/folderlistmodel/trash/trashlocation.cpp'
--- src/plugin/folderlistmodel/trash/trashlocation.cpp 2014-05-17 18:07:11 +0000
+++ src/plugin/folderlistmodel/trash/trashlocation.cpp 2015-03-08 12:31:26 +0000
@@ -180,8 +180,7 @@
180180
181181
182void TrashLocation::startExternalFsWatcher()182void TrashLocation::startExternalFsWatcher()
183{183{
184 //TODO implement a Watcher for this
185 //modify the existent watcher to work having a list of paths184 //modify the existent watcher to work having a list of paths
186 if (m_usingExternalWatcher && m_extWatcher == 0 && isRoot())185 if (m_usingExternalWatcher && m_extWatcher == 0 && isRoot())
187 { 186 {
@@ -286,3 +285,32 @@
286 ret.setTargetFullName( trashInfo.absFile );285 ret.setTargetFullName( trashInfo.absFile );
287 return ret;286 return ret;
288}287}
288
289
290DirItemInfo * TrashLocation::newItemInfo(const QString &urlPath)
291{
292 return new TrashItemInfo(urlPath);
293}
294
295
296/*!
297 * \brief TrashLocation::newListWorker() It is provided only because it is a pure method
298 *
299 * As \rev fetchItems() is reemplemented this method should never be used
300 *
301 * \param urlPath
302 * \param filter
303 * \param isRecursive
304 * \return
305 */
306DirListWorker * TrashLocation::newListWorker(const QString &urlPath, QDir::Filter filter, const bool isRecursive)
307{
308 Q_UNUSED(isRecursive);
309 QString trashDir;
310 if (m_info && !m_info->isRoot())
311 {
312 TrashItemInfo *item = static_cast<TrashItemInfo*> (m_info);
313 trashDir = item->getTrashDir();
314 }
315 return new TrashListWorker(trashDir, urlPath, filter);
316}
289317
=== modified file 'src/plugin/folderlistmodel/trash/trashlocation.h'
--- src/plugin/folderlistmodel/trash/trashlocation.h 2014-05-17 18:07:11 +0000
+++ src/plugin/folderlistmodel/trash/trashlocation.h 2015-03-08 12:31:26 +0000
@@ -45,6 +45,11 @@
4545
46 virtual DirItemInfo *validateUrlPath(const QString& urlPath);46 virtual DirItemInfo *validateUrlPath(const QString& urlPath);
4747
48 virtual DirItemInfo * newItemInfo(const QString& urlPath);
49 virtual DirListWorker * newListWorker(const QString &urlPath,
50 QDir::Filter filter,
51 const bool isRecursive);
52
48 /*!53 /*!
49 * \brief getMovePairPaths() Get: original path and destination trash path54 * \brief getMovePairPaths() Get: original path and destination trash path
50 *55 *

Subscribers

People subscribed via source and target branches