switched to libnotify on linux

This commit is contained in:
Niklas 2019-05-13 19:17:09 +02:00
parent e03b199fe9
commit d64e710c54
7 changed files with 53 additions and 2 deletions

View File

@ -32,6 +32,9 @@ 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

View File

@ -31,6 +31,7 @@ Additionally, on Linux, you require:
* XCB * XCB
* XCB xfixes * XCB xfixes
* XCB cursor * XCB cursor
* libnotify
Despite the name implying so, this project does not depend on the KDE API at all. Despite the name implying so, this project does not depend on the KDE API at all.

View File

@ -18,8 +18,11 @@ It has many features, including:
* Automatic upload/clipboard copying, * Automatic upload/clipboard copying,
* Hotkeys, * Hotkeys,
* Color picker, and last but not least, * Color picker, and last but not least,
* Custom upload destinations * Custom upload destinations,
* Upload from clipboard * Upload from clipboard,
* Upload History,
* Crossplatform,
* Windows 10 Darkmode
## Enough talking, show us how it looks ## Enough talking, show us how it looks
The main window is rather simple, with only a log, and a button in it: The main window is rather simple, with only a log, and a button in it:

View File

@ -109,6 +109,8 @@ int main(int argc, char *argv[]) {
} }
#endif #endif
notifications::init();
QCommandLineParser parser; QCommandLineParser parser;
parser.addHelpOption(); parser.addHelpOption();

View File

@ -4,6 +4,21 @@
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include <QStatusBar> #include <QStatusBar>
#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);
@ -11,7 +26,30 @@ void notifications::notify(QString title, QString body, QSystemTrayIcon::Message
} }
void notifications::notifyNolog(QString title, QString body, QSystemTrayIcon::MessageIcon icon) { void notifications::notifyNolog(QString title, QString body, QSystemTrayIcon::MessageIcon icon) {
#ifdef Q_OS_LINUX
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; if (!MainWindow::inst()) return;
MainWindow::inst()->tray->showMessage(title, body, icon, 5000); MainWindow::inst()->tray->showMessage(title, body, icon, 5000);
#endif
MainWindow::inst()->statusBar()->showMessage(title + ": " + body); MainWindow::inst()->statusBar()->showMessage(title + ": " + body);
} }

View File

@ -5,6 +5,7 @@
#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

View File

@ -146,6 +146,9 @@ nopkg {
} else { } else {
CONFIG += link_pkgconfig CONFIG += link_pkgconfig
PKGCONFIG += libavformat libavcodec libswscale libavutil PKGCONFIG += libavformat libavcodec libswscale libavutil
unix {
PKGCONFIG += libnotify
}
} }
mac { mac {