From 0eeaf66e66e660b550ec9409e774972109716233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20J=C3=BCrgens?= Date: Fri, 9 Feb 2024 14:23:09 +0100 Subject: [PATCH] Add Support for KF6 --- .gitignore | 1 + CMakeLists.txt | 48 ++++++++++++++++++++++++++++--------------- src/centralwidget.cpp | 11 ++++++++++ src/discordpage.cpp | 3 ++- src/main.cpp | 4 ---- src/userscript.cpp | 1 + src/userscript.h | 1 - 7 files changed, 46 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 66247b3..437825f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ .vscode /submodules/arrpc /submodules/Vencord +.cache diff --git a/CMakeLists.txt b/CMakeLists.txt index beebe20..35cb6f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,13 +14,14 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG") +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) string(TIMESTAMP TIMESTAMP %s) # set(CMAKE_AUTOUIC ON) -option(PREFER_QT6 "Prefer Qt6 over Qt5" OFF) +option(PREFER_QT5 "Prefer Qt5 over Qt5" OFF) option(SKIP_KDE "Do not include features requiring KDE Frameworks (notifications, global shortcuts)" OFF) -if(NOT PREFER_QT6) +if(NOT PREFER_QT5) find_package(Qt5 COMPONENTS Widgets QUIET) endif() if (Qt5_FOUND) @@ -50,29 +51,31 @@ if (Qt5_FOUND) endif() endif() else() - find_package(Qt6 CONFIG REQUIRED COMPONENTS Widgets WebEngineWidgets) - message(STATUS "Using Qt6") + find_package(Qt5 CONFIG REQUIRED COMPONENTS Widgets WebEngineWidgets) + message(STATUS "Using Qt5") + add_definitions( -DQT5 ) if(NOT SKIP_KDE) - find_package(KF6Notifications QUIET) - if(KF6Notifications_FOUND) + find_package(KF5Notifications QUIET) + if(KF5Notifications_FOUND) add_definitions( -DKNOTIFICATIONS ) else() - message(WARNING "KF6Notifications not found, notifications will not work") + message(WARNING "KF5Notifications not found, notifications will not work") endif() - find_package(KF6XmlGui QUIET) - if(KF6XmlGui_FOUND) + find_package(KF5XmlGui QUIET) + find_package(KF5CoreAddons QUIET) + if(KF5XmlGui_FOUND AND KF5CoreAddons_FOUND) add_definitions( -DKXMLGUI ) else() - message(WARNING "KF6XmlGui not found, some UI elements and global shortcuts will not work") + message(WARNING "KF5XmlGui not found, some UI elements and global shortcuts will not work") endif() - find_package(KF6GlobalAccel QUIET) - if(KF6GlobalAccel_FOUND) + find_package(KF5GlobalAccel QUIET) + if(KF5GlobalAccel_FOUND) add_definitions( -DKGLOBALACCEL ) else() - message(WARNING "KF6GlobalAccel not found, global shortcuts will not work") + message(WARNING "KF5GlobalAccel not found, global shortcuts will not work") endif() endif() endif() @@ -115,19 +118,30 @@ add_executable(discord-screenaudio ${discord-screenaudio_SRC}) target_link_libraries(discord-screenaudio Qt::Widgets Qt::WebEngineWidgets rohrkabel) -if(KF5Notifications_FOUND OR KF6Notifications_FOUND) +if(KF5Notifications_FOUND) target_link_libraries(discord-screenaudio KF5::Notifications) install(FILES assets/discord-screenaudio.notifyrc DESTINATION ${CMAKE_INSTALL_PREFIX}/share/knotifications5) endif() -if(KF5XmlGui_FOUND OR KF6XmlGui_FOUND) +if(KF5XmlGui_FOUND) target_link_libraries(discord-screenaudio KF5::XmlGui) endif() -if(KF5GlobalAccel_FOUND OR KF6GlobalAccel_FOUND) +if(KF5GlobalAccel_FOUND) + target_link_libraries(discord-screenaudio KF5::GlobalAccel) +endif() + +if(KF5Notifications_FOUND) + target_link_libraries(discord-screenaudio KF5::Notifications) + install(FILES assets/discord-screenaudio.notifyrc DESTINATION ${CMAKE_INSTALL_PREFIX}/share/knotifications5) +endif() +if(KF5XmlGui_FOUND) + target_link_libraries(discord-screenaudio KF5::XmlGui KF5::CoreAddons) +endif() +if(KF5GlobalAccel_FOUND) target_link_libraries(discord-screenaudio KF5::GlobalAccel) 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(FILES assets/de.shorsh.discord-screenaudio.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/255x255/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) diff --git a/src/centralwidget.cpp b/src/centralwidget.cpp index 4461194..9d187c8 100644 --- a/src/centralwidget.cpp +++ b/src/centralwidget.cpp @@ -50,6 +50,16 @@ void CentralWidget::setupWebView() { notification->setText(notificationInfo->message()); notification->setPixmap( QPixmap::fromImage(notificationInfo->icon())); +#ifdef QT6 + auto action = notification->addDefaultAction("View"); + connect(action, &KNotificationAction::activated, + [&, notificationInfo = std::move(notificationInfo)]() { + notificationInfo->click(); + show(); + activateWindow(); + }); + notification->sendEvent(); +#else notification->setDefaultAction("View"); connect(notification, &KNotification::defaultActivated, [&, notificationInfo = std::move(notificationInfo)]() { @@ -58,6 +68,7 @@ void CentralWidget::setupWebView() { activateWindow(); }); notification->sendEvent(); +#endif #endif } }); diff --git a/src/discordpage.cpp b/src/discordpage.cpp index 2216514..bb9d444 100644 --- a/src/discordpage.cpp +++ b/src/discordpage.cpp @@ -20,7 +20,8 @@ #include #include -DiscordPage::DiscordPage(QWidget *parent) : QWebEnginePage(parent) { +DiscordPage::DiscordPage(QWidget *parent) + : QWebEnginePage(new QWebEngineProfile("discord-screenaudio"), parent) { setBackgroundColor(QColor("#313338")); connect(this, &QWebEnginePage::featurePermissionRequested, this, diff --git a/src/main.cpp b/src/main.cpp index 8b7f37a..ca48c0d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,10 +6,6 @@ #include "mainwindow.h" #include "virtmic.h" -#ifdef KXMLGUI -#include -#endif - #include #include #include diff --git a/src/userscript.cpp b/src/userscript.cpp index 2bf864e..e5e1995 100644 --- a/src/userscript.cpp +++ b/src/userscript.cpp @@ -17,6 +17,7 @@ #include #ifdef KXMLGUI +#include #include #endif diff --git a/src/userscript.h b/src/userscript.h index 45ede4f..036dc9f 100644 --- a/src/userscript.h +++ b/src/userscript.h @@ -10,7 +10,6 @@ #include #ifdef KXMLGUI -#include #include #include #include