1
0
Fork 0

[UI] Added audio devices menu.

This commit is contained in:
Kitteh 2018-11-10 13:32:54 +00:00
parent d1606274cc
commit c180f3f17f
8 changed files with 90 additions and 6 deletions

View file

@ -33,7 +33,7 @@ if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
set(CMAKE_BUILD_TYPE MINSIZEREL)
set(CMAKE_BUILD_TYPE DEBUG)
if(TESTING)

View file

@ -5,8 +5,8 @@ QT += qml quickcontrols2 widgets x11extras
SOURCES += src/main.cpp src/MpvPlayerBackend.cpp src/utils.cpp
CONFIG += release
#CONFIG+=qtquickcompiler
CONFIG += debug
CONFIG-=qtquickcompiler
QT_CONFIG -= no-pkg-config
CONFIG += link_pkgconfig
PKGCONFIG += mpv

View file

@ -1,4 +1,3 @@
#include <clocale>
#include <stdbool.h>
#include <stdexcept>
@ -10,6 +9,7 @@
#include <QOpenGLContext>
#include <QOpenGLFramebufferObject>
#include <QQuickWindow>
#include <QSequentialIterable>
#include <math.h>
namespace {
@ -128,6 +128,7 @@ MpvPlayerBackend::MpvPlayerBackend(QQuickItem* parent)
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, "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, "volume", MPV_FORMAT_DOUBLE);
mpv_observe_property(mpv, 0, "muted", MPV_FORMAT_NONE);
@ -201,6 +202,34 @@ MpvPlayerBackend::launchAboutQt()
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
MpvPlayerBackend::togglePlayPause()
{
@ -324,7 +353,8 @@ MpvPlayerBackend::toggleOnTop()
void
MpvPlayerBackend::toggleStats()
{
command(QVariantList() << "script-binding" << "stats/display-stats-toggle");
command(QVariantList() << "script-binding"
<< "stats/display-stats-toggle");
}
void
@ -471,6 +501,8 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event)
updatePlayPause(getProperty("pause"));
} else if (strcmp(prop->name, "tracks-menu") == 0) {
QMetaObject::invokeMethod(this, "tracksUpdate");
} else if (strcmp(prop->name, "audio-device-list") == 0) {
QMetaObject::invokeMethod(this, "audioDevicesUpdate");
}
break;
}

View file

@ -40,6 +40,8 @@ public slots:
void toggleStats();
void updateDurationStringText();
QVariant getTracks() const;
QVariant getaudioDevices() const;
void setAudioDevice(const QString& name);
void updatePrev(const QVariant& val);
void updateVolume(const QVariant& val);
void updatePlayPause(const QVariant& val);

View 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)
}
}

View file

@ -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() {
for (var i = 0, len = audioMenu.count; i < len; i++) {
var audioAction = audioMenu.actionAt(i)
@ -566,6 +587,19 @@ ApplicationWindow {
}
shortcut: keybinds.mute
}
MenuSeparator {
}
CustomMenu {
title: translate.getTranslation("AUDIO_DEVICES",
i18n.language)
id: audioDeviceMenu
ActionGroup {
id: audioDeviceMenuGroup
}
}
MenuSeparator {
}

View file

@ -5,6 +5,7 @@
<file>CustomMenuItem.qml</file>
<file>CustomMenu.qml</file>
<file>TrackItem.qml</file>
<file>AudioDeviceItem.qml</file>
<file>Translator.qml</file>
<file>translations.js</file>
<file>icons/play.svg</file>

View file

@ -40,7 +40,8 @@ var translations = {
ABOUT_QT: "About Qt",
TITLE: "Title",
TOGGLE_ALWAYS_ON_TOP: "Toggle Always On Top",
DISABLE_TRACK: "Disable Track"
DISABLE_TRACK: "Disable Track",
AUDIO_DEVICES: "Audio Devices"
},
spanish: {
SAVE_SCREENSHOT: "Guardar captura en",