[Pkg-owncloud-commits] [owncloud-client] 78/484: Split sharing code

Sandro Knauß hefee-guest at moszumanska.debian.org
Wed Dec 16 00:37:16 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit b293aa762c3b32fe00527647ab5b18b8dbc28541
Author: Roeland Jago Douma <rullzer at owncloud.com>
Date:   Mon Sep 7 13:50:01 2015 +0200

    Split sharing code
    
    There is now a generic OCSJob which must be inherited by other jobs. This is in
    prepartion for the other OCS job that will come (for the Sharee API endpoint
    for example).
    
    More logic is moved from the sharedialog to the OcsShareJob. So in the GUI code
    we now only say what we want (a new share, set the password etc). And the code
    in libsync will make that happen. Error handling is for now still done in the
    GUI part.
    
    For now the ocsjob and ocssharejob live in gui but probabaly we should
    create a libshare or libocs at some point.
---
 src/gui/CMakeLists.txt   |   3 +
 src/gui/ocsjob.cpp       | 115 +++++++++++++++++++++++++++++
 src/gui/ocsjob.h         | 115 +++++++++++++++++++++++++++++
 src/gui/ocssharejob.cpp  | 106 +++++++++++++++++++++++++++
 src/gui/ocssharejob.h    |  90 +++++++++++++++++++++++
 src/gui/sharedialog.cpp  | 187 +++++++----------------------------------------
 src/gui/sharedialog.h    |  44 +----------
 src/gui/thumbnailjob.cpp |  42 +++++++++++
 src/gui/thumbnailjob.h   |  38 ++++++++++
 9 files changed, 537 insertions(+), 203 deletions(-)

diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt
index e9a18be..5eb235a 100644
--- a/src/gui/CMakeLists.txt
+++ b/src/gui/CMakeLists.txt
@@ -50,6 +50,8 @@ set(client_SRCS
     ignorelisteditor.cpp
     logbrowser.cpp
     networksettings.cpp
+    ocsjob.cpp
+    ocssharejob.cpp
     openfilemanager.cpp
     owncloudgui.cpp
     owncloudsetupwizard.cpp
@@ -62,6 +64,7 @@ set(client_SRCS
     sslerrordialog.cpp
     syncrunfilelog.cpp
     systray.cpp
+    thumbnailjob.cpp
     quotainfo.cpp
     accountstate.cpp
     addcertificatedialog.cpp
diff --git a/src/gui/ocsjob.cpp b/src/gui/ocsjob.cpp
new file mode 100644
index 0000000..19bf1e4
--- /dev/null
+++ b/src/gui/ocsjob.cpp
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) by Roeland Jago Douma <roeland at 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.
+ */
+
+#include "ocsjob.h"
+#include "networkjobs.h"
+#include "account.h"
+#include "json.h"
+
+#include <QBuffer>
+
+namespace OCC {
+
+OCSJob::OCSJob(AccountPtr account, QObject* parent)
+: AbstractNetworkJob(account, "", parent)
+{
+    _passStatusCodes.append(100);
+    setIgnoreCredentialFailure(true);
+}
+
+void OCSJob::setVerb(const QByteArray &verb)
+{
+    _verb = verb;
+}
+
+void OCSJob::setUrl(const QUrl &url)
+{
+    _url = url;
+}
+
+void OCSJob::setGetParams(const QList<QPair<QString, QString> >& getParams)
+{
+    _url.setQueryItems(getParams);
+}
+
+void OCSJob::setPostParams(const QList<QPair<QString, QString> >& postParams)
+{
+    _postParams = postParams;
+}
+
+void OCSJob::addPassStatusCode(int code)
+{
+    _passStatusCodes.append(code);
+}
+
+void OCSJob::start()
+{
+    QNetworkRequest req;
+    req.setRawHeader("OCS-APIREQUEST", "true");
+    req.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
+
+    // Url encode the _postParams and put them in a buffer.
+    QByteArray postData;
+    Q_FOREACH(auto tmp2, _postParams) {
+        if (! postData.isEmpty()) {
+            postData.append("&");
+        }
+        postData.append(QUrl::toPercentEncoding(tmp2.first));
+        postData.append("=");
+        postData.append(QUrl::toPercentEncoding(tmp2.second));
+    }
+    QBuffer *buffer = new QBuffer;
+    buffer->setData(postData);
+
+    auto queryItems = _url.queryItems();
+    queryItems.append(qMakePair(QString::fromLatin1("format"), QString::fromLatin1("json")));
+    _url.setQueryItems(queryItems);
+
+    setReply(davRequest(_verb, _url, req, buffer));
+    setupConnections(reply());
+    buffer->setParent(reply());
+    AbstractNetworkJob::start();
+}
+
+bool OCSJob::finished()
+{
+    const QString replyData = reply()->readAll();
+
+    bool success;
+    QVariantMap json = QtJson::parse(replyData, success).toMap();
+    if (!success) {
+        qDebug() << "Could not parse reply to" << _verb << _url << _postParams
+                 << ":" << replyData;
+    }
+
+    QString message;
+    const int statusCode = getJsonReturnCode(json, message);
+    if (!_passStatusCodes.contains(statusCode)) {
+        qDebug() << "Reply to" << _verb << _url << _postParams
+                 << "has unexpected status code:" << statusCode << replyData;
+    }
+
+    emit jobFinished(json);
+    return true;
+}
+
+int OCSJob::getJsonReturnCode(const QVariantMap &json, QString &message)
+{
+    //TODO proper checking
+    int code = json.value("ocs").toMap().value("meta").toMap().value("statuscode").toInt();
+    message = json.value("ocs").toMap().value("meta").toMap().value("message").toString();
+
+    return code;
+}
+
+}
diff --git a/src/gui/ocsjob.h b/src/gui/ocsjob.h
new file mode 100644
index 0000000..fe7752c
--- /dev/null
+++ b/src/gui/ocsjob.h
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) by Roeland Jago Douma <roeland at 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
+ */
+class OCSJob : public AbstractNetworkJob {
+    Q_OBJECT
+
+protected:
+
+    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);
+
+    /**
+     * The url of the OCS endpoint
+     *
+     * @param url
+     */
+    void setUrl(const QUrl& url);
+
+    /**
+     * Set the get parameters to the url
+     *
+     * @param getParams list of pairs to add to the url
+     */
+    void setGetParams(const QList<QPair<QString, QString> >& getParams);
+
+    /**
+     * 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);
+
+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;
+    QUrl _url;
+    QList<QPair<QString, QString> > _postParams;
+    QVector<int> _passStatusCodes;
+};
+
+}
+
+#endif // OCSJOB_H
diff --git a/src/gui/ocssharejob.cpp b/src/gui/ocssharejob.cpp
new file mode 100644
index 0000000..408c529
--- /dev/null
+++ b/src/gui/ocssharejob.cpp
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) by Roeland Jago Douma <roeland at 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.
+ */
+
+#include "ocssharejob.h"
+#include "networkjobs.h"
+#include "account.h"
+#include "json.h"
+
+#include <QBuffer>
+
+namespace OCC {
+
+OcsShareJob::OcsShareJob(AccountPtr account, QObject* parent)
+: OCSJob(account, parent)
+{
+    setUrl(Account::concatUrlPath(account->url(), QString("ocs/v1.php/apps/files_sharing/api/v1/shares")));
+}
+
+OcsShareJob::OcsShareJob(int shareId, AccountPtr account, QObject* parent)
+: OCSJob(account, parent)
+{
+    setUrl(Account::concatUrlPath(account->url(), QString("ocs/v1.php/apps/files_sharing/api/v1/shares/%1").arg(shareId)));
+}
+
+void OcsShareJob::getShares(const QString &path)
+{
+    setVerb("GET");
+    
+    QList<QPair<QString, QString> > getParams;
+    getParams.append(qMakePair(QString::fromLatin1("path"), path));
+    setGetParams(getParams);
+
+    addPassStatusCode(404);
+
+    start();
+
+}
+
+void OcsShareJob::deleteShare()
+{
+    setVerb("DELETE");
+
+    start();
+}
+
+void OcsShareJob::setExpireDate(const QDate &date)
+{
+    setVerb("PUT");
+
+    QList<QPair<QString, QString> > postParams;
+
+    if (date.isValid()) {
+        postParams.append(qMakePair(QString::fromLatin1("expireDate"), date.toString("yyyy-MM-dd")));
+    } else {
+        postParams.append(qMakePair(QString::fromLatin1("expireDate"), QString()));
+    }
+
+    setPostParams(postParams);
+    start();
+}
+
+void OcsShareJob::setPassword(const QString &password)
+{
+    setVerb("PUT");
+
+    QList<QPair<QString, QString> > postParams;
+    postParams.append(qMakePair(QString::fromLatin1("password"), password));
+
+    setPostParams(postParams);
+    start();
+}
+
+void OcsShareJob::createShare(const QString &path, SHARETYPE shareType, const QString &password, const QDate &date)
+{
+    setVerb("POST");
+
+    QList<QPair<QString, QString> > postParams;
+    postParams.append(qMakePair(QString::fromLatin1("path"), path));
+    postParams.append(qMakePair(QString::fromLatin1("shareType"), QString::number(static_cast<int>(shareType))));
+
+    if (!password.isEmpty()) {
+        postParams.append(qMakePair(QString::fromLatin1("shareType"), password));
+    }
+
+    if (date.isValid()) {
+        postParams.append(qMakePair(QString::fromLatin1("expireDate"), date.toString("yyyy-MM-dd")));
+    }
+
+    setPostParams(postParams);
+
+    addPassStatusCode(403);
+
+    start();
+}
+
+}
diff --git a/src/gui/ocssharejob.h b/src/gui/ocssharejob.h
new file mode 100644
index 0000000..e662537
--- /dev/null
+++ b/src/gui/ocssharejob.h
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) by Roeland Jago Douma <roeland at 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 OCSSHAREJOB_H
+#define OCSSHAREJOB_H
+
+#include "ocsjob.h"
+#include <QVector>
+#include <QList>
+#include <QPair>
+
+namespace OCC {
+
+/**
+ * @brief The OcsShareJob class
+ * @ingroup gui
+ */
+class OcsShareJob : public OCSJob {
+    Q_OBJECT
+public:
+
+    /**
+     * Support sharetypes
+     */
+    enum class SHARETYPE : int {
+        LINK = 3
+    };
+
+    /**
+     * Constructor for new shares or listing of shares
+     */
+    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
+     *
+     * @param path Path to request shares for (default all shares)
+     */
+    void getShares(const QString& path = "");
+
+    /**
+     * Delete the current Share
+     */
+    void deleteShare();
+
+    /**
+     * Set the expiration date of a share
+     *
+     * @param date The expire date, if this date is invalid the expire date
+     * will be removed
+     */
+    void setExpireDate(const QDate& date);
+
+    /**
+     * Set the password of a share
+     *
+     * @param password The password of the share, if the password is empty the
+     * share will be removed
+     */
+    void setPassword(const QString& password);
+
+    /**
+     * Create a new share
+     *
+     * @param path The path of the file/folder to share
+     * @param shareType The type of share (user/group/link/federated)
+     * @param password Optionally a password for the share
+     * @param date Optionally an expire date for the share
+     */
+    void createShare(const QString& path, SHARETYPE shareType, const QString& password = "", const QDate& date = QDate());
+};
+
+}
+
+#endif // OCSSHAREJOB_H
diff --git a/src/gui/sharedialog.cpp b/src/gui/sharedialog.cpp
index c4ac51a..e02f686 100644
--- a/src/gui/sharedialog.cpp
+++ b/src/gui/sharedialog.cpp
@@ -14,17 +14,18 @@
 
 #include "sharedialog.h"
 #include "ui_sharedialog.h"
