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/elgato.h"
7 #include "keysets/goldstar.h"
8 #include "keysets/hauppauge.h"
9 #include "keysets/hitachi.h"
10 #include "keysets/jvc.h"
11 #include "keysets/lg.h"
12 #include "keysets/magnavox.h"
13 #include "keysets/mitsubishi.h"
14 #include "keysets/nokia.h"
15 #include "keysets/panasonic.h"
16 #include "keysets/philips.h"
17 #include "keysets/pinnacle.h"
18 #include "keysets/pioneer.h"
19 #include "keysets/raite.h"
20 #include "keysets/rca.h"
21 #include "keysets/sagem.h"
22 #include "keysets/samsung.h"
23 #include "keysets/sanyo.h"
24 #include "keysets/sharp.h"
25 #include "keysets/sony.h"
26 #include "keysets/tivo.h"
27 #include "keysets/toshiba.h"
28 #include "keysets/westinghouse.h"
29 #include "keysets/yamaha.h"
30 #include "keysets/zenith.h"
31 #include "pirmakenames.h"
33 #include "pirexception.h"
37 // I'll be handling the threading of the keyset commands in this object:
40 // Global communications mechanism:
41 extern bool stopRepeatingFlag;
42 extern QMutex stopRepeatingMutex;
44 // Global helper objects:
45 PIRMakeMgr makeManager;
46 PIRDeviceTypeMgr deviceManager;
48 // Now, on to the actual method definitions:
50 PIRKeysetManager::PIRKeysetManager(
54 // Create the keysets. Ugly! This needs to be worked on!
55 populateKeyset(new AppleWhiteRemote(guiObject, counter++));
57 populateKeyset(new DenonDVD1(guiObject, counter++));
58 populateKeyset(new DenonDVD2(guiObject, counter++));
59 populateKeyset(new DenonDVD3(guiObject, counter++));
60 populateKeyset(new DenonReceiver1(guiObject, counter++));
61 populateKeyset(new DenonReceiver1a(guiObject, counter++));
62 populateKeyset(new DenonReceiver1b(guiObject, counter++));
63 populateKeyset(new DenonReceiver1c(guiObject, counter++));
64 populateKeyset(new DenonReceiver1d(guiObject, counter++));
65 populateKeyset(new DenonReceiver1e(guiObject, counter++));
66 populateKeyset(new DenonReceiver1f(guiObject, counter++));
67 populateKeyset(new DenonReceiver2(guiObject, counter++));
68 populateKeyset(new DenonReceiver2a(guiObject, counter++));
69 populateKeyset(new DenonReceiver3(guiObject, counter++));
70 populateKeyset(new DenonAudio1(guiObject, counter++));
71 populateKeyset(new DenonAudio1a(guiObject, counter++));
72 populateKeyset(new DenonAudio1b(guiObject, counter++));
73 populateKeyset(new DenonAudio1c(guiObject, counter++));
74 populateKeyset(new DenonAudio1d(guiObject, counter++));
75 populateKeyset(new DenonAudio2(guiObject, counter++));
76 populateKeyset(new DenonAudio3(guiObject, counter++));
77 populateKeyset(new DenonAudio4(guiObject, counter++));
79 populateKeyset(new EiTV1(guiObject, counter++));
81 populateKeyset(new ElgatoEyeTV1(guiObject, counter++));
83 populateKeyset(new GoldStarTV1(guiObject, counter++));
84 populateKeyset(new GoldStarTV2(guiObject, counter++));
85 populateKeyset(new GoldStarVCR1(guiObject, counter++));
86 populateKeyset(new GoldStarVCR1a(guiObject, counter++));
87 populateKeyset(new GoldStarVCR1b(guiObject, counter++));
88 populateKeyset(new GoldStarVCR1c(guiObject, counter++));
89 populateKeyset(new GoldStarCD1(guiObject, counter++));
91 populateKeyset(new HauppaugePCTV1(guiObject, counter++));
92 populateKeyset(new HauppaugePCTV1a(guiObject, counter++));
93 populateKeyset(new HauppaugePCTV1b(guiObject, counter++));
94 populateKeyset(new HauppaugePCTV1c(guiObject, counter++));
95 populateKeyset(new HauppaugePCTV2(guiObject, counter++));
97 populateKeyset(new JVCSat1(guiObject, counter++));
98 populateKeyset(new JVCSat2(guiObject, counter++));
99 populateKeyset(new JVCVCR1(guiObject, counter++));
100 populateKeyset(new JVCVCR1a(guiObject, counter++));
101 populateKeyset(new JVCVCRBmode1(guiObject, counter++));
102 populateKeyset(new JVCVCRBmode1a(guiObject, counter++));
103 populateKeyset(new JVCTV1(guiObject, counter++));
104 populateKeyset(new JVCTV1a(guiObject, counter++));
105 populateKeyset(new JVCTV1b(guiObject, counter++));
106 populateKeyset(new JVCTV1c(guiObject, counter++));
107 populateKeyset(new JVCTV1d(guiObject, counter++));
108 populateKeyset(new JVCDAT1(guiObject, counter++));
109 populateKeyset(new JVCCarDeck1(guiObject, counter++));
110 populateKeyset(new JVCAudio1(guiObject, counter++));
111 populateKeyset(new JVCAudio1a(guiObject, counter++));
112 populateKeyset(new JVCAudio1b(guiObject, counter++));
113 populateKeyset(new JVCAudio2(guiObject, counter++));
114 populateKeyset(new JVCDVD1(guiObject, counter++));
116 populateKeyset(new LGTV1(guiObject, counter++));
117 populateKeyset(new LGTV1a(guiObject, counter++));
118 populateKeyset(new LGTV1b(guiObject, counter++));
119 populateKeyset(new LGTV1c(guiObject, counter++));
120 populateKeyset(new LGTV2(guiObject, counter++));
121 populateKeyset(new LGTV2a(guiObject, counter++));
122 populateKeyset(new LGTV2b(guiObject, counter++));
123 // populateKeyset(new LGDisc1(guiObject, counter++));
124 // populateKeyset(new LGDisc2(guiObject, counter++));
125 // populateKeyset(new LGDisc2a(guiObject, counter++));
126 populateKeyset(new LGVCR1(guiObject, counter++));
127 populateKeyset(new LGVCR1a(guiObject, counter++));
128 populateKeyset(new LGVCR1b(guiObject, counter++));
130 populateKeyset(new MagnavoxDVD1(guiObject, counter++));
131 populateKeyset(new MagnavoxVCR1(guiObject, counter++));
132 populateKeyset(new MagnavoxConverterBox1(guiObject, counter++));
133 populateKeyset(new MagnavoxTV1(guiObject, counter++));
135 populateKeyset(new MitsubishiTV1(guiObject, counter++));
136 populateKeyset(new MitsubishiTV1a(guiObject, counter++));
137 populateKeyset(new MitsubishiVCR1(guiObject, counter++));
138 populateKeyset(new MitsubishiVCR1a(guiObject, counter++));
140 populateKeyset(new NokiaGenericVCR(guiObject, counter++));
142 populateKeyset(new PanasonicAmp(guiObject, counter++));
143 populateKeyset(new PanasonicCarAudio(guiObject, counter++));
144 populateKeyset(new PanasonicSat1(guiObject, counter++));
145 populateKeyset(new PanasonicSat1a(guiObject, counter++));
146 populateKeyset(new PanasonicTV1(guiObject, counter++));
147 populateKeyset(new PanasonicTV1a(guiObject, counter++));
148 populateKeyset(new PanasonicTV1b(guiObject, counter++));
149 populateKeyset(new PanasonicVCR1(guiObject, counter++));
150 populateKeyset(new PanasonicVCR1a(guiObject, counter++));
151 populateKeyset(new PanasonicVCR1b(guiObject, counter++));
152 populateKeyset(new PanasonicVCR1c(guiObject, counter++));
153 populateKeyset(new PanasonicDVD1(guiObject, counter++));
154 populateKeyset(new PanasonicDVD1a(guiObject, counter++));
155 populateKeyset(new PanasonicAudio1(guiObject, counter++));
156 populateKeyset(new PanasonicAudio1a(guiObject, counter++));
158 populateKeyset(new PhilipsTV1(guiObject, counter++));
159 populateKeyset(new PhilipsTV1a(guiObject, counter++));
160 populateKeyset(new PhilipsTV1b(guiObject, counter++));
161 populateKeyset(new PhilipsTV1c(guiObject, counter++));
162 populateKeyset(new PhilipsTV1d(guiObject, counter++));
163 populateKeyset(new PhilipsTV1e(guiObject, counter++));
164 populateKeyset(new PhilipsTV1f(guiObject, counter++));
165 populateKeyset(new PhilipsTV2(guiObject, counter++));
166 populateKeyset(new PhilipsTV2a(guiObject, counter++));
167 populateKeyset(new PhilipsTV2b(guiObject, counter++));
168 populateKeyset(new PhilipsTV3(guiObject, counter++));
169 populateKeyset(new PhilipsDVD1(guiObject, counter++));
170 populateKeyset(new PhilipsDVD1a(guiObject, counter++));
171 populateKeyset(new PhilipsDVD1b(guiObject, counter++));
172 populateKeyset(new PhilipsDVD1c(guiObject, counter++));
173 populateKeyset(new PhilipsDVD1d(guiObject, counter++));
174 populateKeyset(new PhilipsDVD2(guiObject, counter++));
175 populateKeyset(new PhilipsDVD3(guiObject, counter++));
176 populateKeyset(new PhilipsDVD4(guiObject, counter++));
177 populateKeyset(new PhilipsVCR1(guiObject, counter++));
178 populateKeyset(new PhilipsVCR1a(guiObject, counter++));
179 populateKeyset(new PhilipsVCR1b(guiObject, counter++));
180 populateKeyset(new PhilipsVCR1c(guiObject, counter++));
181 populateKeyset(new PhilipsSat1(guiObject, counter++));
182 populateKeyset(new PhilipsSat2(guiObject, counter++));
183 populateKeyset(new PhilipsSat2a(guiObject, counter++));
184 populateKeyset(new PhilipsSat3(guiObject, counter++));
185 populateKeyset(new PhilipsAudio1(guiObject, counter++));
186 populateKeyset(new PhilipsAudio1a(guiObject, counter++));
187 populateKeyset(new PhilipsAudio1b(guiObject, counter++));
188 populateKeyset(new PhilipsAudio2(guiObject, counter++));
189 populateKeyset(new PhilipsAudio3(guiObject, counter++));
190 populateKeyset(new PhilipsAudio4(guiObject, counter++));
192 populateKeyset(new PinnaclePCTV1(guiObject, counter++));
193 populateKeyset(new PinnaclePCTV2(guiObject, counter++));
194 populateKeyset(new PinnaclePCTV3(guiObject, counter++));
196 populateKeyset(new PioneerTV1(guiObject, counter++));
197 populateKeyset(new PioneerTV2(guiObject, counter++));
198 populateKeyset(new PioneerTV3(guiObject, counter++));
199 populateKeyset(new PioneerAudio1(guiObject, counter++));
200 populateKeyset(new PioneerAudio1a(guiObject, counter++));
201 populateKeyset(new PioneerAudio2(guiObject, counter++));
202 populateKeyset(new PioneerAudio3(guiObject, counter++));
203 populateKeyset(new PioneerAudio4(guiObject, counter++));
204 populateKeyset(new PioneerAudio5(guiObject, counter++));
205 populateKeyset(new PioneerCD1(guiObject, counter++));
206 populateKeyset(new PioneerLaserDisc1(guiObject, counter++));
207 populateKeyset(new PioneerDVD1(guiObject, counter++));
209 populateKeyset(new RaiteDVD1(guiObject, counter++));
211 populateKeyset(new RCATV1(guiObject, counter++));
212 populateKeyset(new RCATV1a(guiObject, counter++));
213 populateKeyset(new RCATV2(guiObject, counter++));
214 populateKeyset(new RCAAux1(guiObject, counter++));
215 populateKeyset(new RCAAux2(guiObject, counter++));
216 populateKeyset(new RCAAux2a(guiObject, counter++));
217 populateKeyset(new RCAVCR1(guiObject, counter++));
218 populateKeyset(new RCAVCR2(guiObject, counter++));
219 populateKeyset(new RCADVD1(guiObject, counter++));
220 populateKeyset(new RCADVD1a(guiObject, counter++));
221 populateKeyset(new RCASat1(guiObject, counter++));
222 populateKeyset(new RCASat2(guiObject, counter++));
224 populateKeyset(new SagemTVBox1(guiObject, counter++));
225 populateKeyset(new SagemTVBox1a(guiObject, counter++));
227 populateKeyset(new SamsungTV1(guiObject, counter++));
228 populateKeyset(new SamsungTV1a(guiObject, counter++));
229 populateKeyset(new SamsungTV1b(guiObject, counter++));
230 populateKeyset(new SamsungTV1c(guiObject, counter++));
231 populateKeyset(new SamsungTV1d(guiObject, counter++));
232 populateKeyset(new SamsungTV1e(guiObject, counter++));
233 populateKeyset(new SamsungTV1f(guiObject, counter++));
234 populateKeyset(new SamsungTV2(guiObject, counter++));
235 populateKeyset(new SamsungTV2a(guiObject, counter++));
236 populateKeyset(new SamsungVCR1(guiObject, counter++));
237 populateKeyset(new SamsungVCR1a(guiObject, counter++));
238 populateKeyset(new SamsungVCR1b(guiObject, counter++));
239 populateKeyset(new SamsungVCR1c(guiObject, counter++));
240 populateKeyset(new SamsungVCR1d(guiObject, counter++));
241 populateKeyset(new SamsungVCR1e(guiObject, counter++));
242 populateKeyset(new SamsungDVD1(guiObject, counter++));
243 populateKeyset(new SamsungDVD1a(guiObject, counter++));
244 populateKeyset(new SamsungDVD1b(guiObject, counter++));
245 populateKeyset(new SamsungDVD2(guiObject, counter++));
246 populateKeyset(new SamsungAC1(guiObject, counter++));
248 populateKeyset(new SanyoVCR1(guiObject, counter++));
249 populateKeyset(new SanyoDVD1(guiObject, counter++));
250 populateKeyset(new SanyoTV1(guiObject, counter++));
251 populateKeyset(new SanyoTV1a(guiObject, counter++));
252 populateKeyset(new SanyoTV1b(guiObject, counter++));
253 populateKeyset(new SanyoTV1c(guiObject, counter++));
254 populateKeyset(new SanyoTV1d(guiObject, counter++));
255 populateKeyset(new SanyoTV1e(guiObject, counter++));
256 populateKeyset(new SanyoProjector(guiObject, counter++));
258 populateKeyset(new SharpTV1(guiObject, counter++));
259 populateKeyset(new SharpTV1a(guiObject, counter++));
260 populateKeyset(new SharpTV1b(guiObject, counter++));
261 populateKeyset(new SharpTV1c(guiObject, counter++));
262 populateKeyset(new SharpTV1d(guiObject, counter++));
263 populateKeyset(new SharpTV1e(guiObject, counter++));
264 populateKeyset(new SharpVCR1(guiObject, counter++));
265 populateKeyset(new SharpReceiver1(guiObject, counter++));
267 populateKeyset(new SonyTV1(guiObject, counter++));
268 populateKeyset(new SonyTV1a(guiObject, counter++));
269 populateKeyset(new SonyTV1b(guiObject, counter++));
270 populateKeyset(new SonyTV1c(guiObject, counter++));
271 populateKeyset(new SonyAmp1(guiObject, counter++));
272 populateKeyset(new SonyAmp2(guiObject, counter++));
273 populateKeyset(new SonyAudio1(guiObject, counter++));
274 populateKeyset(new SonyAudio1a(guiObject, counter++));
275 populateKeyset(new SonyDAT1(guiObject, counter++));
276 populateKeyset(new SonyDVD1(guiObject, counter++));
277 populateKeyset(new SonyDVD1a(guiObject, counter++));
278 populateKeyset(new SonyDVD1b(guiObject, counter++));
279 populateKeyset(new SonyDVD1c(guiObject, counter++));
280 populateKeyset(new SonyVCR1(guiObject, counter++));
281 populateKeyset(new SonyVCR1a(guiObject, counter++));
282 populateKeyset(new SonyVCR1b(guiObject, counter++));
283 populateKeyset(new SonyReceiver1(guiObject, counter++));
285 populateKeyset(new Tivo1(guiObject, counter++));
286 populateKeyset(new Tivo1a(guiObject, counter++));
287 populateKeyset(new Tivo1b(guiObject, counter++));
288 populateKeyset(new Tivo1c(guiObject, counter++));
289 populateKeyset(new Tivo1d(guiObject, counter++));
291 populateKeyset(new ToshibaTV1(guiObject, counter++));
292 populateKeyset(new ToshibaTV1a(guiObject, counter++));
293 populateKeyset(new ToshibaTV1b(guiObject, counter++));
294 populateKeyset(new ToshibaTV1c(guiObject, counter++));
295 populateKeyset(new ToshibaTV1d(guiObject, counter++));
296 populateKeyset(new ToshibaTV1e(guiObject, counter++));
297 populateKeyset(new ToshibaTV1f(guiObject, counter++));
298 populateKeyset(new ToshibaTV1g(guiObject, counter++));
299 populateKeyset(new ToshibaVCR1(guiObject, counter++));
300 populateKeyset(new ToshibaVCR1a(guiObject, counter++));
301 populateKeyset(new ToshibaDisc1(guiObject, counter++));
302 populateKeyset(new ToshibaDisc1a(guiObject, counter++));
303 populateKeyset(new ToshibaDisc1b(guiObject, counter++));
304 populateKeyset(new ToshibaDisc1c(guiObject, counter++));
305 populateKeyset(new ToshibaDisc1d(guiObject, counter++));
307 populateKeyset(new WestinghouseTV1(guiObject, counter++));
308 populateKeyset(new WestinghouseTV2(guiObject, counter++));
310 populateKeyset(new YamahaDVD1(guiObject, counter++));
311 populateKeyset(new YamahaDVD1a(guiObject, counter++));
312 populateKeyset(new YamahaAudio1(guiObject, counter++));
313 populateKeyset(new YamahaAudio1a(guiObject, counter++));
314 populateKeyset(new YamahaAudio2(guiObject, counter++));
315 populateKeyset(new YamahaAudio2a(guiObject, counter++));
316 populateKeyset(new YamahaAudio2b(guiObject, counter++));
317 populateKeyset(new YamahaAudio2c(guiObject, counter++));
318 populateKeyset(new YamahaAudio2d(guiObject, counter++));
319 populateKeyset(new YamahaAudio3(guiObject, counter++));
320 populateKeyset(new YamahaAudio4(guiObject, counter++));
321 populateKeyset(new YamahaTV1(guiObject, counter++));
322 populateKeyset(new YamahaKaraoke1(guiObject, counter++));
324 populateKeyset(new ZenithC32V37(guiObject, counter++));
326 // Start the thread running:
327 commandThread.start();
331 PIRKeysetManager::~PIRKeysetManager()
333 // Tell the keysets to stop doing any work:
335 QMutexLocker locker(&stopRepeatingMutex);
336 stopRepeatingFlag = true;
339 // Tell the thread that we want it to stop:
340 commandThread.exit();
342 // Wait for the thread to stop:
343 commandThread.wait();
345 // Delete all the keysets:
346 PIRKeysetCollection::iterator i = keysetsInfo.begin();
347 while (i != keysetsInfo.end())
349 if ((*i).second) delete (*i).second;
355 bool PIRKeysetManager::keysetExists(
356 unsigned int keysetID) const
358 PIRKeysetCollection::const_iterator i = keysetsInfo.find(keysetID);
360 return (i != keysetsInfo.end());
364 bool PIRKeysetManager::findKeysetID(
367 unsigned int &id) const
369 // Only modify the id if we actually find a match!
371 PIRKeysetMakeIndex::const_iterator i = makeIndex.find(make);
372 if (i == makeIndex.end())
377 PIRKeysetNameIndex::const_iterator ii = (*i).second.find(name);
378 if (ii == (*i).second.end())
383 // Ok, we've found it, pull out the id:
389 PIRKeysetWidgetItem *PIRKeysetManager::makeKeysetItem(
395 if (!findKeysetID(make, name, id))
400 QString fullname = make;
401 fullname.append(" ");
402 fullname.append(name);
404 return new PIRKeysetWidgetItem(fullname, id, getMake(id));
408 bool PIRKeysetManager::hasKey(
409 unsigned int keysetID,
410 PIRKeyName name) const
412 PIRKeysetCollection::const_iterator i = keysetsInfo.find(keysetID);
414 if ((i == keysetsInfo.end()) || !i->second) return false;
416 return i->second->hasKey(name);
420 PIRMakeName PIRKeysetManager::getMake(
421 unsigned int keysetID) const
423 PIRKeysetCollection::const_iterator i = keysetsInfo.find(keysetID);
425 if ((i == keysetsInfo.end()) || !i->second) return Any_Make;
427 return i->second->getMake();
431 QString PIRKeysetManager::getDisplayName(
432 unsigned int keysetID) const
434 PIRKeysetCollection::const_iterator i = keysetsInfo.find(keysetID);
436 if ((i == keysetsInfo.end()) || !i->second)
437 return QString("Database Error");
439 return QString(i->second->getKeysetName());
443 void PIRKeysetManager::populateKeyset(
444 PIRKeysetMetaData *keyset)
446 // Set up the keyset collection:
447 keysetsInfo[keyset->getID()] = keyset;
449 keyset->moveProtocolToThread(commandThread);
451 // Also, set up a name-based index into the collection:
453 [QString(makeManager.getMakeString(keyset->getMake()))]
454 [QString(keyset->getKeysetName())]
459 void PIRKeysetManager::populateGuiWidget(
460 PIRSelectKeysetForm *skf) const
463 PIRKeysetWidgetItem *kwi;
465 PIRKeysetCollection::const_iterator i = keysetsInfo.begin();
467 while (i != keysetsInfo.end())
469 make = i->second->getMake();
470 QString tempString = makeManager.getMakeString(make);
471 tempString.append(" ");
472 tempString.append(i->second->getKeysetName());
473 kwi = new PIRKeysetWidgetItem(tempString, i->first, make);
474 i->second->populateDeviceTypes(kwi);
475 skf->addWidgetItem(kwi);
481 void PIRKeysetManager::populateDeviceTypes(
482 PIRKeysetWidgetItem *kwi,
483 unsigned int keysetID) const
485 PIRKeysetCollection::const_iterator i = keysetsInfo.find(keysetID);
486 if ((i != keysetsInfo.end()) && i->second)
488 i->second->populateDeviceTypes(kwi);