[Pkg-owncloud-commits] [owncloud-client] 209/484: Act properly if OCS endpoint returned an error (OCS error)

Sandro Knauß hefee-guest at moszumanska.debian.org
Wed Dec 16 00:37:43 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 dd8d02b8efb147618f7a9a176f916c010ae01a15
Author: Roeland Jago Douma <rullzer at owncloud.com>
Date:   Thu Oct 29 16:56:23 2015 +0100

    Act properly if OCS endpoint returned an error (OCS error)
    
    For now pass it on to the gui. So at least they know something is wrong.
---
 src/gui/ocsjob.cpp      |  5 ++--
 src/gui/ocsjob.h        |  9 ++++++
 src/gui/share.cpp       | 73 ++++++++++++++++++-------------------------------
 src/gui/share.h         | 12 +++++---
 src/gui/sharedialog.cpp | 23 +++++++++++-----
 src/gui/sharedialog.h   |  2 ++
 6 files changed, 65 insertions(+), 59 deletions(-)

diff --git a/src/gui/ocsjob.cpp b/src/gui/ocsjob.cpp
index d83a1d3..5b0b0ad 100644
--- a/src/gui/ocsjob.cpp
+++ b/src/gui/ocsjob.cpp
@@ -105,9 +105,10 @@ bool OcsJob::finished()
                  << Account::concatUrlPath(account()->url(), path())
                  << _params
                  << "has unexpected status code:" << statusCode << replyData;
+        emit ocsError(statusCode, message);
+    } else {
+        emit jobFinished(json);
     }
-
-    emit jobFinished(json);
     deleteLater();
     return true;
 }
diff --git a/src/gui/ocsjob.h b/src/gui/ocsjob.h
index a6c405d..344b004 100644
--- a/src/gui/ocsjob.h
+++ b/src/gui/ocsjob.h
@@ -108,6 +108,15 @@ signals:
      */
     void jobFinished(QVariantMap reply);
 
+    /**
+     * The status code was not one of the expected (passing)
+     * status code for this command
+     *
+     * @param statusCode The actual status code
+     * @param message The message provided by the server
+     */
+    void ocsError(int statusCode, const QString &message);
+
 private slots:
     virtual bool finished() Q_DECL_OVERRIDE;
 
diff --git a/src/gui/share.cpp b/src/gui/share.cpp
index c8bc5de..06ce066 100644
--- a/src/gui/share.cpp
+++ b/src/gui/share.cpp
@@ -48,21 +48,21 @@ int Share::getPermissions() const
 void Share::deleteShare()
 {
     OcsShareJob *job = new OcsShareJob(_account, this);
-    connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotDeleted(QVariantMap)));
+    connect(job, SIGNAL(shareJobFinished(QVariantMap, QVariant)), SLOT(slotDeleted()));
+    connect(job, SIGNAL(ocsError(int, const QString &)), SLOT(slotOcsError(int, const QString &)));
     job->deleteShare(getId());
 }
 
-void Share::slotDeleted(const QVariantMap &reply)
+void Share::slotDeleted()
 {
-    QString message;
-    int code = OcsShareJob::getJsonReturnCode(reply, message);
-    if (code != 100) {
-        //emit error!
-    }
-
     emit shareDeleted();
 }
 