-#include "networkjobs.h"
 #include "account.h"
 #include "json.h"
 #include "folderman.h"
 #include "folder.h"
 #include "accountmanager.h"
 #include "theme.h"
-#include "syncresult.h"
 #include "configfile.h"
 #include "capabilities.h"
 
+#include "ocssharejob.h"
+#include "thumbnailjob.h"
+
 #include "QProgressIndicator.h"
 #include <QBuffer>
 #include <QFileIconProvider>
@@ -42,8 +43,6 @@ namespace {
 //    int PERMISSION_ALL = 31;
 }
 
-
-
 namespace OCC {
 
 ShareDialog::ShareDialog(AccountPtr account, const QString &sharePath, const QString &localPath, bool resharingAllowed, QWidget *parent) :
@@ -188,15 +187,6 @@ void ShareDialog::done( int r ) {
     QDialog::done(r);
 }
 
-static int getJsonReturnCode(const QVariantMap &json, QString &message)
-{
-    //TODO proper checking
-    int code = json.value("ocs").toMap().value("meta").toMap().value("statuscode").toInt();
-    message = json.value("ocs").toMap().value("meta").toMap().value("message").toString();
-
-    return code;
-}
-
 void ShareDialog::setExpireDate(const QDate &date)
 {
     if( _public_share_id == 0 ) {
@@ -204,25 +194,16 @@ void ShareDialog::setExpireDate(const QDate &date)
         return;
     }
     _pi_date->startAnimation();
-    QUrl url = Account::concatUrlPath(_account->url(), QString("ocs/v1.php/apps/files_sharing/api/v1/shares/%1").arg(_public_share_id));
-    QList<QPair<QString, QString> > postParams;
 
-    if (date.isValid()) {
-        postParams.append(qMakePair(QString::fromLatin1("expireDate"), date.toString("yyyy-MM-dd")));
-    } else {
-        postParams.append(qMakePair(QString::fromLatin1("expireDate"), QString()));
-    }
-
-    OcsShareJob *job = new OcsShareJob("PUT", url, _account, this);
-    job->setPostParams(postParams);
+    OcsShareJob *job = new OcsShareJob(_public_share_id, _account, this);
     connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotExpireSet(QVariantMap)));
