make KF5Notifications optional

This commit is contained in:
Malte Jürgens 2022-07-29 16:31:04 +02:00
parent ef221d4574
commit d68797cebb
No known key found for this signature in database
GPG key ID: D29FBD5F93C0CFC3
2 changed files with 16 additions and 3 deletions

View file

@ -18,7 +18,11 @@ find_package(Qt5 CONFIG REQUIRED COMPONENTS
WebEngineWidgets
)
find_package(KF5Notifications)
option(KF5NOTIFICATIONS "Use KF5Notifications for enhanced system notifications" ON)
if(KF5NOTIFICATIONS)
add_definitions( -DKF5NOTIFICATIONS )
find_package(KF5Notifications)
endif()
set(discord-screenaudio_SRC
src/main.cpp
@ -52,11 +56,15 @@ add_subdirectory(submodules/rohrkabel)
add_executable(discord-screenaudio ${discord-screenaudio_SRC})
target_link_libraries(discord-screenaudio Qt5::Widgets Qt5::WebEngineWidgets KF5::Notifications rohrkabel)
target_link_libraries(discord-screenaudio Qt5::Widgets Qt5::WebEngineWidgets rohrkabel)
if(KF5NOTIFICATIONS)
target_link_libraries(discord-screenaudio KF5::Notifications)
install(FILES assets/discord-screenaudio.notifyrc DESTINATION ${CMAKE_INSTALL_PREFIX}/share/knotifications5)
endif()
install(TARGETS discord-screenaudio DESTINATION bin)
install(FILES assets/de.shorsh.discord-screenaudio.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/256x256/apps)
install(PROGRAMS assets/de.shorsh.discord-screenaudio.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
configure_file(assets/de.shorsh.discord-screenaudio.metainfo.xml.in de.shorsh.discord-screenaudio.metainfo.xml)
install(FILES ${CMAKE_BINARY_DIR}/de.shorsh.discord-screenaudio.metainfo.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/share/metainfo)
install(FILES assets/discord-screenaudio.notifyrc DESTINATION ${CMAKE_INSTALL_PREFIX}/share/knotifications5)

View file

@ -1,7 +1,10 @@
#include "mainwindow.h"
#include "virtmic.h"
#ifdef KF5NOTIFICATIONS
#include <KNotification>
#endif
#include <QApplication>
#include <QColor>
#include <QComboBox>
@ -33,6 +36,7 @@ void MainWindow::setupWebView() {
m_webView = new QWebEngineView(this);
m_webView->setPage(page);
#ifdef KF5NOTIFICATIONS
QWebEngineProfile::defaultProfile()->setNotificationPresenter(
[&](std::unique_ptr<QWebEngineNotification> notificationInfo) {
KNotification *notification = new KNotification("discordNotification");
@ -47,6 +51,7 @@ void MainWindow::setupWebView() {
});
notification->sendEvent();
});
#endif
setCentralWidget(m_webView);
}