Merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-12 into lp:ubuntu-filemanager-app

Proposed by Carlos Jose Mazieri
Status: Merged
Approved by: Arto Jalkanen
Approved revision: 445
Merged at revision: 449
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-12
Merge into: lp:ubuntu-filemanager-app
Prerequisite: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-11
Diff against target: 1042 lines (+847/-25)
14 files modified
src/plugin/folderlistmodel/CMakeLists.txt (+6/-0)
src/plugin/folderlistmodel/disk/disklocation.cpp (+8/-0)
src/plugin/folderlistmodel/disk/disklocation.h (+2/-1)
src/plugin/folderlistmodel/disk/disklocationitemfile.cpp (+138/-0)
src/plugin/folderlistmodel/disk/disklocationitemfile.h (+55/-0)
src/plugin/folderlistmodel/folderlistmodel.pri (+39/-20)
src/plugin/folderlistmodel/location.h (+10/-1)
src/plugin/folderlistmodel/locationitemfile.cpp (+97/-0)
src/plugin/folderlistmodel/locationitemfile.h (+72/-0)
src/plugin/folderlistmodel/smb/qsambaclient/qsambaclient.pri (+5/-2)
src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationitemfile.cpp (+335/-0)
src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationitemfile.h (+71/-0)
src/plugin/folderlistmodel/smb/smblocation.cpp (+8/-1)
src/plugin/folderlistmodel/smb/smblocation.h (+1/-0)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-12
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Arto Jalkanen Approve
Review via email: mp+265211@code.launchpad.net

Commit message

nherited Location classes now provide inherited LocationItemFile classes which will replace Qt QFile class in Actions.
DiskLocation provides DiskLocationItemFile and SmbLocation provides SmbLocationItemFile

Description of the change

Implemented all inherited LocationItemFile classes

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: Needs Fixing (continuous-integration)
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 :

One comment, does not require action unless you think it does.

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

Your suggestion is very good, I will improve that to have createContextIfNotExists()

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

About the comment:
"But it's not clear to me when existing context should be closed and new created etc."