-    job->start();
+    job->setExpireDate(date);
 }
 
 void ShareDialog::slotExpireSet(const QVariantMap &reply)
 {
     QString message;
-    int code = getJsonReturnCode(reply, message);
+    int code = OCSJob::getJsonReturnCode(reply, message);
     if (code != 100) {
         displayError(code);
     } 
@@ -262,44 +243,33 @@ void ShareDialog::setPassword(const QString &password)
     }
     _pi_link->startAnimation();
     _pi_password->startAnimation();
-    QUrl url;
+    QString path;
     QList<QPair<QString, QString> > requestParams;
     QByteArray verb("PUT");
 
     if( _public_share_id > 0 ) {
-        url = Account::concatUrlPath(_account->url(), QString("ocs/v1.php/apps/files_sharing/api/v1/shares/%1").arg(_public_share_id));
-        requestParams.append(qMakePair(QString::fromLatin1("password"), password));
+        OcsShareJob *job = new OcsShareJob(_public_share_id, _account, this);
+        connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotPasswordSet(QVariantMap)));
+        job->setPassword(password);
     } else {
-        // lets create a new share.
-        url = Account::concatUrlPath(_account->url(), QLatin1String("ocs/v1.php/apps/files_sharing/api/v1/shares"));
-        requestParams.append(qMakePair(QString::fromLatin1("path"), _sharePath));
-        requestParams.append(qMakePair(QString::fromLatin1("shareType"), QString::number(SHARETYPE_PUBLIC)));
-        requestParams.append(qMakePair(QString::fromLatin1("password"), password));
-        verb = "POST";
+        OcsShareJob *job = new OcsShareJob(_public_share_id, _account, this);
+        connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotPasswordSet(QVariantMap)));
+        connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotCreateShareFetched(QVariantMap)));
 
+        QDate date;
         if( _ui->checkBox_expire->isChecked() ) {
-            QDate date = _ui->calendar->date();
-            if( date.isValid() ) {
-                requestParams.append(qMakePair(QString::fromLatin1("expireDate"), date.toString("yyyy-MM-dd")));
-            }
+            date = _ui->calendar->date();
         }
-    }
-    OcsShareJob *job = new OcsShareJob(verb, url, _account, this);
-    job->setPostParams(requestParams);
-    connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotPasswordSet(QVariantMap)));
 
