]> git.vomp.tv Git - vompclient.git/blob - inputman.cc
WIP [broken]
[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   //if (inputLinux) inputLinux->addOptionPagesToWTB(wtb);
180   //if (inputCEC) inputCEC->addOptionPagesToWTB(wtb);
181
182   WRemoteConfig* wrc = new WRemoteConfig();
183   wtb->addTab(tr("Remote Control"), wrc);
184
185   return true; // FIXME
186 }
187
188 bool InputMan::saveOptionstoServer()
189 {
190   if (inputLinux) inputLinux->saveOptionstoServer();
191   if (inputCEC) inputCEC->saveOptionstoServer();
192
193   return true; // FIXME
194 }
195
196 const char* InputMan::getVompKeyName(UCHAR number)
197 {
198   switch (number)
199   {
200     case Input::VOLUMEUP:
201       return tr("Volume Up");
202     case Input::VOLUMEDOWN:
203       return tr("Volume Down");
204     case Input::CHANNELUP:
205       return tr("Channel up");
206     case Input::CHANNELDOWN:
207       return tr("Channel down");
208     case Input::ZERO:
209       return "0";
210     case Input::ONE:
211       return "1";
212     case Input::TWO:
213       return "2";
214     case Input::THREE:
215       return "3";
216     case Input::FOUR:
217       return "4";
218     case Input::FIVE:
219       return "5";
220     case Input::SIX:
221       return "6";
222     case Input::SEVEN:
223       return "7";
224     case Input::EIGHT:
225       return "8";
226     case Input::NINE:
227       return "9";
228     case Input::POWER:
229       return tr("Power");
230     case Input::GO:
231       return tr("Go");
232     case Input::BACK:
233       return tr("Back");
234     case Input::MENU:
235       return tr("Menu");
236     case Input::RED:
237       return tr("Red");
238     case Input::GREEN:
239       return tr("Green");
240     case Input::YELLOW:
241       return tr("Yellow");
242     case Input::BLUE:
243       return tr("Blue");
244     case Input::MUTE:
245       return tr("Mute");
246     case Input::RADIO:
247       return tr("Radio");
248     case Input::REVERSE:
249       return tr("Reverse");
250     case Input::PLAY:
251       return tr("Play");
252     case Input::FORWARD:
253       return tr("Forward");
254     case Input::RECORD:
255       return tr("Record");
256     case Input::STOP:
257       return tr("Stop");
258     case Input::PAUSE:
259       return tr("Pause");
260     case Input::SKIPBACK:
261       return tr("Skip back");
262     case Input::SKIPFORWARD:
263       return tr("Skip forward");
264     case Input::OK:
265       return tr("Ok");
266     case Input::FULL:
267       return tr("Fullscreen");
268     case Input::TV:
269       return tr("TV");
270     case Input::VIDEOS:
271       return tr("Videos");
272     case Input::MUSIC:
273       return tr("Music");
274     case Input::PICTURES:
275       return tr("Pictures");
276     case Input::GUIDE:
277       return tr("Guide");
278     case Input::UP:
279       return tr("Up");
280     case Input::DOWN:
281       return tr("Down");
282     case Input::LEFT:
283       return tr("Left");
284     case Input::RIGHT:
285       return tr("Right");
286     case Input::PREVCHANNEL:
287       return tr("Previous Channel");
288     case Input::STAR:
289       return tr("Star");
290     case Input::HASH:
291       return tr("Hash");
292     case Input::PLAYPAUSE:
293        return tr("Play/Pause");
294
295     default:
296       return NULL;
297   }
298 }
299
300 std::string InputMan::getHardCodedHardwareKeyNamesForVompKey(UCHAR vompKey)
301 {
302   // Go through each active Input class and get the hardware key name for vompKey
303
304   // which doesn't make any sense
305
306   std::string keyNames;
307
308   if (inputLinux)
309   {
310     std::string k = inputLinux->getHardCodedHardwareKeyNamesForVompKey(vompKey);
311     if (k.size()) keyNames += k;
312   }
313
314   if (inputCEC)
315   {
316     std::string k = inputCEC->getHardCodedHardwareKeyNamesForVompKey(vompKey);
317     if (k.size()) { keyNames += ", "; keyNames += k; }
318   }
319
320   if (inputUDP)
321   {
322     std::string k = inputUDP->getHardCodedHardwareKeyNamesForVompKey(vompKey);
323     if (k.size()) { keyNames += ", "; keyNames += k; }
324   }
325
326   return keyNames;
327 }
328
329 std::string InputMan::getAllHardwareKeyNamesAssignedToVompKey(UCHAR vompKey)
330 {
331   std::string keyNames;
332
333   if (inputLinux)
334   {
335     std::string k = inputLinux->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
336     if (k.size()) keyNames += k;
337   }
338
339   if (inputCEC)
340   {
341     std::string k = inputCEC->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
342     if (k.size()) { keyNames += ", "; keyNames += k; }
343   }
344
345   if (inputUDP)
346   {
347     std::string k = inputUDP->getAllHardwareKeyNamesAssignedToVompKey(vompKey);
348     if (k.size()) { keyNames += ", "; keyNames += k; }
349   }
350
351   return keyNames;
352 }