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