ubuntu-touch-coreapps-reviewers team mailing list archive
-
ubuntu-touch-coreapps-reviewers team
-
Mailing list archive
-
Message #03652
[Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-08 into lp:ubuntu-filemanager-app
Carlos Jose Mazieri has proposed merging lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-08 into lp:ubuntu-filemanager-app with lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-07 as a prerequisite.
Commit message:
Object LocationItemDirIterator is created by Location classes, it will replace Qt Object QDirIterator in Actions.
Requested reviews:
Ubuntu File Manager Developers (ubuntu-filemanager-dev)
For more details, see:
https://code.launchpad.net/~carlos-mazieri/ubuntu-filemanager-app/samba-actions-08/+merge/265199
Location class improved:
* Created Location::urlBelongsToLocation() to be used in LocationsFactory::parse()
It avoids big changes in the LocationsFactory when adding new protocols to File Manager
* Added creation of LocationItemDirIterator object which is similar to Qt QDirIterator object
--
Your team Ubuntu File Manager Developers is requested to review the proposed merge of lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-08 into lp:ubuntu-filemanager-app.
=== modified file 'src/plugin/folderlistmodel/CMakeLists.txt'
--- src/plugin/folderlistmodel/CMakeLists.txt 2015-06-20 15:15:44 +0000
+++ src/plugin/folderlistmodel/CMakeLists.txt 2015-07-18 22:03:45 +0000
@@ -51,6 +51,8 @@
urliteminfo.h
disk/disklocation.cpp
disk/disklocation.h
+ disk/disklocationitemdiriterator.cpp
+ disk/disklocationitemdiriterator.h
trash/qtrashdir.cpp
trash/qtrashdir.h
trash/qtrashutilinfo.cpp
=== modified file 'src/plugin/folderlistmodel/disk/disklocation.cpp'
--- src/plugin/folderlistmodel/disk/disklocation.cpp 2015-03-01 15:32:42 +0000
+++ src/plugin/folderlistmodel/disk/disklocation.cpp 2015-07-18 22:03:45 +0000
@@ -20,9 +20,16 @@
*/
#include "disklocation.h"
+#include "disklocationitemdiriterator.h"
#include "iorequest.h"
#include "ioworkerthread.h"
#include "externalfswatcher.h"
+#include "locationurl.h"
+
+
+#if defined(Q_OS_UNIX)
+#include <sys/statvfs.h>
+#endif
#include <QDebug>
@@ -168,3 +175,37 @@
return new DirListWorker(urlPath,filter,isRecursive);
}
+
+QString DiskLocation::urlBelongsToLocation(const QString &urlPath, int indexOfColonAndSlashe)
+{
+ QString ret;
+ if (urlPath.startsWith(LocationUrl::DiskRootURL.midRef(0,5)))
+ {
+ ret = QDir::rootPath() + DirItemInfo::removeExtraSlashes(urlPath, indexOfColonAndSlashe+1);
+ }
+ return ret;
+}
+
+
+LocationItemDirIterator *
+DiskLocation::newDirIterator(const QString &path,
+ QDir::Filters filters,
+ QDirIterator::IteratorFlags flags)
+{
+ return new DiskLocationItemDirIterator(path, filters, flags);
+}
+
+
+bool DiskLocation::isThereDiskSpace(const QString &pathname, qint64 requiredSize)
+{
+ bool ret = true;
+#if defined(Q_OS_UNIX)
+ struct statvfs vfs;
+ if ( ::statvfs( QFile::encodeName(pathname).constData(), &vfs) == 0 )
+ {
+ qint64 free = vfs.f_bsize * vfs.f_bfree;
+ ret = free > requiredSize;
+ }
+#endif
+ return ret;
+}
=== modified file 'src/plugin/folderlistmodel/disk/disklocation.h'
--- src/plugin/folderlistmodel/disk/disklocation.h 2015-03-01 15:32:42 +0000
+++ src/plugin/folderlistmodel/disk/disklocation.h 2015-07-18 22:03:45 +0000
@@ -63,6 +63,11 @@
virtual DirListWorker * newListWorker(const QString &urlPath,
QDir::Filter filter,
const bool isRecursive);
+ virtual LocationItemDirIterator * newDirIterator(const QString & path,
+ QDir::Filters filters,
+ QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
+ virtual bool isThereDiskSpace(const QString& pathname, qint64 requiredSize);
+ virtual QString urlBelongsToLocation(const QString& urlPath, int indexOfColonAndSlashe);
protected:
void addExternalFsWorkerRequest(ExternalFileSystemChangesWorker *);
=== added file 'src/plugin/folderlistmodel/disk/disklocationitemdiriterator.cpp'
--- src/plugin/folderlistmodel/disk/disklocationitemdiriterator.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/disk/disklocationitemdiriterator.cpp 2015-07-18 22:03:45 +0000
@@ -0,0 +1,94 @@
+/**************************************************************************
+ *
+ * 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: disklocationitemdiriterator.cpp
+ * Date: 29/03/2015
+ */
+
+#include "disklocationitemdiriterator.h"
+
+#include <QDirIterator>
+
+DiskLocationItemDirIterator::DiskLocationItemDirIterator(const QString &path,
+ const QStringList &nameFilters,
+ QDir::Filters filters,
+ QDirIterator::IteratorFlags flags)
+ : LocationItemDirIterator(path,nameFilters,filters,flags)
+ , m_qtDirIterator(new QDirIterator(path, nameFilters, filters, flags))
+{
+
+}
+
+DiskLocationItemDirIterator::DiskLocationItemDirIterator(const QString &path,
+ QDir::Filters filters,
+ QDirIterator::IteratorFlags flags)
+
+ : LocationItemDirIterator(path,filters,flags)
+ , m_qtDirIterator(new QDirIterator(path,filters, flags))
+{
+
+}
+
+DiskLocationItemDirIterator::DiskLocationItemDirIterator(const QString &path,
+ QDirIterator::IteratorFlags flags)
+ : LocationItemDirIterator(path,flags)
+ , m_qtDirIterator(new QDirIterator(path, flags))
+{
+
+}
+
+DiskLocationItemDirIterator::~DiskLocationItemDirIterator()
+{
+ delete m_qtDirIterator;
+}
+
+
+DirItemInfo DiskLocationItemDirIterator::fileInfo() const
+{
+ DirItemInfo itemInfo (m_qtDirIterator->fileInfo());
+ return itemInfo;
+}
+
+
+QString DiskLocationItemDirIterator::fileName() const
+{
+ return m_qtDirIterator->fileName();
+}
+
+
+QString DiskLocationItemDirIterator::filePath() const
+{
+ return m_qtDirIterator->filePath();
+}
+
+
+bool DiskLocationItemDirIterator::hasNext() const
+{
+ return m_qtDirIterator->hasNext();
+}
+
+
+QString DiskLocationItemDirIterator::next()
+{
+ return m_qtDirIterator->next();
+}
+
+
+QString DiskLocationItemDirIterator::path() const
+{
+ return m_qtDirIterator->path();
+}
=== added file 'src/plugin/folderlistmodel/disk/disklocationitemdiriterator.h'
--- src/plugin/folderlistmodel/disk/disklocationitemdiriterator.h 1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/disk/disklocationitemdiriterator.h 2015-07-18 22:03:45 +0000
@@ -0,0 +1,50 @@
+/**************************************************************************
+ *
+ * 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: disklocationitemdiriterator.h
+ * Date: 29/03/2015
+ */
+
+#ifndef DISKLOCATIONITEMDIRITERATOR_H
+#define DISKLOCATIONITEMDIRITERATOR_H
+
+#include "locationitemdiriterator.h"
+
+class QDirIterator;
+
+class DiskLocationItemDirIterator : public LocationItemDirIterator
+{
+public:
+ explicit DiskLocationItemDirIterator(QObject *parent = 0);
+ ~DiskLocationItemDirIterator();
+public:
+ virtual DirItemInfo fileInfo() const;
+ virtual QString fileName() const;
+ virtual QString filePath() const;
+ virtual bool hasNext() const;
+ virtual QString next() ;
+ virtual QString path() const;
+public:
+ DiskLocationItemDirIterator(const QString & path, QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
+ DiskLocationItemDirIterator(const QString & path, QDir::Filters filters, QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
+ DiskLocationItemDirIterator(const QString & path, const QStringList & nameFilters, QDir::Filters filters = QDir::NoFilter, QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
+private:
+ QDirIterator * m_qtDirIterator;
+
+};
+
+#endif // DISKLOCATIONITEMDIRITERATOR_H
=== modified file 'src/plugin/folderlistmodel/folderlistmodel.pri'
--- src/plugin/folderlistmodel/folderlistmodel.pri 2015-06-03 11:54:36 +0000
+++ src/plugin/folderlistmodel/folderlistmodel.pri 2015-07-18 22:03:45 +0000
@@ -14,7 +14,10 @@
$$PWD/locationsfactory.cpp \
$$PWD/locationurl.cpp \
$$PWD/locationitemdiriterator.cpp \
- $$PWD/cleanurl.cpp
+ $$PWD/cleanurl.cpp \
+ $$PWD/disk/disklocationitemdiriterator.cpp \
+
+
HEADERS += $$PWD/dirmodel.h \
$$PWD/iorequest.h \
@@ -33,7 +36,9 @@
$$PWD/locationsfactory.h \
$$PWD/locationurl.h \
$$PWD/locationitemdiriterator.h \
- $$PWD/cleanurl.h
+ $$PWD/cleanurl.h \
+ $$PWD/disk/disklocationitemdiriterator.h \
+
SOURCES += $$PWD/disk/disklocation.cpp
HEADERS += $$PWD/disk/disklocation.h
=== modified file 'src/plugin/folderlistmodel/location.h'
--- src/plugin/folderlistmodel/location.h 2015-07-18 22:03:45 +0000
+++ src/plugin/folderlistmodel/location.h 2015-07-18 22:03:45 +0000
@@ -25,9 +25,12 @@
#include "diriteminfo.h"
#include <QObject>
+#include <QDirIterator>
class IOWorkerThread;
class DirListWorker;
+class LocationItemDirIterator;
+
/*!
* \brief The Location class represents any location (full path) where there are items to browse: directories, shares, from Disk and from Network.
@@ -109,6 +112,41 @@
*/
virtual DirListWorker * newListWorker(const QString &urlPath, QDir::Filter filter, const bool isRecursive) = 0;
+ /*!
+ * \brief newDirIterator() creates a LocationItemDirIterator object which is similar to Qt QDirIterator object
+ *
+ * It will be used to create a recursive list of items in copy/cut/paste/remove Actions
+ * It can used in DirListWorker as well
+ * \param path
+ * \param flags
+ * \return
+ */
+ virtual LocationItemDirIterator * newDirIterator(const QString & path,
+ QDir::Filters filters,
+ QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags) = 0;
+
+
+ /*!
+ * \brief urlBelongsToLocation() Returns a good url if the \a urlPath is valid URL that belongs to its location
+ *
+ * If the URL or Path in \a urlPath is valid and belongs to its location
+ *
+ * \param urlPath The input URL that is going to be parsed
+ * \param indexOfColonAndSlashe The index of ":/"
+ * \return The good URL (parsed with extra slashes removed)
+ * or an empty string if \a urlPath does not belong to its location
+ *
+ *Example regarding samba where both "cifs://" and "smb://" urls are supported
+ * \code"
+ * For a urlPath like: "cifs://localhost/share/"
+ * The return will be: "smb://localhost/share" -> "cifs" changed by "smb" and last slash removed
+ *
+ * For a urlPath like: "trash:///"
+ * The return will be: an empty string meaning that this URL is not related to Samba
+ *\endcode
+ */
+ virtual QString urlBelongsToLocation(const QString& urlPath, int indexOfColonAndSlashe) = 0;
+
public:
/*!
* \brief isThereDiskSpace() Check if the filesystem has enough space to put a file with size \a requiredSize
=== modified file 'src/plugin/folderlistmodel/locationsfactory.cpp'
--- src/plugin/folderlistmodel/locationsfactory.cpp 2015-07-18 22:03:45 +0000
+++ src/plugin/folderlistmodel/locationsfactory.cpp 2015-07-18 22:03:45 +0000
@@ -80,29 +80,15 @@
Location * location = 0;
if ( (index = uPath.indexOf(LocationUrl::UrlIndicator)) != -1 )
{
-#if defined(Q_OS_WIN)
-#else
-#if defined(Q_OS_UNIX)
- if (uPath.startsWith(LocationUrl::TrashRootURL.midRef(0,6)))
- {
- type = Location::TrashDisk;
- m_tmpPath = LocationUrl::TrashRootURL + DirItemInfo::removeExtraSlashes(uPath, index+1);
- }
- else
-#endif //Q_OS_UNIX
-#endif
- if (uPath.startsWith(LocationUrl::DiskRootURL.midRef(0,5)))
- {
- type = Location::LocalDisk;
- m_tmpPath = QDir::rootPath() + DirItemInfo::removeExtraSlashes(uPath, index+1);
- }
- else
- if ( uPath.startsWith(LocationUrl::SmbURL.midRef(0,4)) ||
- uPath.startsWith(LocationUrl::CifsURL.midRef(0,5))
- )
- {
- type = Location::NetSambaShare;
- m_tmpPath = LocationUrl::SmbURL + DirItemInfo::removeExtraSlashes(uPath, index+1);
+ int counter = m_locations.count();
+ while (counter--)
+ {
+ m_tmpPath = m_locations.at(counter)->urlBelongsToLocation(uPath, index);
+ if (!m_tmpPath.isEmpty())
+ {
+ type = m_locations.at(counter)->type();
+ break;
+ }
}
}
else
=== modified file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.cpp'
--- src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.cpp 2015-03-14 17:38:50 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.cpp 2015-07-18 22:03:45 +0000
@@ -50,7 +50,9 @@
void SmbItemInfo::setInfo(const QString& smb_path)
{
SmbUtil *smb = const_cast<SmbUtil*> (m_smb);
+ //getStatInfo() is supposed to clear the struct stat unless the item does not exist
struct stat st;
+ ::memset(&st, 0, sizeof(struct stat));
int ret = smb->getStatInfo(smb_path, &st);
//lets start with true
d_ptr->_exists = d_ptr->_isReadable = true;
=== modified file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationdiriterator.cpp'
--- src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationdiriterator.cpp 2015-05-20 16:18:07 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smblocationdiriterator.cpp 2015-07-18 22:03:45 +0000
@@ -60,7 +60,7 @@
, INIT_ATTR(path, smb)
{
bool recursive = flags == QDirIterator::Subdirectories ? true : false;
- m_urlItems = smbObj()->listContent(path, recursive);
+ m_urlItems = smbObj()->listContent(path, recursive, QDir::NoFilter);
}
=== modified file 'src/plugin/folderlistmodel/smb/smblocation.cpp'
--- src/plugin/folderlistmodel/smb/smblocation.cpp 2015-03-14 18:20:15 +0000
+++ src/plugin/folderlistmodel/smb/smblocation.cpp 2015-07-18 22:03:45 +0000
@@ -23,8 +23,16 @@
#include "smbutil.h"
#include "smbiteminfo.h"
#include "smblistworker.h"
+#include "smblocationdiriterator.h"
#include "iorequest.h"
#include "ioworkerthread.h"
+#include "locationurl.h"
+
+
+
+#if defined(Q_OS_UNIX)
+#include <sys/statvfs.h>
+#endif
SmbLocation::SmbLocation(int type, QObject *parent)
: Location(type, parent)
@@ -82,3 +90,41 @@
return new SmbListWorker(urlPath,filter,isRecursive, m_info ? m_info->isHost() : false, m_smb);
}
+
+QString SmbLocation::urlBelongsToLocation(const QString &urlPath, int indexOfColonAndSlashe)
+{
+ QString ret;
+ if ( urlPath.startsWith(LocationUrl::SmbURL.midRef(0,4)) ||
+ urlPath.startsWith(LocationUrl::CifsURL.midRef(0,5))
+ )
+ {
+ ret = LocationUrl::SmbURL + DirItemInfo::removeExtraSlashes(urlPath, indexOfColonAndSlashe+1);
+ }
+ return ret;
+}
+
+
+LocationItemDirIterator *
+SmbLocation::newDirIterator(const QString &path,
+ QDir::Filters filters,
+ QDirIterator::IteratorFlags flags)
+{
+ return new SmbLocationDirIterator(path, filters, flags, m_smb);
+}
+
+
+bool SmbLocation::isThereDiskSpace(const QString &pathname, qint64 requiredSize)
+{
+ bool ret = false;
+#if defined(Q_OS_UNIX)
+ struct statvfs st;
+ if (m_smb->getStatvfsInfo(pathname, &st) == SmbUtil::StatDone)
+ {
+ qint64 free = st.f_bsize * st.f_bfree;
+ ret = free > requiredSize;
+ }
+#else
+ ret = true;
+#endif
+ return ret;
+}
=== modified file 'src/plugin/folderlistmodel/smb/smblocation.h'
--- src/plugin/folderlistmodel/smb/smblocation.h 2015-03-14 18:20:15 +0000
+++ src/plugin/folderlistmodel/smb/smblocation.h 2015-07-18 22:03:45 +0000
@@ -39,6 +39,11 @@
virtual DirListWorker * newListWorker(const QString &urlPath,
QDir::Filter filter,
const bool isRecursive);
+ virtual LocationItemDirIterator * newDirIterator(const QString & path,
+ QDir::Filters filters,
+ QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags);
+ virtual bool isThereDiskSpace(const QString& pathname, qint64 requiredSize);
+ virtual QString urlBelongsToLocation(const QString& urlPath, int indexOfColonAndSlashe);
virtual QString currentAuthenticationUser();
virtual QString currentAuthenticationPassword();
=== modified file 'src/plugin/folderlistmodel/smb/smblocationauthentication.cpp'
--- src/plugin/folderlistmodel/smb/smblocationauthentication.cpp 2015-04-29 23:23:31 +0000
+++ src/plugin/folderlistmodel/smb/smblocationauthentication.cpp 2015-07-18 22:03:45 +0000
@@ -30,12 +30,10 @@
# define DEBUG_AUTHENTICATION() /**/
#endif
-namespace
-{
- QByteArray m_AuthUser[MAX_AUTH_INSTANCES];
- QByteArray m_AuthPass[MAX_AUTH_INSTANCES];
- void * m_instances[MAX_AUTH_INSTANCES];
-}
+
+static QByteArray m_AuthUser[MAX_AUTH_INSTANCES];
+static QByteArray m_AuthPass[MAX_AUTH_INSTANCES];
+static void * m_instances[MAX_AUTH_INSTANCES];
SmbLocationAuthentication::SmbLocationAuthentication() : m_infoIndex(-1)
{
Follow ups