LsColJob: one must now specify the properties

So the discovery phase don't ask for the quota, and the selective sync
don't ask for all the other properties

Issue #2906
This commit is contained in:
Olivier Goffart 2015-03-02 11:00:37 +01:00
parent dc2a919e75
commit bd6769a3fd
5 changed files with 57 additions and 12 deletions

View file

@ -357,6 +357,7 @@ void FolderWizardRemotePath::slotUpdateDirectories(const QStringList &list)
void FolderWizardRemotePath::slotRefreshFolders()
{
LsColJob *job = new LsColJob(_account, "/", this);
job->setProperties(QList<QByteArray>() << "resourcetype");
connect(job, SIGNAL(directoryListingSubfolders(QStringList)),
SLOT(slotUpdateDirectories(QStringList)));
job->start();
@ -367,6 +368,7 @@ void FolderWizardRemotePath::slotItemExpanded(QTreeWidgetItem *item)
{
QString dir = item->data(0, Qt::UserRole).toString();
LsColJob *job = new LsColJob(_account, dir, this);
job->setProperties(QList<QByteArray>() << "resourcetype");
connect(job, SIGNAL(directoryListingSubfolders(QStringList)),
SLOT(slotUpdateDirectories(QStringList)));
job->start();

View file

@ -56,6 +56,7 @@ QSize SelectiveSyncTreeView::sizeHint() const
void SelectiveSyncTreeView::refreshFolders()
{
LsColJob *job = new LsColJob(_account, _folderPath, this);
job->setProperties(QList<QByteArray>() << "resourcetype" << "quota-used-bytes");
connect(job, SIGNAL(directoryListingSubfolders(QStringList)),
this, SLOT(slotUpdateDirectories(QStringList)));
connect(job, SIGNAL(finishedWithError(QNetworkReply*)),

View file

@ -169,6 +169,11 @@ void DiscoverySingleDirectoryJob::start()
{
// Start the actual HTTP job
LsColJob *lsColJob = new LsColJob(_account, _subPath, this);
lsColJob->setProperties(QList<QByteArray>() << "resourcetype" << "getlastmodified"
<< "getcontentlength" << "getetag" << "http://owncloud.org/ns:id"
<< "http://owncloud.org/ns:downloadURL" << "http://owncloud.org/ns:dDC"
<< "http://owncloud.org/ns:permissions");
QObject::connect(lsColJob, SIGNAL(directoryListingIterated(QString,QMap<QString,QString>)),
this, SLOT(directoryListingIteratedSlot(QString,QMap<QString,QString>)));
QObject::connect(lsColJob, SIGNAL(finishedWithError(QNetworkReply*)), this, SLOT(lsJobFinishedWithErrorSlot(QNetworkReply*)));

View file

@ -329,24 +329,44 @@ LsColJob::LsColJob(AccountPtr account, const QString &path, QObject *parent)
{
}
void LsColJob::setProperties(QList<QByteArray> properties)
{
_properties = properties;
}
QList<QByteArray> LsColJob::properties() const
{
return _properties;
}
void LsColJob::start()
{
QList<QByteArray> properties = _properties;
if (properties.isEmpty()) {
qWarning() << "Propfind with no properties!";
}
QByteArray propStr;
foreach (const QByteArray &prop, properties) {
if (prop.contains(':')) {
int colIdx = prop.lastIndexOf(":");
auto ns = prop.left(colIdx);
if (ns == "http://owncloud.org/ns") {
propStr += " <oc:" + prop.mid(colIdx+1) + " />\n";
} else {
propStr += " <" + prop.mid(colIdx+1) + " xmlns=\"" + ns + "\" />\n";
}
} else {
propStr += " <d:" + prop + " />\n";
}
}
QNetworkRequest req;
req.setRawHeader("Depth", "1");
// FIXME The results are delivered without namespace, if this is ever a problem we need to check it..
QByteArray xml("<?xml version=\"1.0\" ?>\n"
"<d:propfind xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\">\n"
" <d:prop>\n"
" <d:resourcetype/>\n"
" <d:quota-used-bytes/>\n"
" <d:getlastmodified/>\n"
" <d:getcontentlength/>\n"
" <d:resourcetype/>\n"
" <d:getetag/>\n"
" <oc:id/>\n"
" <oc:downloadURL/>\n"
" <oc:dDC/>\n"
" <oc:permissions/>\n"
+ propStr +
" </d:prop>\n"
"</d:propfind>\n");
QBuffer *buf = new QBuffer(this);

View file

@ -136,20 +136,37 @@ public:
void start() Q_DECL_OVERRIDE;
QHash<QString, qint64> _sizes;
/**
* Used to specify which properties shall be retrieved.
*
* The properties can
* - contain no colon: they refer to a property in the DAV: namespace
* - contain a colon: and thus specify an explicit namespace,
* e.g. "ns:with:colons:bar", which is "bar" in the "ns:with:colons" namespace
*/
void setProperties(QList<QByteArray> properties);
QList<QByteArray> properties() const;
signals:
void directoryListingSubfolders(const QStringList &items);
void directoryListingIterated(const QString name, QMap<QString,QString> properties);
void directoryListingIterated(const QString &name, const QMap<QString,QString> &properties);
void finishedWithError(QNetworkReply *reply);
void finishedWithoutError();
private slots:
virtual bool finished() Q_DECL_OVERRIDE;
private:
QList<QByteArray> _properties;
};
/**
* @brief The PropfindJob class
*
* Setting the desired properties with setProperties() is mandatory.
*
* Note that this job is only for querying one item.
* There is also the LsColJob which can be used to list collections
*/
class PropfindJob : public AbstractNetworkJob {
Q_OBJECT