switched from libnotify to dbus
This commit is contained in:
parent
ef35e2c0da
commit
b36ecb7e88
@ -32,9 +32,6 @@ jobs:
|
|||||||
libxcb-util-dev \
|
libxcb-util-dev \
|
||||||
libxcb-cursor-dev \
|
libxcb-cursor-dev \
|
||||||
libxcb1-dev \
|
libxcb1-dev \
|
||||||
libglib2.0-dev \
|
|
||||||
libgtk2.0-dev \
|
|
||||||
libnotify-dev \
|
|
||||||
- run:
|
- run:
|
||||||
name: QMake Version
|
name: QMake Version
|
||||||
command: qmake --version
|
command: qmake --version
|
||||||
@ -67,4 +64,4 @@ jobs:
|
|||||||
./makedeb.sh ci;
|
./makedeb.sh ci;
|
||||||
cp *.deb /kshare/
|
cp *.deb /kshare/
|
||||||
- store_artifacts:
|
- store_artifacts:
|
||||||
path: /kshare/
|
path: /kshare/
|
||||||
|
@ -7,5 +7,6 @@ DISTFILES += \
|
|||||||
OlderSystemFix.patch \
|
OlderSystemFix.patch \
|
||||||
AppVeyor/appveyor.yml \
|
AppVeyor/appveyor.yml \
|
||||||
AppVeyor/make_installer.sh \
|
AppVeyor/make_installer.sh \
|
||||||
|
.circleci/config.yml \
|
||||||
.travis.yml \
|
.travis.yml \
|
||||||
install.sh
|
install.sh
|
||||||
|
@ -109,8 +109,6 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
notifications::init();
|
|
||||||
|
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.addHelpOption();
|
parser.addHelpOption();
|
||||||
|
|
||||||
|
@ -1,25 +1,10 @@
|
|||||||
#include "notifications.hpp"
|
#include "notifications.hpp"
|
||||||
|
|
||||||
|
#include "systemnotification.h"
|
||||||
#include "mainwindow.hpp"
|
#include "mainwindow.hpp"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
#include <QStatusBar>
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
#ifdef Q_OS_LINUX
|
|
||||||
#undef signals
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#include <libnotify/notify.h>
|
|
||||||
}
|
|
||||||
#define signals public
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void notifications::init() {
|
|
||||||
#ifdef Q_OS_LINUX
|
|
||||||
notify_init("KShare");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void notifications::notify(QString title, QString body, QSystemTrayIcon::MessageIcon icon) {
|
void notifications::notify(QString title, QString body, QSystemTrayIcon::MessageIcon icon) {
|
||||||
if (!MainWindow::inst() || !MainWindow::inst()->valid()) return;
|
if (!MainWindow::inst() || !MainWindow::inst()->valid()) return;
|
||||||
notifyNolog(title, body, icon);
|
notifyNolog(title, body, icon);
|
||||||
@ -32,30 +17,7 @@ void notifications::notifyNolog(QString title, QString body, QSystemTrayIcon::Me
|
|||||||
QApplication::alert(MainWindow::inst());
|
QApplication::alert(MainWindow::inst());
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef Q_OS_LINUX
|
SystemNotification().sendMessage(body, title, icon);
|
||||||
NotifyNotification *n = notify_notification_new(title.toLocal8Bit(), body.toLocal8Bit(), 0);
|
|
||||||
notify_notification_set_timeout(n, 5000);
|
|
||||||
|
|
||||||
NotifyUrgency urgency;
|
|
||||||
switch(icon) {
|
|
||||||
case QSystemTrayIcon::Warning:
|
|
||||||
urgency = NotifyUrgency::NOTIFY_URGENCY_NORMAL;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case QSystemTrayIcon::Critical:
|
|
||||||
urgency = NotifyUrgency::NOTIFY_URGENCY_CRITICAL;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
urgency = NotifyUrgency::NOTIFY_URGENCY_LOW;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
notify_notification_set_urgency(n, urgency);
|
|
||||||
notify_notification_show(n, 0);
|
|
||||||
#else
|
|
||||||
if (!MainWindow::inst()) return;
|
|
||||||
MainWindow::inst()->tray->showMessage(title, body, icon, 5000);
|
|
||||||
#endif
|
|
||||||
MainWindow::inst()->statusBar()->showMessage(title + ": " + body);
|
MainWindow::inst()->statusBar()->showMessage(title + ": " + body);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
|
|
||||||
namespace notifications {
|
namespace notifications {
|
||||||
void init();
|
|
||||||
void notify(QString title, QString body, QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information);
|
void notify(QString title, QString body, QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information);
|
||||||
void notifyNolog(QString title, QString body, QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information);
|
void notifyNolog(QString title, QString body, QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information);
|
||||||
} // namespace notifications
|
} // namespace notifications
|
||||||
|
12
src/src.pro
12
src/src.pro
@ -73,7 +73,8 @@ SOURCES += main.cpp\
|
|||||||
screenoverlay/screenoverlay.cpp \
|
screenoverlay/screenoverlay.cpp \
|
||||||
screenoverlay/screenoverlaysettings.cpp \
|
screenoverlay/screenoverlaysettings.cpp \
|
||||||
logger.cpp \
|
logger.cpp \
|
||||||
clipboard/clipboardcopy.cpp
|
clipboard/clipboardcopy.cpp \
|
||||||
|
systemnotification.cpp
|
||||||
|
|
||||||
HEADERS += mainwindow.hpp \
|
HEADERS += mainwindow.hpp \
|
||||||
cropeditor/cropeditor.hpp \
|
cropeditor/cropeditor.hpp \
|
||||||
@ -125,7 +126,8 @@ HEADERS += mainwindow.hpp \
|
|||||||
screenoverlay/screenoverlay.hpp \
|
screenoverlay/screenoverlay.hpp \
|
||||||
screenoverlay/screenoverlaysettings.hpp \
|
screenoverlay/screenoverlaysettings.hpp \
|
||||||
logger.hpp \
|
logger.hpp \
|
||||||
clipboard/clipboardcopy.hpp
|
clipboard/clipboardcopy.hpp \
|
||||||
|
systemnotification.h
|
||||||
|
|
||||||
nopkg {
|
nopkg {
|
||||||
# win32 {
|
# win32 {
|
||||||
@ -146,9 +148,6 @@ nopkg {
|
|||||||
} else {
|
} else {
|
||||||
CONFIG += link_pkgconfig
|
CONFIG += link_pkgconfig
|
||||||
PKGCONFIG += libavformat libavcodec libswscale libavutil
|
PKGCONFIG += libavformat libavcodec libswscale libavutil
|
||||||
unix {
|
|
||||||
PKGCONFIG += libnotify
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mac {
|
mac {
|
||||||
@ -157,6 +156,7 @@ mac {
|
|||||||
HEADERS += $$PWD/platformspecifics/mac/macbackend.hpp
|
HEADERS += $$PWD/platformspecifics/mac/macbackend.hpp
|
||||||
LIBS += -framework Carbon
|
LIBS += -framework Carbon
|
||||||
QMAKE_INFO_PLIST = $$PWD/../packages/macos/Info.plist
|
QMAKE_INFO_PLIST = $$PWD/../packages/macos/Info.plist
|
||||||
|
QT += dbus
|
||||||
warning(Mac is on TODO);
|
warning(Mac is on TODO);
|
||||||
} else:win32 {
|
} else:win32 {
|
||||||
RC_FILE = $$PWD/icon.rc
|
RC_FILE = $$PWD/icon.rc
|
||||||
@ -168,7 +168,7 @@ mac {
|
|||||||
RC_FILE = $$PWD/icon.rc
|
RC_FILE = $$PWD/icon.rc
|
||||||
SOURCES += $$PWD/platformspecifics/x11/x11backend.cpp
|
SOURCES += $$PWD/platformspecifics/x11/x11backend.cpp
|
||||||
HEADERS += $$PWD/platformspecifics/x11/x11backend.hpp
|
HEADERS += $$PWD/platformspecifics/x11/x11backend.hpp
|
||||||
QT += x11extras
|
QT += x11extras dbus
|
||||||
LIBS += -lxcb-cursor -lxcb-xfixes -lxcb
|
LIBS += -lxcb-cursor -lxcb-xfixes -lxcb
|
||||||
|
|
||||||
target.path = bin/
|
target.path = bin/
|
||||||
|
75
src/systemnotification.cpp
Normal file
75
src/systemnotification.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#include "systemnotification.h"
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
#ifndef Q_OS_WIN
|
||||||
|
#include <QDBusConnection>
|
||||||
|
#include <QDBusMessage>
|
||||||
|
#include <QDBusInterface>
|
||||||
|
#else
|
||||||
|
#include "mainwindow.hpp"
|
||||||
|
#include "ui_mainwindow.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
|
||||||
|
SystemNotification::SystemNotification(QObject *parent) : QObject(parent) {
|
||||||
|
m_interface = new QDBusInterface(QStringLiteral("org.freedesktop.Notifications"),
|
||||||
|
QStringLiteral("/org/freedesktop/Notifications"),
|
||||||
|
QStringLiteral("org.freedesktop.Notifications"),
|
||||||
|
QDBusConnection::sessionBus(),
|
||||||
|
this);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
SystemNotification::SystemNotification(QObject *parent) : QObject(parent) {
|
||||||
|
m_interface = nullptr;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void SystemNotification::sendMessage(const QString &text, const QString &savePath) {
|
||||||
|
sendMessage(text, tr("KShare Info"), QSystemTrayIcon::Information, savePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SystemNotification::sendMessage(
|
||||||
|
const QString &text,
|
||||||
|
const QString &title,
|
||||||
|
const QSystemTrayIcon::MessageIcon icon,
|
||||||
|
const QString &savePath,
|
||||||
|
const int timeout)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifndef Q_OS_WIN
|
||||||
|
QList<QVariant> args;
|
||||||
|
QVariantMap hintsMap;
|
||||||
|
if (!savePath.isEmpty()) {
|
||||||
|
QUrl fullPath = QUrl::fromLocalFile(savePath);
|
||||||
|
// allows the notification to be dragged and dropped
|
||||||
|
hintsMap[QStringLiteral("x-kde-urls")] = QStringList({fullPath.toString()});
|
||||||
|
}
|
||||||
|
|
||||||
|
QString iconString = "";
|
||||||
|
switch (icon) {
|
||||||
|
case QSystemTrayIcon::Warning:
|
||||||
|
iconString = "dialog-warning";
|
||||||
|
break;
|
||||||
|
case QSystemTrayIcon::Critical:
|
||||||
|
iconString = "dialog-error";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
iconString = "dialog-information";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
args << (qAppName()) //appname
|
||||||
|
<< static_cast<unsigned int>(0) //id
|
||||||
|
<< iconString //icon
|
||||||
|
<< title //summary
|
||||||
|
<< text //body
|
||||||
|
<< QStringList() //actions
|
||||||
|
<< hintsMap //hints
|
||||||
|
<< timeout; //timeout
|
||||||
|
m_interface->callWithArgumentList(QDBus::AutoDetect, QStringLiteral("Notify"), args);
|
||||||
|
#else
|
||||||
|
if (!MainWindow::inst()) return;
|
||||||
|
MainWindow::inst()->tray->showMessage(text, title, icon, timeout);
|
||||||
|
#endif
|
||||||
|
}
|
41
src/systemnotification.h
Normal file
41
src/systemnotification.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// Copyright(c) 2017-2019 Alejandro Sirgo Rica & Contributors
|
||||||
|
//
|
||||||
|
// This file is part of Flameshot.
|
||||||
|
//
|
||||||
|
// Flameshot is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Flameshot is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QSystemTrayIcon>
|
||||||
|
|
||||||
|
class QDBusInterface;
|
||||||
|
|
||||||
|
class SystemNotification : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit SystemNotification(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
void sendMessage(const QString &text,
|
||||||
|
const QString &savePath = {});
|
||||||
|
|
||||||
|
void sendMessage(const QString &text,
|
||||||
|
const QString &title,
|
||||||
|
const QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information,
|
||||||
|
const QString &savePath = {},
|
||||||
|
const int timeout = 5000);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QDBusInterface *m_interface;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user