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