2 Copyright 2004-2020 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, see <https://www.gnu.org/licenses/>.
20 #include "wremoteconfig.h"
30 learnmode = NOLEARNMODE;
37 void Input::EnterLearningMode(UCHAR command)
39 learnmode = command; //Armed
42 void Input::ResetToDefault()
45 InitHWCListwithDefaults();
49 UCHAR Input::TranslateHWCFixed(ULLONG code)
73 const char* Input::HardcodedTranslateStr(UCHAR command)
96 UCHAR Input::TranslateHWCList(int code)
98 if (learnmode != NOLEARNMODE)
100 setHWCtoCommand(code, learnmode);
101 learnmode = NOLEARNMODE;
104 RemoteTranslationList::iterator it = translist.find(code);
105 if (it == translist.end())
115 UCHAR Input::TranslateHWC(int code)
117 UCHAR ret = TranslateHWCFixed(code);
118 if (ret == NA_UNKNOWN)
120 ret = TranslateHWCList(code);
124 learnmode = NOLEARNMODE;
127 if (ret == NA_UNKNOWN)
134 void Input::setHWCtoCommand(ULLONG hcw, UCHAR command)
136 translist[hcw] = command;
139 void Input::unsetHWC(ULLONG hcw)
141 translist.erase(hcw);
144 void Input::LoadKeysConfig(VDR *vdr,const char *cfg)
147 if (sscanf(cfg,"%ld",&number) != 1) return;
148 Log::getInstance()->log("Input", Log::INFO, "Config General/Remote keys num keys %d",number);
150 for (ULONG i = 0; i < number; i++) {
151 sprintf(keybuf, "RemoteKey%lu", i);
152 const char *keytrans = vdr->configLoad("General", keybuf);
156 if (sscanf(keytrans, "%lXI%lXK%lX", &ul1, &ul2, &uc) == 3) {
157 translist[((ULLONG) ul1) | ((ULLONG) ul2) << 32] = (UCHAR) uc;
165 void Input::SaveKeysConfig()
170 RemoteTranslationList::const_iterator it;
171 for (it = translist.begin(); it != translist.end(); it++)
173 sprintf(buffer,"%08lXI%08lXK%02X",
174 (ULONG)it->first ,(ULONG) (it->first >> 32), it->second);
175 sprintf(keybuf,"RemoteKey%d",number);
176 VDR::getInstance()->configSave("General",keybuf,buffer);
179 sprintf(buffer,"%d",number);
180 VDR::getInstance()->configSave("General","RemoteKeyNum",buffer);
183 char* Input::HCWDesc(ULLONG hcw)
186 const char* temp = InputMan::CommandDesc((UCHAR)hcw);
189 dest=new char[strlen(temp)+1];
195 sprintf(dest,"C:%lX",(ULONG)hcw);
200 char* Input::CommandTranslateStr(UCHAR command)
203 int length = 5; //:+\t+0
205 const char* commanddesc = InputMan::CommandDesc(command);
206 if (commanddesc != NULL) length += strlen(commanddesc);
208 const char* preassigneddesc = HardcodedTranslateStr(command);
209 if (preassigneddesc != NULL) length += strlen(preassigneddesc);
212 int keys = 0; // max 10
213 RemoteTranslationList::const_iterator it;
214 for (it = translist.begin(); it != translist.end(); it++)
216 if (it->second == command)
218 keydesc[keys] = HCWDesc(it->first);
219 length += strlen(keydesc[keys])+2;
221 if (keys == 10) break;
225 desc = new char[length];
226 char* current = desc;
227 if (commanddesc != NULL)
229 current += sprintf(current, "%s:\t ", commanddesc);
233 current += sprintf(current,":\t ");
236 if (preassigneddesc != NULL)
238 current += sprintf(current, "%s\t", preassigneddesc);
242 current+=sprintf(current,"\t");
245 for (int i = 0; i < keys; i++)
247 current += sprintf(current, "%s, ", keydesc[i]);
254 // bool Input::addOptionPagesToWTB(WTabBar *wtb)
256 // WRemoteConfig* wrc = new WRemoteConfig();
257 // wtb->addTab(tr("Remote Control"), wrc);
261 bool Input::loadOptionsfromServer(VDR* vdr)
265 config = vdr->configLoad("General", "RemoteKeyNum");
269 Log::getInstance()->log("Input", Log::INFO, "Config General/Remote keys load");
270 LoadKeysConfig(vdr,config);
275 Log::getInstance()->log("Input", Log::INFO, "Config General/Remote keys not found");
276 InitHWCListwithDefaults();
281 bool Input::saveOptionstoServer()