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
1=== modified file 'src/plugin/folderlistmodel/CMakeLists.txt'
2--- src/plugin/folderlistmodel/CMakeLists.txt 2015-07-13 20:41:48 +0000
3+++ src/plugin/folderlistmodel/CMakeLists.txt 2015-08-15 18:38:50 +0000
4@@ -45,6 +45,8 @@
5 locationurl.h
6 locationitemdiriterator.cpp
7 locationitemdiriterator.h
8+ locationitemfile.cpp
9+ locationitemfile.h
10 cleanurl.cpp
11 cleanurl.h
12 urliteminfo.cpp
13@@ -53,6 +55,8 @@
14 disk/disklocation.h
15 disk/disklocationitemdiriterator.cpp
16 disk/disklocationitemdiriterator.h
17+ disk/disklocationitemfile.cpp
18+ disk/disklocationitemfile.h
19 trash/qtrashdir.cpp
20 trash/qtrashdir.h
21 trash/qtrashutilinfo.cpp
22@@ -69,6 +73,8 @@
23 smb/qsambaclient/src/smbiteminfo.h
24 smb/qsambaclient/src/smblocationdiriterator.cpp
25 smb/qsambaclient/src/smblocationdiriterator.h
26+ smb/qsambaclient/src/smblocationitemfile.cpp
27+ smb/qsambaclient/src/smblocationitemfile.h
28 smb/qsambaclient/src/smbobject.cpp
29 smb/qsambaclient/src/smbobject.h
30 smb/smblocation.h
31
32=== modified file 'src/plugin/folderlistmodel/disk/disklocation.cpp'
33--- src/plugin/folderlistmodel/disk/disklocation.cpp 2015-07-13 20:41:48 +0000
34+++ src/plugin/folderlistmodel/disk/disklocation.cpp 2015-08-15 18:38:50 +0000
35@@ -25,6 +25,7 @@
36 #include "ioworkerthread.h"
37 #include "externalfswatcher.h"
38 #include "locationurl.h"
39+#include "disklocationitemfile.h"
40
41
42 #if defined(Q_OS_UNIX)
43@@ -196,6 +197,13 @@
44 }
45
46
47+LocationItemFile *
48+DiskLocation::newFile(const QString &path)
49+{
50+ return new DiskLocationItemFile(path, this);
51+}
52+
53+
54 bool DiskLocation::isThereDiskSpace(const QString &pathname, qint64 requiredSize)
55 {
56 bool ret = true;
57
58=== modified file 'src/plugin/folderlistmodel/disk/disklocation.h'
59--- src/plugin/folderlistmodel/disk/disklocation.h 2015-07-13 20:41:48 +0000
60+++ src/plugin/folderlistmodel/disk/disklocation.h 2015-08-15 18:38:50 +0000
61@@ -65,7 +65,8 @@
62 const bool isRecursive);
63 virtual LocationItemDirIterator * newDirIterator(const QString & path,
64 QDir::Filters filters,
65- QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
66+ QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
67+ virtual LocationItemFile * newFile(const QString & path);
68 virtual bool isThereDiskSpace(const QString& pathname, qint64 requiredSize);
69 virtual QString urlBelongsToLocation(const QString& urlPath, int indexOfColonAndSlashe);
70
71
72=== added file 'src/plugin/folderlistmodel/disk/disklocationitemfile.cpp'
73--- src/plugin/folderlistmodel/disk/disklocationitemfile.cpp 1970-01-01 00:00:00 +0000
74+++ src/plugin/folderlistmodel/disk/disklocationitemfile.cpp 2015-08-15 18:38:50 +0000
75@@ -0,0 +1,138 @@
76+/**************************************************************************
77+ *
78+ * Copyright 2015 Canonical Ltd.
79+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
80+ *
81+ * This program is free software; you can redistribute it and/or modify
82+ * it under the terms of the GNU Lesser General Public License as published by
83+ * the Free Software Foundation; version 3.
84+ *
85+ * This program is distributed in the hope that it will be useful,
86+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
87+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
88+ * GNU Lesser General Public License for more details.
89+ *
90+ * You should have received a copy of the GNU Lesser General Public License
91+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
92+ *
93+ * File: disklocationitemfile.cpp
94+ * Date: 20/04/2015
95+ */
96+
97+#include "disklocationitemfile.h"
98+
99+DiskLocationItemFile::DiskLocationItemFile(QObject *parent)
100+ : LocationItemFile(parent)
101+ , m_qtFile( new QFile() )
102+{
103+
104+}
105+
106+DiskLocationItemFile::DiskLocationItemFile(const QString &name, QObject *parent)
107+ : LocationItemFile(parent)
108+ , m_qtFile( new QFile(name) )
109+{
110+
111+}
112+
113+
114+DiskLocationItemFile::~DiskLocationItemFile()
115+{
116+ delete m_qtFile;
117+}
118+
119+
120+QString DiskLocationItemFile::fileName() const
121+{
122+ return m_qtFile->fileName();
123+}
124+
125+
126+bool DiskLocationItemFile::rename(const QString& newName)
127+{
128+ return m_qtFile->rename(newName);
129+}
130+
131+
132+bool DiskLocationItemFile::rename(const QString& oldname, const QString &newName)
133+{
134+ return QFile::rename(oldname, newName);
135+}
136+
137+
138+bool DiskLocationItemFile::remove()
139+{
140+ return m_qtFile->remove();
141+}
142+
143+
144+bool DiskLocationItemFile::remove(const QString& name)
145+{
146+ return QFile::remove(name);
147+}
148+
149+
150+bool DiskLocationItemFile::link(const QString& linkName)
151+{
152+ return m_qtFile->link(linkName);
153+}
154+
155+
156+bool DiskLocationItemFile::open(QIODevice::OpenMode mode)
157+{
158+ return m_qtFile->open(mode);
159+}
160+
161+
162+qint64 DiskLocationItemFile::read(char * buffer, qint64 bytes)
163+{
164+ return m_qtFile->read(buffer, bytes);
165+}
166+
167+
168+qint64 DiskLocationItemFile::write(const char *buffer, qint64 bytes)
169+{
170+ return m_qtFile->write(buffer, bytes);
171+}
172+
173+
174+void DiskLocationItemFile::close()
175+{
176+ m_qtFile->close();
177+}
178+
179+
180+bool DiskLocationItemFile::atEnd() const
181+{
182+ return m_qtFile->atEnd();
183+}
184+
185+
186+qint64 DiskLocationItemFile::size() const
187+{
188+ return m_qtFile->size();
189+}
190+
191+
192+bool DiskLocationItemFile::isOpen() const
193+{
194+ return m_qtFile->isOpen();
195+}
196+
197+
198+bool DiskLocationItemFile::setPermissions(QFileDevice::Permissions perm)
199+{
200+ return m_qtFile->setPermissions(perm);
201+}
202+
203+
204+bool DiskLocationItemFile::setPermissions(const QString &filename, QFileDevice::Permissions perm)
205+{
206+ return QFile::setPermissions(filename, perm);
207+}
208+
209+
210+QFile::Permissions DiskLocationItemFile::permissions() const
211+{
212+ return m_qtFile->permissions();
213+}
214
215=== added file 'src/plugin/folderlistmodel/disk/disklocationitemfile.h'
216--- src/plugin/folderlistmodel/disk/disklocationitemfile.h 1970-01-01 00:00:00 +0000
217+++ src/plugin/folderlistmodel/disk/disklocationitemfile.h 2015-08-15 18:38:50 +0000
218@@ -0,0 +1,55 @@
219+/**************************************************************************
220+ *
221+ * Copyright 2015 Canonical Ltd.
222+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
223+ *
224+ * This program is free software; you can redistribute it and/or modify
225+ * it under the terms of the GNU Lesser General Public License as published by
226+ * the Free Software Foundation; version 3.
227+ *
228+ * This program is distributed in the hope that it will be useful,
229+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
230+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
231+ * GNU Lesser General Public License for more details.
232+ *
233+ * You should have received a copy of the GNU Lesser General Public License
234+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
235+ *
236+ * File: disklocationitemfile.h
237+ * Date: 20/04/2015
238+ */
239+
240+#ifndef DISKLOCATIONITEMFILE_H
241+#define DISKLOCATIONITEMFILE_H
242+
243+#include "locationitemfile.h"
244+
245+class DiskLocationItemFile : public LocationItemFile
246+{
247+ Q_OBJECT
248+public:
249+ explicit DiskLocationItemFile(QObject *parent);
250+ explicit DiskLocationItemFile(const QString& name, QObject *parent);
251+ ~DiskLocationItemFile();
252+public:
253+ virtual QString fileName() const;
254+ virtual bool rename(const QString& newName);
255+ virtual bool rename(const QString& oldname, const QString& newName);
256+ virtual bool remove();
257+ virtual bool remove(const QString& name);
258+ virtual bool link(const QString& linkName);
259+ virtual bool open(QFile::OpenMode mode) ;
260+ virtual qint64 read(char*, qint64);
261+ virtual qint64 write(const char*, qint64);
262+ virtual void close();
263+ virtual bool atEnd() const;
264+ virtual qint64 size() const;
265+ virtual bool isOpen() const;
266+ virtual bool setPermissions(const QString& filename, QFile::Permissions perm);
267+ virtual bool setPermissions(QFile::Permissions perm);
268+ virtual QFile::Permissions permissions() const;
269+private:
270+ QFile * m_qtFile;
271+};
272+
273+#endif // DISKLOCATIONITEMFILE_H
274
275=== modified file 'src/plugin/folderlistmodel/folderlistmodel.pri'
276--- src/plugin/folderlistmodel/folderlistmodel.pri 2015-07-13 20:41:48 +0000
277+++ src/plugin/folderlistmodel/folderlistmodel.pri 2015-08-15 18:38:50 +0000
278@@ -14,9 +14,8 @@
279 $$PWD/locationsfactory.cpp \
280 $$PWD/locationurl.cpp \
281 $$PWD/locationitemdiriterator.cpp \
282- $$PWD/cleanurl.cpp \
283- $$PWD/disk/disklocationitemdiriterator.cpp \
284-
285+ $$PWD/cleanurl.cpp \
286+ $$PWD/locationitemfile.cpp \
287
288
289 HEADERS += $$PWD/dirmodel.h \
290@@ -36,27 +35,47 @@
291 $$PWD/locationsfactory.h \
292 $$PWD/locationurl.h \
293 $$PWD/locationitemdiriterator.h \
294- $$PWD/cleanurl.h \
295+ $$PWD/cleanurl.h \
296+ $$PWD/locationitemfile.h \
297+
298+
299+SOURCES += $$PWD/disk/disklocation.cpp \
300+ $$PWD/disk/disklocationitemdiriterator.cpp \
301+ $$PWD/disk/disklocationitemfile.cpp
302+
303+HEADERS += $$PWD/disk/disklocation.h \
304 $$PWD/disk/disklocationitemdiriterator.h \
305-
306-
307-SOURCES += $$PWD/disk/disklocation.cpp
308-HEADERS += $$PWD/disk/disklocation.h
309-
310-SOURCES += $$PWD/trash/qtrashdir.cpp $$PWD/trash/trashiteminfo.cpp \
311- $$PWD/trash/qtrashutilinfo.cpp $$PWD/trash/trashlocation.cpp
312-HEADERS += $$PWD/trash/qtrashdir.h $$PWD/trash/trashiteminfo.h \
313- $$PWD/trash/qtrashutilinfo.h $$PWD/trash/trashlocation.h
314-
315-SOURCES += $$PWD/smb/smblocation.cpp $$PWD/smb/smblocationauthentication.cpp $$PWD/smb/smblistworker.cpp
316-HEADERS += $$PWD/smb/smblocation.h $$PWD/smb/smblocationauthentication.h $$PWD/smb/smblistworker.h
317-
318-SOURCES += $$PWD/net/netutil.cpp $$PWD/net/netauthenticationdata.cpp
319-HEADERS += $$PWD/net/netutil.h $$PWD/net/netauthenticationdata.h
320+ $$PWD/disk/disklocationitemfile.h
321+
322+
323+SOURCES += $$PWD/trash/qtrashdir.cpp \
324+ $$PWD/trash/trashiteminfo.cpp \
325+ $$PWD/trash/qtrashutilinfo.cpp \
326+ $$PWD/trash/trashlocation.cpp
327+
328+HEADERS += $$PWD/trash/qtrashdir.h \
329+ $$PWD/trash/trashiteminfo.h \
330+ $$PWD/trash/qtrashutilinfo.h \
331+ $$PWD/trash/trashlocation.h
332+
333+SOURCES += $$PWD/smb/smblocation.cpp \
334+ $$PWD/smb/smblocationauthentication.cpp \
335+ $$PWD/smb/smblistworker.cpp
336+
337+HEADERS += $$PWD/smb/smblocation.h \
338+ $$PWD/smb/smblocationauthentication.h \
339+ $$PWD/smb/smblistworker.h
340+
341+include ($$PWD/smb/qsambaclient/qsambaclient.pri)
342+
343+SOURCES += $$PWD/net/netutil.cpp \
344+ $$PWD/net/netauthenticationdata.cpp
345+
346+HEADERS += $$PWD/net/netutil.h \
347+ $$PWD/net/netauthenticationdata.h
348
349 INCLUDEPATH += $$PWD $$PWD/trash $$PWD/disk $$PWD/smb $$PWD/net
350
351-include ($$PWD/smb/qsambaclient/qsambaclient.pri)
352
353 greaterThan(QT_MAJOR_VERSION, 4) {
354 QT += qml
355
356=== modified file 'src/plugin/folderlistmodel/location.h'
357--- src/plugin/folderlistmodel/location.h 2015-07-13 20:41:48 +0000
358+++ src/plugin/folderlistmodel/location.h 2015-08-15 18:38:50 +0000
359@@ -30,7 +30,7 @@
360 class IOWorkerThread;
361 class DirListWorker;
362 class LocationItemDirIterator;
363-
364+class LocationItemFile;
365
366 /*!
367 * \brief The Location class represents any location (full path) where there are items to browse: directories, shares, from Disk and from Network.
368@@ -124,6 +124,15 @@
369 virtual LocationItemDirIterator * newDirIterator(const QString & path,
370 QDir::Filters filters,
371 QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags) = 0;
372+ /*!
373+ * \brief newFile() creates a LocationItemFile object which is similar to Qt QFile object
374+ *
375+ * It will be used in copy/paste/remove Actions
376+ *
377+ * \param path
378+ * \return
379+ */
380+ virtual LocationItemFile * newFile(const QString & path) = 0;
381
382
383 /*!
384
385=== added file 'src/plugin/folderlistmodel/locationitemfile.cpp'
386--- src/plugin/folderlistmodel/locationitemfile.cpp 1970-01-01 00:00:00 +0000
387+++ src/plugin/folderlistmodel/locationitemfile.cpp 2015-08-15 18:38:50 +0000
388@@ -0,0 +1,97 @@
389+/**************************************************************************
390+ *
391+ * Copyright 2015 Canonical Ltd.
392+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
393+ *
394+ * This program is free software; you can redistribute it and/or modify
395+ * it under the terms of the GNU Lesser General Public License as published by
396+ * the Free Software Foundation; version 3.
397+ *
398+ * This program is distributed in the hope that it will be useful,
399+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
400+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
401+ * GNU Lesser General Public License for more details.
402+ *
403+ * You should have received a copy of the GNU Lesser General Public License
404+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
405+ *
406+ * File: locationitemfile.cpp
407+ * Date: 20/04/2015
408+ */
409+
410+#include "locationitemfile.h"
411+
412+#include <sys/types.h>
413+#include <sys/stat.h>
414+#include <unistd.h>
415+
416+LocationItemFile::LocationItemFile(QObject *parent) :
417+ QObject(parent)
418+{
419+}
420+
421+LocationItemFile::LocationItemFile(const QString&, QObject *parent) :
422+ QObject(parent)
423+{
424+}
425+
426+LocationItemFile::~LocationItemFile()
427+{
428+
429+}
430+
431+
432+mode_t LocationItemFile::getUmask()
433+{
434+ mode_t mask = ::umask(0); //first gets the current umask and sets to 0
435+ ::umask(mask); //second restores the current umask
436+ return mask;
437+}
438+
439+/*!
440+ * \brief LocationItemFile::getUmaskCreationMode() Returns a suitable open creation mode for system calls like open() and mkdir() respecting umask()
441+ * \param mode
442+ * \return the open mode in the form: mode & ~umask
443+ */
444+mode_t LocationItemFile::getUmaskCreationMode(mode_t mode)
445+{
446+ mode_t mask = getUmask();
447+ mode_t umode = mode & ~mask;
448+ return umode;
449+}
450+
451+/*!
452+ * \brief LocationItemFile::getUmaskFilesCreation() Returns the default open mode for files
453+ * \return
454+ */
455+mode_t LocationItemFile::getUmaskFilesCreation()
456+{
457+ return LocationItemFile::getUmaskCreationMode(0666);
458+}
459+
460+
461+/*!
462+ * \brief LocationItemFile::getUmaskFilesCreation() Returns the default open mode for directories
463+ * \return
464+ */
465+mode_t LocationItemFile::getUmaskDirsCreation()
466+{
467+ return LocationItemFile::getUmaskCreationMode(0777);
468+}
469+
470+
471+mode_t LocationItemFile::unixPermissions(QFileDevice::Permissions perm)
472+{
473+#define SETMODE(qtPerm, Uperm) if (perm & qtPerm) { mode |= Uperm; }
474+ mode_t mode = 0;
475+ SETMODE((QFile::ReadOwner | QFile::ReadUser), S_IRUSR);
476+ SETMODE((QFile::WriteOwner | QFile::WriteUser), S_IWUSR);
477+ SETMODE((QFile::ExeOwner | QFile::ExeUser), S_IXUSR);
478+ SETMODE(QFile::ReadGroup, S_IRGRP);
479+ SETMODE(QFile::WriteGroup, S_IWGRP);
480+ SETMODE(QFile::ExeGroup, S_IXGRP);
481+ SETMODE(QFile::ReadOther, S_IROTH);
482+ SETMODE(QFile::WriteOther, S_IWOTH);
483+ SETMODE(QFile::ExeOther, S_IXOTH);
484+ return mode;
485+}
486
487=== added file 'src/plugin/folderlistmodel/locationitemfile.h'
488--- src/plugin/folderlistmodel/locationitemfile.h 1970-01-01 00:00:00 +0000
489+++ src/plugin/folderlistmodel/locationitemfile.h 2015-08-15 18:38:50 +0000
490@@ -0,0 +1,72 @@
491+/**************************************************************************
492+ *
493+ * Copyright 2015 Canonical Ltd.
494+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
495+ *
496+ * This program is free software; you can redistribute it and/or modify
497+ * it under the terms of the GNU Lesser General Public License as published by
498+ * the Free Software Foundation; version 3.
499+ *
500+ * This program is distributed in the hope that it will be useful,
501+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
502+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
503+ * GNU Lesser General Public License for more details.
504+ *
505+ * You should have received a copy of the GNU Lesser General Public License
506+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
507+ *
508+ * File: locationitemfile.h
509+ * Date: 20/04/2015
510+ */
511+
512+#ifndef LOCATIONITEMFILE_H
513+#define LOCATIONITEMFILE_H
514+
515+#include <QFile>
516+#include <sys/types.h>
517+
518+
519+
520+/*!
521+ * \brief The LocationItemFile class is an abstract class similar to Qt QFile
522+ *
523+ * It will be used in Actions like copy/paste
524+ */
525+class LocationItemFile : public QObject
526+{
527+ Q_OBJECT
528+protected:
529+ explicit LocationItemFile(QObject *parent = 0);
530+ explicit LocationItemFile(const QString& name, QObject *parent = 0);
531+public:
532+ virtual ~LocationItemFile();
533+public:
534+ virtual QString fileName() const = 0;
535+ virtual bool rename(const QString& newName) = 0;
536+ virtual bool rename(const QString& oldname, const QString& newName) = 0;
537+ virtual bool remove() = 0;
538+ virtual bool remove(const QString& name) = 0;
539+ virtual bool link(const QString& linkName) = 0;
540+ virtual bool open(QFile::OpenMode mode) = 0 ;
541+ virtual qint64 read(char*, qint64) = 0;
542+ virtual qint64 write(const char*, qint64) = 0;
543+ virtual void close() = 0;
544+ virtual bool atEnd() const = 0;
545+ virtual qint64 size() const = 0;
546+ virtual bool isOpen() const = 0;
547+ virtual bool setPermissions(const QString& filename, QFile::Permissions perm) = 0;
548+ virtual bool setPermissions(QFile::Permissions perm) = 0;
549+ virtual QFile::Permissions permissions() const = 0;
550+public: //static functions
551+ static mode_t getUmask(); //return the current umask
552+ static mode_t getUmaskCreationMode(mode_t mode); // mode & ~umask;
553+ static mode_t getUmaskFilesCreation(); // 0666 & ~umask;
554+ static mode_t getUmaskDirsCreation(); // 0777 & ~umask;
555+ static mode_t unixPermissions(QFile::Permissions);
556+signals:
557+
558+public slots:
559+
560+};
561+
562+#endif // LOCATIONITEMFILE_H
563
564=== modified file 'src/plugin/folderlistmodel/smb/qsambaclient/qsambaclient.pri'
565--- src/plugin/folderlistmodel/smb/qsambaclient/qsambaclient.pri 2015-06-20 15:15:44 +0000
566+++ src/plugin/folderlistmodel/smb/qsambaclient/qsambaclient.pri 2015-08-15 18:38:50 +0000
567@@ -4,7 +4,8 @@
568 $$PWD/src/smbiteminfo.cpp \
569 $$PWD/src/smbplaces.cpp \
570 $$PWD/src/smbobject.cpp \
571- $$PWD/src/smblocationdiriterator.cpp
572+ $$PWD/src/smblocationdiriterator.cpp \
573+ $$PWD/src/smblocationitemfile.cpp \
574
575
576 HEADERS += $$PWD/src/smbutil.h \
577@@ -12,7 +13,9 @@
578 $$PWD/src/smbiteminfo.h \
579 $$PWD/src/smbplaces.h \
580 $$PWD/src/smbobject.h \
581- $$PWD/src/smblocationdiriterator.h
582+ $$PWD/src/smblocationdiriterator.h \
583+ $$PWD/src/smblocationitemfile.h \
584+
585
586 QT *= core network
587
588
589=== added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationitemfile.cpp'
590--- src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationitemfile.cpp 1970-01-01 00:00:00 +0000
591+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationitemfile.cpp 2015-08-15 18:38:50 +0000
592@@ -0,0 +1,335 @@
593+/**************************************************************************
594+ *
595+ * Copyright 2015 Canonical Ltd.
596+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
597+ *
598+ * This program is free software; you can redistribute it and/or modify
599+ * it under the terms of the GNU Lesser General Public License as published by
600+ * the Free Software Foundation; version 3.
601+ *
602+ * This program is distributed in the hope that it will be useful,
603+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
604+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
605+ * GNU Lesser General Public License for more details.
606+ *
607+ * You should have received a copy of the GNU Lesser General Public License
608+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
609+ *
610+ * File: smblocationitemfile.cpp
611+ * Date: 20/04/2015
612+ */
613+
614+#include "smblocationitemfile.h"
615+#include "smbiteminfo.h"
616+
617+#include <sys/stat.h>
618+#include <sys/statfs.h>
619+#include <errno.h>
620+
621+#include <QDebug>
622+
623+
624+SmbLocationItemFile::SmbLocationItemFile(QObject *parent, Const_SmbUtil_Ptr smb)
625+ : LocationItemFile(parent)
626+ , SmbObject(QLatin1String(0), smb)
627+ , m_fd(0)
628+ , m_context(0)
629+ , m_curReadPosition(0)
630+ , m_openMode(0)
631+{
632+
633+}
634+
635+SmbLocationItemFile::SmbLocationItemFile(const QString &name, QObject *parent, Const_SmbUtil_Ptr smb)
636+ : LocationItemFile(parent)
637+ , SmbObject(name, smb)
638+ , m_fd(0)
639+ , m_context(0)
640+ , m_curReadPosition(0)
641+ , m_openMode(0)
642+{
643+
644+}
645+
646+
647+SmbLocationItemFile::~SmbLocationItemFile()
648+{
649+ close();
650+ if (m_context)
651+ {
652+ SmbObject::smbObj()->deleteContext(m_context);
653+ m_context = 0;
654+ }
655+}
656+
657+
658+QString SmbLocationItemFile::fileName() const
659+{
660+ return cleanUrl();
661+}
662+
663+
664+bool SmbLocationItemFile::rename(const QString& newName)
665+{
666+ bool ret = false;
667+ if (!cleanUrl().isEmpty())
668+ {
669+ close();
670+ ret = rename(cleanUrl(), newName);
671+ }
672+ return ret;
673+}
674+
675+
676+bool SmbLocationItemFile::rename(const QString& oldname, const QString& newName)
677+{
678+ createContext();
679+ Smb::Context nContext = SmbObject::smbObj()->createContext();
680+ int ret = smbc_getFunctionRename(m_context)
681+ (m_context,
682+ oldname.toLocal8Bit().constData(),
683+ nContext,
684+ newName.toLocal8Bit().constData()
685+ );
686+ SmbObject::smbObj()->deleteContext(nContext);
687+ return ret == 0;
688+}
689+
690+
691+bool SmbLocationItemFile::remove()
692+{
693+ return private_remove(cleanUrl());
694+}
695+
696+
697+bool SmbLocationItemFile::remove(const QString& name)
698+{
699+ CleanUrl otherUrl(name);
700+ if (otherUrl.hasAuthenticationData())
701+ {
702+ qWarning() << Q_FUNC_INFO
703+ << "Authentication in the form smb://user:password@pathname is not supported" ;
704+ }
705+ return private_remove(name) ;
706+}
707+
708+
709+bool SmbLocationItemFile::link(const QString& linkName)
710+{
711+ Q_UNUSED(linkName);
712+ qWarning() << Q_FUNC_INFO << "Smbclient does not provide link() function";
713+ return false;
714+}
715+
716+
717+bool SmbLocationItemFile::open(QIODevice::OpenMode mode)
718+{
719+ bool ret = false;
720+ QString smb_path = cleanUrl();
721+ if (!smb_path.isEmpty() && !isOpen())
722+ {
723+ int openFlags = 0;
724+ m_openMode = mode;
725+ createContext();
726+ if (mode & QFile::ReadOnly)
727+ {
728+ openFlags = mode & QFile::WriteOnly ? O_RDWR : O_RDONLY;
729+ }
730+ else
731+ {
732+ if (mode & QFile::WriteOnly)
733+ {
734+ openFlags = O_CREAT | O_WRONLY;
735+ }
736+ if (mode & QFile::Append)
737+ {
738+ openFlags = O_APPEND | O_CREAT | O_WRONLY;
739+ }
740+ if ((mode & QFile::Truncate) || !(mode & QFile::Append))
741+ {
742+ openFlags |= O_TRUNC;
743+ }
744+ }
745+ int creationMode = LocationItemFile::getUmaskFilesCreation();
746+ /*
747+ * it looks like SMB open() does set the permission properly
748+ * does not matter what value "creationMode" has, libsmbclient always creates files with the following permission:
749+ * -rwxr--r-- 1 nobody nogroup 0 Mai 30 14:04 second_item.txt
750+ * SMB chmod() does not work either
751+ *
752+ * It depends on Samba configuration: force user; force group; force create mode; force directory mode
753+ */
754+ m_fd = SmbObject::smbObj()->openFile(m_context, smb_path, openFlags, creationMode);
755+ ret = m_fd ? true : false;
756+ }
757+ return ret;
758+}
759+
760+
761+qint64 SmbLocationItemFile::read(char * buffer, qint64 bytes)
762+{
763+ qint64 ret = -1;
764+ if (isOpen())
765+ {
766+ size_t to_write = static_cast<size_t> (bytes);
767+ void *buf = static_cast<void*> (buffer);
768+ ssize_t wr = smbc_getFunctionRead(m_context)(m_context, m_fd, buf, to_write);
769+ ret = static_cast<qint64> (wr);
770+ }
771+ if (ret > 0)
772+ {
773+ m_curReadPosition += ret;
774+ }
775+ return ret;
776+}
777+
778+
779+qint64 SmbLocationItemFile::write(const char * buffer, qint64 bytes)
780+{
781+ qint64 ret = -1;
782+ if (isOpen())
783+ {
784+ size_t to_read = static_cast<size_t> (bytes);
785+ const void * const_buf = static_cast<const void*> (buffer);
786+ void *buf = const_cast<void*> (const_buf);
787+ ssize_t rd = smbc_getFunctionWrite(m_context)(m_context, m_fd, buf, to_read);
788+ ret = static_cast<qint64> (rd);
789+ }
790+ return ret;
791+}
792+
793+
794+void SmbLocationItemFile::close()
795+{
796+ if (isOpen())
797+ {
798+ SmbObject::smbObj()->closeHandle(m_context, m_fd);
799+ m_fd = 0;
800+ }
801+ m_curReadPosition = 0;
802+}
803+
804+
805+bool SmbLocationItemFile::atEnd() const
806+{
807+ bool ret = true; //closed files are at end, aren't they?
808+ if (isOpen())
809+ {
810+ struct stat st;
811+ if (smbObj()->getFstat(m_context,m_fd, &st) == SmbUtil::StatDone)
812+ {
813+ ret = m_curReadPosition >= st.st_size;
814+ }
815+ }
816+ return ret;
817+}
818+
819+
820+qint64 SmbLocationItemFile::size() const
821+{
822+ qint64 size = 0;
823+ struct stat st;
824+ SmbUtil::StatReturn ret = SmbUtil::StatInvalid;
825+ if (isOpen())
826+ {
827+ ret = smbObj()->getFstat(m_context,m_fd, &st);
828+ }
829+ else
830+ {
831+ SmbLocationItemFile *mySelf = const_cast<SmbLocationItemFile*> (this);
832+ mySelf->createContext();
833+ ret = smbObj()->getStat(m_context,cleanUrl(), &st);
834+ }
835+ if(ret == SmbUtil::StatDone)
836+ {
837+ size = static_cast<qint64> (st.st_size);
838+ }
839+ return size;
840+}
841+
842+
843+bool SmbLocationItemFile::isOpen() const
844+{
845+ return m_fd != 0 && m_context != 0 ? true : false;
846+}
847+
848+
849+bool SmbLocationItemFile::setPermissions(QFileDevice::Permissions perm)
850+{
851+ return setPermissions(cleanUrl(), perm);
852+}
853+
854+
855+bool SmbLocationItemFile::setPermissions(const QString &filename, QFileDevice::Permissions perm)
856+{
857+ bool ret = false;
858+ if (!filename.isEmpty())
859+ {
860+ createContextIfNotExists();
861+ ret = smbObj()->changePermissions(m_context, filename, LocationItemFile::unixPermissions(perm));
862+ /*
863+ * fake the return in case the file exists becase chmod() on libsmbclient does not work,
864+ * the same comment is present in the \ref open()
865+ */
866+ if (!ret)
867+ {
868+ struct stat st;
869+ ret = smbObj()->getStat(m_context,filename, &st) == SmbUtil::StatDone;
870+ }
871+ }
872+ return ret;
873+}
874+
875+
876+QFile::Permissions SmbLocationItemFile::permissions() const
877+{
878+ SmbItemInfo info(cleanUrl(), m_smb);
879+ return info.permissions();
880+}
881+
882+
883+bool SmbLocationItemFile::private_remove(const QString& smb_path)
884+{
885+ bool ret = false;
886+ if (!smb_path.isEmpty())
887+ {
888+ close();
889+ createContextIfNotExists();
890+ if (smbc_getFunctionUnlink(m_context)(m_context, smb_path.toLocal8Bit().constData()) == 0)
891+ {
892+ ret = true;
893+ }
894+ }
895+ return ret;
896+}
897+
898+
899+/*!
900+ * \brief SmbLocationItemFile::createContext() Always creates a new context, if a context already exists it is deleted.
901+ */
902+void SmbLocationItemFile::createContext()
903+{
904+ if (m_context != 0)
905+ {
906+ SmbObject::smbObj()->deleteContext(m_context);
907+ }
908+ m_context = SmbObject::smbObj()->createContext();
909+ Q_ASSERT(m_context);
910+}
911+
912+
913+/*!
914+ * \brief SmbLocationItemFile::createContextIfNotExists() Creates a new context when the current context is null
915+ *
916+ * It tries to reuse an existent context
917+ */
918+void SmbLocationItemFile::createContextIfNotExists()
919+{
920+ if (m_context == 0)
921+ {
922+ m_context = SmbObject::smbObj()->createContext();
923+ Q_ASSERT(m_context);
924+ }
925+}
926+
927+
928
929=== added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationitemfile.h'
930--- src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationitemfile.h 1970-01-01 00:00:00 +0000
931+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationitemfile.h 2015-08-15 18:38:50 +0000
932@@ -0,0 +1,71 @@
933+/**************************************************************************
934+ *
935+ * Copyright 2015 Canonical Ltd.
936+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
937+ *
938+ * This program is free software; you can redistribute it and/or modify
939+ * it under the terms of the GNU Lesser General Public License as published by
940+ * the Free Software Foundation; version 3.
941+ *
942+ * This program is distributed in the hope that it will be useful,
943+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
944+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
945+ * GNU Lesser General Public License for more details.
946+ *
947+ * You should have received a copy of the GNU Lesser General Public License
948+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
949+ *
950+ * File: smblocationitemfile.h
951+ * Date: 20/04/2015
952+ */
953+
954+#ifndef SMBLOCATIONITEMFILE_H
955+#define SMBLOCATIONITEMFILE_H
956+
957+#include "locationitemfile.h"
958+#include "smbobject.h"
959+#include "smbutil.h"
960+
961+class SmbItemInfo;
962+
963+
964+/*!
965+ * \brief The SmbLocationItemFile class is similar to Qt QFile
966+ *
967+ */
968+class SmbLocationItemFile : public LocationItemFile, public SmbObject
969+{
970+ Q_OBJECT
971+public:
972+ explicit SmbLocationItemFile(QObject *parent = 0, Const_SmbUtil_Ptr smb = 0);
973+ explicit SmbLocationItemFile(const QString& name, QObject *parent = 0, Const_SmbUtil_Ptr smb = 0);
974+ ~SmbLocationItemFile();
975+public:
976+ virtual QString fileName() const;
977+ virtual bool rename(const QString& newName);
978+ virtual bool rename(const QString& oldname, const QString& newName);
979+ virtual bool remove();
980+ virtual bool remove(const QString& name);
981+ virtual bool link(const QString& linkName);
982+ virtual bool open(QFile::OpenMode mode) ;
983+ virtual qint64 read(char*, qint64);
984+ virtual qint64 write(const char *, qint64);
985+ virtual void close();
986+ virtual bool atEnd() const;
987+ virtual qint64 size() const;
988+ virtual bool isOpen() const;
989+ virtual bool setPermissions(const QString& filename, QFile::Permissions perm);
990+ virtual bool setPermissions(QFile::Permissions perm);
991+ virtual QFile::Permissions permissions() const;
992+private:
993+ bool private_remove(const QString& smb_path);
994+ void createContext(); // destroys the context if exists
995+ void createContextIfNotExists(); // creates only if there is no context
996+private:
997+ Smb::FileHandler m_fd;
998+ Smb::Context m_context;
999+ qint64 m_curReadPosition;
1000+ QFile::OpenMode m_openMode;
1001+};
1002+
1003+#endif // SMBLOCATIONITEMFILE_H
1004
1005=== modified file 'src/plugin/folderlistmodel/smb/smblocation.cpp'
1006--- src/plugin/folderlistmodel/smb/smblocation.cpp 2015-07-13 20:41:48 +0000
1007+++ src/plugin/folderlistmodel/smb/smblocation.cpp 2015-08-15 18:38:50 +0000
1008@@ -27,7 +27,7 @@
1009 #include "iorequest.h"
1010 #include "ioworkerthread.h"
1011 #include "locationurl.h"
1012-
1013+#include "smblocationitemfile.h"
1014
1015
1016 #if defined(Q_OS_UNIX)
1017@@ -113,6 +113,13 @@
1018 }
1019
1020
1021+LocationItemFile *
1022+SmbLocation::newFile(const QString &path)
1023+{
1024+ return new SmbLocationItemFile(path, this, m_smb);
1025+}
1026+
1027+
1028 bool SmbLocation::isThereDiskSpace(const QString &pathname, qint64 requiredSize)
1029 {
1030 bool ret = false;
1031
1032=== modified file 'src/plugin/folderlistmodel/smb/smblocation.h'
1033--- src/plugin/folderlistmodel/smb/smblocation.h 2015-07-13 20:41:48 +0000
1034+++ src/plugin/folderlistmodel/smb/smblocation.h 2015-08-15 18:38:50 +0000
1035@@ -42,6 +42,7 @@
1036 virtual LocationItemDirIterator * newDirIterator(const QString & path,
1037 QDir::Filters filters,
1038 QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
1039+ virtual LocationItemFile * newFile(const QString & path);
1040 virtual bool isThereDiskSpace(const QString& pathname, qint64 requiredSize);
1041 virtual QString urlBelongsToLocation(const QString& urlPath, int indexOfColonAndSlashe);
1042 virtual QString currentAuthenticationUser();

Subscribers

People subscribed via source and target branches