← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-14 into lp:ubuntu-filemanager-app

 

Carlos Jose Mazieri has proposed merging lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-14 into lp:ubuntu-filemanager-app with lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-13 as a prerequisite.

Commit message:
Inherited Location classes now provide inherited LocationItemDir classes which will replace Qt QDir class in Actions.
DiskLocation provides DiskLocationItemDir and SmbLocation provides SmbLocationItemDir

Requested reviews:
  Ubuntu File Manager Developers (ubuntu-filemanager-dev)

For more details, see:
https://code.launchpad.net/~carlos-mazieri/ubuntu-filemanager-app/samba-actions-14/+merge/265213

LocationItemDir classes are provided by Location inherited classes.
-- 
Your team Ubuntu File Manager Developers is requested to review the proposed merge of lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-14 into lp:ubuntu-filemanager-app.
=== modified file 'src/plugin/folderlistmodel/CMakeLists.txt'
--- src/plugin/folderlistmodel/CMakeLists.txt	2015-07-19 16:39:36 +0000
+++ src/plugin/folderlistmodel/CMakeLists.txt	2015-07-19 16:39:36 +0000
@@ -45,6 +45,10 @@
     locationurl.h
     locationitemdiriterator.cpp
     locationitemdiriterator.h
+    locationitemfile.cpp
+    locationitemfile.h
+    locationitemdir.cpp
+    locationitemdir.h
     cleanurl.cpp
     cleanurl.h
     urliteminfo.cpp
@@ -55,6 +59,8 @@
     disk/disklocationitemdiriterator.h
     disk/disklocationitemfile.cpp
     disk/disklocationitemfile.h
+    disk/disklocationitemdir.cpp
+    disk/disklocationitemdir.h
     trash/qtrashdir.cpp
     trash/qtrashdir.h   
     trash/qtrashutilinfo.cpp
@@ -73,6 +79,8 @@
     smb/qsambaclient/src/smblocationdiriterator.h
     smb/qsambaclient/src/smblocationitemfile.cpp
     smb/qsambaclient/src/smblocationitemfile.h
+    smb/qsambaclient/src/smblocationitemdir.cpp
+    smb/qsambaclient/src/smblocationitemdir.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 16:39:36 +0000
+++ src/plugin/folderlistmodel/disk/disklocation.cpp	2015-07-19 16:39:36 +0000
@@ -26,6 +26,7 @@
 #include "externalfswatcher.h"
 #include "locationurl.h"
 #include "disklocationitemfile.h"
+#include "disklocationitemdir.h"
 
 
 #if defined(Q_OS_UNIX)
@@ -204,6 +205,13 @@
 }
 
 
+LocationItemDir *
+DiskLocation::newDir(const QString &dir)
+{
+    return new DiskLocationItemDir(dir);
+}
+
+
 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 16:39:36 +0000
+++ src/plugin/folderlistmodel/disk/disklocation.h	2015-07-19 16:39:36 +0000
@@ -67,6 +67,7 @@
                                                      QDir::Filters filters,
                                                      QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
     virtual LocationItemFile   * newFile(const QString & path);
+    virtual LocationItemDir    * newDir(const QString & dir = QLatin1String(0));
     virtual bool        isThereDiskSpace(const QString& pathname, qint64 requiredSize);
     virtual QString     urlBelongsToLocation(const QString& urlPath, int indexOfColonAndSlashe);
 

=== added file 'src/plugin/folderlistmodel/disk/disklocationitemdir.cpp'
--- src/plugin/folderlistmodel/disk/disklocationitemdir.cpp	1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/disk/disklocationitemdir.cpp	2015-07-19 16:39:36 +0000
@@ -0,0 +1,61 @@
+/**************************************************************************
+ *
+ * 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: disklocationitemdir.cpp
+ * Date: 16/05/2015
+ */
+
+#include "disklocationitemdir.h"
+#include <QDir>
+
+DiskLocationItemDir::DiskLocationItemDir(const QString &dir) : LocationItemDir(dir), m_qtQDir(new QDir())
+{
+    if(!dir.isNull() && !dir.isEmpty())
+    {
+        m_qtQDir->setPath(dir);
+    }
+}
+
+
+DiskLocationItemDir::~DiskLocationItemDir()
+{
+
+}
+
+bool DiskLocationItemDir::exists() const
+{
+    return m_qtQDir->exists();
+}
+
+
+bool DiskLocationItemDir::mkdir(const QString& dir) const
+{
+    return m_qtQDir->mkdir(dir);
+}
+
+
+bool DiskLocationItemDir::mkpath(const QString& dir) const
+{
+     return m_qtQDir->mkpath(dir);
+}
+
+
+bool DiskLocationItemDir::rmdir(const QString& dir) const
+{
+    return m_qtQDir->rmdir(dir);
+}
+

