A couple of UI additions
[pierogi] / pirpanelmanager.cpp
1 #include "pirpanelmanager.h"
2
3 #include "pirpanelselectionform.h"
4
5 #include "forms/pirmainform.h"
6 #include "forms/piraltmainform.h"
7 #include "forms/pirutilityform.h"
8 #include "forms/pirkeypadform.h"
9 #include "forms/pirmenuform.h"
10 #include "forms/pirmediaform.h"
11 #include "forms/pirmedia2form.h"
12 #include "forms/pirrecordform.h"
13 #include "forms/pirtvform.h"
14 #include "forms/pirinputform.h"
15 #include "forms/piradjustform.h"
16 #include "forms/pirairconditionerform.h"
17 #include "forms/pirfavoritesform.h"
18
19 #include "mainwindow.h"
20
21 #include <QSettings>
22
23 // Debugging:
24 //#include <QMaemo5InformationBox>
25 #include <iostream>
26
27 PIRPanelManager::PIRPanelManager(MainWindow *mw)
28   : mainForm(0),
29     altMainForm(0),
30     utilityForm(0),
31     keypadForm(0),
32     menuForm(0),
33     mediaForm(0),
34     media2Form(0),
35     recordForm(0),
36     tvForm(0),
37     inputForm(0),
38     adjustForm(0),
39     acForm(0),
40     favoritesForm(0),
41     altMainPanelFlag(false),
42     mainWindow(mw)
43 {
44   // Set up the panel names:
45   shortPanelNames[Main_Panel] = "Main";
46   longPanelNames[Main_Panel] =
47     "Main Panel - power, volume, and channel controls";
48   shortPanelNames[Utility_Panel] = "Utility";
49   longPanelNames[Utility_Panel] = 
50     "Utility Panel - commonly used controls";
51   shortPanelNames[Keypad_Panel] = "Keypad";
52   longPanelNames[Keypad_Panel] =
53     "Keypad Panel - numeric value entry";
54   shortPanelNames[Menu_Panel] = "Menu";
55   longPanelNames[Menu_Panel] =
56     "Menu Panel - enter, exit, and navigate menus";
57   shortPanelNames[Media_Panel] = "Media";
58   longPanelNames[Media_Panel] =
59     "Media Panel - control over recorded data";
60   shortPanelNames[Media2_Panel] = "Media2";
61   longPanelNames[Media2_Panel] =
62     "Media2 Panel - additonal media controls";
63   shortPanelNames[Record_Panel] = "Record";
64   longPanelNames[Record_Panel] =
65     "Program/Record Panel - control over memory and storage";
66   shortPanelNames[TV_Panel] = "TV";
67   longPanelNames[TV_Panel] =
68     "TV Panel - teletext and picture-in-picture";
69   shortPanelNames[Input_Panel] = "Input";
70   longPanelNames[Input_Panel] =
71     "Input Panel - manage data sources";
72   shortPanelNames[Adjust_Panel] = "Adjust";
73   longPanelNames[Adjust_Panel] =
74     "Adjust Panel - modify audio and video";
75   shortPanelNames[AC_Panel] = "AC";
76   longPanelNames[AC_Panel] =
77     "A/C Panel - air conditioner controls";
78   shortPanelNames[Favorites_Panel] = "Favorites";
79   longPanelNames[Favorites_Panel] =
80     "Favorites Panel - memorized keysets";
81
82   activePanels[Main_Panel] = false;
83   activePanels[Utility_Panel]= false;
84   activePanels[Keypad_Panel]= false;
85   activePanels[Menu_Panel]= false;
86   activePanels[Media_Panel]= false;
87   activePanels[Media2_Panel]= false;
88   activePanels[Record_Panel]= false;
89   activePanels[TV_Panel]= false;
90   activePanels[Input_Panel]= false;
91   activePanels[Adjust_Panel]= false;
92   activePanels[AC_Panel]= false;
93   activePanels[Favorites_Panel]= false;
94 }
95
96
97 PIRPanelManager::~PIRPanelManager()
98 {
99   // Note!  We are _not_ deleting the panel forms here, because the Qt GUI
100   // has ownership over some of them.  Moreover, the Panel Manager is not
101   // currently designed to be destroyed until the program ends.  Should the
102   // manager need to be destroyed earlier, this destructor will need to be
103   // changed!
104 }
105
106
107 void PIRPanelManager::setupPanels(
108   PIRPanelSelectionForm *psf)
109 {
110   QSettings settings("pietrzak.org", "Pierogi");
111
112   settings.beginGroup("Panels");
113
114   // Do the panel settings exist? (We'll check for "Main_Panel".)
115   if (!settings.contains(shortPanelNames[Main_Panel]))
116   {
117     // A default set of panels:
118     psf->setCheckBox(Main_Panel, true);
119     psf->setCheckBox(Utility_Panel, true);
120     psf->setCheckBox(Keypad_Panel, true);
121     psf->setCheckBox(Menu_Panel, true);
122     psf->setCheckBox(Media_Panel, true);
123     psf->setCheckBox(Favorites_Panel, true);
124   }
125   else
126   {
127     psf->setCheckBox(
128       Main_Panel,
129       settings.value(shortPanelNames[Main_Panel]).toBool());
130
131     if (settings.contains(shortPanelNames[Utility_Panel]))
132     {
133       psf->setCheckBox(
134         Utility_Panel,
135         settings.value(shortPanelNames[Utility_Panel]).toBool());
136     }
137
138     if (settings.contains(shortPanelNames[Keypad_Panel]))
139     {
140       psf->setCheckBox(
141         Keypad_Panel,
142         settings.value(shortPanelNames[Keypad_Panel]).toBool());
143     }
144
145     if (settings.contains(shortPanelNames[Menu_Panel]))
146     {
147       psf->setCheckBox(
148         Menu_Panel,
149         settings.value(shortPanelNames[Menu_Panel]).toBool());
150     }
151
152     if (settings.contains(shortPanelNames[Media_Panel]))
153     {
154       psf->setCheckBox(
155         Media_Panel,
156         settings.value(shortPanelNames[Media_Panel]).toBool());
157     }
158
159     if (settings.contains(shortPanelNames[Media2_Panel]))
160     {
161       psf->setCheckBox(
162         Media2_Panel,
163         settings.value(shortPanelNames[Media2_Panel]).toBool());
164     }
165
166     if (settings.contains(shortPanelNames[Record_Panel]))
167     {
168       psf->setCheckBox(
169         Record_Panel,
170         settings.value(shortPanelNames[Record_Panel]).toBool());
171     }
172
173     if (settings.contains(shortPanelNames[TV_Panel]))
174     {
175       psf->setCheckBox(
176         TV_Panel,
177         settings.value(shortPanelNames[TV_Panel]).toBool());
178     }
179
180     if (settings.contains(shortPanelNames[Input_Panel]))
181     {
182       psf->setCheckBox(
183         Input_Panel,
184         settings.value(shortPanelNames[Input_Panel]).toBool());
185     }
186
187     if (settings.contains(shortPanelNames[Adjust_Panel]))
188     {
189       psf->setCheckBox(
190         Adjust_Panel,
191         settings.value(shortPanelNames[Adjust_Panel]).toBool());
192     }
193
194     if (settings.contains(shortPanelNames[AC_Panel]))
195     {
196       psf->setCheckBox(
197         AC_Panel,
198         settings.value(shortPanelNames[AC_Panel]).toBool());
199     }
200
201     if (settings.contains(shortPanelNames[Favorites_Panel]))
202     {
203       psf->setCheckBox(
204         Favorites_Panel,
205         settings.value(shortPanelNames[Favorites_Panel]).toBool());
206     }
207   }
208
209   settings.endGroup();
210 }
211
212
213 void PIRPanelManager::enableButtons(
214   const PIRKeysetManager *keyset,
215   unsigned int id)
216 {
217   if (altMainPanelFlag)
218   {
219     if (altMainForm) altMainForm->enableButtons(keyset, id);
220   }
221   else
222   {
223     if (mainForm) mainForm->enableButtons(keyset, id);
224   }
225
226   commonEnableButtons(keyset, id);
227 }
228
229
230 void PIRPanelManager::enableButtons(
231   const PIRKeysetManager *keyset,
232   unsigned int currentID,
233   unsigned int defaultID)
234 {
235   if (altMainPanelFlag)
236   {
237     if (altMainForm) altMainForm->enableButtons(keyset, currentID, defaultID);
238   }
239   else
240   {
241     if (mainForm) mainForm->enableButtons(keyset, currentID, defaultID);
242   }
243
244   commonEnableButtons(keyset, currentID);
245 }
246
247
248 void PIRPanelManager::commonEnableButtons(
249   const PIRKeysetManager *keyset,
250   unsigned int id)
251 {
252   if (utilityForm) utilityForm->enableButtons(keyset, id);
253   if (keypadForm) keypadForm->enableButtons(keyset, id);
254   if (menuForm) menuForm->enableButtons(keyset, id);
255   if (mediaForm) mediaForm->enableButtons(keyset, id);
256   if (media2Form) media2Form->enableButtons(keyset, id);
257   if (recordForm) recordForm->enableButtons(keyset, id);
258   if (tvForm) tvForm->enableButtons(keyset, id);
259   if (inputForm) inputForm->enableButtons(keyset, id);
260   if (adjustForm) adjustForm->enableButtons(keyset, id);
261   if (acForm) acForm->enableButtons(keyset, id);
262 }
263
264
265 void PIRPanelManager::managePanel(
266   PIRPanelName name,
267   int state)
268 {
269   int currentPanel = 0;
270   int displayCount = 0;
271
272 //  PIRPanelList::iterator i = panelList.begin();
273   while (currentPanel < Last_Panel_Marker)
274   {
275     if (currentPanel == name)
276     {
277       break;
278     }
279     else if (activePanels[PIRPanelName(currentPanel)])
280     {
281       ++displayCount;
282     }
283
284     ++currentPanel;
285   }
286
287   if (currentPanel == Last_Panel_Marker)
288   {
289     // should throw an error message here!!!
290     return;
291   }
292
293   QSettings settings("pietrzak.org", "Pierogi");
294
295   settings.beginGroup("Panels");
296
297   if (state == Qt::Unchecked && activePanels[PIRPanelName(currentPanel)])
298   {
299     hidePanel(name, displayCount);
300     activePanels[PIRPanelName(currentPanel)] = false;
301     settings.setValue(shortPanelNames[PIRPanelName(currentPanel)], false);
302   }
303   else if (state == Qt::Checked && !activePanels[PIRPanelName(currentPanel)])
304   {
305     showPanel(name, displayCount);
306     activePanels[PIRPanelName(currentPanel)] = true;
307     settings.setValue(shortPanelNames[PIRPanelName(currentPanel)], true);
308   }
309
310   settings.endGroup();
311 }
312
313
314 void PIRPanelManager::useMainPanel()
315 {
316   if (!altMainPanelFlag)
317   {
318     // Already set correctly, nothing to do:
319     return;
320   }
321
322   altMainPanelFlag = false;
323
324   // Is the main panel currently active?
325   if (activePanels[Main_Panel])
326   {
327     mainWindow->removePanel(0, altMainForm);
328     if (!mainForm)
329     {
330       mainForm = new PIRMainForm(mainWindow);
331     }
332
333     mainWindow->insertPanel(0, mainForm, longPanelNames[Main_Panel]);
334     mainWindow->selectPanel(0);
335   }
336
337   mainWindow->enableButtons();
338 }
339
340
341 void PIRPanelManager::useAltMainPanel()
342 {
343   if (altMainPanelFlag)
344   {
345     // Already set correctly, nothing to do:
346     return;
347   }
348
349   altMainPanelFlag = true;
350
351   // Is the main panel currently active?
352   if (activePanels[Main_Panel])
353   {
354     mainWindow->removePanel(0, mainForm);
355     if (!altMainForm)
356     {
357       altMainForm = new PIRAltMainForm(mainWindow);
358     }
359
360     mainWindow->insertPanel(0, altMainForm, longPanelNames[Main_Panel]);
361     mainWindow->selectPanel(0);
362   }
363
364   mainWindow->enableButtons();
365 }
366
367
368 void PIRPanelManager::hidePanel(
369   PIRPanelName name,
370   int index)
371 {
372   switch (name)
373   {
374     case Main_Panel:
375       if (altMainPanelFlag)
376       {
377         if (altMainForm) mainWindow->removePanel(index, altMainForm);
378       }
379       else
380       {
381         if (mainForm) mainWindow->removePanel(index, mainForm);
382       }
383       break;
384
385     case Utility_Panel:
386       if (utilityForm) mainWindow->removePanel(index, utilityForm);
387       break;
388
389     case Keypad_Panel:
390       if (keypadForm) mainWindow->removePanel(index, keypadForm);
391       break;
392
393     case Menu_Panel:
394       if (menuForm) mainWindow->removePanel(index, menuForm);
395       break;
396
397     case Media_Panel:
398       if (mediaForm) mainWindow->removePanel(index, mediaForm);
399       break;
400
401     case Media2_Panel:
402       if (media2Form) mainWindow->removePanel(index, media2Form);
403       break;
404
405     case Record_Panel:
406       if (recordForm) mainWindow->removePanel(index, recordForm);
407       break;
408
409     case TV_Panel:
410       if (tvForm) mainWindow->removePanel(index, tvForm);
411       break;
412
413     case Input_Panel:
414       if (inputForm) mainWindow->removePanel(index, inputForm);
415       break;
416
417     case Adjust_Panel:
418       if (adjustForm) mainWindow->removePanel(index, adjustForm);
419       break;
420
421     case AC_Panel:
422       if (acForm) mainWindow->removePanel(index, acForm);
423       break;
424
425     case Favorites_Panel:
426       if (favoritesForm) mainWindow->removePanel(index, favoritesForm);
427       break;
428
429     default:
430       return; 
431       break;
432   }
433 }
434
435
436 void PIRPanelManager::showPanel(
437   PIRPanelName name,
438   int index)
439 {
440   switch (name)
441   {
442     case Main_Panel:
443       if (altMainPanelFlag)
444       {
445         if (!altMainForm)
446         {
447           altMainForm = new PIRAltMainForm(mainWindow);
448           mainWindow->enableButtons();
449         }
450
451         mainWindow->insertPanel(
452           index,
453           altMainForm,
454           longPanelNames[Main_Panel]);
455       }
456       else
457       {
458         if (!mainForm)
459         {
460           mainForm = new PIRMainForm(mainWindow);
461           mainWindow->enableButtons();
462         }
463
464         mainWindow->insertPanel(
465           index,
466           mainForm,
467           longPanelNames[Main_Panel]);
468       }
469
470       break;
471
472     case Utility_Panel:
473       if (!utilityForm)
474       {
475         utilityForm = new PIRUtilityForm(mainWindow);
476         mainWindow->enableButtons();
477       }
478
479       mainWindow->insertPanel(
480         index,
481         utilityForm,
482         longPanelNames[Utility_Panel]);
483
484       break;
485
486     case Keypad_Panel:
487       if (!keypadForm)
488       {
489         keypadForm = new PIRKeypadForm(mainWindow);
490         mainWindow->enableButtons();
491       }
492
493       mainWindow->insertPanel(
494         index,
495         keypadForm,
496         longPanelNames[Keypad_Panel]);
497
498       break;
499
500     case Menu_Panel:
501       if (!menuForm)
502       {
503         menuForm = new PIRMenuForm(mainWindow);
504         mainWindow->enableButtons();
505       }
506
507       mainWindow->insertPanel(
508         index,
509         menuForm,
510         longPanelNames[Menu_Panel]);
511
512       break;
513
514     case Media_Panel:
515       if (!mediaForm)
516       {
517         mediaForm = new PIRMediaForm(mainWindow);
518         mainWindow->enableButtons();
519       }
520
521       mainWindow->insertPanel(
522         index,
523         mediaForm,
524         longPanelNames[Media_Panel]);
525
526       break;
527
528     case Media2_Panel:
529       if (!media2Form)
530       {
531         media2Form = new PIRMedia2Form(mainWindow);
532         mainWindow->enableButtons();
533       }
534
535       mainWindow->insertPanel(
536         index,
537         media2Form,
538         longPanelNames[Media2_Panel]);
539
540       break;
541
542     case Record_Panel:
543       if (!recordForm)
544       {
545         recordForm = new PIRRecordForm(mainWindow);
546         mainWindow->enableButtons();
547       }
548
549       mainWindow->insertPanel(
550         index,
551         recordForm,
552         longPanelNames[Record_Panel]);
553
554       break;
555
556     case TV_Panel:
557       if (!tvForm)
558       {
559         tvForm = new PIRTVForm(mainWindow);
560         mainWindow->enableButtons();
561       }
562
563       mainWindow->insertPanel(
564         index,
565         tvForm,
566         longPanelNames[TV_Panel]);
567
568       break;
569
570     case Input_Panel:
571       if (!inputForm)
572       {
573         inputForm = new PIRInputForm(mainWindow);
574         mainWindow->enableButtons();
575       }
576
577       mainWindow->insertPanel(
578         index,
579         inputForm,
580         longPanelNames[Input_Panel]);
581
582       break;
583
584     case Adjust_Panel:
585       if (!adjustForm)
586       {
587         adjustForm = new PIRAdjustForm(mainWindow);
588         mainWindow->enableButtons();
589       }
590
591       mainWindow->insertPanel(
592         index,
593         adjustForm,
594         longPanelNames[Adjust_Panel]);
595
596       break;
597
598     case AC_Panel:
599       if (!acForm)
600       {
601         acForm = new PIRAirConditionerForm(mainWindow);
602         mainWindow->enableButtons();
603       }
604
605       mainWindow->insertPanel(
606         index,
607         acForm,
608         longPanelNames[AC_Panel]);
609
610       break;
611
612     case Favorites_Panel:
613       if (!favoritesForm)
614       {
615         favoritesForm = new PIRFavoritesForm(mainWindow);
616         mainWindow->enableButtons();
617       }
618
619       mainWindow->insertPanel(
620         index,
621         favoritesForm,
622         longPanelNames[Favorites_Panel]);
623
624       break;
625
626     default:
627       break;
628   }
629 }
630
631
632 void PIRPanelManager::selectPrevFavKeyset()
633 {
634   // If the favorites form doesn't exist, no need to continue:
635   if (!favoritesForm) return;
636
637   favoritesForm->selectPrevFavKeyset();
638 }
639
640
641 void PIRPanelManager::selectNextFavKeyset()
642 {
643   // If the favorites form doesn't exist, no need to continue:
644   if (!favoritesForm) return;
645
646   favoritesForm->selectNextFavKeyset();
647 }
648
649
650 void PIRPanelManager::addFavoritesItem(
651   PIRKeysetWidgetItem *item)
652 {
653   if (!favoritesForm)
654   {
655     favoritesForm = new PIRFavoritesForm(mainWindow);
656   }
657
658   favoritesForm->addItem(item);
659 }
660
661
662 QListWidget *PIRPanelManager::getFavoritesListWidget()
663 {
664   if (!favoritesForm)
665   {
666     favoritesForm = new PIRFavoritesForm(mainWindow);
667   }
668
669   return favoritesForm->getFavoritesListWidget();
670 }
671