]> git.tdb.fi Git - xinema.git/blob - remote/source/streamcontrolitem.cpp
Implement seeking and play/pause controls in the remote
[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         }
23
24         emit control_changed();
25
26         if(control)
27         {
28                 emit playback_state_changed();
29                 emit title_changed();
30                 emit duration_changed();
31                 emit position_changed();
32         }
33 }
34
35 StreamControlItem::PlaybackState StreamControlItem::get_playback_state() const
36 {
37         if(!control)
38                 return Stopped;
39
40         return static_cast<PlaybackState>(control->get_control().get_playback_state());
41 }
42
43 void StreamControlItem::set_playback_state(PlaybackState state)
44 {
45         if(!control)
46                 return;
47
48         XinemaControl &xc = control->get_control();
49         if(state==Stopped)
50                 xc.stop();
51         else if(state==Paused)
52                 xc.pause();
53         else if(state==Playing)
54                 xc.play();
55 }
56
57 QString StreamControlItem::get_title() const
58 {
59         if(!control)
60                 return QString();
61
62         return control->get_control().get_title();
63 }
64
65 float StreamControlItem::get_duration() const
66 {
67         if(!control)
68                 return 0;
69
70         return control->get_control().get_duration();
71 }
72
73 void StreamControlItem::set_position(float pos)
74 {
75         if(control)
76                 control->get_control().seek(pos);
77 }
78
79 float StreamControlItem::get_position() const
80 {
81         if(!control)
82                 return 0;
83
84         return control->get_control().get_position();
85 }