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