]> git.vomp.tv Git - vompclient-marten.git/blob - vradiolive.cc
Initial import
[vompclient-marten.git] / vradiolive.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "vradiolive.h"
22
23 VRadioLive::VRadioLive(List* tchanList)
24 {
25   player = new PlayerRadio();
26   player->init();
27   vdr = VDR::getInstance();
28   chanList = tchanList;
29   currentChannel = 0;
30
31   setDimensions(100, 100);
32   setBackgroundColour(0, 0, 0, 255);
33 }
34
35 VRadioLive::~VRadioLive()
36 {
37   delete player;
38 }
39
40 void VRadioLive::draw()
41 {
42   View::draw();
43 }
44
45 int VRadioLive::handleCommand(int command)
46 {
47   switch(command)
48   {
49     case Remote::STOP:
50     case Remote::BACK:
51     case Remote::MENU:
52     {
53       player->stop();
54       vdr->stopStreaming();
55       return 4;
56     }
57     case Remote::UP:
58     {
59       player->stop();
60       vdr->stopStreaming();
61       upChannel();
62       vdr->streamChannel(currentChannel);
63       player->play();
64       return 2;
65     }
66     case Remote::DOWN:
67     {
68       player->stop();
69       vdr->stopStreaming();
70       downChannel();
71       vdr->streamChannel(currentChannel);
72       player->play();
73       return 2;
74     }
75   }
76
77   return 1;
78 }
79
80 void VRadioLive::setChannel(int number)
81 {
82   currentChannel = number;
83   vdr->streamChannel(currentChannel);
84   player->play();
85 }
86
87 void VRadioLive::upChannel()
88 {
89   Channel* channel;
90   for(chanList->reset(); (channel = (Channel*)chanList->getCurrent()); chanList->next())
91   {
92     if (channel->number == currentChannel)
93     {
94       chanList->next();
95       channel = (Channel*)chanList->getCurrent();
96       if (!channel) return;
97       currentChannel = channel->number;
98     }
99   }
100 }
101
102 void VRadioLive::downChannel()
103 {
104   Channel* channel;
105   Channel* prevChannel = NULL;
106   for(chanList->reset(); (channel = (Channel*)chanList->getCurrent()); chanList->next())
107   {
108     if (channel->number == currentChannel)
109     {
110       if (!prevChannel) return;
111       currentChannel = prevChannel->number;
112     }
113     prevChannel = channel;
114   }
115 }