]> git.vomp.tv Git - vompclient.git/blob - vchannelselect.cc
Remove manual sync buttons
[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:
57     case 1:
58     case 2:
59     case 3:
60     case 4:
61     case 5:
62     case 6:
63     case 7:
64     case 8:
65     case 9:
66     {
67       sprintf(text, "%i", first);
68       drawText(text, 7, 5, Colour::LIGHTTEXT);
69       break;
70     }
71     case -1:
72     {
73       drawText("_", 7, 5, Colour::LIGHTTEXT);
74       break;
75     }
76   }
77
78   switch(second)
79   {
80     case 0:
81     case 1:
82     case 2:
83     case 3:
84     case 4:
85     case 5:
86     case 6:
87     case 7:
88     case 8:
89     case 9:
90     {
91       sprintf(text, "%i", second);
92       drawText(text, 20, 5, Colour::LIGHTTEXT);
93       break;
94     }
95     case -1:
96     {
97       drawText("_", 20, 5, Colour::LIGHTTEXT);
98       break;
99     }
100   }
101
102   switch(third)
103   {
104     case 0:
105     case 1:
106     case 2:
107     case 3:
108     case 4:
109     case 5:
110     case 6:
111     case 7:
112     case 8:
113     case 9:
114     {
115       sprintf(text, "%i", third);
116       drawText(text, 33, 5, Colour::LIGHTTEXT);
117       break;
118     }
119     case -1:
120     {
121       drawText("_", 33, 5, Colour::LIGHTTEXT);
122       break;
123     }
124   }
125
126   Timers::getInstance()->setTimerD(this, 1, 3);
127 }
128
129 int VChannelSelect::handleCommand(int command)
130 {
131   switch(command)
132   {
133     case Remote::ZERO:
134     case Remote::ONE:
135     case Remote::TWO:
136     case Remote::THREE:
137     case Remote::FOUR:
138     case Remote::FIVE:
139     case Remote::SIX:
140     case Remote::SEVEN:
141     case Remote::EIGHT:
142     case Remote::NINE:
143     {
144       if (numGot == 2) first = second;
145       second = third;
146       third = command;
147       ++numGot;
148
149       draw();
150       ViewMan::getInstance()->updateView(this);
151
152       if (numGot == 3)
153       {
154         // Is there valid data?
155         if ((first > 0) || (second > 0) || (third > 0))
156         {
157           Message* m = new Message();
158           m->from = this;
159           m->to = videoLive;
160           m->message = Message::CHANNEL_CHANGE;
161           m->parameter = (first * 100) + (second * 10) + third;
162           ViewMan::getInstance()->postMessage(m);
163         }
164
165         return 4;
166       }
167
168       return 2;
169     }
170   }
171
172   // allow command to drop through to other views
173   return 0;
174 }
175
176 void VChannelSelect::timercall(int clientReference)
177 {
178   Log::getInstance()->log("VChannelSelect", Log::DEBUG, "Timer call");
179
180   // Close me
181   Message* m = new Message(); // Delete self
182   m->from = this;
183   m->to = ViewMan::getInstance();
184   m->message = Message::CLOSE_ME;
185   ViewMan::getInstance()->postMessage(m);
186
187   // Is there valid data?
188   if ((first > 0) || (second > 0) || (third > 0))
189   {
190     // Change channel
191
192     ULONG newChannel = 0;
193     switch(numGot)
194     {
195       case 3:
196         newChannel += first * 100;
197       case 2:
198         newChannel += second * 10;
199       case 1:
200         newChannel += third;
201     }
202
203     m = new Message(); // Must be done after this view deleted
204     m->from = this;
205     m->to = videoLive;
206     m->message = Message::CHANNEL_CHANGE;
207     m->parameter = newChannel;
208     ViewMan::getInstance()->postMessage(m);
209   }
210 }