nextcloud-desktop/src/gui/ocsjob.h

123 lines
3 KiB
C
Raw Normal View History

/*
* Copyright (C) by Roeland Jago Douma <roeland@famdouma.nl>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#ifndef OCSJOB_H
#define OCSJOB_H
#include "accountfwd.h"
#include "abstractnetworkjob.h"
#include <QVector>
#include <QList>
#include <QPair>
#include <QUrl>
namespace OCC {
/**
* @brief The OcsShareJob class
* @ingroup gui
2015-10-15 21:54:52 +03:00
*
* Base class for jobs that talk to the OCS endpoints on the server.
2015-10-16 13:51:24 +03:00
* All the communication logic is handled in this class.
2015-10-15 21:54:52 +03:00
*
* All OCS jobs (e.g. sharing) should extend this class.
*/
2015-10-15 21:54:52 +03:00
class OcsJob : public AbstractNetworkJob {
Q_OBJECT
protected:
2015-10-15 21:54:52 +03:00
explicit OcsJob(AccountPtr account, QObject* parent = 0);
/**
* Set the verb for the job
*
* @param verb currently supported PUT POST DELETE
*/
void setVerb(const QByteArray& verb);
/**
* Add a new parameter to the request.
* Depending on the verb this is GET or POST parameter
*
* @param name The name of the parameter
* @param value The value of the parameter
*/
void addParam(const QString& name, const QString &value);
/**
* Set the post parameters
*
* @param postParams list of pairs to add (urlEncoded) to the body of the
* request
*/
void setPostParams(const QList<QPair<QString, QString> >& postParams);
/**
* List of expected statuscodes for this request
* A warning will be printed to the debug log if a different status code is
* encountered
*
* @param code Accepted status code
*/
void addPassStatusCode(int code);
/**
2015-10-16 13:51:24 +03:00
* The base path for an OcsJob is always the same. But it could be the case that
* certain operations need to append something to the URL.
*
2015-10-16 13:51:24 +03:00
* This function appends the common id. so <PATH>/<ID>
*/
void appendPath(int id);
public:
/**
* Parse the response and return the status code and the message of the
* reply (metadata)
*
* @param json The reply from OCS
* @param message The message that is set in the metadata
* @return The statuscode of the OCS response
*/
static int getJsonReturnCode(const QVariantMap &json, QString &message);
protected slots:
/**
* Start the OCS request
*/
void start() Q_DECL_OVERRIDE;
signals:
/**
* Result of the OCS request
*
* @param reply the reply
*/
void jobFinished(QVariantMap reply);
private slots:
virtual bool finished() Q_DECL_OVERRIDE;
private:
QByteArray _verb;
QList<QPair<QString, QString> > _params;
QVector<int> _passStatusCodes;
};
}
#endif // OCSJOB_H