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