From bd4b5b0def35ae3a3a0e20f8ed6ef42d95f9d47d Mon Sep 17 00:00:00 2001 From: lupoDharkael Date: Fri, 28 Jul 2017 18:53:17 +0200 Subject: [PATCH] Add base system notifications class --- flameshot.pro | 6 ++++-- src/capture/capturewidget.cpp | 8 +++++--- src/utils/systemnotification.cpp | 30 ++++++++++++++++++++++++++++++ src/utils/systemnotification.h | 26 ++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 src/utils/systemnotification.cpp create mode 100644 src/utils/systemnotification.h diff --git a/flameshot.pro b/flameshot.pro index 7287772a..abd13fe7 100644 --- a/flameshot.pro +++ b/flameshot.pro @@ -70,7 +70,8 @@ SOURCES += src/main.cpp\ src/capture/tools/sizeindicatortool.cpp \ src/capture/tools/toolfactory.cpp \ src/utils/confighandler.cpp \ - src/core/controller.cpp + src/core/controller.cpp \ + src/utils/systemnotification.cpp HEADERS += \ src/capture/buttonhandler.h \ @@ -107,7 +108,8 @@ HEADERS += \ src/capture/tools/sizeindicatortool.h \ src/capture/tools/toolfactory.h \ src/utils/confighandler.h \ - src/core/controller.h + src/core/controller.h \ + src/utils/systemnotification.h RESOURCES += \ graphics.qrc diff --git a/src/capture/capturewidget.cpp b/src/capture/capturewidget.cpp index 7524724a..c1660279 100644 --- a/src/capture/capturewidget.cpp +++ b/src/capture/capturewidget.cpp @@ -28,6 +28,7 @@ #include "src/capture/colorpicker.h" #include "src/capture/screengrabber.h" #include "src/utils/confighandler.h" +#include "src/utils/systemnotification.h" #include #include #include @@ -364,6 +365,7 @@ void CaptureWidget::keyPressEvent(QKeyEvent *e) { QString CaptureWidget::saveScreenshot(bool toClipboard) { QString savePath, saveMessage; bool ok = false; + SystemNotification notify; if(m_forcedSavePath.isEmpty()) { if(isVisible()) { hide(); @@ -375,7 +377,7 @@ QString CaptureWidget::saveScreenshot(bool toClipboard) { savePath = m_screenshot->fileSave(ok, getExtendedSelection()); if(!ok || config.getSavePath() != m_forcedSavePath) { saveMessage = tr("Error trying to save in ") + savePath; - // TODO send saveMessage + notify.sendMessage(saveMessage); } } if (toClipboard) { @@ -383,7 +385,7 @@ QString CaptureWidget::saveScreenshot(bool toClipboard) { } if(ok) { saveMessage = tr("Capture saved in ") + savePath; - // TODO send saveMessage + notify.sendMessage(saveMessage); } close(); return savePath; @@ -437,7 +439,7 @@ void CaptureWidget::uploadScreenshot() { m_screenshot->uploadToImgur(am, getExtendedSelection()); } hide(); - // TODO send tr("Uploading image...") + SystemNotification().sendMessage(tr("Uploading image...")); } bool CaptureWidget::undo() { diff --git a/src/utils/systemnotification.cpp b/src/utils/systemnotification.cpp new file mode 100644 index 00000000..2b18140f --- /dev/null +++ b/src/utils/systemnotification.cpp @@ -0,0 +1,30 @@ +#include "systemnotification.h" +#include +#include +#include +#include + +SystemNotification::SystemNotification(QObject *parent) : QObject(parent) { + m_interface = new QDBusInterface("org.freedesktop.Notifications", + "/org/freedesktop/Notifications", + "org.freedesktop.Notifications", + QDBusConnection::sessionBus(), + this); +} + +void SystemNotification::sendMessage( + const QString &text, + const QString &title, + const int timeout) +{ + QList args; + args << (qAppName()) //appname + << static_cast(0) //id + << "flameshot.png" //icon + << title //summary + << text //body + << QStringList() //actions + << QVariantMap() //hints + << timeout; //timeout + m_interface->callWithArgumentList(QDBus::AutoDetect, "Notify", args); +} diff --git a/src/utils/systemnotification.h b/src/utils/systemnotification.h new file mode 100644 index 00000000..54320c6f --- /dev/null +++ b/src/utils/systemnotification.h @@ -0,0 +1,26 @@ +#ifndef SYSTEMNOTIFICATION_H +#define SYSTEMNOTIFICATION_H + +#include + +class QDBusInterface; + +class SystemNotification : public QObject +{ + Q_OBJECT +public: + explicit SystemNotification(QObject *parent = nullptr); + + void sendMessage(const QString &text, + const QString &title = "Flameshot Info", + const int timeout = 5000); + +signals: + +public slots: + +private: + QDBusInterface *m_interface; +}; + +#endif // SYSTEMNOTIFICATION_H