Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
Add Support for KF6
Browse files Browse the repository at this point in the history
  • Loading branch information
maltejur committed Mar 22, 2024
1 parent 3f3f179 commit 64bacdb
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
.vscode
/submodules/arrpc
/submodules/Vencord
.cache
75 changes: 45 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,65 +14,69 @@ 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 Qt6" OFF)
option(SKIP_KDE "Do not include features requiring KDE Frameworks (notifications, global shortcuts)" OFF)

if(NOT PREFER_QT6)
find_package(Qt5 COMPONENTS Widgets QUIET)
if(NOT PREFER_QT5)
find_package(Qt6 COMPONENTS Widgets QUIET)
endif()
if (Qt5_FOUND)
find_package(Qt5 CONFIG REQUIRED COMPONENTS Widgets WebEngineWidgets)
message(STATUS "Using Qt5")
if (Qt6_FOUND)
find_package(Qt6 CONFIG REQUIRED COMPONENTS Widgets WebEngineWidgets)
message(STATUS "Using Qt6")

if(NOT SKIP_KDE)
find_package(KF5Notifications QUIET)
if(KF5Notifications_FOUND)
find_package(KF6Notifications QUIET)
if(KF6Notifications_FOUND)
add_definitions( -DKNOTIFICATIONS )
else()
message(WARNING "KF5Notifications not found, notifications will not work")
message(WARNING "KF6Notifications not found, notifications will not work")
endif()

find_package(KF5XmlGui QUIET)
if(KF5XmlGui_FOUND)
find_package(KF6XmlGui QUIET)
if(KF6XmlGui_FOUND)
find_package(KF6CoreAddons QUIET REQUIRED)
add_definitions( -DKXMLGUI )
else()
message(WARNING "KF5XmlGui not found, some UI elements and global shortcuts will not work")
message(WARNING "KF6XmlGui not found, some UI elements and global shortcuts will not work")
endif()

find_package(KF5GlobalAccel QUIET)
if(KF5GlobalAccel_FOUND)
find_package(KF6GlobalAccel QUIET)
if(KF6GlobalAccel_FOUND)
add_definitions( -DKGLOBALACCEL )
else()
message(WARNING "KF5GlobalAccel not found, global shortcuts will not work")
message(WARNING "KF6GlobalAccel not found, global shortcuts will not work")
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()
Expand Down Expand Up @@ -115,19 +119,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(KF6Notifications_FOUND)
target_link_libraries(discord-screenaudio KF6::Notifications)
install(FILES assets/discord-screenaudio.notifyrc DESTINATION ${CMAKE_INSTALL_PREFIX}/share/knotifications6)
endif()
if(KF6XmlGui_FOUND)
target_link_libraries(discord-screenaudio KF6::XmlGui KF6::CoreAddons)
endif()
if(KF6GlobalAccel_FOUND)
target_link_libraries(discord-screenaudio KF6::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)
11 changes: 11 additions & 0 deletions src/centralwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void CentralWidget::setupWebView() {
notification->setText(notificationInfo->message());
notification->setPixmap(
QPixmap::fromImage(notificationInfo->icon()));
#ifdef QT5
notification->setDefaultAction("View");
connect(notification, &KNotification::defaultActivated,
[&, notificationInfo = std::move(notificationInfo)]() {
Expand All @@ -58,6 +59,16 @@ void CentralWidget::setupWebView() {
activateWindow();
});
notification->sendEvent();
#else
auto action = notification->addDefaultAction("View");
connect(action, &KNotificationAction::activated,
[&, notificationInfo = std::move(notificationInfo)]() {
notificationInfo->click();
show();
activateWindow();
});
notification->sendEvent();
#endif
#endif
}
});
Expand Down
3 changes: 2 additions & 1 deletion src/discordpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
#include <QWebEngineScriptCollection>
#include <QWebEngineSettings>

DiscordPage::DiscordPage(QWidget *parent) : QWebEnginePage(parent) {
DiscordPage::DiscordPage(QWidget *parent)
: QWebEnginePage(new QWebEngineProfile("discord-screenaudio"), parent) {
setBackgroundColor(QColor("#313338"));

connect(this, &QWebEnginePage::featurePermissionRequested, this,
Expand Down
4 changes: 0 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
#include "mainwindow.h"
#include "virtmic.h"

#ifdef KXMLGUI
#include <KAboutData>
#endif

#include <QApplication>
#include <QCommandLineParser>
#include <QLocalServer>
Expand Down
2 changes: 1 addition & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ MainWindow::MainWindow(bool useNotifySend, QWidget *parent)
setCentralWidget(m_centralWidget);
setupTrayIcon();
setMinimumSize(800, 300);
connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this),
connect(new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q), this),
&QShortcut::activated, this, &MainWindow::toggleOrCloseWindow);
if (m_settings->contains("geometry")) {
restoreGeometry(m_settings->value("geometry").toByteArray());
Expand Down
1 change: 1 addition & 0 deletions src/userscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <QTimer>

#ifdef KXMLGUI
#include <KAboutData>
#include <KActionCollection>
#endif

Expand Down
1 change: 0 additions & 1 deletion src/userscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <QProcess>

#ifdef KXMLGUI
#include <KAboutData>
#include <KHelpMenu>
#include <KShortcutsDialog>
#include <KXmlGuiWindow>
Expand Down

0 comments on commit 64bacdb

Please sign in to comment.