]> git.vomp.tv Git - vompclient.git/blob - vchannelselect.cc
Display channel name, duration, resume point and size on recording info screen
[vompclient.git] / vchannelselect.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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #include "vchannelselect.h"
22
23 #include "remote.h"
24 #include "message.h"
25 #include "boxstack.h"
26 #include "colour.h"
27 #include "log.h"
28 #include "timers.h"
29 #include "command.h"
30 #include "vdr.h"
31
32 // this class only works as it does because the remote command
33 // values for the numbers are the numbers themselves !
34
35 VChannelSelect::VChannelSelect(Boxx* v)
36 {
37   parent = v;
38   numGot = 0;
39   ignoreTimer = false;
40
41   numWidth = (int)VDR::getInstance()->getChannelNumberWidth();
42   if (numWidth > 10) numWidth = 10;
43   for (int i = 0; i < numWidth; i++) input[i] = -1;
44
45   setSize((numWidth*10) + 22, 30); // 10 px = width of number chars in font
46   createBuffer();
47   setPosition(80, 60);
48   setBackgroundColour(DrawStyle::VIEWBACKGROUND);
49 }
50
51 VChannelSelect::~VChannelSelect()
52 {
53   Timers::getInstance()->cancelTimer(this, 1);
54 }
55
56 void VChannelSelect::timercall(int clientReference)
57 {
58   Log::getInstance()->log("VChannelSelect", Log::DEBUG, "Timer call");
59   if (ignoreTimer) return;
60   changeChannel(false);
61 }
62
63 void VChannelSelect::doInput(int number)
64 {
65   for (int i = numGot - 1; i >= 0; i--)
66   {
67     input[i+1] = input[i];
68   }
69
70   input[0] = number;
71   numGot++;
72 }
73
74 void VChannelSelect::draw()
75 {
76   Boxx::draw();
77
78   // draw numbers
79   char text[2];
80
81   for (int i = 0; i < numWidth; i++)
82   {
83     if (input[i] == -1)
84     {
85       drawText("_", 7 + ((numWidth - 1 - i) * 10), 5, DrawStyle::LIGHTTEXT);
86     }
87     else
88     {
89       sprintf(text, "%i", input[i]);
90       drawText(text, 7 + ((numWidth - 1 - i) * 10), 5, DrawStyle::LIGHTTEXT);
91     }
92   }
93 }
94
95 void VChannelSelect::changeChannel(bool which)
96 {
97   ignoreTimer = true;
98   Timers::getInstance()->cancelTimer(this, 1);
99
100   Message* m;
101
102   // Is there valid data? (is any number not-zero)
103   int i = 0;
104   for(i = 0; i < numWidth; i++) if (input[i]) break;
105
106   if (i < numWidth) // There is data
107   {
108     m = new Message();
109     m->from = this;
110     m->to = parent;
111     m->message = Message::CHANNEL_CHANGE;
112     m->parameter.num = 0;
113
114     for(i = numGot - 1; i >= 0; i--)
115     {
116       m->parameter.num += input[i] * (ULONG)pow(10., i);
117     }
118
119     if (which)
120       Command::getInstance()->postMessageNoLock(m);
121     else
122       Command::getInstance()->postMessageFromOuterSpace(m);
123   }
124
125   // Close me
126   m = new Message(); // Delete self
127   m->from = this;
128   m->to = BoxStack::getInstance();
129   m->message = Message::CLOSE_ME;
130   if (which)
131     Command::getInstance()->postMessageNoLock(m);
132   else
133     Command::getInstance()->postMessageFromOuterSpace(m);
134 }
135
136 int VChannelSelect::handleCommand(int command)
137 {
138   switch(command)
139   {
140     case Remote::ZERO:
141     case Remote::ONE:
142     case Remote::TWO:
143     case Remote::THREE:
144     case Remote::FOUR:
145     case Remote::FIVE:
146     case Remote::SIX:
147     case Remote::SEVEN:
148     case Remote::EIGHT:
149     case Remote::NINE:
150     {
151       doInput(command);
152       draw();
153       BoxStack::getInstance()->update(this);
154       if (numGot == numWidth) changeChannel(true);
155       else Timers::getInstance()->setTimerD(this, 1, 3);
156       return 2;
157     }
158     case Remote::OK:
159     {
160       changeChannel(true);
161       return 2;
162     }
163   }
164
165   // allow command to drop through to other views
166   return 0;
167 }