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