]> git.vomp.tv Git - vompclient.git/blob - voptionsmenu.cc
Connection failed detection
[vompclient.git] / voptionsmenu.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "voptionsmenu.h"
22
23 VOptionsMenu::VOptionsMenu()
24 {
25   viewman = ViewMan::getInstance();
26
27   create(460, 200);
28   if (Video::getInstance()->getFormat() == Video::PAL)
29   {
30     setScreenPos(140, 170);
31   }
32   else
33   {
34     setScreenPos(130, 140);
35   }
36
37   setBackgroundColour(Colour::VIEWBACKGROUND);
38   setTitleBarOn(1);
39   setTitleBarColour(Colour::TITLEBARBACKGROUND);
40   setTitleText(tr("Options"));
41
42   int fontHeight = surface->getFontHeight();
43
44   // Build gui
45   WButton* wb;
46
47   wb = new WButton();
48   wb->setText("General");
49   wb->setSurface(surface);
50   wb->setSurfaceOffset(160, 60);
51   wb->setDimensions(140, fontHeight);
52   wb->setTag(1);
53   buttons.push_back(wb);
54
55   wb = new WButton();
56   wb->setText("Timers");
57   wb->setSurface(surface);
58   wb->setSurfaceOffset(160, 100);
59   wb->setDimensions(140, fontHeight);
60   wb->setTag(2);
61   buttons.push_back(wb);
62
63   wb = new WButton();
64   wb->setText("Advanced");
65   wb->setSurface(surface);
66   wb->setSurfaceOffset(160, 140);
67   wb->setDimensions(140, fontHeight);
68   wb->setTag(3);
69   buttons.push_back(wb);
70
71
72   selectedButton = buttons.begin();
73   (*selectedButton)->setActive(1);
74 }
75
76 VOptionsMenu::~VOptionsMenu()
77 {
78   while (!buttons.empty())
79   {
80     delete buttons.back();
81     buttons.pop_back();
82   }
83 }
84
85 void VOptionsMenu::draw()
86 {
87   View::draw();
88
89   vector<WButton*>::iterator i;
90   for(i = buttons.begin(); i != buttons.end(); i++)
91   {
92     (*i)->draw();
93   }
94 }
95
96 int VOptionsMenu::handleCommand(int command)
97 {
98   switch(command)
99   {
100     case Remote::DF_UP:
101     case Remote::UP:
102     {
103       if (selectedButton == buttons.begin()) return 2;
104       (*selectedButton)->setActive(0);
105       selectedButton--;
106       (*selectedButton)->setActive(1);
107       draw(); // fixme - just draw buttons
108       viewman->updateView(this);
109       return 2;
110     }
111     case Remote::DF_DOWN:
112     case Remote::DOWN:
113     {
114       if (selectedButton == (buttons.end() - 1)) return 2;
115       (*selectedButton)->setActive(0);
116       selectedButton++;
117       (*selectedButton)->setActive(1);
118       draw(); // fixme - just draw buttons
119       viewman->updateView(this);
120       return 2;
121     }
122     case Remote::BACK:
123     {
124       return 4;
125     }
126     case Remote::OK:
127     {
128       switch((*selectedButton)->getTag())
129       {
130         case 1: doGeneral();   break;
131         case 2: doTimers();    break;
132         case 3: doAdvanced();  break;
133       }
134       return 2;
135     }
136   }
137
138   return 1;
139 }
140
141 void VOptionsMenu::processMessage(Message* m)
142 {
143   if (m->message == Message::CHANGED_OPTIONS)
144   {
145     doApplyChanges((map<int,int>*)m->parameter);
146     viewman->removeView(this);
147   }
148 }
149
150 void VOptionsMenu::doApplyChanges(map<int,int>* changedOptions)
151 {
152   Video* video = Video::getInstance();
153   map<int,int>::iterator i;
154
155   for(i = changedOptions->begin(); i != changedOptions->end(); i++)
156   {
157     printf("I FIRST = %i SECOND = %i\n", i->first, i->second);
158
159     switch(i->first)
160     {
161       case 1:
162       {
163         if (i->second == 1)
164         {
165           Log::getInstance()->log("Options", Log::DEBUG, "Setting New Remote");
166           Remote::getInstance()->setRemoteType(Remote::NEWREMOTE);
167         }
168         else
169         {
170           Log::getInstance()->log("Options", Log::DEBUG, "Setting Old Remote");
171           Remote::getInstance()->setRemoteType(Remote::OLDREMOTE);
172         }
173         break;
174       }
175       case 2:
176       {
177         I18n::initialize();
178         VWelcome::getInstance()->redrawLang();
179         break;
180       }
181       case 3:
182       {
183         if (i->second == 1)
184         {
185           Log::getInstance()->log("Options", Log::DEBUG, "Setting S-Video");
186           video->setConnection(Video::SVIDEO);
187         }
188         else
189         {
190           Log::getInstance()->log("Options", Log::DEBUG, "Setting RGB/Composite");
191           video->setConnection(Video::COMPOSITERGB);
192         }
193         break;
194       }
195       case 4:
196       {
197         if (i->second == 1)
198         {
199           Log::getInstance()->log("Options", Log::DEBUG, "Setting 16:9 TV");
200           video->setTVsize(Video::ASPECT16X9);
201         }
202         else
203         {
204           Log::getInstance()->log("Options", Log::DEBUG, "Setting 4:3 TV");
205           video->setTVsize(Video::ASPECT4X3);
206         }
207         break;
208       }
209       case 5:
210       {
211         if (i->second == 1)
212         {
213           Log::getInstance()->log("Options", Log::DEBUG, "Setting letterbox");
214           video->setMode(Video::LETTERBOX);
215         }
216         else
217         {
218           Log::getInstance()->log("Options", Log::DEBUG, "Setting chop-sides");
219           video->setMode(Video::NORMAL);
220         }
221         break;
222       }
223       case 13:
224       {
225         size_t newTCPsize = 2048;
226
227         if (i->second == 0) newTCPsize = 1024;
228         else if (i->second == 1) newTCPsize = 2048;
229         else if (i->second == 2) newTCPsize = 4096;
230         else if (i->second == 3) newTCPsize = 8192;
231         else if (i->second == 4) newTCPsize = 16384;
232         else if (i->second == 5) newTCPsize = 32768;
233         else if (i->second == 6) newTCPsize = 65536;
234
235         Log::getInstance()->log("Options", Log::DEBUG, "Setting TCP window size %i", newTCPsize);
236         VDR::getInstance()->setReceiveWindow(newTCPsize);
237         break;
238       }
239     }
240   }
241
242   delete changedOptions;
243
244 }
245
246 void VOptionsMenu::doGeneral()
247 {
248   static const int numOptions = 7;
249
250   static const char* options1[] = {"Old", "New"};
251   static const char* options3[] = {"RGB+composite", "S-Video"};
252   static const char* options4[] = {"4:3", "16:9"};
253   static const char* options5[] = {"Chop sides", "Letterbox"};
254   static const char* options6[] = {"On", "Off", "Last state"};
255   static const char* options7[] = {"All", "FTA only"};
256
257   const static OPTIONDATA optionData[numOptions] =
258   {
259     {1, "Remote control type",      "General", "Remote type",      OPTIONTYPE_TEXT, 2, 0, 0, options1 },
260     {2, "Language",                 "General", "Language",         OPTIONTYPE_TEXT, I18n::NumLanguages, 0, 0, I18n::Languages },
261     {3, "TV connection type",       "TV",      "Connection",       OPTIONTYPE_TEXT, 2, 0, 0, options3 },
262     {4, "TV aspect ratio",          "TV",      "Aspect",           OPTIONTYPE_TEXT, 2, 0, 0, options4 },
263     {5, "16:9 on 4:3 display mode", "TV",      "Widemode",         OPTIONTYPE_TEXT, 2, 0, 0, options5 },
264     {6, "Power state after bootup", "General", "Power After Boot", OPTIONTYPE_TEXT, 3, 0, 0, options6 },
265     {7, "Display channels",         "General", "Channels",         OPTIONTYPE_TEXT, 2, 0, 0, options7 },
266   };
267
268   // As all the above data is const static, it can be sent to the new View, this stack frame can
269   // quit and the pointers will all still be valid. I think. (Hope).
270
271   VOptions* v = new VOptions(this, tr("General Options"), optionData, numOptions);
272   v->draw();
273   viewman->add(v);
274   viewman->updateView(v);
275 }
276
277
278 void VOptionsMenu::doTimers()
279 {
280   static const int numOptions = 4;
281
282   const static OPTIONDATA optionData[numOptions] =
283   {
284     {9, "Default start margin (minutes)", "Timers", "Start margin",  OPTIONTYPE_INT, 20, 5, 0, NULL },
285     {10, "Default end margin (minutes)",   "Timers", "End margin",    OPTIONTYPE_INT, 20, 5, 0, NULL },
286     {11, "Default priority",               "Timers", "Priority",      OPTIONTYPE_INT, 100, 99, 0, NULL },
287     {12, "Default lifetime",               "Timers", "Lifetime",      OPTIONTYPE_INT, 100, 99, 0, NULL },
288   };
289
290   // As all the above data is const static, it can be sent to the new View, this stack frame can
291   // quit and the pointers will all still be valid. I think. (Hope).
292
293   VOptions* v = new VOptions(this, tr("Timer Options"), optionData, numOptions);
294   v->draw();
295   viewman->add(v);
296   viewman->updateView(v);
297 }
298
299 void VOptionsMenu::doAdvanced()
300 {
301   static const int numOptions = 2;
302
303   static const char* options13[] = {"1024", "2048", "4096", "8192", "16384", "32768", "65536"};
304
305   const static OPTIONDATA optionData[numOptions] =
306   {
307     {8, "VDR-Pri 0=OK !See forums!",  "General",  "Live priority",      OPTIONTYPE_INT,  100, 0, 0, NULL },
308     {13, "TCP receive window size",   "Advanced", "TCP receive window", OPTIONTYPE_TEXT, 7, 1, 0, options13 }
309   };
310
311   // As all the above data is const static, it can be sent to the new View, this stack frame can
312   // quit and the pointers will all still be valid. I think. (Hope).
313
314   VOptions* v = new VOptions(this, tr("Advanced Options"), optionData, numOptions);
315   v->draw();
316   viewman->add(v);
317   viewman->updateView(v);
318 }