← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/new-protocols-support-04 into lp:ubuntu-filemanager-app

 

Carlos Jose Mazieri has proposed merging lp:~carlos-mazieri/ubuntu-filemanager-app/new-protocols-support-04 into lp:ubuntu-filemanager-app with lp:~carlos-mazieri/ubuntu-filemanager-app/new-protocols-support-03 as a prerequisite.

Commit message:
* Created new and generic classes: NetworkLocation and NetworkListWorker
* SmbLocation now inherits from the generic NetworkLocation instead of Location
* SmbListWorker class is no longer used and it will be removed
* NetworkListWorker really performs the loading on a secondary thread

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

For more details, see:
https://code.launchpad.net/~carlos-mazieri/ubuntu-filemanager-app/new-protocols-support-04/+merge/280390

* Created new and generic classes: NetworkLocation and NetworkListWorker
* SmbLocation now inherits from the generic NetworkLocation instead of Location
* SmbListWorker class is no longer used and it will be removed
* NetworkListWorker really performs the loading on a secondary thread
-- 
Your team Ubuntu File Manager Developers is requested to review the proposed merge of lp:~carlos-mazieri/ubuntu-filemanager-app/new-protocols-support-04 into lp:ubuntu-filemanager-app.
=== modified file 'src/plugin/folderlistmodel/CMakeLists.txt'
--- src/plugin/folderlistmodel/CMakeLists.txt	2015-08-25 15:42:01 +0000
+++ src/plugin/folderlistmodel/CMakeLists.txt	2015-12-12 15:47:20 +0000
@@ -35,6 +35,8 @@
     iorequestworker.h
     ioworkerthread.cpp
     ioworkerthread.h
+    networklistworker.cpp
+    networklistworker.h
     plugin.cpp
     plugin.h
     location.cpp
@@ -43,6 +45,8 @@
     locationsfactory.h
     locationurl.cpp
     locationurl.h
+    networklocation.cpp
+    networklocation.h
     locationitemdir.cpp
     locationitemdir.h
     locationitemdiriterator.cpp

=== modified file 'src/plugin/folderlistmodel/folderlistmodel.pri'
--- src/plugin/folderlistmodel/folderlistmodel.pri	2015-07-15 17:42:37 +0000
+++ src/plugin/folderlistmodel/folderlistmodel.pri	2015-12-12 15:47:20 +0000
@@ -16,8 +16,9 @@
            $$PWD/locationitemdiriterator.cpp \
            $$PWD/cleanurl.cpp \           
            $$PWD/locationitemfile.cpp \
-           $$PWD/locationitemdir.cpp
-
+           $$PWD/locationitemdir.cpp \
+           $$PWD/networklocation.cpp \
+           $$PWD/networklistworker.cpp
 
 HEADERS += $$PWD/dirmodel.h \
            $$PWD/iorequest.h \
@@ -38,7 +39,9 @@
            $$PWD/locationitemdiriterator.h \
            $$PWD/cleanurl.h \           
            $$PWD/locationitemfile.h \
-           $$PWD/locationitemdir.h
+           $$PWD/locationitemdir.h \
+           $$PWD/networklocation.h \
+           $$PWD/networklistworker.h
 
 
 SOURCES += $$PWD/disk/disklocation.cpp \

=== added file 'src/plugin/folderlistmodel/networklistworker.cpp'
--- src/plugin/folderlistmodel/networklistworker.cpp	1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/networklistworker.cpp	2015-12-12 15:47:20 +0000
@@ -0,0 +1,74 @@
+/**************************************************************************
+ *
+ * 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: networklistworker.cpp
+ * Date: 06/12/2015
+ */
+
+#include "networklistworker.h"
+#include "locationitemdiriterator.h"
+#include "locationurl.h"
+
+NetworkListWorker::NetworkListWorker(LocationItemDirIterator * dirIterator,
+                                     DirItemInfo * mainItemInfo, const DirItemInfo *parent) :
+    DirListWorker(dirIterator->path(),
+                  dirIterator->filters(),
+                  dirIterator->flags() == QDirIterator::Subdirectories ? true : false),
+    m_dirIterator(dirIterator),
+    m_mainItemInfo(mainItemInfo),
+    m_parent(parent)
+{
+     mLoaderType =  NetworkLoader;
+}
+
+
+NetworkListWorker::~NetworkListWorker()
+{
+    delete m_dirIterator;
+    delete m_mainItemInfo;
+}
+
+
+DirItemInfoList NetworkListWorker::getNetworkContent()
+{
+     DirItemInfoList netContent;
+     m_dirIterator->load();
+     bool is_parent_of_smb_url = m_parent != 0 && m_parent->urlPath().startsWith(LocationUrl::SmbURL);
+     while (m_dirIterator->hasNext())
+     {
+         m_mainItemInfo->setFile(m_dirIterator->next());
+         if (is_parent_of_smb_url)
+         {
+             setSmbItemAttributes();
+         }
+         netContent.append(*m_mainItemInfo);
+     }
+     return netContent;
+}
+
+/*!
+ * \brief NetworkListWorker::setSmbItemAttributes()
+ *
+ *  This original implementation regards only to Samba (smb:// protocol),
+ *  it will not hurt other protocols implementation.
+ */
+void NetworkListWorker::setSmbItemAttributes()
+{    
+    if (m_parent->isHost())      { m_mainItemInfo->setAsShare(); }
+    else
+    if (m_parent->isWorkGroup()) { m_mainItemInfo->setAsHost(); }
+}

