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

Proposed by Carlos Jose Mazieri on 2015-11-02
Status: Merged
Approved by: Arto Jalkanen on 2015-11-03
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 2015-11-02 Approve on 2015-11-03
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve on 2015-11-02
Jenkins Bot continuous-integration Approve on 2015-11-02
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.
review: Approve (continuous-integration)
review: Approve (continuous-integration)
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
1=== modified file 'src/plugin/folderlistmodel/filesystemaction.cpp'
2--- src/plugin/folderlistmodel/filesystemaction.cpp 2015-08-16 15:16:06 +0000
3+++ src/plugin/folderlistmodel/filesystemaction.cpp 2015-11-02 19:15:17 +0000
4@@ -267,6 +267,11 @@
5 action->targetLocation = m_locationsFactory->currentLocation();
6 switch (type)
7 {
8+ case ActionDownload:
9+ case ActionDownLoadAsTemporary:
10+ action->sourceLocation = action->targetLocation;
11+ action->targetLocation = m_locationsFactory->getDiskLocation();
12+ break;
13 case ActionMoveToTrash:
14 action->targetLocation = m_locationsFactory->getTrashLocation();
15 break;
16@@ -334,6 +339,9 @@
17 //action->type is top level for all items, entry->type drives item behaviour
18 switch(action->type)
19 {
20+ case ActionDownload:
21+ case ActionDownLoadAsTemporary: entry->type = ActionCopy;
22+ break;
23 case ActionMoveToTrash:
24 case ActionRestoreFromTrash: entry->type = ActionMove; //needs create .trashinfo file
25 break;
26@@ -432,9 +440,13 @@
27 void FileSystemAction::processAction()
28 {
29 if (m_curAction)
30- {
31- delete m_curAction;
32- m_curAction = 0;
33+ {
34+ if (m_curAction->done && m_curAction->type == ActionDownLoadAsTemporary)
35+ {
36+ emit downloadTemporaryComplete(m_curAction->copyFile.targetName);
37+ }
38+ delete m_curAction;
39+ m_curAction = 0;
40 }
41 if (m_queuedActions.count())
42 {
43@@ -1457,6 +1469,10 @@
44 } while (backuped->exists() && counter < 100);
45 if (counter < 100)
46 {
47+ if (entry->newName)
48+ {
49+ delete entry->newName; // it no longer will be used
50+ }
51 entry->newName = new QString(backuped->fileName());
52 entry->itemPaths.setTargetFullName( backuped->absoluteFilePath() );
53 ret = true;
54@@ -1614,3 +1630,53 @@
55 //target permission is checked in populateEntry()
56 return true;
57 }
58+
59+
60+bool FileSystemAction::downloadAsTemporaryFile(const DirItemInfo &remoteFile)
61+{
62+ QFileInfo f(remoteFile.absoluteFilePath());
63+ QString templateName(QDir::tempPath() + QDir::separator() + QLatin1String("XXXXXX.") + f.completeSuffix());
64+ QTemporaryFile temp(templateName);
65+ temp.setAutoRemove(false);
66+ temp.open();
67+ temp.close();
68+
69+ return createAndProcessDownloadAction(ActionDownLoadAsTemporary, remoteFile, temp.fileName());
70+}
71+
72+
73+bool FileSystemAction::downloadAndSaveAs(const DirItemInfo &remoteFile, const QString &fileName)
74+{
75+ return createAndProcessDownloadAction(ActionDownload, remoteFile, fileName);
76+}
77+
78+
79+bool FileSystemAction::createAndProcessDownloadAction(ActionType a, const DirItemInfo &remoteFile, const QString &fileName)
80+{
81+ bool ret = remoteFile.isRemote() && remoteFile.isFile() && remoteFile.exists();
82+ if (ret) //it can be empty
83+ {
84+ //check if there is enough space to download the file
85+ if (!m_locationsFactory->getDiskLocation()->isThereDiskSpace(fileName, remoteFile.size()))
86+ {
87+ ret = false;
88+ m_errorTitle = QObject::tr("There is no space to download");
89+ m_errorMsg = fileName;
90+ }
91+ }
92+ //peform the copy
93+ if (ret)
94+ {
95+ Action * actionCopy = createAction(a, remoteFile.absoluteFilePath());
96+ ActionPaths pairPaths;
97+ QFileInfo info(fileName);
98+ pairPaths.setSource(remoteFile.absoluteFilePath());
99+ pairPaths.setTargetPathOnly(info.absolutePath());
100+ addEntry(actionCopy, pairPaths);
101+ ActionEntry *entry = actionCopy->entries.at(0);
102+ //it is necessary to se the name, otherwise it copies with same name
103+ entry->newName = new QString(info.fileName());
104+ queueAction(actionCopy);
105+ }
106+ return ret;
107+}
108
109=== modified file 'src/plugin/folderlistmodel/filesystemaction.h'
110--- src/plugin/folderlistmodel/filesystemaction.h 2015-07-15 16:55:32 +0000
111+++ src/plugin/folderlistmodel/filesystemaction.h 2015-11-02 19:15:17 +0000
112@@ -112,8 +112,9 @@
113 void moveToTrash(const ActionPathList& pairPaths );
114 void restoreFromTrash(const ActionPathList& pairPaths);
115 void removeFromTrash(const QStringList& paths);
116- void onClipboardChanged();
117-
118+ void onClipboardChanged();
119+ bool downloadAndSaveAs(const DirItemInfo& remoteFile, const QString& fileName);
120+ bool downloadAsTemporaryFile(const DirItemInfo& remoteFile);
121
122 signals:
123 void error(const QString& errorTitle, const QString &errorMessage);
124@@ -122,6 +123,7 @@
125 void changed(const DirItemInfo&);
126 void progress(int curItem, int totalItems, int percent);
127 void recopy(const QStringList &names, const QString& path);
128+ void downloadTemporaryComplete(const QString&);
129
130 private slots:
131 void processAction();
132@@ -146,7 +148,9 @@
133 ActionHardMoveRemove,
134 ActionMoveToTrash,
135 ActionRestoreFromTrash,
136- ActionRemoveFromTrash
137+ ActionRemoveFromTrash,
138+ ActionDownload,
139+ ActionDownLoadAsTemporary
140 };
141
142 void createAndProcessAction(ActionType actionType, const QStringList& paths);
143@@ -250,6 +254,7 @@
144 void removeTrashInfoFileFromEntry(ActionEntry *entry);
145 void notifyActionOnItem(const DirItemInfo& item, ActionNotification action);
146 bool canMoveItems(Action *action, const QStringList &items);
147+ bool createAndProcessDownloadAction(ActionType a, const DirItemInfo& remoteFile, const QString& fileName);
148
149 #if defined(REGRESSION_TEST_FOLDERLISTMODEL) //used in Unit/Regression tests
150 bool m_forceUsingOtherFS;

Subscribers

People subscribed via source and target branches