From 40ab3ee751644262e496b0535770d25e49692cfa Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 16 Oct 2015 08:28:13 +0200 Subject: [PATCH] Now only 1 constructor to ocssharejob * Pass the share_id to the functions that need it --- src/gui/ocsjob.cpp | 5 +++++ src/gui/ocsjob.h | 8 ++++++++ src/gui/ocssharejob.cpp | 18 ++++++++---------- src/gui/ocssharejob.h | 13 ++++--------- src/gui/sharedialog.cpp | 18 +++++++++--------- 5 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/gui/ocsjob.cpp b/src/gui/ocsjob.cpp index 961e84f14..93819086b 100644 --- a/src/gui/ocsjob.cpp +++ b/src/gui/ocsjob.cpp @@ -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; diff --git a/src/gui/ocsjob.h b/src/gui/ocsjob.h index 36f2eb0da..19bbdf05c 100644 --- a/src/gui/ocsjob.h +++ b/src/gui/ocsjob.h @@ -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 / + */ + void appendPath(int id); + public: /** * Parse the response and return the status code and the message of the diff --git a/src/gui/ocssharejob.cpp b/src/gui/ocssharejob.cpp index feb5eaf31..dea9b530c 100644 --- a/src/gui/ocssharejob.cpp +++ b/src/gui/ocssharejob.cpp @@ -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"); diff --git a/src/gui/ocssharejob.h b/src/gui/ocssharejob.h index 5156a52ad..337f33b8c 100644 --- a/src/gui/ocssharejob.h +++ b/src/gui/ocssharejob.h @@ -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 diff --git a/src/gui/sharedialog.cpp b/src/gui/sharedialog.cpp index 8be6bf008..5cf71187e 100644 --- a/src/gui/sharedialog.cpp +++ b/src/gui/sharedialog.cpp @@ -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) -- 2.30.2