2017-04-25 00:50:30 +02:00
|
|
|
#ifdef QT_UTILITIES_SUPPORT_DBUS_NOTIFICATIONS
|
|
|
|
#include "./dbusstatusnotifier.h"
|
|
|
|
|
2021-01-25 19:48:11 +01:00
|
|
|
#include <syncthingmodel/syncthingicons.h>
|
2018-03-18 03:09:07 +01:00
|
|
|
|
2017-09-09 21:34:25 +02:00
|
|
|
// use meta-data of syncthingtray application here
|
|
|
|
#include "resources/../../tray/resources/config.h"
|
|
|
|
|
2017-04-25 00:50:30 +02:00
|
|
|
#include <QCoreApplication>
|
2018-03-18 03:09:07 +01:00
|
|
|
#include <QPixmap>
|
2017-04-25 00:50:30 +02:00
|
|
|
|
|
|
|
using namespace Data;
|
2019-06-10 22:48:26 +02:00
|
|
|
using namespace QtUtilities;
|
2017-04-25 00:50:30 +02:00
|
|
|
|
|
|
|
namespace QtGui {
|
|
|
|
|
2018-05-01 22:27:03 +02:00
|
|
|
inline QImage makeImage(const QIcon &icon)
|
|
|
|
{
|
|
|
|
return icon.pixmap(QSize(128, 128)).toImage();
|
|
|
|
}
|
|
|
|
|
2017-05-01 03:34:43 +02:00
|
|
|
DBusStatusNotifier::DBusStatusNotifier(QObject *parent)
|
|
|
|
: QObject(parent)
|
2017-09-09 21:34:25 +02:00
|
|
|
, m_disconnectedNotification(QStringLiteral(APP_NAME), QStringLiteral("network-disconnect"), 5000)
|
|
|
|
, m_internalErrorNotification(QStringLiteral(APP_NAME) + tr(" - internal error"), NotificationIcon::Critical, 5000)
|
2019-07-12 20:24:19 +02:00
|
|
|
, m_launcherErrorNotification(QStringLiteral(APP_NAME) + tr(" - launcher error"), NotificationIcon::Critical, 5000)
|
2017-05-01 03:34:43 +02:00
|
|
|
, m_syncthingNotification(tr("Syncthing notification"), NotificationIcon::Warning, 10000)
|
2017-09-09 21:34:25 +02:00
|
|
|
, m_syncCompleteNotification(QStringLiteral(APP_NAME), NotificationIcon::Information, 5000)
|
2018-05-01 22:27:03 +02:00
|
|
|
, m_newDevNotification(QStringLiteral(APP_NAME) + tr(" - new device"), NotificationIcon::Information, 5000)
|
|
|
|
, m_newDirNotification(QStringLiteral(APP_NAME) + tr(" - new directory"), NotificationIcon::Information, 5000)
|
2017-04-25 00:50:30 +02:00
|
|
|
{
|
2019-06-16 17:36:26 +02:00
|
|
|
m_disconnectedNotification.setApplicationName(QStringLiteral(APP_NAME));
|
2017-04-25 00:50:30 +02:00
|
|
|
m_disconnectedNotification.setMessage(tr("Disconnected from Syncthing"));
|
2017-08-20 01:21:03 +02:00
|
|
|
m_disconnectedNotification.setActions(QStringList({ QStringLiteral("reconnect"), tr("Try to reconnect") }));
|
2017-04-25 00:50:30 +02:00
|
|
|
connect(&m_disconnectedNotification, &DBusNotification::actionInvoked, this, &DBusStatusNotifier::connectRequested);
|
2018-05-01 22:27:03 +02:00
|
|
|
|
2019-06-16 17:36:26 +02:00
|
|
|
m_internalErrorNotification.setApplicationName(QStringLiteral(APP_NAME));
|
2017-08-20 01:20:47 +02:00
|
|
|
m_internalErrorNotification.setActions(QStringList({ QStringLiteral("details"), tr("View details") }));
|
|
|
|
connect(&m_internalErrorNotification, &DBusNotification::actionInvoked, this, &DBusStatusNotifier::errorDetailsRequested);
|
2018-05-01 22:27:03 +02:00
|
|
|
|
2019-07-12 20:24:19 +02:00
|
|
|
m_internalErrorNotification.setApplicationName(QStringLiteral(APP_NAME));
|
|
|
|
m_internalErrorNotification.setActions(QStringList({ QStringLiteral("details"), tr("View details") }));
|
|
|
|
connect(&m_internalErrorNotification, &DBusNotification::actionInvoked, this, &DBusStatusNotifier::errorDetailsRequested);
|
|
|
|
|
2019-06-16 17:36:26 +02:00
|
|
|
m_syncthingNotification.setApplicationName(QStringLiteral(APP_NAME));
|
2017-05-01 03:34:43 +02:00
|
|
|
m_syncthingNotification.setActions(QStringList({ QStringLiteral("show"), tr("Show"), QStringLiteral("dismiss"), tr("Dismiss") }));
|
2017-04-25 00:50:30 +02:00
|
|
|
connect(&m_syncthingNotification, &DBusNotification::actionInvoked, this, &DBusStatusNotifier::handleSyncthingNotificationAction);
|
2018-05-01 22:27:03 +02:00
|
|
|
|
2019-06-16 17:36:26 +02:00
|
|
|
m_syncCompleteNotification.setApplicationName(QStringLiteral(APP_NAME));
|
|
|
|
|
|
|
|
m_newDevNotification.setApplicationName(QStringLiteral(APP_NAME));
|
2018-05-01 22:27:03 +02:00
|
|
|
m_newDevNotification.setActions(QStringList({ QStringLiteral("webui"), tr("Open web UI") }));
|
|
|
|
connect(&m_newDevNotification, &DBusNotification::actionInvoked, this, &DBusStatusNotifier::webUiRequested);
|
|
|
|
|
2019-06-16 17:36:26 +02:00
|
|
|
m_newDirNotification.setApplicationName(QStringLiteral(APP_NAME));
|
2018-05-01 22:27:03 +02:00
|
|
|
m_newDirNotification.setActions(m_newDevNotification.actions());
|
|
|
|
connect(&m_newDirNotification, &DBusNotification::actionInvoked, this, &DBusStatusNotifier::webUiRequested);
|
2019-05-26 23:13:43 +02:00
|
|
|
|
|
|
|
const auto &iconManager = IconManager::instance();
|
|
|
|
connect(&iconManager, &Data::IconManager::statusIconsChanged, this, &DBusStatusNotifier::setIcons);
|
2019-07-31 20:16:43 +02:00
|
|
|
setIcons(iconManager.statusIcons(), iconManager.trayIcons());
|
2019-05-26 23:13:43 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 20:16:43 +02:00
|
|
|
void DBusStatusNotifier::setIcons(const StatusIcons &, const StatusIcons &icons)
|
2019-05-26 23:13:43 +02:00
|
|
|
{
|
|
|
|
if (!icons.isValid) {
|
|
|
|
return;
|
|
|
|
}
|
2019-07-12 20:24:19 +02:00
|
|
|
m_launcherErrorNotification.setImage(makeImage(icons.error));
|
|
|
|
m_syncthingNotification.setImage(m_launcherErrorNotification.image());
|
2019-05-26 23:13:43 +02:00
|
|
|
m_syncthingNotification.setImage(makeImage(icons.notify));
|
|
|
|
m_syncCompleteNotification.setImage(makeImage(icons.syncComplete));
|
|
|
|
m_newDevNotification.setImage(makeImage(icons.newItem));
|
|
|
|
m_newDirNotification.setImage(m_newDevNotification.image());
|
2017-04-25 00:50:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DBusStatusNotifier::handleSyncthingNotificationAction(const QString &action)
|
|
|
|
{
|
2017-05-01 03:34:43 +02:00
|
|
|
if (action == QLatin1String("dismiss")) {
|
2017-04-25 00:50:30 +02:00
|
|
|
emit dismissNotificationsRequested();
|
2017-05-01 03:34:43 +02:00
|
|
|
} else if (action == QLatin1String("show")) {
|
2017-04-25 00:50:30 +02:00
|
|
|
emit showNotificationsRequested();
|
|
|
|
}
|
|
|
|
}
|
2019-07-12 20:24:19 +02:00
|
|
|
|
2017-09-17 21:48:15 +02:00
|
|
|
} // namespace QtGui
|
2017-04-25 00:50:30 +02:00
|
|
|
|
|
|
|
#endif
|