=== added file 'src/plugin/folderlistmodel/disk/disklocationitemdir.h'
--- src/plugin/folderlistmodel/disk/disklocationitemdir.h	1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/disk/disklocationitemdir.h	2015-07-19 16:39:36 +0000
@@ -0,0 +1,45 @@
+/**************************************************************************
+ *
+ * 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: disklocationitemdir.h
+ * Date: 16/05/2015
+ */
+
+#ifndef DISKLOCATIONITEMDIR_H
+#define DISKLOCATIONITEMDIR_H
+
+#include "locationitemdir.h"
+
+class QDir;
+
+
+class DiskLocationItemDir : public LocationItemDir
+{
+public:
+    DiskLocationItemDir(const QString& dir = QLatin1String(0) );
+   ~DiskLocationItemDir();
+public:
+    virtual bool    exists()                   const;
+    virtual bool    mkdir(const QString& dir)  const;
+    virtual bool    mkpath(const QString& dir) const;
+    virtual bool    rmdir(const QString& dir)  const;
+private:
+    QDir  * m_qtQDir;
+
+};
+
+#endif // DISKLOCATIONITEMDIR_H

=== modified file 'src/plugin/folderlistmodel/folderlistmodel.pri'
--- src/plugin/folderlistmodel/folderlistmodel.pri	2015-07-19 16:39:36 +0000
+++ src/plugin/folderlistmodel/folderlistmodel.pri	2015-07-19 16:39:36 +0000
@@ -16,6 +16,7 @@
            $$PWD/locationitemdiriterator.cpp \
            $$PWD/cleanurl.cpp \           
            $$PWD/locationitemfile.cpp \
+           $$PWD/locationitemdir.cpp
 
 
 HEADERS += $$PWD/dirmodel.h \
@@ -37,15 +38,18 @@
            $$PWD/locationitemdiriterator.h \
            $$PWD/cleanurl.h \           
            $$PWD/locationitemfile.h \
+           $$PWD/locationitemdir.h
 
 
 SOURCES += $$PWD/disk/disklocation.cpp \
            $$PWD/disk/disklocationitemdiriterator.cpp \
-           $$PWD/disk/disklocationitemfile.cpp
+           $$PWD/disk/disklocationitemfile.cpp \
+           $$PWD/disk/disklocationitemdir.cpp
 
 HEADERS += $$PWD/disk/disklocation.h \
            $$PWD/disk/disklocationitemdiriterator.h \
-           $$PWD/disk/disklocationitemfile.h
+           $$PWD/disk/disklocationitemfile.h \
+           $$PWD/disk/disklocationitemdir.h
 
 
 SOURCES += $$PWD/trash/qtrashdir.cpp      \

=== modified file 'src/plugin/folderlistmodel/location.h'
--- src/plugin/folderlistmodel/location.h	2015-07-19 16:39:36 +0000
+++ src/plugin/folderlistmodel/location.h	2015-07-19 16:39:36 +0000
@@ -31,6 +31,7 @@
 class DirListWorker;
 class LocationItemDirIterator;
 class LocationItemFile;
+class LocationItemDir;
 
 /*!
  * \brief The Location class represents any location (full path) where there are items to browse: directories, shares, from Disk and from Network.
@@ -134,6 +135,15 @@
       */
      virtual LocationItemFile   * newFile(const QString & path) = 0;
 
+    /*!
+      * \brief newDir() creates a LocationItemDir object which is simila to Qt QDir object
+      *
+      * It will be used in copy/paste/remove Actions
+      *
+      * \param dir
+      * \return
+      */
+     virtual LocationItemDir    * newDir(const QString & dir = QLatin1String(0)) = 0;
 
     /*!
       * \brief urlBelongsToLocation() Returns a good  url if the \a urlPath is valid URL that belongs to its location

=== added file 'src/plugin/folderlistmodel/locationitemdir.cpp'
--- src/plugin/folderlistmodel/locationitemdir.cpp	1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/locationitemdir.cpp	2015-07-19 16:39:36 +0000
@@ -0,0 +1,34 @@
+/**************************************************************************
+ *
+ * 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: locationitemdir.cpp
+ * Date: 16/05/2015
+ */
+
+#include "locationitemdir.h"
+#include <QString>
+
+LocationItemDir::LocationItemDir(const QString& dir)
+{
+    Q_UNUSED(dir);
+}
+
+
+LocationItemDir::~LocationItemDir()
+{
+
+}

