From d5ad7202ea77e8a512073f9ce09b6c07e37d6305 Mon Sep 17 00:00:00 2001 From: Miquel Lionel Date: Sun, 6 Feb 2022 20:42:01 +0100 Subject: Move notifications to own header file - also make a skel for files in /usr/, useful for sounds and notifyrc - build.sh use plain simple cp -r to copy the skel. also copies the knotifications5 in the current directory for qml.qrc embedding in case the app is used on android. --- CMakeLists.txt | 3 ++- README.md | 4 ++++ build.sh | 6 +++++- main.cpp | 9 +++++++++ notifications.cpp | 21 +++++++++++++++++++++ notifications.h | 13 +++++++++++++ qml.qrc | 1 + qml/ChatPage.qml | 2 +- .../applications/chat.delta.KDeltaChat.desktop | 9 +++++++++ .../hicolor/256x256/chat.delta.KDeltaChat.png | Bin 0 -> 18772 bytes usr/share/knotifications5/kdeltachat.notifyrc | 18 ++++++++++++++++++ usr/share/sounds/kdeltachat/incomingmessage.ogg | Bin 0 -> 6938 bytes 12 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 notifications.cpp create mode 100644 notifications.h create mode 100755 usr/share/applications/chat.delta.KDeltaChat.desktop create mode 100755 usr/share/icons/hicolor/256x256/chat.delta.KDeltaChat.png create mode 100755 usr/share/knotifications5/kdeltachat.notifyrc create mode 100644 usr/share/sounds/kdeltachat/incomingmessage.ogg diff --git a/CMakeLists.txt b/CMakeLists.txt index f10a4f8..4817196 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ ecm_find_qmlmodule(org.kde.kirigami 2.12) # # See https://doc.qt.io/qt-5/qtquick-deployment.html#ahead-of-time-compilation find_package(Qt5QuickCompiler REQUIRED) +find_package(KF5Notifications REQUIRED) qtquick_compiler_add_resources(KDELTACHAT_QML_QRC qml.qrc) add_executable( @@ -48,6 +49,7 @@ add_executable( chatlist.cpp contact.cpp chat.cpp + notifications.cpp eventemitter.cpp lot.cpp dcevent.cpp @@ -55,7 +57,6 @@ add_executable( find_package(Threads REQUIRED) find_package(KF5Kirigami2 REQUIRED) -find_package(KF5Notifications REQUIRED) pkg_check_modules(DeltaChat IMPORTED_TARGET deltachat) target_compile_definitions( diff --git a/README.md b/README.md index 506b251..a6c8a78 100755 --- a/README.md +++ b/README.md @@ -160,6 +160,10 @@ to help in this case. This results in usage of Adwaita icon theme. The pinned and muted chat icons are converted to PNG from the [Twemoji](https://twemoji.twitter.com/) font. Licensed under [CC-BY 4.0](https://creativecommons.org/licenses/by/4.0/) - Copyright 2020 Twitter, Inc and other contributors. +The incoming message notification sound, `incomingmessage.ogg`, is a .wav file made by [BeezleFM](https://freesound.org/people/BeezleFM/sounds/512136/) and then converted to .ogg through ffmpeg. Original title is 'Notification Sound'. +Licensed under [CC-BY 3.0](http://creativecommons.org/licenses/by/3.0/). +Copyright 2020 BeezleFM at freesound.org. + # License This program is free software: you can redistribute it and/or modify diff --git a/build.sh b/build.sh index 31845a2..ad735b2 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,9 @@ #!/bin/sh + +# for the qml.qrc +cp -r usr/share/knotifications5 . + cmake -B build . cmake --build build -sudo install -vDm644 usr/* -t / +cp -v -r usr/ / sudo install -vDm755 build/kdeltachat -t /usr/local/bin/ diff --git a/main.cpp b/main.cpp index 57334a4..fb7cded 100644 --- a/main.cpp +++ b/main.cpp @@ -2,6 +2,7 @@ #include #include #include +//#include #include "accounts.h" #include "message.h" @@ -10,6 +11,7 @@ #include "context.h" #include "contact.h" #include "eventemitter.h" +#include "notifications.h" int main(int argc, char *argv[]) { @@ -52,15 +54,22 @@ int main(int argc, char *argv[]) { QCoreApplication::exit(-1); } + if (qmlRegisterType("DcNotifications", 1, 0, "DcNotifications") == -1) + { + QCoreApplication::exit(-1); + } if (qmlRegisterType("DeltaChat", 1, 0, "DcAccountsEventEmitter") == -1) { QCoreApplication::exit(-1); } + + DcNotifications* KNotif = new DcNotifications(); qRegisterMetaType("size_t"); qRegisterMetaType("uint32_t"); qRegisterMetaType>("QVector"); QQmlApplicationEngine engine; + engine.rootContext()->setContextProperty("KNotif", KNotif); const QUrl url(QStringLiteral("qrc:/qml/main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { diff --git a/notifications.cpp b/notifications.cpp new file mode 100644 index 0000000..712e37e --- /dev/null +++ b/notifications.cpp @@ -0,0 +1,21 @@ +#include +#include "notifications.h" + +DcNotifications::DcNotifications(QObject *parent) + : QObject{parent} +{ +} + +void +DcNotifications::send(QString event, QString pfpPath, QString title, QString message) { + + KNotification *newMess = new KNotification(event); + newMess->setPixmap(QPixmap(pfpPath)); + newMess->setIconName("chat.delta.KDeltaChat"); + newMess->setComponentName("kdeltachat"); + newMess->setTitle(title); + newMess->setText(message); + newMess->sendEvent(); + +} +//newMess->setPixmap(QPixmap(":/res/chat.delta.KDeltaChat.png")); diff --git a/notifications.h b/notifications.h new file mode 100644 index 0000000..5d7852b --- /dev/null +++ b/notifications.h @@ -0,0 +1,13 @@ +#pragma once +#include + +class DcNotifications: public QObject { + Q_OBJECT +public: + explicit DcNotifications(QObject *parent = nullptr); + //explicit DcEvent(dc_event_t *event); + + //~DcNotifications(); + + Q_INVOKABLE void send(QString event, QString pfpPath, QString title, QString message); +}; diff --git a/qml.qrc b/qml.qrc index 506ed7b..cff9f53 100644 --- a/qml.qrc +++ b/qml.qrc @@ -15,5 +15,6 @@ knotifications5/kdeltachat.notifyrc res/pin_48x48.png res/muted_48x48.png + res/chat.delta.KDeltaChat.png diff --git a/qml/ChatPage.qml b/qml/ChatPage.qml index 667e01d..a82e0f6 100644 --- a/qml/ChatPage.qml +++ b/qml/ChatPage.qml @@ -57,7 +57,7 @@ Kirigami.ScrollablePage { updateMessagelist(); console.log("Incoming message for chat " + chatId); if(!chat.muted || chatId != 0 || chatId != root.chatId) - chat.notifyNewMess(); + KNotif.send("onIncomingMessage",chat.getProfileImage() ,chat.name ,"has sent you a message.") } function onMessagesChanged(accountId, chatId, msgId) { diff --git a/usr/share/applications/chat.delta.KDeltaChat.desktop b/usr/share/applications/chat.delta.KDeltaChat.desktop new file mode 100755 index 0000000..35c2999 --- /dev/null +++ b/usr/share/applications/chat.delta.KDeltaChat.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Type=Application +Name=KDeltaChat +Comment=Delta Chat client built with Kirigami +Icon=chat.delta.KDeltaChat +TryExec=kdeltachat +Exec=kdeltachat +Categories=Network;Email;InstantMessaging;Chat;KDE;Qt; +StartupWMClass=KDeltaChat diff --git a/usr/share/icons/hicolor/256x256/chat.delta.KDeltaChat.png b/usr/share/icons/hicolor/256x256/chat.delta.KDeltaChat.png new file mode 100755 index 0000000..62f445e Binary files /dev/null and b/usr/share/icons/hicolor/256x256/chat.delta.KDeltaChat.png differ diff --git a/usr/share/knotifications5/kdeltachat.notifyrc b/usr/share/knotifications5/kdeltachat.notifyrc new file mode 100755 index 0000000..901db73 --- /dev/null +++ b/usr/share/knotifications5/kdeltachat.notifyrc @@ -0,0 +1,18 @@ +[Global] +IconName=chat.delta.KDeltaChat +Name=KDeltaChat +Comment=KDeltaChat +DesktopEntry=chat.delta.KDeltaChat + +[Event/onIncomingMessage] +Name=New Message +Comment=You have got a new message +Contexts=none +Sound=kdeltachat/incomingmessage.ogg +Action=Popup|Sound + +[Event/workMode] +Name=Working offline +Comment=Switch to offline mode +Contexts=none +Action=Popup diff --git a/usr/share/sounds/kdeltachat/incomingmessage.ogg b/usr/share/sounds/kdeltachat/incomingmessage.ogg new file mode 100644 index 0000000..e7eb72d Binary files /dev/null and b/usr/share/sounds/kdeltachat/incomingmessage.ogg differ -- cgit v1.2.3-70-g09d2