2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
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.
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.
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.
22 #include "wremoteconfig.h"
28 Remote* Remote::instance = NULL;
34 remoteType = OLDREMOTE;
35 learnmode = NOLEARNMODE;
43 Remote* Remote::getInstance()
48 void Remote::setRemoteType(UCHAR newType)
50 if ((newType != OLDREMOTE) && (newType != NEWREMOTE)) return;
54 void Remote::EnterLearningMode(UCHAR command)
56 learnmode = command; //Armed
59 void Remote::ResetToDefault()
62 InitHWCListwithDefaults();
66 UCHAR Remote::TranslateHWCFixed(ULLONG code)
97 const char*Remote::HardcodedTranslateStr(UCHAR command)
120 UCHAR Remote::TranslateHWCList(ULLONG code)
122 if (learnmode != NOLEARNMODE)
124 setHWCtoCommand(code, learnmode);
125 learnmode = NOLEARNMODE;
128 RemoteTranslationList::iterator it = translist.find(code);
129 if (it == translist.end())
139 UCHAR Remote::TranslateHWC(ULLONG code)
141 UCHAR ret = TranslateHWCFixed(code);
142 if (ret == NA_UNKNOWN)
144 ret = TranslateHWCList(code);
148 learnmode = NOLEARNMODE;
151 if (ret == NA_UNKNOWN)
158 void Remote::setHWCtoCommand(ULLONG hcw, UCHAR command)
160 translist[hcw] = command;
163 void Remote::unsetHWC(ULLONG hcw)
165 translist.erase(hcw);
168 void Remote::LoadKeysConfig(char *cfg)
171 start = strchr(cfg,'H')+1;
172 while ((start-1) != NULL)
176 if (sscanf(start,"%lXI%lXK%lX",&ul1,&ul2,&uc) == 3)
178 translist[((ULLONG) ul1) | ((ULLONG)ul2) << 32]=(UCHAR)uc;
180 start = strchr(start, 'H')+1;
184 char *Remote::SaveKeysConfig()
186 int length=21*translist.size() +1;
187 char *output=new char[length];
188 char *current=output;
189 RemoteTranslationList::const_iterator it;
190 for (it = translist.begin(); it != translist.end(); it++)
192 current+=sprintf(current,"H%08lXI%08lXK%02X",
193 (ULONG)it->first ,(ULONG) (it->first >> 32), it->second);
199 void Remote::InitHWCListwithDefaults()
201 translist[VOLUMEUP] = VOLUMEUP;
202 translist[VOLUMEDOWN] = VOLUMEDOWN;
203 translist[CHANNELUP] = CHANNELUP;
204 translist[CHANNELDOWN] = CHANNELDOWN;
207 translist[ZERO] = ZERO;
208 translist[ONE] = ONE;
209 translist[TWO] = TWO;
210 translist[THREE] = THREE;
211 translist[FOUR] = FOUR;
212 translist[FIVE] = FIVE;
213 translist[SIX] = SIX;
214 translist[SEVEN] = SEVEN;
215 translist[EIGHT] = EIGHT;
216 translist[NINE] = NINE;
217 translist[POWER] = POWER;
219 translist[RED] = RED;
220 translist[GREEN] = GREEN;
221 translist[YELLOW] = YELLOW;
222 translist[BLUE] = BLUE;
224 translist[MUTE] = MUTE;
225 translist[RADIO] = RADIO;
226 translist[REVERSE] = REVERSE;
227 translist[FORWARD] = FORWARD;
228 translist[RECORD] = RECORD;
229 translist[STOP] = STOP;
230 translist[PAUSE] = PAUSE;
231 translist[PLAY] = PLAY;
232 translist[SKIPBACK] = SKIPBACK;
233 translist[SKIPFORWARD] = SKIPFORWARD;
236 translist[FULL] = FULL;
240 translist[VIDEOS] = VIDEOS;
241 translist[MUSIC] = MUSIC;
242 translist[PICTURES] = PICTURES;
243 translist[GUIDE] = GUIDE;
244 translist[PREVCHANNEL] = PREVCHANNEL;
245 translist[STAR] = STAR;
246 translist[HASH] = HASH;
249 const char *Remote::CommandDesc(UCHAR number)
254 return tr("Volume Up");
257 return tr("Volume Down");
259 return tr("Channel up");
261 return tr("Channel down");
303 return tr("Reverse");
307 return tr("Forward");
315 return tr("Skip back");
317 return tr("Skip forward");
321 return tr("Fullscreen");
329 return tr("Pictures");
341 return tr("Previous Channel");
352 char* Remote::HCWDesc(ULLONG hcw)
355 temp=(char*)CommandDesc((UCHAR)hcw);
358 dest=new char[strlen(temp)+1];
364 sprintf(dest,"C:%lX",(ULONG)hcw);
369 char *Remote::CommandTranslateStr(UCHAR command)
372 int length=5;//:+\t+0
373 int keys=0; //max 10;
374 char *commanddesc=(char*)CommandDesc(command);
375 if (commanddesc != NULL)
377 length+=strlen(commanddesc);
379 char *preassigneddesc=(char*)HardcodedTranslateStr(command);
380 if (preassigneddesc != NULL)
382 length+=strlen(preassigneddesc);
386 RemoteTranslationList::const_iterator it;
387 for (it = translist.begin(); it != translist.end(); it++)
389 if (it->second == command)
391 keydesc[keys] = HCWDesc(it->first);
392 length += strlen(keydesc[keys])+2;
394 if (keys == 10) break;
398 desc=new char [length];
400 if (commanddesc != NULL)
402 current+=sprintf(current,"%s:\t ",commanddesc);
406 current+=sprintf(current,":\t ");
408 if (preassigneddesc != NULL)
410 current+=sprintf(current,"%s\t",preassigneddesc);
414 current+=sprintf(current,"\t");
416 for (int i = 0;i < keys; i++)
418 current += sprintf(current,"%s, ",keydesc[i]);
419 delete [] keydesc[i];
424 bool Remote::addOptionPagesToWTB(WTabBar *wtb)
426 WRemoteConfig* wrc = new WRemoteConfig();
427 wtb->addTab(tr("Remote Control"), wrc);
431 bool Remote::loadOptionsfromServer(VDR* vdr)
435 config = vdr->configLoad("General", "Remote keys");
439 Log::getInstance()->log("Remote", Log::INFO, "Config General/Remote keys load");
440 LoadKeysConfig(config);
445 Log::getInstance()->log("Remote", Log::INFO, "Config General/Remote keys not found");
446 InitHWCListwithDefaults();
451 bool Remote::saveOptionstoServer()
453 char *keyscon=SaveKeysConfig();
454 VDR::getInstance()->configSave("General","Remote keys",keyscon);