[CSE] Fetch file-id for subfolders

File id is a must if we want to call any API.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
Tomaz Canabrava 2017-08-25 13:56:13 +02:00 committed by Roeland Jago Douma
parent 9318c487b9
commit 9870f39dcb
No known key found for this signature in database
GPG key ID: F941078878347C0C
5 changed files with 24 additions and 12 deletions

View file

@ -554,7 +554,9 @@ void FolderStatusModel::fetchMore(const QModelIndex &parent)
LsColJob *job = new LsColJob(_accountState->account(), path, this);
job->setProperties(QList<QByteArray>() << "resourcetype"
<< "http://owncloud.org/ns:size"
<< "http://owncloud.org/ns:permissions");
<< "http://owncloud.org/ns:permissions"
<< "http://owncloud.org/ns:fileid");
job->setTimeout(60 * 1000);
connect(job, &LsColJob::directoryListingSubfolders,
this, &FolderStatusModel::slotUpdateDirectories);
@ -655,11 +657,13 @@ void FolderStatusModel::slotUpdateDirectories(const QStringList &list)
newInfo._folder = parentInfo->_folder;
newInfo._pathIdx = parentInfo->_pathIdx;
newInfo._pathIdx << newSubs.size();
newInfo._size = job->_sizes.value(path);
newInfo._isExternal = permissionMap.value(removeTrailingSlash(path)).toString().contains("M");
newInfo._path = relativePath;
newInfo._name = removeTrailingSlash(relativePath).split('/').last();
const auto& folderInfo = job->_folderInfos.value(path);
newInfo._size = folderInfo.size;
newInfo._fileId = folderInfo.fileId;
if (relativePath.isEmpty())
continue;

View file

@ -79,9 +79,9 @@ public:
bool _hasError; // If the last fetching job ended in an error
QString _lastErrorString;
bool _fetchingLabel; // Whether a 'fetching in progress' label is shown.
// undecided folders are the big folders that the user has not accepted yet
bool _isUndecided;
QByteArray _fileId; // the file id for this folder on the server.
Qt::CheckState _checked;
@ -168,7 +168,6 @@ signals:
// Tell the view that this item should be expanded because it has an undecided item
void suggestExpand(const QModelIndex &);
friend struct SubFolderInfo;
};

View file

@ -235,7 +235,7 @@ void SelectiveSyncWidget::slotUpdateDirectories(QStringList list)
root->setIcon(0, Theme::instance()->applicationIcon());
root->setData(0, Qt::UserRole, QString());
root->setCheckState(0, Qt::Checked);
qint64 size = job ? job->_sizes.value(pathToRemove, -1) : -1;
qint64 size = job ? job->_folderInfos[pathToRemove].size : -1;
if (size >= 0) {
root->setText(1, Utility::octetsToString(size));
root->setData(1, Qt::UserRole, size);
@ -244,7 +244,7 @@ void SelectiveSyncWidget::slotUpdateDirectories(QStringList list)
Utility::sortFilenames(list);
foreach (QString path, list) {
auto size = job ? job->_sizes.value(path) : 0;
auto size = job ? job->_folderInfos[path].size : 0;
path.remove(pathToRemove);
QStringList paths = path.split('/');
if (paths.last().isEmpty())

View file

@ -185,7 +185,7 @@ LsColXMLParser::LsColXMLParser()
{
}
bool LsColXMLParser::parse(const QByteArray &xml, QHash<QString, qint64> *sizes, const QString &expectedPath)
bool LsColXMLParser::parse(const QByteArray &xml, QHash<QString, ExtraFolderInfo> *fileInfo, const QString &expectedPath)
{
// Parse DAV response
QXmlStreamReader reader(xml);
@ -241,9 +241,11 @@ bool LsColXMLParser::parse(const QByteArray &xml, QHash<QString, qint64> *sizes,
} else if (name == QLatin1String("size")) {
bool ok = false;
auto s = propertyContent.toLongLong(&ok);
if (ok && sizes) {
sizes->insert(currentHref, s);
if (ok && fileInfo) {
(*fileInfo)[currentHref].size = s;
}
} else if (name == QLatin1String("fileid")) {
(*fileInfo)[currentHref].fileId = propertyContent.toUtf8();
}
currentTmpProperties.insert(reader.name().toString(), propertyContent);
}
@ -372,7 +374,7 @@ bool LsColJob::finished()
this, &LsColJob::finishedWithoutError);
QString expectedPath = reply()->request().url().path(); // something like "/owncloud/remote.php/webdav/folder"
if (!parser.parse(reply()->readAll(), &_sizes, expectedPath)) {
if (!parser.parse(reply()->readAll(), &_folderInfos, expectedPath)) {
// XML parse error
emit finishedWithError(reply());
}

View file

@ -41,6 +41,11 @@ private slots:
virtual bool finished() Q_DECL_OVERRIDE;
};
struct ExtraFolderInfo {
QByteArray fileId;
qint64 size = -1;
};
/**
* @brief The LsColJob class
* @ingroup libsync
@ -51,7 +56,9 @@ class OWNCLOUDSYNC_EXPORT LsColXMLParser : public QObject
public:
explicit LsColXMLParser();
bool parse(const QByteArray &xml, QHash<QString, qint64> *sizes, const QString &expectedPath);
bool parse(const QByteArray &xml,
QHash<QString, ExtraFolderInfo> *sizes,
const QString &expectedPath);
signals:
void directoryListingSubfolders(const QStringList &items);
@ -67,7 +74,7 @@ public:
explicit LsColJob(AccountPtr account, const QString &path, QObject *parent = 0);
explicit LsColJob(AccountPtr account, const QUrl &url, QObject *parent = 0);
void start() Q_DECL_OVERRIDE;
QHash<QString, qint64> _sizes;
QHash<QString, ExtraFolderInfo> _folderInfos;
/**
* Used to specify which properties shall be retrieved.