]> git.vomp.tv Git - vompclient.git/blob - vchannelselect.cc
Internationalise EPG, add timed input code to vchannelselect
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "vchannelselect.h"
22
23 // this class only works as it does because the remote command
24 // values for the numbers are the numbers themselves !
25
26 VChannelSelect::VChannelSelect(VVideoLive* v, int command)
27 {
28   create(53, 30);
29   setScreenPos(80, 60);
30
31   setBackgroundColour(Colour::VIEWBACKGROUND);
32
33   first = -1;
34   second = -1;
35   third = command;
36   numGot = 1;
37
38   videoLive = v;
39 }
40
41 VChannelSelect::~VChannelSelect()
42 {
43   Timers::getInstance()->cancelTimer(this, 1);
44 }
45
46 void VChannelSelect::draw()
47 {
48   View::draw();
49
50   // draw numbers
51
52   char text[2];
53
54   switch(first)
55   {
56     case 0 ... 9:
57     {
58       sprintf(text, "%i", first);
59       drawText(text, 7, 5, Colour::LIGHTTEXT);
60       break;
61     }
62     case -1:
63     {
64       drawText("_", 7, 5, Colour::LIGHTTEXT);
65       break;
66     }
67   }
68
69   switch(second)
70   {
71     case 0 ... 9:
72     {
73       sprintf(text, "%i", second);
74       drawText(text, 20, 5, Colour::LIGHTTEXT);
75       break;
76     }
77     case -1:
78     {
79       drawText("_", 20, 5, Colour::LIGHTTEXT);
80       break;
81     }
82   }
83
84   switch(third)
85   {
86     case 0 ... 9:
87     {
88       sprintf(text, "%i", third);
89       drawText(text, 33, 5, Colour::LIGHTTEXT);
90       break;
91     }
92     case -1:
93     {
94       drawText("_", 33, 5, Colour::LIGHTTEXT);
95       break;
96     }
97   }
98
99   Timers::getInstance()->setTimer(this, 1, (struct timespec){3, 0});
100 }
101
102 int VChannelSelect::handleCommand(int command)
103 {
104   switch(command)
105   {
106     case Remote::ZERO ... Remote::NINE:
107     {
108       if (numGot == 2) first = second;
109       second = third;
110       third = command;
111       ++numGot;
112
113       draw();
114       show();
115
116       if (numGot == 3)
117       {
118         Message* m = new Message();
119         m->from = this;
120         m->to = ViewMan::getInstance();
121         m->message = Message::CLOSE_ME;
122         ViewMan::getInstance()->postMessage(m);
123
124         // Is there valid data?
125         if ((first > 0) || (second > 0) || (third > 0))
126         {
127           m = new Message();
128           m->from = this;
129           m->to = videoLive;
130           m->message = Message::CHANNEL_CHANGE;
131           m->parameter = (first * 100) + (second * 10) + third;
132           ViewMan::getInstance()->postMessage(m);
133         }
134       }
135
136       return 2;
137     }
138   }
139
140   // allow command to drop through to other views
141   return 0;
142 }
143
144 void VChannelSelect::timercall(int clientReference)
145 {
146   Log::getInstance()->log("VChannelSelect", Log::DEBUG, "Timer call");
147
148   // Close me
149   Message* m = new Message();
150   m->from = this;
151   m->to = ViewMan::getInstance();
152   m->message = Message::CLOSE_ME;
153   ViewMan::getInstance()->postMessage(m);
154
155   // Is there valid data?
156   if ((first > 0) || (second > 0) || (third > 0))
157   {
158     // Change channel
159
160     ULONG newChannel = 0;
161     switch(numGot)
162     {
163       case 3:
164         newChannel += first * 100;
165       case 2:
166         newChannel += second * 10;
167       case 1:
168         newChannel += third;
169     }
170
171     m = new Message();
172     m->from = this;
173     m->to = videoLive;
174     m->message = Message::CHANNEL_CHANGE;
175     m->parameter = newChannel;
176     ViewMan::getInstance()->postMessage(m);
177   }
178 }