]> git.vomp.tv Git - vompclient.git/blob - inputman.cc
Fixes for Windows
[vompclient.git] / inputman.cc
1 /*
2     Copyright 2020 Chris Tallon; 2012 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, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include "log.h"
21 #include "wremoteconfig.h"
22 #include "wtabbar.h"
23 #ifdef VOMP_PLATFORM_RASPBERRY
24 #include "inputlinux.h"
25 #include "inputcec.h"
26 #endif
27 #include "inputudp.h"
28 #ifdef WIN32
29 #include "inputwin.h"
30 #endif
31 #include "i18n.h"
32 #include "input.h"
33
34 #include "inputman.h"
35
36 InputMan* InputMan::instance = NULL;
37
38 InputMan::InputMan()
39 {
40   instance = this;
41 }
42
43 InputMan::~InputMan()
44 {
45   instance = NULL;
46 }
47
48 InputMan* InputMan::getInstance()
49 {
50   return instance;
51 }
52
53 bool InputMan::init()
54 {
55   bool ret;
56   bool oneOK{};
57
58 #ifdef VOMP_PLATFORM_RASPBERRY
59   inputLinux = new InputLinux();
60   ret = inputLinux->init();
61   if (ret)
62     oneOK = true;
63   else
64     { delete inputLinux; inputLinux = NULL; }
65
66   // FIXME enable modules by new config system NCONFIG
67
68 //  inputCEC = new InputCEC();
69 //  ret = inputCEC->init();
70 //  if (ret)
71 //    oneOK = true;
72 //  else
73 //    { delete inputCEC; inputCEC = NULL; }
74 #endif
75
76   inputUDP = new InputUDP();
77   ret = inputUDP->init();
78   if (ret)
79     oneOK = true;
80   else
81     { delete inputUDP; inputUDP = NULL; }
82
83 #ifdef WIN32
84   inputWin = new InputWin();
85   ret = inputWin->init();
86   if (ret)
87     oneOK = true;
88   else
89     { delete inputWin; inputWin = NULL; }
90 #endif
91
92   if (!oneOK)
93   {
94     Log::getInstance()->log("InputMan", Log::CRIT, "InputMan could not init any input module");
95     return false;
96   }
97
98   initted = true;
99   return true;
100 }
101
102 bool InputMan::start()
103 {
104   Log::getInstance()->log("InputMan", Log::DEBUG, "Start");
105
106   bool oneOK{};
107
108 #ifdef VOMP_PLATFORM_RASPBERRY
109   if (inputLinux && inputLinux->start()) oneOK = true;
110 #endif
111
112   if (inputUDP && inputUDP->start()) oneOK = true;
113
114   if (!oneOK)
115     Log::getInstance()->log("InputMan", Log::CRIT, "InputMan could not start any input module");
116
117   return oneOK;
118 }
119
120 void InputMan::stop()
121 {
122   Log::getInstance()->log("InputMan", Log::DEBUG, "Stop called");
123
124 #ifdef VOMP_PLATFORM_RASPBERRY
125   if (inputLinux) inputLinux->stop();
126 #endif
127   if (inputUDP) inputUDP->stop();
128 }
129
130 void InputMan::shutdown()
131 {
132   Log::getInstance()->log("InputMan", Log::DEBUG, "Shutdown start");
133
134 #ifdef VOMP_PLATFORM_RASPBERRY
135
136   if (inputLinux)
137   {
138     Log::getInstance()->log("InputMan", Log::DEBUG, "Shutdown start - Linux");
139     inputLinux->stop();
140     inputLinux->shutdown();
141     delete inputLinux;
142     inputLinux = NULL;
143   }
144
145   if (inputCEC)
146   {
147     Log::getInstance()->log("InputMan", Log::DEBUG, "Shutdown start - CEC");
148     inputCEC->shutdown();
149     delete inputCEC;
150     inputCEC = NULL;
151   }
152
153 #endif
154
155   if (inputUDP)
156   {
157     Log::getInstance()->log("InputMan", Log::DEBUG, "Shutdown start - UDP");
158     inputUDP->stop();
159     inputUDP->shutdown();
160     delete inputUDP;
161     inputUDP = NULL;
162   }
163
164   initted = false;
165 }
166
167 bool InputMan::mayHaveFewButtons()
168 {
169   // 052 returned true if remotelinux was in effect - linux or CEC. What was it for?
170
171   if (inputLinux || inputCEC) return true;
172   return false;
173 }
174
175 bool InputMan::handlesVolume()
176 {
177 #ifdef VOMP_PLATFORM_RASPBERRY
178   if (!inputCEC) return false;
179   return inputCEC->handlesVolume();
180 #else
181   return false;
182 #endif
183 }
184
185 void InputMan::volumeUp()
186 {
187 #ifdef VOMP_PLATFORM_RASPBERRY
188         if (inputCEC) inputCEC->volumeUp();
189 #endif
190 }
191
192 void InputMan::volumeDown()
193 {
194 #ifdef VOMP_PLATFORM_RASPBERRY
195         if (inputCEC) inputCEC->volumeDown();
196 #endif
197 }
198
199 void InputMan::volumeMute()
200 {
201 #ifdef VOMP_PLATFORM_RASPBERRY
202   if (inputCEC) inputCEC->volumeMute();
203 #endif
204 }
205
206 void InputMan::changePowerState(bool powerOn)
207 {
208 #ifdef VOMP_PLATFORM_RASPBERRY
209   if (inputCEC) inputCEC->changePowerState(powerOn);
210 #endif
211 }
212
213 bool InputMan::addOptionsToPanes(int panenumber, Options* options, WOptionPane* pane)
214 {
215 #ifdef VOMP_PLATFORM_RASPBERRY
216   if (inputLinux) inputLinux->addOptionsToPanes(panenumber, options, pane);
217   if (inputCEC) inputCEC->addOptionsToPanes(panenumber, options, pane);
218 #endif
219
220   return true; // FIXME
221 }
222
223 bool InputMan::addOptionPagesToWTB(WTabBar *wtb)
224 {
225   WRemoteConfig* wrc = new WRemoteConfig();
226   wtb->addTab(tr("Remote Control"), wrc);
227
228   return true; // FIXME
229 }
230
231 bool InputMan::loadOptionsFromServer(VDR* vdr)
232 {
233 #ifdef VOMP_PLATFORM_RASPBERRY
234   if (inputLinux) inputLinux->loadOptionsFromServer(vdr);
235   if (inputCEC) inputCEC->loadOptionsFromServer(vdr);
236 #endif
237
238   return true; // FIXME
239 }
240
241 bool InputMan::saveOptionstoServer()
242 {
243 #ifdef VOMP_PLATFORM_RASPBERRY
244   if (inputLinux) inputLinux->saveOptionstoServer();
245   if (inputCEC) inputCEC->saveOptionstoServer();
246 #endif
247   return true; // FIXME
248 }
249
250 const char* InputMan::getVompKeyName(UCHAR number)
251 {
252   switch (number)
253   {
254     case Input::VOLUMEUP:
255       return tr("Volume Up");
256     case Input::VOLUMEDOWN:
257       return tr("Volume Down");
258     case Input::CHANNELUP:
259       return tr("Channel up");
260     case Input::CHANNELDOWN:
261       return tr("Channel down");
262     case Input::ZERO:
263       return "0";
264     case Input::ONE:
265       return "1";
266     case Input::TWO:
267       return "2";
268     case Input::THREE:
269       return "3";
270     case Input::FOUR:
271       return "4";
272     case Input::FIVE:
273       return "5";
274     case Input::SIX:
275       return "6";
276     case Input::SEVEN:
277       return "7";
278     case Input::EIGHT:
279       return "8";
280     case Input::NINE:
281       return "9";
282     case Input::POWER:
283       return tr("Power");
284     case Input::GO:
285       return tr("Go");
286     case Input::BACK:
287       return tr("Back");
288     case Input::MENU:
289       return tr("Menu");
290     case Input::RED:
291       return tr("Red");
292     case Input::GREEN:
293       return tr("Green");
294     case Input::YELLOW:
295       return tr("Yellow");
296     case Input::BLUE:
297       return tr("Blue");
298     case Input::MUTE:
299       return tr("Mute");
300     case Input::RADIO:
301       return tr("Radio");
302     case Input::REVERSE:
303       return tr("Reverse");
304     case Input::PLAY:
305       return tr("Play");
306     case Input::FORWARD:
307       return tr("Forward");
308     case Input::RECORD:
309       return tr("Record");
310     case Input::STOP:
311       return tr("Stop");
312     case Input::PAUSE:
313       return tr("Pause");
314     case Input::SKIPBACK:
315       return tr("Skip back");
316     case Input::SKIPFORWARD:
317       return tr("Skip forward");
318     case Input::OK:
319       return tr("Ok");
320     case Input::FULL:
321       return tr("Fullscreen");
322     case Input::TV:
323       return tr("TV");
324     case Input::VIDEOS:
325       return tr("Videos");
326     case Input::MUSIC:
327       return tr("Music");
328     case Input::PICTURES:
329       return tr("Pictures");
330     case Input::GUIDE:
331       return tr("Guide");
332     case Input::UP:
333       return tr("Up");
334     case Input::DOWN:
335       return tr("Down");
336     case Input::LEFT:
337       return tr("Left");
338     case Input::RIGHT:
339       return tr("Right");
340     case Input::PREVCHANNEL:
341       return tr("Previous Channel");
342     case Input::STAR:
343       return tr("Star");
344     case Input::HASH:
345       return tr("Hash");
346     case Input::PLAYPAUSE:
347        return tr("Play/Pause");
348
349     default:
350       return NULL;
351   }
352 }
353
354 std::string InputMan::getHardCodedHardwareKeyNamesForVompKey(UCHAR vompKey)
355 {
356   // Go through each active Input class and get the hardware key name for vompKey
357
358   // which doesn't make any sense
359
360   std::string keyNames;
361
362 #ifdef VOMP_PLATFORM_RASPBERRY
363   if (inputLinux)
364   {
365     std::string k = inputLinux->getHardCodedHardwareKeyNamesForVompKey(vompKey);
366     if (k.size()) keyNames += k;
367   }
368
369   if (inputCEC)
370   {
371     std::string k = inputCEC->getHardCodedHardwareKeyNamesForVompKey(vompKey);
372     if (k.size()) { keyNames += ", "; keyNames += k; }
373   }
374 #endif
375
376   if (inputUDP)
377   {
378     std::string k = inputUDP->getHardCodedHardwareKeyNamesForVompKey(vompKey);
379     if (k.size()) { keyNames += ", "; keyNames += k; }
380   }
381
382   return keyNames;
383 }
384
385 std::string InputMan::getAllHardwareKeyNamesAssignedToVompKey(UCHAR vompKey)
386 {
387   std::string keyNames;
388
389 #ifdef VOMP_PLATFORM_RASPBERRY
390   if (inputLinux)
391   {
392     std::string k = inputLinux->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
393     if (k.size()) keyNames += k;
394   }
395
396   if (inputCEC)
397   {
398     std::string k = inputCEC->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
399     if (k.size()) { keyNames += ", "; keyNames += k; }
400   }
401 #endif
402
403   if (inputUDP)
404   {
405     std::string k = inputUDP->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
406     if (k.size()) { keyNames += ", "; keyNames += k; }
407   }
408
409   return keyNames;
410 }
411
412 void InputMan::ResetToDefault()
413 {
414 #ifdef VOMP_PLATFORM_RASPBERRY
415
416   if (inputLinux) inputLinux->ResetToDefault();
417
418   if (inputCEC) inputCEC->ResetToDefault();
419
420 #endif
421
422   if (inputUDP) inputUDP->ResetToDefault();
423 }
424
425 void InputMan::EnterLearningMode(UCHAR vompKey)
426 {
427 #ifdef VOMP_PLATFORM_RASPBERRY
428   if (inputLinux) inputLinux->EnterLearningMode(vompKey);
429
430 //  if (inputCEC) inputCEC->EnterLearningMode();  FIXME - is there any such thing?
431 #endif
432 }
433
434 void InputMan::cancelLearnMode()
435 {
436 #ifdef VOMP_PLATFORM_RASPBERRY
437   if (inputLinux) inputLinux->cancelLearnMode();
438   if (inputCEC) inputCEC->cancelLearnMode();
439 #endif
440   if (inputUDP) inputUDP->cancelLearnMode();
441 }