Merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-01 into lp:ubuntu-filemanager-app

Proposed by Carlos Jose Mazieri
Status: Merged
Approved by: Arto Jalkanen
Approved revision: 387
Merged at revision: 395
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-01
Merge into: lp:ubuntu-filemanager-app
Diff against target: 472 lines (+304/-13)
4 files modified
src/plugin/folderlistmodel/diriteminfo.cpp (+246/-1)
src/plugin/folderlistmodel/diriteminfo.h (+22/-4)
src/plugin/folderlistmodel/dirmodel.cpp (+31/-8)
src/plugin/folderlistmodel/dirmodel.h (+5/-0)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-01
Reviewer Review Type Date Requested Status
Arto Jalkanen Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+252216@code.launchpad.net

Commit message

Class DirItemInfo which represents items being shown receives more attributes suitable for network like: DirItemInfo::isHost(), DirItemInfo::Browsable() and DirItemInfo::isSharedDir(); DirItemInfo::isShare() and DirItemInfo::isWorkgroup() are related to samba only.

Description of the change

This starts a series of MPs that provides samba browsing in the filemanager plugin.
There will be some samba-browsing-nn MPs until a samba-browsing-final from where it should be possible to browse a properly configured samba network by entering url "smb://" or "cifs://".

These changes provide browsing only, the development for samba Actions (copy/cut/pate, remove) will start next.

MPs from 01 to 03 are introduce new "Item Properties" and some refactoring to allow others network protocols be easily implemented.

Class DirItemInfo which represents items being shown receives more attributes suitable for network like: DirItemInfo::isHost(), DirItemInfo::Browsable() and DirItemInfo::isSharedDir(); DirItemInfo::isShare() and DirItemInfo::isWorkgroup() are related to samba 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: Approve (continuous-integration)
Revision history for this message
Arto Jalkanen (ajalkane) wrote :

Please fix the few issues I inlined in comments.

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

Thanks, I will fix that.

387. By Carlos Jose Mazieri

