15d0de05890b01a63815c7c2b2008918a7dcb0fc
[pierogi] / pirkeysetmanager.cpp
1 #include "pirkeysetmanager.h"
2
3 #include "pirkeysetmetadata.h"
4 #include "pirselectkeysetform.h"
5 #include "pirkeysetwidgetitem.h"
6
7 #include "keysets/acer.h"
8 #include "keysets/admiral.h"
9 #include "keysets/aiwa.h"
10 #include "keysets/apple.h"
11 #include "keysets/bose.h"
12 #include "keysets/daewoo.h"
13 #include "keysets/denon.h"
14 #include "keysets/ei.h"
15 #include "keysets/elgato.h"
16 #include "keysets/goldstar.h"
17 #include "keysets/grundig.h"
18 #include "keysets/hauppauge.h"
19 #include "keysets/hitachi.h"
20 #include "keysets/jvc.h"
21 #include "keysets/lg.h"
22 #include "keysets/logitech.h"
23 #include "keysets/magnavox.h"
24 #include "keysets/mce.h"
25 #include "keysets/mitsubishi.h"
26 #include "keysets/nokia.h"
27 #include "keysets/panasonic.h"
28 #include "keysets/philco.h"
29 #include "keysets/philips.h"
30 #include "keysets/pinnacle.h"
31 #include "keysets/pioneer.h"
32 #include "keysets/raite.h"
33 #include "keysets/rca.h"
34 #include "keysets/roku.h"
35 #include "keysets/sagem.h"
36 #include "keysets/samsung.h"
37 #include "keysets/sanyo.h"
38 #include "keysets/sharp.h"
39 #include "keysets/sony.h"
40 #include "keysets/tivo.h"
41 #include "keysets/topfield.h"
42 #include "keysets/toshiba.h"
43 #include "keysets/westinghouse.h"
44 #include "keysets/yamaha.h"
45 #include "keysets/zenith.h"
46
47 #include "pirexception.h"
48
49 // I'll be handling the threading of the keyset commands in this object:
50 #include <QMutex>
51
52 // Global communications mechanism:
53 extern bool stopRepeatingFlag;
54 extern QMutex stopRepeatingMutex;
55
56 // Global helper objects:
57 PIRMakeMgr makeManager;
58 PIRDeviceTypeMgr deviceManager;
59
60 // Now, on to the actual method definitions:
61
62 PIRKeysetManager::PIRKeysetManager(
63   QObject *guiObject)
64   : counter(0)
65 {
66   // Create the keysets.  Ugly!  This needs to be worked on!
67   populateKeyset(new AcerTV1(guiObject, counter++));
68   populateKeyset(new AcerPC1(guiObject, counter++));
69
70   populateKeyset(new AdmiralTV1(guiObject, counter++));
71   populateKeyset(new AdmiralVCR1(guiObject, counter++));
72
73   populateKeyset(new AiwaVCR1(guiObject, counter++));
74   populateKeyset(new AiwaVCR2(guiObject, counter++));
75   populateKeyset(new AiwaVCR3(guiObject, counter++));
76   populateKeyset(new AiwaAudio1(guiObject, counter++));
77   populateKeyset(new AiwaAudio1a(guiObject, counter++));
78   populateKeyset(new AiwaAudio2(guiObject, counter++));
79   populateKeyset(new AiwaAudio2a(guiObject, counter++));
80   populateKeyset(new AiwaAudio2b(guiObject, counter++));
81   populateKeyset(new AiwaAudio2c(guiObject, counter++));
82   populateKeyset(new AiwaAudio3(guiObject, counter++));
83   populateKeyset(new AiwaAudio4(guiObject, counter++));
84   populateKeyset(new AiwaAudio5(guiObject, counter++));
85   populateKeyset(new AiwaAudio6(guiObject, counter++));
86   populateKeyset(new AiwaCarStereo1(guiObject, counter++));
87   populateKeyset(new AiwaDVD1(guiObject, counter++));
88
89   populateKeyset(new AppleWhiteRemote(guiObject, counter++));
90
91   populateKeyset(new BoseRadio1(guiObject, counter++));
92   populateKeyset(new BoseRadio2(guiObject, counter++));
93   populateKeyset(new BoseRadio3(guiObject, counter++));
94
95   populateKeyset(new DaewooTV1(guiObject, counter++));
96   populateKeyset(new DaewooTV2(guiObject, counter++));
97   populateKeyset(new DaewooDVD1(guiObject, counter++));
98   populateKeyset(new DaewooVCR1(guiObject, counter++));
99   populateKeyset(new DaewooVCR2(guiObject, counter++));
100
101   populateKeyset(new DenonDVD1(guiObject, counter++));
102   populateKeyset(new DenonDVD2(guiObject, counter++));
103   populateKeyset(new DenonDVD3(guiObject, counter++));
104   populateKeyset(new DenonReceiver1(guiObject, counter++));
105   populateKeyset(new DenonReceiver1a(guiObject, counter++));
106   populateKeyset(new DenonReceiver1b(guiObject, counter++));
107   populateKeyset(new DenonReceiver1c(guiObject, counter++));
108   populateKeyset(new DenonReceiver1d(guiObject, counter++));
109   populateKeyset(new DenonReceiver1e(guiObject, counter++));
110   populateKeyset(new DenonReceiver1f(guiObject, counter++));
111   populateKeyset(new DenonReceiver2(guiObject, counter++));
112   populateKeyset(new DenonReceiver2a(guiObject, counter++));
113   populateKeyset(new DenonReceiver3(guiObject, counter++));
114   populateKeyset(new DenonAudio1(guiObject, counter++));
115   populateKeyset(new DenonAudio1a(guiObject, counter++));
116   populateKeyset(new DenonAudio1b(guiObject, counter++));
117   populateKeyset(new DenonAudio1c(guiObject, counter++));
118   populateKeyset(new DenonAudio1d(guiObject, counter++));
119   populateKeyset(new DenonAudio2(guiObject, counter++));
120   populateKeyset(new DenonAudio3(guiObject, counter++));
121   populateKeyset(new DenonAudio4(guiObject, counter++));
122
123   populateKeyset(new EiTV1(guiObject, counter++));
124
125   populateKeyset(new ElgatoEyeTV1(guiObject, counter++));
126
127   populateKeyset(new GoldStarTV1(guiObject, counter++));
128   populateKeyset(new GoldStarTV2(guiObject, counter++));
129   populateKeyset(new GoldStarVCR1(guiObject, counter++));
130   populateKeyset(new GoldStarVCR1a(guiObject, counter++));
131   populateKeyset(new GoldStarVCR1b(guiObject, counter++));
132   populateKeyset(new GoldStarVCR1c(guiObject, counter++));
133   populateKeyset(new GoldStarCD1(guiObject, counter++));
134
135   populateKeyset(new GrundigSat1(guiObject, counter++));
136   populateKeyset(new GrundigSat2(guiObject, counter++));
137   populateKeyset(new GrundigAmp1(guiObject, counter++));
138   populateKeyset(new GrundigAudio1(guiObject, counter++));
139   populateKeyset(new GrundigAudio2(guiObject, counter++));
140   populateKeyset(new GrundigVCR1(guiObject, counter++));
141   populateKeyset(new GrundigVCR1a(guiObject, counter++));
142   populateKeyset(new GrundigTV1(guiObject, counter++));
143   populateKeyset(new GrundigTV2(guiObject, counter++));
144   populateKeyset(new GrundigTV3(guiObject, counter++));
145   populateKeyset(new GrundigDVD1(guiObject, counter++));
146
147   populateKeyset(new HauppaugePCTV1(guiObject, counter++));
148   populateKeyset(new HauppaugePCTV1a(guiObject, counter++));
149   populateKeyset(new HauppaugePCTV1b(guiObject, counter++));
150   populateKeyset(new HauppaugePCTV1c(guiObject, counter++));
151   populateKeyset(new HauppaugePCTV2(guiObject, counter++));
152
153   populateKeyset(new HitachiTV1(guiObject, counter++));
154   populateKeyset(new HitachiTV1a(guiObject, counter++));
155   populateKeyset(new HitachiTV1b(guiObject, counter++));
156   populateKeyset(new HitachiTV1c(guiObject, counter++));
157   populateKeyset(new HitachiTV2(guiObject, counter++));
158   populateKeyset(new HitachiTV3(guiObject, counter++));
159   populateKeyset(new HitachiProjector(guiObject, counter++));
160   populateKeyset(new HitachiDVD1(guiObject, counter++));
161   populateKeyset(new HitachiAudio1(guiObject, counter++));
162   populateKeyset(new HitachiVCR1(guiObject, counter++));
163
164   populateKeyset(new JVCSat1(guiObject, counter++));
165   populateKeyset(new JVCSat2(guiObject, counter++));
166   populateKeyset(new JVCVCR1(guiObject, counter++));
167   populateKeyset(new JVCVCR1a(guiObject, counter++));
168   populateKeyset(new JVCVCRBmode1(guiObject, counter++));
169   populateKeyset(new JVCVCRBmode1a(guiObject, counter++));
170   populateKeyset(new JVCTV1(guiObject, counter++));
171   populateKeyset(new JVCTV1a(guiObject, counter++));
172   populateKeyset(new JVCTV1b(guiObject, counter++));
173   populateKeyset(new JVCTV1c(guiObject, counter++));
174   populateKeyset(new JVCTV1d(guiObject, counter++));
175   populateKeyset(new JVCDAT1(guiObject, counter++));
176   populateKeyset(new JVCCarDeck1(guiObject, counter++));
177   populateKeyset(new JVCAudio1(guiObject, counter++));
178   populateKeyset(new JVCAudio1a(guiObject, counter++));
179   populateKeyset(new JVCAudio1b(guiObject, counter++));
180   populateKeyset(new JVCAudio2(guiObject, counter++));
181   populateKeyset(new JVCDVD1(guiObject, counter++));
182
183   populateKeyset(new LGTV1(guiObject, counter++));
184   populateKeyset(new LGTV1a(guiObject, counter++));
185   populateKeyset(new LGTV1b(guiObject, counter++));
186   populateKeyset(new LGTV1c(guiObject, counter++));
187   populateKeyset(new LGTV2(guiObject, counter++));
188   populateKeyset(new LGTV2a(guiObject, counter++));
189   populateKeyset(new LGTV2b(guiObject, counter++));
190   populateKeyset(new LGDisc1(guiObject, counter++));
191   populateKeyset(new LGDisc2(guiObject, counter++));
192   populateKeyset(new LGDisc2a(guiObject, counter++));
193   populateKeyset(new LGVCR1(guiObject, counter++));
194   populateKeyset(new LGVCR1a(guiObject, counter++));
195   populateKeyset(new LGVCR1b(guiObject, counter++));
196
197   populateKeyset(new LogitechSpeakers(guiObject, counter++));
198
199   populateKeyset(new MagnavoxDVD1(guiObject, counter++));
200   populateKeyset(new MagnavoxVCR1(guiObject, counter++));
201   populateKeyset(new MagnavoxConverterBox1(guiObject, counter++));
202   populateKeyset(new MagnavoxTV1(guiObject, counter++));
203
204   populateKeyset(new MCERemote1(guiObject, counter++));
205   populateKeyset(new MCERemote1a(guiObject, counter++));
206   populateKeyset(new MCERemote1b(guiObject, counter++));
207   populateKeyset(new MCERemote1c(guiObject, counter++));
208   populateKeyset(new MCERemote1d(guiObject, counter++));
209   populateKeyset(new MCERemote1e(guiObject, counter++));
210   populateKeyset(new MCERemote1f(guiObject, counter++));
211   populateKeyset(new MCERemote1g(guiObject, counter++));
212
213   populateKeyset(new MitsubishiTV1(guiObject, counter++));
214   populateKeyset(new MitsubishiTV1a(guiObject, counter++));
215   populateKeyset(new MitsubishiVCR1(guiObject, counter++));
216   populateKeyset(new MitsubishiVCR1a(guiObject, counter++));
217
218   populateKeyset(new NokiaGenericVCR(guiObject, counter++));
219
220   populateKeyset(new PanasonicCarAudio(guiObject, counter++));
221   populateKeyset(new PanasonicSat1(guiObject, counter++));
222   populateKeyset(new PanasonicSat1a(guiObject, counter++));
223   populateKeyset(new PanasonicTV1(guiObject, counter++));
224   populateKeyset(new PanasonicTV1a(guiObject, counter++));
225   populateKeyset(new PanasonicTV1b(guiObject, counter++));
226   populateKeyset(new PanasonicVCR1(guiObject, counter++));
227   populateKeyset(new PanasonicVCR1a(guiObject, counter++));
228   populateKeyset(new PanasonicVCR1b(guiObject, counter++));
229   populateKeyset(new PanasonicVCR1c(guiObject, counter++));
230   populateKeyset(new PanasonicDVD1(guiObject, counter++));
231   populateKeyset(new PanasonicDVD1a(guiObject, counter++));
232   populateKeyset(new PanasonicAudio1(guiObject, counter++));
233
234   populateKeyset(new PhilcoTV(guiObject, counter++));
235
236   populateKeyset(new PhilipsTV1(guiObject, counter++));
237   populateKeyset(new PhilipsTV1a(guiObject, counter++));
238   populateKeyset(new PhilipsTV1b(guiObject, counter++));
239   populateKeyset(new PhilipsTV1c(guiObject, counter++));
240   populateKeyset(new PhilipsTV1d(guiObject, counter++));
241   populateKeyset(new PhilipsTV1e(guiObject, counter++));
242   populateKeyset(new PhilipsTV1f(guiObject, counter++));
243   populateKeyset(new PhilipsTV2(guiObject, counter++));
244   populateKeyset(new PhilipsTV2a(guiObject, counter++));
245   populateKeyset(new PhilipsTV2b(guiObject, counter++));
246   populateKeyset(new PhilipsTV3(guiObject, counter++));
247   populateKeyset(new PhilipsDVD1(guiObject, counter++));
248   populateKeyset(new PhilipsDVD1a(guiObject, counter++));
249   populateKeyset(new PhilipsDVD1b(guiObject, counter++));
250   populateKeyset(new PhilipsDVD1c(guiObject, counter++));
251   populateKeyset(new PhilipsDVD1d(guiObject, counter++));
252   populateKeyset(new PhilipsDVD2(guiObject, counter++));
253   populateKeyset(new PhilipsDVD3(guiObject, counter++));
254   populateKeyset(new PhilipsDVD4(guiObject, counter++));
255   populateKeyset(new PhilipsVCR1(guiObject, counter++));
256   populateKeyset(new PhilipsVCR1a(guiObject, counter++));
257   populateKeyset(new PhilipsVCR1b(guiObject, counter++));
258   populateKeyset(new PhilipsVCR1c(guiObject, counter++));
259   populateKeyset(new PhilipsSat1(guiObject, counter++));
260   populateKeyset(new PhilipsSat2(guiObject, counter++));
261   populateKeyset(new PhilipsSat2a(guiObject, counter++));
262   populateKeyset(new PhilipsSat3(guiObject, counter++));
263   populateKeyset(new PhilipsAudio1(guiObject, counter++));
264   populateKeyset(new PhilipsAudio1a(guiObject, counter++));
265   populateKeyset(new PhilipsAudio1b(guiObject, counter++));
266   populateKeyset(new PhilipsAudio2(guiObject, counter++));
267   populateKeyset(new PhilipsAudio3(guiObject, counter++));
268   populateKeyset(new PhilipsAudio4(guiObject, counter++));
269
270   populateKeyset(new PinnaclePCTV1(guiObject, counter++));
271   populateKeyset(new PinnaclePCTV2(guiObject, counter++));
272   populateKeyset(new PinnaclePCTV3(guiObject, counter++));
273
274   populateKeyset(new PioneerTV1(guiObject, counter++));
275   populateKeyset(new PioneerTV2(guiObject, counter++));
276   populateKeyset(new PioneerTV3(guiObject, counter++));
277   populateKeyset(new PioneerAudio1(guiObject, counter++));
278   populateKeyset(new PioneerAudio1a(guiObject, counter++));
279   populateKeyset(new PioneerAudio2(guiObject, counter++));
280   populateKeyset(new PioneerAudio3(guiObject, counter++));
281   populateKeyset(new PioneerAudio4(guiObject, counter++));
282   populateKeyset(new PioneerAudio5(guiObject, counter++));
283   populateKeyset(new PioneerCD1(guiObject, counter++));
284   populateKeyset(new PioneerLaserDisc1(guiObject, counter++));
285   populateKeyset(new PioneerDVD1(guiObject, counter++));
286
287   populateKeyset(new RaiteDVD1(guiObject, counter++));
288
289   populateKeyset(new RCATV1(guiObject, counter++));
290   populateKeyset(new RCATV1a(guiObject, counter++));
291   populateKeyset(new RCATV1b(guiObject, counter++));
292 /*
293   populateKeyset(new RCAAux1(guiObject, counter++));
294   populateKeyset(new RCAAux2(guiObject, counter++));
295   populateKeyset(new RCAAux2a(guiObject, counter++));
296 */
297   populateKeyset(new RCAVCR1(guiObject, counter++));
298   populateKeyset(new RCAVCR1a(guiObject, counter++));
299   populateKeyset(new RCADVD1(guiObject, counter++));
300   populateKeyset(new RCADVD1a(guiObject, counter++));
301   populateKeyset(new RCASat1(guiObject, counter++));
302   populateKeyset(new RCASat2(guiObject, counter++));
303
304   populateKeyset(new RokuBox1(guiObject, counter++));
305   populateKeyset(new RokuBox2(guiObject, counter++));
306
307   populateKeyset(new SagemTVBox1(guiObject, counter++));
308   populateKeyset(new SagemTVBox1a(guiObject, counter++));
309
310   populateKeyset(new SamsungTV1(guiObject, counter++));
311   populateKeyset(new SamsungTV1a(guiObject, counter++));
312   populateKeyset(new SamsungTV1b(guiObject, counter++));
313   populateKeyset(new SamsungTV1c(guiObject, counter++));
314   populateKeyset(new SamsungTV1d(guiObject, counter++));
315   populateKeyset(new SamsungTV1e(guiObject, counter++));
316   populateKeyset(new SamsungTV1f(guiObject, counter++));
317   populateKeyset(new SamsungTV2(guiObject, counter++));
318   populateKeyset(new SamsungTV2a(guiObject, counter++));
319   populateKeyset(new SamsungVCR1(guiObject, counter++));
320   populateKeyset(new SamsungVCR1a(guiObject, counter++));
321   populateKeyset(new SamsungVCR1b(guiObject, counter++));
322   populateKeyset(new SamsungVCR1c(guiObject, counter++));
323   populateKeyset(new SamsungVCR1d(guiObject, counter++));
324   populateKeyset(new SamsungVCR1e(guiObject, counter++));
325   populateKeyset(new SamsungDVD1(guiObject, counter++));
326   populateKeyset(new SamsungDVD1a(guiObject, counter++));
327   populateKeyset(new SamsungDVD1b(guiObject, counter++));
328   populateKeyset(new SamsungDVD2(guiObject, counter++));
329   populateKeyset(new SamsungAC1(guiObject, counter++));
330
331   populateKeyset(new SanyoVCR1(guiObject, counter++));
332   populateKeyset(new SanyoDVD1(guiObject, counter++));
333   populateKeyset(new SanyoTV1(guiObject, counter++));
334   populateKeyset(new SanyoTV1a(guiObject, counter++));
335   populateKeyset(new SanyoTV1b(guiObject, counter++));
336   populateKeyset(new SanyoTV1c(guiObject, counter++));
337   populateKeyset(new SanyoTV1d(guiObject, counter++));
338   populateKeyset(new SanyoProjector(guiObject, counter++));
339
340   populateKeyset(new SharpTV1(guiObject, counter++));
341   populateKeyset(new SharpTV1a(guiObject, counter++));
342   populateKeyset(new SharpTV1b(guiObject, counter++));
343   populateKeyset(new SharpTV1c(guiObject, counter++));
344   populateKeyset(new SharpTV1d(guiObject, counter++));
345   populateKeyset(new SharpTV1e(guiObject, counter++));
346   populateKeyset(new SharpVCR1(guiObject, counter++));
347   populateKeyset(new SharpReceiver1(guiObject, counter++));
348
349   populateKeyset(new SonyTV1(guiObject, counter++));
350   populateKeyset(new SonyTV1a(guiObject, counter++));
351   populateKeyset(new SonyTV1b(guiObject, counter++));
352   populateKeyset(new SonyTV1c(guiObject, counter++));
353   populateKeyset(new SonyAmp1(guiObject, counter++));
354   populateKeyset(new SonyAmp2(guiObject, counter++));
355   populateKeyset(new SonyAudio1(guiObject, counter++));
356   populateKeyset(new SonyAudio1a(guiObject, counter++));
357   populateKeyset(new SonyDAT1(guiObject, counter++));
358   populateKeyset(new SonyDVD1(guiObject, counter++));
359   populateKeyset(new SonyDVD1a(guiObject, counter++));
360   populateKeyset(new SonyDVD1b(guiObject, counter++));
361   populateKeyset(new SonyDVD1c(guiObject, counter++));
362   populateKeyset(new SonyVCR1(guiObject, counter++));
363   populateKeyset(new SonyVCR1a(guiObject, counter++));
364   populateKeyset(new SonyVCR1b(guiObject, counter++));
365   populateKeyset(new SonyReceiver1(guiObject, counter++));
366
367   populateKeyset(new Tivo1(guiObject, counter++));
368   populateKeyset(new Tivo1a(guiObject, counter++));
369   populateKeyset(new Tivo1b(guiObject, counter++));
370   populateKeyset(new Tivo1c(guiObject, counter++));
371   populateKeyset(new Tivo1d(guiObject, counter++));
372
373   populateKeyset(new TopfieldPVR1(guiObject, counter++));
374   populateKeyset(new TopfieldSat1(guiObject, counter++));
375
376   populateKeyset(new ToshibaTV1(guiObject, counter++));
377   populateKeyset(new ToshibaTV1a(guiObject, counter++));
378   populateKeyset(new ToshibaTV1b(guiObject, counter++));
379   populateKeyset(new ToshibaTV1c(guiObject, counter++));
380   populateKeyset(new ToshibaTV1d(guiObject, counter++));
381   populateKeyset(new ToshibaTV1e(guiObject, counter++));
382   populateKeyset(new ToshibaTV1f(guiObject, counter++));
383   populateKeyset(new ToshibaTV1g(guiObject, counter++));
384   populateKeyset(new ToshibaTV1h(guiObject, counter++));
385   populateKeyset(new ToshibaVCR1(guiObject, counter++));
386   populateKeyset(new ToshibaVCR1a(guiObject, counter++));
387   populateKeyset(new ToshibaDisc1(guiObject, counter++));
388   populateKeyset(new ToshibaDisc1a(guiObject, counter++));
389   populateKeyset(new ToshibaDisc1b(guiObject, counter++));
390   populateKeyset(new ToshibaDisc1c(guiObject, counter++));
391   populateKeyset(new ToshibaDisc1d(guiObject, counter++));
392
393   populateKeyset(new WestinghouseTV1(guiObject, counter++));
394   populateKeyset(new WestinghouseTV2(guiObject, counter++));
395
396   populateKeyset(new YamahaDVD1(guiObject, counter++));
397   populateKeyset(new YamahaDVD1a(guiObject, counter++));
398   populateKeyset(new YamahaAudio1(guiObject, counter++));
399   populateKeyset(new YamahaAudio1a(guiObject, counter++));
400   populateKeyset(new YamahaAudio2(guiObject, counter++));
401   populateKeyset(new YamahaAudio2a(guiObject, counter++));
402   populateKeyset(new YamahaAudio2b(guiObject, counter++));
403   populateKeyset(new YamahaAudio2c(guiObject, counter++));
404   populateKeyset(new YamahaAudio2d(guiObject, counter++));
405   populateKeyset(new YamahaAudio3(guiObject, counter++));
406   populateKeyset(new YamahaAudio4(guiObject, counter++));
407   populateKeyset(new YamahaTV1(guiObject, counter++));
408   populateKeyset(new YamahaKaraoke1(guiObject, counter++));
409
410   populateKeyset(new ZenithC32V37(guiObject, counter++));
411
412   // Start the thread running:
413   commandThread.start();
414 }
415
416
417 PIRKeysetManager::~PIRKeysetManager()
418 {
419   // Tell the keysets to stop doing any work:
420   {
421     QMutexLocker locker(&stopRepeatingMutex);
422     stopRepeatingFlag = true;
423   }
424
425   // Tell the thread that we want it to stop:
426   commandThread.exit();
427
428   // Wait for the thread to stop:
429   commandThread.wait();
430
431   // Delete all the keysets:
432   PIRKeysetCollection::iterator i = keysetsInfo.begin();
433   while (i != keysetsInfo.end())
434   {
435     if ((*i).second) delete (*i).second;
436     ++i;
437   }
438 }
439
440
441 bool PIRKeysetManager::keysetExists(
442   unsigned int keysetID) const
443 {
444   PIRKeysetCollection::const_iterator i = keysetsInfo.find(keysetID);
445
446   return (i != keysetsInfo.end());
447 }
448
449
450 bool PIRKeysetManager::findKeysetID(
451   QString make,
452   QString name,
453   unsigned int &id) const
454 {
455   // Only modify the id if we actually find a match!
456
457   PIRKeysetMakeIndex::const_iterator i = makeIndex.find(make);
458   if (i == makeIndex.end())
459   {
460     return false;
461   }
462
463   PIRKeysetNameIndex::const_iterator ii = (*i).second.find(name);
464   if (ii == (*i).second.end())
465   {
466     return false;
467   }
468
469   //  Ok, we've found it, pull out the id:
470   id = (*ii).second;
471   return true;
472 }
473
474
475 PIRKeysetWidgetItem *PIRKeysetManager::makeKeysetItem(
476   QString make,
477   QString name) const
478 {
479   unsigned int id;
480
481   if (!findKeysetID(make, name, id))
482   {
483     return NULL;
484   }
485
486   QString fullname = make;
487   fullname.append(" ");
488   fullname.append(name);
489
490   return new PIRKeysetWidgetItem(fullname, id, getMake(id));
491 }
492
493
494 bool PIRKeysetManager::hasKey(
495   unsigned int keysetID,
496   PIRKeyName name) const
497 {
498   PIRKeysetCollection::const_iterator i = keysetsInfo.find(keysetID);
499
500   if ((i == keysetsInfo.end()) || !i->second) return false;
501
502   return i->second->hasKey(name);
503 }
504
505
506 PIRMakeName PIRKeysetManager::getMake(
507   unsigned int keysetID) const
508 {
509   PIRKeysetCollection::const_iterator i = keysetsInfo.find(keysetID);
510
511   if ((i == keysetsInfo.end()) || !i->second) return Any_Make;
512
513   return i->second->getMake();
514 }
515
516
517 QString PIRKeysetManager::getDisplayName(
518   unsigned int keysetID) const
519 {
520   PIRKeysetCollection::const_iterator i = keysetsInfo.find(keysetID);
521
522   if ((i == keysetsInfo.end()) || !i->second)
523     return QString("Database Error");
524
525   return QString(i->second->getKeysetName());
526 }
527
528
529 void PIRKeysetManager::populateKeyset(
530   PIRKeysetMetaData *keyset)
531 {
532   // Set up the keyset collection:
533   keysetsInfo[keyset->getID()] = keyset;
534
535   keyset->moveProtocolToThread(&commandThread);
536
537   // Also, set up a name-based index into the collection:
538   makeIndex
539     [QString(makeManager.getMakeString(keyset->getMake()))]
540     [QString(keyset->getKeysetName())]
541     = keyset->getID();
542 }
543
544
545 void PIRKeysetManager::populateGuiWidget(
546   PIRSelectKeysetForm *skf) const
547 {
548   PIRMakeName make;
549   PIRKeysetWidgetItem *kwi;
550
551   PIRKeysetCollection::const_iterator i = keysetsInfo.begin();
552
553   while (i != keysetsInfo.end())
554   {
555     make = i->second->getMake();
556     QString tempString = makeManager.getMakeString(make);
557     tempString.append(" ");
558     tempString.append(i->second->getKeysetName());
559     kwi = new PIRKeysetWidgetItem(tempString, i->first, make);
560     i->second->populateDeviceTypes(kwi);
561     skf->addWidgetItem(kwi);
562     ++i;
563   }
564 }
565
566
567 void PIRKeysetManager::populateDeviceTypes(
568   PIRKeysetWidgetItem *kwi,
569   unsigned int keysetID) const
570 {
571   PIRKeysetCollection::const_iterator i = keysetsInfo.find(keysetID);
572   if ((i != keysetsInfo.end()) && i->second)
573   {
574     i->second->populateDeviceTypes(kwi);
575   }
576 }