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