From 2716ffaf602fd9f39d9aca06a0853ed10cf90132 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Sat, 21 Nov 2020 19:15:08 +0800 Subject: feat: windows extra plugin --- windows-extra/CMakeLists.txt | 16 ++++++++++ windows-extra/windowsextra.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++ windows-extra/windowsextra.hpp | 38 ++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 windows-extra/CMakeLists.txt create mode 100644 windows-extra/windowsextra.cpp create mode 100644 windows-extra/windowsextra.hpp (limited to 'windows-extra') diff --git a/windows-extra/CMakeLists.txt b/windows-extra/CMakeLists.txt new file mode 100644 index 0000000..6754e46 --- /dev/null +++ b/windows-extra/CMakeLists.txt @@ -0,0 +1,16 @@ +set(windowsextra_SOURCES + windowsextra.hpp + windowsextra.cpp +) + +include_directories(${PROJECT_SOURCE_DIR}/include/) + +find_package(Qt5 REQUIRED COMPONENTS Widgets WinExtras) + +add_library(windowsextra MODULE + ${windowsextra_SOURCES} +) + +target_link_libraries(windowsextra Qt5::Widgets Qt5::WinExtras) + +install(TARGETS windowsextra LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/qmidiplayer/) diff --git a/windows-extra/windowsextra.cpp b/windows-extra/windowsextra.cpp new file mode 100644 index 0000000..6c5ef1f --- /dev/null +++ b/windows-extra/windowsextra.cpp @@ -0,0 +1,71 @@ +#include +#include "windowsextra.hpp" + +#include +#include +#include + +qmpWindowsExtraPlugin::qmpWindowsExtraPlugin(qmpPluginAPI *_api) +{ + api = _api; +} +qmpWindowsExtraPlugin::~qmpWindowsExtraPlugin() +{ + api = nullptr; +} +void qmpWindowsExtraPlugin::init() +{ + QMainWindow * w = static_cast(api->getMainWindow()); + m_timer = new QTimer(); + m_taskbarIcon = new QWinTaskbarButton(); + m_taskbarIcon->setWindow(w->windowHandle()); + + m_timerConnection = QObject::connect(m_timer, &QTimer::timeout, [ = ](){ + m_taskbarIcon->progress()->setValue(api->getCurrentPlaybackPercentage()); + }); + + ui_start = api->registerUIHook("main.start", [this](const void *, void *) + { + m_taskbarIcon->progress()->show(); + m_taskbarIcon->progress()->resume(); + m_timer->start(250); + }, nullptr); + ui_stop = api->registerUIHook("main.stop", [this](const void *, void *) + { + m_taskbarIcon->progress()->stop(); + m_taskbarIcon->progress()->hide(); + }, nullptr); + ui_pause = api->registerUIHook("main.pause", [this](const void *, void *) + { + PlaybackStatus ps = api->getPlaybackStatus(); + if (ps.paused) { + m_taskbarIcon->progress()->pause(); + } else { + m_taskbarIcon->progress()->resume(); + } + }, nullptr); + ui_reset = api->registerUIHook("main.reset", [this](const void *, void *) + { + m_taskbarIcon->progress()->reset(); + }, nullptr); +} +void qmpWindowsExtraPlugin::deinit() +{ + QObject::disconnect(m_timerConnection); + + m_timer->deleteLater(); + m_taskbarIcon->deleteLater(); + + api->unregisterUIHook("main.start", ui_start); + api->unregisterUIHook("main.stop", ui_stop); + api->unregisterUIHook("main.pause", ui_pause); + api->unregisterUIHook("main.reset", ui_reset); +} +const char *qmpWindowsExtraPlugin::pluginGetName() +{ + return "Windows Extra Feature Plugin"; +} +const char *qmpWindowsExtraPlugin::pluginGetVersion() +{ + return "0.0.0"; +} diff --git a/windows-extra/windowsextra.hpp b/windows-extra/windowsextra.hpp new file mode 100644 index 0000000..227d4ad --- /dev/null +++ b/windows-extra/windowsextra.hpp @@ -0,0 +1,38 @@ +#ifndef SAMPLEPLUGIN_H +#define SAMPLEPLUGIN_H + +#include "../include/qmpcorepublic.hpp" + +#include + +class qmpWindowsExtraPlugin: public qmpPluginIntf +{ +private: + qmpPluginAPI *api; +public: + qmpWindowsExtraPlugin(qmpPluginAPI *_api); + ~qmpWindowsExtraPlugin(); + void init(); + void deinit(); + const char *pluginGetName(); + const char *pluginGetVersion(); + +private: + QWinTaskbarButton * m_taskbarIcon = nullptr; + QTimer * m_timer = nullptr; + QMetaObject::Connection m_timerConnection; + int ui_start, ui_stop, ui_pause, ui_reset; +}; + +extern "C" { + EXPORTSYM qmpPluginIntf *qmpPluginGetInterface(qmpPluginAPI *api) + { + return new qmpWindowsExtraPlugin(api); + } + EXPORTSYM const char *qmpPluginGetAPIRev() + { + return QMP_PLUGIN_API_REV; + } +} + +#endif // SAMPLEPLUGIN_H -- cgit v1.2.3