1/*
2 * Copyright (C) by Klaas Freitag <freitag@owncloud.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 */
14
15#ifndef ACTIVITYWIDGET_H
16#define ACTIVITYWIDGET_H
17
18#include <QDialog>
19#include <QDateTime>
20#include <QLocale>
21#include <QAbstractListModel>
22#include <chrono>
23
24#include "progressdispatcher.h"
25#include "owncloudgui.h"
26#include "account.h"
27#include "activitydata.h"
28
29#include "ui_activitywidget.h"
30
31class QPushButton;
32class QProgressIndicator;
33
34namespace OCC {
35
36class Account;
37class AccountStatusPtr;
38class ProtocolWidget;
39class IssuesWidget;
40class JsonApiJob;
41class NotificationWidget;
42class ActivityListModel;
43
44namespace Ui {
45 class ActivityWidget;
46}
47class Application;
48
49/**
50 * @brief The ActivityWidget class
51 * @ingroup gui
52 *
53 * The list widget to display the activities, contained in the
54 * subsequent ActivitySettings widget.
55 */
56
57class ActivityWidget : public QWidget
58{
59 Q_OBJECT
60public:
61 explicit ActivityWidget(QWidget *parent = 0);
62 ~ActivityWidget();
63 QSize sizeHint() const Q_DECL_OVERRIDE { return ownCloudGui::settingsDialogSize(); }
64 void storeActivityList(QTextStream &ts);
65
66 /**
67 * Adjusts the activity tab's and some widgets' visibility
68 *
69 * Based on whether activities are enabled and whether notifications are
70 * available.
71 */
72 void checkActivityTabVisibility();
73
74public slots:
75 void slotOpenFile(QModelIndex indx);
76 void slotRefreshActivities(AccountState *ptr);
77 void slotRefreshNotifications(AccountState *ptr);
78 void slotRemoveAccount(AccountState *ptr);
79 void slotAccountActivityStatus(AccountState *ast, int statusCode);
80 void slotRequestCleanupAndBlacklist(const Activity &blacklistActivity);
81
82signals:
83 void guiLog(const QString &, const QString &);
84 void copyToClipboard();
85 void rowsInserted();
86 void hideActivityTab(bool);
87 void newNotification();
88
89private slots:
90 void slotBuildNotificationDisplay(const ActivityList &list);
91 void slotSendNotificationRequest(const QString &accountName, const QString &link, const QByteArray &verb);
92 void slotNotifyNetworkError(QNetworkReply *);
93 void slotNotifyServerFinished(const QString &reply, int replyCode);
94 void endNotificationRequest(NotificationWidget *widget, int replyCode);
95 void scheduleWidgetToRemove(NotificationWidget *widget, int milliseconds = 100);
96 void slotCheckToCleanWidgets();
97
98private:
99 void showLabels();
100 QString timeString(QDateTime dt, QLocale::FormatType format) const;
101 Ui::ActivityWidget *_ui;
102 QPushButton *_copyBtn;
103
104 QSet<QString> _accountsWithoutActivities;
105 QMap<Activity::Identifier, NotificationWidget *> _widgetForNotifId;
106 QElapsedTimer _guiLogTimer;
107 QSet<int> _guiLoggedNotifications;
108 ActivityList _blacklistedNotifications;
109
110 QHash<NotificationWidget *, QDateTime> _widgetsToRemove;
111 QTimer _removeTimer;
112
113 // number of currently running notification requests. If non zero,
114 // no query for notifications is started.
115 int _notificationRequestsRunning;
116
117 ActivityListModel *_model;
118 QVBoxLayout *_notificationsLayout;
119};
120
121
122/**
123 * @brief The ActivitySettings class
124 * @ingroup gui
125 *
126 * Implements a tab for the settings dialog, displaying the three activity
127 * lists.
128 */
129class ActivitySettings : public QWidget
130{
131 Q_OBJECT
132public:
133 explicit ActivitySettings(QWidget *parent = 0);
134 ~ActivitySettings();
135 QSize sizeHint() const Q_DECL_OVERRIDE { return ownCloudGui::settingsDialogSize(); }
136
137public slots:
138 void slotRefresh(AccountState *ptr);
139 void slotRemoveAccount(AccountState *ptr);
140
141 void setNotificationRefreshInterval(std::chrono::milliseconds interval);
142
143 void slotShowIssuesTab(const QString &folderAlias);
144
145private slots:
146 void slotCopyToClipboard();
147 void setActivityTabHidden(bool hidden);
148 void slotRegularNotificationCheck();
149 void slotShowIssueItemCount(int cnt);
150 void slotShowActivityTab();
151
152signals:
153 void guiLog(const QString &, const QString &);
154
155private:
156 bool event(QEvent *e) Q_DECL_OVERRIDE;
157
158 QTabWidget *_tab;
159 int _activityTabId;
160 int _protocolTabId;
161 int _syncIssueTabId;
162
163 ActivityWidget *_activityWidget;
164 ProtocolWidget *_protocolWidget;
165 IssuesWidget *_issuesWidget;
166 QProgressIndicator *_progressIndicator;
167 QTimer _notificationCheckTimer;
168 QHash<AccountState *, QElapsedTimer> _timeSinceLastCheck;
169};
170}
171#endif // ActivityWIDGET_H
172