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

Proposed by Carlos Jose Mazieri
Status: Merged
Approved by: Arto Jalkanen
Approved revision: 392
Merged at revision: 407
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-05
Merge into: lp:ubuntu-filemanager-app
Prerequisite: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-04
Diff against target: 586 lines (+518/-3)
8 files modified
src/plugin/folderlistmodel/CMakeLists.txt (+7/-1)
src/plugin/folderlistmodel/folderlistmodel.pri (+5/-2)
src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.cpp (+167/-0)
src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.h (+52/-0)
src/plugin/folderlistmodel/smb/qsambaclient/src/smbobject.cpp (+50/-0)
src/plugin/folderlistmodel/smb/qsambaclient/src/smbobject.h (+45/-0)
src/plugin/folderlistmodel/urliteminfo.cpp (+139/-0)
src/plugin/folderlistmodel/urliteminfo.h (+53/-0)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-05
Reviewer Review Type Date Requested Status
Arto Jalkanen Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+252974@code.launchpad.net

Commit message

Introduces the class SmbItemInfo which represents an Samba Item (folder,files,host,workgroup,share).

Description of the change

Introduces the class SmbItemInfo which represents an Samba Item (folder,files,host,workgroup,share).

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/plugin/folderlistmodel/CMakeLists.txt'
--- src/plugin/folderlistmodel/CMakeLists.txt 2015-03-14 17:44:21 +0000
+++ src/plugin/folderlistmodel/CMakeLists.txt 2015-03-14 17:44:21 +0000
@@ -46,7 +46,9 @@
46 locationitemdiriterator.cpp46 locationitemdiriterator.cpp
47 locationitemdiriterator.h47 locationitemdiriterator.h
48 cleanurl.cpp48 cleanurl.cpp
49 cleanurl.h 49 cleanurl.h
50 urliteminfo.cpp
51 urliteminfo.h
50 disk/disklocation.cpp52 disk/disklocation.cpp
51 disk/disklocation.h53 disk/disklocation.h
52 trash/qtrashdir.cpp54 trash/qtrashdir.cpp
@@ -59,6 +61,10 @@
59 trash/trashlocation.h 61 trash/trashlocation.h
60 smb/qsambaclient/src/smbutil.cpp62 smb/qsambaclient/src/smbutil.cpp
61 smb/qsambaclient/src/smbutil.h63 smb/qsambaclient/src/smbutil.h
64 smb/qsambaclient/src/smbiteminfo.cpp
65 smb/qsambaclient/src/smbiteminfo.h
66 smb/qsambaclient/src/smbobject.cpp
67 smb/qsambaclient/src/smbobject.h
62 net/netauthenticationdata.cpp68 net/netauthenticationdata.cpp
63 net/netauthenticationdata.h 69 net/netauthenticationdata.h
64 net/netutil.cpp70 net/netutil.cpp
6571
=== modified file 'src/plugin/folderlistmodel/folderlistmodel.pri'
--- src/plugin/folderlistmodel/folderlistmodel.pri 2015-03-14 17:44:21 +0000
+++ src/plugin/folderlistmodel/folderlistmodel.pri 2015-03-14 17:44:21 +0000
@@ -8,7 +8,8 @@
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/urliteminfo.cpp \
12 $$PWD/location.cpp \13 $$PWD/location.cpp \
13 $$PWD/locationsfactory.cpp \ 14 $$PWD/locationsfactory.cpp \
14 $$PWD/locationurl.cpp \ 15 $$PWD/locationurl.cpp \
@@ -25,7 +26,9 @@
25 $$PWD/clipboard.h \26 $$PWD/clipboard.h \
26 $$PWD/fmutil.h \27 $$PWD/fmutil.h \
27 $$PWD/dirselection.h \ 28 $$PWD/dirselection.h \
28 $$PWD/diritemabstractlistmodel.h \ 29 $$PWD/diritemabstractlistmodel.h \
30 $$PWD/diriteminfo.h \
31 $$PWD/urliteminfo.h \
29 $$PWD/location.h \32 $$PWD/location.h \
30 $$PWD/locationsfactory.h \ 33 $$PWD/locationsfactory.h \
31 $$PWD/locationurl.h \ 34 $$PWD/locationurl.h \
3235
=== added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.cpp'
--- src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.cpp 2015-03-14 17:44:21 +0000
@@ -0,0 +1,167 @@
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: smbiteminfo.cpp
19 * Date: 08/12/2014
20 */
21
22#include "smbiteminfo.h"
23#include "locationurl.h"
24#include "smbutil.h"
25
26#include <QUrl>
27
28SmbItemInfo::SmbItemInfo() : UrlItemInfo(), SmbObject(QLatin1String(0))
29{
30
31}
32
33SmbItemInfo::SmbItemInfo(const QString &urlPath, Const_SmbUtil_Ptr smb) :
34 UrlItemInfo(urlPath, LocationUrl::SmbURL)
35 ,SmbObject(urlPath, smb)
36{
37 if (isValid() && !isRoot())
38 {
39 setInfo(cleanUrl());
40 }
41}
42
43
44SmbItemInfo::~SmbItemInfo()
45{
46
47}
48
49
50void SmbItemInfo::setInfo(const QString& smb_path)
51{
52 SmbUtil *smb = const_cast<SmbUtil*> (m_smb);
53 struct stat st;
54 int ret = smb->getStatInfo(smb_path, &st);
55 //lets start with true
56 d_ptr->_exists = d_ptr->_isReadable = true;
57 switch(ret)
58 {
59 case SmbUtil::StatInvalid:
60 case SmbUtil::StatDoesNotExist:
61 //reset _isHost because it might be set in UrlItemInfo
62 d_ptr->_isHost = false;
63 d_ptr->_exists = d_ptr->_isReadable = false;
64 break;
65 case SmbUtil::StatDir:
66 //if directories does not have permissions lets set default
67 //some smb stat functions does not work, this code will not hurt
68 if ((st.st_mode & S_IFMT) == 0)
69 {
70 st.st_mode |= S_IRUSR | S_IWUSR | S_IXUSR |
71 S_IRGRP | S_IWGRP | S_IXGRP |
72 S_IROTH | S_IXOTH;
73 }
74 st.st_mode |= S_IFDIR;
75 break;
76 case SmbUtil::StatHost:
77 d_ptr->_isHost = true;
78 break;
79 case SmbUtil::StatShare:
80 d_ptr->_isNetworkShare = true;
81 break;
82 case SmbUtil::StatWorkgroup:
83 d_ptr->_isHost = false;
84 d_ptr->_isWorkGroup = true;
85 break;
86 case SmbUtil::StatNoAccess:
87 //it is special case where the authentication might have failed
88 d_ptr->_isReadable = false;
89 d_ptr->_needsAuthentication = true;
90 break;
91 }
92 //all the information should be in place now
93 fillFromStatBuf(st);
94}
95
96
97QString SmbItemInfo::authenticationPath() const
98{
99 return sharePath();
100}
101
102/*!
103 * \brief SmbItemInfo::sharePath() returns the share part of the item
104 * \return NULL if the item is root
105 */
106QString SmbItemInfo::sharePath() const
107{
108 QString share;
109 if (isWorkGroup() || isHost() || isShare())
110 {
111 share = absoluteFilePath();
112 }
113 else
114 if (!isRoot())
115 {
116 //0 1 2 3 4 6
117 //s m b : / / smb://host/share[/dir]
118 int slashIndex = 6;
119 int found = 0;
120 QString fullpath(absoluteFilePath());
121 for (; found < 2 && slashIndex != -1; ++found)
122 {
123 slashIndex = fullpath.indexOf(QDir::separator(), slashIndex +1);
124 }
125 switch(found)
126 {
127 case 1: share = fullpath; break;
128 case 2: share = fullpath.left(slashIndex); break;
129 default: break;
130 }
131 }
132 return share;
133}
134
135
136void SmbItemInfo::setFile(const QString &dir, const QString &file)
137{
138 QString smb_path;
139 if (dir.startsWith(LocationUrl::SmbURL))
140 {
141 smb_path = dir;
142 }
143 else
144 {
145 QUrl url(urlPath());
146 QFileInfo f(url.path() + QDir::separator() + dir);
147 url.setPath(f.canonicalFilePath());
148 smb_path = url.toString();
149 }
150 smb_path += QDir::separator() + file;
151 SmbItemInfo *other = new SmbItemInfo( LocationUrl::SmbURL + DirItemInfo::removeExtraSlashes(smb_path),
152 m_smb);
153 if (other->isValid())
154 {
155 *this = *other;
156 }
157 else
158 {
159 delete other;
160 }
161}
162
163
164void SmbItemInfo::setAsShare()
165{
166 d_ptr->_isNetworkShare = true;
167}
0168
=== added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.h'
--- src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.h 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.h 2015-03-14 17:44:21 +0000
@@ -0,0 +1,52 @@
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: smbiteminfo.h
19 * Date: 08/12/2014
20 */
21
22#ifndef SMBITEMINFO_H
23#define SMBITEMINFO_H
24
25#include "urliteminfo.h"
26#include "smbobject.h"
27
28class QUrl;
29
30class SmbItemInfo : public UrlItemInfo, public SmbObject
31{
32public:
33 /*!
34 * \brief SmbItemInfo
35 * \param urlPath a url
36 * \param smb an instance of \ref SmbUtil that has an authentication callback already set
37 */
38 SmbItemInfo(const QString& urlPath, Const_SmbUtil_Ptr smb = 0);
39 SmbItemInfo();
40 ~SmbItemInfo();
41
42public:
43 QString sharePath() const;
44 void setAsShare();
45 virtual QString authenticationPath() const;
46 virtual void setFile(const QString &dir, const QString & file);
47
48protected:
49 void setInfo(const QString &smb_path);
50};
51
52#endif // SMBITEMINFO_H
053
=== added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbobject.cpp'
--- src/plugin/folderlistmodel/smb/qsambaclient/src/smbobject.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbobject.cpp 2015-03-14 17:44:21 +0000
@@ -0,0 +1,50 @@
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: smbobject.cpp
19 * Date: 02/01/2015
20 */
21
22#include "smbobject.h"
23#include "smbutil.h"
24
25#include <QUrl>
26
27SmbObject::SmbObject(const QString &urlPath, Const_SmbUtil_Ptr smb)
28 : CleanUrl(urlPath), m_smb(smb), m_smbOwnInstance(0)
29{
30 if (m_smb == 0)
31 {
32 m_smb = m_smbOwnInstance = new SmbUtil(cleanUrl());
33 }
34}
35
36
37SmbObject::~SmbObject()
38{
39 if (m_smbOwnInstance != 0)
40 {
41 delete m_smbOwnInstance;
42 m_smbOwnInstance = 0;
43 }
44}
45
46
47SmbUtil_Ptr SmbObject::smbObj() const
48{
49 return const_cast<SmbUtil_Ptr>(m_smb);
50}
051
=== added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbobject.h'
--- src/plugin/folderlistmodel/smb/qsambaclient/src/smbobject.h 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbobject.h 2015-03-14 17:44:21 +0000
@@ -0,0 +1,45 @@
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: smbobject.h
19 * Date: 02/01/2015
20 */
21
22#ifndef SMBOBJECT_H
23#define SMBOBJECT_H
24
25#include "cleanurl.h"
26
27#include <QString>
28
29class SmbUtil;
30typedef SmbUtil const * Const_SmbUtil_Ptr;
31typedef SmbUtil * SmbUtil_Ptr;
32
33class SmbObject : public CleanUrl
34{
35protected:
36 SmbObject(const QString &urlPath, Const_SmbUtil_Ptr smb = 0);
37 SmbUtil_Ptr smbObj() const;
38public:
39 virtual ~SmbObject();
40protected:
41 Const_SmbUtil_Ptr m_smb;
42 SmbUtil_Ptr m_smbOwnInstance; //!< not zero only if smb == 0
43};
44
45#endif // SMBOBJECT_H
046
=== added file 'src/plugin/folderlistmodel/urliteminfo.cpp'
--- src/plugin/folderlistmodel/urliteminfo.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/urliteminfo.cpp 2015-03-14 17:44:21 +0000
@@ -0,0 +1,139 @@
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: urliteminfo.cpp
19 * Date: 08/12/2014
20 */
21
22#include "urliteminfo.h"
23
24#include <QUrl>
25
26UrlItemInfo::UrlItemInfo(): DirItemInfo()
27{
28
29}
30
31UrlItemInfo::UrlItemInfo(const QString& urlPath, const QString& urlRoot):
32 DirItemInfo()
33{
34 if (urlPath == urlRoot)
35 {
36 setRoot(urlPath);
37 }
38 else
39 {
40 if (!urlPath.startsWith(urlRoot))
41 {
42 d_ptr->_isValid = false;
43 d_ptr->_isAbsolute = false;
44 }
45 else
46 {
47 init(urlPath);
48 }
49 }
50
51}
52
53
54void UrlItemInfo::setRoot(const QString& urlPath)
55{
56 d_ptr->_isValid = true;
57 d_ptr->_isRoot = true;
58 d_ptr->_isDir = true;
59 d_ptr->_isReadable = true;
60 d_ptr->_isExecutable = true;
61 d_ptr->_exists = true;
62 d_ptr->_isAbsolute = true;
63 d_ptr->_isRemote = true;
64 d_ptr->_fileName.clear();
65 d_ptr->_path = urlPath;
66 d_ptr->_normalizedPath = d_ptr->_path;
67}
68
69
70/*!
71 * \brief UrlItemInfo::init() fill basic item information
72 *
73 * It is supposed the URL does contain duplicates slashes
74 *
75 * \param urlPath
76 */
77void UrlItemInfo::init(const QString& urlPath)
78{
79 d_ptr->_isValid = true;
80 d_ptr->_isAbsolute = true;
81 d_ptr->_isRemote = true;
82
83 //veryfy if the item is a host
84 verifyHost(urlPath);
85
86 QStringList pathAndFile = separatePathFilename(urlPath);
87 if (pathAndFile.count() == 2)
88 {
89 d_ptr->_path = pathAndFile.at(0);
90 d_ptr->_fileName = pathAndFile.at(1);
91 }
92 else
93 {
94 d_ptr->_path = urlPath;
95 }
96 d_ptr->_normalizedPath = d_ptr->_path;
97}
98
99
100void UrlItemInfo::verifyHost(const QString urlPath)
101{
102 QUrl url(urlPath);
103 if (url.isValid() && !url.isLocalFile())
104 {
105 if (url.path().isEmpty())
106 {
107 //!< initial set is "host", Samba shares also have Workspace which will be handled in \ref SmbItemInfo
108 d_ptr->_isHost = true;
109 //set as it exists so far
110 d_ptr->_exists = true;
111 d_ptr->_isReadable = true;
112 d_ptr->_isExecutable = true;
113 }
114 }
115}
116
117
118/*!
119 * \brief UrlItemInfo::separatePathFilename()
120 * \param urlPath
121 * \return [0]=path [1]=filename when it exists
122 */
123QStringList UrlItemInfo::separatePathFilename(const QString &urlPath)
124{
125 QStringList separated;
126 int lastDir = urlPath.lastIndexOf(QDir::separator());
127 //path and filename must fill the url,
128 // smb://localost path=smb:// filename=localhost
129 // smb://localhost/dir path=smb://localhost filename=dir
130 if (lastDir != -1)
131 {
132 QString path = urlPath.at(lastDir-1) == QDir::separator() ?
133 urlPath.left(lastDir+1) : urlPath.left(lastDir);
134
135 separated.append(path);
136 separated.append(urlPath.mid(lastDir + 1));
137 }
138 return separated;
139}
0140
=== added file 'src/plugin/folderlistmodel/urliteminfo.h'
--- src/plugin/folderlistmodel/urliteminfo.h 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/urliteminfo.h 2015-03-14 17:44:21 +0000
@@ -0,0 +1,53 @@
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: urliteminfo.h
19 * Date: 08/12/2014
20 */
21
22#ifndef URLITEMINFO_H
23#define URLITEMINFO_H
24
25#include "diriteminfo.h"
26
27
28/*!
29 * \brief The UrlItemInfo is an abstract class that provides URL root
30 *
31 * Basically it differs from DirItemInfo in the field \a d_ptr->_normalizedPath, it must store the
32 * url like trash:///Item, while the field d_ptr->_path stores the current path in the file system as usual.
33 *
34 */
35
36class UrlItemInfo : public DirItemInfo
37{
38public:
39 static QStringList separatePathFilename(const QString& urlPath);
40protected:
41 UrlItemInfo(const QString& urlPath, const QString& urlRoot);
42 UrlItemInfo();
43
44protected:
45 void setRoot(const QString& urlRoot);
46
47
48private:
49 void init(const QString& urlPath);
50 void verifyHost(const QString urlPath);
51};
52
53#endif // URLITEMINFO_H

Subscribers

People subscribed via source and target branches