-    if (_public_share_id == 0) {
-        connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotCreateShareFetched(QVariantMap)));
+        job->createShare(_sharePath, OcsShareJob::SHARETYPE::LINK, password, date);
     }
-
-    job->start();
     _passwordJobRunning = true;
 }
 
 void ShareDialog::slotPasswordSet(const QVariantMap &reply)
 {
     QString message;
-    int code = getJsonReturnCode(reply, message);
+    int code = OcsShareJob::getJsonReturnCode(reply, message);
     if (code != 100) {
         displayError(code);
     }
@@ -316,14 +286,9 @@ void ShareDialog::slotPasswordSet(const QVariantMap &reply)
 
 void ShareDialog::getShares()
 {
-    QUrl url = Account::concatUrlPath(_account->url(), QLatin1String("ocs/v1.php/apps/files_sharing/api/v1/shares"));
-    QList<QPair<QString, QString> > params;
-    params.append(qMakePair(QString::fromLatin1("path"), _sharePath));
-    url.setQueryItems(params);
-    OcsShareJob *job = new OcsShareJob("GET", url, _account, this);
-    job->addPassStatusCode(404); // don't report error if share doesn't exist yet
+    OcsShareJob *job = new OcsShareJob(_account, this);
     connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotSharesFetched(QVariantMap)));
