- disabled gui for a moment
[vuplus_dvbapp] / lib / nav / core.cpp
1 #include <lib/nav/core.h>
2
3 void eNavigation::serviceEvent(iPlayableService* service, int event)
4 {
5         if (service != m_runningService)
6         {
7                 eDebug("nav: event for other service");
8                 return;
9         }
10
11         switch (event)
12         {
13         case iPlayableService::evEnd:
14                 assert(m_playlist); /* we need to have a playlist */
15                 
16                         /* at first, kill the running service */
17                 m_event(this, evStopService);
18                 m_runningService = 0;
19                 m_service_event_conn = 0;
20                         /* our running main service stopped. identify what to do next. */
21                         
22                         /* unless the playlist current position is invalid (because there was */
23                         /* playlist, for example when the service was engaged with playService */
24                 if (m_playlist->m_current != m_playlist->end())
25                         ++m_playlist->m_current;
26                         
27                         /* was the current service the last one? */
28                 if (m_playlist->m_current == m_playlist->end())
29                 {
30                         m_event(this, evPlaylistDone);
31                         break;
32                 }
33
34                         /* there is another service in the playlist. play it. */
35                 RESULT res;
36                 res = playService(*m_playlist->m_current);
37                 if (res)
38                         m_event(this, evPlayFailed);
39                 break;
40         case iPlayableService::evStart:
41                 m_event(this, evNewService);
42                 break;
43         default:
44                 break;
45         }
46 }
47
48 RESULT eNavigation::playService(const eServiceReference &service)
49 {
50         assert(m_servicehandler);
51         RESULT res = m_servicehandler->play(service, m_runningService);
52         if (m_runningService)
53         {
54                 m_runningService->connectEvent(slot(*this, &eNavigation::serviceEvent), m_service_event_conn);
55                 res = m_runningService->start();
56         }
57         return res;
58 }
59
60 RESULT eNavigation::enqueueService(const eServiceReference &service)
61 {
62         assert(m_playlist);
63                 /* check if we need to play after the service was enqueued. */
64         int doplay = m_playlist->m_current == m_playlist->end();
65         
66                 /* add the service to the playlist. the playlist's m_current */
67                 /* points either to a service before the last or 'doplay' is set. */
68         m_playlist->push_back(service);
69
70         if (doplay)
71         {
72                 m_playlist->m_current = m_playlist->end();
73                 --m_playlist->m_current;
74                 return playService(*m_playlist->m_current);
75         }
76         return 0;
77 }
78
79 RESULT eNavigation::connectEvent(const Slot2<void,eNavigation*,int> &event, ePtr<eConnection> &connection)
80 {
81         connection = new eConnection(this, m_event.connect(event));
82         return 0;
83 }
84
85 RESULT eNavigation::getCurrentService(ePtr<iPlayableService> &service)
86 {
87         service = m_runningService;
88         return 0;
89 }
90
91 RESULT eNavigation::getPlaylist(ePtr<ePlaylist> &playlist)
92 {
93         if (!m_playlist)
94                 return -1;
95         playlist = m_playlist;
96         return 0;
97 }
98
99 RESULT eNavigation::pause(int dop)
100 {
101         if (!m_runningService)
102                 return -1;
103         ePtr<iPauseableService> p;
104         if (m_runningService->getIPausableService(p))
105                 return -2;
106         if (dop)
107                 return p->pause();
108         else
109                 return p->unpause();
110 }
111
112 eNavigation::eNavigation(iServiceHandler *serviceHandler)
113 {
114         assert(serviceHandler);
115         m_servicehandler = serviceHandler;
116         m_playlist = new ePlaylist;
117
118                 /* start with no current selection */
119         m_playlist->m_current = m_playlist->end();
120 }
121
122 eNavigation::~eNavigation()
123 {
124 }
125
126 DEFINE_REF(eNavigation);