It is not clear to me either, I could not find good documentation of "libsmbclient", this source code is based on "libsmbclient" examples and some own tests, all operations require a "context", but it is not clear if a "context" can be reused for example doing a rename after writing data into a file, that is the reason why some methods always create a context as example in SmbLocationItemFile::rename(const QString& oldname, const QString& newName).

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)

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-07-13 20:41:48 +0000
+++ src/plugin/folderlistmodel/CMakeLists.txt 2015-08-15 18:38:50 +0000
@@ -45,6 +45,8 @@
45 locationurl.h45 locationurl.h
46 locationitemdiriterator.cpp46 locationitemdiriterator.cpp
47 locationitemdiriterator.h47 locationitemdiriterator.h
48 locationitemfile.cpp
49 locationitemfile.h
48 cleanurl.cpp50 cleanurl.cpp
49 cleanurl.h51 cleanurl.h
50 urliteminfo.cpp52 urliteminfo.cpp
@@ -53,6 +55,8 @@
53 disk/disklocation.h55 disk/disklocation.h
54 disk/disklocationitemdiriterator.cpp56 disk/disklocationitemdiriterator.cpp
55 disk/disklocationitemdiriterator.h57 disk/disklocationitemdiriterator.h
58 disk/disklocationitemfile.cpp
59 disk/disklocationitemfile.h
56 trash/qtrashdir.cpp60 trash/qtrashdir.cpp
57 trash/qtrashdir.h 61 trash/qtrashdir.h
58 trash/qtrashutilinfo.cpp62 trash/qtrashutilinfo.cpp
@@ -69,6 +73,8 @@
69 smb/qsambaclient/src/smbiteminfo.h73 smb/qsambaclient/src/smbiteminfo.h
70 smb/qsambaclient/src/smblocationdiriterator.cpp74 smb/qsambaclient/src/smblocationdiriterator.cpp
71 smb/qsambaclient/src/smblocationdiriterator.h75 smb/qsambaclient/src/smblocationdiriterator.h
76 smb/qsambaclient/src/smblocationitemfile.cpp
77 smb/qsambaclient/src/smblocationitemfile.h
72 smb/qsambaclient/src/smbobject.cpp78 smb/qsambaclient/src/smbobject.cpp
73 smb/qsambaclient/src/smbobject.h79 smb/qsambaclient/src/smbobject.h
74 smb/smblocation.h80 smb/smblocation.h
7581
=== modified file 'src/plugin/folderlistmodel/disk/disklocation.cpp'
--- src/plugin/folderlistmodel/disk/disklocation.cpp 2015-07-13 20:41:48 +0000
+++ src/plugin/folderlistmodel/disk/disklocation.cpp 2015-08-15 18:38:50 +0000
@@ -25,6 +25,7 @@
25#include "ioworkerthread.h"25#include "ioworkerthread.h"
26#include "externalfswatcher.h"26#include "externalfswatcher.h"
27#include "locationurl.h"27#include "locationurl.h"
28#include "disklocationitemfile.h"
2829
2930
30#if defined(Q_OS_UNIX)31#if defined(Q_OS_UNIX)
@@ -196,6 +197,13 @@
196}197}
197198
198199
200LocationItemFile *
201DiskLocation::newFile(const QString &path)
202{
203 return new DiskLocationItemFile(path, this);
204}
205
206
199bool DiskLocation::isThereDiskSpace(const QString &pathname, qint64 requiredSize)207bool DiskLocation::isThereDiskSpace(const QString &pathname, qint64 requiredSize)
200{208{
201 bool ret = true;209 bool ret = true;
202210
=== modified file 'src/plugin/folderlistmodel/disk/disklocation.h'
--- src/plugin/folderlistmodel/disk/disklocation.h 2015-07-13 20:41:48 +0000
+++ src/plugin/folderlistmodel/disk/disklocation.h 2015-08-15 18:38:50 +0000
@@ -65,7 +65,8 @@
65 const bool isRecursive);65 const bool isRecursive);
66 virtual LocationItemDirIterator * newDirIterator(const QString & path,66 virtual LocationItemDirIterator * newDirIterator(const QString & path,
67 QDir::Filters filters,67 QDir::Filters filters,
68 QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags); 68 QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
69 virtual LocationItemFile * newFile(const QString & path);
69 virtual bool isThereDiskSpace(const QString& pathname, qint64 requiredSize);70 virtual bool isThereDiskSpace(const QString& pathname, qint64 requiredSize);
70 virtual QString urlBelongsToLocation(const QString& urlPath, int indexOfColonAndSlashe);71 virtual QString urlBelongsToLocation(const QString& urlPath, int indexOfColonAndSlashe);
7172
7273
=== added file 'src/plugin/folderlistmodel/disk/disklocationitemfile.cpp'
--- src/plugin/folderlistmodel/disk/disklocationitemfile.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/disk/disklocationitemfile.cpp 2015-08-15 18:38:50 +0000
@@ -0,0 +1,138 @@
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: disklocationitemfile.cpp
19 * Date: 20/04/2015
20 */
21
22#include "disklocationitemfile.h"
23
24DiskLocationItemFile::DiskLocationItemFile(QObject *parent)
25 : LocationItemFile(parent)
26 , m_qtFile( new QFile() )
27{
28
29}
30
31DiskLocationItemFile::DiskLocationItemFile(const QString &name, QObject *parent)
32 : LocationItemFile(parent)
33 , m_qtFile( new QFile(name) )
34{
35
36}
37
38
39DiskLocationItemFile::~DiskLocationItemFile()
40{
41 delete m_qtFile;
42}
43
44
45QString DiskLocationItemFile::fileName() const
46{
47 return m_qtFile->fileName();
48}
49
50
51bool DiskLocationItemFile::rename(const QString& newName)
52{
53 return m_qtFile->rename(newName);
54}
55
56
57bool DiskLocationItemFile::rename(const QString& oldname, const QString &newName)
58{
59 return QFile::rename(oldname, newName);
60}
61
62
63bool DiskLocationItemFile::remove()
64{
65 return m_qtFile->remove();
66}
67
68
69bool DiskLocationItemFile::remove(const QString& name)
70{
71 return QFile::remove(name);
72}
73
74
75bool DiskLocationItemFile::link(const QString& linkName)
76{
77 return m_qtFile->link(linkName);
78}
79
80
81bool DiskLocationItemFile::open(QIODevice::OpenMode mode)
82{
83 return m_qtFile->open(mode);
84}
85
86
87qint64 DiskLocationItemFile::read(char * buffer, qint64 bytes)
88{
89 return m_qtFile->read(buffer, bytes);
90}
91
92
93qint64 DiskLocationItemFile::write(const char *buffer, qint64 bytes)
94{
95 return m_qtFile->write(buffer, bytes);
96}
97
98
99void DiskLocationItemFile::close()
100{
101 m_qtFile->close();
102}
103
104
105bool DiskLocationItemFile::atEnd() const
106{
107 return m_qtFile->atEnd();
108}
109
110
111qint64 DiskLocationItemFile::size() const
112{
113 return m_qtFile->size();
114}
115
116
117bool DiskLocationItemFile::isOpen() const
118{
119 return m_qtFile->isOpen();
120}
121
122
123bool DiskLocationItemFile::setPermissions(QFileDevice::Permissions perm)
124{
125 return m_qtFile->setPermissions(perm);
126}
127
128
129bool DiskLocationItemFile::setPermissions(const QString &filename, QFileDevice::Permissions perm)
130{
131 return QFile::setPermissions(filename, perm);
132}
133
134
135QFile::Permissions DiskLocationItemFile::permissions() const
136{
137 return m_qtFile->permissions();
138}
0139
=== added file 'src/plugin/folderlistmodel/disk/disklocationitemfile.h'
--- src/plugin/folderlistmodel/disk/disklocationitemfile.h 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/disk/disklocationitemfile.h 2015-08-15 18:38:50 +0000
@@ -0,0 +1,55 @@
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: disklocationitemfile.h
19 * Date: 20/04/2015
20 */
21
22#ifndef DISKLOCATIONITEMFILE_H
23#define DISKLOCATIONITEMFILE_H
24
25#include "locationitemfile.h"
26
27class DiskLocationItemFile : public LocationItemFile
28{
29 Q_OBJECT
30public:
31 explicit DiskLocationItemFile(QObject *parent);
32 explicit DiskLocationItemFile(const QString& name, QObject *parent);
33 ~DiskLocationItemFile();
34public:
35 virtual QString fileName() const;
36 virtual bool rename(const QString& newName);
37 virtual bool rename(const QString& oldname, const QString& newName);
38 virtual bool remove();
39 virtual bool remove(const QString& name);
40 virtual bool link(const QString& linkName);
41 virtual bool open(QFile::OpenMode mode) ;
42 virtual qint64 read(char*, qint64);
43 virtual qint64 write(const char*, qint64);
44 virtual void close();
45 virtual bool atEnd() const;
46 virtual qint64 size() const;
47 virtual bool isOpen() const;
48 virtual bool setPermissions(const QString& filename, QFile::Permissions perm);
49 virtual bool setPermissions(QFile::Permissions perm);
50 virtual QFile::Permissions permissions() const;
51private:
52 QFile * m_qtFile;
53};
54
55#endif // DISKLOCATIONITEMFILE_H
056
=== modified file 'src/plugin/folderlistmodel/folderlistmodel.pri'
--- src/plugin/folderlistmodel/folderlistmodel.pri 2015-07-13 20:41:48 +0000
+++ src/plugin/folderlistmodel/folderlistmodel.pri 2015-08-15 18:38:50 +0000
@@ -14,9 +14,8 @@
14 $$PWD/locationsfactory.cpp \ 14 $$PWD/locationsfactory.cpp \
15 $$PWD/locationurl.cpp \ 15 $$PWD/locationurl.cpp \
16 $$PWD/locationitemdiriterator.cpp \16 $$PWD/locationitemdiriterator.cpp \
17 $$PWD/cleanurl.cpp \17 $$PWD/cleanurl.cpp \
18 $$PWD/disk/disklocationitemdiriterator.cpp \ 18 $$PWD/locationitemfile.cpp \
19
2019
2120
22HEADERS += $$PWD/dirmodel.h \21HEADERS += $$PWD/dirmodel.h \
@@ -36,27 +35,47 @@
36 $$PWD/locationsfactory.h \ 35 $$PWD/locationsfactory.h \
37 $$PWD/locationurl.h \ 36 $$PWD/locationurl.h \
38 $$PWD/locationitemdiriterator.h \37 $$PWD/locationitemdiriterator.h \
39 $$PWD/cleanurl.h \38 $$PWD/cleanurl.h \
39 $$PWD/locationitemfile.h \
40
41
42SOURCES += $$PWD/disk/disklocation.cpp \
43 $$PWD/disk/disklocationitemdiriterator.cpp \
44 $$PWD/disk/disklocationitemfile.cpp
45
46HEADERS += $$PWD/disk/disklocation.h \
40 $$PWD/disk/disklocationitemdiriterator.h \47 $$PWD/disk/disklocationitemdiriterator.h \
4148 $$PWD/disk/disklocationitemfile.h
4249
43SOURCES += $$PWD/disk/disklocation.cpp50
44HEADERS += $$PWD/disk/disklocation.h51SOURCES += $$PWD/trash/qtrashdir.cpp \
4552 $$PWD/trash/trashiteminfo.cpp \
46SOURCES += $$PWD/trash/qtrashdir.cpp $$PWD/trash/trashiteminfo.cpp \53 $$PWD/trash/qtrashutilinfo.cpp \
47 $$PWD/trash/qtrashutilinfo.cpp $$PWD/trash/trashlocation.cpp54 $$PWD/trash/trashlocation.cpp
48HEADERS += $$PWD/trash/qtrashdir.h $$PWD/trash/trashiteminfo.h \55
49 $$PWD/trash/qtrashutilinfo.h $$PWD/trash/trashlocation.h56HEADERS += $$PWD/trash/qtrashdir.h \
5057 $$PWD/trash/trashiteminfo.h \
51SOURCES += $$PWD/smb/smblocation.cpp $$PWD/smb/smblocationauthentication.cpp $$PWD/smb/smblistworker.cpp58 $$PWD/trash/qtrashutilinfo.h \
52HEADERS += $$PWD/smb/smblocation.h $$PWD/smb/smblocationauthentication.h $$PWD/smb/smblistworker.h59 $$PWD/trash/trashlocation.h
5360
54SOURCES += $$PWD/net/netutil.cpp $$PWD/net/netauthenticationdata.cpp61SOURCES += $$PWD/smb/smblocation.cpp \
55HEADERS += $$PWD/net/netutil.h $$PWD/net/netauthenticationdata.h62 $$PWD/smb/smblocationauthentication.cpp \
63 $$PWD/smb/smblistworker.cpp
64
65HEADERS += $$PWD/smb/smblocation.h \
66 $$PWD/smb/smblocationauthentication.h \
67 $$PWD/smb/smblistworker.h
68
69include ($$PWD/smb/qsambaclient/qsambaclient.pri)
70
71SOURCES += $$PWD/net/netutil.cpp \
72 $$PWD/net/netauthenticationdata.cpp
73
74HEADERS += $$PWD/net/netutil.h \
75 $$PWD/net/netauthenticationdata.h
5676
57INCLUDEPATH += $$PWD $$PWD/trash $$PWD/disk $$PWD/smb $$PWD/net77INCLUDEPATH += $$PWD $$PWD/trash $$PWD/disk $$PWD/smb $$PWD/net
5878
59include ($$PWD/smb/qsambaclient/qsambaclient.pri)
6079
61greaterThan(QT_MAJOR_VERSION, 4) {80greaterThan(QT_MAJOR_VERSION, 4) {
62 QT += qml81 QT += qml
6382
=== modified file 'src/plugin/folderlistmodel/location.h'
--- src/plugin/folderlistmodel/location.h 2015-07-13 20:41:48 +0000
+++ src/plugin/folderlistmodel/location.h 2015-08-15 18:38:50 +0000
@@ -30,7 +30,7 @@
30class IOWorkerThread;30class IOWorkerThread;
31class DirListWorker;31class DirListWorker;
32class LocationItemDirIterator;32class LocationItemDirIterator;
3333class LocationItemFile;
3434
35/*!35/*!
36 * \brief The Location class represents any location (full path) where there are items to browse: directories, shares, from Disk and from Network.36 * \brief The Location class represents any location (full path) where there are items to browse: directories, shares, from Disk and from Network.
@@ -124,6 +124,15 @@
124 virtual LocationItemDirIterator * newDirIterator(const QString & path,124 virtual LocationItemDirIterator * newDirIterator(const QString & path,
125 QDir::Filters filters,125 QDir::Filters filters,
126 QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags) = 0;126 QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags) = 0;
127 /*!
128 * \brief newFile() creates a LocationItemFile object which is similar to Qt QFile object
129 *
130 * It will be used in copy/paste/remove Actions
131 *
132 * \param path
133 * \return
134 */
135 virtual LocationItemFile * newFile(const QString & path) = 0;
127136
128137
129 /*!138 /*!
130139
=== added file 'src/plugin/folderlistmodel/locationitemfile.cpp'
--- src/plugin/folderlistmodel/locationitemfile.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/locationitemfile.cpp 2015-08-15 18:38:50 +0000
@@ -0,0 +1,97 @@
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: locationitemfile.cpp
19 * Date: 20/04/2015
20 */
21
22#include "locationitemfile.h"
23
24#include <sys/types.h>
25#include <sys/stat.h>
26#include <unistd.h>
27
28LocationItemFile::LocationItemFile(QObject *parent) :
29 QObject(parent)
30{
31}
32
33LocationItemFile::LocationItemFile(const QString&, QObject *parent) :
34 QObject(parent)
35{
36}
37
38LocationItemFile::~LocationItemFile()
39{
40
41}
42
43
44mode_t LocationItemFile::getUmask()
45{
46 mode_t mask = ::umask(0); //first gets the current umask and sets to 0
47 ::umask(mask); //second restores the current umask
48 return mask;
49}
50
51/*!
52 * \brief LocationItemFile::getUmaskCreationMode() Returns a suitable open creation mode for system calls like open() and mkdir() respecting umask()
53 * \param mode
54 * \return the open mode in the form: mode & ~umask
55 */
56mode_t LocationItemFile::getUmaskCreationMode(mode_t mode)
57{
58 mode_t mask = getUmask();
59 mode_t umode = mode & ~mask;
60 return umode;
61}
62
63/*!
64 * \brief LocationItemFile::getUmaskFilesCreation() Returns the default open mode for files
65 * \return
66 */
67mode_t LocationItemFile::getUmaskFilesCreation()
68{
69 return LocationItemFile::getUmaskCreationMode(0666);
70}
71
72
73/*!
74 * \brief LocationItemFile::getUmaskFilesCreation() Returns the default open mode for directories
75 * \return
76 */
77mode_t LocationItemFile::getUmaskDirsCreation()
78{
79 return LocationItemFile::getUmaskCreationMode(0777);
80}
81
82
83mode_t LocationItemFile::unixPermissions(QFileDevice::Permissions perm)
84{
85#define SETMODE(qtPerm, Uperm) if (perm & qtPerm) { mode |= Uperm; }
86 mode_t mode = 0;
87 SETMODE((QFile::ReadOwner | QFile::ReadUser), S_IRUSR);
88 SETMODE((QFile::WriteOwner | QFile::WriteUser), S_IWUSR);
89 SETMODE((QFile::ExeOwner | QFile::ExeUser), S_IXUSR);
90 SETMODE(QFile::ReadGroup, S_IRGRP);
91 SETMODE(QFile::WriteGroup, S_IWGRP);
92 SETMODE(QFile::ExeGroup, S_IXGRP);
93 SETMODE(QFile::ReadOther, S_IROTH);
94 SETMODE(QFile::WriteOther, S_IWOTH);
95 SETMODE(QFile::ExeOther, S_IXOTH);
96 return mode;
97}
098
=== added file 'src/plugin/folderlistmodel/locationitemfile.h'
--- src/plugin/folderlistmodel/locationitemfile.h 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/locationitemfile.h 2015-08-15 18:38:50 +0000
@@ -0,0 +1,72 @@
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: locationitemfile.h
19 * Date: 20/04/2015
20 */
21
22#ifndef LOCATIONITEMFILE_H
23#define LOCATIONITEMFILE_H
24
25#include <QFile>
26#include <sys/types.h>
27
28
29
30/*!
31 * \brief The LocationItemFile class is an abstract class similar to Qt QFile
32 *
33 * It will be used in Actions like copy/paste
34 */
35class LocationItemFile : public QObject
36{
37 Q_OBJECT
38protected:
39 explicit LocationItemFile(QObject *parent = 0);
40 explicit LocationItemFile(const QString& name, QObject *parent = 0);
41public:
42 virtual ~LocationItemFile();
43public:
44 virtual QString fileName() const = 0;
45 virtual bool rename(const QString& newName) = 0;
46 virtual bool rename(const QString& oldname, const QString& newName) = 0;
47 virtual bool remove() = 0;
48 virtual bool remove(const QString& name) = 0;
49 virtual bool link(const QString& linkName) = 0;
50 virtual bool open(QFile::OpenMode mode) = 0 ;
51 virtual qint64 read(char*, qint64) = 0;
52 virtual qint64 write(const char*, qint64) = 0;
53 virtual void close() = 0;
54 virtual bool atEnd() const = 0;
55 virtual qint64 size() const = 0;
56 virtual bool isOpen() const = 0;
57 virtual bool setPermissions(const QString& filename, QFile::Permissions perm) = 0;
58 virtual bool setPermissions(QFile::Permissions perm) = 0;
59 virtual QFile::Permissions permissions() const = 0;
60public: //static functions
61 static mode_t getUmask(); //return the current umask
62 static mode_t getUmaskCreationMode(mode_t mode); // mode & ~umask;
63 static mode_t getUmaskFilesCreation(); // 0666 & ~umask;
64 static mode_t getUmaskDirsCreation(); // 0777 & ~umask;
65 static mode_t unixPermissions(QFile::Permissions);
66signals:
67
68public slots:
69
70};
71
72#endif // LOCATIONITEMFILE_H
073
=== modified file 'src/plugin/folderlistmodel/smb/qsambaclient/qsambaclient.pri'
--- src/plugin/folderlistmodel/smb/qsambaclient/qsambaclient.pri 2015-06-20 15:15:44 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/qsambaclient.pri 2015-08-15 18:38:50 +0000
@@ -4,7 +4,8 @@
4 $$PWD/src/smbiteminfo.cpp \4 $$PWD/src/smbiteminfo.cpp \
5 $$PWD/src/smbplaces.cpp \5 $$PWD/src/smbplaces.cpp \
6 $$PWD/src/smbobject.cpp \6 $$PWD/src/smbobject.cpp \
7 $$PWD/src/smblocationdiriterator.cpp7 $$PWD/src/smblocationdiriterator.cpp \
8 $$PWD/src/smblocationitemfile.cpp \
89
910
10HEADERS += $$PWD/src/smbutil.h \11HEADERS += $$PWD/src/smbutil.h \
@@ -12,7 +13,9 @@
12 $$PWD/src/smbiteminfo.h \13 $$PWD/src/smbiteminfo.h \
13 $$PWD/src/smbplaces.h \14 $$PWD/src/smbplaces.h \
14 $$PWD/src/smbobject.h \15 $$PWD/src/smbobject.h \
15 $$PWD/src/smblocationdiriterator.h16 $$PWD/src/smblocationdiriterator.h \
17 $$PWD/src/smblocationitemfile.h \
18
16 19
17QT *= core network 20QT *= core network
1821
1922
=== added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationitemfile.cpp'
--- src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationitemfile.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationitemfile.cpp 2015-08-15 18:38:50 +0000
@@ -0,0 +1,335 @@
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: smblocationitemfile.cpp
19 * Date: 20/04/2015
20 */
21
22#include "smblocationitemfile.h"
23#include "smbiteminfo.h"
24
25#include <sys/stat.h>
26#include <sys/statfs.h>
27#include <errno.h>
28
29#include <QDebug>
30
31
32SmbLocationItemFile::SmbLocationItemFile(QObject *parent, Const_SmbUtil_Ptr smb)
33 : LocationItemFile(parent)
34 , SmbObject(QLatin1String(0), smb)
35 , m_fd(0)
36 , m_context(0)
37 , m_curReadPosition(0)
38 , m_openMode(0)
39{
40
41}
42
43SmbLocationItemFile::SmbLocationItemFile(const QString &name, QObject *parent, Const_SmbUtil_Ptr smb)
44 : LocationItemFile(parent)
45 , SmbObject(name, smb)
46 , m_fd(0)
47 , m_context(0)
48 , m_curReadPosition(0)
49 , m_openMode(0)
50{
51
52}
53
54
55SmbLocationItemFile::~SmbLocationItemFile()
56{
57 close();
58 if (m_context)
59 {
60 SmbObject::smbObj()->deleteContext(m_context);
61 m_context = 0;
62 }
63}
64
65
66QString SmbLocationItemFile::fileName() const
67{
68 return cleanUrl();
69}
70
71
72bool SmbLocationItemFile::rename(const QString& newName)
73{
74 bool ret = false;
75 if (!cleanUrl().isEmpty())
76 {
77 close();
78 ret = rename(cleanUrl(), newName);
79 }
80 return ret;
81}
82
83
84bool SmbLocationItemFile::rename(const QString& oldname, const QString& newName)
85{
86 createContext();
87 Smb::Context nContext = SmbObject::smbObj()->createContext();
88 int ret = smbc_getFunctionRename(m_context)
89 (m_context,
90 oldname.toLocal8Bit().constData(),
91 nContext,
92 newName.toLocal8Bit().constData()
93 );
94 SmbObject::smbObj()->deleteContext(nContext);
95 return ret == 0;
96}
97
98
99bool SmbLocationItemFile::remove()
100{
101 return private_remove(cleanUrl());
102}
103
104
105bool SmbLocationItemFile::remove(const QString& name)
106{
107 CleanUrl otherUrl(name);
108 if (otherUrl.hasAuthenticationData())
109 {
110 qWarning() << Q_FUNC_INFO
111 << "Authentication in the form smb://user:password@pathname is not supported" ;
112 }
113 return private_remove(name) ;
114}
115
116
117bool SmbLocationItemFile::link(const QString& linkName)
118{
119 Q_UNUSED(linkName);
120 qWarning() << Q_FUNC_INFO << "Smbclient does not provide link() function";
121 return false;
122}
123
124
125bool SmbLocationItemFile::open(QIODevice::OpenMode mode)
126{
127 bool ret = false;
128 QString smb_path = cleanUrl();
129 if (!smb_path.isEmpty() && !isOpen())
130 {
131 int openFlags = 0;
132 m_openMode = mode;
133 createContext();
134 if (mode & QFile::ReadOnly)
135 {
136 openFlags = mode & QFile::WriteOnly ? O_RDWR : O_RDONLY;
137 }
138 else
139 {
140 if (mode & QFile::WriteOnly)
141 {
142 openFlags = O_CREAT | O_WRONLY;
143 }
144 if (mode & QFile::Append)
145 {
146 openFlags = O_APPEND | O_CREAT | O_WRONLY;
147 }
148 if ((mode & QFile::Truncate) || !(mode & QFile::Append))
149 {
150 openFlags |= O_TRUNC;
151 }
152 }
153 int creationMode = LocationItemFile::getUmaskFilesCreation();
154 /*
155 * it looks like SMB open() does set the permission properly
156 * does not matter what value "creationMode" has, libsmbclient always creates files with the following permission:
157 * -rwxr--r-- 1 nobody nogroup 0 Mai 30 14:04 second_item.txt
158 * SMB chmod() does not work either
159 *
160 * It depends on Samba configuration: force user; force group; force create mode; force directory mode
161 */
162 m_fd = SmbObject::smbObj()->openFile(m_context, smb_path, openFlags, creationMode);
163 ret = m_fd ? true : false;
164 }
165 return ret;
166}
167
168
169qint64 SmbLocationItemFile::read(char * buffer, qint64 bytes)
170{
171 qint64 ret = -1;
172 if (isOpen())
173 {
174 size_t to_write = static_cast<size_t> (bytes);
175 void *buf = static_cast<void*> (buffer);
176 ssize_t wr = smbc_getFunctionRead(m_context)(m_context, m_fd, buf, to_write);
177 ret = static_cast<qint64> (wr);
178 }
179 if (ret > 0)
180 {
181 m_curReadPosition += ret;
182 }
183 return ret;
184}
185
186
187qint64 SmbLocationItemFile::write(const char * buffer, qint64 bytes)
188{
189 qint64 ret = -1;
190 if (isOpen())
191 {
192 size_t to_read = static_cast<size_t> (bytes);
193 const void * const_buf = static_cast<const void*> (buffer);
194 void *buf = const_cast<void*> (const_buf);
195 ssize_t rd = smbc_getFunctionWrite(m_context)(m_context, m_fd, buf, to_read);
196 ret = static_cast<qint64> (rd);
197 }
198 return ret;
199}
200
201
202void SmbLocationItemFile::close()
203{
204 if (isOpen())
205 {
206 SmbObject::smbObj()->closeHandle(m_context, m_fd);
207 m_fd = 0;
208 }
209 m_curReadPosition = 0;
210}
211
212
213bool SmbLocationItemFile::atEnd() const
214{
215 bool ret = true; //closed files are at end, aren't they?
216 if (isOpen())
217 {
218 struct stat st;
219 if (smbObj()->getFstat(m_context,m_fd, &st) == SmbUtil::StatDone)
220 {
221 ret = m_curReadPosition >= st.st_size;
222 }
223 }
224 return ret;
225}
226
227
228qint64 SmbLocationItemFile::size() const
229{
230 qint64 size = 0;
231 struct stat st;
232 SmbUtil::StatReturn ret = SmbUtil::StatInvalid;
233 if (isOpen())
234 {
235 ret = smbObj()->getFstat(m_context,m_fd, &st);
236 }
237 else
238 {
239 SmbLocationItemFile *mySelf = const_cast<SmbLocationItemFile*> (this);
240 mySelf->createContext();
241 ret = smbObj()->getStat(m_context,cleanUrl(), &st);
242 }
243 if(ret == SmbUtil::StatDone)
244 {
245 size = static_cast<qint64> (st.st_size);
246 }
247 return size;
248}
249
250
251bool SmbLocationItemFile::isOpen() const
252{
253 return m_fd != 0 && m_context != 0 ? true : false;
254}
255
256
257bool SmbLocationItemFile::setPermissions(QFileDevice::Permissions perm)
258{
259 return setPermissions(cleanUrl(), perm);
260}
261
262
263bool SmbLocationItemFile::setPermissions(const QString &filename, QFileDevice::Permissions perm)
264{
265 bool ret = false;
266 if (!filename.isEmpty())
267 {
268 createContextIfNotExists();
269 ret = smbObj()->changePermissions(m_context, filename, LocationItemFile::unixPermissions(perm));
270 /*
271 * fake the return in case the file exists becase chmod() on libsmbclient does not work,
272 * the same comment is present in the \ref open()
273 */
274 if (!ret)
275 {
276 struct stat st;
277 ret = smbObj()->getStat(m_context,filename, &st) == SmbUtil::StatDone;
278 }
279 }
280 return ret;
281}
282
283
284QFile::Permissions SmbLocationItemFile::permissions() const
285{
286 SmbItemInfo info(cleanUrl(), m_smb);
287 return info.permissions();
288}
289
290
291bool SmbLocationItemFile::private_remove(const QString& smb_path)
292{
293 bool ret = false;
294 if (!smb_path.isEmpty())
295 {
296 close();
297 createContextIfNotExists();
298 if (smbc_getFunctionUnlink(m_context)(m_context, smb_path.toLocal8Bit().constData()) == 0)
299 {
300 ret = true;
301 }
302 }
303 return ret;
304}
305
306
307/*!
308 * \brief SmbLocationItemFile::createContext() Always creates a new context, if a context already exists it is deleted.
309 */
310void SmbLocationItemFile::createContext()
311{
312 if (m_context != 0)
313 {
314 SmbObject::smbObj()->deleteContext(m_context);
315 }
316 m_context = SmbObject::smbObj()->createContext();
317 Q_ASSERT(m_context);
318}
319
320
321/*!
322 * \brief SmbLocationItemFile::createContextIfNotExists() Creates a new context when the current context is null
323 *
324 * It tries to reuse an existent context
325 */
326void SmbLocationItemFile::createContextIfNotExists()
327{
328 if (m_context == 0)
329 {
330 m_context = SmbObject::smbObj()->createContext();
331 Q_ASSERT(m_context);
332 }
333}
334
335
0336
=== added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationitemfile.h'
--- src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationitemfile.h 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationitemfile.h 2015-08-15 18:38:50 +0000
@@ -0,0 +1,71 @@
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: smblocationitemfile.h
19 * Date: 20/04/2015
20 */
21
22#ifndef SMBLOCATIONITEMFILE_H
23#define SMBLOCATIONITEMFILE_H
24
25#include "locationitemfile.h"
26#include "smbobject.h"
27#include "smbutil.h"
28
29class SmbItemInfo;
30
31
32/*!
33 * \brief The SmbLocationItemFile class is similar to Qt QFile
34 *
35 */
36class SmbLocationItemFile : public LocationItemFile, public SmbObject
37{
38 Q_OBJECT
39public:
40 explicit SmbLocationItemFile(QObject *parent = 0, Const_SmbUtil_Ptr smb = 0);
41 explicit SmbLocationItemFile(const QString& name, QObject *parent = 0, Const_SmbUtil_Ptr smb = 0);
42 ~SmbLocationItemFile();
43public:
44 virtual QString fileName() const;
45 virtual bool rename(const QString& newName);
46 virtual bool rename(const QString& oldname, const QString& newName);
47 virtual bool remove();
48 virtual bool remove(const QString& name);
49 virtual bool link(const QString& linkName);
50 virtual bool open(QFile::OpenMode mode) ;
51 virtual qint64 read(char*, qint64);
52 virtual qint64 write(const char *, qint64);
53 virtual void close();
54 virtual bool atEnd() const;
55 virtual qint64 size() const;
56 virtual bool isOpen() const;
57 virtual bool setPermissions(const QString& filename, QFile::Permissions perm);
58 virtual bool setPermissions(QFile::Permissions perm);
59 virtual QFile::Permissions permissions() const;
60private:
61 bool private_remove(const QString& smb_path);
62 void createContext(); // destroys the context if exists
63 void createContextIfNotExists(); // creates only if there is no context
64private:
65 Smb::FileHandler m_fd;
66 Smb::Context m_context;
67 qint64 m_curReadPosition;
68 QFile::OpenMode m_openMode;
69};
70
71#endif // SMBLOCATIONITEMFILE_H
072
=== modified file 'src/plugin/folderlistmodel/smb/smblocation.cpp'
--- src/plugin/folderlistmodel/smb/smblocation.cpp 2015-07-13 20:41:48 +0000
+++ src/plugin/folderlistmodel/smb/smblocation.cpp 2015-08-15 18:38:50 +0000
@@ -27,7 +27,7 @@
27#include "iorequest.h"27#include "iorequest.h"
28#include "ioworkerthread.h"28#include "ioworkerthread.h"
29#include "locationurl.h"29#include "locationurl.h"
3030#include "smblocationitemfile.h"
3131
3232
33#if defined(Q_OS_UNIX)33#if defined(Q_OS_UNIX)
@@ -113,6 +113,13 @@
113}113}
114114
115115
116LocationItemFile *
117SmbLocation::newFile(const QString &path)
118{
119 return new SmbLocationItemFile(path, this, m_smb);
120}
121
122
116bool SmbLocation::isThereDiskSpace(const QString &pathname, qint64 requiredSize)123bool SmbLocation::isThereDiskSpace(const QString &pathname, qint64 requiredSize)
117{124{
118 bool ret = false;125 bool ret = false;
119126
=== modified file 'src/plugin/folderlistmodel/smb/smblocation.h'
--- src/plugin/folderlistmodel/smb/smblocation.h 2015-07-13 20:41:48 +0000
+++ src/plugin/folderlistmodel/smb/smblocation.h 2015-08-15 18:38:50 +0000
@@ -42,6 +42,7 @@
42 virtual LocationItemDirIterator * newDirIterator(const QString & path,42 virtual LocationItemDirIterator * newDirIterator(const QString & path,
43 QDir::Filters filters,43 QDir::Filters filters,
44 QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);44 QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
45 virtual LocationItemFile * newFile(const QString & path);
45 virtual bool isThereDiskSpace(const QString& pathname, qint64 requiredSize);46 virtual bool isThereDiskSpace(const QString& pathname, qint64 requiredSize);
46 virtual QString urlBelongsToLocation(const QString& urlPath, int indexOfColonAndSlashe);47 virtual QString urlBelongsToLocation(const QString& urlPath, int indexOfColonAndSlashe);
47 virtual QString currentAuthenticationUser();48 virtual QString currentAuthenticationUser();

Subscribers

People subscribed via source and target branches