]> git.vomp.tv Git - vompclient.git/blob - vremoteconfig.cc
Minor fixes
[vompclient.git] / vremoteconfig.cc
1 /*
2     Copyright 2004-2007 Chris Tallon, Marten Richter
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 "vremoteconfig.h"
22
23 VRemoteConfig::VRemoteConfig(void* tparent)
24 {
25   parent = tparent;
26   viewman = ViewMan::getInstance();
27   remote = Remote::getInstance();
28   learnmode = false;
29  
30
31   create(530, 320);
32   if (Video::getInstance()->getFormat() == Video::PAL)
33   {
34     setScreenPos(80, 70);
35   }
36   else
37   {
38     setScreenPos(70, 35);
39   }
40
41   setBackgroundColour(Colour::VIEWBACKGROUND);
42   setTitleBarOn(1);
43   setTitleBarColour(Colour::TITLEBARBACKGROUND);
44   setTitleText(tr("Remote control"));
45
46   
47  
48   initSelectList(true);
49   sl.setShowSelOption(false);
50   
51
52
53 }
54
55 VRemoteConfig::~VRemoteConfig()
56 {
57   
58 }
59
60 void VRemoteConfig::initSelectList(bool startup)
61 {
62     ULONG selection=0;
63     ULONG top=0;
64     if (!startup)
65     {
66         selection=sl.getCurrentOption();
67         top=sl.getTopOption();
68         
69     }
70     sl.setSurface(surface);
71     sl.setSurfaceOffset(10,  40);
72     sl.setDimensions(area.w - 20, area.h - 30 - 15 -30 );
73     sl.clear();
74     sl.addColumn(0);
75     sl.addColumn(150);
76     sl.addColumn(300);
77     ULONG i;
78     for (i = 0; i < 256;i++)
79     {
80       const char * name = remote->CommandDesc((UCHAR)i);
81       if (name != NULL)
82       {
83           char *line = remote->CommandTranslateStr((UCHAR)i);
84       //    char * desc=new char [strlen(line)+1];    // CJT memory leak and unneccessary?
85       //    strcpy(desc,line);
86           sl.addOption(line,i,0);
87       }
88     }
89     if (!startup)
90     {
91         sl.hintSetCurrent(selection);
92         sl.hintSetTop(top);
93     }
94 }
95
96
97 void VRemoteConfig::draw()
98 {
99   View::draw();
100   
101   drawText(tr("Command"), 15, 15, Colour::LIGHTTEXT);
102   drawText(tr("Hard wired"), 165, 15, Colour::LIGHTTEXT);
103   drawText(tr("User assignable"), 315, 15, Colour::LIGHTTEXT);
104   sl.draw();
105   if (learnmode)
106   {
107       drawText(tr("Learning! Press any hardwired key to exit!"), 15, area.h - 30, Colour::SELECTHIGHLIGHT);
108   }
109   else
110   {
111       drawText(tr("Press [ok] for learning or MENU to reset to defaults! "), 15, area.h - 30, Colour::LIGHTTEXT);
112   }
113
114   
115
116   
117 }
118
119
120 void VRemoteConfig::processMessage(Message* m)
121 {
122   Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
123
124   if (m->message == Message::MOUSE_MOVE)
125   {
126     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
127     {
128       sl.setShowSelOption(true);
129       sl.draw();
130       viewman->updateView(this);
131     }
132   }
133   else if (m->message == Message::MOUSE_LBDOWN)
134   {
135     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
136     {
137       ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
138     }
139     else
140     {
141       //check if press is outside this view! then simulate cancel
142       int x=(m->parameter>>16)-getScreenX();
143       int y=(m->parameter&0xFFFF)-getScreenY();
144       if (x<0 || y <0 || x>getWidth() || y>getHeight())
145       {
146         ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
147       }
148     }
149   }
150   
151 }
152
153
154 void VRemoteConfig::doSave()
155 {
156     Message* m = new Message();
157     m->message = Message::CHANGED_REMOTECONTROL;
158     m->to = parent;
159     m->parameter = 0;
160     Command::getInstance()->postMessageNoLock(m);
161     
162 }
163
164
165 int VRemoteConfig::handleCommand(int command)
166 {
167   if (learnmode)
168   {
169       learnmode = false;
170       if (command == Remote::NA_LEARN)
171       {
172           initSelectList(false);
173       }
174       draw();
175       viewman->updateView(this);
176       return 2;
177   }
178   switch(command)
179   {
180     case Remote::DF_UP:
181     case Remote::UP:
182     {
183       if (sl.getCurrentOption() != 0)
184       {
185           sl.up();
186           sl.setShowSelOption(true);
187           draw();
188           viewman->updateView(this);
189           return 2;
190       }
191       else
192       {
193           sl.setShowSelOption(false);
194           return 0; //Control to tab control
195       }
196     }
197     case Remote::DF_DOWN:
198     case Remote::DOWN:
199     {
200       Log::getInstance()->log("P", Log::DEBUG, "1");
201       sl.down();
202       sl.setShowSelOption(true);
203       Log::getInstance()->log("P", Log::DEBUG, "1.5");
204       draw();
205       Log::getInstance()->log("P", Log::DEBUG, "2");
206
207       
208       Log::getInstance()->log("P", Log::DEBUG, "3");
209       viewman->updateView(this);
210       Log::getInstance()->log("P", Log::DEBUG, "4");
211       return 2;
212     }
213     case Remote::SKIPBACK:
214     {
215       sl.pageUp();
216       sl.draw();
217
218       
219       viewman->updateView(this);
220       return 2;
221     }
222     case Remote::SKIPFORWARD:
223     {
224       sl.pageDown();
225       sl.draw();
226
227       
228       viewman->updateView(this);
229       return 2;
230     }
231     case Remote::OK:
232     {
233       learnmode = true;
234       draw();
235       remote->EnterLearningMode(sl.getCurrentOptionData());
236       viewman->updateView(this);
237       return 2;
238     }
239     case Remote::BACK:
240     {
241       doSave();
242
243       // Instead of returning 4 here which would delete this view
244       // before the doSave message is processed, let the message queue
245       // do the doSave then this close message. That will make the options menu
246       // disappear before this view
247
248       Message* m = new Message();
249       m->message = Message::CLOSE_ME;
250       m->from = this;
251       m->to = viewman;
252       Command::getInstance()->postMessageNoLock(m);
253       return 2;
254       
255     }
256     case Remote::MENU:
257         {
258             remote->ResetToDefault();
259             initSelectList(false);
260             draw();
261             viewman->updateView(this);
262             return 2;
263         }
264
265     
266   }
267   // stop command getting to any more views
268   return 1;
269 }
270
271