ubuntu-touch-coreapps-reviewers team mailing list archive
-
ubuntu-touch-coreapps-reviewers team
-
Mailing list archive
-
Message #03668
[Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-12 into lp:ubuntu-filemanager-app
Carlos Jose Mazieri has proposed merging lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-12 into lp:ubuntu-filemanager-app with lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-11 as a prerequisite.
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
Requested reviews:
Ubuntu File Manager Developers (ubuntu-filemanager-dev)
For more details, see:
https://code.launchpad.net/~carlos-mazieri/ubuntu-filemanager-app/samba-actions-12/+merge/265211
Implemented all inherited LocationItemFile classes
--
Your team Ubuntu File Manager Developers is requested to review the proposed merge of lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-12 into lp:ubuntu-filemanager-app.
=== modified file 'src/plugin/folderlistmodel/CMakeLists.txt'
--- src/plugin/folderlistmodel/CMakeLists.txt 2015-07-19 15:38:39 +0000
+++ src/plugin/folderlistmodel/CMakeLists.txt 2015-07-19 15:38:39 +0000
@@ -53,6 +53,8 @@
disk/disklocation.h
disk/disklocationitemdiriterator.cpp
disk/disklocationitemdiriterator.h
+ disk/disklocationitemfile.cpp
+ disk/disklocationitemfile.h
trash/qtrashdir.cpp
trash/qtrashdir.h
trash/qtrashutilinfo.cpp
@@ -69,6 +71,8 @@
smb/qsambaclient/src/smbiteminfo.h
smb/qsambaclient/src/smblocationdiriterator.cpp
smb/qsambaclient/src/smblocationdiriterator.h
+ smb/qsambaclient/src/smblocationitemfile.cpp
+ smb/qsambaclient/src/smblocationitemfile.h
smb/qsambaclient/src/smbobject.cpp
smb/qsambaclient/src/smbobject.h
smb/smblocation.h
=== modified file 'src/plugin/folderlistmodel/disk/disklocation.cpp'
--- src/plugin/folderlistmodel/disk/disklocation.cpp 2015-07-19 15:38:39 +0000
+++ src/plugin/folderlistmodel/disk/disklocation.cpp 2015-07-19 15:38:39 +0000
@@ -25,6 +25,7 @@
#include "ioworkerthread.h"
#include "externalfswatcher.h"
#include "locationurl.h"
+#include "disklocationitemfile.h"
#if defined(Q_OS_UNIX)
@@ -196,6 +197,13 @@
}
+LocationItemFile *
+DiskLocation::newFile(const QString &path)
+{
+ return new DiskLocationItemFile(path, this);
+}
+
+
bool DiskLocation::isThereDiskSpace(const QString &pathname, qint64 requiredSize)
{
bool ret = true;
=== modified file 'src/plugin/folderlistmodel/disk/disklocation.h'
--- src/plugin/folderlistmodel/disk/disklocation.h 2015-07-19 15:38:39 +0000
+++ src/plugin/folderlistmodel/disk/disklocation.h 2015-07-19 15:38:39 +0000
@@ -65,7 +65,8 @@
const bool isRecursive);
virtual LocationItemDirIterator * newDirIterator(const QString & path,
QDir::Filters filters,
- QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
+ QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
+ virtual LocationItemFile * newFile(const QString & path);
virtual bool isThereDiskSpace(const QString& pathname, qint64 requiredSize);
virtual QString urlBelongsToLocation(const QString& urlPath, int indexOfColonAndSlashe);
=== 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-07-19 15:38:39 +0000
@@ -0,0 +1,138 @@
+/**************************************************************************
+ *
+ * Copyright 2015 Canonical Ltd.
+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@xxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * File: disklocationitemfile.cpp
+ * Date: 20/04/2015
+ */
+
+#include "disklocationitemfile.h"
+
+DiskLocationItemFile::DiskLocationItemFile(QObject *parent)
+ : LocationItemFile(parent)
+ , m_qtFile( new QFile() )
+{
+
+}
+
+DiskLocationItemFile::DiskLocationItemFile(const QString &name, QObject *parent)
+ : LocationItemFile(parent)
+ , m_qtFile( new QFile(name) )
+{
+
+}
+
+
+DiskLocationItemFile::~DiskLocationItemFile()
+{
+ delete m_qtFile;
+}
+
+
+QString DiskLocationItemFile::fileName() const
+{
+ return m_qtFile->fileName();
+}
+
+
+bool DiskLocationItemFile::rename(const QString& newName)
+{
+ return m_qtFile->rename(newName);
+}
+
+
+bool DiskLocationItemFile::rename(const QString& oldname, const QString &newName)
+{
+ return QFile::rename(oldname, newName);
+}
+
+
+bool DiskLocationItemFile::remove()
+{
+ return m_qtFile->remove();
+}
+
+
+bool DiskLocationItemFile::remove(const QString& name)
+{
+ return QFile::remove(name);
+}
+
+
+bool DiskLocationItemFile::link(const QString& linkName)
+{
+ return m_qtFile->link(linkName);
+}
+
+
+bool DiskLocationItemFile::open(QIODevice::OpenMode mode)
+{
+ return m_qtFile->open(mode);
+}
+
+
+qint64 DiskLocationItemFile::read(char * buffer, qint64 bytes)
+{
+ return m_qtFile->read(buffer, bytes);
+}
+
+
+qint64 DiskLocationItemFile::write(const char *buffer, qint64 bytes)
+{
+ return m_qtFile->write(buffer, bytes);
+}
+
+
+void DiskLocationItemFile::close()
+{
+ m_qtFile->close();
+}
+
+
+bool DiskLocationItemFile::atEnd() const
+{
+ return m_qtFile->atEnd();
+}
+
+
+qint64 DiskLocationItemFile::size() const
+{
+ return m_qtFile->size();
+}
+
+
+bool DiskLocationItemFile::isOpen() const
+{
+ return m_qtFile->isOpen();
+}
+
+
+bool DiskLocationItemFile::setPermissions(QFileDevice::Permissions perm)
+{
+ return m_qtFile->setPermissions(perm);
+}
+
+
+bool DiskLocationItemFile::setPermissions(const QString &filename, QFileDevice::Permissions perm)
+{
+ return QFile::setPermissions(filename, perm);
+}
+
+
+QFile::Permissions DiskLocationItemFile::permissions() const
+{
+ return m_qtFile->permissions();
+}
=== 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-07-19 15:38:39 +0000
@@ -0,0 +1,55 @@
+/**************************************************************************
+ *
+ * Copyright 2015 Canonical Ltd.
+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@xxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * File: disklocationitemfile.h
+ * Date: 20/04/2015
+ */
+
+#ifndef DISKLOCATIONITEMFILE_H
+#define DISKLOCATIONITEMFILE_H
+
+#include "locationitemfile.h"
+
+class DiskLocationItemFile : public LocationItemFile
+{
+ Q_OBJECT
+public:
+ explicit DiskLocationItemFile(QObject *parent);
+ explicit DiskLocationItemFile(const QString& name, QObject *parent);
+ ~DiskLocationItemFile();
+public:
+ virtual QString fileName() const;
+ virtual bool rename(const QString& newName);
+ virtual bool rename(const QString& oldname, const QString& newName);
+ virtual bool remove();
+ virtual bool remove(const QString& name);
+ virtual bool link(const QString& linkName);
+ virtual bool open(QFile::OpenMode mode) ;
+ virtual qint64 read(char*, qint64);
+ virtual qint64 write(const char*, qint64);
+ virtual void close();
+ virtual bool atEnd() const;
+ virtual qint64 size() const;
+ virtual bool isOpen() const;
+ virtual bool setPermissions(const QString& filename, QFile::Permissions perm);
+ virtual bool setPermissions(QFile::Permissions perm);
+ virtual QFile::Permissions permissions() const;
+private:
+ QFile * m_qtFile;
+};
+
+#endif // DISKLOCATIONITEMFILE_H
=== modified file 'src/plugin/folderlistmodel/folderlistmodel.pri'
--- src/plugin/folderlistmodel/folderlistmodel.pri 2015-07-19 15:38:39 +0000
+++ src/plugin/folderlistmodel/folderlistmodel.pri 2015-07-19 15:38:39 +0000
@@ -14,9 +14,8 @@
$$PWD/locationsfactory.cpp \
$$PWD/locationurl.cpp \
$$PWD/locationitemdiriterator.cpp \
- $$PWD/cleanurl.cpp \
- $$PWD/disk/disklocationitemdiriterator.cpp \
-
+ $$PWD/cleanurl.cpp \
+ $$PWD/locationitemfile.cpp \
HEADERS += $$PWD/dirmodel.h \
@@ -36,27 +35,47 @@
$$PWD/locationsfactory.h \
$$PWD/locationurl.h \
$$PWD/locationitemdiriterator.h \
- $$PWD/cleanurl.h \
+ $$PWD/cleanurl.h \
+ $$PWD/locationitemfile.h \
+
+
+SOURCES += $$PWD/disk/disklocation.cpp \
+ $$PWD/disk/disklocationitemdiriterator.cpp \
+ $$PWD/disk/disklocationitemfile.cpp
+
+HEADERS += $$PWD/disk/disklocation.h \
$$PWD/disk/disklocationitemdiriterator.h \
-
-
-SOURCES += $$PWD/disk/disklocation.cpp
-HEADERS += $$PWD/disk/disklocation.h
-
-SOURCES += $$PWD/trash/qtrashdir.cpp $$PWD/trash/trashiteminfo.cpp \
- $$PWD/trash/qtrashutilinfo.cpp $$PWD/trash/trashlocation.cpp
-HEADERS += $$PWD/trash/qtrashdir.h $$PWD/trash/trashiteminfo.h \
- $$PWD/trash/qtrashutilinfo.h $$PWD/trash/trashlocation.h
-
-SOURCES += $$PWD/smb/smblocation.cpp $$PWD/smb/smblocationauthentication.cpp $$PWD/smb/smblistworker.cpp
-HEADERS += $$PWD/smb/smblocation.h $$PWD/smb/smblocationauthentication.h $$PWD/smb/smblistworker.h
-
-SOURCES += $$PWD/net/netutil.cpp $$PWD/net/netauthenticationdata.cpp
-HEADERS += $$PWD/net/netutil.h $$PWD/net/netauthenticationdata.h
+ $$PWD/disk/disklocationitemfile.h
+
+
+SOURCES += $$PWD/trash/qtrashdir.cpp \
+ $$PWD/trash/trashiteminfo.cpp \
+ $$PWD/trash/qtrashutilinfo.cpp \
+ $$PWD/trash/trashlocation.cpp
+
+HEADERS += $$PWD/trash/qtrashdir.h \
+ $$PWD/trash/trashiteminfo.h \
+ $$PWD/trash/qtrashutilinfo.h \
+ $$PWD/trash/trashlocation.h
+
+SOURCES += $$PWD/smb/smblocation.cpp \
+ $$PWD/smb/smblocationauthentication.cpp \
+ $$PWD/smb/smblistworker.cpp
+
+HEADERS += $$PWD/smb/smblocation.h \
+ $$PWD/smb/smblocationauthentication.h \
+ $$PWD/smb/smblistworker.h
+
+include ($$PWD/smb/qsambaclient/qsambaclient.pri)
+
+SOURCES += $$PWD/net/netutil.cpp \
+ $$PWD/net/netauthenticationdata.cpp
+
+HEADERS += $$PWD/net/netutil.h \
+ $$PWD/net/netauthenticationdata.h
INCLUDEPATH += $$PWD $$PWD/trash $$PWD/disk $$PWD/smb $$PWD/net
-include ($$PWD/smb/qsambaclient/qsambaclient.pri)
greaterThan(QT_MAJOR_VERSION, 4) {
QT += qml
=== modified file 'src/plugin/folderlistmodel/location.h'
--- src/plugin/folderlistmodel/location.h 2015-07-19 15:38:39 +0000
+++ src/plugin/folderlistmodel/location.h 2015-07-19 15:38:39 +0000
@@ -30,7 +30,7 @@
class IOWorkerThread;
class DirListWorker;
class LocationItemDirIterator;
-
+class LocationItemFile;
/*!
* \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 @@
virtual LocationItemDirIterator * newDirIterator(const QString & path,
QDir::Filters filters,
QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags) = 0;
+ /*!
+ * \brief newFile() creates a LocationItemFile object which is similar to Qt QFile object
+ *
+ * It will be used in copy/paste/remove Actions
+ *
+ * \param path
+ * \return
+ */
+ virtual LocationItemFile * newFile(const QString & path) = 0;
/*!
=== 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-07-19 15:38:39 +0000
@@ -0,0 +1,97 @@
+/**************************************************************************
+ *
+ * Copyright 2015 Canonical Ltd.
+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@xxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * File: locationitemfile.cpp
+ * Date: 20/04/2015
+ */
+
+#include "locationitemfile.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+LocationItemFile::LocationItemFile(QObject *parent) :
+ QObject(parent)
+{
+}
+
+LocationItemFile::LocationItemFile(const QString&, QObject *parent) :
+ QObject(parent)
+{
+}
+
+LocationItemFile::~LocationItemFile()
+{
+
+}
+
+
+mode_t LocationItemFile::getUmask()
+{
+ mode_t mask = ::umask(0); //first gets the current umask and sets to 0
+ ::umask(mask); //second restores the current umask
+ return mask;
+}
+
+/*!
+ * \brief LocationItemFile::getUmaskCreationMode() Returns a suitable open creation mode for system calls like open() and mkdir() respecting umask()
+ * \param mode
+ * \return the open mode in the form: mode & ~umask
+ */
+mode_t LocationItemFile::getUmaskCreationMode(mode_t mode)
+{
+ mode_t mask = getUmask();
+ mode_t umode = mode & ~mask;
+ return umode;
+}
+
+/*!
+ * \brief LocationItemFile::getUmaskFilesCreation() Returns the default open mode for files
+ * \return
+ */
+mode_t LocationItemFile::getUmaskFilesCreation()
+{
+ return LocationItemFile::getUmaskCreationMode(0666);
+}
+
+
+/*!
+ * \brief LocationItemFile::getUmaskFilesCreation() Returns the default open mode for directories
+ * \return
+ */
+mode_t LocationItemFile::getUmaskDirsCreation()
+{
+ return LocationItemFile::getUmaskCreationMode(0777);
+}
+
+
+mode_t LocationItemFile::unixPermissions(QFileDevice::Permissions perm)
+{
+#define SETMODE(qtPerm, Uperm) if (perm & qtPerm) { mode |= Uperm; }
+ mode_t mode = 0;
+ SETMODE((QFile::ReadOwner | QFile::ReadUser), S_IRUSR);
+ SETMODE((QFile::WriteOwner | QFile::WriteUser), S_IWUSR);
+ SETMODE((QFile::ExeOwner | QFile::ExeUser), S_IXUSR);
+ SETMODE(QFile::ReadGroup, S_IRGRP);
+ SETMODE(QFile::WriteGroup, S_IWGRP);
+ SETMODE(QFile::ExeGroup, S_IXGRP);
+ SETMODE(QFile::ReadOther, S_IROTH);
+ SETMODE(QFile::WriteOther, S_IWOTH);
+ SETMODE(QFile::ExeOther, S_IXOTH);
+ return mode;
+}
=== 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-07-19 15:38:39 +0000
@@ -0,0 +1,72 @@
+/**************************************************************************
+ *
+ * Copyright 2015 Canonical Ltd.
+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@xxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * File: locationitemfile.h
+ * Date: 20/04/2015
+ */
+
+#ifndef LOCATIONITEMFILE_H
+#define LOCATIONITEMFILE_H
+
+#include <QFile>
+#include <sys/types.h>
+
+
+
+/*!
+ * \brief The LocationItemFile class is an abstract class similar to Qt QFile
+ *
+ * It will be used in Actions like copy/paste
+ */
+class LocationItemFile : public QObject
+{
+ Q_OBJECT
+protected:
+ explicit LocationItemFile(QObject *parent = 0);
+ explicit LocationItemFile(const QString& name, QObject *parent = 0);
+public:
+ virtual ~LocationItemFile();
+public:
+ virtual QString fileName() const = 0;
+ virtual bool rename(const QString& newName) = 0;
+ virtual bool rename(const QString& oldname, const QString& newName) = 0;
+ virtual bool remove() = 0;
+ virtual bool remove(const QString& name) = 0;
+ virtual bool link(const QString& linkName) = 0;
+ virtual bool open(QFile::OpenMode mode) = 0 ;
+ virtual qint64 read(char*, qint64) = 0;
+ virtual qint64 write(const char*, qint64) = 0;
+ virtual void close() = 0;
+ virtual bool atEnd() const = 0;
+ virtual qint64 size() const = 0;
+ virtual bool isOpen() const = 0;
+ virtual bool setPermissions(const QString& filename, QFile::Permissions perm) = 0;
+ virtual bool setPermissions(QFile::Permissions perm) = 0;
+ virtual QFile::Permissions permissions() const = 0;
+public: //static functions
+ static mode_t getUmask(); //return the current umask
+ static mode_t getUmaskCreationMode(mode_t mode); // mode & ~umask;
+ static mode_t getUmaskFilesCreation(); // 0666 & ~umask;
+ static mode_t getUmaskDirsCreation(); // 0777 & ~umask;
+ static mode_t unixPermissions(QFile::Permissions);
+signals:
+
+public slots:
+
+};
+
+#endif // LOCATIONITEMFILE_H
=== 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-07-19 15:38:39 +0000
@@ -4,7 +4,8 @@
$$PWD/src/smbiteminfo.cpp \
$$PWD/src/smbplaces.cpp \
$$PWD/src/smbobject.cpp \
- $$PWD/src/smblocationdiriterator.cpp
+ $$PWD/src/smblocationdiriterator.cpp \
+ $$PWD/src/smblocationitemfile.cpp \
HEADERS += $$PWD/src/smbutil.h \
@@ -12,7 +13,9 @@
$$PWD/src/smbiteminfo.h \
$$PWD/src/smbplaces.h \
$$PWD/src/smbobject.h \
- $$PWD/src/smblocationdiriterator.h
+ $$PWD/src/smblocationdiriterator.h \
+ $$PWD/src/smblocationitemfile.h \
+
QT *= core network
=== 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-07-19 15:38:39 +0000
@@ -0,0 +1,321 @@
+/**************************************************************************
+ *
+ * Copyright 2015 Canonical Ltd.
+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@xxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * File: smblocationitemfile.cpp
+ * Date: 20/04/2015
+ */
+
+#include "smblocationitemfile.h"
+#include "smbiteminfo.h"
+
+#include <sys/stat.h>
+#include <sys/statfs.h>
+#include <errno.h>
+
+#include <QDebug>
+
+
+SmbLocationItemFile::SmbLocationItemFile(QObject *parent, Const_SmbUtil_Ptr smb)
+ : LocationItemFile(parent)
+ , SmbObject(QLatin1String(0), smb)
+ , m_fd(0)
+ , m_context(0)
+ , m_curReadPosition(0)
+ , m_openMode(0)
+{
+
+}
+
+SmbLocationItemFile::SmbLocationItemFile(const QString &name, QObject *parent, Const_SmbUtil_Ptr smb)
+ : LocationItemFile(parent)
+ , SmbObject(name, smb)
+ , m_fd(0)
+ , m_context(0)
+ , m_curReadPosition(0)
+ , m_openMode(0)
+{
+
+}
+
+
+SmbLocationItemFile::~SmbLocationItemFile()
+{
+ close();
+ if (m_context)
+ {
+ SmbObject::smbObj()->deleteContext(m_context);
+ m_context = 0;
+ }
+}
+
+
+QString SmbLocationItemFile::fileName() const
+{
+ return cleanUrl();
+}
+
+
+bool SmbLocationItemFile::rename(const QString& newName)
+{
+ bool ret = false;
+ if (!cleanUrl().isEmpty())
+ {
+ close();
+ ret = rename(cleanUrl(), newName);
+ }
+ return ret;
+}
+
+
+bool SmbLocationItemFile::rename(const QString& oldname, const QString& newName)
+{
+ createContext();
+ Smb::Context nContext = SmbObject::smbObj()->createContext();
+ int ret = smbc_getFunctionRename(m_context)
+ (m_context,
+ oldname.toLocal8Bit().constData(),
+ nContext,
+ newName.toLocal8Bit().constData()
+ );
+ SmbObject::smbObj()->deleteContext(nContext);
+ return ret == 0;
+}
+
+
+bool SmbLocationItemFile::remove()
+{
+ return private_remove(cleanUrl());
+}
+
+
+bool SmbLocationItemFile::remove(const QString& name)
+{
+ CleanUrl otherUrl(name);
+ if (otherUrl.hasAuthenticationData())
+ {
+ qWarning() << Q_FUNC_INFO
+ << "Authentication in the form smb://user:password@pathname is not supported" ;
+ }
+ return private_remove(name) ;
+}
+
+
+bool SmbLocationItemFile::link(const QString& linkName)
+{
+ Q_UNUSED(linkName);
+ qWarning() << Q_FUNC_INFO << "Smbclient does not provide link() function";
+ return false;
+}
+
+
+bool SmbLocationItemFile::open(QIODevice::OpenMode mode)
+{
+ bool ret = false;
+ QString smb_path = cleanUrl();
+ if (!smb_path.isEmpty() && !isOpen())
+ {
+ int openFlags = 0;
+ m_openMode = mode;
+ createContext();
+ if (mode & QFile::ReadOnly)
+ {
+ openFlags = mode & QFile::WriteOnly ? O_RDWR : O_RDONLY;
+ }
+ else
+ {
+ if (mode & QFile::WriteOnly)
+ {
+ openFlags = O_CREAT | O_WRONLY;
+ }
+ if (mode & QFile::Append)
+ {
+ openFlags = O_APPEND | O_CREAT | O_WRONLY;
+ }
+ if ((mode & QFile::Truncate) || !(mode & QFile::Append))
+ {
+ openFlags |= O_TRUNC;
+ }
+ }
+ int creationMode = LocationItemFile::getUmaskFilesCreation();
+ /*
+ * it looks like SMB open() does set the permission properly
+ * does not matter what value "creationMode" has, libsmbclient always creates files with the following permission:
+ * -rwxr--r-- 1 nobody nogroup 0 Mai 30 14:04 second_item.txt
+ * SMB chmod() does not work either
+ *
+ * It depends on Samba configuration: force user; force group; force create mode; force directory mode
+ */
+ m_fd = SmbObject::smbObj()->openFile(m_context, smb_path, openFlags, creationMode);
+ ret = m_fd ? true : false;
+ }
+ return ret;
+}
+
+
+qint64 SmbLocationItemFile::read(char * buffer, qint64 bytes)
+{
+ qint64 ret = -1;
+ if (isOpen())
+ {
+ size_t to_write = static_cast<size_t> (bytes);
+ void *buf = static_cast<void*> (buffer);
+ ssize_t wr = smbc_getFunctionRead(m_context)(m_context, m_fd, buf, to_write);
+ ret = static_cast<qint64> (wr);
+ }
+ if (ret > 0)
+ {
+ m_curReadPosition += ret;
+ }
+ return ret;
+}
+
+
+qint64 SmbLocationItemFile::write(const char * buffer, qint64 bytes)
+{
+ qint64 ret = -1;
+ if (isOpen())
+ {
+ size_t to_read = static_cast<size_t> (bytes);
+ const void * const_buf = static_cast<const void*> (buffer);
+ void *buf = const_cast<void*> (const_buf);
+ ssize_t rd = smbc_getFunctionWrite(m_context)(m_context, m_fd, buf, to_read);
+ ret = static_cast<qint64> (rd);
+ }
+ return ret;
+}
+
+
+void SmbLocationItemFile::close()
+{
+ if (isOpen())
+ {
+ SmbObject::smbObj()->closeHandle(m_context, m_fd);
+ m_fd = 0;
+ }
+ m_curReadPosition = 0;
+}
+
+
+bool SmbLocationItemFile::atEnd() const
+{
+ bool ret = true; //closed files are at end, aren't they?
+ if (isOpen())
+ {
+ struct stat st;
+ if (smbObj()->getFstat(m_context,m_fd, &st) == SmbUtil::StatDone)
+ {
+ ret = m_curReadPosition >= st.st_size;
+ }
+ }
+ return ret;
+}
+
+
+qint64 SmbLocationItemFile::size() const
+{
+ qint64 size = 0;
+ struct stat st;
+ SmbUtil::StatReturn ret = SmbUtil::StatInvalid;
+ if (isOpen())
+ {
+ ret = smbObj()->getFstat(m_context,m_fd, &st);
+ }
+ else
+ {
+ SmbLocationItemFile *mySelf = const_cast<SmbLocationItemFile*> (this);
+ mySelf->createContext();
+ ret = smbObj()->getStat(m_context,cleanUrl(), &st);
+ }
+ if(ret == SmbUtil::StatDone)
+ {
+ size = static_cast<qint64> (st.st_size);
+ }
+ return size;
+}
+
+
+bool SmbLocationItemFile::isOpen() const
+{
+ return m_fd != 0 && m_context != 0 ? true : false;
+}
+
+
+bool SmbLocationItemFile::setPermissions(QFileDevice::Permissions perm)
+{
+ return setPermissions(cleanUrl(), perm);
+}
+
+
+bool SmbLocationItemFile::setPermissions(const QString &filename, QFileDevice::Permissions perm)
+{
+ bool ret = false;
+ if (!filename.isEmpty())
+ {
+ if (m_context == 0)
+ {
+ createContext();
+ }
+ ret = smbObj()->changePermissions(m_context, filename, LocationItemFile::unixPermissions(perm));
+ /*
+ * fake the return in case the file exists becase chmod() on libsmbclient does not work,
+ * the same comment is present in the \ref open()
+ */
+ if (!ret)
+ {
+ struct stat st;
+ ret = smbObj()->getStat(m_context,filename, &st) == SmbUtil::StatDone;
+ }
+ }
+ return ret;
+}
+
+
+QFile::Permissions SmbLocationItemFile::permissions() const
+{
+ SmbItemInfo info(cleanUrl(), m_smb);
+ return info.permissions();
+}
+
+
+bool SmbLocationItemFile::private_remove(const QString& smb_path)
+{
+ bool ret = false;
+ if (!smb_path.isEmpty())
+ {
+ close();
+ if (m_context == 0)
+ {
+ createContext();
+ }
+ if (smbc_getFunctionUnlink(m_context)(m_context, smb_path.toLocal8Bit().constData()) == 0)
+ {
+ ret = true;
+ }
+ }
+ return ret;
+}
+
+
+void SmbLocationItemFile::createContext()
+{
+ if (m_context != 0)
+ {
+ SmbObject::smbObj()->deleteContext(m_context);
+ }
+ m_context = SmbObject::smbObj()->createContext();
+ Q_ASSERT(m_context);
+}
=== 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-07-19 15:38:39 +0000
@@ -0,0 +1,70 @@
+/**************************************************************************
+ *
+ * Copyright 2015 Canonical Ltd.
+ * Copyright 2015 Carlos J Mazieri <carlos.mazieri@xxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * File: smblocationitemfile.h
+ * Date: 20/04/2015
+ */
+
+#ifndef SMBLOCATIONITEMFILE_H
+#define SMBLOCATIONITEMFILE_H
+
+#include "locationitemfile.h"
+#include "smbobject.h"
+#include "smbutil.h"
+
+class SmbItemInfo;
+
+
+/*!
+ * \brief The SmbLocationItemFile class is similar to Qt QFile
+ *
+ */
+class SmbLocationItemFile : public LocationItemFile, public SmbObject
+{
+ Q_OBJECT
+public:
+ explicit SmbLocationItemFile(QObject *parent = 0, Const_SmbUtil_Ptr smb = 0);
+ explicit SmbLocationItemFile(const QString& name, QObject *parent = 0, Const_SmbUtil_Ptr smb = 0);
+ ~SmbLocationItemFile();
+public:
+ virtual QString fileName() const;
+ virtual bool rename(const QString& newName);
+ virtual bool rename(const QString& oldname, const QString& newName);
+ virtual bool remove();
+ virtual bool remove(const QString& name);
+ virtual bool link(const QString& linkName);
+ virtual bool open(QFile::OpenMode mode) ;
+ virtual qint64 read(char*, qint64);
+ virtual qint64 write(const char *, qint64);
+ virtual void close();
+ virtual bool atEnd() const;
+ virtual qint64 size() const;
+ virtual bool isOpen() const;
+ virtual bool setPermissions(const QString& filename, QFile::Permissions perm);
+ virtual bool setPermissions(QFile::Permissions perm);
+ virtual QFile::Permissions permissions() const;
+private:
+ bool private_remove(const QString& smb_path);
+ void createContext();
+private:
+ Smb::FileHandler m_fd;
+ Smb::Context m_context;
+ qint64 m_curReadPosition;
+ QFile::OpenMode m_openMode;
+};
+
+#endif // SMBLOCATIONITEMFILE_H
=== modified file 'src/plugin/folderlistmodel/smb/smblocation.cpp'
--- src/plugin/folderlistmodel/smb/smblocation.cpp 2015-07-19 15:38:39 +0000
+++ src/plugin/folderlistmodel/smb/smblocation.cpp 2015-07-19 15:38:39 +0000
@@ -27,7 +27,7 @@
#include "iorequest.h"
#include "ioworkerthread.h"
#include "locationurl.h"
-
+#include "smblocationitemfile.h"
#if defined(Q_OS_UNIX)
@@ -113,6 +113,13 @@
}
+LocationItemFile *
+SmbLocation::newFile(const QString &path)
+{
+ return new SmbLocationItemFile(path, this, m_smb);
+}
+
+
bool SmbLocation::isThereDiskSpace(const QString &pathname, qint64 requiredSize)
{
bool ret = false;
=== modified file 'src/plugin/folderlistmodel/smb/smblocation.h'
--- src/plugin/folderlistmodel/smb/smblocation.h 2015-07-19 15:38:39 +0000
+++ src/plugin/folderlistmodel/smb/smblocation.h 2015-07-19 15:38:39 +0000
@@ -42,6 +42,7 @@
virtual LocationItemDirIterator * newDirIterator(const QString & path,
QDir::Filters filters,
QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
+ virtual LocationItemFile * newFile(const QString & path);
virtual bool isThereDiskSpace(const QString& pathname, qint64 requiredSize);
virtual QString urlBelongsToLocation(const QString& urlPath, int indexOfColonAndSlashe);
virtual QString currentAuthenticationUser();
Follow ups
-
[Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-12 into lp:ubuntu-filemanager-app
From: noreply, 2015-08-22
-
[Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-12 into lp:ubuntu-filemanager-app
From: Arto Jalkanen, 2015-08-22
-
Re: [Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-12 into lp:ubuntu-filemanager-app
From: Ubuntu Phone Apps Jenkins Bot, 2015-08-21
-
Re: [Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-12 into lp:ubuntu-filemanager-app
From: Ubuntu Phone Apps Jenkins Bot, 2015-08-21
-
[Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-12 into lp:ubuntu-filemanager-app
From: Ubuntu Phone Apps Jenkins Bot, 2015-08-21
-
Re: [Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-12 into lp:ubuntu-filemanager-app
From: Carlos Jose Mazieri, 2015-08-15
-
Re: [Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-12 into lp:ubuntu-filemanager-app
From: Carlos Jose Mazieri, 2015-08-12
-
[Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-12 into lp:ubuntu-filemanager-app
From: Arto Jalkanen, 2015-08-09
-
Re: [Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-12 into lp:ubuntu-filemanager-app
From: Arto Jalkanen, 2015-08-09
-
Re: [Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-12 into lp:ubuntu-filemanager-app
From: Ubuntu Phone Apps Jenkins Bot, 2015-07-21
-
Re: [Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-12 into lp:ubuntu-filemanager-app
From: Ubuntu Phone Apps Jenkins Bot, 2015-07-19