[Pkg-owncloud-commits] [owncloud-client] 225/484: ActivityWidget: Add a job to fetch activities, Activity object added

Sandro Knauß hefee-guest at moszumanska.debian.org
Wed Dec 16 00:37:45 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 302d6b321e3e6a8280429c119410aaf7f2f245ec
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Sun Nov 1 22:27:33 2015 +0100

    ActivityWidget: Add a job to fetch activities, Activity object added
---
 src/gui/activitywidget.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++---
 src/gui/activitywidget.h   | 37 +++++++++++++++++++++
 2 files changed, 113 insertions(+), 4 deletions(-)

diff --git a/src/gui/activitywidget.cpp b/src/gui/activitywidget.cpp
index 04539b3..7c6c022 100644
--- a/src/gui/activitywidget.cpp
+++ b/src/gui/activitywidget.cpp
@@ -27,6 +27,9 @@
 #include "folder.h"
 #include "openfilemanager.h"
 #include "owncloudpropagator.h"
+#include "account.h"
+#include "accountstate.h"
+#include "accountmanager.h"
 
 #include "ui_activitywidget.h"
 
@@ -34,6 +37,18 @@
 
 namespace OCC {
 
+void ActivityList::setAccountName( const QString& name )
+{
+    _accountName = name;
+}
+
+QString ActivityList::accountName() const
+{
+    return _accountName;
+}
+
+// ========================================================================
+
 ActivityListModel::ActivityListModel(QWidget *parent)
     :QAbstractListModel(parent)
 {
@@ -62,7 +77,19 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const
 
 int ActivityListModel::rowCount(const QModelIndex&) const
 {
-    return 4;
+    int cnt = 0;
+    foreach(ActivityList al, _activityLists) {
+        cnt += al.count();
+    }
+    return cnt;
+}
+
+void ActivityListModel::addActivities( const ActivityList& activities )
+{
+    bool found = false;
+
+    // build up a time list here.
+
 }
 
 /* ==================================================================== */
@@ -78,16 +105,61 @@ ActivityWidget::ActivityWidget(QWidget *parent) :
     _ui->_activityList->setMinimumWidth(400);
 #endif
 
-    _ui->_activityList->setModel(new ActivityListModel(this));
-
-    connect(this, SIGNAL(guiLog(QString,QString)), Logger::instance(), SIGNAL(guiLog(QString,QString)));
+    _model = new ActivityListModel(this);
+    _ui->_activityList->setModel(_model);
 
     _copyBtn = _ui->_dialogButtonBox->addButton(tr("Copy"), QDialogButtonBox::ActionRole);
     _copyBtn->setToolTip( tr("Copy the activity list to the clipboard."));
     _copyBtn->setEnabled(false);
     connect(_copyBtn, SIGNAL(clicked()), SLOT(copyToClipboard()));
+
+    connect( &_timer, SIGNAL(timeout()), this, SLOT(slotRefresh()));
+
+    _timer.start(10000);
 }
 
+void ActivityWidget::slotRefresh()
+{
+    foreach (auto ai , AccountManager::instance()->accounts()) {
+        if( ai->isConnected() ) {
+            slotAddAccount(ai);
+        }
+    }
+}
+
+void ActivityWidget::slotAddAccount( AccountStatePtr s )
+{
+    if( s && s->state() == AccountState::Connected ) {
+        // start a new fetch job for this account
+
+        JsonApiJob *job = new JsonApiJob(s->account(), QLatin1String("ocs/v1.php/cloud/activity"), this);
+        QObject::connect(job, SIGNAL(jsonRecieved(QVariantMap)), this, SLOT(slotActivitiesReceived(QVariantMap)));
+        job->setProperty("AccountStatePtr", QVariant::fromValue<AccountStatePtr>(s));
+        job->start();
+
+    }
+}
+
+void ActivityWidget::slotActivitiesReceived(const QVariantMap& json)
+{
+    auto activities = json.value("ocs").toMap().value("data").toList();
+    qDebug() << "*** activities" << activities;
+
+    ActivityList list;
+    AccountStatePtr ai = qvariant_cast<AccountStatePtr>(sender()->property("AccountStatePtr"));
+
+    list.setAccountName( ai->account()->displayName());
+    foreach( auto activ, activities ) {
+        Activity a;
+        a._id = activ.toMap().value("id").toLongLong();
+        a._subject = activ.toMap().value("subject").toString();
+        list.append(a);
+    }
+
+   _model->addActivities(list);
+}
+
+
 ActivityWidget::~ActivityWidget()
 {
     delete _ui;
diff --git a/src/gui/activitywidget.h b/src/gui/activitywidget.h
index 1fa9262..1f99dcb 100644
--- a/src/gui/activitywidget.h
+++ b/src/gui/activitywidget.h
@@ -21,6 +21,7 @@
 
 #include "progressdispatcher.h"
 #include "owncloudgui.h"
+#include "account.h"
 
 #include "ui_activitywidget.h"
 
@@ -28,6 +29,8 @@ class QPushButton;
 
 namespace OCC {
 
+class Account;
+
 namespace Ui {
   class ActivityWidget;
 }
@@ -38,6 +41,28 @@ class Application;
  * @ingroup gui
  */
 
+class Activity
+{
+public:
+    qlonglong _id;
+    QString   _subject;
+    QString   _message;
+    QString   _file;
+    QUrl      _link;
+    QDateTime _dateTime;
+};
+
+class ActivityList:public QList<Activity>
+{
+    // explicit ActivityList();
+public:
+    void setAccountName( const QString& name );
+    QString accountName() const;
+
+private:
+    QString _accountName;
+};
+
 class ActivityListModel : public QAbstractListModel
 {
     Q_OBJECT
@@ -47,6 +72,10 @@ public:
     QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
     int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
 
+    void addActivities( const ActivityList& activities );
+private:
+
+    QMap<QString, ActivityList> _activityLists;
 };
 
 /**
@@ -62,10 +91,15 @@ public:
     QSize sizeHint() const { return ownCloudGui::settingsDialogSize(); }
 
 public slots:
+    void slotAddAccount( AccountStatePtr s );
     void slotOpenFile();
 
 protected slots:
     void copyToClipboard();
+    void slotRefresh();
+
+private slots:
+    void slotActivitiesReceived(const QVariantMap& json);
 
 protected:
 
@@ -76,6 +110,9 @@ private:
     QString timeString(QDateTime dt, QLocale::FormatType format) const;
     Ui::ActivityWidget *_ui;
     QPushButton *_copyBtn;
+    QTimer _timer;
+
+    ActivityListModel *_model;
 };
 
 }

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