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

Proposed by Carlos Jose Mazieri
Status: Merged
Approved by: Arto Jalkanen
Approved revision: 436
Merged at revision: 440
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-05
Merge into: lp:ubuntu-filemanager-app
Prerequisite: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-04
Diff against target: 134 lines (+59/-14)
3 files modified
src/plugin/folderlistmodel/trash/qtrashdir.cpp (+2/-2)
src/plugin/folderlistmodel/trash/qtrashutilinfo.cpp (+27/-10)
src/plugin/folderlistmodel/trash/trashiteminfo.cpp (+30/-2)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-05
Reviewer Review Type Date Requested Status
Arto Jalkanen Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+265196@code.launchpad.net

Commit message

Improved TrashItemInfo creator to identify which is the Trash Root part

Description of the change

Actions on Trash were performed using Qt QFileInfo object, the TrashItemInfo class was improved to be used instead.

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)
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/trash/qtrashdir.cpp'
2--- src/plugin/folderlistmodel/trash/qtrashdir.cpp 2014-05-02 12:22:11 +0000
3+++ src/plugin/folderlistmodel/trash/qtrashdir.cpp 2015-07-18 21:48:42 +0000
4@@ -248,8 +248,8 @@
5 QString QTrashDir::getSuitableTopTrashDir(const QString &mountPoint) const
6 {
7 QString trashDir(getSharedTopTrashDir(mountPoint));
8- //if previous shared mountPoint/Trash/$uid failed
9- //try mountPoint/Trash-$uid
10+ //if previous shared mountPoint/.Trash/$uid failed
11+ //try mountPoint/.Trash-$uid
12 if (trashDir.isEmpty())
13 {
14 trashDir = getSingleTopTrashDir(mountPoint, true);
15
16=== modified file 'src/plugin/folderlistmodel/trash/qtrashutilinfo.cpp'
17--- src/plugin/folderlistmodel/trash/qtrashutilinfo.cpp 2014-05-02 12:22:11 +0000
18+++ src/plugin/folderlistmodel/trash/qtrashutilinfo.cpp 2015-07-18 21:48:42 +0000
19@@ -20,13 +20,23 @@
20 */
21
22 #include "qtrashutilinfo.h"
23-
24+#include <unistd.h>
25+#include <sys/types.h>
26 #include <QDir>
27 #include <QSettings>
28 #include <QDateTime>
29
30-QLatin1String filesDirString("files");
31-QLatin1String infoDirString("info");
32+namespace
33+{
34+ QLatin1String filesDirString("files");
35+ QLatin1String infoDirString("info");
36+ uint userId = ::getuid();
37+ QStringList trashes = QStringList()
38+ << QLatin1String("/Trash/files")
39+ << QString( QString("/.Trash-") + QString::number(userId) + QLatin1String("/files"))
40+ << QString( QString("/.Trash/") + QString::number(userId) + QLatin1String("/files"));
41+}
42+
43
44 void QTrashUtilInfo::clear()
45 {
46@@ -55,16 +65,23 @@
47
48 void QTrashUtilInfo::setInfoFromTrashItem(const QString &absTrashItem)
49 {
50- valid = false;
51- QFileInfo item(absTrashItem);
52- if (item.absolutePath().endsWith(filesDirString))
53+ clear();
54+ //try to guess which is the Trash directory
55+ int trashPathIndex = -1;
56+ int counter = 0;
57+ for (; trashPathIndex == -1 && counter < trashes.count(); ++counter)
58 {
59- QFileInfo filesUnderRoot(item.absolutePath());
60- QTrashUtilInfo::setInfo(filesUnderRoot.absolutePath(), absTrashItem);
61+ trashPathIndex = absTrashItem.indexOf(trashes.at(counter));
62 }
63- else
64+ if (trashPathIndex != -1) //counter -1 points to the item found
65 {
66- clear();
67+ trashPathIndex += trashes.at(counter-1).length();
68+ // it is something under "files/" directory
69+ if (trashPathIndex < absTrashItem.length() && absTrashItem.at(trashPathIndex) == QDir::separator())
70+ {
71+ trashPathIndex -= 6; // 6 is the length of "files/", we want to get the Trash root dir
72+ QTrashUtilInfo::setInfo(absTrashItem.left(trashPathIndex), absTrashItem);
73+ }
74 }
75 }
76
77
78=== modified file 'src/plugin/folderlistmodel/trash/trashiteminfo.cpp'
79--- src/plugin/folderlistmodel/trash/trashiteminfo.cpp 2014-05-17 09:58:10 +0000
80+++ src/plugin/folderlistmodel/trash/trashiteminfo.cpp 2015-07-18 21:48:42 +0000
81@@ -20,9 +20,15 @@
82 */
83
84 #include "trashiteminfo.h"
85+#include "qtrashutilinfo.h"
86 #include "locationurl.h"
87-
88-
89+#include <QDebug>
90+
91+/*!
92+ * \brief TrashItemInfo::TrashItemInfo() This constructor does not receive the Trash path
93+ *
94+ * \param urlPath the full pathname starting with th \a trashPath as "/home/devubuntu/.local/share/Trash/files/test.txt"
95+ */
96 TrashItemInfo::TrashItemInfo(const QString &urlPath)
97 : DirItemInfo()
98 {
99@@ -33,6 +39,22 @@
100 {
101 setRoot();
102 }
103+ else
104+ {
105+ QTrashUtilInfo trashInfo;
106+ trashInfo.setInfoFromTrashItem(urlPath);
107+ //try to guess the Trash path
108+ if (trashInfo.isValid() && !trashInfo.filesDir.isEmpty())
109+ {
110+ //Trash path found
111+ init(trashInfo.filesDir);
112+ }
113+ QFileInfo maybeDiskUrl(urlPath);
114+ if (maybeDiskUrl.exists())
115+ {
116+ d_ptr->setFileInfo(maybeDiskUrl);
117+ }
118+ }
119 }
120
121
122@@ -42,6 +64,12 @@
123 }
124
125
126+/*!
127+ * \brief TrashItemInfo::TrashItemInfo()
128+ *
129+ * \param trashPath the trash PATH finished with "files" like as "/home/user/.local/share/Trash/files"
130+ * \param urlPath the full pathname starting with th \a trashPath as "/home/user/.local/share/Trash/files/test.txt"
131+ */
132 TrashItemInfo::TrashItemInfo(const QString& trashPath, const QString &urlPath)
133 : DirItemInfo(urlPath)
134 {

Subscribers

People subscribed via source and target branches