]> git.vomp.tv Git - vompclient.git/blob - vremoteconfig.cc
Display channel name, duration, resume point and size on recording info screen
[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 void VRemoteConfig::doSave()
163 {
164   Message* m = new Message();
165   m->message = Message::CHANGED_REMOTECONTROL;
166   m->to = parent;
167   m->parameter = 0;
168   Command::getInstance()->postMessageNoLock(m);
169 }
170
171 int VRemoteConfig::handleCommand(int command)
172 {
173   if (learnmode)
174   {
175     learnmode = false;
176     if (command == Remote::NA_LEARN)
177     {
178       initSelectList(false);
179     }
180     draw();
181     viewman->updateView(this);
182     return 2;
183   }
184   switch(command)
185   {
186     case Remote::DF_UP:
187     case Remote::UP:
188     {
189       if (sl.getCurrentOption() != 0)
190       {
191         sl.up();
192         sl.setShowSelOption(true);
193         draw();
194         viewman->updateView(this);
195         return 2;
196       }
197       else
198       {
199         sl.setShowSelOption(false);
200         return 0; //Control to tab control
201       }
202     }
203     case Remote::DF_DOWN:
204     case Remote::DOWN:
205     {
206       sl.down();
207       sl.setShowSelOption(true);
208       draw();
209       viewman->updateView(this);
210       return 2;
211     }
212     case Remote::SKIPBACK:
213     {
214       sl.pageUp();
215       sl.draw();
216
217       
218       viewman->updateView(this);
219       return 2;
220     }
221     case Remote::SKIPFORWARD:
222     {
223       sl.pageDown();
224       sl.draw();
225
226       
227       viewman->updateView(this);
228       return 2;
229     }
230     case Remote::OK:
231     {
232       learnmode = true;
233       draw();
234       remote->EnterLearningMode(sl.getCurrentOptionData());
235       viewman->updateView(this);
236       return 2;
237     }
238     case Remote::BACK:
239     {
240       doSave();
241
242       // Instead of returning 4 here which would delete this view
243       // before the doSave message is processed, let the message queue
244       // do the doSave then this close message. That will make the options menu
245       // disappear before this view
246
247       Message* m = new Message();
248       m->message = Message::CLOSE_ME;
249       m->from = this;
250       m->to = viewman;
251       Command::getInstance()->postMessageNoLock(m);
252       return 2;
253       
254     }
255     case Remote::MENU:
256         {
257             remote->ResetToDefault();
258             initSelectList(false);
259             draw();
260             viewman->updateView(this);
261             return 2;
262         }
263
264     
265   }
266   // stop command getting to any more views
267   return 1;
268 }
269
270