← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-05 into lp:ubuntu-filemanager-app

 

Carlos Jose Mazieri has proposed merging lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-05 into lp:ubuntu-filemanager-app with lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-04 as a prerequisite.

Commit message:
Improved TrashItemInfo creator to identify which is the Trash Root part

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

For more details, see:
https://code.launchpad.net/~carlos-mazieri/ubuntu-filemanager-app/samba-actions-05/+merge/265196

Actions on Trash were performed using Qt QFileInfo object, the TrashItemInfo class was improved to be used instead.
-- 
Your team Ubuntu File Manager Developers is requested to review the proposed merge of lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-05 into lp:ubuntu-filemanager-app.
=== modified file 'src/plugin/folderlistmodel/trash/qtrashdir.cpp'
--- src/plugin/folderlistmodel/trash/qtrashdir.cpp	2014-05-02 12:22:11 +0000
+++ src/plugin/folderlistmodel/trash/qtrashdir.cpp	2015-07-18 21:48:42 +0000
@@ -248,8 +248,8 @@
 QString QTrashDir::getSuitableTopTrashDir(const QString &mountPoint) const
 {
     QString trashDir(getSharedTopTrashDir(mountPoint));
-    //if previous shared mountPoint/Trash/$uid failed
-    //try  mountPoint/Trash-$uid
+    //if previous shared mountPoint/.Trash/$uid failed
+    //try  mountPoint/.Trash-$uid
     if (trashDir.isEmpty())
     {
         trashDir = getSingleTopTrashDir(mountPoint, true);

=== modified file 'src/plugin/folderlistmodel/trash/qtrashutilinfo.cpp'
--- src/plugin/folderlistmodel/trash/qtrashutilinfo.cpp	2014-05-02 12:22:11 +0000
+++ src/plugin/folderlistmodel/trash/qtrashutilinfo.cpp	2015-07-18 21:48:42 +0000
@@ -20,13 +20,23 @@
  */
 
 #include "qtrashutilinfo.h"
-
+#include <unistd.h>
+#include <sys/types.h>
 #include <QDir>
 #include <QSettings>
 #include <QDateTime>
 
-QLatin1String filesDirString("files");
-QLatin1String infoDirString("info");
+namespace
+{
+   QLatin1String filesDirString("files");
+   QLatin1String infoDirString("info");
+   uint userId = ::getuid();
+   QStringList trashes = QStringList()
+           << QLatin1String("/Trash/files")
+           << QString( QString("/.Trash-") + QString::number(userId) + QLatin1String("/files"))
+           << QString( QString("/.Trash/") + QString::number(userId) + QLatin1String("/files"));
+}
+
 
 void QTrashUtilInfo::clear()
 {
@@ -55,16 +65,23 @@
 
 void QTrashUtilInfo::setInfoFromTrashItem(const QString &absTrashItem)
 {
-    valid = false;
-    QFileInfo item(absTrashItem);
-    if (item.absolutePath().endsWith(filesDirString))
+    clear();
+    //try to guess which is the Trash directory
+    int trashPathIndex = -1;
+    int counter        = 0;
+    for (; trashPathIndex == -1 && counter < trashes.count(); ++counter)
     {
-        QFileInfo filesUnderRoot(item.absolutePath());
-        QTrashUtilInfo::setInfo(filesUnderRoot.absolutePath(), absTrashItem);
+        trashPathIndex = absTrashItem.indexOf(trashes.at(counter));
     }
-    else
+    if (trashPathIndex != -1)  //counter -1 points to the item found
     {
-        clear();
+        trashPathIndex += trashes.at(counter-1).length();
+        // it is something under "files/" directory
+        if (trashPathIndex < absTrashItem.length() && absTrashItem.at(trashPathIndex) == QDir::separator())
+        {
+            trashPathIndex -= 6; // 6 is the length of "files/", we want to get the Trash root dir
+            QTrashUtilInfo::setInfo(absTrashItem.left(trashPathIndex), absTrashItem);
+        }
     }
 }
 

=== modified file 'src/plugin/folderlistmodel/trash/trashiteminfo.cpp'
--- src/plugin/folderlistmodel/trash/trashiteminfo.cpp	2014-05-17 09:58:10 +0000
+++ src/plugin/folderlistmodel/trash/trashiteminfo.cpp	2015-07-18 21:48:42 +0000
@@ -20,9 +20,15 @@
  */
 
 #include "trashiteminfo.h"
+#include "qtrashutilinfo.h"
 #include "locationurl.h"
-
-
+#include <QDebug>
+
+/*!
+ * \brief TrashItemInfo::TrashItemInfo() This constructor does not receive the Trash path
+ *
+ * \param urlPath  the  full pathname  starting with th \a trashPath as "/home/devubuntu/.local/share/Trash/files/test.txt"
+ */
 TrashItemInfo::TrashItemInfo(const QString &urlPath)
     : DirItemInfo()  
 {  
@@ -33,6 +39,22 @@
    {
       setRoot();
    }
+   else
+   {
+       QTrashUtilInfo trashInfo;
+       trashInfo.setInfoFromTrashItem(urlPath);
+       //try to guess the Trash path
+       if (trashInfo.isValid() && !trashInfo.filesDir.isEmpty())
+       {
+           //Trash path found
+           init(trashInfo.filesDir);
+       }
+       QFileInfo maybeDiskUrl(urlPath);
+       if (maybeDiskUrl.exists())
+       {
+           d_ptr->setFileInfo(maybeDiskUrl);
+       }
+   }
 }
 
 
@@ -42,6 +64,12 @@
 }
 
 
+/*!
+ * \brief TrashItemInfo::TrashItemInfo()
+ *
+ * \param trashPath the trash PATH finished with "files" like as "/home/user/.local/share/Trash/files"
+ * \param urlPath  the  full pathname  starting with th \a trashPath as "/home/user/.local/share/Trash/files/test.txt"
+ */
 TrashItemInfo::TrashItemInfo(const QString& trashPath, const QString &urlPath)
    : DirItemInfo(urlPath)  
 {


Follow ups