Add Windows taskbar integration.

Progress indication and pause/resume button.
This commit is contained in:
Denis Shemanaev 2021-04-23 10:51:37 +03:00
parent aaaf23df17
commit fd93d635b0
11 changed files with 190 additions and 0 deletions

View File

@ -33,6 +33,10 @@ if(LINUX_DBUS)
set(components ${components} DBus)
endif(LINUX_DBUS)
if(WIN32)
set(components ${components} WinExtras)
endif(WIN32)
foreach(COMP ${components})
set(mod Qt5${COMP})

View File

@ -65,6 +65,7 @@ class mpvAudioPlayer {
player.updateDuration.connect(onDuration);
player.error.connect(onError);
player.paused.connect(onPause);
window.api.taskbar.pauseClicked.connect(onPauseClicked);
}
return setCurrentSrc(options);
@ -95,6 +96,7 @@ class mpvAudioPlayer {
};
self.events.trigger(self, 'stopped', [stopInfo]);
window.api.taskbar.setControlsVisible(false);
self._currentTime = null;
self._currentSrc = null;
@ -135,6 +137,7 @@ class mpvAudioPlayer {
player.updateDuration.disconnect(onDuration);
player.error.disconnect(onError);
player.paused.disconnect(onPause);
window.api.taskbar.pauseClicked.disconnect(onPauseClicked);
};
function onDuration(duration) {
@ -150,12 +153,14 @@ class mpvAudioPlayer {
if (!self._isFadingOut) {
self._currentTime = time;
self.events.trigger(self, 'timeupdate');
window.api.taskbar.setProgress(time * 100 / self._duration);
}
}
function onPlaying() {
if (!self._started) {
self._started = true;
window.api.taskbar.setControlsVisible(true);
}
self.setPlaybackRate(1);
@ -164,6 +169,7 @@ class mpvAudioPlayer {
if (self._paused) {
self._paused = false;
self.events.trigger(self, 'unpause');
window.api.taskbar.setPaused(false);
}
self.events.trigger(self, 'playing');
@ -172,6 +178,7 @@ class mpvAudioPlayer {
function onPause() {
self._paused = true;
self.events.trigger(self, 'pause');
window.api.taskbar.setPaused(true);
}
function onError(error) {
@ -183,6 +190,10 @@ class mpvAudioPlayer {
}
]);
}
function onPauseClicked() {
self.paused() ? self.unpause() : self.pause();
}
}
getSavedVolume() {

View File

@ -126,6 +126,7 @@
this._currentTime = time;
this.events.trigger(this, 'timeupdate');
window.api.taskbar.setProgress(time * 100 / this._duration);
};
/**
@ -164,11 +165,13 @@
// Need to override default style.
this._videoDialog.style.setProperty('background', 'transparent', 'important');
window.api.taskbar.setControlsVisible(true);
}
if (this._paused) {
this._paused = false;
this.events.trigger(this, 'unpause');
window.api.taskbar.setPaused(false);
}
this.events.trigger(this, 'playing');
@ -181,6 +184,7 @@
this._paused = true;
// For Syncplay ready notification
this.events.trigger(this, 'pause');
window.api.taskbar.setPaused(true);
};
this.onWaiting = () => {
@ -205,6 +209,9 @@
this._duration = duration;
};
this.onPauseClicked = () => {
this.paused() ? this.unpause() : this.pause();
};
}
currentSrc() {
@ -360,6 +367,7 @@
};
this.events.trigger(this, 'stopped', [stopInfo]);
window.api.taskbar.setControlsVisible(false);
this._currentTime = null;
this._currentSrc = null;
@ -394,6 +402,7 @@
player.updateDuration.disconnect(this.onDuration);
player.error.disconnect(this.onError);
player.paused.disconnect(this.onPause);
window.api.taskbar.pauseClicked.disconnect(this.onPauseClicked);
const dlg = this._videoDialog;
if (dlg) {
@ -446,6 +455,7 @@
player.updateDuration.connect(this.onDuration);
player.error.connect(this.onError);
player.paused.connect(this.onPause);
window.api.taskbar.pauseClicked.connect(this.onPauseClicked);
}
if (options.fullscreen) {

View File

@ -24,6 +24,7 @@ add_subdirectory(input)
add_subdirectory(system)
add_subdirectory(settings)
add_subdirectory(power)
add_subdirectory(taskbar)
get_property(ALL_SRCS GLOBAL PROPERTY SRCS_LIST)
set(MAIN_SRCS main.cpp)

View File

@ -10,6 +10,7 @@
#include "display/DisplayComponent.h"
#include "system/SystemComponent.h"
#include "settings/SettingsComponent.h"
#include "taskbar/TaskbarComponent.h"
#if KONVERGO_OPENELEC
#include "system/openelec/OESystemComponent.h"
@ -57,6 +58,7 @@ void ComponentManager::initialize()
registerComponent(&DisplayComponent::Get());
registerComponent(&PlayerComponent::Get());
registerComponent(&PowerComponent::Get());
registerComponent(&TaskbarComponent::Get());
#if KONVERGO_OPENELEC
registerComponent(&OESystemComponent::Get());

View File

@ -0,0 +1,5 @@
add_sources(TaskbarComponent.h TaskbarComponent.cpp)
if(WIN32)
add_sources(TaskbarComponentWin.cpp TaskbarComponentWin.h)
endif(WIN32)

View File

@ -0,0 +1,25 @@
#include "TaskbarComponent.h"
#if defined(Q_OS_WIN32)
#include "TaskbarComponentWin.h"
#endif
/////////////////////////////////////////////////////////////////////////////////////////
TaskbarComponent& TaskbarComponent::Get()
{
#if defined(Q_OS_WIN32)
static TaskbarComponentWin instance;
return instance;
#else
QLOG_WARN() << "Could not find a taskbar component matching this platform. Taskbar functions disabled.";
static TaskbarComponent instance;
return instance;
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////
void TaskbarComponent::setWindow(QQuickWindow* window)
{
m_window = window;
}

View File

@ -0,0 +1,35 @@
#ifndef TASKBARCOMPONENT_H
#define TASKBARCOMPONENT_H
#include <QsLog.h>
#include <QQuickWindow>
#include "ComponentManager.h"
class TaskbarComponent : public ComponentBase
{
Q_OBJECT
public:
static TaskbarComponent& Get();
explicit TaskbarComponent(QObject* parent = nullptr): ComponentBase(parent) {}
const char* componentName() override { return "taskbar"; }
bool componentExport() override { return true; }
bool componentInitialize() override { return true; }
void componentPostInitialize() override {}
virtual void setWindow(QQuickWindow* window);
public Q_SLOTS:
virtual void setControlsVisible(bool value) {}
virtual void setProgress(int value) {}
virtual void setPaused(bool value) {}
Q_SIGNALS:
void pauseClicked();
protected:
QQuickWindow* m_window;
};
#endif // TASKBARCOMPONENT_H

View File

@ -0,0 +1,65 @@
#include <QApplication>
#include <QStyle>
#include "TaskbarComponentWin.h"
/////////////////////////////////////////////////////////////////////////////////////////
void TaskbarComponentWin::setWindow(QQuickWindow* window)
{
TaskbarComponent::setWindow(window);
m_button = new QWinTaskbarButton(m_window);
m_button->setWindow(m_window);
m_toolbar = new QWinThumbnailToolBar(m_window);
m_toolbar->setWindow(m_window);
m_pause = new QWinThumbnailToolButton(m_toolbar);
connect(m_pause, &QWinThumbnailToolButton::clicked, this, &TaskbarComponentWin::onPauseClicked);
m_toolbar->addButton(m_pause);
setControlsVisible(false);
setPaused(false);
}
/////////////////////////////////////////////////////////////////////////////////////////
void TaskbarComponentWin::onPauseClicked()
{
emit pauseClicked();
}
/////////////////////////////////////////////////////////////////////////////////////////
void TaskbarComponentWin::setControlsVisible(bool value)
{
m_button->progress()->setVisible(value);
for (auto& button : m_toolbar->buttons())
{
button->setVisible(value);
}
}
/////////////////////////////////////////////////////////////////////////////////////////
void TaskbarComponentWin::setProgress(int value)
{
m_button->progress()->setValue(value);
}
/////////////////////////////////////////////////////////////////////////////////////////
void TaskbarComponentWin::setPaused(bool value)
{
if (value)
{
// m_pause->setToolTip("Resume");
m_pause->setIcon(QApplication::style()->standardIcon(QStyle::SP_MediaPlay));
}
else
{
// m_pause->setToolTip("Pause");
m_pause->setIcon(QApplication::style()->standardIcon(QStyle::SP_MediaPause));
}
m_button->progress()->setPaused(value);
}

View File

@ -0,0 +1,30 @@
#ifndef TASKBARCOMPONENTWIN_H
#define TASKBARCOMPONENTWIN_H
#include <QWinTaskbarButton>
#include <QWinTaskbarProgress>
#include <QWinThumbnailToolBar>
#include <QWinThumbnailToolButton>
#include "TaskbarComponent.h"
class TaskbarComponentWin : public TaskbarComponent
{
public:
TaskbarComponentWin(): TaskbarComponent(nullptr) {}
virtual void setControlsVisible(bool value) override;
virtual void setProgress(int value) override;
virtual void setPaused(bool value) override;
virtual void setWindow(QQuickWindow* window) override;
private:
void onPauseClicked();
QWinTaskbarButton* m_button;
QWinThumbnailToolBar* m_toolbar;
QWinThumbnailToolButton* m_pause;
};
#endif // TASKBARCOMPONENTWIN_H

View File

@ -15,6 +15,7 @@
#include "player/PlayerComponent.h"
#include "player/PlayerQuickItem.h"
#include "display/DisplayComponent.h"
#include "taskbar/TaskbarComponent.h"
#include "QsLog.h"
#include "utils/Utils.h"
#include "Globals.h"
@ -284,6 +285,7 @@ void KonvergoWindow::enableVideoWindow()
{
PlayerComponent::Get().setWindow(this);
DisplayComponent::Get().setApplicationWindow(this);
TaskbarComponent::Get().setWindow(this);
}
///////////////////////////////////////////////////////////////////////////////////////////////////