Interim Update
[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   if (utilityForm) utilityForm->enableButtons(keyset, id);
226   if (keypadForm) keypadForm->enableButtons(keyset, id);
227   if (menuForm) menuForm->enableButtons(keyset, id);
228   if (mediaForm) mediaForm->enableButtons(keyset, id);
229   if (media2Form) media2Form->enableButtons(keyset, id);
230   if (recordForm) recordForm->enableButtons(keyset, id);
231   if (tvForm) tvForm->enableButtons(keyset, id);
232   if (inputForm) inputForm->enableButtons(keyset, id);
233   if (adjustForm) adjustForm->enableButtons(keyset, id);
234   if (acForm) acForm->enableButtons(keyset, id);
235 }
236
237
238 void PIRPanelManager::managePanel(
239   PIRPanelName name,
240   int state)
241 {
242   int currentPanel = 0;
243   int displayCount = 0;
244
245 //  PIRPanelList::iterator i = panelList.begin();
246   while (currentPanel < Last_Panel_Marker)
247   {
248     if (currentPanel == name)
249     {
250       break;
251     }
252     else if (activePanels[PIRPanelName(currentPanel)])
253     {
254       ++displayCount;
255     }
256
257     ++currentPanel;
258   }
259
260   if (currentPanel == Last_Panel_Marker)
261   {
262     // should throw an error message here!!!
263     return;
264   }
265
266   QSettings settings("pietrzak.org", "Pierogi");
267
268   settings.beginGroup("Panels");
269
270   if (state == Qt::Unchecked && activePanels[PIRPanelName(currentPanel)])
271   {
272     hidePanel(name, displayCount);
273     activePanels[PIRPanelName(currentPanel)] = false;
274     settings.setValue(shortPanelNames[PIRPanelName(currentPanel)], false);
275   }
276   else if (state == Qt::Checked && !activePanels[PIRPanelName(currentPanel)])
277   {
278     showPanel(name, displayCount);
279     activePanels[PIRPanelName(currentPanel)] = true;
280     settings.setValue(shortPanelNames[PIRPanelName(currentPanel)], true);
281   }
282
283   settings.endGroup();
284 }
285
286
287 void PIRPanelManager::useMainPanel()
288 {
289   if (!altMainPanelFlag)
290   {
291     // Already set correctly, nothing to do:
292     return;
293   }
294
295   altMainPanelFlag = false;
296
297   // Is the main panel currently active?
298   if (activePanels[Main_Panel])
299   {
300     mainWindow->removePanel(0, altMainForm);
301     if (!mainForm)
302     {
303       mainForm = new PIRMainForm(mainWindow);
304     }
305
306     mainWindow->insertPanel(0, mainForm, longPanelNames[Main_Panel]);
307     mainWindow->selectPanel(0);
308   }
309
310   mainWindow->enableButtons();
311 }
312
313
314 void PIRPanelManager::useAltMainPanel()
315 {
316   if (altMainPanelFlag)
317   {
318     // Already set correctly, nothing to do:
319     return;
320   }
321
322   altMainPanelFlag = true;
323
324   // Is the main panel currently active?
325   if (activePanels[Main_Panel])
326   {
327     mainWindow->removePanel(0, mainForm);
328     if (!altMainForm)
329     {
330       altMainForm = new PIRAltMainForm(mainWindow);
331     }
332
333     mainWindow->insertPanel(0, altMainForm, longPanelNames[Main_Panel]);
334     mainWindow->selectPanel(0);
335   }
336
337   mainWindow->enableButtons();
338 }
339
340
341 void PIRPanelManager::hidePanel(
342   PIRPanelName name,
343   int index)
344 {
345   switch (name)
346   {
347     case Main_Panel:
348       if (altMainPanelFlag)
349       {
350         if (altMainForm) mainWindow->removePanel(index, altMainForm);
351       }
352       else
353       {
354         if (mainForm) mainWindow->removePanel(index, mainForm);
355       }
356       break;
357
358     case Utility_Panel:
359       if (utilityForm) mainWindow->removePanel(index, utilityForm);
360       break;
361
362     case Keypad_Panel:
363       if (keypadForm) mainWindow->removePanel(index, keypadForm);
364       break;
365
366     case Menu_Panel:
367       if (menuForm) mainWindow->removePanel(index, menuForm);
368       break;
369
370     case Media_Panel:
371       if (mediaForm) mainWindow->removePanel(index, mediaForm);
372       break;
373
374     case Media2_Panel:
375       if (media2Form) mainWindow->removePanel(index, media2Form);
376       break;
377
378     case Record_Panel:
379       if (recordForm) mainWindow->removePanel(index, recordForm);
380       break;
381
382     case TV_Panel:
383       if (tvForm) mainWindow->removePanel(index, tvForm);
384       break;
385
386     case Input_Panel:
387       if (inputForm) mainWindow->removePanel(index, inputForm);
388       break;
389
390     case Adjust_Panel:
391       if (adjustForm) mainWindow->removePanel(index, adjustForm);
392       break;
393
394     case AC_Panel:
395       if (acForm) mainWindow->removePanel(index, acForm);
396       break;
397
398     case Favorites_Panel:
399       if (favoritesForm) mainWindow->removePanel(index, favoritesForm);
400       break;
401
402     default:
403       return; 
404       break;
405   }
406 }
407
408
409 void PIRPanelManager::showPanel(
410   PIRPanelName name,
411   int index)
412 {
413   switch (name)
414   {
415     case Main_Panel:
416       if (altMainPanelFlag)
417       {
418         if (!altMainForm)
419         {
420           altMainForm = new PIRAltMainForm(mainWindow);
421           mainWindow->enableButtons();
422         }
423
424         mainWindow->insertPanel(
425           index,
426           altMainForm,
427           longPanelNames[Main_Panel]);
428       }
429       else
430       {
431         if (!mainForm)
432         {
433           mainForm = new PIRMainForm(mainWindow);
434           mainWindow->enableButtons();
435         }
436
437         mainWindow->insertPanel(
438           index,
439           mainForm,
440           longPanelNames[Main_Panel]);
441       }
442
443       break;
444
445     case Utility_Panel:
446       if (!utilityForm)
447       {
448         utilityForm = new PIRUtilityForm(mainWindow);
449         mainWindow->enableButtons();
450       }
451
452       mainWindow->insertPanel(
453         index,
454         utilityForm,
455         longPanelNames[Utility_Panel]);
456
457       break;
458
459     case Keypad_Panel:
460       if (!keypadForm)
461       {
462         keypadForm = new PIRKeypadForm(mainWindow);
463         mainWindow->enableButtons();
464       }
465
466       mainWindow->insertPanel(
467         index,
468         keypadForm,
469         longPanelNames[Keypad_Panel]);
470
471       break;
472
473     case Menu_Panel:
474       if (!menuForm)
475       {
476         menuForm = new PIRMenuForm(mainWindow);
477         mainWindow->enableButtons();
478       }
479
480       mainWindow->insertPanel(
481         index,
482         menuForm,
483         longPanelNames[Menu_Panel]);
484
485       break;
486
487     case Media_Panel:
488       if (!mediaForm)
489       {
490         mediaForm = new PIRMediaForm(mainWindow);
491         mainWindow->enableButtons();
492       }
493
494       mainWindow->insertPanel(
495         index,
496         mediaForm,
497         longPanelNames[Media_Panel]);
498
499       break;
500
501     case Media2_Panel:
502       if (!media2Form)
503       {
504         media2Form = new PIRMedia2Form(mainWindow);
505         mainWindow->enableButtons();
506       }
507
508       mainWindow->insertPanel(
509         index,
510         media2Form,
511         longPanelNames[Media2_Panel]);
512
513       break;
514
515     case Record_Panel:
516       if (!recordForm)
517       {
518         recordForm = new PIRRecordForm(mainWindow);
519         mainWindow->enableButtons();
520       }
521
522       mainWindow->insertPanel(
523         index,
524         recordForm,
525         longPanelNames[Record_Panel]);
526
527       break;
528
529     case TV_Panel:
530       if (!tvForm)
531       {
532         tvForm = new PIRTVForm(mainWindow);
533         mainWindow->enableButtons();
534       }
535
536       mainWindow->insertPanel(
537         index,
538         tvForm,
539         longPanelNames[TV_Panel]);
540
541       break;
542
543     case Input_Panel:
544       if (!inputForm)
545       {
546         inputForm = new PIRInputForm(mainWindow);
547         mainWindow->enableButtons();
548       }
549
550       mainWindow->insertPanel(
551         index,
552         inputForm,
553         longPanelNames[Input_Panel]);
554
555       break;
556
557     case Adjust_Panel:
558       if (!adjustForm)
559       {
560         adjustForm = new PIRAdjustForm(mainWindow);
561         mainWindow->enableButtons();
562       }
563
564       mainWindow->insertPanel(
565         index,
566         adjustForm,
567         longPanelNames[Adjust_Panel]);
568
569       break;
570
571     case AC_Panel:
572       if (!acForm)
573       {
574         acForm = new PIRAirConditionerForm(mainWindow);
575         mainWindow->enableButtons();
576       }
577
578       mainWindow->insertPanel(
579         index,
580         acForm,
581         longPanelNames[AC_Panel]);
582
583       break;
584
585     case Favorites_Panel:
586       if (!favoritesForm)
587       {
588         favoritesForm = new PIRFavoritesForm(mainWindow);
589         mainWindow->enableButtons();
590       }
591
592       mainWindow->insertPanel(
593         index,
594         favoritesForm,
595         longPanelNames[Favorites_Panel]);
596
597       break;
598
599     default:
600       break;
601   }
602 }
603
604
605 void PIRPanelManager::selectPrevFavKeyset()
606 {
607   // If the favorites form doesn't exist, no need to continue:
608   if (!favoritesForm) return;
609
610   favoritesForm->selectPrevFavKeyset();
611 }
612
613
614 void PIRPanelManager::selectNextFavKeyset()
615 {
616   // If the favorites form doesn't exist, no need to continue:
617   if (!favoritesForm) return;
618
619   favoritesForm->selectNextFavKeyset();
620 }
621
622
623 void PIRPanelManager::addFavoritesItem(
624   PIRKeysetWidgetItem *item)
625 {
626   if (!favoritesForm)
627   {
628     favoritesForm = new PIRFavoritesForm(mainWindow);
629   }
630
631   favoritesForm->addItem(item);
632 }
633
634
635 QListWidget *PIRPanelManager::getFavoritesListWidget()
636 {
637   if (!favoritesForm)
638   {
639     favoritesForm = new PIRFavoritesForm(mainWindow);
640   }
641
642   return favoritesForm->getFavoritesListWidget();
643 }
644