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
=== modified file 'src/plugin/folderlistmodel/diriteminfo.cpp'
--- src/plugin/folderlistmodel/diriteminfo.cpp 2014-05-09 21:03:22 +0000
+++ src/plugin/folderlistmodel/diriteminfo.cpp 2015-03-16 21:40:07 +0000
@@ -20,6 +20,8 @@
20 */20 */
2121
22#include "diriteminfo.h"22#include "diriteminfo.h"
23#include <sys/types.h>
24#include <sys/stat.h>
2325
2426
25QMimeDatabase DirItemInfoPrivate::mimeDatabase;27QMimeDatabase DirItemInfoPrivate::mimeDatabase;
@@ -32,12 +34,18 @@
32 ,_isSelected(false)34 ,_isSelected(false)
33 ,_isAbsolute(false)35 ,_isAbsolute(false)
34 ,_exists(false)36 ,_exists(false)
37 ,_isFile(false)
35 ,_isDir(false)38 ,_isDir(false)
36 ,_isSymLink(false)39 ,_isSymLink(false)
37 ,_isRoot(false)40 ,_isRoot(false)
38 ,_isReadable(false)41 ,_isReadable(false)
39 ,_isWritable(false)42 ,_isWritable(false)
40 ,_isExecutable(false)43 ,_isExecutable(false)
44 ,_isLocalSharedDir(false)
45 ,_isHost(false)
46 ,_isWorkGroup(false)
47 ,_isNetworkShare(false)
48 ,_needsAuthentication(false)
41 ,_permissions(0)49 ,_permissions(0)
42 ,_size(0)50 ,_size(0)
43{51{
@@ -53,19 +61,26 @@
53 ,_isSelected(other._isSelected)61 ,_isSelected(other._isSelected)
54 ,_isAbsolute(other._isAbsolute)62 ,_isAbsolute(other._isAbsolute)
55 ,_exists(other._exists)63 ,_exists(other._exists)
64 ,_isFile(other._isFile)
56 ,_isDir(other._isDir)65 ,_isDir(other._isDir)
57 ,_isSymLink(other._isSymLink)66 ,_isSymLink(other._isSymLink)
58 ,_isRoot(other._isRoot)67 ,_isRoot(other._isRoot)
59 ,_isReadable(other._isReadable)68 ,_isReadable(other._isReadable)
60 ,_isWritable(other._isWritable)69 ,_isWritable(other._isWritable)
61 ,_isExecutable(other._isExecutable)70 ,_isExecutable(other._isExecutable)
71 ,_isLocalSharedDir(other._isLocalSharedDir)
72 ,_isHost(other._isHost)
73 ,_isWorkGroup(false)
74 ,_isNetworkShare(false)
75 ,_needsAuthentication(false)
62 ,_permissions(other._permissions)76 ,_permissions(other._permissions)
63 ,_size(other._size)77 ,_size(other._size)
64 ,_created(other._created)78 ,_created(other._created)
65 ,_lastModified(other._lastModified)79 ,_lastModified(other._lastModified)
66 ,_lastRead(other._lastRead)80 ,_lastRead(other._lastRead)
67 ,_path(other._path)81 ,_path(other._path)
68 ,_fileName(other._fileName)82 ,_fileName(other._fileName)
83 ,_normalizedPath(other._normalizedPath)
69{84{
7085
71}86}
@@ -76,6 +91,21 @@
76 ,_isLocal(true)91 ,_isLocal(true)
77 ,_isRemote(false)92 ,_isRemote(false)
78 ,_isSelected(false)93 ,_isSelected(false)
94 ,_isAbsolute(false)
95 ,_exists(false)
96 ,_isFile(false)
97 ,_isDir(false)
98 ,_isSymLink(false)
99 ,_isRoot(false)
100 ,_isReadable(false)
101 ,_isWritable(false)
102 ,_isExecutable(false)
103 ,_isLocalSharedDir(false)
104 ,_isHost(false)
105 ,_isWorkGroup(false)
106 ,_isNetworkShare(false)
107 ,_needsAuthentication(false)
108 ,_permissions(0)
79{109{
80 setFileInfo(fi);110 setFileInfo(fi);
81}111}
@@ -333,3 +363,218 @@
333 filepath += d_ptr->_fileName;363 filepath += d_ptr->_fileName;
334 return filepath;364 return filepath;
335}365}
366
367bool DirItemInfo::permission(QFileDevice::Permissions permissions) const
368{
369 return (d_ptr->_permissions & permissions) == permissions;
370}
371
372bool DirItemInfo::isSharedDir() const
373{
374 return d_ptr->_isLocalSharedDir;
375}
376
377bool DirItemInfo::isHost() const
378{
379 return d_ptr->_isHost;
380}
381
382
383bool DirItemInfo::isWorkGroup() const
384{
385 return d_ptr->_isWorkGroup;
386}
387
388bool DirItemInfo::isShare() const
389{
390 return d_ptr->_isNetworkShare;
391}
392
393/*!
394 * \brief DirItemInfo::isBrowsable() considers browsable items that can hold a list of items
395 * \return
396 */
397bool DirItemInfo::isBrowsable() const
398{
399 return isDir() || isHost() || isShare() || isWorkGroup();
400}
401
402bool DirItemInfo::needsAuthentication() const
403{
404 return d_ptr->_needsAuthentication;
405}
406
407QString DirItemInfo::authenticationPath() const
408{
409 return QLatin1String(0);
410}
411
412
413/*!
414 * \brief DirItemInfo::fillFromStatBuf() This was copied from \ref QFileSystemMetaData::fillFromStatBuf()
415 * \param statBuffer
416 */
417void DirItemInfo::fillFromStatBuf(const struct stat & statBuffer)
418{
419#define LinkType 0x00010000
420#define FileType 0x00020000
421#define DirectoryType 0x00040000
422#define SequentialType 0x00800000
423
424 //size
425 d_ptr->_size = statBuffer.st_size;
426 //times
427 d_ptr->_lastModified = statBuffer.st_mtime ?
428 QDateTime::fromTime_t(statBuffer.st_mtime) :
429 QDateTime(QDate(), QTime());
430 d_ptr->_created = statBuffer.st_ctime ?
431 QDateTime::fromTime_t(statBuffer.st_ctime) :
432 d_ptr->_lastModified ;
433 d_ptr->_lastRead = statBuffer.st_atime ?
434 QDateTime::fromTime_t(statBuffer.st_atime) :
435 d_ptr->_lastModified;
436
437 /*
438 //user, group
439 userId_ = statBuffer.st_uid;
440 groupId_ = statBuffer.st_gid;
441 */
442
443 /*
444 * When handling filesystems other than local (e.g. any network)
445 * Permissions are relative to the user being used to access the resource
446 *
447 * So it is necessary to qualify the user accessing the resource as
448 * owner / belongs to group or / others
449 */
450 // quint32 userMatches = 0;
451 QFile::Permissions readPermission = 0;
452 QFile::Permissions writePermission = 0;
453 QFile::Permissions execPermission = 0;
454
455
456 //owner permissions
457 if (statBuffer.st_mode & S_IRUSR)
458 {
459 readPermission |= QFile::ReadOwner;
460 }
461 if (statBuffer.st_mode & S_IWUSR)
462 {
463 writePermission |= QFile::WriteOwner;
464 }
465 if (statBuffer.st_mode & S_IXUSR)
466 {
467 execPermission |= QFile::ExeOwner;
468 }
469 //group permissions
470 if (statBuffer.st_mode & S_IRGRP)
471 {
472 readPermission |= QFile::ReadGroup;
473 }
474 if (statBuffer.st_mode & S_IWGRP)
475 {
476 writePermission |= QFile::WriteGroup;
477 }
478 if (statBuffer.st_mode & S_IXGRP)
479 {
480 execPermission |= QFile::ExeGroup;
481 }
482 //other permissions
483 if (statBuffer.st_mode & S_IROTH)
484 {
485 readPermission |= QFile::ReadOther;
486 }
487 if (statBuffer.st_mode & S_IWOTH)
488 {
489 writePermission |= QFile::WriteOther;
490 }
491 if (statBuffer.st_mode & S_IXOTH)
492 {
493 execPermission |= QFile::ExeOther;
494 }
495
496 /*
497 * Permissions are relative to a remote user
498 * it was necessary to be the user being accessing the file
499 */
500 if (readPermission)
501 {
502 d_ptr->_isReadable = true;
503 }
504 if (writePermission)
505 {
506 d_ptr->_isWritable = true;
507 }
508 if (execPermission)
509 {
510 d_ptr->_isExecutable = true;
511 }
512
513 //set full permissions flag
514 d_ptr->_permissions = readPermission | writePermission | execPermission;
515
516 // Type
517 if ((statBuffer.st_mode & S_IFMT) == S_IFREG)
518 {
519 // d_ptr->_permissions |= FileType;
520 d_ptr->_isFile = true;
521 }
522 else if ((statBuffer.st_mode & S_IFMT) == S_IFDIR)
523 {
524 // d_ptr->_permissions |= DirectoryType;
525 d_ptr->_isDir = true;
526 }
527 else
528 {
529 // d_ptr->_permissions |= SequentialType;
530 }
531}
532
533
534
535QString DirItemInfo::removeExtraSlashes(const QString &url, int firstSlashIndex)
536{
537 QString ret;
538 if (firstSlashIndex == -1)
539 {
540 firstSlashIndex = url.indexOf(QLatin1String(":/"));
541 if (firstSlashIndex != -1)
542 {
543 ++firstSlashIndex;
544 }
545 else
546 {
547 firstSlashIndex = -1;
548 }
549 }
550 if (firstSlashIndex >=0)
551 {
552 while ( firstSlashIndex < url.length() && url.at(firstSlashIndex) == QDir::separator())
553 {
554 ++firstSlashIndex;
555 }
556 if (firstSlashIndex < url.length())
557 {
558 ret = url.mid(firstSlashIndex);
559 }
560 }
561 else
562 {
563 ret = url;
564 firstSlashIndex = -1;
565 }
566 if (firstSlashIndex >= 0 && ret.endsWith(QDir::separator()))
567 {
568 ret.chop(1);
569 }
570 //replace any double slashes by just one
571 for(int charCounter = ret.size() -1; charCounter > 0; --charCounter)
572 {
573 if (ret.at(charCounter) == QDir::separator() &&
574 ret.at(charCounter-1) == QDir::separator())
575 {
576 ret.remove(charCounter,1);
577 }
578 }
579 return ret;
580}
336581
=== modified file 'src/plugin/folderlistmodel/diriteminfo.h'
--- src/plugin/folderlistmodel/diriteminfo.h 2014-05-18 18:09:04 +0000
+++ src/plugin/folderlistmodel/diriteminfo.h 2015-03-16 21:40:07 +0000
@@ -101,16 +101,26 @@
101 virtual QDateTime lastModified() const;101 virtual QDateTime lastModified() const;
102 virtual QDateTime lastRead() const;102 virtual QDateTime lastRead() const;
103 virtual QMimeType mimeType() const;103 virtual QMimeType mimeType() const;
104 virtual bool isHost() const;
105 virtual bool isSharedDir() const;
106 virtual bool isWorkGroup() const;
107 virtual bool isShare() const;
108 virtual bool isBrowsable() const;
109 virtual bool needsAuthentication() const;
110 virtual QString authenticationPath() const;
111 virtual void setFile(const QString &dir, const QString & file);
112 virtual bool permission(QFile::Permissions permissions) const;
113 void fillFromStatBuf(const struct stat& statBuffer);
104114
105 virtual void setFile(const QString &dir, const QString & file);115public:
116 static QString removeExtraSlashes(const QString &url, int firstSlashIndex = -1);
106117
107#if 0118#if 0
108 virtual QString path() const;119 virtual QString path() const;
109 virtual QString owner() const;120 virtual QString owner() const;
110 virtual uint ownerId() const;121 virtual uint ownerId() const;
111 virtual QString group() const;122 virtual QString group() const;
112 virtual uint groupId() const;123 virtual uint groupId() const;
113 virtual bool permission(QFile::Permissions permissions) const;
114#endif124#endif
115125
116protected:126protected:
@@ -149,7 +159,14 @@
149 bool _isRoot :1;159 bool _isRoot :1;
150 bool _isReadable :1;160 bool _isReadable :1;
151 bool _isWritable :1;161 bool _isWritable :1;
152 bool _isExecutable:1;162 bool _isExecutable:1;
163 bool _isLocalSharedDir :1; //!< the directory in the local disk is shared folder (perhaps using Samba)
164 bool _isHost :1; //!< the item points to a host like fish://localhost, smb://10.10.200.1, etc.
165 bool _isWorkGroup :1; //!< specific to Samba
166 bool _isNetworkShare :1; //!< samba share (entry point)
167 bool _needsAuthentication:1;//!< the url may require authentication do access
168
169
153 QFile::Permissions _permissions;170 QFile::Permissions _permissions;
154 qint64 _size;171 qint64 _size;
155 QDateTime _created;172 QDateTime _created;
@@ -158,6 +175,7 @@
158 QString _path;175 QString _path;
159 QString _fileName;176 QString _fileName;
160 QString _normalizedPath;177 QString _normalizedPath;
178
161 static QMimeDatabase mimeDatabase;179 static QMimeDatabase mimeDatabase;
162};180};
163181
164182
=== modified file 'src/plugin/folderlistmodel/dirmodel.cpp'
--- src/plugin/folderlistmodel/dirmodel.cpp 2015-01-01 20:43:56 +0000
+++ src/plugin/folderlistmodel/dirmodel.cpp 2015-03-16 21:40:07 +0000
@@ -216,7 +216,12 @@
216 roles.insert(FileSizeRole, QByteArray("fileSize"));216 roles.insert(FileSizeRole, QByteArray("fileSize"));
217 roles.insert(IconSourceRole, QByteArray("iconSource"));217 roles.insert(IconSourceRole, QByteArray("iconSource"));
218 roles.insert(FilePathRole, QByteArray("filePath"));218 roles.insert(FilePathRole, QByteArray("filePath"));
219 roles.insert(IsDirRole, QByteArray("isDir"));219 roles.insert(IsDirRole, QByteArray("isDir"));
220 roles.insert(IsHostRole, QByteArray("isHost"));
221 roles.insert(IsSmbWorkgroupRole, QByteArray("IsSmbWorkgroup"));
222 roles.insert(IsSmbShareRole, QByteArray("IsSmbShare"));
223 roles.insert(IsSharedDirRole, QByteArray("IsSharedDir"));
224 roles.insert(IsSharingAllowedRole, QByteArray("IsSharingAllowed"));
220 roles.insert(IsFileRole, QByteArray("isFile"));225 roles.insert(IsFileRole, QByteArray("isFile"));
221 roles.insert(IsReadableRole, QByteArray("isReadable"));226 roles.insert(IsReadableRole, QByteArray("isReadable"));
222 roles.insert(IsWritableRole, QByteArray("isWritable"));227 roles.insert(IsWritableRole, QByteArray("isWritable"));
@@ -268,7 +273,7 @@
268 { 273 {
269 QIcon icon; 274 QIcon icon;
270 QMimeType mime = mDirectoryContents.at(index.row()).mimeType();275 QMimeType mime = mDirectoryContents.at(index.row()).mimeType();
271 if (mime.isValid())276 if (mime.isValid() && mDirectoryContents.at(index.row()).isLocal())
272 {277 {
273 if (QIcon::hasThemeIcon(mime.iconName()) ) {278 if (QIcon::hasThemeIcon(mime.iconName()) ) {
274 icon = QIcon::fromTheme(mime.iconName());279 icon = QIcon::fromTheme(mime.iconName());
@@ -333,9 +338,15 @@
333 case ModifiedDateRole:338 case ModifiedDateRole:
334 return fi.lastModified();339 return fi.lastModified();
335 case FileSizeRole: {340 case FileSizeRole: {
336 if (fi.isDir() && fi.isLocal())341 if (fi.isBrowsable())
337 {342 {
338 return dirItems(fi.diskFileInfo());343 if (fi.isLocal())
344 {
345 return dirItems(fi.diskFileInfo());
346 }
347 //it is possible to browse network folders and get its
348 //number of items, but it may take longer
349 return tr("unkown");
339 }350 }
340 return fileSize(fi.size());351 return fileSize(fi.size());
341 }352 }
@@ -357,7 +368,7 @@
357 case IsDirRole:368 case IsDirRole:
358 return fi.isDir();369 return fi.isDir();
359 case IsFileRole:370 case IsFileRole:
360 return !fi.isDir();371 return !fi.isBrowsable();
361 case IsReadableRole:372 case IsReadableRole:
362 return fi.isReadable();373 return fi.isReadable();
363 case IsWritableRole:374 case IsWritableRole:
@@ -366,6 +377,18 @@
366 return fi.isExecutable();377 return fi.isExecutable();
367 case IsSelectedRole:378 case IsSelectedRole:
368 return fi.isSelected();379 return fi.isSelected();
380 case IsHostRole:
381 return fi.isHost();
382 case IsSmbWorkgroupRole:
383 return fi.isWorkGroup();
384 case IsSmbShareRole:
385 return fi.isShare();
386 case IsSharingAllowedRole:
387 return fi.isDir() && !fi.isSymLink() && !fi.isSharedDir()
388 && mCurLocation->type() == LocationsFactory::LocalDisk
389 && fi.isWritable() && fi.isExecutable() && fi.isReadable();
390 case IsSharedDirRole:
391 return fi.isSharedDir();
369#ifndef DO_NOT_USE_TAG_LIB392#ifndef DO_NOT_USE_TAG_LIB
370 case TrackTitleRole:393 case TrackTitleRole:
371 case TrackArtistRole:394 case TrackArtistRole:
@@ -388,7 +411,7 @@
388 qWarning() << Q_FUNC_INFO << this << "Got an unknown role: " << role;411 qWarning() << Q_FUNC_INFO << this << "Got an unknown role: " << role;
389#endif412#endif
390 break;413 break;
391 }414 }//switch (role)
392415
393 return QVariant();416 return QVariant();
394}417}
@@ -1779,13 +1802,13 @@
1779 case TrackGenreRole:1802 case TrackGenreRole:
1780 return QString::fromUtf8(tag->genre().toCString(true));1803 return QString::fromUtf8(tag->genre().toCString(true));
1781 case TrackLengthRole:1804 case TrackLengthRole:
1782 if(!f.isNull() && f.audioProperties()) {1805 if (!f.isNull() && f.audioProperties()) {
1783 return QString::number(f.audioProperties()->length());1806 return QString::number(f.audioProperties()->length());
1784 } else {1807 } else {
1785 return QString::number(0);1808 return QString::number(0);
1786 }1809 }
1787 case TrackCoverRole:1810 case TrackCoverRole:
1788 if(!list.isEmpty()) {1811 if (!list.isEmpty()) {
1789 TagLib::ID3v2::AttachedPictureFrame *Pic = static_cast<TagLib::ID3v2::AttachedPictureFrame *>(list.front());1812 TagLib::ID3v2::AttachedPictureFrame *Pic = static_cast<TagLib::ID3v2::AttachedPictureFrame *>(list.front());
1790 QImage img;1813 QImage img;
1791 img.loadFromData((const uchar *) Pic->picture().data(), Pic->picture().size());1814 img.loadFromData((const uchar *) Pic->picture().data(), Pic->picture().size());
17921815
=== modified file 'src/plugin/folderlistmodel/dirmodel.h'
--- src/plugin/folderlistmodel/dirmodel.h 2015-01-01 20:43:56 +0000
+++ src/plugin/folderlistmodel/dirmodel.h 2015-03-16 21:40:07 +0000
@@ -62,6 +62,11 @@
62 IconSourceRole,62 IconSourceRole,
63 FilePathRole,63 FilePathRole,
64 IsDirRole,64 IsDirRole,
65 IsHostRole, //!< it can also be used for other protocols than smb/cifs
66 IsSmbWorkgroupRole,
67 IsSmbShareRole,
68 IsSharedDirRole, //!< it can also be used for other protocols than smb/cifs
69 IsSharingAllowedRole,//!< true for local directories (not in Trash) and not IsSharedDirRole
65 IsFileRole,70 IsFileRole,
66 IsReadableRole,71 IsReadableRole,
67 IsWritableRole,72 IsWritableRole,

Subscribers

People subscribed via source and target branches