]> git.vomp.tv Git - vompclient.git/blob - vchannelselect.cc
Connection failed detection
[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       ViewMan::getInstance()->updateView(this);
115
116       if (numGot == 3)
117       {
118         // Is there valid data?
119         if ((first > 0) || (second > 0) || (third > 0))
120         {
121           Message* m = new Message();
122           m->from = this;
123           m->to = videoLive;
124           m->message = Message::CHANNEL_CHANGE;
125           m->parameter = (first * 100) + (second * 10) + third;
126           ViewMan::getInstance()->postMessage(m);
127         }
128
129         return 4;
130       }
131
132       return 2;
133     }
134   }
135
136   // allow command to drop through to other views
137   return 0;
138 }
139
140 void VChannelSelect::timercall(int clientReference)
141 {
142   Log::getInstance()->log("VChannelSelect", Log::DEBUG, "Timer call");
143
144   // Close me
145   Message* m = new Message(); // Delete self
146   m->from = this;
147   m->to = ViewMan::getInstance();
148   m->message = Message::CLOSE_ME;
149   ViewMan::getInstance()->postMessage(m);
150
151   // Is there valid data?
152   if ((first > 0) || (second > 0) || (third > 0))
153   {
154     // Change channel
155
156     ULONG newChannel = 0;
157     switch(numGot)
158     {
159       case 3:
160         newChannel += first * 100;
161       case 2:
162         newChannel += second * 10;
163       case 1:
164         newChannel += third;
165     }
166
167     m = new Message(); // Must be done after this view deleted
168     m->from = this;
169     m->to = videoLive;
170     m->message = Message::CHANNEL_CHANGE;
171     m->parameter = newChannel;
172     ViewMan::getInstance()->postMessage(m);
173   }
174 }