Browse Source

switched to libnotify on linux

tags/v5.0.0^2
Niklas 3 years ago
parent
commit
d64e710c54
  1. 3
      .circleci/config.yml
  2. 1
      README.md
  3. 7
      docs/index.md
  4. 2
      src/main.cpp
  5. 38
      src/notifications.cpp
  6. 1
      src/notifications.hpp
  7. 3
      src/src.pro

3
.circleci/config.yml

@ -32,6 +32,9 @@ jobs:
libxcb-util-dev \
libxcb-cursor-dev \
libxcb1-dev \
libglib2.0-dev \
libgtk2.0-dev \
libnotify-dev \
- run:
name: QMake Version
command: qmake --version

1
README.md

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

7
docs/index.md

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

2
src/main.cpp

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

38
src/notifications.cpp

@ -4,6 +4,21 @@
#include "ui_mainwindow.h"
#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) {
if (!MainWindow::inst() || !MainWindow::inst()->valid()) return;
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) {
#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;
MainWindow::inst()->tray->showMessage(title, body, icon, 5000);
#endif
MainWindow::inst()->statusBar()->showMessage(title + ": " + body);
}

1
src/notifications.hpp

@ -5,6 +5,7 @@
#include <QSystemTrayIcon>
namespace notifications {
void init();
void notify(QString title, QString body, QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information);
void notifyNolog(QString title, QString body, QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information);
} // namespace notifications

3
src/src.pro

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

Loading…
Cancel
Save