]> git.vomp.tv Git - vompclient.git/blob - vradiolive.cc
Zero length recording segfault fixed
[vompclient.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(ChannelList* tchanList)
24 {
25   player = new PlayerRadio();
26   player->init();
27   vdr = VDR::getInstance();
28   chanList = tchanList;
29   currentChannel = 0;
30
31   create(100, 100);
32   setBackgroundColour(Colour::VIEWBACKGROUND);
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::DF_UP:
58     case Remote::UP:
59     {
60       player->stop();
61       vdr->stopStreaming();
62       upChannel();
63       vdr->streamChannel((*chanList)[currentChannel]->number);
64       player->play();
65       return 2;
66     }
67     case Remote::DF_DOWN:
68     case Remote::DOWN:
69     {
70       player->stop();
71       vdr->stopStreaming();
72       downChannel();
73       vdr->streamChannel((*chanList)[currentChannel]->number);
74       player->play();
75       return 2;
76     }
77   }
78
79   return 1;
80 }
81
82 void VRadioLive::setChannel(UINT number)
83 {
84   currentChannel = channelIndexFromNumber(number);
85   vdr->streamChannel((*chanList)[currentChannel]->number);
86   player->play();
87 }
88
89 void VRadioLive::upChannel()
90 {
91   if (currentChannel == (chanList->size() - 1)) return; // at the end
92
93   ++currentChannel;
94 }
95
96 void VRadioLive::downChannel()
97 {
98   if (currentChannel == 0) return; // at the start
99
100   --currentChannel;
101 }
102
103 UINT VRadioLive::channelIndexFromNumber(int number)
104 {
105   for(UINT i = 0; i < chanList->size(); i++)
106   {
107     if ((*chanList)[i]->number == (UINT)number) return i;
108   }
109   return 0;
110 }
111