First attempt to implement RC6 Protocol
[pierogi] / pirkeysetmanager.cpp
1 #include "pirkeysetmanager.h"
2 #include "pirkeysetmetadata.h"
3 #include "keysets/apple.h"
4 #include "keysets/denon.h"
5 #include "keysets/ei.h"
6 #include "keysets/goldstar.h"
7 #include "keysets/hauppauge.h"
8 #include "keysets/hitachi.h"
9 #include "keysets/jvc.h"
10 #include "keysets/lg.h"
11 #include "keysets/magnavox.h"
12 #include "keysets/mitsubishi.h"
13 #include "keysets/nokia.h"
14 #include "keysets/panasonic.h"
15 #include "keysets/philips.h"
16 #include "keysets/pinnacle.h"
17 #include "keysets/raite.h"
18 #include "keysets/rca.h"
19 #include "keysets/sagem.h"
20 #include "keysets/samsung.h"
21 #include "keysets/sanyo.h"
22 #include "keysets/sharp.h"
23 #include "keysets/sony.h"
24 #include "keysets/tivo.h"
25 #include "keysets/toshiba.h"
26 #include "keysets/westinghouse.h"
27 #include "keysets/yamaha.h"
28 #include "keysets/zenith.h"
29 #include "pirmakenames.h"
30
31 #include "pirexception.h"
32
33 #include <QObject>
34
35 // I'll be handling the threading of the keyset commands in this object:
36 #include <QMutex>
37
38 // Global communications mechanism:
39 extern bool stopRepeatingFlag;
40 extern QMutex stopRepeatingMutex;
41
42 // Global helper objects:
43 PIRMakeMgr makeManager;
44 PIRDeviceTypeMgr deviceManager;
45
46 // Now, on to the actual method definitions:
47
48 PIRKeysetManager::PIRKeysetManager(
49   QObject *guiObject)
50   : counter(0)
51 {
52   // Create the keysets.  Ugly!  This needs to be worked on!
53   populateKeyset(new AppleWhiteRemote(guiObject, counter++));
54
55   populateKeyset(new DenonDVD1(guiObject, counter++));
56   populateKeyset(new DenonDVD2(guiObject, counter++));
57   populateKeyset(new DenonDVD3(guiObject, counter++));
58   populateKeyset(new DenonReceiver1(guiObject, counter++));
59   populateKeyset(new DenonReceiver1a(guiObject, counter++));
60   populateKeyset(new DenonReceiver1b(guiObject, counter++));
61   populateKeyset(new DenonReceiver1c(guiObject, counter++));
62   populateKeyset(new DenonReceiver2(guiObject, counter++));
63   populateKeyset(new DenonReceiver2a(guiObject, counter++));
64   populateKeyset(new DenonReceiver3(guiObject, counter++));
65   populateKeyset(new DenonReceiver3a(guiObject, counter++));
66   populateKeyset(new DenonReceiver4(guiObject, counter++));
67   populateKeyset(new DenonReceiver5(guiObject, counter++));
68   populateKeyset(new DenonAudio1(guiObject, counter++));
69   populateKeyset(new DenonAudio1a(guiObject, counter++));
70   populateKeyset(new DenonAudio1b(guiObject, counter++));
71   populateKeyset(new DenonAudio1c(guiObject, counter++));
72   populateKeyset(new DenonAudio1d(guiObject, counter++));
73   populateKeyset(new DenonAudio2(guiObject, counter++));
74   populateKeyset(new DenonAudio3(guiObject, counter++));
75   populateKeyset(new DenonAudio4(guiObject, counter++));
76   populateKeyset(new DenonAudio5(guiObject, counter++));
77
78   populateKeyset(new EiKeyset(guiObject, counter++));
79
80   populateKeyset(new GoldStarTV1(guiObject, counter++));
81   populateKeyset(new GoldStarTV2(guiObject, counter++));
82   populateKeyset(new GoldStarVCR1(guiObject, counter++));
83   populateKeyset(new GoldStarVCR1a(guiObject, counter++));
84   populateKeyset(new GoldStarVCR1b(guiObject, counter++));
85   populateKeyset(new GoldStarVCR1c(guiObject, counter++));
86   populateKeyset(new GoldStarVCR1d(guiObject, counter++));
87   populateKeyset(new GoldStarCD1(guiObject, counter++));
88
89   populateKeyset(new HauppaugePCTV1(guiObject, counter++));
90   populateKeyset(new HauppaugePCTV1a(guiObject, counter++));
91   populateKeyset(new HauppaugePCTV1b(guiObject, counter++));
92   populateKeyset(new HauppaugePCTV1c(guiObject, counter++));
93   populateKeyset(new HauppaugePCTV2(guiObject, counter++));
94
95   populateKeyset(new JVCSat1(guiObject, counter++));
96   populateKeyset(new JVCSat2(guiObject, counter++));
97   populateKeyset(new JVCVCR1(guiObject, counter++));
98   populateKeyset(new JVCVCR1a(guiObject, counter++));
99   populateKeyset(new JVCVCR1b(guiObject, counter++));
100   populateKeyset(new JVCVCR1c(guiObject, counter++));
101   populateKeyset(new JVCVCR2(guiObject, counter++));
102   populateKeyset(new JVCVCR2a(guiObject, counter++));
103   populateKeyset(new JVCVCR2b(guiObject, counter++));
104   populateKeyset(new JVCVCR2c(guiObject, counter++));
105   populateKeyset(new JVCTV1(guiObject, counter++));
106   populateKeyset(new JVCTV1a(guiObject, counter++));
107   populateKeyset(new JVCTV1b(guiObject, counter++));
108   populateKeyset(new JVCTV1c(guiObject, counter++));
109   populateKeyset(new JVCTV1d(guiObject, counter++));
110   populateKeyset(new JVCTV2(guiObject, counter++));
111   populateKeyset(new JVCTV2a(guiObject, counter++));
112   populateKeyset(new JVCTV2b(guiObject, counter++));
113   populateKeyset(new JVCTV2c(guiObject, counter++));
114   populateKeyset(new JVCTV2d(guiObject, counter++));
115   populateKeyset(new JVCDAT1(guiObject, counter++));
116   populateKeyset(new JVCCarDeck1(guiObject, counter++));
117   populateKeyset(new JVCPortableAudio1(guiObject, counter++));
118   populateKeyset(new JVCPortableAudio1a(guiObject, counter++));
119   populateKeyset(new JVCPortableAudio1b(guiObject, counter++));
120   populateKeyset(new JVCPortableAudio2(guiObject, counter++));
121   populateKeyset(new JVCDVD1(guiObject, counter++));
122
123   populateKeyset(new LGTV1(guiObject, counter++));
124   populateKeyset(new LGTV1a(guiObject, counter++));
125   populateKeyset(new LGTV1b(guiObject, counter++));
126   populateKeyset(new LGTV1c(guiObject, counter++));
127   populateKeyset(new LGTV2(guiObject, counter++));
128   populateKeyset(new LGTV2a(guiObject, counter++));
129   populateKeyset(new LGTV2b(guiObject, counter++));
130   populateKeyset(new LGDisc1(guiObject, counter++));
131   populateKeyset(new LGDisc2(guiObject, counter++));
132   populateKeyset(new LGDisc2a(guiObject, counter++));
133   populateKeyset(new LGVCR1(guiObject, counter++));
134   populateKeyset(new LGVCR1a(guiObject, counter++));
135   populateKeyset(new LGVCR1b(guiObject, counter++));
136
137   populateKeyset(new MagnavoxDVD1(guiObject, counter++));
138   populateKeyset(new MagnavoxVCR1(guiObject, counter++));
139   populateKeyset(new MagnavoxConverterBox1(guiObject, counter++));
140   populateKeyset(new MagnavoxTV1(guiObject, counter++));
141
142   populateKeyset(new MitsubishiTV1(guiObject, counter++));
143   populateKeyset(new MitsubishiTV1a(guiObject, counter++));
144   populateKeyset(new MitsubishiVCR1(guiObject, counter++));
145   populateKeyset(new MitsubishiVCR1a(guiObject, counter++));
146
147   populateKeyset(new NokiaGenericVCR(guiObject, counter++));
148
149   populateKeyset(new PanasonicAmp(guiObject, counter++));
150   populateKeyset(new PanasonicCarAudio(guiObject, counter++));
151   populateKeyset(new PanasonicSat1(guiObject, counter++));
152   populateKeyset(new PanasonicSat1a(guiObject, counter++));
153   populateKeyset(new PanasonicTV1(guiObject, counter++));
154   populateKeyset(new PanasonicTV1a(guiObject, counter++));
155   populateKeyset(new PanasonicTV1b(guiObject, counter++));
156   populateKeyset(new PanasonicVCR1(guiObject, counter++));
157   populateKeyset(new PanasonicVCR1a(guiObject, counter++));
158   populateKeyset(new PanasonicVCR1b(guiObject, counter++));
159   populateKeyset(new PanasonicVCR1c(guiObject, counter++));
160   populateKeyset(new PanasonicDVD1(guiObject, counter++));
161   populateKeyset(new PanasonicDVD1a(guiObject, counter++));
162   populateKeyset(new PanasonicAudio1(guiObject, counter++));
163   populateKeyset(new PanasonicAudio1a(guiObject, counter++));
164
165   populateKeyset(new PhilipsTV1(guiObject, counter++));
166   populateKeyset(new PhilipsTV1a(guiObject, counter++));
167   populateKeyset(new PhilipsTV1b(guiObject, counter++));
168   populateKeyset(new PhilipsTV1c(guiObject, counter++));
169   populateKeyset(new PhilipsTV1d(guiObject, counter++));
170   populateKeyset(new PhilipsTV1e(guiObject, counter++));
171   populateKeyset(new PhilipsTV1f(guiObject, counter++));
172   populateKeyset(new PhilipsTV2(guiObject, counter++));
173   populateKeyset(new PhilipsTV2a(guiObject, counter++));
174   populateKeyset(new PhilipsTV2b(guiObject, counter++));
175   populateKeyset(new PhilipsTV3(guiObject, counter++));
176   populateKeyset(new PhilipsDVD1(guiObject, counter++));
177   populateKeyset(new PhilipsDVD1a(guiObject, counter++));
178   populateKeyset(new PhilipsDVD1b(guiObject, counter++));
179   populateKeyset(new PhilipsDVD1c(guiObject, counter++));
180   populateKeyset(new PhilipsDVD1d(guiObject, counter++));
181   populateKeyset(new PhilipsDVD2(guiObject, counter++));
182   populateKeyset(new PhilipsDVD3(guiObject, counter++));
183   populateKeyset(new PhilipsDVD4(guiObject, counter++));
184   populateKeyset(new PhilipsVCR1(guiObject, counter++));
185   populateKeyset(new PhilipsVCR1a(guiObject, counter++));
186   populateKeyset(new PhilipsVCR1b(guiObject, counter++));
187   populateKeyset(new PhilipsVCR1c(guiObject, counter++));
188   populateKeyset(new PhilipsSat1(guiObject, counter++));
189   populateKeyset(new PhilipsSat2(guiObject, counter++));
190   populateKeyset(new PhilipsSat2a(guiObject, counter++));
191   populateKeyset(new PhilipsSat3(guiObject, counter++));
192   populateKeyset(new PhilipsAudio1(guiObject, counter++));
193   populateKeyset(new PhilipsAudio1a(guiObject, counter++));
194   populateKeyset(new PhilipsAudio1b(guiObject, counter++));
195   populateKeyset(new PhilipsAudio2(guiObject, counter++));
196   populateKeyset(new PhilipsAudio3(guiObject, counter++));
197   populateKeyset(new PhilipsAudio4(guiObject, counter++));
198
199   populateKeyset(new PinnaclePCTV1(guiObject, counter++));
200   populateKeyset(new PinnaclePCTV2(guiObject, counter++));
201   populateKeyset(new PinnaclePCTV3(guiObject, counter++));
202
203   populateKeyset(new RaiteDVD1(guiObject, counter++));
204
205   populateKeyset(new RCATV1(guiObject, counter++));
206   populateKeyset(new RCATV1a(guiObject, counter++));
207   populateKeyset(new RCATV2(guiObject, counter++));
208   populateKeyset(new RCAAux1(guiObject, counter++));
209   populateKeyset(new RCAAux2(guiObject, counter++));
210   populateKeyset(new RCAAux2a(guiObject, counter++));
211   populateKeyset(new RCAVCR1(guiObject, counter++));
212   populateKeyset(new RCAVCR2(guiObject, counter++));
213   populateKeyset(new RCADVD1(guiObject, counter++));
214   populateKeyset(new RCADVD1a(guiObject, counter++));
215   populateKeyset(new RCASat1(guiObject, counter++));
216   populateKeyset(new RCASat2(guiObject, counter++));
217
218   populateKeyset(new SagemTVBox1(guiObject, counter++));
219   populateKeyset(new SagemTVBox1a(guiObject, counter++));
220
221   populateKeyset(new SamsungTV1(guiObject, counter++));
222   populateKeyset(new SamsungTV1a(guiObject, counter++));
223   populateKeyset(new SamsungTV1b(guiObject, counter++));
224   populateKeyset(new SamsungTV1c(guiObject, counter++));
225   populateKeyset(new SamsungTV1d(guiObject, counter++));
226   populateKeyset(new SamsungTV1e(guiObject, counter++));
227   populateKeyset(new SamsungTV1f(guiObject, counter++));
228   populateKeyset(new SamsungTV2(guiObject, counter++));
229   populateKeyset(new SamsungTV2a(guiObject, counter++));
230   populateKeyset(new SamsungVCR1(guiObject, counter++));
231   populateKeyset(new SamsungVCR1a(guiObject, counter++));
232   populateKeyset(new SamsungVCR1b(guiObject, counter++));
233   populateKeyset(new SamsungVCR1c(guiObject, counter++));
234   populateKeyset(new SamsungVCR1d(guiObject, counter++));
235   populateKeyset(new SamsungVCR1e(guiObject, counter++));
236   populateKeyset(new SamsungDVD1(guiObject, counter++));
237   populateKeyset(new SamsungDVD1a(guiObject, counter++));
238   populateKeyset(new SamsungDVD1b(guiObject, counter++));
239   populateKeyset(new SamsungDVD2(guiObject, counter++));
240   populateKeyset(new SamsungAC1(guiObject, counter++));
241
242   populateKeyset(new SanyoVCR1(guiObject, counter++));
243   populateKeyset(new SanyoDVD1(guiObject, counter++));
244   populateKeyset(new SanyoTV1(guiObject, counter++));
245   populateKeyset(new SanyoTV1a(guiObject, counter++));
246   populateKeyset(new SanyoTV1b(guiObject, counter++));
247   populateKeyset(new SanyoTV1c(guiObject, counter++));
248   populateKeyset(new SanyoTV1d(guiObject, counter++));
249   populateKeyset(new SanyoProjector(guiObject, counter++));
250
251   populateKeyset(new SharpTV1(guiObject, counter++));
252   populateKeyset(new SharpTV1a(guiObject, counter++));
253   populateKeyset(new SharpTV1b(guiObject, counter++));
254   populateKeyset(new SharpTV1c(guiObject, counter++));
255   populateKeyset(new SharpTV1d(guiObject, counter++));
256   populateKeyset(new SharpTV1e(guiObject, counter++));
257   populateKeyset(new SharpVCR1(guiObject, counter++));
258   populateKeyset(new SharpReceiver1(guiObject, counter++));
259
260   populateKeyset(new SonyTV1(guiObject, counter++));
261   populateKeyset(new SonyTV1a(guiObject, counter++));
262   populateKeyset(new SonyTV1b(guiObject, counter++));
263   populateKeyset(new SonyTV1d(guiObject, counter++));
264   populateKeyset(new SonyAmp1(guiObject, counter++));
265   populateKeyset(new SonyAmp2(guiObject, counter++));
266   populateKeyset(new SonyCD1(guiObject, counter++));
267   populateKeyset(new SonyCD1a(guiObject, counter++));
268   populateKeyset(new SonyCD2(guiObject, counter++));
269   populateKeyset(new SonyCD3(guiObject, counter++));
270   populateKeyset(new SonyDAT1(guiObject, counter++));
271   populateKeyset(new SonyDVD1(guiObject, counter++));
272   populateKeyset(new SonyDVD1a(guiObject, counter++));
273   populateKeyset(new SonyDVD1b(guiObject, counter++));
274   populateKeyset(new SonyDVD1c(guiObject, counter++));
275   populateKeyset(new SonyVCR1(guiObject, counter++));
276   populateKeyset(new SonyVCR1a(guiObject, counter++));
277   populateKeyset(new SonyReceiver1(guiObject, counter++));
278
279   populateKeyset(new Tivo1(guiObject, counter++));
280   populateKeyset(new Tivo1a(guiObject, counter++));
281   populateKeyset(new Tivo1b(guiObject, counter++));
282   populateKeyset(new Tivo1c(guiObject, counter++));
283   populateKeyset(new Tivo1d(guiObject, counter++));
284
285   populateKeyset(new ToshibaTV1(guiObject, counter++));
286   populateKeyset(new ToshibaTV1a(guiObject, counter++));
287   populateKeyset(new ToshibaTV1b(guiObject, counter++));
288   populateKeyset(new ToshibaTV1c(guiObject, counter++));
289   populateKeyset(new ToshibaTV1d(guiObject, counter++));
290   populateKeyset(new ToshibaTV1e(guiObject, counter++));
291   populateKeyset(new ToshibaTV1f(guiObject, counter++));
292   populateKeyset(new ToshibaVCR1(guiObject, counter++));
293   populateKeyset(new ToshibaVCR1a(guiObject, counter++));
294   populateKeyset(new ToshibaDisc1(guiObject, counter++));
295   populateKeyset(new ToshibaDisc1a(guiObject, counter++));
296   populateKeyset(new ToshibaDisc1b(guiObject, counter++));
297   populateKeyset(new ToshibaDisc1c(guiObject, counter++));
298   populateKeyset(new ToshibaDisc1d(guiObject, counter++));
299
300   populateKeyset(new WestinghouseTV1(guiObject, counter++));
301   populateKeyset(new WestinghouseTV2(guiObject, counter++));
302
303   populateKeyset(new YamahaDVD1(guiObject, counter++));
304   populateKeyset(new YamahaDVD1a(guiObject, counter++));
305   populateKeyset(new YamahaAudio1(guiObject, counter++));
306   populateKeyset(new YamahaAudio1a(guiObject, counter++));
307   populateKeyset(new YamahaAudio2(guiObject, counter++));
308   populateKeyset(new YamahaAudio2a(guiObject, counter++));
309   populateKeyset(new YamahaAudio2b(guiObject, counter++));
310   populateKeyset(new YamahaAudio2c(guiObject, counter++));
311   populateKeyset(new YamahaAudio2d(guiObject, counter++));
312   populateKeyset(new YamahaAudio3(guiObject, counter++));
313   populateKeyset(new YamahaAudio4(guiObject, counter++));
314   populateKeyset(new YamahaAudio5(guiObject, counter++));
315   populateKeyset(new YamahaAudio6(guiObject, counter++));
316   populateKeyset(new YamahaAudio7(guiObject, counter++));
317   populateKeyset(new YamahaTV1(guiObject, counter++));
318   populateKeyset(new YamahaKaraoke1(guiObject, counter++));
319
320   populateKeyset(new ZenithC32V37(guiObject, counter++));
321
322   // Start the thread running:
323   commandThread.start();
324 }
325
326
327 PIRKeysetManager::~PIRKeysetManager()
328 {
329   // Tell the keysets to stop doing any work:
330   {
331     QMutexLocker locker(&stopRepeatingMutex);
332     stopRepeatingFlag = true;
333   }
334
335   // Tell the thread that we want it to stop:
336   commandThread.exit();
337
338   // Wait for the thread to stop:
339   commandThread.wait();
340
341   // Delete all the keysets:
342   PIRKeysetCollection::iterator i = keysetsInfo.begin();
343   while (i != keysetsInfo.end())
344   {
345     if ((*i).second) delete (*i).second;
346     ++i;
347   }
348 }
349
350
351 bool PIRKeysetManager::keysetExists(
352   unsigned int keysetID)
353 {
354   PIRKeysetCollection::const_iterator i = keysetsInfo.find(keysetID);
355
356   return (i != keysetsInfo.end());
357 }
358
359
360 bool PIRKeysetManager::hasKey(
361   unsigned int keysetID,
362   PIRKeyName name)
363 {
364   PIRKeysetMetaData *meta = keysetsInfo[keysetID];
365
366   if (!meta) return false;
367
368   return meta->hasKey(name);
369 }
370
371
372 PIRMakeName PIRKeysetManager::getMake(
373   unsigned int keysetID)
374 {
375   PIRKeysetMetaData *meta = keysetsInfo[keysetID];
376
377   if (!meta) return Any_Make; // Work on this!
378
379   return meta->getMake();
380 }
381
382
383 QString PIRKeysetManager::getDisplayName(
384   unsigned int keysetID)
385 {
386   PIRKeysetMetaData *meta = keysetsInfo[keysetID];
387
388   if (!meta) return QString("Database Error");
389
390   return QString(meta->getKeysetName());
391 }
392
393
394 void PIRKeysetManager::populateKeyset(
395   PIRKeysetMetaData *keyset)
396 {
397   keysetsInfo[keyset->getID()] = keyset;
398
399   keyset->moveProtocolToThread(commandThread);
400 }
401
402
403 void PIRKeysetManager::populateGuiWidget(
404   PIRSelectKeysetForm *skf)
405 {
406   PIRMakeName make;
407   PIRKeysetWidgetItem *kwi;
408
409   PIRKeysetCollection::const_iterator i = keysetsInfo.begin();
410
411   while (i != keysetsInfo.end())
412   {
413     make = i->second->getMake();
414     QString tempString = makeManager.getMakeString(make);
415     tempString.append(" ");
416     tempString.append(i->second->getKeysetName());
417     kwi = new PIRKeysetWidgetItem(tempString, i->first, make);
418     i->second->populateDeviceTypes(kwi);
419     skf->addWidgetItem(kwi);
420     ++i;
421   }
422 }
423
424
425 void PIRKeysetManager::populateDeviceTypes(
426   PIRKeysetWidgetItem *kwi,
427   unsigned int keysetID)
428 {
429   // Pass the buck:  (Need to check for bad keysetID here?)
430   keysetsInfo[keysetID]->populateDeviceTypes(kwi);
431 }