=== added file 'src/plugin/folderlistmodel/locationitemdir.h'
--- src/plugin/folderlistmodel/locationitemdir.h	1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/locationitemdir.h	2015-07-19 16:39:36 +0000
@@ -0,0 +1,41 @@
+/**************************************************************************
+ *
+ * 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: locationitemdir.h
+ * Date: 16/05/2015
+ */
+
+#ifndef LOCATIONITEMDIR_H
+#define LOCATIONITEMDIR_H
+
+#include <QString>
+
+class LocationItemDir
+{
+public:
+    virtual  ~LocationItemDir();
+public:
+    virtual bool    exists()                   const = 0;
+    virtual bool    mkdir(const QString& dir)  const = 0;
+    virtual bool    mkpath(const QString& dir) const = 0;
+    virtual bool    rmdir(const QString& dir)  const = 0;
+protected:
+    LocationItemDir ();
+    LocationItemDir (const QString& dir =  QLatin1String(0));
+};
+
+#endif // LOCATIONITEMDIR_H

=== modified file 'src/plugin/folderlistmodel/smb/qsambaclient/qsambaclient.pri'
--- src/plugin/folderlistmodel/smb/qsambaclient/qsambaclient.pri	2015-07-19 16:39:36 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/qsambaclient.pri	2015-07-19 16:39:36 +0000
@@ -6,6 +6,7 @@
              $$PWD/src/smbobject.cpp \
              $$PWD/src/smblocationdiriterator.cpp \
              $$PWD/src/smblocationitemfile.cpp \
+             $$PWD/src/smblocationitemdir.cpp
 
 
 HEADERS +=   $$PWD/src/smbutil.h \
@@ -15,6 +16,7 @@
              $$PWD/src/smbobject.h \
              $$PWD/src/smblocationdiriterator.h \
              $$PWD/src/smblocationitemfile.h \
+             $$PWD/src/smblocationitemdir.h
 
           
 QT          *= core network             

=== added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationitemdir.cpp'
--- src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationitemdir.cpp	1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationitemdir.cpp	2015-07-19 16:39:36 +0000
@@ -0,0 +1,128 @@
+/**************************************************************************
+ *
+ * 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: smblocationitemdir.cpp
+ * Date: 16/05/2015
+ */
+
+#include "smblocationitemdir.h"
+#include "locationitemfile.h"
+#include "smbiteminfo.h"
+#include "smbutil.h"
+#include "locationurl.h"
+
+#include <QUrl>
+
+SmbLocationItemDir::SmbLocationItemDir(const QString &dir, Const_SmbUtil_Ptr smb)
+     : LocationItemDir(dir), SmbObject(dir, smb)
+{
+
+}
+
+
+SmbLocationItemDir::~SmbLocationItemDir()
+{
+
+}
+
+bool SmbLocationItemDir::exists() const
+{
+    bool ret = false;
+    if (!cleanUrl().isEmpty())
+    {
+        SmbItemInfo item(cleanUrl(), m_smb);
+        ret = item.exists();
+    }
+    return ret;
+}
+
+
+bool SmbLocationItemDir::mkdir(const QString& dir) const
+{
+    return this->mkpath(dir);
+}
+
+
+bool SmbLocationItemDir::mkpath(const QString& dir) const
+{
+#define  MKDIR_NOT_CALLED_YET   0x300  // any value greater than zero as mkdir returns values <= zero
+     bool ret = false;
+     QString absPath = makeAbsoluteUrl(dir);
+     QUrl url(absPath);
+     if (url.isValid() && absPath.startsWith(LocationUrl::SmbURL))
+     {
+         QLatin1Char slash('/');
+         QStringList paths = url.path().split(slash, QString::SkipEmptyParts);         
+         QString partPath = LocationUrl::SmbURL + url.host();
+         ret  = true;
+         //first mkdir call updates this  mkdir_return
+         int  mkdir_return = MKDIR_NOT_CALLED_YET;
+         Smb::Context context = smbObj()->createContext();
+         Q_ASSERT(context);
+         //loop starts with share, appends each path and if it does exist tries to create it
+         //for shares (counter == 0) it must exist, so it it is not created
+         for(int counter = 0; ret && counter < paths.count(); ++counter)
+         {            
+             partPath += slash + paths.at(counter);
+             //if mkdir was called it means any path in the loop will not exist, so it is NOT necessary to call openDir()
+             Smb::FileHandler fd = mkdir_return == MKDIR_NOT_CALLED_YET ?
+                                   smbObj()->openDir(context,partPath) : 0;
+             //OK if it already exists or if it was created
+             //shares (the first path, when counter == 0) must already exist
+             ret = fd != 0 || (counter > 0 &&
+                               (mkdir_return = ::smbc_getFunctionMkdir(context)(context, partPath.toLocal8Bit().constData(), LocationItemFile::getUmaskDirsCreation())) == 0
+                              );
+             if (fd != 0)
+             {
+                 smbObj()->closeHandle(context,fd);
+             }            
+         }
+         smbObj()->deleteContext(context);
+     }
+     return ret;
+}
+
+
+bool SmbLocationItemDir::rmdir(const QString& dir) const
+{
+    bool ret = false;
+    QString fullpath = makeAbsoluteUrl(dir);
+    if (fullpath.startsWith(LocationUrl::SmbURL))
+    {
+        Smb::Context context = smbObj()->createContext();
+        Q_ASSERT(context);
+        if (::smbc_getFunctionRmdir(context)(context,fullpath.toLocal8Bit().constData()) == 0)
+        {
+            ret = true;
+        }
+        smbObj()->deleteContext(context);
+    }
+    return ret;
+}
+
+
+QString SmbLocationItemDir::makeAbsoluteUrl(const QString &dir) const
+{
+    //dir should be a full URL like smb://host/share
+    QString ret(dir);
+    //verify if dir is relative
+    if (!dir.startsWith(LocationUrl::SmbURL) && cleanUrl().startsWith(LocationUrl::SmbURL))
+    {
+        ret = cleanUrl() + QDir::separator() + dir;
+    }
+    return ret;
+}

