Merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-04 into lp:ubuntu-filemanager-app

Proposed by Carlos Jose Mazieri
Status: Merged
Approved by: Arto Jalkanen
Approved revision: 436
Merged at revision: 439
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-04
Merge into: lp:ubuntu-filemanager-app
Prerequisite: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-03
Diff against target: 426 lines (+72/-97)
5 files modified
src/plugin/folderlistmodel/dirmodel.cpp (+6/-33)
src/plugin/folderlistmodel/dirmodel.h (+2/-4)
src/plugin/folderlistmodel/filesystemaction.cpp (+48/-37)
src/plugin/folderlistmodel/filesystemaction.h (+12/-5)
src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp (+4/-18)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-04
Reviewer Review Type Date Requested Status
Arto Jalkanen Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+265195@code.launchpad.net

Commit message

    FileSystemAction needs to interact with Locations, it now depends from LocationsFactory and Locations classes.

    The following methods were removed because the Location where the Action was performed needs to create its DirIteminfo for its items:
       * Removed signals FileSystemAction::added(QString) and FileSystemAction::removed(QString)
       * Removed slots DirModel::onItemAdded(QString) and DirModel::onItemRemoved(QString)

    FileSystemAction::isThereDiskSpace() was removed and Location::isThereDiskSpace() is used.

Description of the change

Preparing FileSystemAction class to work based on Locations

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
436. By Carlos Jose Mazieri

