← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

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

 

Carlos Jose Mazieri has proposed merging lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-01 into lp:ubuntu-filemanager-app.

Commit message:
Clipboard now uses LocationURL class to know which URLs are supported by the file manager.
Added LocationURL::supportedURLs() LocationURL::isSupportedUrl()
New protocols added into File Manager does not require clipboard changes anymore.

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

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

This starts a series of MPs that puts Actions copy/cut/paste/remove/mkdir in place for Samba.
There will be 18 MPs where the "01..17" plus the "final".

Besides putting Samba Actions in place it also prepares others protocols to be easily added without requiring any change in the Actions.

The main idea
============== 
   1. FileSystemAction class (it now could be called FileManagerAction) will NOT use Qt objects directly
   2. Actions will be based in "Source Location" and "Target Location". 
      Example: Copy from "Disk" to "Samba":
         Source Location = DiskLocation class; 
         Target Location = SmbLocation class. 
   3. Each Location will provide its Qt similar objects to perform the Action, they are:
        Qt             Similar object provided by inherited Location classes
        ======================
        QFileInfo      DirItemInfo
        QFile          LocationItemFile
        QDir           LocationItemDir
        QDirIterator   LocationItemDirIterator
-- 
Your team Ubuntu File Manager Developers is requested to review the proposed merge of lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-01 into lp:ubuntu-filemanager-app.
=== added file 'src/app/qml/ui/.directory'
--- src/app/qml/ui/.directory	1970-01-01 00:00:00 +0000
+++ src/app/qml/ui/.directory	2015-07-18 21:15:22 +0000
@@ -0,0 +1,5 @@
+[Dolphin]
+PreviewsShown=true
+Timestamp=2015,7,11,14,49,26
+Version=3
+ViewMode=2

=== modified file 'src/plugin/folderlistmodel/clipboard.cpp'
--- src/plugin/folderlistmodel/clipboard.cpp	2014-10-21 21:20:29 +0000
+++ src/plugin/folderlistmodel/clipboard.cpp	2015-07-18 21:15:22 +0000
@@ -35,6 +35,7 @@
  */
 
 #include "clipboard.h"
+#include "locationurl.h"
 
 #include <QClipboard>
 #include <QApplication>
@@ -189,8 +190,7 @@
  */
 DirModelMimeData::ClipBoardDataOwner
 DirModelMimeData::setIntoClipboard(const QStringList &files, const QString& path, ClipboardOperation operation)
-{
-    static bool firstTime = true;
+{   
     DirModelMimeData::ClipBoardDataOwner  ret = Nobody;
     QClipboard *clipboard = QApplication::clipboard();
     if (clipboard)
@@ -200,6 +200,7 @@
                                                   : new DirModelMimeData();
         if (mime->fillClipboard(files, path, operation))
         {
+            static bool firstTime = true;
             clipboard->setMimeData(mime);
             //it looks like some mobile devices does not have X or Clipboard does work for other reason
             //in this case we simulate our own clipboard, the QClipboard::dataChanged() signal is also
@@ -254,14 +255,24 @@
     QStringList fullPaths = makeFullPath(files, path);
     for(int counter = 0; counter < fullPaths.count(); counter++)
     {
-        QUrl item = QUrl::fromLocalFile(fullPaths.at((counter)));
-        m_urls.append(item);
-        m_gnomeData += QLatin1Char('\n') + item.toEncoded() ;
-    }
-    setData(GNOME_COPIED_MIME_TYPE, m_gnomeData);
-    setUrls(m_urls);
-
-    return true;
+        QUrl item(fullPaths.at((counter)));
+        if (item.scheme().isEmpty() && !item.isLocalFile())
+        {
+            item = QUrl::fromLocalFile(fullPaths.at((counter)));
+        }
+        if (LocationUrl::isSupportedUrl(item))
+        {
+            m_urls.append(item);
+            m_gnomeData += QLatin1Char('\n') + item.toEncoded() ;
+        }
+    }
+    bool ret = m_urls.count() > 0;
+    if (ret)
+    {
+        setData(GNOME_COPIED_MIME_TYPE, m_gnomeData);
+        setUrls(m_urls);
+    }
+    return ret;
 }
 
 //===============================================================================================
@@ -292,11 +303,11 @@
 
 //===============================================================================================
 /*!
- * \brief DirModelMimeData::localUrls
- * \return
+ * \brief DirModelMimeData::storedUrls
+ * \return the list of Urls stored in the Clipboard
  */
 QStringList
-DirModelMimeData::localUrls(ClipboardOperation& operation)
+DirModelMimeData::storedUrls(ClipboardOperation& operation)
 {
      m_appMime = clipboardMimeData();
      QStringList paths;
@@ -315,9 +326,16 @@
          }
          for (int counter=0; counter < urls.count(); counter++)
          {
-             if (urls.at(counter).toString().startsWith(QLatin1String("file://")))
+             if (LocationUrl::isSupportedUrl(urls.at(counter)))
              {
-                 paths.append(urls.at(counter).toLocalFile());
+                 if (urls.at(counter).isLocalFile())
+                 {
+                     paths.append(urls.at(counter).toLocalFile());
+                 }
+                 else
+                 {
+                     paths.append(urls.at(counter).toString());
+                 }
              }
          }
      }
