1 #if !defined(SYNCTHINGWIDGETS_DBUSSTATUSNOTIFIER_H) && defined(QT_UTILITIES_SUPPORT_DBUS_NOTIFICATIONS)
2 #define SYNCTHINGWIDGETS_DBUSSTATUSNOTIFIER_H
3
4 #include "./internalerror.h"
5
6 #include <qtutilities/misc/dbusnotification.h>
7
8 #include <c++utilities/chrono/datetime.h>
9
10 #include <QObject>
11 #include <QStringList>
12
13 namespace Data {
14 enum class SyncthingErrorCategory;
15 struct StatusIcons;
16 } // namespace Data
17
18 namespace QtGui {
19
20 class SYNCTHINGWIDGETS_EXPORT DBusStatusNotifier : public QObject {
21 Q_OBJECT
22
23 public:
24 explicit DBusStatusNotifier(QObject *parent = nullptr);
25
26 public Q_SLOTS:
27 void showDisconnect();
28 void hideDisconnect();
29 void showInternalError(const InternalError &error);
30 void showLauncherError(const QString &errorMessage, const QString &additionalInfo);
31 void showSyncthingNotification(CppUtilities::DateTime when, const QString &message);
32 void showSyncComplete(const QString &message);
33 void showNewDev(const QString &devId, const QString &message);
34 void showNewDir(const QString &devId, const QString &dirId, const QString &message);
35 void setIcons(const Data::StatusIcons &statusIcons, const Data::StatusIcons &icons);
36
37 Q_SIGNALS:
38 void connectRequested();
39 void dismissNotificationsRequested();
40 void showNotificationsRequested();
41 void errorDetailsRequested();
42 void webUiRequested();
43
44 private Q_SLOTS:
45 void handleSyncthingNotificationAction(const QString &action);
46
47 private:
48 QtUtilities::DBusNotification m_disconnectedNotification;
49 QtUtilities::DBusNotification m_internalErrorNotification;
50 QtUtilities::DBusNotification m_launcherErrorNotification;
51 QtUtilities::DBusNotification m_syncthingNotification;
52 QtUtilities::DBusNotification m_syncCompleteNotification;
53 QtUtilities::DBusNotification m_newDevNotification;
54 QtUtilities::DBusNotification m_newDirNotification;
55 };
56
showDisconnect()57 inline void DBusStatusNotifier::showDisconnect()
58 {
59 m_disconnectedNotification.show();
60 }
61
hideDisconnect()62 inline void DBusStatusNotifier::hideDisconnect()
63 {
64 m_disconnectedNotification.hide();
65 }
66
showInternalError(const InternalError & error)67 inline void DBusStatusNotifier::showInternalError(const InternalError &error)
68 {
69 m_internalErrorNotification.update(error.message);
70 }
71
showLauncherError(const QString & errorMessage,const QString & additionalInfo)72 inline void QtGui::DBusStatusNotifier::showLauncherError(const QString &errorMessage, const QString &additionalInfo)
73 {
74 m_launcherErrorNotification.update(QStringList({ errorMessage, additionalInfo }).join(QStringLiteral("\n ")));
75 }
76
showSyncthingNotification(CppUtilities::DateTime when,const QString & message)77 inline void DBusStatusNotifier::showSyncthingNotification(CppUtilities::DateTime when, const QString &message)
78 {
79 Q_UNUSED(when)
80 m_syncthingNotification.update(message);
81 }
82
showSyncComplete(const QString & message)83 inline void DBusStatusNotifier::showSyncComplete(const QString &message)
84 {
85 m_syncCompleteNotification.update(message);
86 }
87
showNewDev(const QString & devId,const QString & message)88 inline void DBusStatusNotifier::showNewDev(const QString &devId, const QString &message)
89 {
90 Q_UNUSED(devId)
91 m_newDevNotification.update(message);
92 }
93
showNewDir(const QString & devId,const QString & dirId,const QString & message)94 inline void DBusStatusNotifier::showNewDir(const QString &devId, const QString &dirId, const QString &message)
95 {
96 Q_UNUSED(devId)
97 Q_UNUSED(dirId)
98 m_newDirNotification.update(message);
99 }
100
101 } // namespace QtGui
102
103 #endif // !defined(SYNCTHINGWIDGETS_DBUSSTATUSNOTIFIER_H) && defined(QT_UTILITIES_SUPPORT_DBUS_NOTIFICATIONS)
104