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 31 class QPushButton; 32 class QProgressIndicator; 33 34 namespace OCC { 35 36 class Account; 37 class AccountStatusPtr; 38 class ProtocolWidget; 39 class IssuesWidget; 40 class JsonApiJob; 41 class NotificationWidget; 42 class ActivityListModel; 43 44 namespace Ui { 45 class ActivityWidget; 46 } 47 class 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 57 class ActivityWidget : public QWidget 58 { 59 Q_OBJECT 60 public: 61 explicit ActivityWidget(QWidget *parent = nullptr); 62 ~ActivityWidget() override; 63 void storeActivityList(QTextStream &ts); 64 65 /** 66 * Adjusts the activity tab's and some widgets' visibility 67 * 68 * Based on whether activities are enabled and whether notifications are 69 * available. 70 */ 71 void checkActivityTabVisibility(); 72 73 public slots: 74 void slotOpenFile(QModelIndex indx); 75 void slotRefreshActivities(AccountState *ptr); 76 void slotRefreshNotifications(AccountState *ptr); 77 void slotRemoveAccount(AccountState *ptr); 78 void slotAccountActivityStatus(AccountState *ast, int statusCode); 79 void slotRequestCleanupAndBlacklist(const Activity &blacklistActivity); 80 81 signals: 82 void guiLog(const QString &, const QString &); 83 void copyToClipboard(); 84 void rowsInserted(); 85 void hideActivityTab(bool); 86 void newNotification(); 87 88 private slots: 89 void slotBuildNotificationDisplay(const ActivityList &list); 90 void slotSendNotificationRequest(const QString &accountName, const QString &link, const QByteArray &verb); 91 void slotNotifyNetworkError(QNetworkReply *); 92 void slotNotifyServerFinished(const QString &reply, int replyCode); 93 void endNotificationRequest(NotificationWidget *widget, int replyCode); 94 void scheduleWidgetToRemove(NotificationWidget *widget, int milliseconds = 100); 95 void slotCheckToCleanWidgets(); 96 97 private: 98 void showLabels(); 99 QString timeString(QDateTime dt, QLocale::FormatType format) const; 100 Ui::ActivityWidget *_ui; 101 QPushButton *_copyBtn; 102 103 QSet<QString> _accountsWithoutActivities; 104 QMap<Activity::Identifier, NotificationWidget *> _widgetForNotifId; 105 QElapsedTimer _guiLogTimer; 106 QSet<int> _guiLoggedNotifications; 107 ActivityList _blacklistedNotifications; 108 109 QHash<NotificationWidget *, QDateTime> _widgetsToRemove; 110 QTimer _removeTimer; 111 112 // number of currently running notification requests. If non zero, 113 // no query for notifications is started. 114 int _notificationRequestsRunning; 115 116 ActivityListModel *_model; 117 QVBoxLayout *_notificationsLayout; 118 }; 119 120 121 /** 122 * @brief The ActivitySettings class 123 * @ingroup gui 124 * 125 * Implements a tab for the settings dialog, displaying the three activity 126 * lists. 127 */ 128 class ActivitySettings : public QWidget 129 { 130 Q_OBJECT 131 public: 132 explicit ActivitySettings(QWidget *parent = nullptr); 133 ~ActivitySettings() override; 134 135 public slots: 136 void slotRefresh(AccountState *ptr); 137 void slotRemoveAccount(AccountState *ptr); 138 139 void setNotificationRefreshInterval(std::chrono::milliseconds interval); 140 141 void slotShowIssuesTab(const QString &folderAlias); 142 143 private slots: 144 void slotCopyToClipboard(); 145 void setActivityTabHidden(bool hidden); 146 void slotRegularNotificationCheck(); 147 void slotShowIssueItemCount(int cnt); 148 void slotShowActivityTab(); 149 150 signals: 151 void guiLog(const QString &, const QString &); 152 153 private: 154 bool event(QEvent *e) override; 155 156 QTabWidget *_tab; 157 int _activityTabId; 158 int _protocolTabId; 159 int _syncIssueTabId; 160 161 ActivityWidget *_activityWidget; 162 ProtocolWidget *_protocolWidget; 163 IssuesWidget *_issuesWidget; 164 QProgressIndicator *_progressIndicator; 165 QTimer _notificationCheckTimer; 166 QHash<AccountState *, QElapsedTimer> _timeSinceLastCheck; 167 }; 168 } 169 #endif // ActivityWIDGET_H 170