=== added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationitemdir.h'
--- src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationitemdir.h	1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationitemdir.h	2015-07-19 16:39:36 +0000
@@ -0,0 +1,42 @@
+/**************************************************************************
+ *
+ * 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: smblocationitemdir.h
+ * Date: 16/05/2015
+ */
+
+#ifndef SMBLOCATIONITEMDIR_H
+#define SMBLOCATIONITEMDIR_H
+
+#include "locationitemdir.h"
+#include "smbobject.h"
+
+class SmbLocationItemDir : public LocationItemDir, public SmbObject
+{
+public:
+    SmbLocationItemDir(const QString& dir = QLatin1String(0), Const_SmbUtil_Ptr  smb  = 0 );
+   ~SmbLocationItemDir();
+public:
+    virtual bool    exists()                   const;
+    virtual bool    mkdir(const QString& dir)  const;
+    virtual bool    mkpath(const QString& dir) const;
+    virtual bool    rmdir(const QString& dir)  const;
+private:
+    QString        makeAbsoluteUrl(const QString& dir) const;
+};
+
+#endif // SMBLOCATIONITEMDIR_H

=== modified file 'src/plugin/folderlistmodel/smb/smblocation.cpp'
--- src/plugin/folderlistmodel/smb/smblocation.cpp	2015-07-19 16:39:36 +0000
+++ src/plugin/folderlistmodel/smb/smblocation.cpp	2015-07-19 16:39:36 +0000
@@ -28,6 +28,7 @@
 #include "ioworkerthread.h"
 #include "locationurl.h"
 #include "smblocationitemfile.h"
+#include "smblocationitemdir.h"
 
 
 #if defined(Q_OS_UNIX)
@@ -120,6 +121,14 @@
 }
 
 
+LocationItemDir *
+SmbLocation::newDir(const QString &dir)
+{
+    return new SmbLocationItemDir(dir, 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 16:39:36 +0000
+++ src/plugin/folderlistmodel/smb/smblocation.h	2015-07-19 16:39:36 +0000
@@ -43,7 +43,8 @@
                                                       QDir::Filters filters,
                                                       QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
     virtual LocationItemFile   * newFile(const QString & path);   
-    virtual bool        isThereDiskSpace(const QString& pathname, qint64 requiredSize);
+    virtual LocationItemDir    * newDir(const QString & dir = QLatin1String(0));
+     virtual bool       isThereDiskSpace(const QString& pathname, qint64 requiredSize);
     virtual QString     urlBelongsToLocation(const QString& urlPath, int indexOfColonAndSlashe);
     virtual QString     currentAuthenticationUser();
     virtual QString     currentAuthenticationPassword();


Follow ups