+void Share::slotOcsError(int statusCode, const QString &message)
+{
+    emit serverError(statusCode, message);   
+}
+
 QUrl LinkShare::getLink() const
 {
     return _url;
@@ -103,21 +103,13 @@ bool LinkShare::getPublicUpload()
 void LinkShare::setPublicUpload(bool publicUpload)
 {
     OcsShareJob *job = new OcsShareJob(_account, this);
-    connect(job, SIGNAL(shareJobFinished(QVariantMap, QVariant)), this, SLOT(slotPublicUploadSet(QVariantMap, QVariant)));
+    connect(job, SIGNAL(shareJobFinished(QVariantMap, QVariant)), SLOT(slotPublicUploadSet(QVariantMap, QVariant)));
+    connect(job, SIGNAL(ocsError(int, QString)), SLOT(slotOcsError(int, QString)));
     job->setPublicUpload(getId(), publicUpload);
 }
 
-void LinkShare::slotPublicUploadSet(const QVariantMap &reply, const QVariant &value)
+void LinkShare::slotPublicUploadSet(const QVariantMap&, const QVariant &value)
 {
-    qDebug() << Q_FUNC_INFO << reply;
-    qDebug() << Q_FUNC_INFO << value;
-
-    QString message;
-    int code = OcsShareJob::getJsonReturnCode(reply, message);
-    if (code != 100) {
-        //emit error
-    }
-
     //TODO FIX permission with names
     if (value.toBool()) {
         _permissions = 7;
@@ -131,18 +123,13 @@ void LinkShare::slotPublicUploadSet(const QVariantMap &reply, const QVariant &va
 void LinkShare::setPassword(const QString &password)
 {
     OcsShareJob *job = new OcsShareJob(_account, this);
-    connect(job, SIGNAL(shareJobFinished(QVariantMap, QVariant)), this, SLOT(slotPasswordSet(QVariantMap, QVariant)));
+    connect(job, SIGNAL(shareJobFinished(QVariantMap, QVariant)), SLOT(slotPasswordSet(QVariantMap, QVariant)));
+    connect(job, SIGNAL(ocsError(int, QString)), SLOT(slotOcsError(int, QString)));
     job->setPassword(getId(), password);
 }
 
-void LinkShare::slotPasswordSet(const QVariantMap &reply, const QVariant &value)
+void LinkShare::slotPasswordSet(const QVariantMap&, const QVariant &value)
 {
-    QString message;
-    int code = OcsShareJob::getJsonReturnCode(reply, message);
-    if (code != 100) {
-        //emit error
-    }
-
     _passwordSet = value.toString() == "";
     emit passwordSet();
 }
@@ -150,18 +137,13 @@ void LinkShare::slotPasswordSet(const QVariantMap &reply, const QVariant &value)
 void LinkShare::setExpireDate(const QDate &date)
 {
     OcsShareJob *job = new OcsShareJob(_account, this);
-    connect(job, SIGNAL(shareJobFinished(QVariantMap, QVariant)), this, SLOT(slotExpireDateSet(QVariantMap, QVariant)));
+    connect(job, SIGNAL(shareJobFinished(QVariantMap, QVariant)), SLOT(slotExpireDateSet(QVariantMap, QVariant)));
+    connect(job, SIGNAL(ocsError(int, QString)), SLOT(slotOcsError(int, QString)));
     job->setExpireDate(getId(), date);
 }
 
-void LinkShare::slotExpireDateSet(const QVariantMap &reply, const QVariant &value)
+void LinkShare::slotExpireDateSet(const QVariantMap&, const QVariant &value)
 {
-    QString message;
-    int code = OcsShareJob::getJsonReturnCode(reply, message);
-    if (code != 100) {
-        //emit error
-    }
-
     _expireDate = value.toDate();
     emit expireDateSet();
 }
@@ -177,7 +159,8 @@ void ShareManager::createLinkShare(const QString &path,
                                    const QString &password)
 {
     OcsShareJob *job = new OcsShareJob(_account, this);
-    connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotLinkShareCreated(QVariantMap)));
+    connect(job, SIGNAL(shareJobFinished(QVariantMap, QVariant)), SLOT(slotLinkShareCreated(QVariantMap)));
+    connect(job, SIGNAL(ocsError(int, QString)), SLOT(slotOcsError(int, QString)));
     job->createShare(path, OcsShareJob::ShareType::Link, password);
 }
 
@@ -193,9 +176,7 @@ void ShareManager::slotLinkShareCreated(const QVariantMap &reply)
     if (code == 403) {
         emit linkShareRequiresPassword();
         return;
-    } else if (code != 100) {
-        //emit error
-    }
+    } 
 
     //Parse share
     auto data = reply.value("ocs").toMap().value("data").toMap();
@@ -207,18 +188,13 @@ void ShareManager::slotLinkShareCreated(const QVariantMap &reply)
 void ShareManager::fetchShares(const QString &path)
 {
     OcsShareJob *job = new OcsShareJob(_account, this);
-    connect(job, SIGNAL(jobFinished(QVariantMap)), this, SLOT(slotSharesFetched(QVariantMap)));
+    connect(job, SIGNAL(shareJobFinished(QVariantMap, QVariant)), SLOT(slotSharesFetched(QVariantMap)));
+    connect(job, SIGNAL(ocsError(int, QString)), SLOT(slotOcsError(int, QString)));
     job->getShares(path);
 }
 
 void ShareManager::slotSharesFetched(const QVariantMap &reply)
 {
-    QString message;
-    int code = OcsShareJob::getJsonReturnCode(reply, message);
-    if (code != 100 && code != 404) {
-        //emit error!
-    }
-
     auto tmpShares = reply.value("ocs").toMap().value("data").toList();
     const QString versionString = _account->serverVersion();
     qDebug() << Q_FUNC_INFO << versionString << "Fetched" << tmpShares.count() << "shares";
@@ -280,4 +256,9 @@ QSharedPointer<LinkShare> ShareManager::parseLinkShare(const QVariantMap &data)
                                                    expireDate));
 }
 
+void ShareManager::slotOcsError(int statusCode, const QString &message)
+{
+    emit serverError(statusCode, message);   
+}
+
 }
diff --git a/src/gui/share.h b/src/gui/share.h
index 9fbc4b1..fca2c24 100644
--- a/src/gui/share.h
+++ b/src/gui/share.h
@@ -82,8 +82,11 @@ protected:
     int _shareType;
     int _permissions;
 
+protected slots:
+    void slotOcsError(int statusCode, const QString &message);
+
 private slots:
-    void slotDeleted(const QVariantMap &reply);
+    void slotDeleted();
 
 };
 
@@ -156,9 +159,9 @@ signals:
     void passwordSet();
 
 private slots:
-    void slotPasswordSet(const QVariantMap &reply, const QVariant &value);
-    void slotPublicUploadSet(const QVariantMap &reply, const QVariant &value);
-    void slotExpireDateSet(const QVariantMap &reply, const QVariant &value);
+    void slotPasswordSet(const QVariantMap&, const QVariant &value);
+    void slotPublicUploadSet(const QVariantMap&, const QVariant &value);
+    void slotExpireDateSet(const QVariantMap&, const QVariant &value);
 
 private:
     bool _passwordSet;
@@ -208,6 +211,7 @@ signals:
 private slots:
     void slotSharesFetched(const QVariantMap &reply);
     void slotLinkShareCreated(const QVariantMap &reply);
+    void slotOcsError(int statusCode, const QString &message);
 
 private:
     QSharedPointer<LinkShare> parseLinkShare(const QVariantMap &data);
diff --git a/src/gui/sharedialog.cpp b/src/gui/sharedialog.cpp
index ded38b0..4cdc28b 100644
--- a/src/gui/sharedialog.cpp
+++ b/src/gui/sharedialog.cpp
@@ -175,9 +175,10 @@ ShareDialog::ShareDialog(AccountPtr account, const QString &sharePath, const QSt
      */
     _manager = new ShareManager(_account, this);
 
-    connect(_manager, SIGNAL(sharesFetched(QList<QSharedPointer<Share>>)), this, SLOT(slotSharesFetched(QList<QSharedPointer<Share>>)));
-    connect(_manager, SIGNAL(linkShareCreated(const QSharedPointer<LinkShare>)), this, SLOT(slotCreateShareFetched(const QSharedPointer<LinkShare>)));
-    connect(_manager, SIGNAL(linkShareRequiresPassword()), this, SLOT(slotCreateShareRequiresPassword()));
+    connect(_manager, SIGNAL(sharesFetched(QList<QSharedPointer<Share>>)), SLOT(slotSharesFetched(QList<QSharedPointer<Share>>)));
+    connect(_manager, SIGNAL(linkShareCreated(QSharedPointer<LinkShare>)), SLOT(slotCreateShareFetched(const QSharedPointer<LinkShare>)));
+    connect(_manager, SIGNAL(linkShareRequiresPassword()), SLOT(slotCreateShareRequiresPassword()));
+    connect(_manager, SIGNAL(serverError(int, QString)), SLOT(displayError(int, QString)));
 }
 
 void ShareDialog::done( int r ) {
@@ -320,10 +321,11 @@ void ShareDialog::slotSharesFetched(const QList<QSharedPointer<Share>> &shares)
             _ui->pushButton_copy->setEnabled(true);
 
             // Connect all shares signals to gui slots
-            connect(_share.data(), SIGNAL(expireDateSet()), this, SLOT(slotExpireSet()));
-            connect(_share.data(), SIGNAL(publicUploadSet()), this, SLOT(slotPublicUploadSet()));
-            connect(_share.data(), SIGNAL(passwordSet()), this, SLOT(slotPasswordSet()));
-            connect(_share.data(), SIGNAL(shareDeleted()), this, SLOT(slotDeleteShareFetched()));
+            connect(_share.data(), SIGNAL(expireDateSet()), SLOT(slotExpireSet()));
+            connect(_share.data(), SIGNAL(publicUploadSet()), SLOT(slotPublicUploadSet()));
+            connect(_share.data(), SIGNAL(passwordSet()), SLOT(slotPasswordSet()));
+            connect(_share.data(), SIGNAL(shareDeleted()), SLOT(slotDeleteShareFetched()));
+            connect(_share.data(), SIGNAL(serverError(int, QString)), SLOT(displayError(int, QString)));
 
             break;
         }
@@ -545,6 +547,13 @@ void ShareDialog::setShareCheckBoxTitle(bool haveShares)
 
 }
 
+void ShareDialog::displayError(int code, const QString &message)
+{
+    const QString arg = QString("%1, %2").arg(code).arg(message);
+    const QString errMsg = tr("OCS API error code: %1").arg(arg);
+    displayError(errMsg);
+}
+
 void ShareDialog::displayError(const QString& errMsg)
 {
     _ui->errorLabel->setText( errMsg );
diff --git a/src/gui/sharedialog.h b/src/gui/sharedialog.h
index 7ffdee3..fea7015 100644
--- a/src/gui/sharedialog.h
+++ b/src/gui/sharedialog.h
@@ -66,6 +66,8 @@ private slots:
     void slotCheckBoxEditingClicked();
     void slotPublicUploadSet();
 
+    void displayError(int code, const QString &message);
+
     void done( int r );
 private:
     void setShareCheckBoxTitle(bool haveShares);

-- 
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