=== added file 'src/plugin/folderlistmodel/networklistworker.h'
--- src/plugin/folderlistmodel/networklistworker.h	1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/networklistworker.h	2015-12-12 15:47:20 +0000
@@ -0,0 +1,54 @@
+/**************************************************************************
+ *
+ * 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: networklistworker.h
+ * Date: 06/12/2015
+ */
+
+#ifndef NETWORKLISTWORKER_H
+#define NETWORKLISTWORKER_H
+
+#include "iorequestworker.h"
+
+class LocationItemDirIterator;
+class DirItemInfo;
+
+/*!
+ * \brief The NetworkListWorker class intends to be a generic Network directory loader.
+ *.
+ *  It trusts on \ref LocationItemDirIterator and \ref DirItemInfo classes
+ *
+ *  The LocationItemDirIterator::load() must bring the list of items.
+ */
+class NetworkListWorker : public DirListWorker
+{
+   Q_OBJECT
+public:
+    NetworkListWorker(LocationItemDirIterator * dirIterator,
+                      DirItemInfo             * mainItemInfo,
+                      const DirItemInfo       * parent = 0);
+    ~NetworkListWorker();
+protected:
+    virtual DirItemInfoList getNetworkContent();
+    void                    setSmbItemAttributes();
+protected:
+     LocationItemDirIterator     * m_dirIterator;
+     DirItemInfo                 * m_mainItemInfo;
+     const DirItemInfo           * m_parent;
+};
+
+#endif // NETWORKLISTWORKER_H

=== added file 'src/plugin/folderlistmodel/networklocation.cpp'
--- src/plugin/folderlistmodel/networklocation.cpp	1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/networklocation.cpp	2015-12-12 15:47:20 +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: networklocation.cpp
+ * Date: 08/12/2015
+ */
+
+#include "networklocation.h"
+#include "networklistworker.h"
+#include "locationitemdiriterator.h"
+#include "diriteminfo.h"
+
+NetworkLocation::NetworkLocation(int type, QObject *parent): Location(type, parent)
+{
+}
+
+
+
+DirListWorker * NetworkLocation::newListWorker(const QString &urlPath, QDir::Filters filter, const bool isRecursive)
+{
+    QDirIterator::IteratorFlags flags = isRecursive ? QDirIterator::Subdirectories : QDirIterator::NoIteratorFlags;
+
+    LocationItemDirIterator *dirIterator  = newDirIterator(urlPath,filter,flags,LocationItemDirIterator::LoadLater);
+    DirItemInfo             *baseitemInfo = newItemInfo(QLatin1String(0));
+
+    return new NetworkListWorker(dirIterator, baseitemInfo, m_info);
+}

