aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Gary Wang <wzc782970009@gmail.com> 2020-11-21 19:15:08 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2021-01-07 14:16:22 +0800
commit2716ffaf602fd9f39d9aca06a0853ed10cf90132 (patch)
treec70579c587e30a36980cc74218bff4dc33a4f808
parentea68a817c1947b2001775d42755d260d66f4d37f (diff)
downloadQMidiPlayer-2716ffaf602fd9f39d9aca06a0853ed10cf90132.tar.xz
feat: windows extra plugin
-rw-r--r--CMakeLists.txt12
-rw-r--r--windows-extra/CMakeLists.txt16
-rw-r--r--windows-extra/windowsextra.cpp71
-rw-r--r--windows-extra/windowsextra.hpp38
4 files changed, 133 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 32fc3c9..5862f0e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,7 +16,8 @@ pkg_search_module(rtmidi REQUIRED rtmidi)
option(BUILD_VISUALIZATION "Build visualization plugin" ON)
if(WIN32)
- option(BUILD_BACKTRACE "Build backtrace library" OFF)
+ option(BUILD_WINEXTRA "Build Windows extra library" ON)
+ option(BUILD_BACKTRACE "Build backtrace library" OFF)
endif()
if(UNIX)
option(BUILD_PORTABLE "Instruct the built binary not to search system directories" OFF)
@@ -37,7 +38,10 @@ if(BUILD_VISUALIZATION)
add_subdirectory(visualization)
endif()
if(WIN32)
-if(BUILD_BACKTRACE)
- add_subdirectory(third_party/backtrace-mingw)
-endif()
+ if(BUILD_WINEXTRA)
+ add_subdirectory(windows-extra)
+ endif()
+ if(BUILD_BACKTRACE)
+ add_subdirectory(third_party/backtrace-mingw)
+ endif()
endif()
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 <cstdio>
+#include "windowsextra.hpp"
+
+#include <QMainWindow>
+#include <QTimer>
+#include <QWinTaskbarProgress>
+
+qmpWindowsExtraPlugin::qmpWindowsExtraPlugin(qmpPluginAPI *_api)
+{
+ api = _api;
+}
+qmpWindowsExtraPlugin::~qmpWindowsExtraPlugin()
+{
+ api = nullptr;
+}
+void qmpWindowsExtraPlugin::init()
+{
+ QMainWindow * w = static_cast<QMainWindow *>(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 <QWinTaskbarButton>
+
+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