diff --git a/CMakeLists.txt b/CMakeLists.txt index b9fd93a..f6fc1ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/KittehPlayer.pro b/KittehPlayer.pro index d36f221..d96600a 100644 --- a/KittehPlayer.pro +++ b/KittehPlayer.pro @@ -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 diff --git a/src/MpvPlayerBackend.cpp b/src/MpvPlayerBackend.cpp index e640057..0242f57 100644 --- a/src/MpvPlayerBackend.cpp +++ b/src/MpvPlayerBackend.cpp @@ -1,4 +1,3 @@ - #include #include #include @@ -10,6 +9,7 @@ #include #include #include +#include #include 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(); + foreach (const QVariant& v, iterable) { + QVariantMap item = v.toMap(); + item["selected"] = currentDevice == item["name"]; + newDrivers[item["description"].toString()] = item; + } + QMap 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; } diff --git a/src/MpvPlayerBackend.h b/src/MpvPlayerBackend.h index e795bd8..e9214ed 100644 --- a/src/MpvPlayerBackend.h +++ b/src/MpvPlayerBackend.h @@ -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); diff --git a/src/qml/AudioDeviceItem.qml b/src/qml/AudioDeviceItem.qml new file mode 100644 index 0000000..6f7f5ad --- /dev/null +++ b/src/qml/AudioDeviceItem.qml @@ -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) + } +} diff --git a/src/qml/main.qml b/src/qml/main.qml index 65f8cba..4c54e4e 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -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 { } diff --git a/src/qml/qml.qrc b/src/qml/qml.qrc index 307e646..ec1b64c 100644 --- a/src/qml/qml.qrc +++ b/src/qml/qml.qrc @@ -5,6 +5,7 @@ CustomMenuItem.qml CustomMenu.qml TrackItem.qml + AudioDeviceItem.qml Translator.qml translations.js icons/play.svg diff --git a/src/qml/translations.js b/src/qml/translations.js index cedffbf..258d6c2 100644 --- a/src/qml/translations.js +++ b/src/qml/translations.js @@ -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",