diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2017-01-27 19:45:05 +0300 |
---|---|---|
committer | Olivier Goffart <ogoffart@woboq.com> | 2017-01-27 19:45:05 +0300 |
commit | 0d16cf41fea41de9bf3bff9ceb8674b2f878c75b (patch) | |
tree | 5c2faff70136c9612f8c8f95cd9fda2231c92ef5 /src/gui/folderstatusmodel.cpp | |
parent | 4f28b2daadd0a902a955325b6de9f93ba356f611 (diff) | |
parent | 65e4afedc4034886463a46885186a9e813e957ba (diff) |
Merge remote-tracking branch 'origin/master' into 2.3
We can do that because the only changes that were in master but not in 2.3 were the
translations change and documentation change, and the support for the 'M' permission
which we want in 2.3.
Diffstat (limited to 'src/gui/folderstatusmodel.cpp')
-rw-r--r-- | src/gui/folderstatusmodel.cpp | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index c8b5c4925..dc9acce8d 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -29,6 +29,14 @@ Q_DECLARE_METATYPE(QPersistentModelIndex) namespace OCC { static const char propertyParentIndexC[] = "oc_parentIndex"; +static const char propertyPermissionMap[] = "oc_permissionMap"; + +static QString removeTrailingSlash(const QString &s) { + if (s.endsWith('/')) { + return s.left(s.size() - 1); + } + return s; +} FolderStatusModel::FolderStatusModel(QObject *parent) :QAbstractItemModel(parent), _accountState(0), _dirty(false) @@ -162,7 +170,7 @@ QVariant FolderStatusModel::data(const QModelIndex &index, int role) const case Qt::CheckStateRole: return x._checked; case Qt::DecorationRole: - return QFileIconProvider().icon(QFileIconProvider::Folder); + return QFileIconProvider().icon(x._isExternal ? QFileIconProvider::Network : QFileIconProvider::Folder); case Qt::ForegroundRole: if (x._isUndecided) { return QColor(Qt::red); @@ -368,6 +376,9 @@ FolderStatusModel::SubFolderInfo* FolderStatusModel::infoForIndex(const QModelIn if (parentInfo->hasLabel()) { return 0; } + if (index.row() >= parentInfo->_subs.size()) { + return 0; + } return &parentInfo->_subs[index.row()]; } else { if (index.row() >= _folders.count()) { @@ -537,12 +548,15 @@ void FolderStatusModel::fetchMore(const QModelIndex& parent) path += info->_path; } LsColJob *job = new LsColJob(_accountState->account(), path, this); - job->setProperties(QList<QByteArray>() << "resourcetype" << "http://owncloud.org/ns:size"); + job->setProperties(QList<QByteArray>() << "resourcetype" << "http://owncloud.org/ns:size" << "http://owncloud.org/ns:permissions"); job->setTimeout(60 * 1000); connect(job, SIGNAL(directoryListingSubfolders(QStringList)), SLOT(slotUpdateDirectories(QStringList))); connect(job, SIGNAL(finishedWithError(QNetworkReply*)), this, SLOT(slotLscolFinishedWithError(QNetworkReply*))); + connect(job, SIGNAL(directoryListingIterated(const QString&, const QMap<QString,QString>&)), + this, SLOT(slotGatherPermissions(const QString&, const QMap<QString,QString>&))); + job->start(); QPersistentModelIndex persistentIndex(parent); @@ -553,6 +567,20 @@ void FolderStatusModel::fetchMore(const QModelIndex& parent) QTimer::singleShot(1000, this, SLOT(slotShowFetchProgress())); } +void FolderStatusModel::slotGatherPermissions(const QString &href, const QMap<QString,QString> &map) +{ + auto it = map.find("permissions"); + if (it == map.end()) + return; + + auto job = sender(); + auto permissionMap = job->property(propertyPermissionMap).toMap(); + job->setProperty(propertyPermissionMap, QVariant()); // avoid a detach of the map while it is modified + Q_ASSERT(!href.endsWith(QLatin1Char('/'))); // LsColXMLParser::parse removes the trailing slash before calling us. + permissionMap[href] = *it; + job->setProperty(propertyPermissionMap, permissionMap); +} + void FolderStatusModel::slotUpdateDirectories(const QStringList &list) { auto job = qobject_cast<LsColJob *>(sender()); @@ -598,6 +626,7 @@ void FolderStatusModel::slotUpdateDirectories(const QStringList &list) selectiveSyncUndecidedSet.insert(str); } } + const auto permissionMap = job->property(propertyPermissionMap).toMap(); QStringList sortedSubfolders = list; // skip the parent item (first in the list) @@ -618,8 +647,8 @@ void FolderStatusModel::slotUpdateDirectories(const QStringList &list) newInfo._folder = parentInfo->_folder; newInfo._pathIdx = parentInfo->_pathIdx; newInfo._pathIdx << newSubs.size(); - auto size = job ? job->_sizes.value(path) : 0; - newInfo._size = size; + newInfo._size = job->_sizes.value(path); + newInfo._isExternal = permissionMap.value(removeTrailingSlash(path)).toString().contains("M"); newInfo._path = relativePath; newInfo._name = relativePath.split('/', QString::SkipEmptyParts).last(); |