← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-05 into lp:ubuntu-filemanager-app

 

Carlos Jose Mazieri has proposed merging lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-05 into lp:ubuntu-filemanager-app with lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-04 as a prerequisite.

Commit message:
ntroduces the class SmbItemInfo which represents an Samba Item (folder,files,host,workgroup,share).

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

For more details, see:
https://code.launchpad.net/~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-05/+merge/252974

ntroduces the class SmbItemInfo which represents an Samba Item (folder,files,host,workgroup,share).
-- 
Your team Ubuntu File Manager Developers is requested to review the proposed merge of lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-05 into lp:ubuntu-filemanager-app.
=== modified file 'src/plugin/folderlistmodel/CMakeLists.txt'
--- src/plugin/folderlistmodel/CMakeLists.txt	2015-03-14 17:44:21 +0000
+++ src/plugin/folderlistmodel/CMakeLists.txt	2015-03-14 17:44:21 +0000
@@ -46,7 +46,9 @@
     locationitemdiriterator.cpp
     locationitemdiriterator.h
     cleanurl.cpp
-    cleanurl.h  
+    cleanurl.h
+    urliteminfo.cpp
+    urliteminfo.h
     disk/disklocation.cpp
     disk/disklocation.h
     trash/qtrashdir.cpp
@@ -59,6 +61,10 @@
     trash/trashlocation.h          
     smb/qsambaclient/src/smbutil.cpp
     smb/qsambaclient/src/smbutil.h
+    smb/qsambaclient/src/smbiteminfo.cpp
+    smb/qsambaclient/src/smbiteminfo.h
+    smb/qsambaclient/src/smbobject.cpp
+    smb/qsambaclient/src/smbobject.h
     net/netauthenticationdata.cpp
     net/netauthenticationdata.h  
     net/netutil.cpp

=== modified file 'src/plugin/folderlistmodel/folderlistmodel.pri'
--- src/plugin/folderlistmodel/folderlistmodel.pri	2015-03-14 17:44:21 +0000
+++ src/plugin/folderlistmodel/folderlistmodel.pri	2015-03-14 17:44:21 +0000
@@ -8,7 +8,8 @@
            $$PWD/clipboard.cpp \
            $$PWD/fmutil.cpp \
            $$PWD/dirselection.cpp \
-           $$PWD/diriteminfo.cpp \         
+           $$PWD/diriteminfo.cpp \
+           $$PWD/urliteminfo.cpp \
            $$PWD/location.cpp \
            $$PWD/locationsfactory.cpp \                    
            $$PWD/locationurl.cpp \             
@@ -25,7 +26,9 @@
            $$PWD/clipboard.h \
            $$PWD/fmutil.h  \
            $$PWD/dirselection.h \          
-           $$PWD/diritemabstractlistmodel.h \               
+           $$PWD/diritemabstractlistmodel.h \
+           $$PWD/diriteminfo.h \
+           $$PWD/urliteminfo.h \           
            $$PWD/location.h \
            $$PWD/locationsfactory.h \                   
            $$PWD/locationurl.h \          

