aboutsummaryrefslogtreecommitdiff
path: root/windows-extra/windowsextra.cpp
blob: 6c5ef1fdd4486dd451b80d0cb03e597c50209d53 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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";
}