]> git.tdb.fi Git - xinema.git/commitdiff
Add channel selection controls in the remote
authorMikko Rasa <tdb@tdb.fi>
Sat, 17 Oct 2015 13:58:47 +0000 (16:58 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 17 Oct 2015 13:58:47 +0000 (16:58 +0300)
remote/qml/pages/ChannelItem.qml [new file with mode: 0644]
remote/qml/pages/ChannelSelect.qml [new file with mode: 0644]
remote/qml/pages/PlaybackPage.qml
remote/source/streamcontrolitem.cpp
remote/source/streamcontrolitem.h
remote/source/xinemacontrol.cpp
remote/source/xinemacontrol.h

diff --git a/remote/qml/pages/ChannelItem.qml b/remote/qml/pages/ChannelItem.qml
new file mode 100644 (file)
index 0000000..714e707
--- /dev/null
@@ -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 (file)
index 0000000..43c6cf7
--- /dev/null
@@ -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);
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+}
index 24817c697e6a4a5cef40bb96d3cf3e11a9bbe9ff..7bf7cc9069ab1f923659b6036070229a50ec83db 100644 (file)
@@ -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;
        }
 }
index b7624df813d6c5f45cbe24cf99171fdeb84320f5..fb518bf0ab8fd102a645edcac30d42d0160b156b 100644 (file)
@@ -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();
+}
index cb08836c69ca0a21327832057069202b5405020d..8bb2ccee397a19f0ed4ec16755cf66d7d9a8d8a8 100644 (file)
@@ -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
index f793e3bb0f1a271fcb69e119fc4692d29ae75b1c..eb2ec47e5706b0a67016491cedde811468c31ede 100644 (file)
@@ -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()<size)
+               list.append(QString());
 }
index 5693554836b88f7e0639810ea57f08f272affe7d..573207365c27b2dcfcbd0422620f176bd688faba 100644 (file)
@@ -16,6 +16,11 @@ public:
                PLAYING
        };
 
+       enum
+       {
+               OFF = -1
+       };
+
 private:
        QTcpSocket socket;
        QByteArray buffer;
@@ -23,6 +28,10 @@ private:
        QString title;
        float duration;
        float position;
+       QStringList audio_channels;
+       QStringList spu_channels;
+       int current_audio_channel;
+       int current_spu_channel;
 
 public:
        XinemaControl();
@@ -43,6 +52,13 @@ public:
        void pause();
        void stop();
 
+       const QStringList &get_audio_channels() const { return audio_channels; }
+       const QStringList &get_spu_channels() const { return spu_channels; }
+       void select_audio_channel(int);
+       void select_spu_channel(int);
+       int get_current_audio_channel() const { return current_audio_channel; }
+       int get_current_spu_channel() const { return current_spu_channel; }
+
 signals:
        void connected();
        void disconnected();
@@ -53,6 +69,9 @@ signals:
        void title_changed(const QString &);
        void duration_changed(float);
        void position_changed(float);
+       void channels_changed();
+       void current_audio_channel_changed(int);
+       void current_spu_channel_changed(int);
 
 private:
        void send_request(const QString &);
@@ -60,6 +79,8 @@ private:
 private slots:
        void data_available();
        void process_reply(const QString &);
+       static int convert_channel(const QString &);
+       static void resize_list(QStringList &, int);
 };
 
 #endif