]> git.tdb.fi Git - xinema.git/blob - remote/source/streamcontrolitem.cpp
fb518bf0ab8fd102a645edcac30d42d0160b156b
[xinema.git] / remote / source / streamcontrolitem.cpp
1 #include "streamcontrolitem.h"
2 #include "xinemacontrolitem.h"
3
4 StreamControlItem::StreamControlItem():
5         control(0)
6 {
7 }
8
9 void StreamControlItem::set_control(XinemaControlItem *c)
10 {
11         if(control)
12                 disconnect(control, 0, this, 0);
13
14         control = c;
15         if(control)
16         {
17                 XinemaControl &xc = control->get_control();
18                 connect(&xc, &XinemaControl::playback_state_changed, this, &StreamControlItem::playback_state_changed);
19                 connect(&xc, &XinemaControl::title_changed, this, &StreamControlItem::title_changed);
20                 connect(&xc, &XinemaControl::duration_changed, this, &StreamControlItem::duration_changed);
21                 connect(&xc, &XinemaControl::position_changed, this, &StreamControlItem::position_changed);
22                 connect(&xc, &XinemaControl::channels_changed, this, &StreamControlItem::control_channels_changed);
23                 connect(&xc, &XinemaControl::current_audio_channel_changed, this, &StreamControlItem::current_audio_channel_changed);
24                 connect(&xc, &XinemaControl::current_spu_channel_changed, this, &StreamControlItem::current_spu_channel_changed);
25         }
26
27         emit control_changed();
28
29         if(control)
30         {
31                 emit playback_state_changed();
32                 emit title_changed();
33                 emit duration_changed();
34                 emit position_changed();
35                 emit channels_changed();
36                 emit current_audio_channel_changed();
37                 emit current_spu_channel_changed();
38         }
39 }
40
41 StreamControlItem::PlaybackState StreamControlItem::get_playback_state() const
42 {
43         if(!control)
44                 return Stopped;
45
46         return static_cast<PlaybackState>(control->get_control().get_playback_state());
47 }
48
49 void StreamControlItem::set_playback_state(PlaybackState state)
50 {
51         if(!control)
52                 return;
53
54         XinemaControl &xc = control->get_control();
55         if(state==Stopped)
56                 xc.stop();
57         else if(state==Paused)
58                 xc.pause();
59         else if(state==Playing)
60                 xc.play();
61 }
62
63 QString StreamControlItem::get_title() const
64 {
65         if(!control)
66                 return QString();
67
68         return control->get_control().get_title();
69 }
70
71 float StreamControlItem::get_duration() const
72 {
73         if(!control)
74                 return 0;
75
76         return control->get_control().get_duration();
77 }
78
79 void StreamControlItem::set_position(float pos)
80 {
81         if(control)
82                 control->get_control().seek(pos);
83 }
84
85 float StreamControlItem::get_position() const
86 {
87         if(!control)
88                 return 0;
89
90         return control->get_control().get_position();
91 }
92
93 QStringList StreamControlItem::get_audio_channels() const
94 {
95         if(!control)
96                 return QStringList();
97
98         return control->get_control().get_audio_channels();
99 }
100
101 QStringList StreamControlItem::get_spu_channels() const
102 {
103         if(!control)
104                 return QStringList();
105
106         return control->get_control().get_spu_channels();
107 }
108
109 void StreamControlItem::select_audio_channel(int chan)
110 {
111         if(control)
112                 control->get_control().select_audio_channel(chan);
113 }
114
115 void StreamControlItem::select_spu_channel(int chan)
116 {
117         if(control)
118                 control->get_control().select_spu_channel(chan);
119 }
120
121 int StreamControlItem::get_current_audio_channel() const
122 {
123         if(!control)
124                 return -1;
125
126         return control->get_control().get_current_audio_channel();
127 }
128
129 int StreamControlItem::get_current_spu_channel() const
130 {
131         if(!control)
132                 return -1;
133
134         return control->get_control().get_current_spu_channel();
135 }
136
137 void StreamControlItem::control_channels_changed()
138 {
139         emit channels_changed();
140         emit current_audio_channel_changed();
141         emit current_spu_channel_changed();
142 }