Merge lp:~carlos-mazieri/ubuntu-filemanager-app/trash-operations-3 into lp:ubuntu-filemanager-app

Proposed by Carlos Jose Mazieri
Status: Merged
Approved by: Francis Ginther
Approved revision: 188
Merged at revision: 206
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/trash-operations-3
Merge into: lp:ubuntu-filemanager-app
Prerequisite: lp:~carlos-mazieri/ubuntu-filemanager-app/trash-operations-2
Diff against target: 429 lines (+294/-8)
6 files modified
src/plugin/folderlistmodel/dirmodel.cpp (+110/-2)
src/plugin/folderlistmodel/dirmodel.h (+21/-1)
src/plugin/folderlistmodel/filesystemaction.cpp (+103/-3)
src/plugin/folderlistmodel/filesystemaction.h (+10/-2)
src/plugin/folderlistmodel/trash/trashlocation.cpp (+28/-0)
src/plugin/folderlistmodel/trash/trashlocation.h (+22/-0)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/trash-operations-3
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Arto Jalkanen Approve
Review via email: mp+219943@code.launchpad.net

Commit message

Code to complete Trash opearations: move into / restore from / restore all / empty trash

Description of the change

Code to complete Trash opearations: move into / restore from / restore all / empty trash

Removing items from trash is driven to DirModel::rm() as normal remove, the operation differs from a normal remove only that for each top level item the ".trashinfo" file is also removed, but removing sub items from Trash is not allowed.

All Trash operations in Trash sub items (not in top level) are not allowed, that means, items in Trash sub folders are not allowed to be restored neither removed, these actions are supported on the top Trash root only.

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: Needs Fixing (continuous-integration)
Revision history for this message
Arto Jalkanen (ajalkane) wrote :

1)

#define IS_BROWSING_TRASH() (mCurLocation && mCurLocation->type() == LocationsFactory::TrashDisk && mCurLocation->isRoot())

Wouldn't this be clearer if it was IS_BROWSING_TRASH_ROOTDIR or something like that?

2)
297 +void FileSystemAction::createTrashInfoFileFromEnry(ActionEntry *entry)
Typo: should be createTrashInfoFileFromEntry
310 +void FileSystemAction::removeTrashInfoFileFromEnry(ActionEntry *entry)
Typo: should be removeTrashInfoFileFromEntry

3)
This is not anything that should be changed, just a note if there's a problem later when doing QML work:
Q_INVOKABLE void moveIndexesToTrash(const QList<int>&);

And functions like this, that take const reference to a list. I have an impression these were a problem in Qt 4.8 for QML, and if I remember correctly QML needed a QVariantList pointer. But lots have changed for Qt5 so perhaps this cleaner way works now. Let's only do some QML specific functions if there is a problem.

So in summary, only the cosmetic change of 2) is needed, and I'd think 1) would be a change that would make the macro's intent clearer.

review: Needs Fixing
Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

Thanks,

All items have been addressed in revision 189.

I was not aware about item 3), Q_INVOKABLE was removed, it'd better to create a better QML interface for that.
The last MP has functions using selections like moveSelectionToTrash(), and restoreSelectionFromTrash().

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Arto Jalkanen (ajalkane) wrote :

Thank you, looks good.

review: Approve
Revision history for this message
Arto Jalkanen (ajalkane) wrote :

Ready to approve once Jenkins is not failing.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

Can anyone help here?

I think that needs manual fixing in the build process,it has happened once more.

Revision history for this message
Francis Ginther (fginther) wrote :

