]> 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 "i18n.h"
26 #include "input.h"
27
28 #include "inputman.h"
29
30 InputMan* InputMan::instance = NULL;
31
32 InputMan::InputMan()
33 {
34   instance = this;
35 }
36
37 InputMan::~InputMan()
38 {
39   instance = NULL;
40 }
41
42 InputMan* InputMan::getInstance()
43 {
44   return instance;
45 }
46
47 bool InputMan::init()
48 {
49   bool i1{}, i2{};
50
51 #ifdef VOMP_PLATFORM_RASPBERRY
52   inputLinux = new InputLinux();
53   i1 = inputLinux->init();
54   if (!i1) { delete inputLinux; inputLinux = NULL; }
55
56 //  inputCEC = new InputCEC();
57 //  i2 = inputCEC->init();
58 //  if (!i2) { delete inputCEC; inputCEC = NULL; }
59 #endif
60
61   if (!i1 && !i2)
62   {
63     Log::getInstance()->log("InputMan", Log::CRIT, "InputMan could not init any input module");
64     return false;
65   }
66
67   initted = true;
68   return true;
69 }
70
71 bool InputMan::start()
72 {
73   bool i1{};
74
75   if (inputLinux)
76   {
77     i1 = inputLinux->start();
78   }
79
80   return i1;
81 }
82
83 void InputMan::stop()
84 {
85   if (inputLinux) inputLinux->stop();
86 }
87
88 void InputMan::shutdown()
89 {
90   Log::getInstance()->log("InputMan", Log::DEBUG, "Shutdown start");
91
92   if (inputLinux)
93   {
94     Log::getInstance()->log("InputMan", Log::DEBUG, "Shutdown start - Linux");
95     inputLinux->stop();
96     inputLinux->shutdown();
97     delete inputLinux;
98     inputLinux = NULL;
99   }
100
101   if (inputCEC)
102   {
103     Log::getInstance()->log("InputMan", Log::DEBUG, "Shutdown start - CEC");
104     inputCEC->shutdown();
105     delete inputCEC;
106     inputCEC = NULL;
107   }
108
109   initted = false;
110 }
111
112 bool InputMan::mayHaveFewButtons()
113 {
114   // 052 returned true if remotelinux was in effect - linux or CEC. What was it for?
115
116   if (inputLinux || inputCEC) return true;
117   return false;
118 }
119
120 bool InputMan::handlesVolume()
121 {
122   if (!inputCEC) return false;
123   return inputCEC->handlesVolume();
124 }
125
126 void InputMan::volumeUp()
127 {
128   if (inputCEC) inputCEC->volumeUp();
129 }
130
131 void InputMan::volumeDown()
132 {
133   if (inputCEC) inputCEC->volumeDown();
134 }
135
136 void InputMan::volumeMute()
137 {
138   if (inputCEC) inputCEC->volumeMute();
139 }
140
141 void InputMan::changePowerState(bool powerOn)
142 {
143   if (inputCEC) inputCEC->changePowerState(powerOn);
144 }
145
146 bool InputMan::addOptionsToPanes(int panenumber, Options* options, WOptionPane* pane)
147 {
148   if (inputLinux) inputLinux->addOptionsToPanes(panenumber, options, pane);
149   if (inputCEC) inputCEC->addOptionsToPanes(panenumber, options, pane);
150
151   return true; // FIXME
152 }
153
154 bool InputMan::addOptionPagesToWTB(WTabBar *wtb)
155 {
156   //if (inputLinux) inputLinux->addOptionPagesToWTB(wtb);
157   //if (inputCEC) inputCEC->addOptionPagesToWTB(wtb);
158
159   WRemoteConfig* wrc = new WRemoteConfig();
160   wtb->addTab(tr("Remote Control"), wrc);
161
162   return true; // FIXME
163 }
164
165 bool InputMan::saveOptionstoServer()
166 {
167   if (inputLinux) inputLinux->saveOptionstoServer();
168   if (inputCEC) inputCEC->saveOptionstoServer();
169
170   return true; // FIXME
171 }
172
173 const char* InputMan::CommandDesc(UCHAR number)
174 {
175   switch (number)
176   {
177     case Input::VOLUMEUP:
178       return tr("Volume Up");
179     case Input::VOLUMEDOWN:
180       return tr("Volume Down");
181     case Input::CHANNELUP:
182       return tr("Channel up");
183     case Input::CHANNELDOWN:
184       return tr("Channel down");
185     case Input::ZERO:
186       return "0";
187     case Input::ONE:
188       return "1";
189     case Input::TWO:
190       return "2";
191     case Input::THREE:
192       return "3";
193     case Input::FOUR:
194       return "4";
195     case Input::FIVE:
196       return "5";
197     case Input::SIX:
198       return "6";
199     case Input::SEVEN:
200       return "7";
201     case Input::EIGHT:
202       return "8";
203     case Input::NINE:
204       return "9";
205     case Input::POWER:
206       return tr("Power");
207     case Input::GO:
208       return tr("Go");
209     case Input::BACK:
210       return tr("Back");
211     case Input::MENU:
212       return tr("Menu");
213     case Input::RED:
214       return tr("Red");
215     case Input::GREEN:
216       return tr("Green");
217     case Input::YELLOW:
218       return tr("Yellow");
219     case Input::BLUE:
220       return tr("Blue");
221     case Input::MUTE:
222       return tr("Mute");
223     case Input::RADIO:
224       return tr("Radio");
225     case Input::REVERSE:
226       return tr("Reverse");
227     case Input::PLAY:
228       return tr("Play");
229     case Input::FORWARD:
230       return tr("Forward");
231     case Input::RECORD:
232       return tr("Record");
233     case Input::STOP:
234       return tr("Stop");
235     case Input::PAUSE:
236       return tr("Pause");
237     case Input::SKIPBACK:
238       return tr("Skip back");
239     case Input::SKIPFORWARD:
240       return tr("Skip forward");
241     case Input::OK:
242       return tr("Ok");
243     case Input::FULL:
244       return tr("Fullscreen");
245     case Input::TV:
246       return tr("TV");
247     case Input::VIDEOS:
248       return tr("Videos");
249     case Input::MUSIC:
250       return tr("Music");
251     case Input::PICTURES:
252       return tr("Pictures");
253     case Input::GUIDE:
254       return tr("Guide");
255     case Input::UP:
256       return tr("Up");
257     case Input::DOWN:
258       return tr("Down");
259     case Input::LEFT:
260       return tr("Left");
261     case Input::RIGHT:
262       return tr("Right");
263     case Input::PREVCHANNEL:
264       return tr("Previous Channel");
265     case Input::STAR:
266       return tr("Star");
267     case Input::HASH:
268       return tr("Hash");
269     case Input::PLAYPAUSE:
270        return tr("Play/Pause");
271
272     default:
273       return NULL;
274   }
275 }