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