Missed one file
[pierogi] / pirpanelmanager.cpp
1 #include "pirpanelmanager.h"
2
3 #include "forms/pirmainform.h"
4 #include "forms/piraltmainform.h"
5 #include "forms/pirutilityform.h"
6 #include "forms/pirkeypadform.h"
7 #include "forms/pirmenuform.h"
8 #include "forms/pirmediaform.h"
9 #include "forms/pirmedia2form.h"
10 #include "forms/pirrecordform.h"
11 #include "forms/pirtvform.h"
12 #include "forms/pirinputform.h"
13 #include "forms/piradjustform.h"
14 #include "forms/pirairconditionerform.h"
15 #include "forms/piraudiodeviceform.h"
16 #include "forms/pircameraform.h"
17 #include "forms/pirroombaform.h"
18 #include "forms/pirpowersearchform.h"
19
20 #include "mainwindow.h"
21
22 #include <QSettings>
23 #include <QDialogButtonBox>
24 #include <QPushButton>
25
26 // Debugging:
27 //#include <QMaemo5InformationBox>
28 //#include <iostream>
29
30 PIRPanelManager::PIRPanelManager(
31   MainWindow *mw):
32     mainForm(0),
33     altMainForm(0),
34     utilityForm(0),
35     keypadForm(0),
36     menuForm(0),
37     mediaForm(0),
38     media2Form(0),
39     recordForm(0),
40     tvForm(0),
41     inputForm(0),
42     adjustForm(0),
43     acForm(0),
44     audioDeviceForm(0),
45     cameraForm(0),
46     roombaForm(0),
47     powerSearchForm(0),
48     altMainPanelFlag(false),
49     currentTabsName(Universal_Tabs),
50     mainWindow(mw)
51 {
52   QSettings settings("pietrzak.org", "Pierogi");
53   if (settings.contains("currentTabsName"))
54   {
55     currentTabsName = PIRTabBarName(settings.value("currentTabsName").toInt());
56   }
57
58   // Set up the panel names:
59   shortPanelNames[Main_Panel] = "Main";
60   longPanelNames[Main_Panel] =
61     "Main Panel - power, volume, and channel controls";
62   shortPanelNames[Utility_Panel] = "Utility";
63   longPanelNames[Utility_Panel] = 
64     "Utility Panel - commonly used controls";
65   shortPanelNames[Keypad_Panel] = "Keypad";
66   longPanelNames[Keypad_Panel] =
67     "Keypad Panel - numeric value entry";
68   shortPanelNames[Menu_Panel] = "Menu";
69   longPanelNames[Menu_Panel] =
70     "Menu Panel - enter, exit, and navigate menus";
71   shortPanelNames[Media_Panel] = "Media";
72   longPanelNames[Media_Panel] =
73     "Media Panel - control over recorded data";
74   shortPanelNames[Media2_Panel] = "Media2";
75   longPanelNames[Media2_Panel] =
76     "Media2 Panel - additonal media controls";
77   shortPanelNames[Record_Panel] = "Record";
78   longPanelNames[Record_Panel] =
79     "Program/Record Panel - control over memory and storage";
80   shortPanelNames[TV_Panel] = "TV";
81   longPanelNames[TV_Panel] =
82     "TV Panel - teletext and picture-in-picture";
83   shortPanelNames[Input_Panel] = "Input";
84   longPanelNames[Input_Panel] =
85     "Input Panel - manage data sources";
86   shortPanelNames[Adjust_Panel] = "Adjust";
87   longPanelNames[Adjust_Panel] =
88     "Adjust Panel - modify audio and video";
89   shortPanelNames[AC_Panel] = "AC";
90   longPanelNames[AC_Panel] =
91     "A/C Panel - air conditioner controls";
92   shortPanelNames[Audio_Panel] = "Audio";
93   longPanelNames[Audio_Panel] =
94     "Audio Device Panel - various audio related buttons";
95   shortPanelNames[Camera_Panel] = "Camera";
96   longPanelNames[Camera_Panel] =
97     "Camera Panel - simple shutter controls";
98   shortPanelNames[Roomba_Panel] = "Roomba";
99   longPanelNames[Roomba_Panel] =
100     "Roomba Panel - robotic vacuum cleaner controls";
101   shortPanelNames[PowerSearch_Panel] = "Keyset Search";
102   longPanelNames[PowerSearch_Panel] =
103     "Keyset Search Panel - execute power button in each keyset";
104
105   mainForm = new PIRMainForm(mainWindow);
106   panels[Main_Panel] = mainForm;
107
108   altMainForm = new PIRAltMainForm(mainWindow);
109   panels[Alt_Main_Panel] = altMainForm;
110
111   utilityForm = new PIRUtilityForm(mainWindow);
112   panels[Utility_Panel] = utilityForm;
113
114   keypadForm = new PIRKeypadForm(mainWindow);
115   panels[Keypad_Panel] = keypadForm;
116
117   menuForm = new PIRMenuForm(mainWindow);
118   panels[Menu_Panel] = menuForm;
119
120   mediaForm = new PIRMediaForm(mainWindow);
121   panels[Media_Panel] = mediaForm;
122
123   media2Form = new PIRMedia2Form(mainWindow);
124   panels[Media2_Panel] = media2Form;
125
126   recordForm = new PIRRecordForm(mainWindow);
127   panels[Record_Panel] = recordForm;
128
129   tvForm = new PIRTVForm(mainWindow);
130   panels[TV_Panel] = tvForm;
131
132   inputForm = new PIRInputForm(mainWindow);
133   panels[Input_Panel] = inputForm;
134
135   adjustForm = new PIRAdjustForm(mainWindow);
136   panels[Adjust_Panel] = adjustForm;
137
138   acForm = new PIRAirConditionerForm(mainWindow);
139   panels[AC_Panel] = acForm;
140
141   audioDeviceForm = new PIRAudioDeviceForm(mainWindow);
142   panels[Audio_Panel] = audioDeviceForm;
143
144   cameraForm = new PIRCameraForm(mainWindow);
145   panels[Camera_Panel] = cameraForm;
146
147   roombaForm = new PIRRoombaForm(mainWindow);
148   panels[Roomba_Panel] = roombaForm;
149
150   powerSearchForm = new PIRPowerSearchForm(mainWindow);
151   panels[PowerSearch_Panel] = powerSearchForm;
152
153   // Set up the panel collections:
154   PIRPanelNameList pset;
155
156   // The universal collection:
157   pset.push_back(Main_Panel);
158   pset.push_back(Utility_Panel);
159   pset.push_back(Keypad_Panel);
160   pset.push_back(Menu_Panel);
161   pset.push_back(Media_Panel);
162 //  pset.push_back(Input_Panel);
163   tabLists[Universal_Tabs] = pset;
164
165   // The TV collection:
166   pset.clear();
167   pset.push_back(Main_Panel);
168   pset.push_back(Utility_Panel);
169   pset.push_back(Keypad_Panel);
170   pset.push_back(Menu_Panel);
171   pset.push_back(TV_Panel);
172   pset.push_back(Adjust_Panel);
173   tabLists[TV_Tabs] = pset;
174
175   // The video media collection:
176   pset.clear();
177   pset.push_back(Main_Panel);
178   pset.push_back(Menu_Panel);
179   pset.push_back(Media_Panel);
180   pset.push_back(Media2_Panel);
181   pset.push_back(Input_Panel);
182   tabLists[VideoMedia_Tabs] = pset;
183
184   // Audio panel collection:
185   pset.clear();
186   pset.push_back(Main_Panel);
187   pset.push_back(Keypad_Panel);
188   pset.push_back(Media_Panel);
189   pset.push_back(Audio_Panel);
190   tabLists[Audio_Tabs] = pset;
191
192   // The air conditioner collection:
193   pset.clear();
194   pset.push_back(AC_Panel);
195   tabLists[AC_Tabs] = pset;
196
197   // The recording collection:
198   pset.clear();
199   pset.push_back(Record_Panel);
200   pset.push_back(Keypad_Panel);
201   tabLists[Record_Tabs] = pset;
202
203   // The camera control collection:
204   pset.clear();
205   pset.push_back(Camera_Panel);
206   tabLists[Camera_Tabs] = pset;
207
208   // The Roomba collection:
209   pset.clear();
210   pset.push_back(Roomba_Panel);
211   tabLists[Roomba_Tabs] = pset;
212
213   // The Power Search collection:
214   pset.clear();
215   pset.push_back(PowerSearch_Panel);
216   tabLists[PowerSearch_Tabs] = pset;
217 }
218
219
220 PIRPanelManager::~PIRPanelManager()
221 {
222   // Note!  We are _not_ deleting the panel forms here, because the Qt GUI
223   // has ownership over some of them.  Moreover, the Panel Manager is not
224   // currently designed to be destroyed until the program ends.  Should the
225   // manager need to be destroyed earlier, this destructor will need to be
226   // changed!
227 }
228
229
230 void PIRPanelManager::updateTabSet()
231 {
232   QSettings settings("pietrzak.org", "Pierogi");
233   settings.setValue("currentTabsName", currentTabsName);
234
235   mainWindow->disableUpdates();
236   mainWindow->clearTabs();
237
238   PIRPanelNameList::const_iterator i = tabLists[currentTabsName].begin();
239
240   while (i != tabLists[currentTabsName].end())
241   {
242     if ((*i == Main_Panel) && altMainPanelFlag)
243     {
244       mainWindow->addTab(altMainForm, shortPanelNames[Main_Panel]);
245     }
246     else
247     {
248       mainWindow->addTab(panels[*i], shortPanelNames[*i]);
249     }
250
251     ++i;
252   }
253
254   mainWindow->enableUpdates();
255 }
256
257
258 void PIRPanelManager::enableButtons(
259   const PIRKeysetManager *keyset,
260   unsigned int id)
261 {
262   mainForm->enableButtons(keyset, id);
263   altMainForm->enableButtons(keyset, id);
264   commonEnableButtons(keyset, id);
265 }
266
267
268 void PIRPanelManager::enableButtons(
269   const PIRKeysetManager *keyset,
270   unsigned int currentID,
271   unsigned int defaultID)
272 {
273   mainForm->enableButtons(keyset, currentID, defaultID);
274   altMainForm->enableButtons(keyset, currentID, defaultID);
275   commonEnableButtons(keyset, currentID);
276 }
277
278
279 void PIRPanelManager::commonEnableButtons(
280   const PIRKeysetManager *keyset,
281   unsigned int id)
282 {
283   utilityForm->enableButtons(keyset, id);
284   keypadForm->enableButtons(keyset, id);
285   menuForm->enableButtons(keyset, id);
286   mediaForm->enableButtons(keyset, id);
287   media2Form->enableButtons(keyset, id);
288   recordForm->enableButtons(keyset, id);
289   tvForm->enableButtons(keyset, id);
290   inputForm->enableButtons(keyset, id);
291   adjustForm->enableButtons(keyset, id);
292   acForm->enableButtons(keyset, id);
293   audioDeviceForm->enableButtons(keyset, id);
294   cameraForm->enableButtons(keyset, id);
295   roombaForm->enableButtons(keyset, id);
296
297   // Also, set the label in the power search form:
298   powerSearchForm->setKeysetName(mainWindow->getCurrentFullName());
299 }
300
301
302 void PIRPanelManager::useMainPanel()
303 {
304   if (!altMainPanelFlag)
305   {
306     // Already set correctly, nothing to do:
307     return;
308   }
309
310   altMainPanelFlag = false;
311
312   updateTabSet();
313 }
314
315
316 void PIRPanelManager::useAltMainPanel()
317 {
318   if (altMainPanelFlag)
319   {
320     // Already set correctly, nothing to do:
321     return;
322   }
323
324   altMainPanelFlag = true;
325
326   updateTabSet();
327 }
328
329
330 /*
331 void PIRPanelManager::setupUniversalTabs()
332 {
333   if (currentTabsName == Universal_Tabs) return;
334
335   currentTabsName = Universal_Tabs;
336   updateTabSet();
337 }
338
339
340 void PIRPanelManager::setupTVTabs()
341 {
342   if (currentTabsName == TV_Tabs) return;
343
344   currentTabsName = TV_Tabs;
345   updateTabSet();
346 }
347
348
349 void PIRPanelManager::setupVideoTabs()
350 {
351   if (currentTabsName == VideoMedia_Tabs) return;
352
353   currentTabsName = VideoMedia_Tabs;
354   updateTabSet();
355 }
356
357
358 void PIRPanelManager::setupACTabs()
359 {
360   if (currentTabsName == AC_Tabs) return;
361
362   currentTabsName = AC_Tabs;
363   updateTabSet();
364 }
365
366
367 void PIRPanelManager::setupRecordTabs()
368 {
369   if (currentTabsName == Record_Tabs) return;
370
371   currentTabsName = Record_Tabs;
372   updateTabSet();
373 }
374 */
375
376
377 void PIRPanelManager::setupTabs(
378   PIRTabBarName name)
379 {
380   if (currentTabsName == name) return;
381
382   currentTabsName = name;
383   updateTabSet();
384 }