Commit 7dfe11a6 authored by LNJ's avatar LNJ 💬

Use KNotifications to massively improve notifications

This replaces the old libnotify-binary based notifications (executing
shell commands) by cross-platform working notifications provided by
KNotifications.

Currently the dependencies (knotifications and its dependencies) are not
built on the CI for the most platforms (android, macOS, windows, ut),
however knotifications would also work on these platforms.
parent df891fd8
......@@ -82,7 +82,7 @@ android:
- sudo apt -y install inkscape optipng
- GIT_EXTRA="--branch ${KF5_VERSION}" /opt/helpers/build-kde-dependencies --withProject kirigami
- /opt/helpers/build-cmake qxmpp https://github.com/qxmpp-project/qxmpp.git -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF
- GIT_EXTRA="--branch ${CI_COMMIT_REF_NAME} --recursive" /opt/helpers/build-cmake ${CI_PROJECT_NAME} ${CI_REPOSITORY_URL} -DQTANDROID_EXPORTED_TARGET=kaidan -DANDROID_APK_DIR=${CI_PROJECT_DIR}/src/${CI_PROJECT_NAME}/misc/android -DI18N=1
- GIT_EXTRA="--branch ${CI_COMMIT_REF_NAME} --recursive" /opt/helpers/build-cmake ${CI_PROJECT_NAME} ${CI_REPOSITORY_URL} -DQTANDROID_EXPORTED_TARGET=kaidan -DANDROID_APK_DIR=${CI_PROJECT_DIR}/src/${CI_PROJECT_NAME}/misc/android -DI18N=1 -DUSE_KNOTIFICATIONS=OFF
- ${CI_PROJECT_DIR}/src/${CI_PROJECT_NAME}/utils/render-logos.sh
- /opt/helpers/create-apk ${CI_PROJECT_NAME}
- mv ${CI_PROJECT_DIR}/build/${CI_PROJECT_NAME}/kaidan_build_apk/build/outputs/apk/kaidan_build_apk-debug.apk ${CI_PROJECT_DIR}
......
......@@ -26,6 +26,7 @@ option(UBUNTU_TOUCH "Building an Ubuntu Touch click (internal use only!)" FALSE)
option(CLICK_ARCH "Architecture that will be used in the click's manifest")
option(CLICK_DATE "Date used in the version number in the click's manifest")
option(QUICK_COMPILER "Use QtQuick compiler to improve performance" FALSE)
option(USE_KNOTIFICATIONS "Use KNotifications for displaying notifications" TRUE)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
......@@ -66,6 +67,12 @@ if(QUICK_COMPILER)
)
endif()
if(USE_KNOTIFICATIONS)
find_package(KF5Notifications REQUIRED)
set(__KF5Notifications_LIBRARIES KF5::Notifications)
add_definitions(-DHAVE_KNOTIFICATIONS)
endif()
# Optional QWidget style integration (not on mobile)
if(NOT UBUNTU_TOUCH AND NOT ANDROID AND NOT IOS)
find_package(Qt5Widgets)
......@@ -160,6 +167,7 @@ target_link_libraries(${PROJECT_NAME}
Qt5::Network
Qt5::Xml
${__Qt5Widgets_LIBRARIES}
${__KF5Notifications_LIBRARIES}
# currently needs to be hardcoded for windows builds
qxmpp
)
......@@ -396,5 +404,9 @@ elseif(UNIX AND NOT APPLE)
)
endif()
# KNotifications
if(USE_KNOTIFICATIONS)
install(FILES misc/kaidan.notifyrc DESTINATION ${KNOTIFYRC_INSTALL_DIR})
endif()
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
......@@ -43,6 +43,7 @@ Here are the general dependencies of Kaidan listed:
* [QXmpp][qxmpp] (>= 0.9.0)
* [Kirigami 2](https://phabricator.kde.org/source/kirigami/) (>= 5.42.0)
* [ECM (extra-cmake-modules)](https://api.kde.org/ecm/manual/ecm.7.html)
* [KNotifications][knotif] (`-DUSE_KNOTIFICATIONS=OFF` to disable)
### Build instructions
......@@ -58,3 +59,4 @@ There are guides on how to build Kaidan for each supported platform (currently t
[openstore]: https://open-store.io/app/im.kaidan.kaidan
[android]: https://www.kaidan.im/download/#android
[supp-xeps]: https://invent.kde.org/kde/kaidan/wikis/Supported-XEPs
[knotif]: https://api.kde.org/frameworks/knotifications/html/index.html
[Global]
IconName=kaidan
Comment=A user-friendly XMPP client for every device
Name=Kaidan
[Event/new-message]
Name=New message
Comment=You have received a new message
Action=Sound|Popup
......@@ -175,8 +175,7 @@ void MessageHandler::handleMessage(const QXmppMessage &msg)
contactName = contactJid;
if (!message.sentByMe())
Notifications::sendMessageNotification(contactName.toStdString(),
msg.body().toStdString());
Notifications::sendMessageNotification(contactName, msg.body());
// TODO: Move back following call to RosterManager::handleMessage when spoiler
// messages are implemented in QXmpp
......
......@@ -30,11 +30,20 @@
// Kaidan
#include "Notifications.h"
// KNotifications
#ifdef HAVE_KNOTIFICATIONS
#include <KNotification>
#endif
void Notifications::sendMessageNotification(std::string fromName, std::string message)
#ifdef HAVE_KNOTIFICATIONS
void Notifications::sendMessageNotification(const QString& fromName, const QString& message)
{
#ifdef NOTIFICATIONS_LIBNOTIFY
std::string command = "notify-send \"" + fromName + ": " + message + "\" -a kaidan -i kaidan -t 7000";
system(command.c_str());
#endif
KNotification *notif = new KNotification("new-message");
notif->setText(QString("<b>%1</b>: %2").arg(fromName, message));
notif->sendEvent();
}
#else
void Notifications::sendMessageNotification(const QString&, const QString&)
{
}
#endif
......@@ -28,9 +28,10 @@
* along with Kaidan. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string>
#include <QString>
namespace Notifications
class Notifications
{
void sendMessageNotification(std::string fromName, std::string message);
}
public:
static void sendMessageNotification(const QString &fromName, const QString &message);
};
......@@ -27,6 +27,7 @@ build_kaidan() {
-DCLICK_ARCH="${ARCH}" \
-DCLICK_DATE="${DATE}" \
-DQUICK_COMPILER=OFF \
-DUSE_KNOTIFICATIONS=OFF \
-DCMAKE_BUILD_TYPE=Release
ninja install
......
......@@ -119,7 +119,9 @@ echo "*****************************************"
${OSXCROSS_TARGET}-cmake .. \
-DECM_DIR=/usr/local/share/ECM/cmake \
-DCMAKE_PREFIX_PATH=$QT_MACOS\;$KIRIGAMI_BUILD\;$QXMPP_BUILD \
-DKF5Kirigami2_DIR=$KIRIGAMI_BUILD/lib/cmake/KF5Kirigami2 -DI18N=1 \
-DKF5Kirigami2_DIR=$KIRIGAMI_BUILD/lib/cmake/KF5Kirigami2 \
-DI18N=1 \
-DUSE_KNOTIFICATIONS=OFF \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DQUICK_COMPILER=OFF
......
......@@ -136,7 +136,8 @@ echo "*****************************************"
-DECM_DIR=/usr/share/ECM/cmake -DI18N=1 \
-DSTATIC_BUILD=1 \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DQUICK_COMPILER=1
-DQUICK_COMPILER=1 \
-DUSE_KNOTIFICATIONS=OFF
make -j$(nproc)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment