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