Now only 1 constructor to ocssharejob

* Pass the share_id to the functions that need it
This commit is contained in:
Roeland Jago Douma 2015-10-16 08:28:13 +02:00
parent f95fea9866
commit 40ab3ee751
5 changed files with 34 additions and 28 deletions

View file

@ -42,6 +42,11 @@ void OcsJob::addPassStatusCode(int code)
_passStatusCodes.append(code);
}
void OcsJob::appendPath(int id)
{
setPath(path() + QString("/%1").arg(id));
}
void OcsJob::start()
{
QNetworkRequest req;

View file

@ -73,6 +73,14 @@ protected:
*/
void addPassStatusCode(int code);
/**
* The base path for an OcsJob is always the same. But it could be that case that
* certain operations need to append something to the URL.
*
* This functions 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

View file

@ -26,12 +26,6 @@ OcsShareJob::OcsShareJob(AccountPtr account, QObject* parent)
setPath("ocs/v1.php/apps/files_sharing/api/v1/shares");
}
OcsShareJob::OcsShareJob(int shareId, AccountPtr account, QObject* parent)
: OcsJob(account, parent)
{
setPath(QString("ocs/v1.php/apps/files_sharing/api/v1/shares/%1").arg(shareId));
}
void OcsShareJob::getShares(const QString &path)
{
setVerb("GET");
@ -42,15 +36,17 @@ void OcsShareJob::getShares(const QString &path)
start();
}
void OcsShareJob::deleteShare()
void OcsShareJob::deleteShare(int shareId)
{
appendPath(shareId);
setVerb("DELETE");
start();
}
void OcsShareJob::setExpireDate(const QDate &date)
void OcsShareJob::setExpireDate(int shareId, const QDate &date)
{
appendPath(shareId);
setVerb("PUT");
if (date.isValid()) {
@ -62,8 +58,9 @@ void OcsShareJob::setExpireDate(const QDate &date)
start();
}
void OcsShareJob::setPassword(const QString &password)
void OcsShareJob::setPassword(int shareId, const QString &password)
{
appendPath(shareId);
setVerb("PUT");
addParam(QString::fromLatin1("password"), password);
@ -71,8 +68,9 @@ void OcsShareJob::setPassword(const QString &password)
start();
}
void OcsShareJob::setPublicUpload(bool publicUpload)
void OcsShareJob::setPublicUpload(int shareId, bool publicUpload)
{
appendPath(shareId);
setVerb("PUT");
const QString value = QString::fromLatin1(publicUpload ? "true" : "false");

View file

@ -56,11 +56,6 @@ public:
*/
explicit OcsShareJob(AccountPtr account, QObject *parent = 0);
/**
* Constructors for existing shares of which we know the shareId
*/
explicit OcsShareJob(int shareId, AccountPtr account, QObject *parent = 0);
/**
* Get all the shares
*
@ -71,7 +66,7 @@ public:
/**
* Delete the current Share
*/
void deleteShare();
void deleteShare(int shareId);
/**
* Set the expiration date of a share
@ -79,7 +74,7 @@ public:
* @param date The expire date, if this date is invalid the expire date
* will be removed
*/
void setExpireDate(const QDate& date);
void setExpireDate(int shareId, const QDate& date);
/**
* Set the password of a share
@ -87,14 +82,14 @@ public:
* @param password The password of the share, if the password is empty the
* share will be removed
*/
void setPassword(const QString& password);
void setPassword(int shareId, const QString& password);
/**
* Void set the a share to be public upload
*
* @param publicUpload Set or remove public upload
*/
void setPublicUpload(bool publicUpload);
void setPublicUpload(int shareId, bool publicUpload);
/**
* Create a new share

View file

@ -184,9 +184,9 @@ void ShareDialog::setExpireDate(const QDate &date)
}
_pi_date->startAnimation();
OcsShareJob *job = new OcsShareJob(_public_share_id, _account, this);
OcsShareJob *job = new OcsShareJob(_account, this);
connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotExpireSet(QVariantMap)));
job->setExpireDate(date);
job->setExpireDate(_public_share_id, date);
}
void ShareDialog::slotExpireSet(const QVariantMap &reply)
@ -235,11 +235,11 @@ void ShareDialog::setPassword(const QString &password)
QString path;
if( _public_share_id > 0 ) {
OcsShareJob *job = new OcsShareJob(_public_share_id, _account, this);
OcsShareJob *job = new OcsShareJob(_account, this);
connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotPasswordSet(QVariantMap)));
job->setPassword(password);
job->setPassword(_public_share_id, password);
} else {
OcsShareJob *job = new OcsShareJob(_public_share_id, _account, this);
OcsShareJob *job = new OcsShareJob(_account, this);
connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotPasswordSet(QVariantMap)));
connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotCreateShareFetched(QVariantMap)));
@ -471,9 +471,9 @@ void ShareDialog::slotCheckBoxShareLinkClicked()
job->createShare(_sharePath, OcsShareJob::SHARETYPE::LINK);
} else {
_pi_link->startAnimation();
OcsShareJob *job = new OcsShareJob(_public_share_id, _account, this);
OcsShareJob *job = new OcsShareJob(_account, this);
connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotDeleteShareFetched(QVariantMap)));
job->deleteShare();
job->deleteShare(_public_share_id);
}
}
@ -553,9 +553,9 @@ void ShareDialog::setPublicUpload(bool publicUpload)
_ui->checkBox_editing->setEnabled(false);
_pi_editing->startAnimation();
OcsShareJob *job = new OcsShareJob(_public_share_id, _account, this);
OcsShareJob *job = new OcsShareJob(_account, this);
connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotPublicUploadSet(QVariantMap)));
job->setPublicUpload(publicUpload);
job->setPublicUpload(_public_share_id, publicUpload);
}
void ShareDialog::slotPublicUploadSet(const QVariantMap &reply)