Fixed DirItemInfo::removeExtraSlashes() using now QString::indexOf(QLatin1String(":/") to prevent common files using ':' in the names
Fixed documentation from DirItemInfo::fillFromStatBuf()
Expanded some if without space as "if(" to "if (" in class DirModel

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/diriteminfo.cpp'
2--- src/plugin/folderlistmodel/diriteminfo.cpp 2014-05-09 21:03:22 +0000
3+++ src/plugin/folderlistmodel/diriteminfo.cpp 2015-03-16 21:40:07 +0000
4@@ -20,6 +20,8 @@
5 */
6
7 #include "diriteminfo.h"
8+#include <sys/types.h>
9+#include <sys/stat.h>
10
11
12 QMimeDatabase DirItemInfoPrivate::mimeDatabase;
13@@ -32,12 +34,18 @@
14 ,_isSelected(false)
15 ,_isAbsolute(false)
16 ,_exists(false)
17+ ,_isFile(false)
18 ,_isDir(false)
19 ,_isSymLink(false)
20 ,_isRoot(false)
21 ,_isReadable(false)
22 ,_isWritable(false)
23 ,_isExecutable(false)
24+ ,_isLocalSharedDir(false)
25+ ,_isHost(false)
26+ ,_isWorkGroup(false)
27+ ,_isNetworkShare(false)
28+ ,_needsAuthentication(false)
29 ,_permissions(0)
30 ,_size(0)
31 {
32@@ -53,19 +61,26 @@
33 ,_isSelected(other._isSelected)
34 ,_isAbsolute(other._isAbsolute)
35 ,_exists(other._exists)
36+ ,_isFile(other._isFile)
37 ,_isDir(other._isDir)
38 ,_isSymLink(other._isSymLink)
39 ,_isRoot(other._isRoot)
40 ,_isReadable(other._isReadable)
41 ,_isWritable(other._isWritable)
42 ,_isExecutable(other._isExecutable)
43+ ,_isLocalSharedDir(other._isLocalSharedDir)
44+ ,_isHost(other._isHost)
45+ ,_isWorkGroup(false)
46+ ,_isNetworkShare(false)
47+ ,_needsAuthentication(false)
48 ,_permissions(other._permissions)
49 ,_size(other._size)
50 ,_created(other._created)
51 ,_lastModified(other._lastModified)
52 ,_lastRead(other._lastRead)
53 ,_path(other._path)
54- ,_fileName(other._fileName)
55+ ,_fileName(other._fileName)
56+ ,_normalizedPath(other._normalizedPath)
57 {
58
59 }
60@@ -76,6 +91,21 @@
61 ,_isLocal(true)
62 ,_isRemote(false)
63 ,_isSelected(false)
64+ ,_isAbsolute(false)
65+ ,_exists(false)
66+ ,_isFile(false)
67+ ,_isDir(false)
68+ ,_isSymLink(false)
69+ ,_isRoot(false)
70+ ,_isReadable(false)
71+ ,_isWritable(false)
72+ ,_isExecutable(false)
73+ ,_isLocalSharedDir(false)
74+ ,_isHost(false)
75+ ,_isWorkGroup(false)
76+ ,_isNetworkShare(false)
77+ ,_needsAuthentication(false)
78+ ,_permissions(0)
79 {
80 setFileInfo(fi);
81 }
82@@ -333,3 +363,218 @@
83 filepath += d_ptr->_fileName;
84 return filepath;
85 }
86+
87+bool DirItemInfo::permission(QFileDevice::Permissions permissions) const
88+{
89+ return (d_ptr->_permissions & permissions) == permissions;
90+}
91+
92+bool DirItemInfo::isSharedDir() const
93+{
94+ return d_ptr->_isLocalSharedDir;
95+}
96+
97+bool DirItemInfo::isHost() const
98+{
99+ return d_ptr->_isHost;
100+}
101+
102+
103+bool DirItemInfo::isWorkGroup() const
104+{
105+ return d_ptr->_isWorkGroup;
106+}
107+
108+bool DirItemInfo::isShare() const
109+{
110+ return d_ptr->_isNetworkShare;
111+}
112+
113+/*!
114+ * \brief DirItemInfo::isBrowsable() considers browsable items that can hold a list of items
115+ * \return
116+ */
117+bool DirItemInfo::isBrowsable() const
118+{
119+ return isDir() || isHost() || isShare() || isWorkGroup();
120+}
121+
122+bool DirItemInfo::needsAuthentication() const
123+{
124+ return d_ptr->_needsAuthentication;
125+}
126+
127+QString DirItemInfo::authenticationPath() const
128+{
129+ return QLatin1String(0);
130+}
131+
132+
133+/*!
134+ * \brief DirItemInfo::fillFromStatBuf() This was copied from \ref QFileSystemMetaData::fillFromStatBuf()
135+ * \param statBuffer
136+ */
137+void DirItemInfo::fillFromStatBuf(const struct stat & statBuffer)
138+{
139+#define LinkType 0x00010000
140+#define FileType 0x00020000
141+#define DirectoryType 0x00040000
142+#define SequentialType 0x00800000
143+
144+ //size
145+ d_ptr->_size = statBuffer.st_size;
146+ //times
147+ d_ptr->_lastModified = statBuffer.st_mtime ?
148+ QDateTime::fromTime_t(statBuffer.st_mtime) :
149+ QDateTime(QDate(), QTime());
150+ d_ptr->_created = statBuffer.st_ctime ?
151+ QDateTime::fromTime_t(statBuffer.st_ctime) :
152+ d_ptr->_lastModified ;
153+ d_ptr->_lastRead = statBuffer.st_atime ?
154+ QDateTime::fromTime_t(statBuffer.st_atime) :
155+ d_ptr->_lastModified;
156+
157+ /*
158+ //user, group
159+ userId_ = statBuffer.st_uid;
160+ groupId_ = statBuffer.st_gid;
161+ */
162+
163+ /*
164+ * When handling filesystems other than local (e.g. any network)
165+ * Permissions are relative to the user being used to access the resource
166+ *
167+ * So it is necessary to qualify the user accessing the resource as
168+ * owner / belongs to group or / others
169+ */
170+ // quint32 userMatches = 0;
171+ QFile::Permissions readPermission = 0;
172+ QFile::Permissions writePermission = 0;
173+ QFile::Permissions execPermission = 0;
174+
175+
176+ //owner permissions
177+ if (statBuffer.st_mode & S_IRUSR)
178+ {
179+ readPermission |= QFile::ReadOwner;
180+ }
181+ if (statBuffer.st_mode & S_IWUSR)
182+ {
183+ writePermission |= QFile::WriteOwner;
184+ }
185+ if (statBuffer.st_mode & S_IXUSR)
186+ {
187+ execPermission |= QFile::ExeOwner;
188+ }
189+ //group permissions
190+ if (statBuffer.st_mode & S_IRGRP)
191+ {
192+ readPermission |= QFile::ReadGroup;
193+ }
194+ if (statBuffer.st_mode & S_IWGRP)
195+ {
196+ writePermission |= QFile::WriteGroup;
197+ }
198+ if (statBuffer.st_mode & S_IXGRP)
199+ {
200+ execPermission |= QFile::ExeGroup;
201+ }
202+ //other permissions
203+ if (statBuffer.st_mode & S_IROTH)
204+ {
205+ readPermission |= QFile::ReadOther;
206+ }
207+ if (statBuffer.st_mode & S_IWOTH)
208+ {
209+ writePermission |= QFile::WriteOther;
210+ }
211+ if (statBuffer.st_mode & S_IXOTH)
212+ {
213+ execPermission |= QFile::ExeOther;
214+ }
215+
216+ /*
217+ * Permissions are relative to a remote user
218+ * it was necessary to be the user being accessing the file
219+ */
220+ if (readPermission)
221+ {
222+ d_ptr->_isReadable = true;
223+ }
224+ if (writePermission)
225+ {
226+ d_ptr->_isWritable = true;
227+ }
228+ if (execPermission)
229+ {
230+ d_ptr->_isExecutable = true;
231+ }
232+
233+ //set full permissions flag
234+ d_ptr->_permissions = readPermission | writePermission | execPermission;
235+
236+ // Type
237+ if ((statBuffer.st_mode & S_IFMT) == S_IFREG)
238+ {
239+ // d_ptr->_permissions |= FileType;
240+ d_ptr->_isFile = true;
241+ }
242+ else if ((statBuffer.st_mode & S_IFMT) == S_IFDIR)
243+ {
244+ // d_ptr->_permissions |= DirectoryType;
245+ d_ptr->_isDir = true;
246+ }
247+ else
248+ {
249+ // d_ptr->_permissions |= SequentialType;
250+ }
251+}
252+
253+
254+
255+QString DirItemInfo::removeExtraSlashes(const QString &url, int firstSlashIndex)
256+{
257+ QString ret;
258+ if (firstSlashIndex == -1)
259+ {
260+ firstSlashIndex = url.indexOf(QLatin1String(":/"));
261+ if (firstSlashIndex != -1)
262+ {
263+ ++firstSlashIndex;
264+ }
265+ else
266+ {
267+ firstSlashIndex = -1;
268+ }
269+ }
270+ if (firstSlashIndex >=0)
271+ {
272+ while ( firstSlashIndex < url.length() && url.at(firstSlashIndex) == QDir::separator())
273+ {
274+ ++firstSlashIndex;
275+ }
276+ if (firstSlashIndex < url.length())
277+ {
278+ ret = url.mid(firstSlashIndex);
279+ }
280+ }
281+ else
282+ {
283+ ret = url;
284+ firstSlashIndex = -1;
285+ }
286+ if (firstSlashIndex >= 0 && ret.endsWith(QDir::separator()))
287+ {
288+ ret.chop(1);
289+ }
290+ //replace any double slashes by just one
291+ for(int charCounter = ret.size() -1; charCounter > 0; --charCounter)
292+ {
293+ if (ret.at(charCounter) == QDir::separator() &&
294+ ret.at(charCounter-1) == QDir::separator())
295+ {
296+ ret.remove(charCounter,1);
297+ }
298+ }
299+ return ret;
300+}
301
302=== modified file 'src/plugin/folderlistmodel/diriteminfo.h'
303--- src/plugin/folderlistmodel/diriteminfo.h 2014-05-18 18:09:04 +0000
304+++ src/plugin/folderlistmodel/diriteminfo.h 2015-03-16 21:40:07 +0000
305@@ -101,16 +101,26 @@
306 virtual QDateTime lastModified() const;
307 virtual QDateTime lastRead() const;
308 virtual QMimeType mimeType() const;
309+ virtual bool isHost() const;
310+ virtual bool isSharedDir() const;
311+ virtual bool isWorkGroup() const;
312+ virtual bool isShare() const;
313+ virtual bool isBrowsable() const;
314+ virtual bool needsAuthentication() const;
315+ virtual QString authenticationPath() const;
316+ virtual void setFile(const QString &dir, const QString & file);
317+ virtual bool permission(QFile::Permissions permissions) const;
318+ void fillFromStatBuf(const struct stat& statBuffer);
319
320- virtual void setFile(const QString &dir, const QString & file);
321+public:
322+ static QString removeExtraSlashes(const QString &url, int firstSlashIndex = -1);
323
324 #if 0
325 virtual QString path() const;
326 virtual QString owner() const;
327 virtual uint ownerId() const;
328 virtual QString group() const;
329- virtual uint groupId() const;
330- virtual bool permission(QFile::Permissions permissions) const;
331+ virtual uint groupId() const;
332 #endif
333
334 protected:
335@@ -149,7 +159,14 @@
336 bool _isRoot :1;
337 bool _isReadable :1;
338 bool _isWritable :1;
339- bool _isExecutable:1;
340+ bool _isExecutable:1;
341+ bool _isLocalSharedDir :1; //!< the directory in the local disk is shared folder (perhaps using Samba)
342+ bool _isHost :1; //!< the item points to a host like fish://localhost, smb://10.10.200.1, etc.
343+ bool _isWorkGroup :1; //!< specific to Samba
344+ bool _isNetworkShare :1; //!< samba share (entry point)
345+ bool _needsAuthentication:1;//!< the url may require authentication do access
346+
347+
348 QFile::Permissions _permissions;
349 qint64 _size;
350 QDateTime _created;
351@@ -158,6 +175,7 @@
352 QString _path;
353 QString _fileName;
354 QString _normalizedPath;
355+
356 static QMimeDatabase mimeDatabase;
357 };
358
359
360=== modified file 'src/plugin/folderlistmodel/dirmodel.cpp'
361--- src/plugin/folderlistmodel/dirmodel.cpp 2015-01-01 20:43:56 +0000
362+++ src/plugin/folderlistmodel/dirmodel.cpp 2015-03-16 21:40:07 +0000
363@@ -216,7 +216,12 @@
364 roles.insert(FileSizeRole, QByteArray("fileSize"));
365 roles.insert(IconSourceRole, QByteArray("iconSource"));
366 roles.insert(FilePathRole, QByteArray("filePath"));
367- roles.insert(IsDirRole, QByteArray("isDir"));
368+ roles.insert(IsDirRole, QByteArray("isDir"));
369+ roles.insert(IsHostRole, QByteArray("isHost"));
370+ roles.insert(IsSmbWorkgroupRole, QByteArray("IsSmbWorkgroup"));
371+ roles.insert(IsSmbShareRole, QByteArray("IsSmbShare"));
372+ roles.insert(IsSharedDirRole, QByteArray("IsSharedDir"));
373+ roles.insert(IsSharingAllowedRole, QByteArray("IsSharingAllowed"));
374 roles.insert(IsFileRole, QByteArray("isFile"));
375 roles.insert(IsReadableRole, QByteArray("isReadable"));
376 roles.insert(IsWritableRole, QByteArray("isWritable"));
377@@ -268,7 +273,7 @@
378 {
379 QIcon icon;
380 QMimeType mime = mDirectoryContents.at(index.row()).mimeType();
381- if (mime.isValid())
382+ if (mime.isValid() && mDirectoryContents.at(index.row()).isLocal())
383 {
384 if (QIcon::hasThemeIcon(mime.iconName()) ) {
385 icon = QIcon::fromTheme(mime.iconName());
386@@ -333,9 +338,15 @@
387 case ModifiedDateRole:
388 return fi.lastModified();
389 case FileSizeRole: {
390- if (fi.isDir() && fi.isLocal())
391+ if (fi.isBrowsable())
392 {
393- return dirItems(fi.diskFileInfo());
394+ if (fi.isLocal())
395+ {
396+ return dirItems(fi.diskFileInfo());
397+ }
398+ //it is possible to browse network folders and get its
399+ //number of items, but it may take longer
400+ return tr("unkown");
401 }
402 return fileSize(fi.size());
403 }
404@@ -357,7 +368,7 @@
405 case IsDirRole:
406 return fi.isDir();
407 case IsFileRole:
408- return !fi.isDir();
409+ return !fi.isBrowsable();
410 case IsReadableRole:
411 return fi.isReadable();
412 case IsWritableRole:
413@@ -366,6 +377,18 @@
414 return fi.isExecutable();
415 case IsSelectedRole:
416 return fi.isSelected();
417+ case IsHostRole:
418+ return fi.isHost();
419+ case IsSmbWorkgroupRole:
420+ return fi.isWorkGroup();
421+ case IsSmbShareRole:
422+ return fi.isShare();
423+ case IsSharingAllowedRole:
424+ return fi.isDir() && !fi.isSymLink() && !fi.isSharedDir()
425+ && mCurLocation->type() == LocationsFactory::LocalDisk
426+ && fi.isWritable() && fi.isExecutable() && fi.isReadable();
427+ case IsSharedDirRole:
428+ return fi.isSharedDir();
429 #ifndef DO_NOT_USE_TAG_LIB
430 case TrackTitleRole:
431 case TrackArtistRole:
432@@ -388,7 +411,7 @@
433 qWarning() << Q_FUNC_INFO << this << "Got an unknown role: " << role;
434 #endif
435 break;
436- }
437+ }//switch (role)
438
439 return QVariant();
440 }
441@@ -1779,13 +1802,13 @@
442 case TrackGenreRole:
443 return QString::fromUtf8(tag->genre().toCString(true));
444 case TrackLengthRole:
445- if(!f.isNull() && f.audioProperties()) {
446+ if (!f.isNull() && f.audioProperties()) {
447 return QString::number(f.audioProperties()->length());
448 } else {
449 return QString::number(0);
450 }
451 case TrackCoverRole:
452- if(!list.isEmpty()) {
453+ if (!list.isEmpty()) {
454 TagLib::ID3v2::AttachedPictureFrame *Pic = static_cast<TagLib::ID3v2::AttachedPictureFrame *>(list.front());
455 QImage img;
456 img.loadFromData((const uchar *) Pic->picture().data(), Pic->picture().size());
457
458=== modified file 'src/plugin/folderlistmodel/dirmodel.h'
459--- src/plugin/folderlistmodel/dirmodel.h 2015-01-01 20:43:56 +0000
460+++ src/plugin/folderlistmodel/dirmodel.h 2015-03-16 21:40:07 +0000
461@@ -62,6 +62,11 @@
462 IconSourceRole,
463 FilePathRole,
464 IsDirRole,
465+ IsHostRole, //!< it can also be used for other protocols than smb/cifs
466+ IsSmbWorkgroupRole,
467+ IsSmbShareRole,
468+ IsSharedDirRole, //!< it can also be used for other protocols than smb/cifs
469+ IsSharingAllowedRole,//!< true for local directories (not in Trash) and not IsSharedDirRole
470 IsFileRole,
471 IsReadableRole,
472 IsWritableRole,

Subscribers

People subscribed via source and target branches