@@ -340,7 +358,7 @@
     bool ret = false;
     ClipboardOperation tmpOperation;
     QStringList expectedList = makeFullPath(files,path);
-    QStringList realList     = localUrls(tmpOperation);
+    QStringList realList     = storedUrls(tmpOperation);
     if (realList == expectedList)
     {
         ret = true;
@@ -354,7 +372,7 @@
 
 //===============================================================================================
 /*!
- * \brief DirModelMimeData::makeFullPath() Just creates a fulpath file list when they do exist
+ * \brief DirModelMimeData::makeFullPath() Just creates a fulpath file list if files are relative
  * \param files
  * \param path
  * \return the list itself
@@ -362,18 +380,19 @@
 QStringList DirModelMimeData::makeFullPath(const QStringList& files, const QString &path)
 {
     QStringList fullPathnameList;
-    QFileInfo fi;
-    for(int counter = 0; counter < files.count(); counter++)
+    if (files.count() > 0)
     {
-        const QString& item = files.at(counter);
-        fi.setFile(item);
-        if (!fi.isAbsolute())
+        if (path.length() > 0 && !files.at(0).startsWith(path))
         {
-            fi.setFile(path + QDir::separator() + item);
+            for(int counter = 0; counter < files.count(); counter++)
+            {
+                fullPathnameList.append(path + QDir::separator() + files.at(counter));
+            }
         }
-        if (fi.exists())
+        else
         {
-            fullPathnameList.append(fi.absoluteFilePath());
+            //they already have a full path
+            fullPathnameList = files;
         }
     }
     return fullPathnameList;
@@ -459,13 +478,13 @@
 
 //=======================================================
 /*!
- * \brief Clipboard::clipboardLocalUrlsCounter
+ * \brief Clipboard::storedUrlsCounter
  * \return
  */
-int Clipboard::clipboardLocalUrlsCounter()
+int Clipboard::storedUrlsCounter()
 {
     ClipboardOperation operation;
-    return m_mimeData->localUrls(operation).count();
+    return m_mimeData->storedUrls(operation).count();
 }
 
 
@@ -477,7 +496,7 @@
  */
 QStringList Clipboard::paste(ClipboardOperation &operation)
 {
-    QStringList items = m_mimeData->localUrls(operation);
+    QStringList items = m_mimeData->storedUrls(operation);
     if (operation == ClipboardCut)
     {
         //this must still be false when cut finishes to change the clipboard to the target

=== modified file 'src/plugin/folderlistmodel/clipboard.h'
--- src/plugin/folderlistmodel/clipboard.h	2014-10-21 21:20:29 +0000
+++ src/plugin/folderlistmodel/clipboard.h	2015-07-18 21:15:22 +0000
@@ -60,7 +60,7 @@
    explicit Clipboard(QObject *parent = 0);
     ~Clipboard();
     QStringList  paste(ClipboardOperation& operation);
-    int          clipboardLocalUrlsCounter();
+    int          storedUrlsCounter();
     inline bool  hasClipboardModifiedByOtherApplication() const {return m_clipboardModifiedByOther;}
 
 public slots:
@@ -108,7 +108,7 @@
                                              const QString &path,
                                              ClipboardOperation operation);
     const QMimeData *       clipboardMimeData();
-    QStringList             localUrls(ClipboardOperation& operation);
+    QStringList             storedUrls(ClipboardOperation& operation);
 
 private:
     static QList<QUrl>      gnomeUrls(const QMimeData *mime, ClipboardOperation& operation);

=== modified file 'src/plugin/folderlistmodel/dirmodel.cpp'
--- src/plugin/folderlistmodel/dirmodel.cpp	2015-06-03 12:38:34 +0000
+++ src/plugin/folderlistmodel/dirmodel.cpp	2015-07-18 21:15:22 +0000
@@ -1229,7 +1229,7 @@
 
 int DirModel::getClipboardUrlsCounter() const
 {
-    return mClipboard->clipboardLocalUrlsCounter();
+    return mClipboard->storedUrlsCounter();
 }
 
 

=== modified file 'src/plugin/folderlistmodel/locationurl.cpp'
--- src/plugin/folderlistmodel/locationurl.cpp	2015-06-28 18:07:28 +0000
+++ src/plugin/folderlistmodel/locationurl.cpp	2015-07-18 21:15:22 +0000
@@ -20,6 +20,7 @@
  */
 
 #include "locationurl.h"
+#include <QUrl>
 
 const QString LocationUrl::UrlIndicator("://");
 
@@ -30,8 +31,35 @@
 #if 0
 QString LocationURL::FishURL("fish:///");
 #endif
-
+                                                              // keep this list ordered
+const QStringList LocationUrl::m_supportedURLs = QStringList() << LocationUrl::CifsURL
+                                                               << LocationUrl::DiskRootURL
+                                                               << LocationUrl::SmbURL
+                                                               << LocationUrl::TrashRootURL
+                                                               ;
 
 LocationUrl::LocationUrl()
 {
+
+}
+
+
+const QStringList& LocationUrl::supportedURLs()
+{
+   return m_supportedURLs;
+}
+
+
+bool LocationUrl::isSupportedUrl(const QUrl &url)
+{
+    bool ret = url.isValid() && url.isLocalFile(); // local files does not need to check
+    if (!ret && !url.scheme().isEmpty())
+    {
+       int counter = m_supportedURLs.count();
+       while (!ret && counter--)
+       {
+           ret = m_supportedURLs.at(counter).startsWith(url.scheme(), Qt::CaseSensitive);
+       }
+    }
+    return ret;
 }

=== modified file 'src/plugin/folderlistmodel/locationurl.h'
--- src/plugin/folderlistmodel/locationurl.h	2015-06-28 18:07:28 +0000
+++ src/plugin/folderlistmodel/locationurl.h	2015-07-18 21:15:22 +0000
@@ -22,7 +22,8 @@
 #ifndef LOCATIONURL_H
 #define LOCATIONURL_H
 
-#include <QString>
+#include <QStringList>
+class QUrl;
 
 class LocationUrl
 {
@@ -35,8 +36,18 @@
 #if 0
     static const   QString FishURL;
 #endif
+    /*!
+     * \brief supportedURLs() Tells which URLs are supported by file manager
+     *
+     *   It may be useful for Clipboard handling
+     *
+     * \return URLs list
+     */
+    static const QStringList&  supportedURLs();
+    static bool                isSupportedUrl(const QUrl& url);
 private:
     LocationUrl();
+    static   const QStringList   m_supportedURLs;
 };
 
 #endif // LOCATIONURL_H


Follow ups