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)
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);
if (parentInfo->hasLabel()) {
return 0;
}
+ if (index.row() >= parentInfo->_subs.size()) {
+ return 0;
+ }
return &parentInfo->_subs[index.row()];
} else {
if (index.row() >= _folders.count()) {
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);
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());
selectiveSyncUndecidedSet.insert(str);
}
}
+ const auto permissionMap = job->property(propertyPermissionMap).toMap();
QStringList sortedSubfolders = list;
// skip the parent item (first in the 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();
struct SubFolderInfo {
SubFolderInfo()
- : _folder(0), _size(0), _fetched(false), _fetching(false),
+ : _folder(0), _size(0), _isExternal(false), _fetched(false), _fetching(false),
_hasError(false), _fetchingLabel(false), _isUndecided(false), _checked(Qt::Checked) {}
Folder *_folder;
QString _name;
QVector<int> _pathIdx;
QVector<SubFolderInfo> _subs;
qint64 _size;
+ bool _isExternal;
bool _fetched; // If we did the LSCOL for this folder already
bool _fetching; // Whether a LSCOL job is currently running
private slots:
void slotUpdateDirectories(const QStringList &);
+ void slotGatherPermissions(const QString &name, const QMap<QString,QString> &properties);
void slotLscolFinishedWithError(QNetworkReply *r);
void slotFolderSyncStateChange(Folder* f);
void slotFolderScheduleQueueChanged();