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

Proposed by Carlos Jose Mazieri
Status: Merged
Approved by: Arto Jalkanen
Approved revision: 493
Merged at revision: 494
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/open-remote-files-01
Merge into: lp:ubuntu-filemanager-app
Diff against target: 150 lines (+77/-6)
2 files modified
src/plugin/folderlistmodel/filesystemaction.cpp (+69/-3)
src/plugin/folderlistmodel/filesystemaction.h (+8/-3)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/open-remote-files-01
Reviewer Review Type Date Requested Status
Arto Jalkanen Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Jenkins Bot continuous-integration Approve
Review via email: mp+276444@code.launchpad.net

Commit message

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

Description of the change

Open remote files by downloading them as temporary files and then open when the download finishes.

To post a comment you must log in.
Revision history for this message
Jenkins Bot (ubuntu-core-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Arto Jalkanen (ajalkane) wrote :

Ok,

I'm just a bit worried how to ensure the temporary files do not fill up the space on device and are they eventually removed to avoid that.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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 @@
267 action->targetLocation = m_locationsFactory->currentLocation();267 action->targetLocation = m_locationsFactory->currentLocation();
268 switch (type)268 switch (type)
269 {269 {
270 case ActionDownload:
271 case ActionDownLoadAsTemporary:
272 action->sourceLocation = action->targetLocation;
273 action->targetLocation = m_locationsFactory->getDiskLocation();
274 break;
270 case ActionMoveToTrash:275 case ActionMoveToTrash:
271 action->targetLocation = m_locationsFactory->getTrashLocation();276 action->targetLocation = m_locationsFactory->getTrashLocation();
272 break;277 break;
@@ -334,6 +339,9 @@
334 //action->type is top level for all items, entry->type drives item behaviour339 //action->type is top level for all items, entry->type drives item behaviour
335 switch(action->type)340 switch(action->type)
336 {341 {
342 case ActionDownload:
343 case ActionDownLoadAsTemporary: entry->type = ActionCopy;
344 break;
337 case ActionMoveToTrash:345 case ActionMoveToTrash:
338 case ActionRestoreFromTrash: entry->type = ActionMove; //needs create .trashinfo file346 case ActionRestoreFromTrash: entry->type = ActionMove; //needs create .trashinfo file
339 break;347 break;
@@ -432,9 +440,13 @@
432void FileSystemAction::processAction()440void FileSystemAction::processAction()
433{441{
434 if (m_curAction)442 if (m_curAction)
435 { 443 {
436 delete m_curAction;444 if (m_curAction->done && m_curAction->type == ActionDownLoadAsTemporary)
437 m_curAction = 0;445 {
446 emit downloadTemporaryComplete(m_curAction->copyFile.targetName);
447 }
448 delete m_curAction;
449 m_curAction = 0;
438 }450 }
439 if (m_queuedActions.count())451 if (m_queuedActions.count())
440 {452 {
@@ -1457,6 +1469,10 @@
1457 } while (backuped->exists() && counter < 100);1469 } while (backuped->exists() && counter < 100);
1458 if (counter < 100)1470 if (counter < 100)
1459 {1471 {
1472 if (entry->newName)
1473 {
1474 delete entry->newName; // it no longer will be used
1475 }
1460 entry->newName = new QString(backuped->fileName());1476 entry->newName = new QString(backuped->fileName());
1461 entry->itemPaths.setTargetFullName( backuped->absoluteFilePath() );1477 entry->itemPaths.setTargetFullName( backuped->absoluteFilePath() );
1462 ret = true;1478 ret = true;
@@ -1614,3 +1630,53 @@
1614 //target permission is checked in populateEntry()1630 //target permission is checked in populateEntry()
1615 return true;1631 return true;
1616}1632}
1633
1634
1635bool FileSystemAction::downloadAsTemporaryFile(const DirItemInfo &remoteFile)
1636{
1637 QFileInfo f(remoteFile.absoluteFilePath());
1638 QString templateName(QDir::tempPath() + QDir::separator() + QLatin1String("XXXXXX.") + f.completeSuffix());
1639 QTemporaryFile temp(templateName);
1640 temp.setAutoRemove(false);
1641 temp.open();
1642 temp.close();
1643
1644 return createAndProcessDownloadAction(ActionDownLoadAsTemporary, remoteFile, temp.fileName());
1645}
1646
1647
1648bool FileSystemAction::downloadAndSaveAs(const DirItemInfo &remoteFile, const QString &fileName)
1649{
1650 return createAndProcessDownloadAction(ActionDownload, remoteFile, fileName);
1651}
1652
1653
1654bool FileSystemAction::createAndProcessDownloadAction(ActionType a, const DirItemInfo &remoteFile, const QString &fileName)
1655{
1656 bool ret = remoteFile.isRemote() && remoteFile.isFile() && remoteFile.exists();
1657 if (ret) //it can be empty
1658 {
1659 //check if there is enough space to download the file
1660 if (!m_locationsFactory->getDiskLocation()->isThereDiskSpace(fileName, remoteFile.size()))
1661 {
1662 ret = false;
1663 m_errorTitle = QObject::tr("There is no space to download");
1664 m_errorMsg = fileName;
1665 }
1666 }
1667 //peform the copy
1668 if (ret)
1669 {
1670 Action * actionCopy = createAction(a, remoteFile.absoluteFilePath());
1671 ActionPaths pairPaths;
1672 QFileInfo info(fileName);
1673 pairPaths.setSource(remoteFile.absoluteFilePath());
1674 pairPaths.setTargetPathOnly(info.absolutePath());
1675 addEntry(actionCopy, pairPaths);
1676 ActionEntry *entry = actionCopy->entries.at(0);
1677 //it is necessary to se the name, otherwise it copies with same name
1678 entry->newName = new QString(info.fileName());
1679 queueAction(actionCopy);
1680 }
1681 return ret;
1682}
16171683
=== 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 @@
112 void moveToTrash(const ActionPathList& pairPaths );112 void moveToTrash(const ActionPathList& pairPaths );
113 void restoreFromTrash(const ActionPathList& pairPaths);113 void restoreFromTrash(const ActionPathList& pairPaths);
114 void removeFromTrash(const QStringList& paths);114 void removeFromTrash(const QStringList& paths);
115 void onClipboardChanged();115 void onClipboardChanged();
116116 bool downloadAndSaveAs(const DirItemInfo& remoteFile, const QString& fileName);
117 bool downloadAsTemporaryFile(const DirItemInfo& remoteFile);
117118
118signals:119signals:
119 void error(const QString& errorTitle, const QString &errorMessage);120 void error(const QString& errorTitle, const QString &errorMessage);
@@ -122,6 +123,7 @@
122 void changed(const DirItemInfo&);123 void changed(const DirItemInfo&);
123 void progress(int curItem, int totalItems, int percent);124 void progress(int curItem, int totalItems, int percent);
124 void recopy(const QStringList &names, const QString& path);125 void recopy(const QStringList &names, const QString& path);
126 void downloadTemporaryComplete(const QString&);
125127
126private slots:128private slots:
127 void processAction();129 void processAction();
@@ -146,7 +148,9 @@
146 ActionHardMoveRemove,148 ActionHardMoveRemove,
147 ActionMoveToTrash,149 ActionMoveToTrash,
148 ActionRestoreFromTrash,150 ActionRestoreFromTrash,
149 ActionRemoveFromTrash151 ActionRemoveFromTrash,
152 ActionDownload,
153 ActionDownLoadAsTemporary
150 };154 };
151155
152 void createAndProcessAction(ActionType actionType, const QStringList& paths);156 void createAndProcessAction(ActionType actionType, const QStringList& paths);
@@ -250,6 +254,7 @@
250 void removeTrashInfoFileFromEntry(ActionEntry *entry);254 void removeTrashInfoFileFromEntry(ActionEntry *entry);
251 void notifyActionOnItem(const DirItemInfo& item, ActionNotification action);255 void notifyActionOnItem(const DirItemInfo& item, ActionNotification action);
252 bool canMoveItems(Action *action, const QStringList &items);256 bool canMoveItems(Action *action, const QStringList &items);
257 bool createAndProcessDownloadAction(ActionType a, const DirItemInfo& remoteFile, const QString& fileName);
253258
254#if defined(REGRESSION_TEST_FOLDERLISTMODEL) //used in Unit/Regression tests259#if defined(REGRESSION_TEST_FOLDERLISTMODEL) //used in Unit/Regression tests
255 bool m_forceUsingOtherFS;260 bool m_forceUsingOtherFS;

Subscribers

People subscribed via source and target branches