← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/open-remote-files-01 into lp:ubuntu-filemanager-app

 

Carlos Jose Mazieri has proposed merging lp:~carlos-mazieri/ubuntu-filemanager-app/open-remote-files-01 into lp:ubuntu-filemanager-app.

Commit message:
added a set of download functions, they are basically a "copy" renaming the destination file.

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

For more details, see:
https://code.launchpad.net/~carlos-mazieri/ubuntu-filemanager-app/open-remote-files-01/+merge/276444

Open remote files by downloading them as temporary files and then open when the download finishes.
-- 
Your team Ubuntu File Manager Developers is requested to review the proposed merge of lp:~carlos-mazieri/ubuntu-filemanager-app/open-remote-files-01 into lp:ubuntu-filemanager-app.
=== modified file 'src/plugin/folderlistmodel/filesystemaction.cpp'
--- src/plugin/folderlistmodel/filesystemaction.cpp	2015-08-16 15:16:06 +0000
+++ src/plugin/folderlistmodel/filesystemaction.cpp	2015-11-02 19:15:17 +0000
@@ -267,6 +267,11 @@
     action->targetLocation     =  m_locationsFactory->currentLocation();
     switch (type)
     {
+       case ActionDownload:
+       case ActionDownLoadAsTemporary:
+            action->sourceLocation =  action->targetLocation;
+            action->targetLocation =  m_locationsFactory->getDiskLocation();
+            break;
        case ActionMoveToTrash:
             action->targetLocation = m_locationsFactory->getTrashLocation();
             break;
@@ -334,6 +339,9 @@
     //action->type is top level for all items, entry->type drives item behaviour
     switch(action->type)
     {
+       case ActionDownload:
+       case ActionDownLoadAsTemporary:  entry->type = ActionCopy;
+            break;
        case ActionMoveToTrash:
        case ActionRestoreFromTrash:   entry->type = ActionMove;  //needs create .trashinfo file
             break;
@@ -432,9 +440,13 @@
 void FileSystemAction::processAction()
 {
     if (m_curAction)
-    {        
-            delete m_curAction;
-            m_curAction = 0;
+    {
+        if (m_curAction->done && m_curAction->type == ActionDownLoadAsTemporary)
+        {
+            emit downloadTemporaryComplete(m_curAction->copyFile.targetName);
+        }
+        delete m_curAction;
+        m_curAction = 0;
     }
     if (m_queuedActions.count())
     {
@@ -1457,6 +1469,10 @@
         } while (backuped->exists() && counter < 100);
         if (counter < 100)
         {
+            if (entry->newName)
+            {
+                delete entry->newName; // it no longer will be used
+            }
             entry->newName = new QString(backuped->fileName());
             entry->itemPaths.setTargetFullName( backuped->absoluteFilePath() );
             ret = true;
@@ -1614,3 +1630,53 @@
     //target permission is checked in populateEntry()
     return true;
 }
+
+
+bool FileSystemAction::downloadAsTemporaryFile(const DirItemInfo &remoteFile)
+{
+    QFileInfo f(remoteFile.absoluteFilePath());
+    QString templateName(QDir::tempPath() + QDir::separator() + QLatin1String("XXXXXX.") + f.completeSuffix());
+    QTemporaryFile  temp(templateName);
+    temp.setAutoRemove(false);
+    temp.open();
+    temp.close();
+
+    return createAndProcessDownloadAction(ActionDownLoadAsTemporary, remoteFile, temp.fileName());
+}
+
+
+bool FileSystemAction::downloadAndSaveAs(const DirItemInfo &remoteFile, const QString &fileName)
+{
+    return createAndProcessDownloadAction(ActionDownload, remoteFile, fileName);
+}
+
+
+bool FileSystemAction::createAndProcessDownloadAction(ActionType a, const DirItemInfo &remoteFile, const QString &fileName)
+{
+    bool ret = remoteFile.isRemote() && remoteFile.isFile() && remoteFile.exists();
+    if (ret) //it can be empty
+    {
+        //check if there is enough space to download the file
+        if (!m_locationsFactory->getDiskLocation()->isThereDiskSpace(fileName, remoteFile.size()))
+        {
+            ret = false;
+            m_errorTitle = QObject::tr("There is no space to download");
+            m_errorMsg   =  fileName;
+        }
+    }
+    //peform the copy
+    if (ret)
+    {
+        Action * actionCopy  = createAction(a, remoteFile.absoluteFilePath());
+        ActionPaths pairPaths;
+        QFileInfo info(fileName);
+        pairPaths.setSource(remoteFile.absoluteFilePath());
+        pairPaths.setTargetPathOnly(info.absolutePath());
+        addEntry(actionCopy, pairPaths);
+        ActionEntry *entry = actionCopy->entries.at(0);
+        //it is necessary to se the name, otherwise it copies with same name
+        entry->newName     = new QString(info.fileName());
+        queueAction(actionCopy);
+    }
+    return ret;
+}

=== modified file 'src/plugin/folderlistmodel/filesystemaction.h'
--- src/plugin/folderlistmodel/filesystemaction.h	2015-07-15 16:55:32 +0000
+++ src/plugin/folderlistmodel/filesystemaction.h	2015-11-02 19:15:17 +0000
@@ -112,8 +112,9 @@
     void     moveToTrash(const ActionPathList& pairPaths );
     void     restoreFromTrash(const ActionPathList& pairPaths);
     void     removeFromTrash(const QStringList& paths);
-    void     onClipboardChanged();
-
+    void     onClipboardChanged();   
+    bool     downloadAndSaveAs(const DirItemInfo& remoteFile, const QString& fileName);
+    bool     downloadAsTemporaryFile(const DirItemInfo& remoteFile);
 
 signals:
     void     error(const QString& errorTitle, const QString &errorMessage);
@@ -122,6 +123,7 @@
     void     changed(const DirItemInfo&);
     void     progress(int curItem, int totalItems, int percent);
     void     recopy(const QStringList &names, const QString& path);
+    void     downloadTemporaryComplete(const QString&);
 
 private slots:
     void     processAction();
@@ -146,7 +148,9 @@
        ActionHardMoveRemove,
        ActionMoveToTrash,
        ActionRestoreFromTrash,
-       ActionRemoveFromTrash
+       ActionRemoveFromTrash,
+       ActionDownload,
+       ActionDownLoadAsTemporary
    };
 
    void     createAndProcessAction(ActionType actionType, const QStringList& paths);
@@ -250,6 +254,7 @@
    void     removeTrashInfoFileFromEntry(ActionEntry *entry);
    void     notifyActionOnItem(const DirItemInfo& item, ActionNotification action);
    bool     canMoveItems(Action *action, const QStringList &items);
+   bool     createAndProcessDownloadAction(ActionType a, const DirItemInfo& remoteFile, const QString& fileName);
 
 #if defined(REGRESSION_TEST_FOLDERLISTMODEL) //used in Unit/Regression tests
    bool     m_forceUsingOtherFS;


Follow ups