=== added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.cpp'
--- src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.cpp	1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.cpp	2015-03-14 17:44:21 +0000
@@ -0,0 +1,167 @@
+/**************************************************************************
+ *
+ * Copyright 2014 Canonical Ltd.
+ * Copyright 2014 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: smbiteminfo.cpp
+ * Date: 08/12/2014
+ */
+
+#include "smbiteminfo.h"
+#include "locationurl.h"
+#include "smbutil.h"
+
+#include <QUrl>
+
+SmbItemInfo::SmbItemInfo() :  UrlItemInfo(), SmbObject(QLatin1String(0))
+{
+
+}
+
+SmbItemInfo::SmbItemInfo(const QString &urlPath, Const_SmbUtil_Ptr smb) :
+   UrlItemInfo(urlPath, LocationUrl::SmbURL)
+  ,SmbObject(urlPath, smb)
+{  
+    if (isValid() && !isRoot())
+    {
+        setInfo(cleanUrl());
+    }
+}
+
+
+SmbItemInfo::~SmbItemInfo()
+{
+
+}
+
+
+void SmbItemInfo::setInfo(const QString& smb_path)
+{   
+    SmbUtil *smb = const_cast<SmbUtil*> (m_smb);
+    struct stat st;
+    int ret  = smb->getStatInfo(smb_path, &st);
+    //lets start with true
+    d_ptr->_exists  = d_ptr->_isReadable = true;
+    switch(ret)
+    {
+    case SmbUtil::StatInvalid:
+    case SmbUtil::StatDoesNotExist:
+         //reset _isHost because it might be set in UrlItemInfo
+         d_ptr->_isHost = false;
+         d_ptr->_exists  = d_ptr->_isReadable = false;
+         break;
+    case SmbUtil::StatDir:              
+        //if directories does not have permissions lets set default
+        //some smb stat functions does not work, this code will not hurt
+        if ((st.st_mode & S_IFMT) == 0)
+        {
+            st.st_mode |= S_IRUSR | S_IWUSR | S_IXUSR |
+                          S_IRGRP | S_IWGRP | S_IXGRP |
+                          S_IROTH | S_IXOTH;
+        }
+        st.st_mode |= S_IFDIR;
+        break;
+    case SmbUtil::StatHost:
+        d_ptr->_isHost = true;
+        break;
+    case SmbUtil::StatShare:
+        d_ptr->_isNetworkShare = true;
+        break;
+    case SmbUtil::StatWorkgroup:
+        d_ptr->_isHost = false;
+        d_ptr->_isWorkGroup = true;
+        break;
+    case SmbUtil::StatNoAccess:
+        //it is special case where the authentication might have failed
+        d_ptr->_isReadable = false;
+        d_ptr->_needsAuthentication = true;
+        break;
+    }
+    //all the information should be in place now
+    fillFromStatBuf(st);    
+}
+
+
+QString SmbItemInfo::authenticationPath() const
+{
+    return sharePath();
+}
+
+/*!
+ * \brief SmbItemInfo::sharePath() returns the share part of the item
+ * \return NULL if the item is root
+ */
+QString SmbItemInfo::sharePath() const
+{
+    QString share;
+    if (isWorkGroup() || isHost() || isShare())
+    {
+           share = absoluteFilePath();
+    }
+    else
+    if (!isRoot())
+    {
+        //0 1 2 3 4 6
+        //s m b : / /    smb://host/share[/dir]
+        int slashIndex = 6;
+        int found = 0;
+        QString fullpath(absoluteFilePath());
+        for (; found < 2 && slashIndex != -1; ++found)
+        {
+            slashIndex = fullpath.indexOf(QDir::separator(), slashIndex +1);
+        }
+        switch(found)
+        {
+          case 1: share = fullpath; break;
+          case 2: share = fullpath.left(slashIndex); break;
+          default: break;
+        }
+    }
+    return share;
+}
+
+
+void SmbItemInfo::setFile(const QString &dir, const QString &file)
+{
+    QString smb_path;
+    if (dir.startsWith(LocationUrl::SmbURL))
+    {
+        smb_path = dir;
+    }
+    else
+    {
+        QUrl url(urlPath());
+        QFileInfo f(url.path() + QDir::separator() + dir);
+        url.setPath(f.canonicalFilePath());
+        smb_path = url.toString();
+    }
+    smb_path += QDir::separator() + file;
+    SmbItemInfo *other  = new SmbItemInfo( LocationUrl::SmbURL + DirItemInfo::removeExtraSlashes(smb_path),
+                                           m_smb);
+    if (other->isValid())
+    {
+        *this = *other;
+    }
+    else
+    {
+        delete other;
+    }
+}
+
+
+void SmbItemInfo::setAsShare()
+{
+    d_ptr->_isNetworkShare = true;
+}