The trusty testing has been disabled for dependency reasons. Re-approving to try autolanding again.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/plugin/folderlistmodel/dirmodel.cpp'
--- src/plugin/folderlistmodel/dirmodel.cpp 2014-05-17 12:57:46 +0000
+++ src/plugin/folderlistmodel/dirmodel.cpp 2014-05-28 21:14:07 +0000
@@ -38,6 +38,7 @@
38#include "location.h"38#include "location.h"
39#include "locationurl.h"39#include "locationurl.h"
40#include "disklocation.h"40#include "disklocation.h"
41#include "trashlocation.h"
4142
4243
43#ifndef DO_NOT_USE_TAG_LIB44#ifndef DO_NOT_USE_TAG_LIB
@@ -75,7 +76,7 @@
7576
76#define IS_FILE_MANAGER_IDLE() (!mAwaitingResults)77#define IS_FILE_MANAGER_IDLE() (!mAwaitingResults)
7778
7879#define IS_BROWSING_TRASH_ROOTDIR() (mCurLocation && mCurLocation->type() == LocationsFactory::TrashDisk && mCurLocation->isRoot())
7980
80namespace {81namespace {
81 QHash<QByteArray, int> roleMapping;82 QHash<QByteArray, int> roleMapping;
@@ -482,7 +483,18 @@
482483
483void DirModel::rm(const QStringList &paths)484void DirModel::rm(const QStringList &paths)
484{485{
485 m_fsAction->remove(paths);486 //if current location is Trash only in the root is allowed to remove Items
487 if (mCurLocation->type() == LocationsFactory::TrashDisk)
488 {
489 if (IS_BROWSING_TRASH_ROOTDIR())
490 {
491 m_fsAction->removeFromTrash(paths);
492 }
493 }
494 else
495 {
496 m_fsAction->remove(paths);
497 }
486}498}
487499
488500
@@ -1509,6 +1521,102 @@
1509}1521}
15101522
15111523
1524void DirModel:: moveIndexesToTrash(const QList<int>& items)
1525{
1526 if (mCurLocation->type() == LocationsFactory::LocalDisk)
1527 {
1528 const TrashLocation *trashLocation = static_cast<const TrashLocation*>
1529 (mLocationFactory->getLocation(LocationsFactory::TrashDisk));
1530 ActionPathList itemsAndTrashPath;
1531 int index = 0;
1532 for (int counter=0; counter < items.count(); ++counter)
1533 {
1534 index = items.at(counter);
1535 if (IS_VALID_ROW(index))
1536 {
1537 const DirItemInfo &it = mDirectoryContents.at(index);
1538 itemsAndTrashPath.append(trashLocation->getMovePairPaths(it));
1539 }
1540 }
1541 if (itemsAndTrashPath.count() > 0)
1542 {
1543 m_fsAction->moveToTrash(itemsAndTrashPath);
1544 }
1545 }
1546}
1547
1548
1549void DirModel:: moveIndexToTrash(int index)
1550{
1551 QList<int> list;
1552 list.append(index);
1553 return moveIndexesToTrash(list);
1554}
1555
1556
1557void DirModel::restoreTrash()
1558{
1559 if ( IS_BROWSING_TRASH_ROOTDIR() )
1560 {
1561 QList<int> allItems;
1562 for (int counter=0; counter < rowCount(); ++counter)
1563 {
1564 allItems.append(counter);
1565 }
1566 restoreIndexesFromTrash(allItems);
1567 }
1568}
1569
1570
1571void DirModel::emptyTrash()
1572{
1573 if ( IS_BROWSING_TRASH_ROOTDIR() )
1574 {
1575 QStringList allItems;
1576 for (int counter=0; counter < rowCount(); ++counter)
1577 {
1578 allItems.append(mDirectoryContents.at(counter).absoluteFilePath());
1579 }
1580 if (allItems.count() > 0)
1581 {
1582 m_fsAction->removeFromTrash(allItems);
1583 }
1584 }
1585}
1586
1587
1588void DirModel::restoreIndexFromTrash(int index)
1589{
1590 QList<int> item;
1591 item.append(index);
1592 restoreIndexesFromTrash(item);
1593}
1594
1595
1596void DirModel::restoreIndexesFromTrash(const QList<int> &items)
1597{
1598 if ( IS_BROWSING_TRASH_ROOTDIR() )
1599 {
1600 TrashLocation *trashLocation = static_cast<TrashLocation*> (mCurLocation);
1601 ActionPathList itemsAndOriginalPaths;
1602 int index = 0;
1603 for (int counter=0; counter < items.count(); ++counter)
1604 {
1605 index = items.at(counter);
1606 if (IS_VALID_ROW(index))
1607 {
1608 const DirItemInfo &it = mDirectoryContents.at(index);
1609 itemsAndOriginalPaths.append(trashLocation->getRestorePairPaths(it));
1610 }
1611 }
1612 if (itemsAndOriginalPaths.count() > 0)
1613 {
1614 m_fsAction->restoreFromTrash(itemsAndOriginalPaths);
1615 }
1616 }
1617}
1618
1619
1512#ifndef DO_NOT_USE_TAG_LIB1620#ifndef DO_NOT_USE_TAG_LIB
1513QVariant DirModel::getAudioMetaData(const QFileInfo& fi, int role) const1621QVariant DirModel::getAudioMetaData(const QFileInfo& fi, int role) const
1514{1622{
15151623
=== modified file 'src/plugin/folderlistmodel/dirmodel.h'
--- src/plugin/folderlistmodel/dirmodel.h 2014-05-02 12:22:11 +0000
+++ src/plugin/folderlistmodel/dirmodel.h 2014-05-28 21:14:07 +0000
@@ -289,7 +289,27 @@
289 Q_INVOKABLE bool existsFile(const QString& fileName) const;289 Q_INVOKABLE bool existsFile(const QString& fileName) const;
290 Q_INVOKABLE bool canReadFile(const QString& fileName) const;290 Q_INVOKABLE bool canReadFile(const QString& fileName) const;
291291
292public slots:292 // Trash functions
293 Q_INVOKABLE void moveIndexToTrash(int index);
294 void moveIndexesToTrash(const QList<int>&);
295 Q_INVOKABLE void restoreIndexFromTrash(int index);
296 void restoreIndexesFromTrash(const QList<int>&);
297
298public slots:
299 /*!
300 * \brief restoreTrash() restore all items being actually browsed in the Trash
301 *
302 */
303 void restoreTrash();
304
305 /*!
306 * \brief emptyTrash() remove definitely all items being actually browsed in the Trash
307 *
308 * \sa \ref removeSelection() and \ref rm()
309 *
310 */
311 void emptyTrash();
312
293 /*!313 /*!
294 * \brief goHome() goes to user home dir314 * \brief goHome() goes to user home dir
295 * Go to user home dir, we may have a tab for places or something like that315 * Go to user home dir, we may have a tab for places or something like that
296316
=== modified file 'src/plugin/folderlistmodel/filesystemaction.cpp'
--- src/plugin/folderlistmodel/filesystemaction.cpp 2014-05-24 01:40:01 +0000
+++ src/plugin/folderlistmodel/filesystemaction.cpp 2014-05-28 21:14:07 +0000
@@ -36,6 +36,7 @@
3636
37#include "filesystemaction.h"37#include "filesystemaction.h"
38#include "clipboard.h"38#include "clipboard.h"
39#include "qtrashutilinfo.h"
3940
40#if defined(Q_OS_UNIX)41#if defined(Q_OS_UNIX)
41#include <sys/statvfs.h>42#include <sys/statvfs.h>
@@ -264,8 +265,17 @@
264 );265 );
265 return false;266 return false;
266 }267 }
267 //action->type is top level for all items, entry->type drives item behaviour 268 //action->type is top level for all items, entry->type drives item behaviour
268 entry->type = action->type; //normal behaviour269 switch(action->type)
270 {
271 case ActionMoveToTrash:
272 case ActionRestoreFromTrash: entry->type = ActionMove; //needs create .trashinfo file
273 break;
274 case ActionRemoveFromTrash: entry->type = ActionRemove; //needs remove .trashinfo file
275 break;
276 default: entry->type = action->type; //normal behaviour
277 break;
278 }
269 //this is the item being handled279 //this is the item being handled
270 entry->reversedOrder.append(info);280 entry->reversedOrder.append(info);
271 // verify if the destination item already exists and it the destination path is in other file system281 // verify if the destination item already exists and it the destination path is in other file system
@@ -447,9 +457,31 @@
447 const DirItemInfo & mainItem = curEntry->reversedOrder.at(curEntry->currItem -1);457 const DirItemInfo & mainItem = curEntry->reversedOrder.at(curEntry->currItem -1);
448 m_curAction->currEntryIndex++;458 m_curAction->currEntryIndex++;
449459
460 //check Trash operations
461 if ( (m_curAction->type == ActionMoveToTrash || m_curAction->type == ActionRestoreFromTrash)
462 && (curEntry->type == ActionMove || curEntry->type == ActionHardMoveRemove)
463 )
464 {
465 if ( m_curAction->type == ActionMoveToTrash )
466 {
467 createTrashInfoFileFromEntry(curEntry);
468 }
469 else
470 {
471 removeTrashInfoFileFromEntry(curEntry);
472 }
473 emit removed(mainItem);
474 }
475 else
476 {
450 switch(curEntry->type)477 switch(curEntry->type)
451 {478 {
452 case ActionRemove: 479 case ActionRemove:
480 if (m_curAction->type == ActionRemoveFromTrash)
481 {
482 //it is necessary to remove also (file).trashinfo file
483 removeTrashInfoFileFromEntry(curEntry);
484 }
453 emit removed(mainItem);485 emit removed(mainItem);
454 break;486 break;
455 case ActionHardMoveRemove: // nothing to do487 case ActionHardMoveRemove: // nothing to do
@@ -478,6 +510,7 @@
478 default:510 default:
479 break;511 break;
480 }//switch512 }//switch
513 }
481 }//end if (curEntry->currItem == curEntry->reversedOrder.count())514 }//end if (curEntry->currItem == curEntry->reversedOrder.count())
482515
483 if (curEntry->currStep == STEP_FILES)516 if (curEntry->currStep == STEP_FILES)
@@ -1403,3 +1436,70 @@
1403{1436{
1404 m_clipboardChanged = true;1437 m_clipboardChanged = true;
1405}1438}
1439
1440
1441//==================================================================
1442/*!
1443 * \brief FileSystemAction::moveToTrash() Move a set of files to Trash
1444 * \param items files/dirs that belong to the same parent directory
1445 */
1446void FileSystemAction::moveToTrash(const ActionPathList &pairPaths)
1447{
1448 Action *moveAction = createAction(ActionMoveToTrash);
1449 for (int counter=0; counter < pairPaths.count(); ++counter)
1450 {
1451 addEntry(moveAction, pairPaths.at(counter));
1452 }
1453 queueAction(moveAction);
1454}
1455
1456//==================================================================
1457/*!
1458 * \brief FileSystemAction::restoreFromTrash() restore a set of Files to
1459 * their original path
1460 * \param pairPaths
1461 */
1462void FileSystemAction::restoreFromTrash(const ActionPathList &pairPaths)
1463{
1464 Action *moveAction = createAction(ActionRestoreFromTrash);
1465 for (int counter=0; counter < pairPaths.count(); ++counter)
1466 {
1467 addEntry(moveAction, pairPaths.at(counter));
1468 }
1469 queueAction(moveAction);
1470}
1471
1472/*!
1473 * \brief FileSystemAction::removeFromTrash
1474 * \param paths
1475 */
1476void FileSystemAction::removeFromTrash(const QStringList &paths)
1477{
1478 createAndProcessAction(ActionRemoveFromTrash, paths);
1479}
1480
1481
1482void FileSystemAction::createTrashInfoFileFromEntry(ActionEntry *entry)
1483{
1484 QTrashUtilInfo trashUtil;
1485 trashUtil.setInfoFromTrashItem(entry->itemPaths.target());
1486 if (!trashUtil.createTrashInfoFile(entry->itemPaths.source()))
1487 {
1488 m_cancelCurrentAction = true;
1489 m_errorTitle = QObject::tr("Could not create trash info file");
1490 m_errorMsg = trashUtil.absInfo;
1491 }
1492}
1493
1494
1495void FileSystemAction::removeTrashInfoFileFromEntry(ActionEntry *entry)
1496{
1497 QTrashUtilInfo trashUtil;
1498 trashUtil.setInfoFromTrashItem(entry->itemPaths.source());
1499 if (!trashUtil.removeTrashInfoFile())
1500 {
1501 m_cancelCurrentAction = true;
1502 m_errorTitle = QObject::tr("Could not remove the trash info file");
1503 m_errorMsg = trashUtil.absInfo;
1504 }
1505}
14061506
=== modified file 'src/plugin/folderlistmodel/filesystemaction.h'
--- src/plugin/folderlistmodel/filesystemaction.h 2014-05-24 01:40:01 +0000
+++ src/plugin/folderlistmodel/filesystemaction.h 2014-05-28 21:14:07 +0000
@@ -108,6 +108,9 @@
108 void pathChanged(const QString& path); 108 void pathChanged(const QString& path);
109 void copyIntoCurrentPath(const QStringList& items);109 void copyIntoCurrentPath(const QStringList& items);
110 void moveIntoCurrentPath(const QStringList& items);110 void moveIntoCurrentPath(const QStringList& items);
111 void moveToTrash(const ActionPathList& pairPaths );
112 void restoreFromTrash(const ActionPathList& pairPaths);
113 void removeFromTrash(const QStringList& paths);
111 void onClipboardChanged();114 void onClipboardChanged();
112115
113116
@@ -134,7 +137,10 @@
134 ActionCopy,137 ActionCopy,
135 ActionMove,138 ActionMove,
136 ActionHardMoveCopy,139 ActionHardMoveCopy,
137 ActionHardMoveRemove140 ActionHardMoveRemove,
141 ActionMoveToTrash,
142 ActionRestoreFromTrash,
143 ActionRemoveFromTrash
138 };144 };
139145
140 void createAndProcessAction(ActionType actionType, const QStringList& paths);146 void createAndProcessAction(ActionType actionType, const QStringList& paths);
@@ -227,7 +233,9 @@
227 bool makeBackupNameForCurrentItem(ActionEntry *entry);233 bool makeBackupNameForCurrentItem(ActionEntry *entry);
228 bool endCopySingleFile();234 bool endCopySingleFile();
229 bool isThereDiskSpace(const ActionEntry *entry, qint64 requiredSize);235 bool isThereDiskSpace(const ActionEntry *entry, qint64 requiredSize);
230 void queueAction(Action *myAction); 236 void queueAction(Action *myAction);
237 void createTrashInfoFileFromEntry(ActionEntry *entry);
238 void removeTrashInfoFileFromEntry(ActionEntry *entry);
231239
232#if defined(REGRESSION_TEST_FOLDERLISTMODEL) //used in Unit/Regression tests240#if defined(REGRESSION_TEST_FOLDERLISTMODEL) //used in Unit/Regression tests
233 bool m_forceUsingOtherFS;241 bool m_forceUsingOtherFS;
234242
=== modified file 'src/plugin/folderlistmodel/trash/trashlocation.cpp'
--- src/plugin/folderlistmodel/trash/trashlocation.cpp 2014-05-17 11:47:11 +0000
+++ src/plugin/folderlistmodel/trash/trashlocation.cpp 2014-05-28 21:14:07 +0000
@@ -258,3 +258,31 @@
258{258{
259 // do nothing, the startExternalFsWatcher() is called in fetchItems()259 // do nothing, the startExternalFsWatcher() is called in fetchItems()
260}260}
261
262
263ActionPaths
264TrashLocation::getRestorePairPaths(const DirItemInfo& item) const
265{
266 const TrashItemInfo* ptrash = static_cast<const TrashItemInfo*> (&item);
267 QTrashUtilInfo trashInfo;
268
269 trashInfo.setInfo(ptrash->getRootTrashDir(), ptrash->absoluteFilePath());
270
271 ActionPaths ret(ptrash->absoluteFilePath());
272 ret.setTargetFullName(trashInfo.getOriginalPathName());
273
274 return ret;
275}
276
277
278ActionPaths
279TrashLocation::getMovePairPaths(const DirItemInfo &item) const
280{
281 ActionPaths ret(item.absoluteFilePath());
282
283 QTrashUtilInfo trashInfo;
284 trashInfo.setInfo(suitableTrash(item.absoluteFilePath()), item.absoluteFilePath());
285
286 ret.setTargetFullName( trashInfo.absFile );
287 return ret;
288}
261289
=== modified file 'src/plugin/folderlistmodel/trash/trashlocation.h'
--- src/plugin/folderlistmodel/trash/trashlocation.h 2014-05-15 00:18:54 +0000
+++ src/plugin/folderlistmodel/trash/trashlocation.h 2014-05-28 21:14:07 +0000
@@ -45,10 +45,32 @@
4545
46 virtual DirItemInfo *validateUrlPath(const QString& urlPath);46 virtual DirItemInfo *validateUrlPath(const QString& urlPath);
4747
48 /*!
49 * \brief getMovePairPaths() Get: original path and destination trash path
50 *
51 *
52 * \param item desired item to be moved into Trash
53 *
54 * \return an \ref ActionPaths that contains the source orginal file and
55 * the suitable Trash path where the source will moved into
56 */
57 ActionPaths getMovePairPaths(const DirItemInfo& item) const;
58
59 /*!
60 * \brief getRestorePairPaths() Get: Trash path as source and item original path as destination
61 *
62 * \param item desired to be restored from Trash
63 *
64 * \return n \ref ActionPaths that contains the thash item and
65 * the original source path as destionation
66 */
67 ActionPaths getRestorePairPaths(const DirItemInfo& item) const;
68
48private:69private:
49 void addTrashFetchRequest(TrashListWorker *workerObject);70 void addTrashFetchRequest(TrashListWorker *workerObject);
5071
51private:72private:
73 ActionPathList m_actionPathList;
52 QStringList m_currentPaths; //!< also used in the startExternalFsWatcher(), it can br activated any time74 QStringList m_currentPaths; //!< also used in the startExternalFsWatcher(), it can br activated any time
53};75};
5476

Subscribers

People subscribed via source and target branches