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