New GUI, many changes
[pierogi] / pirpanelmanager.cpp
1 #include "pirpanelmanager.h"
2
3 #include "forms/pirmainform.h"
4 #include "forms/pirutilityform.h"
5 #include "forms/pirkeypadform.h"
6 #include "forms/pirmenuform.h"
7 #include "forms/pirmediaform.h"
8 #include "forms/pirfavoritesform.h"
9 #include "forms/pirtvform.h"
10 #include "forms/pirmedia2form.h"
11 #include "forms/pirinputform.h"
12 #include "forms/piradjustform.h"
13 #include "forms/pirairconditionerform.h"
14
15 #include "mainwindow.h"
16
17 PIRPanelManager::PIRPanelManager(MainWindow *mw)
18   : mainForm(0),
19     utilityForm(0),
20     keypadForm(0),
21     menuForm(0),
22     mediaForm(0),
23     media2Form(0),
24     tvForm(0),
25     inputForm(0),
26     adjustForm(0),
27     acForm(0),
28     favoritesForm(0),
29     mainWindow(mw)
30 {
31   panelList.push_back(PIRPanelPair(Main_Panel, false));
32   panelList.push_back(PIRPanelPair(Utility_Panel, false));
33   panelList.push_back(PIRPanelPair(Keypad_Panel, false));
34   panelList.push_back(PIRPanelPair(Menu_Panel, false));
35   panelList.push_back(PIRPanelPair(Media_Panel, false));
36   panelList.push_back(PIRPanelPair(Media2_Panel, false));
37   panelList.push_back(PIRPanelPair(TV_Panel, false));
38   panelList.push_back(PIRPanelPair(Input_Panel, false));
39   panelList.push_back(PIRPanelPair(Adjust_Panel, false));
40   panelList.push_back(PIRPanelPair(AC_Panel, false));
41   panelList.push_back(PIRPanelPair(Favorites_Panel, false));
42 }
43
44
45 PIRPanelManager::~PIRPanelManager()
46 {
47   // Note!  We are _not_ deleting the panel forms here, because the Qt GUI
48   // has ownership over some of them.  Moreover, the Panel Manager is not
49   // currently designed to be destroyed until the program ends.  Should the
50   // manager need to be destroyed earlier, this destructor will need to be
51   // changed!
52 }
53
54
55 /*
56 void PIRPanelManager::setupPanels(
57   PIRPanelSelectionForm *psf)
58 {
59 }
60 */
61
62
63 void PIRPanelManager::enableButtons(
64   const PIRKeysetManager *keyset,
65   unsigned int id)
66 {
67   if (mainForm) mainForm->enableButtons(keyset, id);
68   if (utilityForm) utilityForm->enableButtons(keyset, id);
69   if (keypadForm) keypadForm->enableButtons(keyset, id);
70   if (menuForm) menuForm->enableButtons(keyset, id);
71   if (mediaForm) mediaForm->enableButtons(keyset, id);
72   if (media2Form) media2Form->enableButtons(keyset, id);
73   if (tvForm) tvForm->enableButtons(keyset, id);
74   if (inputForm) inputForm->enableButtons(keyset, id);
75   if (adjustForm) adjustForm->enableButtons(keyset, id);
76   if (acForm) acForm->enableButtons(keyset, id);
77 }
78
79
80 void PIRPanelManager::managePanel(
81   PIRPanelName name,
82   int state)
83 {
84   int index = 0;
85
86   PIRPanelList::iterator i = panelList.begin();
87   while (i != panelList.end())
88   {
89     if (i->name == name)
90     {
91       break;
92     }
93     else if (i->displayed)
94     {
95       ++index;
96     }
97     ++i;
98   }
99
100   if (i == panelList.end())
101   {
102     // should throw an error message here!!!
103     return;
104   }
105
106   if (state == Qt::Unchecked && i->displayed)
107   {
108     hidePanel(name, index);
109     i->displayed = false;
110   }
111   else if (state == Qt::Checked && !i->displayed)
112   {
113     showPanel(name, index);
114     i->displayed = true;
115   }
116 }
117
118
119 void PIRPanelManager::hidePanel(
120   PIRPanelName name,
121   int index)
122 {
123   switch (name)
124   {
125     case Main_Panel:
126       if (mainForm) mainWindow->removePanel(index, mainForm);
127       break;
128
129     case Utility_Panel:
130       if (utilityForm) mainWindow->removePanel(index, utilityForm);
131       break;
132
133     case Keypad_Panel:
134       if (keypadForm) mainWindow->removePanel(index, keypadForm);
135       break;
136
137     case Menu_Panel:
138       if (menuForm) mainWindow->removePanel(index, menuForm);
139       break;
140
141     case Media_Panel:
142       if (mediaForm) mainWindow->removePanel(index, mediaForm);
143       break;
144
145     case TV_Panel:
146       if (tvForm) mainWindow->removePanel(index, tvForm);
147       break;
148
149     case Media2_Panel:
150       if (media2Form) mainWindow->removePanel(index, media2Form);
151       break;
152
153     case Input_Panel:
154       if (inputForm) mainWindow->removePanel(index, inputForm);
155       break;
156
157     case Adjust_Panel:
158       if (adjustForm) mainWindow->removePanel(index, adjustForm);
159       break;
160
161     case AC_Panel:
162       if (acForm) mainWindow->removePanel(index, acForm);
163       break;
164
165     case Favorites_Panel:
166       if (favoritesForm) mainWindow->removePanel(index, favoritesForm);
167       break;
168
169     default:
170       return; 
171       break;
172   }
173 }
174
175
176 void PIRPanelManager::showPanel(
177   PIRPanelName name,
178   int index)
179 {
180   switch (name)
181   {
182     case Main_Panel:
183       if (!mainForm)
184       {
185         mainForm = new PIRMainForm(mainWindow);
186         mainWindow->enableButtons();
187       }
188
189       mainWindow->insertPanel(
190         index,
191         mainForm,
192         QString("Main Panel - power, volume, and channel controls"));
193
194       break;
195
196     case Utility_Panel:
197       if (!utilityForm)
198       {
199         utilityForm = new PIRUtilityForm(mainWindow);
200         mainWindow->enableButtons();
201       }
202
203       mainWindow->insertPanel(
204         index,
205         utilityForm,
206         QString("Utility Panel - commonly used controls"));
207
208       break;
209
210     case Keypad_Panel:
211       if (!keypadForm)
212       {
213         keypadForm = new PIRKeypadForm(mainWindow);
214         mainWindow->enableButtons();
215       }
216
217       mainWindow->insertPanel(
218         index,
219         keypadForm,
220         QString("Keypad Panel - numeric value entry"));
221
222       break;
223
224     case Menu_Panel:
225       if (!menuForm)
226       {
227         menuForm = new PIRMenuForm(mainWindow);
228         mainWindow->enableButtons();
229       }
230
231       mainWindow->insertPanel(
232         index,
233         menuForm,
234         QString("Menu Panel - enter, exit, and navigate menus"));
235
236       break;
237
238     case Media_Panel:
239       if (!mediaForm)
240       {
241         mediaForm = new PIRMediaForm(mainWindow);
242         mainWindow->enableButtons();
243       }
244
245       mainWindow->insertPanel(
246         index,
247         mediaForm,
248         QString("Media Panel - control over recorded data"));
249
250       break;
251
252     case Media2_Panel:
253       if (!media2Form)
254       {
255         media2Form = new PIRMedia2Form(mainWindow);
256         mainWindow->enableButtons();
257       }
258
259       mainWindow->insertPanel(
260         index,
261         media2Form,
262         QString("Media2 Panel - additonal media controls"));
263
264       break;
265
266     case TV_Panel:
267       if (!tvForm)
268       {
269         tvForm = new PIRTVForm(mainWindow);
270         mainWindow->enableButtons();
271       }
272
273       mainWindow->insertPanel(
274         index,
275         tvForm,
276         QString("TV Panel - teletext and picture-in-picture"));
277
278       break;
279
280     case Input_Panel:
281       if (!inputForm)
282       {
283         inputForm = new PIRInputForm(mainWindow);
284         mainWindow->enableButtons();
285       }
286
287       mainWindow->insertPanel(
288         index,
289         inputForm,
290         QString("Input Panel - manage data sources"));
291
292       break;
293
294     case Adjust_Panel:
295       if (!adjustForm)
296       {
297         adjustForm = new PIRAdjustForm(mainWindow);
298         mainWindow->enableButtons();
299       }
300
301       mainWindow->insertPanel(
302         index,
303         adjustForm,
304         QString("Adjust Panel - modify audio and video"));
305
306       break;
307
308     case AC_Panel:
309       if (!acForm)
310       {
311         acForm = new PIRAirConditionerForm(mainWindow);
312         mainWindow->enableButtons();
313       }
314
315       mainWindow->insertPanel(
316         index,
317         acForm,
318         QString("A/C Panel - air conditioner controls"));
319
320       break;
321
322     case Favorites_Panel:
323       if (!favoritesForm)
324       {
325         favoritesForm = new PIRFavoritesForm(mainWindow);
326         mainWindow->enableButtons();
327       }
328
329       mainWindow->insertPanel(
330         index,
331         favoritesForm,
332         QString("Favorites Panel - memorized keysets"));
333
334       break;
335
336     default:
337       break;
338   }
339 }
340
341
342 void PIRPanelManager::selectPrevFavKeyset()
343 {
344   // If the favorites form doesn't exist, no need to continue:
345   if (!favoritesForm) return;
346
347   favoritesForm->selectPrevFavKeyset();
348 }
349
350
351 void PIRPanelManager::selectNextFavKeyset()
352 {
353   // If the favorites form doesn't exist, no need to continue:
354   if (!favoritesForm) return;
355
356   favoritesForm->selectNextFavKeyset();
357 }
358
359
360 void PIRPanelManager::addFavoritesItem(
361   PIRKeysetWidgetItem *item)
362 {
363   if (!favoritesForm)
364   {
365     favoritesForm = new PIRFavoritesForm(mainWindow);
366   }
367
368   favoritesForm->addItem(item);
369 }
370
371
372 QListWidget *PIRPanelManager::getFavoritesListWidget()
373 {
374   if (!favoritesForm)
375   {
376     favoritesForm = new PIRFavoritesForm(mainWindow);
377   }
378
379   return favoritesForm->getFavoritesListWidget();
380 }
381