]> git.vomp.tv Git - vompclient.git/blob - input.cc
Bitmap and VPictureBanner CWFs
[vompclient.git] / input.cc
1 /*
2     Copyright 2004-2020 Chris Tallon
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, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include "wremoteconfig.h"
21 #include "i18n.h"
22 #include "log.h"
23 #include "vdr.h"
24 #include "wtabbar.h"
25 #include "message.h"
26 #include "messagequeue.h"
27 #include "inputman.h"
28 #include "input.h"
29
30 void Input::ResetToDefault()
31 {
32   translist.clear();
33   InitHWCListwithDefaults();
34 }
35
36 UCHAR Input::TranslateHWC(HWC_TYPE code)
37 {
38   UCHAR ret = TranslateHWCFixed(code);
39
40   if (ret != NA_UNKNOWN) // Found in fixed list
41   {
42     InputMan::getInstance()->cancelLearnMode(); // Just in case
43     return ret;
44   }
45
46   return TranslateHWCList(code);
47 }
48
49 UCHAR Input::TranslateHWCList(HWC_TYPE code)
50 {
51   if (learnMode != NOLEARNMODE)
52   {
53     setHWCtoCommand(code, static_cast<UCHAR>(learnMode));
54     InputMan::getInstance()->cancelLearnMode();
55     return NA_LEARN;
56   }
57   RemoteTranslationList::iterator it = translist.find(code);
58   if (it == translist.end())
59   {
60     return NA_UNKNOWN;
61   }
62   else
63   {
64     return it->second;
65   }
66 }
67
68 void Input::setHWCtoCommand(HWC_TYPE hcw, UCHAR command)
69 {
70   translist[hcw] = command;
71 }
72
73 void Input::unsetHWC(HWC_TYPE hcw) // FIXME never used
74 {
75   translist.erase(hcw);
76 }
77
78 void Input::LoadKeysConfig(VDR *vdr,const char *cfg)
79 {
80         ULONG number=0;
81         if (sscanf(cfg,"%ld",&number) != 1) return;
82         Log::getInstance()->log("Input", Log::INFO, "Config Input/Remote keys num keys %d",number);
83         char keybuf[1024];
84         for (ULONG i = 0; i < number; i++) {
85                 sprintf(keybuf, "RemoteKey%lu", i);
86                 const char *keytrans = vdr->configLoad(modName(), keybuf);
87                 if (keytrans) {
88                         ULONG ul1, ul2;
89                         ULONG uc;
90                         if (sscanf(keytrans, "%lXI%lXK%lX", &ul1, &ul2, &uc) == 3) {
91                                 translist[((ULLONG) ul1) | ((ULLONG) ul2) << 32] = (UCHAR) uc;
92                         }
93                         delete[] keytrans;
94                 }
95
96         }
97 }
98
99 // FIXME - These two still use the bit shifting stuff. Leave it for now, might still
100 // need it for Windows
101
102 void Input::SaveKeysConfig()
103 {
104   int number=0;
105   char buffer[1024];
106   char keybuf[1024];
107   RemoteTranslationList::const_iterator it;
108   for (it = translist.begin(); it != translist.end(); it++)
109   {
110           sprintf(buffer,"%08lXI%08lXK%02X",
111                           (ULONG)it->first ,(ULONG) (it->first >> 32), it->second);
112           sprintf(keybuf,"RemoteKey%d",number);
113           VDR::getInstance()->configSave(modName(), keybuf, buffer);
114           number++;
115   }
116   sprintf(buffer,"%d",number);
117   VDR::getInstance()->configSave(modName(), "RemoteKeyNum", buffer);
118 }
119
120 bool Input::loadOptionsFromServer(VDR* vdr)
121 {
122    // Set remote keys
123   char * config;
124   config = vdr->configLoad(modName(), "RemoteKeyNum");
125
126   if (config)
127   {
128     Log::getInstance()->log("Input", Log::INFO, "Config Input/Remote keys load");
129     LoadKeysConfig(vdr,config);
130     delete[] config;
131   }
132   else
133   {
134     Log::getInstance()->log("Input", Log::INFO, "Config Input/Remote keys not found");
135     InitHWCListwithDefaults();
136   }
137   return true;
138 }
139
140 bool Input::saveOptionstoServer()
141 {
142   SaveKeysConfig();
143   return true;
144 }
145
146 void Input::sendInputKey(int key)
147 {
148   Message* m = new Message();
149   m->message = Message::INPUT_EVENT;
150   m->p_to = Message::CONTROL;
151   m->from = this;
152   m->parameter = key;
153   MessageQueue::getInstance()->postMessage(m);
154 }
155
156 std::string Input::getAllHardwareKeyNamesAssignedToVompKey(UCHAR vompKey)
157 {
158   std::string keyNames;
159   keyNames.reserve(50);
160   int keys = 0; // max 10
161   RemoteTranslationList::const_iterator it;
162   bool first = true;
163   for (it = translist.begin(); it != translist.end(); it++)
164   {
165     if (it->second == vompKey)
166     {
167       if (!first) keyNames += ", ";
168       first = false;
169
170       keyNames += getHardwareKeyName(it->first);
171       keys++;
172       if (keys == 10) break;
173     }
174   }
175   return keyNames;
176 }