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