From: Mikko Rasa Date: Sat, 17 Oct 2015 13:58:47 +0000 (+0300) Subject: Add channel selection controls in the remote X-Git-Url: http://git.tdb.fi/?p=xinema.git;a=commitdiff_plain;h=857fbdc12041b7f01f45d4dcf2208f9dccf29294 Add channel selection controls in the remote --- diff --git a/remote/qml/pages/ChannelItem.qml b/remote/qml/pages/ChannelItem.qml new file mode 100644 index 0000000..714e707 --- /dev/null +++ b/remote/qml/pages/ChannelItem.qml @@ -0,0 +1,31 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 + +Label +{ + id: item + + anchors + { + left: parent.left + right: parent.right + margins: Theme.paddingLarge + } + + property int channelIndex: 0 + property string channelName: "" + property bool down: false + + signal clicked() + + text: channelIndex+": "+channelName + horizontalAlignment: Text.AlignHCenter + color: down ? Theme.primaryColor : Theme.highlightColor + + MouseArea + { + anchors.fill: parent + + onClicked: item.clicked() + } +} diff --git a/remote/qml/pages/ChannelSelect.qml b/remote/qml/pages/ChannelSelect.qml new file mode 100644 index 0000000..43c6cf7 --- /dev/null +++ b/remote/qml/pages/ChannelSelect.qml @@ -0,0 +1,78 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 + +ValueButton +{ + id: channelSelect + + property var channels: null + property int currentChannel: -1 + property bool _channelsAvailable: channels && channels.length + enabled: _channelsAvailable + + value: (_channelsAvailable ? currentChannel>=0 ? (currentChannel+1)+": "+channels[currentChannel] : "0: (off)" : "(not available)") + + onClicked: + { + if(_channelsAvailable) + pageStack.push(selectDialog); + } + + Component + { + id: selectDialog + + Page + { + id: page + + function selectChannel(index) + { + channelSelect.currentChannel = index; + pageStack.pop(); + } + + SilicaFlickable + { + width: parent.width + contentHeight: column.height + + Column + { + id: column + width: parent.width + spacing: Theme.paddingLarge + + PageHeader + { + id: header + title: channelSelect.label + } + + ChannelItem + { + channelIndex: 0 + channelName: "(off)" + down: channelSelect.currentChannel+1==channelIndex + + onClicked: page.selectChannel(channelIndex-1); + } + Repeater + { + id: repeater + model: channelSelect.channels + + ChannelItem + { + channelIndex: index+1 + channelName: modelData + down: channelSelect.currentChannel+1==channelIndex + + onClicked: page.selectChannel(channelIndex-1); + } + } + } + } + } + } +} diff --git a/remote/qml/pages/PlaybackPage.qml b/remote/qml/pages/PlaybackPage.qml index 24817c6..7bf7cc9 100644 --- a/remote/qml/pages/PlaybackPage.qml +++ b/remote/qml/pages/PlaybackPage.qml @@ -80,6 +80,22 @@ Page streamControl.playbackState = StreamControl.Paused; } } + + ChannelSelect + { + id: audioSelect + label: "Audio" + channels: streamControl.audioChannels + onCurrentChannelChanged: streamControl.currentAudioChannel = currentChannel + } + + ChannelSelect + { + id: spuSelect + label: "Subtitles" + channels: streamControl.spuChannels + onCurrentChannelChanged: streamControl.currentSpuChannel = currentChannel + } } StreamControl @@ -91,5 +107,7 @@ Page if(!slider.down) slider.value = position; } + onCurrentAudioChannelChanged: audioSelect.currentChannel = streamControl.currentAudioChannel; + onCurrentSpuChannelChanged: spuSelect.currentChannel = streamControl.currentSpuChannel; } } diff --git a/remote/source/streamcontrolitem.cpp b/remote/source/streamcontrolitem.cpp index b7624df..fb518bf 100644 --- a/remote/source/streamcontrolitem.cpp +++ b/remote/source/streamcontrolitem.cpp @@ -19,6 +19,9 @@ void StreamControlItem::set_control(XinemaControlItem *c) connect(&xc, &XinemaControl::title_changed, this, &StreamControlItem::title_changed); connect(&xc, &XinemaControl::duration_changed, this, &StreamControlItem::duration_changed); connect(&xc, &XinemaControl::position_changed, this, &StreamControlItem::position_changed); + connect(&xc, &XinemaControl::channels_changed, this, &StreamControlItem::control_channels_changed); + connect(&xc, &XinemaControl::current_audio_channel_changed, this, &StreamControlItem::current_audio_channel_changed); + connect(&xc, &XinemaControl::current_spu_channel_changed, this, &StreamControlItem::current_spu_channel_changed); } emit control_changed(); @@ -29,6 +32,9 @@ void StreamControlItem::set_control(XinemaControlItem *c) emit title_changed(); emit duration_changed(); emit position_changed(); + emit channels_changed(); + emit current_audio_channel_changed(); + emit current_spu_channel_changed(); } } @@ -83,3 +89,54 @@ float StreamControlItem::get_position() const return control->get_control().get_position(); } + +QStringList StreamControlItem::get_audio_channels() const +{ + if(!control) + return QStringList(); + + return control->get_control().get_audio_channels(); +} + +QStringList StreamControlItem::get_spu_channels() const +{ + if(!control) + return QStringList(); + + return control->get_control().get_spu_channels(); +} + +void StreamControlItem::select_audio_channel(int chan) +{ + if(control) + control->get_control().select_audio_channel(chan); +} + +void StreamControlItem::select_spu_channel(int chan) +{ + if(control) + control->get_control().select_spu_channel(chan); +} + +int StreamControlItem::get_current_audio_channel() const +{ + if(!control) + return -1; + + return control->get_control().get_current_audio_channel(); +} + +int StreamControlItem::get_current_spu_channel() const +{ + if(!control) + return -1; + + return control->get_control().get_current_spu_channel(); +} + +void StreamControlItem::control_channels_changed() +{ + emit channels_changed(); + emit current_audio_channel_changed(); + emit current_spu_channel_changed(); +} diff --git a/remote/source/streamcontrolitem.h b/remote/source/streamcontrolitem.h index cb08836..8bb2cce 100644 --- a/remote/source/streamcontrolitem.h +++ b/remote/source/streamcontrolitem.h @@ -15,6 +15,10 @@ class StreamControlItem: public QQuickItem Q_PROPERTY(QString title READ get_title NOTIFY title_changed) Q_PROPERTY(float duration READ get_duration NOTIFY duration_changed) Q_PROPERTY(float position READ get_position WRITE set_position NOTIFY position_changed) + Q_PROPERTY(QStringList audioChannels READ get_audio_channels NOTIFY channels_changed) + Q_PROPERTY(QStringList spuChannels READ get_spu_channels NOTIFY channels_changed) + Q_PROPERTY(int currentAudioChannel READ get_current_audio_channel WRITE select_audio_channel NOTIFY current_audio_channel_changed) + Q_PROPERTY(int currentSpuChannel READ get_current_spu_channel WRITE select_spu_channel NOTIFY current_spu_channel_changed) Q_ENUMS(PlaybackState) @@ -41,6 +45,12 @@ public: float get_duration() const; void set_position(float); float get_position() const; + QStringList get_audio_channels() const; + QStringList get_spu_channels() const; + void select_audio_channel(int); + void select_spu_channel(int); + int get_current_audio_channel() const; + int get_current_spu_channel() const; signals: void control_changed(); @@ -48,6 +58,12 @@ signals: void title_changed(); void duration_changed(); void position_changed(); + void channels_changed(); + void current_audio_channel_changed(); + void current_spu_channel_changed(); + +private slots: + void control_channels_changed(); }; #endif diff --git a/remote/source/xinemacontrol.cpp b/remote/source/xinemacontrol.cpp index f793e3b..eb2ec47 100644 --- a/remote/source/xinemacontrol.cpp +++ b/remote/source/xinemacontrol.cpp @@ -3,7 +3,9 @@ XinemaControl::XinemaControl(): playback_state(STOPPED), duration(0.0f), - position(0.0f) + position(0.0f), + current_audio_channel(-1), + current_spu_channel(-1) { QObject::connect(&socket, &QAbstractSocket::connected, this, &XinemaControl::connected); QObject::connect(&socket, &QAbstractSocket::disconnected, this, &XinemaControl::disconnected); @@ -56,6 +58,22 @@ void XinemaControl::stop() send_request("stop"); } +void XinemaControl::select_audio_channel(int chan) +{ + if(chan<0) + send_request("select_audio off"); + else + send_request(QString("select_audio %1").arg(chan)); +} + +void XinemaControl::select_spu_channel(int chan) +{ + if(chan<0) + send_request("select_spu off"); + else + send_request(QString("select_spu %1").arg(chan)); +} + void XinemaControl::send_request(const QString &req) { socket.write(req.toUtf8()); @@ -129,4 +147,46 @@ void XinemaControl::process_reply(const QString &reply) position = args.toFloat(); emit position_changed(position); } + else if(keyword=="audio_count") + resize_list(audio_channels, args.toInt()); + else if(keyword=="audio") + { + space = args.indexOf(' '); + audio_channels[args.mid(0, space).toInt()] = args.mid(space+1); + } + else if(keyword=="spu_count") + resize_list(spu_channels, args.toInt()); + else if(keyword=="spu") + { + space = args.indexOf(' '); + spu_channels[args.mid(0, space).toInt()] = args.mid(space+1); + } + else if(keyword=="channels_end") + emit channels_changed(); + else if(keyword=="current_audio") + { + current_audio_channel = convert_channel(args); + emit current_audio_channel_changed(current_audio_channel); + } + else if(keyword=="current_spu") + { + current_spu_channel = convert_channel(args); + emit current_spu_channel_changed(current_spu_channel); + } +} + +int XinemaControl::convert_channel(const QString &arg) +{ + if(arg=="off") + return OFF; + else + return arg.toInt(); +} + +void XinemaControl::resize_list(QStringList &list, int size) +{ + while(list.size()>size) + list.removeLast(); + while(list.size()