=== added file 'src/plugin/folderlistmodel/networklocation.h'
--- src/plugin/folderlistmodel/networklocation.h	1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/networklocation.h	2015-12-12 15:47:20 +0000
@@ -0,0 +1,89 @@
+/**************************************************************************
+ *
+ * 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: networklocation.h
+ * Date: 08/12/2015
+ */
+
+#ifndef NETWORKLOCATION_H
+#define NETWORKLOCATION_H
+
+#include "location.h"
+
+/*!
+ * \brief The NetworkLocation class is an Abstract class suitable for Network protocols easy browsing implementation
+ *
+ * Support to new protocols can have its browsing provided by this class and for the generic class \ref NetworkListWorker.
+ *
+ * To get the browsing working on a network protocol just create a new \ref Location class inherited from NetworkLocation,
+ *  then provide both suitable classes \ref DirItemInfo and  \ref descendant classes for this new \ref Location.
+ *
+ * The browsing itself will be performed inside a secondary thread using the \ref NetworkListWorker class.
+ *
+ *\note  For this new \ref Location class it is also necessary:
+ *    \li an enumerator item (the type) needs be added into Location::Locations
+ *    \li the corresponding protocol URL need be registered in \ref LocationUrl
+ *    \li an instance of this class needs to be created in the \ref LocationsFactory creator
+ *
+ * Minimal example of adding a new Location class the adds support to a new protocol in the File Manager:
+ *\code
+ *
+ *  class NewLocation : public NetworkLocation
+ *  {
+ *  public:
+ *      explicit NewLocation(int type, QObject *parent=0) : NetworkLocation(type, parent) {}
+ *      ~NewLocation() {}
+ *
+ *  public:
+ *      virtual DirItemInfo * newItemInfo(const QString& urlPath)
+ *      {
+ *          //provide the suitable DirItemInfo inherited class here
+ *      }
+ *
+ *      virtual LocationItemDirIterator * newDirIterator(const QString & path,
+ *                                                        QDir::Filters filters,
+ *                                                        QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags,
+ *                                                        LocationItemDirIterator::LoadMode loadmode = LocationItemDirIterator::LoadOnConstructor)
+ *      {
+ *        //provide the suitable LocationItemDirIterator object for the new protocol here
+ *      }
+ *
+ *      virtual LocationItemFile   * newFile(const QString & path) { return 0; }                  //used only in Actions, browsing does not use it
+ *      virtual LocationItemDir    * newDir(const QString & dir = QLatin1String(0)) { return 0; } //used only in Actions, browsing does not use it
+ *
+ *      virtual QString     urlBelongsToLocation(const QString& urlPath, int indexOfColonAndSlash)
+ *      {
+ *          // provide some kind of URL parsing for the new protocol, see other implementations
+ *      }
+ *  };
+ *\endcode
+ *
+ *  \sa \ref SmbLocation, \ref SmbItemInfo, \ref SmbLocationDirIterator, \ref SmbLocationItemFile, \ref SmbLocationItemDir,
+ *      \ref SmbLocationAuthentication , \ref NetAuthenticationData and \ref NetAuthenticationDataList
+ */
+
+class NetworkLocation: public Location
+{
+protected:
+    explicit NetworkLocation(int type, QObject *parent=0);
+public:
+     virtual DirListWorker * newListWorker(const QString &urlPath,
+                                          QDir::Filters filter,
+                                          const bool isRecursive);
+};
+
+#endif // NETWORKLOCATION_H

=== modified file 'src/plugin/folderlistmodel/smb/smblocation.cpp'
--- src/plugin/folderlistmodel/smb/smblocation.cpp	2015-12-12 15:47:20 +0000
+++ src/plugin/folderlistmodel/smb/smblocation.cpp	2015-12-12 15:47:20 +0000
@@ -22,7 +22,6 @@
 #include "smblocation.h"
 #include "smbutil.h"
 #include "smbiteminfo.h"
-#include "smblistworker.h"
 #include "smblocationdiriterator.h"
 #include "iorequest.h"
 #include "ioworkerthread.h"
@@ -38,7 +37,7 @@
 #endif
 
 SmbLocation::SmbLocation(int type, QObject *parent)
-     : Location(type, parent)
+     : NetworkLocation(type, parent)
      , SmbLocationAuthentication()
 {
      m_smb = new SmbUtil(suitableAuthenticationFunction());
@@ -89,12 +88,6 @@
 }
 
 
-DirListWorker * SmbLocation::newListWorker(const QString &urlPath, QDir::Filters filter, const bool isRecursive)
-{
-    return new SmbListWorker(urlPath,filter,isRecursive, m_info, m_smb);
-}
-
-
 QString SmbLocation::urlBelongsToLocation(const QString &urlPath, int indexOfColonAndSlash)
 {
     QString ret;

=== modified file 'src/plugin/folderlistmodel/smb/smblocation.h'
--- src/plugin/folderlistmodel/smb/smblocation.h	2015-12-12 15:47:20 +0000
+++ src/plugin/folderlistmodel/smb/smblocation.h	2015-12-12 15:47:20 +0000
@@ -22,12 +22,12 @@
 #ifndef SMBLOCATION_H
 #define SMBLOCATION_H
 
-#include "location.h"
+#include "networklocation.h"
 #include "smblocationauthentication.h"
 #include "smbobject.h"
 
 
-class SmbLocation : public Location, public SmbLocationAuthentication
+class SmbLocation : public NetworkLocation, public SmbLocationAuthentication
 {
     Q_OBJECT
 public:
@@ -36,10 +36,7 @@
 
 public:   
     virtual DirItemInfo * newItemInfo(const QString& urlPath);
-    virtual DirListWorker * newListWorker(const QString &urlPath,
-                                          QDir::Filters filter,
-                                          const bool isRecursive);
-     virtual LocationItemDirIterator * newDirIterator(const QString & path,
+    virtual LocationItemDirIterator * newDirIterator(const QString & path,
                                                       QDir::Filters filters,
                                                       QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags,
                                                       LocationItemDirIterator::LoadMode loadmode = LocationItemDirIterator::LoadOnConstructor);


Follow ups