Avoided using operator=() for DirItemInfo as it has the copy constructor

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) :
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/dirmodel.cpp'
2--- src/plugin/folderlistmodel/dirmodel.cpp 2015-07-25 19:26:01 +0000
3+++ src/plugin/folderlistmodel/dirmodel.cpp 2015-07-25 19:26:01 +0000
4@@ -114,7 +114,7 @@
5 , mAuthData(NetAuthenticationDataList::getInstance(this))
6 , mLocationFactory(new LocationsFactory(this))
7 , mCurLocation(0)
8- , m_fsAction(new FileSystemAction(this) )
9+ , m_fsAction(new FileSystemAction(mLocationFactory,this) )
10 {
11 mNameFilters = QStringList() << "*";
12
13@@ -126,15 +126,9 @@
14 connect(m_fsAction, SIGNAL(added(DirItemInfo)),
15 this, SLOT(onItemAdded(DirItemInfo)));
16
17- connect(m_fsAction, SIGNAL(added(QString)),
18- this, SLOT(onItemAdded(QString)));
19-
20 connect(m_fsAction, SIGNAL(removed(DirItemInfo)),
21 this, SLOT(onItemRemoved(DirItemInfo)));
22
23- connect(m_fsAction, SIGNAL(removed(QString)),
24- this, SLOT(onItemRemoved(QString)));
25-
26 connect(m_fsAction, SIGNAL(error(QString,QString)),
27 this, SIGNAL(error(QString,QString)));
28
29@@ -960,16 +954,6 @@
30 return ret;
31 }
32
33-/*!
34- * \brief DirModel::onItemRemoved()
35- * \param pathname full pathname of removed file
36- */
37-void DirModel::onItemRemoved(const QString &pathname)
38-{
39- DirItemInfo info(pathname);
40- onItemRemoved(info);
41-}
42-
43
44 void DirModel::onItemRemoved(const DirItemInfo &fi)
45 {
46@@ -993,17 +977,6 @@
47 }
48
49
50-/*!
51- * \brief DirModel::onItemAdded()
52- * \param pathname full pathname of the added file
53- */
54-void DirModel::onItemAdded(const QString &pathname)
55-{
56- DirItemInfo info(pathname);
57- onItemAdded(info);
58-}
59-
60-
61 void DirModel::onItemAdded(const DirItemInfo &fi)
62 {
63 int newRow = addItem(fi);
64@@ -1509,26 +1482,26 @@
65
66 bool DirModel::existsDir(const QString &folderName) const
67 {
68- DirItemInfo d = setParentIfRelative(folderName);
69+ DirItemInfo d(setParentIfRelative(folderName));
70 return d.exists() && d.isDir();
71 }
72
73 bool DirModel::canReadDir(const QString &folderName) const
74 {
75- DirItemInfo d = setParentIfRelative(folderName);
76- return d.isDir() && d.isReadable();
77+ DirItemInfo d(setParentIfRelative(folderName));
78+ return d.isDir() && d.isReadable() && d.isExecutable();
79 }
80
81
82 bool DirModel::existsFile(const QString &fileName) const
83 {
84- DirItemInfo f = setParentIfRelative(fileName);
85+ DirItemInfo f(setParentIfRelative(fileName));
86 return f.exists() && f.isFile();
87 }
88
89 bool DirModel::canReadFile(const QString &fileName) const
90 {
91- DirItemInfo f = setParentIfRelative(fileName);
92+ DirItemInfo f(setParentIfRelative(fileName));
93 return f.isReadable() && f.isFile();
94 }
95
96
97=== modified file 'src/plugin/folderlistmodel/dirmodel.h'
98--- src/plugin/folderlistmodel/dirmodel.h 2015-07-25 19:26:01 +0000
99+++ src/plugin/folderlistmodel/dirmodel.h 2015-07-25 19:26:01 +0000
100@@ -461,10 +461,8 @@
101 void clipboardChanged();
102 void enabledExternalFSWatcherChanged(bool);
103
104-private slots:
105- void onItemRemoved(const QString&);
106- void onItemRemoved(const DirItemInfo&);
107- void onItemAdded(const QString&);
108+private slots:
109+ void onItemRemoved(const DirItemInfo&);
110 void onItemAdded(const DirItemInfo&);
111 void onItemChanged(const DirItemInfo&);
112
113
114=== modified file 'src/plugin/folderlistmodel/filesystemaction.cpp'
115--- src/plugin/folderlistmodel/filesystemaction.cpp 2014-12-29 11:29:21 +0000
116+++ src/plugin/folderlistmodel/filesystemaction.cpp 2015-07-25 19:26:01 +0000
117@@ -37,6 +37,9 @@
118 #include "filesystemaction.h"
119 #include "clipboard.h"
120 #include "qtrashutilinfo.h"
121+#include "location.h"
122+#include "locationsfactory.h"
123+
124
125 #if defined(Q_OS_UNIX)
126 #include <sys/statvfs.h>
127@@ -51,6 +54,7 @@
128 #include <QDir>
129 #include <QThread>
130 #include <QTemporaryFile>
131+#include <QScopedPointer>
132
133 /*!
134 * number of the files to work on a step, when this number is reached a signal is emitted
135@@ -177,14 +181,16 @@
136 //===============================================================================================
137 /*!
138 * \brief FileSystemAction::FileSystemAction
139+ * \param LocationsFactory locationsFactory
140 * \param parent
141 */
142-FileSystemAction::FileSystemAction(QObject *parent) :
143+FileSystemAction::FileSystemAction(LocationsFactory *locationsFactory, QObject *parent) :
144 QObject(parent)
145 , m_curAction(0)
146 , m_cancelCurrentAction(false)
147 , m_busy(false)
148 , m_clipboardChanged(false)
149+ , m_locationsFactory(locationsFactory)
150 #if defined(REGRESSION_TEST_FOLDERLISTMODEL) //used in Unit/Regression tests
151 , m_forceUsingOtherFS(false)
152 #endif
153@@ -475,7 +481,7 @@
154 {
155 removeTrashInfoFileFromEntry(curEntry);
156 }
157- emit removed(mainItem);
158+ notifyActionOnItem(mainItem, ItemRemoved);
159 }
160 else
161 {
162@@ -487,21 +493,24 @@
163 //it is necessary to remove also (file).trashinfo file
164 removeTrashInfoFileFromEntry(curEntry);
165 }
166- emit removed(mainItem);
167+ notifyActionOnItem(mainItem, ItemRemoved);
168 break;
169 case ActionHardMoveRemove: // nothing to do
170 break;
171 case ActionHardMoveCopy:
172 case ActionCopy: // ActionHardMoveCopy is lso checked here
173 case ActionMove:
174- if (!curEntry->added && !curEntry->alreadyExists)
175- {
176- emit added(curEntry->itemPaths.target());
177- curEntry->added = true;
178- }
179- else
180- {
181- emit changed(DirItemInfo(curEntry->itemPaths.target()));
182+ {
183+ QScopedPointer <DirItemInfo> item(m_locationsFactory->currentLocation()->newItemInfo(curEntry->itemPaths.target()));
184+ if (!curEntry->added && !curEntry->alreadyExists)
185+ {
186+ curEntry->added = true;
187+ notifyActionOnItem(*item, ItemAdded);
188+ }
189+ else
190+ {
191+ notifyActionOnItem(*item, ItemChanged);
192+ }
193 }
194 if (curEntry->type == ActionHardMoveCopy)
195 {
196@@ -674,8 +683,9 @@
197 QDir entryDirObj(entryDir);
198 if (!entryDirObj.exists() && entryDirObj.mkpath(entryDir))
199 {
200- emit added(entryDir);
201+ QScopedPointer <DirItemInfo> item(m_locationsFactory->currentLocation()->newItemInfo(entryDir));
202 entry->added = true;
203+ notifyActionOnItem(*item, ItemAdded);
204 }
205 }
206 QDir d(path);
207@@ -732,11 +742,11 @@
208 needsSize -= m_curAction->copyFile.target->size();
209 m_curAction->copyFile.target->close();
210 }
211- //check if there is disk space to copy source to target
212- if (needsSize > 0 && !isThereDiskSpace(entry, needsSize ))
213+ //check if there is disk space to copy source to target
214+ if (needsSize > 0 && !m_locationsFactory->currentLocation()->isThereDiskSpace(entry->itemPaths.targetPath(), needsSize))
215 {
216 m_cancelCurrentAction = true;
217- m_errorTitle = QObject::tr("There is no space on disk to copy");
218+ m_errorTitle = QObject::tr("There is no space to copy");
219 m_errorMsg = m_curAction->copyFile.target->fileName();
220 }
221 }
222@@ -758,14 +768,15 @@
223 //depending on the file size it may take longer, the view needs to be informed
224 if (m_curAction->copyFile.isEntryItem && !m_cancelCurrentAction)
225 {
226+ QScopedPointer <DirItemInfo> item(m_locationsFactory->currentLocation()->newItemInfo(target));
227 if (!entry->alreadyExists)
228- {
229- emit added(target);
230+ {
231 entry->added = true;
232+ notifyActionOnItem(*item, ItemAdded);
233 }
234 else
235- {
236- emit changed(DirItemInfo(target));
237+ {
238+ notifyActionOnItem(*item, ItemChanged);
239 }
240 }
241 }
242@@ -1143,8 +1154,9 @@
243 m_curAction->copyFile.target->close();
244 }
245 if (m_curAction->copyFile.target->remove())
246- {
247- emit removed(m_curAction->copyFile.targetName);
248+ {
249+ QScopedPointer<DirItemInfo> item(m_locationsFactory->currentLocation()->newItemInfo(m_curAction->copyFile.targetName));
250+ notifyActionOnItem(*item, ItemRemoved);
251 }
252 }
253 m_curAction->copyFile.clear();
254@@ -1172,8 +1184,9 @@
255 notifyProgress();
256 if (m_curAction->copyFile.isEntryItem && m_curAction->copyFile.amountSavedToRefresh <= 0)
257 {
258+ QScopedPointer <DirItemInfo> item(m_locationsFactory->currentLocation()->newItemInfo(m_curAction->copyFile.targetName));
259 m_curAction->copyFile.amountSavedToRefresh = AMOUNT_COPIED_TO_REFRESH_ITEM_INFO;
260- emit changed(DirItemInfo(m_curAction->copyFile.targetName));
261+ notifyActionOnItem(*item, ItemChanged);
262 }
263 scheduleSlot(SLOT(processCopySingleFile()));
264 }
265@@ -1415,21 +1428,6 @@
266 return ret;
267 }
268
269-//==================================================================
270-bool FileSystemAction::isThereDiskSpace(const ActionEntry *entry, qint64 requiredSize)
271-{
272- bool ret = true;
273-#if defined(Q_OS_UNIX)
274- struct statvfs vfs;
275- if ( ::statvfs( QFile::encodeName(entry->itemPaths.targetPath()).constData(), &vfs) == 0 )
276- {
277- qint64 free = vfs.f_bsize * vfs.f_bfree;
278- ret = free > requiredSize;
279- }
280-#endif
281- return ret;
282-}
283-
284
285 //==================================================================
286 /*!
287@@ -1508,3 +1506,16 @@
288 m_errorMsg = trashUtil.absInfo;
289 }
290 }
291+
292+
293+void FileSystemAction::notifyActionOnItem(const DirItemInfo& item, ActionNotification action)
294+{
295+ switch(action)
296+ {
297+ case ItemAdded: emit added(item); break;
298+ case ItemRemoved: emit removed(item); break;
299+ case ItemChanged: emit changed(item); break;
300+ default: break;
301+ }
302+}
303+
304
305=== modified file 'src/plugin/folderlistmodel/filesystemaction.h'
306--- src/plugin/folderlistmodel/filesystemaction.h 2014-06-17 20:42:35 +0000
307+++ src/plugin/folderlistmodel/filesystemaction.h 2015-07-25 19:26:01 +0000
308@@ -51,7 +51,8 @@
309 class DirModelMimeData;
310 class QFile;
311 class QTemporaryFile;
312-
313+class Location;
314+class LocationsFactory;
315
316 /*!
317 * \brief The FileSystemAction class does file system operations copy/cut/paste/remove items
318@@ -95,7 +96,7 @@
319 {
320 Q_OBJECT
321 public:
322- explicit FileSystemAction(QObject *parent = 0);
323+ explicit FileSystemAction(LocationsFactory *locationsFactory, QObject *parent = 0);
324 ~FileSystemAction();
325
326 public:
327@@ -116,9 +117,7 @@
328
329 signals:
330 void error(const QString& errorTitle, const QString &errorMessage);
331- void removed(const QString& item);
332 void removed(const DirItemInfo&);
333- void added(const QString& );
334 void added(const DirItemInfo& );
335 void changed(const DirItemInfo&);
336 void progress(int curItem, int totalItems, int percent);
337@@ -131,6 +130,13 @@
338 bool processCopySingleFile();
339
340 private:
341+ enum ActionNotification
342+ {
343+ ItemAdded,
344+ ItemRemoved,
345+ ItemChanged
346+ };
347+
348 enum ActionType
349 {
350 ActionRemove,
351@@ -213,6 +219,7 @@
352 QString m_errorTitle;
353 QString m_errorMsg;
354 bool m_clipboardChanged; //!< this is set to false in \ref moveIntoCurrentPath() and \ref copyIntoCurrentPath();
355+ LocationsFactory * m_locationsFactory;
356
357
358 private:
359@@ -232,10 +239,10 @@
360 void moveDirToTempAndRemoveItLater(const QString& dir);
361 bool makeBackupNameForCurrentItem(ActionEntry *entry);
362 bool endCopySingleFile();
363- bool isThereDiskSpace(const ActionEntry *entry, qint64 requiredSize);
364 void queueAction(Action *myAction);
365 void createTrashInfoFileFromEntry(ActionEntry *entry);
366 void removeTrashInfoFileFromEntry(ActionEntry *entry);
367+ void notifyActionOnItem(const DirItemInfo& item, ActionNotification action);
368
369 #if defined(REGRESSION_TEST_FOLDERLISTMODEL) //used in Unit/Regression tests
370 bool m_forceUsingOtherFS;
371
372=== modified file 'src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp'
373--- src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp 2015-07-25 19:26:01 +0000
374+++ src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp 2015-07-25 19:26:01 +0000
375@@ -74,9 +74,7 @@
376 TestDirModel();
377 ~TestDirModel();
378
379-protected slots:
380- void slotFileAdded(const QString& s) {m_filesAdded.append(s); }
381- void slotFileRemoved(const QString& s) {m_filesRemoved.append(s); }
382+protected slots:
383 void slotFileAdded(const DirItemInfo& f) {m_filesAdded.append(f.absoluteFilePath()); }
384 void slotFileRemoved(const DirItemInfo& f) {m_filesRemoved.append(f.absoluteFilePath()); }
385 void slotPathChamged(QString path) { m_currentPath = path;}
386@@ -211,17 +209,13 @@
387
388 };
389
390-TestDirModel::TestDirModel() : m_deepDir_01(0)
391+TestDirModel::TestDirModel() : fsAction(new LocationsFactory(this), this)
392+ ,m_deepDir_01(0)
393 ,m_deepDir_02(0)
394 ,m_deepDir_03(0)
395 ,m_dirModel_01(0)
396 ,m_dirModel_02(0)
397-{
398- connect(&fsAction, SIGNAL(added(QString)),
399- this, SLOT(slotFileAdded(QString)) );
400- connect(&fsAction, SIGNAL(removed(QString)),
401- this, SLOT(slotFileRemoved(QString)) );
402-
403+{
404 connect(&fsAction, SIGNAL(added(DirItemInfo)),
405 this, SLOT(slotFileAdded(DirItemInfo)));
406 connect(&fsAction, SIGNAL(removed(DirItemInfo)),
407@@ -401,19 +395,11 @@
408 m_dirModel_01 = new DirModel();
409 m_dirModel_02 = new DirModel();
410
411- connect(m_dirModel_01->m_fsAction, SIGNAL(added(QString)),
412- this, SLOT(slotFileAdded(QString)) );
413- connect(m_dirModel_01->m_fsAction, SIGNAL(removed(QString)),
414- this, SLOT(slotFileRemoved(QString)) );
415 connect(m_dirModel_01->m_fsAction, SIGNAL(added(DirItemInfo)),
416 this, SLOT(slotFileAdded(DirItemInfo)));
417 connect(m_dirModel_01->m_fsAction, SIGNAL(removed(DirItemInfo)),
418 this, SLOT(slotFileRemoved(DirItemInfo)));
419
420- connect(m_dirModel_02->m_fsAction, SIGNAL(added(QString)),
421- this, SLOT(slotFileAdded(QString)) );
422- connect(m_dirModel_02->m_fsAction, SIGNAL(removed(QString)),
423- this, SLOT(slotFileRemoved(QString)) );
424 connect(m_dirModel_02->m_fsAction, SIGNAL(added(DirItemInfo)),
425 this, SLOT(slotFileAdded(DirItemInfo)));
426 connect(m_dirModel_02->m_fsAction, SIGNAL(removed(DirItemInfo)),

Subscribers

People subscribed via source and target branches