2015-10-19 15:41:53 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
|
|
|
*
|
|
|
|
* 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 ACTIVITYWIDGET_H
|
|
|
|
#define ACTIVITYWIDGET_H
|
|
|
|
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QLocale>
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
|
|
|
|
#include "progressdispatcher.h"
|
|
|
|
#include "owncloudgui.h"
|
2015-11-02 00:27:33 +03:00
|
|
|
#include "account.h"
|
2015-10-19 15:41:53 +03:00
|
|
|
|
|
|
|
#include "ui_activitywidget.h"
|
|
|
|
|
|
|
|
class QPushButton;
|
2015-11-10 20:10:58 +03:00
|
|
|
class QProgressIndicator;
|
2015-10-19 15:41:53 +03:00
|
|
|
|
|
|
|
namespace OCC {
|
|
|
|
|
2015-11-02 00:27:33 +03:00
|
|
|
class Account;
|
2015-11-04 18:40:22 +03:00
|
|
|
class AccountStatusPtr;
|
2015-11-10 17:12:35 +03:00
|
|
|
class ProtocolWidget;
|
2016-03-04 19:41:57 +03:00
|
|
|
class JsonApiJob;
|
|
|
|
class NotificationWidget;
|
2015-11-02 00:27:33 +03:00
|
|
|
|
2015-10-19 15:41:53 +03:00
|
|
|
namespace Ui {
|
|
|
|
class ActivityWidget;
|
|
|
|
}
|
|
|
|
class Application;
|
|
|
|
|
2016-03-04 19:41:57 +03:00
|
|
|
/**
|
|
|
|
* @brief The ActivityLink class describes actions of an activity
|
|
|
|
*
|
|
|
|
* These are part of notifications which are mapped into activities.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class ActivityLink
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QHash <QString, QVariant> toVariantHash();
|
|
|
|
|
|
|
|
QString _label;
|
|
|
|
QString _link;
|
|
|
|
QString _verb;
|
|
|
|
bool _isPrimary;
|
|
|
|
};
|
|
|
|
|
2015-10-19 15:41:53 +03:00
|
|
|
/**
|
2015-11-16 17:38:08 +03:00
|
|
|
* @brief Activity Structure
|
2015-10-19 15:41:53 +03:00
|
|
|
* @ingroup gui
|
2015-11-16 17:38:08 +03:00
|
|
|
*
|
|
|
|
* contains all the information describing a single activity.
|
2015-10-19 15:41:53 +03:00
|
|
|
*/
|
|
|
|
|
2015-11-02 00:27:33 +03:00
|
|
|
class Activity
|
|
|
|
{
|
|
|
|
public:
|
2016-03-04 19:41:57 +03:00
|
|
|
enum Type {
|
|
|
|
ActivityType,
|
|
|
|
NotificationType
|
|
|
|
};
|
|
|
|
Type _type;
|
2015-11-02 00:27:33 +03:00
|
|
|
qlonglong _id;
|
|
|
|
QString _subject;
|
|
|
|
QString _message;
|
|
|
|
QString _file;
|
|
|
|
QUrl _link;
|
|
|
|
QDateTime _dateTime;
|
2015-11-02 17:44:13 +03:00
|
|
|
QString _accName;
|
|
|
|
|
2016-03-04 19:41:57 +03:00
|
|
|
QVector <ActivityLink> _links;
|
2015-11-02 17:44:13 +03:00
|
|
|
/**
|
|
|
|
* @brief Sort operator to sort the list youngest first.
|
|
|
|
* @param val
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
bool operator<( const Activity& val ) const {
|
|
|
|
return _dateTime.toMSecsSinceEpoch() > val._dateTime.toMSecsSinceEpoch();
|
|
|
|
}
|
|
|
|
|
2015-11-02 00:27:33 +03:00
|
|
|
};
|
|
|
|
|
2015-11-16 17:38:08 +03:00
|
|
|
/**
|
|
|
|
* @brief The ActivityList
|
|
|
|
* @ingroup gui
|
|
|
|
*
|
|
|
|
* A QList based list of Activities
|
|
|
|
*/
|
2015-11-02 00:27:33 +03:00
|
|
|
class ActivityList:public QList<Activity>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void setAccountName( const QString& name );
|
|
|
|
QString accountName() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString _accountName;
|
|
|
|
};
|
|
|
|
|
2015-11-02 17:44:13 +03:00
|
|
|
|
2015-11-16 17:38:08 +03:00
|
|
|
/**
|
|
|
|
* @brief The ActivityListModel
|
|
|
|
* @ingroup gui
|
|
|
|
*
|
|
|
|
* Simple list model to provide the list view with data.
|
|
|
|
*/
|
2015-10-19 15:41:53 +03:00
|
|
|
class ActivityListModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit ActivityListModel(QWidget *parent=0);
|
|
|
|
|
|
|
|
QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
|
|
|
|
int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
|
|
|
|
2015-11-17 11:54:38 +03:00
|
|
|
bool canFetchMore(const QModelIndex& ) const Q_DECL_OVERRIDE;
|
|
|
|
void fetchMore(const QModelIndex&) Q_DECL_OVERRIDE;
|
2015-11-02 17:44:13 +03:00
|
|
|
|
2015-11-10 17:12:35 +03:00
|
|
|
ActivityList activityList() { return _finalList; }
|
|
|
|
|
2015-11-02 19:52:04 +03:00
|
|
|
public slots:
|
2015-11-04 18:40:22 +03:00
|
|
|
void slotRefreshActivity(AccountState* ast);
|
2015-11-12 17:39:07 +03:00
|
|
|
void slotRemoveAccount( AccountState *ast );
|
2015-11-02 19:52:04 +03:00
|
|
|
|
2015-11-02 17:44:13 +03:00
|
|
|
private slots:
|
2015-11-19 17:59:10 +03:00
|
|
|
void slotActivitiesReceived(const QVariantMap& json, int statusCode);
|
2015-11-02 17:44:13 +03:00
|
|
|
|
2015-11-19 18:00:22 +03:00
|
|
|
signals:
|
2016-03-08 20:01:42 +03:00
|
|
|
void activityJobStatusCode(AccountState* ast, int statusCode);
|
2015-11-19 18:00:22 +03:00
|
|
|
|
2015-11-02 00:27:33 +03:00
|
|
|
private:
|
2015-11-04 18:40:22 +03:00
|
|
|
void startFetchJob(AccountState* s);
|
2015-11-02 17:44:13 +03:00
|
|
|
void combineActivityLists();
|
2015-11-02 00:27:33 +03:00
|
|
|
|
2015-11-04 18:40:22 +03:00
|
|
|
QMap<AccountState*, ActivityList> _activityLists;
|
2015-11-02 17:44:13 +03:00
|
|
|
ActivityList _finalList;
|
2015-11-04 18:40:22 +03:00
|
|
|
QSet<AccountState*> _currentlyFetching;
|
2015-10-19 15:41:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The ActivityWidget class
|
|
|
|
* @ingroup gui
|
2015-11-16 17:38:08 +03:00
|
|
|
*
|
|
|
|
* The list widget to display the activities, contained in the
|
|
|
|
* subsequent ActivitySettings widget.
|
2015-10-19 15:41:53 +03:00
|
|
|
*/
|
2015-11-10 17:12:35 +03:00
|
|
|
|
2015-10-19 15:41:53 +03:00
|
|
|
class ActivityWidget : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit ActivityWidget(QWidget *parent = 0);
|
|
|
|
~ActivityWidget();
|
2015-11-19 12:50:52 +03:00
|
|
|
QSize sizeHint() const Q_DECL_OVERRIDE { return ownCloudGui::settingsDialogSize(); }
|
2015-11-10 17:12:35 +03:00
|
|
|
void storeActivityList(QTextStream &ts);
|
2015-11-02 17:44:13 +03:00
|
|
|
|
2015-10-19 15:41:53 +03:00
|
|
|
public slots:
|
2015-11-16 17:31:24 +03:00
|
|
|
void slotOpenFile(QModelIndex indx);
|
2015-11-04 18:40:22 +03:00
|
|
|
void slotRefresh(AccountState* ptr);
|
2015-11-12 17:39:07 +03:00
|
|
|
void slotRemoveAccount( AccountState *ptr );
|
2016-03-08 20:01:42 +03:00
|
|
|
void slotAccountActivityStatus(AccountState *ast, int statusCode);
|
2016-03-04 19:41:57 +03:00
|
|
|
void slotFetchNotifications(AccountState *ptr);
|
2015-10-19 15:41:53 +03:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void guiLog(const QString&, const QString&);
|
2015-11-10 17:12:35 +03:00
|
|
|
void copyToClipboard();
|
2015-11-10 20:10:58 +03:00
|
|
|
void rowsInserted();
|
2016-03-08 20:01:42 +03:00
|
|
|
void hideAcitivityTab(bool);
|
2016-03-04 19:41:57 +03:00
|
|
|
void newNotificationList(const ActivityList& list);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void slotNotificationsReceived(const QVariantMap& json, int statusCode);
|
|
|
|
void slotBuildNotificationDisplay(const ActivityList& list);
|
|
|
|
void slotSendNotificationRequest(const QString &accountName, const QString& link, const QString& verb);
|
|
|
|
void slotNotifyNetworkError( QNetworkReply* );
|
|
|
|
void slotNotifyServerFinished( const QString& reply, int replyCode );
|
2015-10-19 15:41:53 +03:00
|
|
|
|
|
|
|
private:
|
2015-11-19 18:00:22 +03:00
|
|
|
void showLabels();
|
2015-10-19 15:41:53 +03:00
|
|
|
QString timeString(QDateTime dt, QLocale::FormatType format) const;
|
|
|
|
Ui::ActivityWidget *_ui;
|
|
|
|
QPushButton *_copyBtn;
|
2015-11-02 00:27:33 +03:00
|
|
|
|
2015-11-19 18:00:22 +03:00
|
|
|
QSet<QString> _accountsWithoutActivities;
|
2016-03-04 19:41:57 +03:00
|
|
|
QMap<int, NotificationWidget*> _widgetForNotifId;
|
|
|
|
QPointer<JsonApiJob> _notificationJob;
|
2015-11-02 00:27:33 +03:00
|
|
|
ActivityListModel *_model;
|
2016-03-04 19:41:57 +03:00
|
|
|
QVBoxLayout *_notificationsLayout;
|
2015-10-19 15:41:53 +03:00
|
|
|
};
|
|
|
|
|
2015-11-10 17:12:35 +03:00
|
|
|
|
2015-11-16 17:38:08 +03:00
|
|
|
/**
|
|
|
|
* @brief The ActivitySettings class
|
|
|
|
* @ingroup gui
|
|
|
|
*
|
|
|
|
* Implements a tab for the settings dialog, displaying the three activity
|
|
|
|
* lists.
|
|
|
|
*/
|
2015-11-10 17:12:35 +03:00
|
|
|
class ActivitySettings : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit ActivitySettings(QWidget *parent = 0);
|
|
|
|
~ActivitySettings();
|
2015-11-19 12:50:52 +03:00
|
|
|
QSize sizeHint() const Q_DECL_OVERRIDE { return ownCloudGui::settingsDialogSize(); }
|
2015-11-10 17:12:35 +03:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void slotRefresh( AccountState* ptr );
|
2015-11-12 17:39:07 +03:00
|
|
|
void slotRemoveAccount( AccountState *ptr );
|
|
|
|
|
2016-03-08 20:01:42 +03:00
|
|
|
private slots:
|
2015-11-10 17:12:35 +03:00
|
|
|
void slotCopyToClipboard();
|
2016-03-08 20:01:42 +03:00
|
|
|
void setActivityTabHidden(bool hidden);
|
2015-11-10 17:12:35 +03:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void guiLog(const QString&, const QString&);
|
|
|
|
|
|
|
|
private:
|
2015-11-18 17:25:29 +03:00
|
|
|
bool event(QEvent* e) Q_DECL_OVERRIDE;
|
|
|
|
|
2015-11-10 17:12:35 +03:00
|
|
|
QTabWidget *_tab;
|
2016-03-08 20:01:42 +03:00
|
|
|
int _activityTabId;
|
|
|
|
|
2015-11-10 17:12:35 +03:00
|
|
|
ActivityWidget *_activityWidget;
|
|
|
|
ProtocolWidget *_protocolWidget;
|
2015-11-10 20:10:58 +03:00
|
|
|
QProgressIndicator *_progressIndicator;
|
2015-11-10 17:12:35 +03:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-10-19 15:41:53 +03:00
|
|
|
}
|
|
|
|
#endif // ActivityWIDGET_H
|