[UI] Added audio devices menu.
This commit is contained in:
parent
d1606274cc
commit
c180f3f17f
|
@ -33,7 +33,7 @@ if(CCACHE_FOUND)
|
||||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
|
||||||
endif(CCACHE_FOUND)
|
endif(CCACHE_FOUND)
|
||||||
|
|
||||||
set(CMAKE_BUILD_TYPE MINSIZEREL)
|
set(CMAKE_BUILD_TYPE DEBUG)
|
||||||
|
|
||||||
|
|
||||||
if(TESTING)
|
if(TESTING)
|
||||||
|
|
|
@ -5,8 +5,8 @@ QT += qml quickcontrols2 widgets x11extras
|
||||||
|
|
||||||
SOURCES += src/main.cpp src/MpvPlayerBackend.cpp src/utils.cpp
|
SOURCES += src/main.cpp src/MpvPlayerBackend.cpp src/utils.cpp
|
||||||
|
|
||||||
CONFIG += release
|
CONFIG += debug
|
||||||
#CONFIG+=qtquickcompiler
|
CONFIG-=qtquickcompiler
|
||||||
QT_CONFIG -= no-pkg-config
|
QT_CONFIG -= no-pkg-config
|
||||||
CONFIG += link_pkgconfig
|
CONFIG += link_pkgconfig
|
||||||
PKGCONFIG += mpv
|
PKGCONFIG += mpv
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
#include <clocale>
|
#include <clocale>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
@ -10,6 +9,7 @@
|
||||||
#include <QOpenGLContext>
|
#include <QOpenGLContext>
|
||||||
#include <QOpenGLFramebufferObject>
|
#include <QOpenGLFramebufferObject>
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
|
#include <QSequentialIterable>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -128,6 +128,7 @@ MpvPlayerBackend::MpvPlayerBackend(QQuickItem* parent)
|
||||||
mpv_observe_property(mpv, 0, "playback-abort", MPV_FORMAT_NONE);
|
mpv_observe_property(mpv, 0, "playback-abort", MPV_FORMAT_NONE);
|
||||||
mpv_observe_property(mpv, 0, "chapter-list", MPV_FORMAT_NODE);
|
mpv_observe_property(mpv, 0, "chapter-list", MPV_FORMAT_NODE);
|
||||||
mpv_observe_property(mpv, 0, "track-list", MPV_FORMAT_NODE);
|
mpv_observe_property(mpv, 0, "track-list", MPV_FORMAT_NODE);
|
||||||
|
mpv_observe_property(mpv, 0, "audio-device-list", MPV_FORMAT_NODE);
|
||||||
mpv_observe_property(mpv, 0, "playlist-pos", MPV_FORMAT_DOUBLE);
|
mpv_observe_property(mpv, 0, "playlist-pos", MPV_FORMAT_DOUBLE);
|
||||||
mpv_observe_property(mpv, 0, "volume", MPV_FORMAT_DOUBLE);
|
mpv_observe_property(mpv, 0, "volume", MPV_FORMAT_DOUBLE);
|
||||||
mpv_observe_property(mpv, 0, "muted", MPV_FORMAT_NONE);
|
mpv_observe_property(mpv, 0, "muted", MPV_FORMAT_NONE);
|
||||||
|
@ -201,6 +202,34 @@ MpvPlayerBackend::launchAboutQt()
|
||||||
qapp->aboutQt();
|
qapp->aboutQt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant
|
||||||
|
MpvPlayerBackend::getaudioDevices() const
|
||||||
|
{
|
||||||
|
QVariant drivers = getProperty("audio-device-list");
|
||||||
|
QVariant currentDevice = getProperty("audio-device");
|
||||||
|
|
||||||
|
QVariantMap newDrivers;
|
||||||
|
|
||||||
|
QSequentialIterable iterable = drivers.value<QSequentialIterable>();
|
||||||
|
foreach (const QVariant& v, iterable) {
|
||||||
|
QVariantMap item = v.toMap();
|
||||||
|
item["selected"] = currentDevice == item["name"];
|
||||||
|
newDrivers[item["description"].toString()] = item;
|
||||||
|
}
|
||||||
|
QMap<QString, QVariant> pulseItem;
|
||||||
|
pulseItem["name"] = "pulse";
|
||||||
|
pulseItem["description"] = "Default (pulseaudio)";
|
||||||
|
pulseItem["selected"] = currentDevice == "pulse";
|
||||||
|
newDrivers[pulseItem["description"].toString()] = pulseItem;
|
||||||
|
return QVariant(newDrivers);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MpvPlayerBackend::setAudioDevice(const QString& name)
|
||||||
|
{
|
||||||
|
setProperty("audio-device", name);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MpvPlayerBackend::togglePlayPause()
|
MpvPlayerBackend::togglePlayPause()
|
||||||
{
|
{
|
||||||
|
@ -324,7 +353,8 @@ MpvPlayerBackend::toggleOnTop()
|
||||||
void
|
void
|
||||||
MpvPlayerBackend::toggleStats()
|
MpvPlayerBackend::toggleStats()
|
||||||
{
|
{
|
||||||
command(QVariantList() << "script-binding" << "stats/display-stats-toggle");
|
command(QVariantList() << "script-binding"
|
||||||
|
<< "stats/display-stats-toggle");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -471,6 +501,8 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
|
||||||
updatePlayPause(getProperty("pause"));
|
updatePlayPause(getProperty("pause"));
|
||||||
} else if (strcmp(prop->name, "tracks-menu") == 0) {
|
} else if (strcmp(prop->name, "tracks-menu") == 0) {
|
||||||
QMetaObject::invokeMethod(this, "tracksUpdate");
|
QMetaObject::invokeMethod(this, "tracksUpdate");
|
||||||
|
} else if (strcmp(prop->name, "audio-device-list") == 0) {
|
||||||
|
QMetaObject::invokeMethod(this, "audioDevicesUpdate");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,8 @@ public slots:
|
||||||
void toggleStats();
|
void toggleStats();
|
||||||
void updateDurationStringText();
|
void updateDurationStringText();
|
||||||
QVariant getTracks() const;
|
QVariant getTracks() const;
|
||||||
|
QVariant getaudioDevices() const;
|
||||||
|
void setAudioDevice(const QString& name);
|
||||||
void updatePrev(const QVariant& val);
|
void updatePrev(const QVariant& val);
|
||||||
void updateVolume(const QVariant& val);
|
void updateVolume(const QVariant& val);
|
||||||
void updatePlayPause(const QVariant& val);
|
void updatePlayPause(const QVariant& val);
|
||||||
|
|
14
src/qml/AudioDeviceItem.qml
Normal file
14
src/qml/AudioDeviceItem.qml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import QtQuick 2.11
|
||||||
|
import QtQuick.Controls 2.4
|
||||||
|
import Qt.labs.settings 1.0
|
||||||
|
|
||||||
|
Action {
|
||||||
|
id: audioDeviceItem
|
||||||
|
property string deviceID: "none"
|
||||||
|
checkable: true
|
||||||
|
checked: false
|
||||||
|
|
||||||
|
onTriggered: {
|
||||||
|
player.setAudioDevice(deviceID)
|
||||||
|
}
|
||||||
|
}
|
|
@ -103,6 +103,27 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function audioDevicesUpdate() {
|
||||||
|
var audioDevices = player.getaudioDevices()
|
||||||
|
for (var i = 0, len = audioDeviceMenu.count; i < len; i++) {
|
||||||
|
audioDeviceMenu.takeAction(0)
|
||||||
|
}
|
||||||
|
for (var thing in audioDevices) {
|
||||||
|
var audioDevice = audioDevices[thing]
|
||||||
|
var name = audioDevice["name"]
|
||||||
|
var description = audioDevice["description"]
|
||||||
|
var selected = audioDevice["selected"]
|
||||||
|
var component = Qt.createComponent("AudioDeviceItem.qml")
|
||||||
|
var action = component.createObject(audioDeviceMenu, {
|
||||||
|
text: description,
|
||||||
|
deviceID: String(name),
|
||||||
|
checked: audioDevice["selected"]
|
||||||
|
})
|
||||||
|
action.ActionGroup.group = audioDeviceMenuGroup
|
||||||
|
audioDeviceMenu.addAction(action)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function tracksUpdate() {
|
function tracksUpdate() {
|
||||||
for (var i = 0, len = audioMenu.count; i < len; i++) {
|
for (var i = 0, len = audioMenu.count; i < len; i++) {
|
||||||
var audioAction = audioMenu.actionAt(i)
|
var audioAction = audioMenu.actionAt(i)
|
||||||
|
@ -566,6 +587,19 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
shortcut: keybinds.mute
|
shortcut: keybinds.mute
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MenuSeparator {
|
||||||
|
}
|
||||||
|
|
||||||
|
CustomMenu {
|
||||||
|
title: translate.getTranslation("AUDIO_DEVICES",
|
||||||
|
i18n.language)
|
||||||
|
id: audioDeviceMenu
|
||||||
|
ActionGroup {
|
||||||
|
id: audioDeviceMenuGroup
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MenuSeparator {
|
MenuSeparator {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
<file>CustomMenuItem.qml</file>
|
<file>CustomMenuItem.qml</file>
|
||||||
<file>CustomMenu.qml</file>
|
<file>CustomMenu.qml</file>
|
||||||
<file>TrackItem.qml</file>
|
<file>TrackItem.qml</file>
|
||||||
|
<file>AudioDeviceItem.qml</file>
|
||||||
<file>Translator.qml</file>
|
<file>Translator.qml</file>
|
||||||
<file>translations.js</file>
|
<file>translations.js</file>
|
||||||
<file>icons/play.svg</file>
|
<file>icons/play.svg</file>
|
||||||
|
|
|
@ -40,7 +40,8 @@ var translations = {
|
||||||
ABOUT_QT: "About Qt",
|
ABOUT_QT: "About Qt",
|
||||||
TITLE: "Title",
|
TITLE: "Title",
|
||||||
TOGGLE_ALWAYS_ON_TOP: "Toggle Always On Top",
|
TOGGLE_ALWAYS_ON_TOP: "Toggle Always On Top",
|
||||||
DISABLE_TRACK: "Disable Track"
|
DISABLE_TRACK: "Disable Track",
|
||||||
|
AUDIO_DEVICES: "Audio Devices"
|
||||||
},
|
},
|
||||||
spanish: {
|
spanish: {
|
||||||
SAVE_SCREENSHOT: "Guardar captura en",
|
SAVE_SCREENSHOT: "Guardar captura en",
|
||||||
|
|
Loading…
Reference in a new issue