mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-23 13:35:58 +03:00
ActivityWidget: Add a job to fetch activities, Activity object added
This commit is contained in:
parent
9279bcdba4
commit
302d6b321e
2 changed files with 113 additions and 4 deletions
|
@ -27,6 +27,9 @@
|
||||||
#include "folder.h"
|
#include "folder.h"
|
||||||
#include "openfilemanager.h"
|
#include "openfilemanager.h"
|
||||||
#include "owncloudpropagator.h"
|
#include "owncloudpropagator.h"
|
||||||
|
#include "account.h"
|
||||||
|
#include "accountstate.h"
|
||||||
|
#include "accountmanager.h"
|
||||||
|
|
||||||
#include "ui_activitywidget.h"
|
#include "ui_activitywidget.h"
|
||||||
|
|
||||||
|
@ -34,6 +37,18 @@
|
||||||
|
|
||||||
namespace OCC {
|
namespace OCC {
|
||||||
|
|
||||||
|
void ActivityList::setAccountName( const QString& name )
|
||||||
|
{
|
||||||
|
_accountName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ActivityList::accountName() const
|
||||||
|
{
|
||||||
|
return _accountName;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========================================================================
|
||||||
|
|
||||||
ActivityListModel::ActivityListModel(QWidget *parent)
|
ActivityListModel::ActivityListModel(QWidget *parent)
|
||||||
:QAbstractListModel(parent)
|
:QAbstractListModel(parent)
|
||||||
{
|
{
|
||||||
|
@ -62,7 +77,19 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const
|
||||||
|
|
||||||
int ActivityListModel::rowCount(const QModelIndex&) 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);
|
_ui->_activityList->setMinimumWidth(400);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_ui->_activityList->setModel(new ActivityListModel(this));
|
_model = new ActivityListModel(this);
|
||||||
|
_ui->_activityList->setModel(_model);
|
||||||
connect(this, SIGNAL(guiLog(QString,QString)), Logger::instance(), SIGNAL(guiLog(QString,QString)));
|
|
||||||
|
|
||||||
_copyBtn = _ui->_dialogButtonBox->addButton(tr("Copy"), QDialogButtonBox::ActionRole);
|
_copyBtn = _ui->_dialogButtonBox->addButton(tr("Copy"), QDialogButtonBox::ActionRole);
|
||||||
_copyBtn->setToolTip( tr("Copy the activity list to the clipboard."));
|
_copyBtn->setToolTip( tr("Copy the activity list to the clipboard."));
|
||||||
_copyBtn->setEnabled(false);
|
_copyBtn->setEnabled(false);
|
||||||
connect(_copyBtn, SIGNAL(clicked()), SLOT(copyToClipboard()));
|
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()
|
ActivityWidget::~ActivityWidget()
|
||||||
{
|
{
|
||||||
delete _ui;
|
delete _ui;
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include "progressdispatcher.h"
|
#include "progressdispatcher.h"
|
||||||
#include "owncloudgui.h"
|
#include "owncloudgui.h"
|
||||||
|
#include "account.h"
|
||||||
|
|
||||||
#include "ui_activitywidget.h"
|
#include "ui_activitywidget.h"
|
||||||
|
|
||||||
|
@ -28,6 +29,8 @@ class QPushButton;
|
||||||
|
|
||||||
namespace OCC {
|
namespace OCC {
|
||||||
|
|
||||||
|
class Account;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ActivityWidget;
|
class ActivityWidget;
|
||||||
}
|
}
|
||||||
|
@ -38,6 +41,28 @@ class Application;
|
||||||
* @ingroup gui
|
* @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
|
class ActivityListModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -47,6 +72,10 @@ public:
|
||||||
QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
|
QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
|
||||||
int rowCount(const QModelIndex& parent = QModelIndex()) 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(); }
|
QSize sizeHint() const { return ownCloudGui::settingsDialogSize(); }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void slotAddAccount( AccountStatePtr s );
|
||||||
void slotOpenFile();
|
void slotOpenFile();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void copyToClipboard();
|
void copyToClipboard();
|
||||||
|
void slotRefresh();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void slotActivitiesReceived(const QVariantMap& json);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -76,6 +110,9 @@ private:
|
||||||
QString timeString(QDateTime dt, QLocale::FormatType format) const;
|
QString timeString(QDateTime dt, QLocale::FormatType format) const;
|
||||||
Ui::ActivityWidget *_ui;
|
Ui::ActivityWidget *_ui;
|
||||||
QPushButton *_copyBtn;
|
QPushButton *_copyBtn;
|
||||||
|
QTimer _timer;
|
||||||
|
|
||||||
|
ActivityListModel *_model;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue