From 01a3775ac752ddaef0e7ca2e91d506cd920c6666 Mon Sep 17 00:00:00 2001 From: Dark Steveneq Date: Thu, 16 Oct 2025 19:21:35 +0200 Subject: [PATCH] Begin rewriting Player in C++ --- .gitignore | 5 +- .vscode/settings.json | 6 ++ CMakeLists.txt | 19 ++++++- Player.qml => Player.qml.prev | 0 build.nix | 6 ++ buildFlags.h.in | 1 + cmake/FindDiscordSDK.cmake | 103 ++++++++++++++++++++++++++++++++++ ext/.gitkeep | 0 main.cpp | 8 +++ player.cpp | 21 +++++++ player.h | 18 ++++++ 11 files changed, 184 insertions(+), 3 deletions(-) create mode 100644 .vscode/settings.json rename Player.qml => Player.qml.prev (100%) create mode 100644 buildFlags.h.in create mode 100644 cmake/FindDiscordSDK.cmake create mode 100644 ext/.gitkeep create mode 100644 player.cpp create mode 100644 player.h diff --git a/.gitignore b/.gitignore index 8ab001e..14c5dc1 100755 --- a/.gitignore +++ b/.gitignore @@ -88,4 +88,7 @@ out/ .direnv dist CMakePresets.json -CMakeUserPresets.json \ No newline at end of file +CMakeUserPresets.json + +ext/* +!ext/.gitkeep \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..748131f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "flake.lock": "json", + "qobject": "cpp" + } +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 99df125..e8c2ce7 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,22 @@ cmake_minimum_required(VERSION 3.16) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) + project(qyouradio VERSION 0.1 LANGUAGES CXX) set(CMAKE_CXX_STANDARD_REQUIRED ON) -find_package(Qt6 REQUIRED COMPONENTS Quick Multimedia) +find_package(Qt6 REQUIRED COMPONENTS Core Quick Multimedia) +find_package(DiscordSDK) qt_standard_project_setup(REQUIRES 6.8) +configure_file(buildFlags.h.in buildFlags.h) + qt_add_executable(appqyouradio main.cpp + buildFlags.h + player.cpp player.h resources/qyouradio.rc resources/resource.h ) @@ -28,7 +35,7 @@ qt_add_qml_module(appqyouradio VERSION 1.0 QML_FILES Main.qml - Player.qml + # Player.qml ViewPlayer.qml ViewSettings.qml ) @@ -44,10 +51,18 @@ set_target_properties(appqyouradio PROPERTIES WIN32_EXECUTABLE TRUE ) +target_include_directories(appqyouradio PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") + target_link_libraries(appqyouradio PUBLIC Qt6::Quick Qt6::Multimedia ) +if (DiscordSDK_FOUND) + target_link_libraries(appqyouradio + PRIVATE DiscordSDK::DiscordSDK + ) +endif() + include(GNUInstallDirs) install(TARGETS appqyouradio BUNDLE DESTINATION . diff --git a/Player.qml b/Player.qml.prev similarity index 100% rename from Player.qml rename to Player.qml.prev diff --git a/build.nix b/build.nix index 7e59737..551d4a5 100755 --- a/build.nix +++ b/build.nix @@ -1,5 +1,7 @@ { stdenv , lib +, alsa-lib +, xorg , clang , qtbase , qtdeclarative @@ -18,6 +20,10 @@ stdenv.mkDerivation { src = ./.; buildInputs = [ + # alsa-lib + # xorg.libX11 + # xorg.libXext + qtbase qtdeclarative qtlocation diff --git a/buildFlags.h.in b/buildFlags.h.in new file mode 100644 index 0000000..b192e0f --- /dev/null +++ b/buildFlags.h.in @@ -0,0 +1 @@ +#cmakedefine01 DiscordSDK_FOUND \ No newline at end of file diff --git a/cmake/FindDiscordSDK.cmake b/cmake/FindDiscordSDK.cmake new file mode 100644 index 0000000..af9d0b2 --- /dev/null +++ b/cmake/FindDiscordSDK.cmake @@ -0,0 +1,103 @@ +# Locate Discord Social SDK library and headers. +# +# Copyright (c) 2025 hat_kid +# https://github.com/thehatkid/DiscordSocialSDKExample +# +# Usage of this module as follows: +# find_package(DiscordSDK) +# +# Variables defined by this module: +# DISCORDSDK_FOUND Whether was found library and headers. +# DISCORDSDK_INCLUDE_DIR SDK include path. +# DISCORDSDK_LIBRARY SDK shared library path. +# DISCORDSDK_IMPLIB Win32: SDK object library path to link. + +# Set SDK root directory path (You can change it to different path) +set(DISCORDSDK_ROOT_DIR "${CMAKE_SOURCE_DIR}/ext/discord_social_sdk" CACHE PATH "Discord Social SDK root path") + +# Set SDK library build variant +set(DISCORDSDK_VARIANT "release" CACHE STRING "Discord Social SDK library variant") + +set_property(CACHE DISCORDSDK_VARIANT PROPERTY STRINGS "release" "debug") + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(DISCORDSDK_VARIANT "debug") +endif() + +# Find SDK include directory path +find_path( + DISCORDSDK_INCLUDE_DIR + NAMES cdiscord.h discordpp.h + PATHS ${DISCORDSDK_ROOT_DIR}/include + DOC "Discord Social SDK include directory" + NO_DEFAULT_PATH +) + +# Find SDK library path +if(WIN32) + find_file( + DISCORDSDK_LIBRARY + NAMES discord_partner_sdk.dll + PATHS ${DISCORDSDK_ROOT_DIR}/bin/${DISCORDSDK_VARIANT} + DOC "Discord Social SDK Windows Dynamic Link Library (.dll)" + NO_DEFAULT_PATH + ) + find_file( + DISCORDSDK_IMPLIB + NAMES discord_partner_sdk.lib + PATHS ${DISCORDSDK_ROOT_DIR}/lib/${DISCORDSDK_VARIANT} + DOC "Discord Social SDK Windows Object Library (.lib)" + NO_DEFAULT_PATH + ) +else() + find_library( + DISCORDSDK_LIBRARY + NAMES libdiscord_partner_sdk discord_partner_sdk + PATHS ${DISCORDSDK_ROOT_DIR}/lib/${DISCORDSDK_VARIANT} + DOC "Discord Social SDK shared library" + NO_DEFAULT_PATH + ) +endif() + +mark_as_advanced( + DISCORDSDK_ROOT_DIR + DISCORDSDK_VARIANT + DISCORDSDK_INCLUDE_DIR + DISCORDSDK_LIBRARY +) + +include(FindPackageHandleStandardArgs) + +if(WIN32) + find_package_handle_standard_args( + DiscordSDK + REQUIRED_VARS DISCORDSDK_IMPLIB DISCORDSDK_LIBRARY DISCORDSDK_INCLUDE_DIR + ) + mark_as_advanced(DISCORDSDK_IMPLIB) +else() + find_package_handle_standard_args( + DiscordSDK + REQUIRED_VARS DISCORDSDK_LIBRARY DISCORDSDK_INCLUDE_DIR + ) +endif() + +if(NOT DiscordSDK_FOUND) + message("Could NOT find Discord Social SDK redistributable! Please check for SDK files in ${DISCORDSDK_ROOT_DIR}") +else() + # Add imported shared library as DiscordSDK::DiscordSDK + add_library(DiscordSDK::DiscordSDK SHARED IMPORTED) + + set_target_properties( + DiscordSDK::DiscordSDK PROPERTIES + IMPORTED_LOCATION ${DISCORDSDK_LIBRARY} + INTERFACE_COMPILE_DEFINITIONS DISCORDPP_IMPLEMENTATION + INTERFACE_INCLUDE_DIRECTORIES ${DISCORDSDK_INCLUDE_DIR} + ) + + if(WIN32) + set_target_properties( + DiscordSDK::DiscordSDK PROPERTIES + IMPORTED_IMPLIB ${DISCORDSDK_IMPLIB} + ) + endif() +endif() \ No newline at end of file diff --git a/ext/.gitkeep b/ext/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/main.cpp b/main.cpp index b4fd983..9d36542 100755 --- a/main.cpp +++ b/main.cpp @@ -1,7 +1,9 @@ #include #include #include +#include +#include "buildFlags.h" int main(int argc, char *argv[]) { @@ -14,6 +16,12 @@ int main(int argc, char *argv[]) engine.loadFromModule("qyouradio", "Main"); app.setWindowIcon(QIcon(":/resources/logo.png")); + +#if DiscordSDK_FOUND + qInfo("Has Discord Social SDK: true"); +#else + qInfo("Has Discord Social SDK: false"); +#endif return app.exec(); } diff --git a/player.cpp b/player.cpp new file mode 100644 index 0000000..181bb6e --- /dev/null +++ b/player.cpp @@ -0,0 +1,21 @@ +#include "player.h" + +Player::Player(QObject *parent) : QObject(parent) +{ + qDebug("Player::Player(): Constructed"); +} + +Player::~Player() +{ + qDebug("Player::~Player(): Destructed"); +} + +void Player::startPlaying(int index) +{ + qDebug("Player::startPlaying(): Success, I can call between both environments!"); +} + +void Player::stopPlaying() +{ + qDebug("Player::stopPlaying(): Success, I can even tell C++ to stop!"); +} \ No newline at end of file diff --git a/player.h b/player.h new file mode 100644 index 0000000..66da0ff --- /dev/null +++ b/player.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include +#include + +class Player : public QObject +{ + Q_OBJECT + QML_SINGLETON + QML_ELEMENT +public: + Player(QObject *parent = nullptr); + ~Player(); + + Q_INVOKABLE void startPlaying(int index); + Q_INVOKABLE void stopPlaying(); +};