=== added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.h'
--- src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.h	1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbiteminfo.h	2015-03-14 17:44:21 +0000
@@ -0,0 +1,52 @@
+/**************************************************************************
+ *
+ * Copyright 2014 Canonical Ltd.
+ * Copyright 2014 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: smbiteminfo.h
+ * Date: 08/12/2014
+ */
+
+#ifndef SMBITEMINFO_H
+#define SMBITEMINFO_H
+
+#include "urliteminfo.h"
+#include "smbobject.h"
+
+class QUrl;
+
+class SmbItemInfo : public UrlItemInfo, public SmbObject
+{
+public:
+    /*!
+     * \brief SmbItemInfo
+     * \param urlPath  a url
+     * \param smb   an instance of \ref SmbUtil that has an authentication callback already set
+     */
+    SmbItemInfo(const QString& urlPath, Const_SmbUtil_Ptr  smb  = 0);
+    SmbItemInfo();
+    ~SmbItemInfo();
+
+public:
+    QString          sharePath() const;
+    void             setAsShare();
+    virtual QString  authenticationPath() const;
+    virtual void     setFile(const QString &dir, const QString & file);
+
+protected:    
+     void            setInfo(const QString &smb_path);
+};
+
+#endif // SMBITEMINFO_H

=== added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbobject.cpp'
--- src/plugin/folderlistmodel/smb/qsambaclient/src/smbobject.cpp	1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbobject.cpp	2015-03-14 17:44:21 +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: smbobject.cpp
+ * Date: 02/01/2015
+ */
+
+#include "smbobject.h"
+#include "smbutil.h"
+
+#include <QUrl>
+
+SmbObject::SmbObject(const QString &urlPath, Const_SmbUtil_Ptr smb)
+  : CleanUrl(urlPath), m_smb(smb), m_smbOwnInstance(0)
+{
+    if (m_smb == 0)
+    {
+        m_smb = m_smbOwnInstance = new SmbUtil(cleanUrl());
+    }    
+}
+
+
+SmbObject::~SmbObject()
+{
+    if (m_smbOwnInstance != 0)
+    {
+        delete m_smbOwnInstance;
+        m_smbOwnInstance = 0;
+    }
+}
+
+
+SmbUtil_Ptr SmbObject::smbObj() const
+{
+    return const_cast<SmbUtil_Ptr>(m_smb);
+}

=== added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbobject.h'
--- src/plugin/folderlistmodel/smb/qsambaclient/src/smbobject.h	1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbobject.h	2015-03-14 17:44:21 +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: smbobject.h
+ * Date: 02/01/2015
+ */
+
+#ifndef SMBOBJECT_H
+#define SMBOBJECT_H
+
+#include "cleanurl.h"
+
+#include <QString>
+
+class SmbUtil;
+typedef SmbUtil const * Const_SmbUtil_Ptr;
+typedef SmbUtil       * SmbUtil_Ptr;
+
+class SmbObject : public CleanUrl
+{
+protected:
+    SmbObject(const QString &urlPath, Const_SmbUtil_Ptr smb = 0);
+    SmbUtil_Ptr     smbObj() const;
+public:
+    virtual ~SmbObject();
+protected:
+    Const_SmbUtil_Ptr   m_smb;
+    SmbUtil_Ptr         m_smbOwnInstance; //!<  not zero only if smb == 0
+};
+
+#endif // SMBOBJECT_H