-    job->start();
+    job->getShares(_sharePath);
 
     if (QFileInfo(_localPath).isFile()) {
         ThumbnailJob *job2 = new ThumbnailJob(_sharePath, _account, this);
@@ -335,7 +300,7 @@ void ShareDialog::getShares()
 void ShareDialog::slotSharesFetched(const QVariantMap &reply)
 {
     QString message;
-    int code = getJsonReturnCode(reply, message);
+    int code = OcsShareJob::getJsonReturnCode(reply, message);
     if (code != 100 && code != 404) {
         displayError(code);
     }
@@ -352,7 +317,7 @@ void ShareDialog::slotSharesFetched(const QVariantMap &reply)
     Q_FOREACH(auto share, ShareDialog::_shares) {
         QVariantMap data = share.toMap();
 
-        if (data.value("share_type").toInt() == SHARETYPE_PUBLIC) {
+        if (data.value("share_type").toInt() == static_cast<int>(OcsShareJob::SHARETYPE::LINK)) {
             _public_share_id = data.value("id").toULongLong();
             _ui->pushButton_copy->show();
 
@@ -465,7 +430,7 @@ void ShareDialog::setShareLink( const QString& url )
 void ShareDialog::slotDeleteShareFetched(const QVariantMap &reply)
 {
     QString message;
-    int code = getJsonReturnCode(reply, message);
+    int code = OcsShareJob::getJsonReturnCode(reply, message);
     if (code != 100) {
         displayError(code);
     }
@@ -494,10 +459,6 @@ void ShareDialog::slotCheckBoxShareLinkClicked()
     qDebug() << Q_FUNC_INFO <<( _ui->checkBox_shareLink->checkState() == Qt::Checked);
     if (_ui->checkBox_shareLink->checkState() == Qt::Checked) {
         _pi_link->startAnimation();
-        QUrl url = Account::concatUrlPath(_account->url(), QLatin1String("ocs/v1.php/apps/files_sharing/api/v1/shares"));
-        QList<QPair<QString, QString> > postParams;
-        postParams.append(qMakePair(QString::fromLatin1("path"), _sharePath));
-        postParams.append(qMakePair(QString::fromLatin1("shareType"), QString::number(SHARETYPE_PUBLIC)));
 
         /*
          * Check the capabilities if the server requires a password for a share
@@ -516,24 +477,21 @@ void ShareDialog::slotCheckBoxShareLinkClicked()
             return;
         }
 
-        OcsShareJob *job = new OcsShareJob("POST", url, _account, this);
-        job->setPostParams(postParams);
-        job->addPassStatusCode(403); // "password required" is not an error
+        OcsShareJob *job = new OcsShareJob(_account, this);
         connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotCreateShareFetched(QVariantMap)));
-        job->start();
+        job->createShare(_sharePath, OcsShareJob::SHARETYPE::LINK);
     } else {
         _pi_link->startAnimation();
-        QUrl url = Account::concatUrlPath(_account->url(), QString("ocs/v1.php/apps/files_sharing/api/v1/shares/%1").arg(_public_share_id));
-        OcsShareJob *job = new OcsShareJob("DELETE", url, _account, this);
+        OcsShareJob *job = new OcsShareJob(_public_share_id, _account, this);
         connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotDeleteShareFetched(QVariantMap)));
-        job->start();
+        job->deleteShare();
     }
 }
 
 void ShareDialog::slotCreateShareFetched(const QVariantMap &reply)
 {
     QString message;
-    int code = getJsonReturnCode(reply, message);
+    int code = OcsShareJob::getJsonReturnCode(reply, message);
     _pi_link->stopAnimation();
 
     if (code == 403) {
@@ -784,95 +742,4 @@ void ShareDialog::slotThumbnailFetched(const int &statusCode, const QByteArray &
     _ui->label_icon->setPixmap(p);
 }
 
-OcsShareJob::OcsShareJob(const QByteArray &verb, const QUrl &url, AccountPtr account, QObject* parent)
-: AbstractNetworkJob(account, "", parent),
-  _verb(verb),
-  _url(url)
-{
-    _passStatusCodes.append(100);
-    setIgnoreCredentialFailure(true);
-}
-
-void OcsShareJob::setPostParams(const QList<QPair<QString, QString> >& postParams)
-{
-    _postParams = postParams;
-}
-
-void OcsShareJob::addPassStatusCode(int code)
-{
-    _passStatusCodes.append(code);
-}
-
-void OcsShareJob::start()
-{
-    QNetworkRequest req;
-    req.setRawHeader("OCS-APIREQUEST", "true");
-    req.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
-
-    // Url encode the _postParams and put them in a buffer.
-    QByteArray postData;
-    Q_FOREACH(auto tmp2, _postParams) {
-        if (! postData.isEmpty()) {
-            postData.append("&");
-        }
-        postData.append(QUrl::toPercentEncoding(tmp2.first));
-        postData.append("=");
-        postData.append(QUrl::toPercentEncoding(tmp2.second));
-    }
-    QBuffer *buffer = new QBuffer;
-    buffer->setData(postData);
-
-    auto queryItems = _url.queryItems();
-    queryItems.append(qMakePair(QString::fromLatin1("format"), QString::fromLatin1("json")));
-    _url.setQueryItems(queryItems);
-
-    setReply(davRequest(_verb, _url, req, buffer));
-    setupConnections(reply());
-    buffer->setParent(reply());
-    AbstractNetworkJob::start();
-}
-
-bool OcsShareJob::finished()
-{
-    const QString replyData = reply()->readAll();
-
-    bool success;
-    QVariantMap json = QtJson::parse(replyData, success).toMap();
-    if (!success) {
-        qDebug() << "Could not parse reply to" << _verb << _url << _postParams
-                 << ":" << replyData;
-    }
-
-    QString message;
-    const int statusCode = getJsonReturnCode(json, message);
-    if (!_passStatusCodes.contains(statusCode)) {
-        qDebug() << "Reply to" << _verb << _url << _postParams
-                 << "has unexpected status code:" << statusCode << replyData;
-    }
-
-    emit jobFinished(json);
-    return true;
-}
-
-ThumbnailJob::ThumbnailJob(const QString &path, AccountPtr account, QObject* parent)
-: AbstractNetworkJob(account, "", parent)
-{
-    _url = Account::concatUrlPath(account->url(), QLatin1String("index.php/apps/files/api/v1/thumbnail/150/150/") + path);
-    setIgnoreCredentialFailure(true);
-}
-
-void ThumbnailJob::start()
-{
-    qDebug() << Q_FUNC_INFO;
-    setReply(getRequest(_url));
-    setupConnections(reply());
-    AbstractNetworkJob::start();
-}
-
-bool ThumbnailJob::finished()
-{
-    emit jobFinished(reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), reply()->readAll());
-    return true;
-}
-
 }
diff --git a/src/gui/sharedialog.h b/src/gui/sharedialog.h
index fba05f3..29f1a89 100644
--- a/src/gui/sharedialog.h
+++ b/src/gui/sharedialog.h
@@ -15,55 +15,13 @@
 #ifndef SHAREDIALOG_H
 #define SHAREDIALOG_H
 
-#include "networkjobs.h"
 #include "accountfwd.h"
 #include "QProgressIndicator.h"
 #include <QDialog>
-#include <QTreeWidgetItem>
+#include <QVariantMap>
 
 namespace OCC {
 
-/**
- * @brief The OcsShareJob class
- * @ingroup gui
- */
-class OcsShareJob : public AbstractNetworkJob {
-    Q_OBJECT
-public:
-    explicit OcsShareJob(const QByteArray& verb, const QUrl& url, AccountPtr account, QObject* parent = 0);
-
-    void setPostParams(const QList<QPair<QString, QString> >& postParams);
-    void addPassStatusCode(int code);
-
-public slots:
-    void start() Q_DECL_OVERRIDE;
-signals:
-    void jobFinished(QVariantMap reply);
-private slots:
-    virtual bool finished() Q_DECL_OVERRIDE;
-private:
-    QByteArray _verb;
-    QUrl _url;
-    QList<QPair<QString, QString> > _postParams;
-    QVector<int> _passStatusCodes;
-};
-
-
-class ThumbnailJob : public AbstractNetworkJob {
-    Q_OBJECT
-public:
-    explicit ThumbnailJob(const QString& path, AccountPtr account, QObject* parent = 0);
-public slots:
-    void start() Q_DECL_OVERRIDE;
-signals:
-    void jobFinished(int statusCode, QByteArray reply);
-private slots:
-    virtual bool finished() Q_DECL_OVERRIDE;
-private:
-    QUrl _url;
-};
-
-
 namespace Ui {
 class ShareDialog;
 }
diff --git a/src/gui/thumbnailjob.cpp b/src/gui/thumbnailjob.cpp
new file mode 100644
index 0000000..43d4b77
--- /dev/null
+++ b/src/gui/thumbnailjob.cpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) by Roeland Jago Douma <roeland at 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.
+ */
+
+#include "thumbnailjob.h"
+#include "networkjobs.h"
+#include "account.h"
+#include "json.h"
+
+namespace OCC {
+
+ThumbnailJob::ThumbnailJob(const QString &path, AccountPtr account, QObject* parent)
+: AbstractNetworkJob(account, "", parent)
+{
+    _url = Account::concatUrlPath(account->url(), QLatin1String("index.php/apps/files/api/v1/thumbnail/150/150/") + path);
+    setIgnoreCredentialFailure(true);
+}
+
+void ThumbnailJob::start()
+{
+    qDebug() << Q_FUNC_INFO;
+    setReply(getRequest(_url));
+    setupConnections(reply());
+    AbstractNetworkJob::start();
+}
+
+bool ThumbnailJob::finished()
+{
+    emit jobFinished(reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), reply()->readAll());
+    return true;
+}
+
+}
diff --git a/src/gui/thumbnailjob.h b/src/gui/thumbnailjob.h
new file mode 100644
index 0000000..7c58f24
--- /dev/null
+++ b/src/gui/thumbnailjob.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) by Roeland Jago Douma <roeland at 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 THUMBNAILJOB_H
+#define THUMBNAILJOB_H
+
+#include "networkjobs.h"
+#include "accountfwd.h"
+
+namespace OCC {
+
+class ThumbnailJob : public AbstractNetworkJob {
+    Q_OBJECT
+public:
+    explicit ThumbnailJob(const QString& path, AccountPtr account, QObject* parent = 0);
+public slots:
+    void start() Q_DECL_OVERRIDE;
+signals:
+    void jobFinished(int statusCode, QByteArray reply);
+private slots:
+    virtual bool finished() Q_DECL_OVERRIDE;
+private:
+    QUrl _url;
+};
+
+}
+
+#endif // THUMBNAILJOB_H

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list