[Pkg-owncloud-commits] [owncloud-client] 130/470: Notifications: Add a Progress indicator and handle job results.

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu May 12 16:24:54 UTC 2016


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 4a4dac22e2611b5abd53cc27fafa1b11f8218254
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Wed Mar 9 15:21:52 2016 +0100

    Notifications: Add a Progress indicator and handle job results.
    
    Parse the replyCode from the button action calls and disable
    buttons accordingly.
---
 src/gui/activitywidget.cpp         | 34 +++++++++++++++++++++++++++++-----
 src/gui/activitywidget.h           |  1 +
 src/gui/notificationconfirmjob.cpp | 24 +++++++++++++++++++++---
 src/gui/notificationconfirmjob.h   |  7 +++++++
 src/gui/notificationwidget.cpp     | 28 ++++++++++++++++++++++++++--
 src/gui/notificationwidget.h       |  2 ++
 6 files changed, 86 insertions(+), 10 deletions(-)

diff --git a/src/gui/activitywidget.cpp b/src/gui/activitywidget.cpp
index 0347b43..ec01dde 100644
--- a/src/gui/activitywidget.cpp
+++ b/src/gui/activitywidget.cpp
@@ -530,6 +530,7 @@ void ActivityWidget::slotBuildNotificationDisplay(const ActivityList& list)
 void ActivityWidget::slotSendNotificationRequest(const QString& accountName, const QString& link, const QString& verb)
 {
     qDebug() << "Server Notification Request " << verb << link << "on account" << accountName;
+    NotificationWidget *theSender = qobject_cast<NotificationWidget*>(sender());
 
     const QStringList validVerbs = QStringList() << "GET" << "PUT" << "POST" << "DELETE";
 
@@ -537,9 +538,9 @@ void ActivityWidget::slotSendNotificationRequest(const QString& accountName, con
         AccountStatePtr acc = AccountManager::instance()->account(accountName);
         if( acc ) {
             NotificationConfirmJob *job = new NotificationConfirmJob(acc->account());
-            QString myLink(link);
-            QUrl l(myLink);
+            QUrl l(link);
             job->setLinkAndVerb(l, verb);
+            job->setWidget(theSender);
             connect( job, SIGNAL( networkError(QNetworkReply*)),
                                   this, SLOT(slotNotifyNetworkError(QNetworkReply*)));
             connect( job, SIGNAL( jobFinished(QString, int)),
@@ -547,21 +548,44 @@ void ActivityWidget::slotSendNotificationRequest(const QString& accountName, con
             job->start();
         }
     } else {
-        qDebug() << "Invalid verb:" << verb;
+        qDebug() << "Notificatio Links: Invalid verb:" << verb;
     }
 }
 
+void ActivityWidget::endNotificationRequest( NotificationWidget *widget, int replyCode )
+{
+    if( widget ) {
+        widget->slotNotificationRequestFinished(replyCode);
+    }
+}
 
-void ActivityWidget::slotNotifyNetworkError( QNetworkReply* )
+void ActivityWidget::slotNotifyNetworkError( QNetworkReply *reply)
 {
+    NotificationConfirmJob *job = qobject_cast<NotificationConfirmJob*>(sender());
+    if( !job ) {
+        return;
+    }
+
+    int resultCode =0;
+    if( reply ) {
+        resultCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+    }
+
+    endNotificationRequest(job->widget(), resultCode);
     qDebug() << "Server notify job failed.";
+
 }
 
 void ActivityWidget::slotNotifyServerFinished( const QString& reply, int replyCode )
 {
+    NotificationConfirmJob *job = qobject_cast<NotificationConfirmJob*>(sender());
+    if( !job ) {
+        return;
+    }
+
+    endNotificationRequest(job->widget(), replyCode);
     // FIXME: remove the  widget after a couple of seconds
     qDebug() << "Server Notification reply code"<< replyCode << reply;
-
 }
 
 /* ==================================================================== */
diff --git a/src/gui/activitywidget.h b/src/gui/activitywidget.h
index c27724c..7ad8c99 100644
--- a/src/gui/activitywidget.h
+++ b/src/gui/activitywidget.h
@@ -186,6 +186,7 @@ private slots:
     void slotSendNotificationRequest(const QString &accountName, const QString& link, const QString& verb);
     void slotNotifyNetworkError( QNetworkReply* );
     void slotNotifyServerFinished( const QString& reply, int replyCode );
+    void endNotificationRequest(NotificationWidget *widget , int replyCode);
 
 private:
     void showLabels();
diff --git a/src/gui/notificationconfirmjob.cpp b/src/gui/notificationconfirmjob.cpp
index f243656..8bcbbea 100644
--- a/src/gui/notificationconfirmjob.cpp
+++ b/src/gui/notificationconfirmjob.cpp
@@ -21,7 +21,8 @@
 namespace OCC {
 
 NotificationConfirmJob::NotificationConfirmJob(AccountPtr account)
-: AbstractNetworkJob(account, "")
+: AbstractNetworkJob(account, ""),
+  _widget(0)
 {
     setIgnoreCredentialFailure(true);
 }
@@ -32,6 +33,16 @@ void NotificationConfirmJob::setLinkAndVerb(const QUrl& link, const QString &ver
     _verb = verb;
 }
 
+void NotificationConfirmJob::setWidget( NotificationWidget *widget )
+{
+    _widget = widget;
+}
+
+NotificationWidget *NotificationConfirmJob::widget()
+{
+    return _widget;
+}
+
 void NotificationConfirmJob::start()
 {
     if( !_link.isValid() ) {
@@ -52,9 +63,16 @@ bool NotificationConfirmJob::finished()
 {
     int replyCode = 0;
     // FIXME: check for the reply code!
-    const QString replyData = reply()->readAll();
+    const QString replyStr = reply()->readAll();
 
-    emit jobFinished(replyData, replyCode);
+    if( replyStr.contains( "<?xml version=\"1.0\"?>") ) {
+         QRegExp rex("<statuscode>(\\d+)</statuscode>");
+         if( replyStr.contains(rex) ) {
+             // this is a error message coming back from ocs.
+             replyCode = rex.cap(1).toInt();
+         }
+    }
+    emit jobFinished(replyStr, replyCode);
 
     return true;
 
diff --git a/src/gui/notificationconfirmjob.h b/src/gui/notificationconfirmjob.h
index e723b42..3f0e8bb 100644
--- a/src/gui/notificationconfirmjob.h
+++ b/src/gui/notificationconfirmjob.h
@@ -24,6 +24,8 @@
 
 namespace OCC {
 
+class NotificationWidget;
+
 /**
  * @brief The NotificationConfirmJob class
  * @ingroup gui
@@ -51,6 +53,10 @@ public:
      */
     void start() Q_DECL_OVERRIDE;
 
+    void setWidget( NotificationWidget *widget );
+
+    NotificationWidget *widget();
+
 signals:
 
     /**
@@ -66,6 +72,7 @@ private slots:
 private:
     QString _verb;
     QUrl _link;
+    NotificationWidget *_widget;
 };
 
 }
diff --git a/src/gui/notificationwidget.cpp b/src/gui/notificationwidget.cpp
index 4160968..db94138 100644
--- a/src/gui/notificationwidget.cpp
+++ b/src/gui/notificationwidget.cpp
@@ -12,6 +12,7 @@
  */
 
 #include "notificationwidget.h"
+#include "QProgressIndicator.h"
 
 #include <QPushButton>
 
@@ -20,6 +21,8 @@ namespace OCC {
 NotificationWidget::NotificationWidget(QWidget *parent) : QWidget(parent)
 {
     _ui.setupUi(this);
+    _progressIndi = new QProgressIndicator(this);
+    _ui.horizontalLayout->addWidget(_progressIndi);
 }
 
 void NotificationWidget::setAccountName( const QString& name )
@@ -65,19 +68,40 @@ void NotificationWidget::slotButtonClicked()
     QObject *buttonWidget = QObject::sender();
     int index = -1;
     if( buttonWidget ) {
+        // find the button that was clicked, it has to be in the list
+        // of buttons that were added to the button box before.
         for( int i = 0; i < _buttons.count(); i++ ) {
             if( _buttons.at(i) == buttonWidget ) {
                 index = i;
-                break;
             }
+            _buttons.at(i)->setEnabled(false);
         }
+
+        // if the button was found, the link must be called
         if( index > -1 && index < _myActivity._links.count() ) {
             ActivityLink triggeredLink = _myActivity._links.at(index);
             qDebug() << "Notification Link: "<< triggeredLink._verb << triggeredLink._link;
-
+            _progressIndi->startAnimation();
             emit sendNotificationRequest( _accountName, triggeredLink._link, triggeredLink._verb );
         }
     }
 }
 
+void NotificationWidget::slotNotificationRequestFinished(int statusCode)
+{
+    int i = 0;
+    // the ocs API returns stat code 100 if it succeeded.
+    if( statusCode != 100 ) {
+        qDebug() << "Notification Request to Server failed, leave button visible.";
+        for( i = 0; i < _buttons.count(); i++ ) {
+            _buttons.at(i)->setEnabled(true);
+        }
+    } else {
+        // the call to the ocs API succeeded.
+        _ui._buttonBox->hide();
+
+    }
+    _progressIndi->stopAnimation();
+}
+
 }
diff --git a/src/gui/notificationwidget.h b/src/gui/notificationwidget.h
index 63f4e14..c183742 100644
--- a/src/gui/notificationwidget.h
+++ b/src/gui/notificationwidget.h
@@ -35,6 +35,7 @@ signals:
 
 public slots:
      void setActivity(const Activity& activity);
+     void slotNotificationRequestFinished(int statusCode);
 
 private slots:
      void slotButtonClicked();
@@ -44,6 +45,7 @@ private:
     Activity _myActivity;
     QList<QPushButton*> _buttons;
     QString _accountName;
+    QProgressIndicator *_progressIndi;
 };
 
 }

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