=== added file 'src/plugin/folderlistmodel/urliteminfo.cpp'
--- src/plugin/folderlistmodel/urliteminfo.cpp	1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/urliteminfo.cpp	2015-03-14 17:44:21 +0000
@@ -0,0 +1,139 @@
+/**************************************************************************
+ *
+ * Copyright 2014 Canonical Ltd.
+ * Copyright 2014 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: urliteminfo.cpp
+ * Date: 08/12/2014
+ */
+
+#include "urliteminfo.h"
+
+#include <QUrl>
+
+UrlItemInfo::UrlItemInfo():    DirItemInfo()
+{
+
+}
+
+UrlItemInfo::UrlItemInfo(const QString& urlPath, const QString& urlRoot):
+     DirItemInfo()
+{
+    if (urlPath == urlRoot)
+    {
+        setRoot(urlPath);
+    }
+    else
+    {
+        if (!urlPath.startsWith(urlRoot))
+        {
+            d_ptr->_isValid    = false;
+            d_ptr->_isAbsolute = false;
+        }
+        else
+        {
+             init(urlPath);
+        }
+    }
+
+}
+
+
+void UrlItemInfo::setRoot(const QString& urlPath)
+{
+    d_ptr->_isValid      = true;
+    d_ptr->_isRoot       = true;
+    d_ptr->_isDir        = true;
+    d_ptr->_isReadable   = true;
+    d_ptr->_isExecutable = true;
+    d_ptr->_exists       = true;
+    d_ptr->_isAbsolute   = true;
+    d_ptr->_isRemote     = true;
+    d_ptr->_fileName.clear();
+    d_ptr->_path         = urlPath;
+    d_ptr->_normalizedPath = d_ptr->_path;
+}
+
+
+/*!
+ * \brief UrlItemInfo::init() fill basic item information
+ *
+ * It is supposed the URL does contain duplicates slashes
+ *
+ * \param urlPath
+ */
+void UrlItemInfo::init(const QString& urlPath)
+{    
+    d_ptr->_isValid      = true;
+    d_ptr->_isAbsolute   = true;
+    d_ptr->_isRemote     = true;
+
+    //veryfy if the item is a host
+    verifyHost(urlPath);
+
+    QStringList pathAndFile = separatePathFilename(urlPath);
+    if (pathAndFile.count() == 2)
+    {
+        d_ptr->_path     = pathAndFile.at(0);
+        d_ptr->_fileName = pathAndFile.at(1);
+    }
+    else
+    {
+        d_ptr->_path           = urlPath;    
+    }
+    d_ptr->_normalizedPath = d_ptr->_path;
+}
+
+
+void UrlItemInfo::verifyHost(const QString urlPath)
+{
+    QUrl url(urlPath);
+    if (url.isValid() && !url.isLocalFile())
+    {       
+        if (url.path().isEmpty())
+        {
+            //!< initial set is "host", Samba shares also have Workspace which will be handled in \ref SmbItemInfo
+            d_ptr->_isHost = true;
+            //set as it exists so far
+            d_ptr->_exists = true;
+            d_ptr->_isReadable   = true;
+            d_ptr->_isExecutable = true;
+        }
+    }
+}
+
+
+/*!
+ * \brief UrlItemInfo::separatePathFilename()
+ * \param urlPath
+ * \return [0]=path [1]=filename when it exists
+ */
+QStringList UrlItemInfo::separatePathFilename(const QString &urlPath)
+{
+    QStringList separated;
+    int lastDir = urlPath.lastIndexOf(QDir::separator());
+    //path and filename must fill the url,
+    // smb://localost      path=smb://          filename=localhost
+    // smb://localhost/dir path=smb://localhost filename=dir
+    if (lastDir != -1)
+    {
+        QString path = urlPath.at(lastDir-1)  == QDir::separator() ?
+                       urlPath.left(lastDir+1) : urlPath.left(lastDir);
+
+        separated.append(path);
+        separated.append(urlPath.mid(lastDir + 1));
+    }
+    return separated;
+}

=== added file 'src/plugin/folderlistmodel/urliteminfo.h'
--- src/plugin/folderlistmodel/urliteminfo.h	1970-01-01 00:00:00 +0000
+++ src/plugin/folderlistmodel/urliteminfo.h	2015-03-14 17:44:21 +0000
@@ -0,0 +1,53 @@
+/**************************************************************************
+ *
+ * Copyright 2014 Canonical Ltd.
+ * Copyright 2014 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: urliteminfo.h
+ * Date: 08/12/2014
+ */
+
+#ifndef URLITEMINFO_H
+#define URLITEMINFO_H
+
+#include "diriteminfo.h"
+
+
+/*!
+ * \brief The UrlItemInfo is an abstract class that provides URL root
+ *
+ *  Basically it differs from DirItemInfo in the field \a d_ptr->_normalizedPath, it must store the
+ *  url like trash:///Item, while the field d_ptr->_path stores the current path in the file system as usual.
+ *
+ */
+
+class UrlItemInfo : public DirItemInfo
+{
+public:
+    static QStringList separatePathFilename(const QString& urlPath);
+protected:
+    UrlItemInfo(const QString& urlPath, const QString& urlRoot);
+    UrlItemInfo();
+
+protected:
+    void               setRoot(const QString& urlRoot);
+
+
+private:
+    void    init(const QString& urlPath);
+    void    verifyHost(const QString urlPath);
+};
+
+#endif // URLITEMINFO_H


Follow ups