--- /dev/null
+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()
+ }
+}
--- /dev/null
+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);
+ }
+ }
+ }
+ }
+ }
+ }
+}
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
if(!slider.down)
slider.value = position;
}
+ onCurrentAudioChannelChanged: audioSelect.currentChannel = streamControl.currentAudioChannel;
+ onCurrentSpuChannelChanged: spuSelect.currentChannel = streamControl.currentSpuChannel;
}
}
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();
emit title_changed();
emit duration_changed();
emit position_changed();
+ emit channels_changed();
+ emit current_audio_channel_changed();
+ emit current_spu_channel_changed();
}
}
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();
+}
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)
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();
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
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);
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());
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());
}
PLAYING
};
+ enum
+ {
+ OFF = -1
+ };
+
private:
QTcpSocket socket;
QByteArray buffer;
QString title;
float duration;
float position;
+ QStringList audio_channels;
+ QStringList spu_channels;
+ int current_audio_channel;
+ int current_spu_channel;
public:
XinemaControl();
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();
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 &);
private slots:
void data_available();
void process_reply(const QString &);
+ static int convert_channel(const QString &);
+ static void resize_list(QStringList &, int);
};
#endif