Add base system notifications class
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 <QScreen>
|
||||
#include <QGuiApplication>
|
||||
#include <QApplication>
|
||||
@@ -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() {
|
||||
|
||||
30
src/utils/systemnotification.cpp
Normal file
30
src/utils/systemnotification.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "systemnotification.h"
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusInterface>
|
||||
#include <QApplication>
|
||||
|
||||
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<QVariant> args;
|
||||
args << (qAppName()) //appname
|
||||
<< static_cast<unsigned int>(0) //id
|
||||
<< "flameshot.png" //icon
|
||||
<< title //summary
|
||||
<< text //body
|
||||
<< QStringList() //actions
|
||||
<< QVariantMap() //hints
|
||||
<< timeout; //timeout
|
||||
m_interface->callWithArgumentList(QDBus::AutoDetect, "Notify", args);
|
||||
}
|
||||
26
src/utils/systemnotification.h
Normal file
26
src/utils/systemnotification.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef SYSTEMNOTIFICATION_H
|
||||
#define SYSTEMNOTIFICATION_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user