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
1=== modified file 'src/plugin/folderlistmodel/CMakeLists.txt'
2--- src/plugin/folderlistmodel/CMakeLists.txt 2015-03-14 17:44:21 +0000
3+++ src/plugin/folderlistmodel/CMakeLists.txt 2015-03-14 17:44:21 +0000
4@@ -46,7 +46,9 @@
5 locationitemdiriterator.cpp
6 locationitemdiriterator.h
7 cleanurl.cpp
8- cleanurl.h
9+ cleanurl.h
10+ urliteminfo.cpp
11+ urliteminfo.h
12 disk/disklocation.cpp
13 disk/disklocation.h
14 trash/qtrashdir.cpp
15@@ -59,6 +61,10 @@
16 trash/trashlocation.h
17 smb/qsambaclient/src/smbutil.cpp
18 smb/qsambaclient/src/smbutil.h
19+ smb/qsambaclient/src/smbiteminfo.cpp
20+ smb/qsambaclient/src/smbiteminfo.h
21+ smb/qsambaclient/src/smbobject.cpp
22+ smb/qsambaclient/src/smbobject.h
23 net/netauthenticationdata.cpp
24 net/netauthenticationdata.h
25 net/netutil.cpp
26
27=== modified file 'src/plugin/folderlistmodel/folderlistmodel.pri'
28--- src/plugin/folderlistmodel/folderlistmodel.pri 2015-03-14 17:44:21 +0000
29+++ src/plugin/folderlistmodel/folderlistmodel.pri 2015-03-14 17:44:21 +0000
30@@ -8,7 +8,8 @@
31 $$PWD/clipboard.cpp \
32 $$PWD/fmutil.cpp \
33 $$PWD/dirselection.cpp \
34- $$PWD/diriteminfo.cpp \
35+ $$PWD/diriteminfo.cpp \
36+ $$PWD/urliteminfo.cpp \
37 $$PWD/location.cpp \
38 $$PWD/locationsfactory.cpp \
39 $$PWD/locationurl.cpp \
40@@ -25,7 +26,9 @@
41 $$PWD/clipboard.h \
42 $$PWD/fmutil.h \
43 $$PWD/dirselection.h \
44- $$PWD/diritemabstractlistmodel.h \
45+ $$PWD/diritemabstractlistmodel.h \
46+ $$PWD/diriteminfo.h \
47+ $$PWD/urliteminfo.h \
48 $$PWD/location.h \
49 $$PWD/locationsfactory.h \
50 $$PWD/locationurl.h \
51
52=== added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.cpp'
53--- src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.cpp 1970-01-01 00:00:00 +0000
54+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.cpp 2015-03-14 17:44:21 +0000
55@@ -0,0 +1,167 @@
56+/**************************************************************************
57+ *
58+ * Copyright 2014 Canonical Ltd.
59+ * Copyright 2014 Carlos J Mazieri <carlos.mazieri@gmail.com>
60+ *
61+ * This program is free software; you can redistribute it and/or modify
62+ * it under the terms of the GNU Lesser General Public License as published by
63+ * the Free Software Foundation; version 3.
64+ *
65+ * This program is distributed in the hope that it will be useful,
66+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
67+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
68+ * GNU Lesser General Public License for more details.
69+ *
70+ * You should have received a copy of the GNU Lesser General Public License
71+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
72+ *
73+ * File: smbiteminfo.cpp
74+ * Date: 08/12/2014
75+ */
76+
77+#include "smbiteminfo.h"
78+#include "locationurl.h"
79+#include "smbutil.h"
80+
81+#include <QUrl>
82+
83+SmbItemInfo::SmbItemInfo() : UrlItemInfo(), SmbObject(QLatin1String(0))
84+{
85+
86+}
87+
88+SmbItemInfo::SmbItemInfo(const QString &urlPath, Const_SmbUtil_Ptr smb) :
89+ UrlItemInfo(urlPath, LocationUrl::SmbURL)
90+ ,SmbObject(urlPath, smb)
91+{
92+ if (isValid() && !isRoot())
93+ {
94+ setInfo(cleanUrl());
95+ }
96+}
97+
98+
99+SmbItemInfo::~SmbItemInfo()
100+{
101+
102+}
103+
104+
105+void SmbItemInfo::setInfo(const QString& smb_path)
106+{
107+ SmbUtil *smb = const_cast<SmbUtil*> (m_smb);
108+ struct stat st;
109+ int ret = smb->getStatInfo(smb_path, &st);
110+ //lets start with true
111+ d_ptr->_exists = d_ptr->_isReadable = true;
112+ switch(ret)
113+ {
114+ case SmbUtil::StatInvalid:
115+ case SmbUtil::StatDoesNotExist:
116+ //reset _isHost because it might be set in UrlItemInfo
117+ d_ptr->_isHost = false;
118+ d_ptr->_exists = d_ptr->_isReadable = false;
119+ break;
120+ case SmbUtil::StatDir:
121+ //if directories does not have permissions lets set default
122+ //some smb stat functions does not work, this code will not hurt
123+ if ((st.st_mode & S_IFMT) == 0)
124+ {
125+ st.st_mode |= S_IRUSR | S_IWUSR | S_IXUSR |
126+ S_IRGRP | S_IWGRP | S_IXGRP |
127+ S_IROTH | S_IXOTH;
128+ }
129+ st.st_mode |= S_IFDIR;
130+ break;
131+ case SmbUtil::StatHost:
132+ d_ptr->_isHost = true;
133+ break;
134+ case SmbUtil::StatShare:
135+ d_ptr->_isNetworkShare = true;
136+ break;
137+ case SmbUtil::StatWorkgroup:
138+ d_ptr->_isHost = false;
139+ d_ptr->_isWorkGroup = true;
140+ break;
141+ case SmbUtil::StatNoAccess:
142+ //it is special case where the authentication might have failed
143+ d_ptr->_isReadable = false;
144+ d_ptr->_needsAuthentication = true;
145+ break;
146+ }
147+ //all the information should be in place now
148+ fillFromStatBuf(st);
149+}
150+
151+
152+QString SmbItemInfo::authenticationPath() const
153+{
154+ return sharePath();
155+}
156+
157+/*!
158+ * \brief SmbItemInfo::sharePath() returns the share part of the item
159+ * \return NULL if the item is root
160+ */
161+QString SmbItemInfo::sharePath() const
162+{
163+ QString share;
164+ if (isWorkGroup() || isHost() || isShare())
165+ {
166+ share = absoluteFilePath();
167+ }
168+ else
169+ if (!isRoot())
170+ {
171+ //0 1 2 3 4 6
172+ //s m b : / / smb://host/share[/dir]
173+ int slashIndex = 6;
174+ int found = 0;
175+ QString fullpath(absoluteFilePath());
176+ for (; found < 2 && slashIndex != -1; ++found)
177+ {
178+ slashIndex = fullpath.indexOf(QDir::separator(), slashIndex +1);
179+ }
180+ switch(found)
181+ {
182+ case 1: share = fullpath; break;
183+ case 2: share = fullpath.left(slashIndex); break;
184+ default: break;
185+ }
186+ }
187+ return share;
188+}
189+
190+
191+void SmbItemInfo::setFile(const QString &dir, const QString &file)
192+{
193+ QString smb_path;
194+ if (dir.startsWith(LocationUrl::SmbURL))
195+ {
196+ smb_path = dir;
197+ }
198+ else
199+ {
200+ QUrl url(urlPath());
201+ QFileInfo f(url.path() + QDir::separator() + dir);
202+ url.setPath(f.canonicalFilePath());
203+ smb_path = url.toString();
204+ }
205+ smb_path += QDir::separator() + file;
206+ SmbItemInfo *other = new SmbItemInfo( LocationUrl::SmbURL + DirItemInfo::removeExtraSlashes(smb_path),
207+ m_smb);
208+ if (other->isValid())
209+ {
210+ *this = *other;
211+ }
212+ else
213+ {
214+ delete other;
215+ }
216+}
217+
218+
219+void SmbItemInfo::setAsShare()
220+{
221+ d_ptr->_isNetworkShare = true;
222+}
223
224=== added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.h'
225--- src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.h 1970-01-01 00:00:00 +0000
226+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.h 2015-03-14 17:44:21 +0000
227@@ -0,0 +1,52 @@
228+/**************************************************************************
229+ *
230+ * Copyright 2014 Canonical Ltd.
231+ * Copyright 2014 Carlos J Mazieri <carlos.mazieri@gmail.com>
232+ *
233+ * This program is free software; you can redistribute it and/or modify
234+ * it under the terms of the GNU Lesser General Public License as published by
235+ * the Free Software Foundation; version 3.
236+ *
237+ * This program is distributed in the hope that it will be useful,
238+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
239+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
240+ * GNU Lesser General Public License for more details.
241+ *
242+ * You should have received a copy of the GNU Lesser General Public License
243+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
244+ *
245+ * File: smbiteminfo.h
246+ * Date: 08/12/2014
247+ */
248+
249+#ifndef SMBITEMINFO_H
250+#define SMBITEMINFO_H
251+
252+#include "urliteminfo.h"
253+#include "smbobject.h"
254+
255+class QUrl;
256+
257+class SmbItemInfo : public UrlItemInfo, public SmbObject
258+{
259+public:
260+ /*!
261+ * \brief SmbItemInfo
262+ * \param urlPath a url
263+ * \param smb an instance of \ref SmbUtil that has an authentication callback already set
264+ */
265+ SmbItemInfo(const QString& urlPath, Const_SmbUtil_Ptr smb = 0);
266+ SmbItemInfo();
267+ ~SmbItemInfo();
268+
269+public:
270+ QString sharePath() const;
271+ void setAsShare();
272+ virtual QString authenticationPath() const;
273+ virtual void setFile(const QString &dir, const QString & file);
274+
275+protected:
276+ void setInfo(const QString &smb_path);
277+};
278+
279+#endif // SMBITEMINFO_H
280
281=== added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbobject.cpp'
282--- src/plugin/folderlistmodel/smb/qsambaclient/src/smbobject.cpp 1970-01-01 00:00:00 +0000
283+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbobject.cpp 2015-03-14 17:44:21 +0000
284@@ -0,0 +1,50 @@
285+/**************************************************************************
286+ *
287+ * Copyright 2015 Canonical Ltd.
288+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
289+ *
290+ * This program is free software; you can redistribute it and/or modify
291+ * it under the terms of the GNU Lesser General Public License as published by
292+ * the Free Software Foundation; version 3.
293+ *
294+ * This program is distributed in the hope that it will be useful,
295+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
296+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
297+ * GNU Lesser General Public License for more details.
298+ *
299+ * You should have received a copy of the GNU Lesser General Public License
300+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
301+ *
302+ * File: smbobject.cpp
303+ * Date: 02/01/2015
304+ */
305+
306+#include "smbobject.h"
307+#include "smbutil.h"
308+
309+#include <QUrl>
310+
311+SmbObject::SmbObject(const QString &urlPath, Const_SmbUtil_Ptr smb)
312+ : CleanUrl(urlPath), m_smb(smb), m_smbOwnInstance(0)
313+{
314+ if (m_smb == 0)
315+ {
316+ m_smb = m_smbOwnInstance = new SmbUtil(cleanUrl());
317+ }
318+}
319+
320+
321+SmbObject::~SmbObject()
322+{
323+ if (m_smbOwnInstance != 0)
324+ {
325+ delete m_smbOwnInstance;
326+ m_smbOwnInstance = 0;
327+ }
328+}
329+
330+
331+SmbUtil_Ptr SmbObject::smbObj() const
332+{
333+ return const_cast<SmbUtil_Ptr>(m_smb);
334+}
335
336=== added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbobject.h'
337--- src/plugin/folderlistmodel/smb/qsambaclient/src/smbobject.h 1970-01-01 00:00:00 +0000
338+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbobject.h 2015-03-14 17:44:21 +0000
339@@ -0,0 +1,45 @@
340+/**************************************************************************
341+ *
342+ * Copyright 2015 Canonical Ltd.
343+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
344+ *
345+ * This program is free software; you can redistribute it and/or modify
346+ * it under the terms of the GNU Lesser General Public License as published by
347+ * the Free Software Foundation; version 3.
348+ *
349+ * This program is distributed in the hope that it will be useful,
350+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
351+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
352+ * GNU Lesser General Public License for more details.
353+ *
354+ * You should have received a copy of the GNU Lesser General Public License
355+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
356+ *
357+ * File: smbobject.h
358+ * Date: 02/01/2015
359+ */
360+
361+#ifndef SMBOBJECT_H
362+#define SMBOBJECT_H
363+
364+#include "cleanurl.h"
365+
366+#include <QString>
367+
368+class SmbUtil;
369+typedef SmbUtil const * Const_SmbUtil_Ptr;
370+typedef SmbUtil * SmbUtil_Ptr;
371+
372+class SmbObject : public CleanUrl
373+{
374+protected:
375+ SmbObject(const QString &urlPath, Const_SmbUtil_Ptr smb = 0);
376+ SmbUtil_Ptr smbObj() const;
377+public:
378+ virtual ~SmbObject();
379+protected:
380+ Const_SmbUtil_Ptr m_smb;
381+ SmbUtil_Ptr m_smbOwnInstance; //!< not zero only if smb == 0
382+};
383+
384+#endif // SMBOBJECT_H
385
386=== added file 'src/plugin/folderlistmodel/urliteminfo.cpp'
387--- src/plugin/folderlistmodel/urliteminfo.cpp 1970-01-01 00:00:00 +0000
388+++ src/plugin/folderlistmodel/urliteminfo.cpp 2015-03-14 17:44:21 +0000
389@@ -0,0 +1,139 @@
390+/**************************************************************************
391+ *
392+ * Copyright 2014 Canonical Ltd.
393+ * Copyright 2014 Carlos J Mazieri <carlos.mazieri@gmail.com>
394+ *
395+ * This program is free software; you can redistribute it and/or modify
396+ * it under the terms of the GNU Lesser General Public License as published by
397+ * the Free Software Foundation; version 3.
398+ *
399+ * This program is distributed in the hope that it will be useful,
400+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
401+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
402+ * GNU Lesser General Public License for more details.
403+ *
404+ * You should have received a copy of the GNU Lesser General Public License
405+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
406+ *
407+ * File: urliteminfo.cpp
408+ * Date: 08/12/2014
409+ */
410+
411+#include "urliteminfo.h"
412+
413+#include <QUrl>
414+
415+UrlItemInfo::UrlItemInfo(): DirItemInfo()
416+{
417+
418+}
419+
420+UrlItemInfo::UrlItemInfo(const QString& urlPath, const QString& urlRoot):
421+ DirItemInfo()
422+{
423+ if (urlPath == urlRoot)
424+ {
425+ setRoot(urlPath);
426+ }
427+ else
428+ {
429+ if (!urlPath.startsWith(urlRoot))
430+ {
431+ d_ptr->_isValid = false;
432+ d_ptr->_isAbsolute = false;
433+ }
434+ else
435+ {
436+ init(urlPath);
437+ }
438+ }
439+
440+}
441+
442+
443+void UrlItemInfo::setRoot(const QString& urlPath)
444+{
445+ d_ptr->_isValid = true;
446+ d_ptr->_isRoot = true;
447+ d_ptr->_isDir = true;
448+ d_ptr->_isReadable = true;
449+ d_ptr->_isExecutable = true;
450+ d_ptr->_exists = true;
451+ d_ptr->_isAbsolute = true;
452+ d_ptr->_isRemote = true;
453+ d_ptr->_fileName.clear();
454+ d_ptr->_path = urlPath;
455+ d_ptr->_normalizedPath = d_ptr->_path;
456+}
457+
458+
459+/*!
460+ * \brief UrlItemInfo::init() fill basic item information
461+ *
462+ * It is supposed the URL does contain duplicates slashes
463+ *
464+ * \param urlPath
465+ */
466+void UrlItemInfo::init(const QString& urlPath)
467+{
468+ d_ptr->_isValid = true;
469+ d_ptr->_isAbsolute = true;
470+ d_ptr->_isRemote = true;
471+
472+ //veryfy if the item is a host
473+ verifyHost(urlPath);
474+
475+ QStringList pathAndFile = separatePathFilename(urlPath);
476+ if (pathAndFile.count() == 2)
477+ {
478+ d_ptr->_path = pathAndFile.at(0);
479+ d_ptr->_fileName = pathAndFile.at(1);
480+ }
481+ else
482+ {
483+ d_ptr->_path = urlPath;
484+ }
485+ d_ptr->_normalizedPath = d_ptr->_path;
486+}
487+
488+
489+void UrlItemInfo::verifyHost(const QString urlPath)
490+{
491+ QUrl url(urlPath);
492+ if (url.isValid() && !url.isLocalFile())
493+ {
494+ if (url.path().isEmpty())
495+ {
496+ //!< initial set is "host", Samba shares also have Workspace which will be handled in \ref SmbItemInfo
497+ d_ptr->_isHost = true;
498+ //set as it exists so far
499+ d_ptr->_exists = true;
500+ d_ptr->_isReadable = true;
501+ d_ptr->_isExecutable = true;
502+ }
503+ }
504+}
505+
506+
507+/*!
508+ * \brief UrlItemInfo::separatePathFilename()
509+ * \param urlPath
510+ * \return [0]=path [1]=filename when it exists
511+ */
512+QStringList UrlItemInfo::separatePathFilename(const QString &urlPath)
513+{
514+ QStringList separated;
515+ int lastDir = urlPath.lastIndexOf(QDir::separator());
516+ //path and filename must fill the url,
517+ // smb://localost path=smb:// filename=localhost
518+ // smb://localhost/dir path=smb://localhost filename=dir
519+ if (lastDir != -1)
520+ {
521+ QString path = urlPath.at(lastDir-1) == QDir::separator() ?
522+ urlPath.left(lastDir+1) : urlPath.left(lastDir);
523+
524+ separated.append(path);
525+ separated.append(urlPath.mid(lastDir + 1));
526+ }
527+ return separated;
528+}
529
530=== added file 'src/plugin/folderlistmodel/urliteminfo.h'
531--- src/plugin/folderlistmodel/urliteminfo.h 1970-01-01 00:00:00 +0000
532+++ src/plugin/folderlistmodel/urliteminfo.h 2015-03-14 17:44:21 +0000
533@@ -0,0 +1,53 @@
534+/**************************************************************************
535+ *
536+ * Copyright 2014 Canonical Ltd.
537+ * Copyright 2014 Carlos J Mazieri <carlos.mazieri@gmail.com>
538+ *
539+ * This program is free software; you can redistribute it and/or modify
540+ * it under the terms of the GNU Lesser General Public License as published by
541+ * the Free Software Foundation; version 3.
542+ *
543+ * This program is distributed in the hope that it will be useful,
544+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
545+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
546+ * GNU Lesser General Public License for more details.
547+ *
548+ * You should have received a copy of the GNU Lesser General Public License
549+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
550+ *
551+ * File: urliteminfo.h
552+ * Date: 08/12/2014
553+ */
554+
555+#ifndef URLITEMINFO_H
556+#define URLITEMINFO_H
557+
558+#include "diriteminfo.h"
559+
560+
561+/*!
562+ * \brief The UrlItemInfo is an abstract class that provides URL root
563+ *
564+ * Basically it differs from DirItemInfo in the field \a d_ptr->_normalizedPath, it must store the
565+ * url like trash:///Item, while the field d_ptr->_path stores the current path in the file system as usual.
566+ *
567+ */
568+
569+class UrlItemInfo : public DirItemInfo
570+{
571+public:
572+ static QStringList separatePathFilename(const QString& urlPath);
573+protected:
574+ UrlItemInfo(const QString& urlPath, const QString& urlRoot);
575+ UrlItemInfo();
576+
577+protected:
578+ void setRoot(const QString& urlRoot);
579+
580+
581+private:
582+ void init(const QString& urlPath);
583+ void verifyHost(const QString urlPath);
584+};
585+
586+#endif // URLITEMINFO_H

Subscribers

People subscribed via source and target branches