]> git.vomp.tv Git - vompclient-marten.git/blob - vopts.cc
Vogel Media Player 2008-11-28
[vompclient-marten.git] / vopts.cc
1 /*
2     Copyright 2007 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #include "vopts.h"
22
23 #include "colour.h"
24 #include "video.h"
25 #include "audio.h"
26 #include "remote.h"
27 #include "boxstack.h"
28 #include "woptionpane.h"
29 #include "wremoteconfig.h"
30 #include "log.h"
31 #include "option.h"
32 #include "vdr.h"
33 #include "command.h"
34 #include "mediaoptions.h"
35
36 //#include "vdr.h"
37 //#include "command.h"
38
39 VOpts::VOpts()
40 {
41   setTitleBarOn(1);
42   setTitleBarColour(Colour::TITLEBARBACKGROUND);
43   setTitleText(tr("Options"));
44
45   setSize(520, 360);
46   createBuffer();
47   if (Video::getInstance()->getFormat() == Video::PAL)
48     setPosition(100, 110);
49   else
50     setPosition(90, 90);
51   
52   tabbar.setPosition(6, 32);
53   tabbar.setSize(getWidth() - 12, getHeight() - 34);
54   add(&tabbar);
55   
56   Option* option;
57   WOptionPane* wop;
58   
59   //  --- edit options start here
60   
61   static const char* options1[] = {"Old", "New"};
62   static const char* options3[] = {"RGB+composite", "S-Video"};
63   static const char* options4[] = {"4:3", "16:9"};
64   static const char* options5[] = {"Chop sides", "Letterbox"};
65   static const char* options6[] = {"On", "Off", "Last state"};
66   static const char* options7[] = {"All", "FTA only"};
67   static const char* options15[] = {"Alphabetical", "Chronological"};
68
69   static const char* options13[] = {"1024", "2048", "4096", "8192", "16384", "32768", "65536"};
70   static const char* options14[] = {"No", "Yes"};
71
72   // Get list of languages from VDR and construct options table
73   LangCode = VDR::getInstance()->getLanguageList();
74   options2 = new const char*[LangCode.size()];
75   options2keys = new const char*[LangCode.size()];
76   I18n::lang_code_list::const_iterator iter;
77   UINT LangNumber = 0;
78   for (iter = LangCode.begin(); iter != LangCode.end(); ++iter,++LangNumber)
79   {
80     options2[LangNumber] = iter->second.c_str();
81     options2keys[LangNumber] = iter->first.c_str();
82   }
83
84   numPanes = 4;
85   panes = new Boxx*[numPanes];
86  
87   wop = new WOptionPane(); 
88   tabbar.addTab(tr("General"), wop);
89   panes[0] = wop;
90   
91   option = new Option(1, "Remote control type",      "General", "Remote type",           Option::TYPE_TEXT, 2, 0, 0, options1);
92   options.push_back(option);
93   wop->addOptionLine(option);
94   option = new Option(2, "Language",                 "General", "LangCode",              Option::TYPE_KEYED_TEXT, LangCode.size(), 0, 0, options2, options2keys);
95   options.push_back(option);
96   wop->addOptionLine(option);
97   option = new Option(3, "TV connection type",       "TV",      "Connection",            Option::TYPE_TEXT, 2, 0, 0, options3);
98   options.push_back(option);
99   wop->addOptionLine(option);
100   option = new Option(4, "TV aspect ratio",          "TV",      "Aspect",                Option::TYPE_TEXT, 2, 0, 0, options4);
101   options.push_back(option);
102   wop->addOptionLine(option);
103   option = new Option(5, "16:9 on 4:3 display mode", "TV",      "Widemode",              Option::TYPE_TEXT, 2, 0, 0, options5);
104   options.push_back(option);
105   wop->addOptionLine(option);
106   option = new Option(6, "Power state after bootup", "General", "Power After Boot",      Option::TYPE_TEXT, 3, 0, 0, options6);
107   options.push_back(option);
108   wop->addOptionLine(option);
109   option = new Option(7, "Display channels",         "General", "Channels",              Option::TYPE_TEXT, 2, 0, 0, options7);
110   options.push_back(option);
111   wop->addOptionLine(option);
112   option = new Option(15, "Recordings sort order",   "General", "Recordings Sort Order", Option::TYPE_TEXT, 2, 0, 0, options15);
113   options.push_back(option);
114   wop->addOptionLine(option);
115   
116   Remote::getInstance()->addOptionsToPanes(0,&options,wop);
117   Video::getInstance()->addOptionsToPanes(0,&options,wop);
118   Audio::getInstance()->addOptionsToPanes(0,&options,wop);
119   
120     
121 /*  WRemoteConfig* wrc = new WRemoteConfig();
122   tabbar.addTab(tr("Remote Control"), wrc);*/
123   Remote::getInstance()->addOptionPagesToWTB(&tabbar);
124  // panes[1] = wrc;
125
126   Video::getInstance()->addOptionPagesToWTB(&tabbar);
127   Audio::getInstance()->addOptionPagesToWTB(&tabbar);
128   MediaOptions::getInstance()->addOptionPagesToWTB(&tabbar);
129   
130   
131   wop = new WOptionPane(); 
132   tabbar.addTab(tr("Timers"), wop);
133   panes[1] = wop;
134   
135   option = new Option(9, "Default start margin (minutes)",  "Timers", "Start margin",  Option::TYPE_INT, 20, 5, 0, NULL);
136   options.push_back(option);
137   wop->addOptionLine(option);
138   option = new Option(10, "Default end margin (minutes)",   "Timers", "End margin",    Option::TYPE_INT, 20, 5, 0, NULL);
139   options.push_back(option);
140   wop->addOptionLine(option);
141   option = new Option(11, "Default priority",               "Timers", "Priority",      Option::TYPE_INT, 100, 99, 0, NULL);
142   options.push_back(option);
143   wop->addOptionLine(option);
144   option = new Option(12, "Default lifetime",               "Timers", "Lifetime",      Option::TYPE_INT, 100, 99, 0, NULL);
145   options.push_back(option);
146   wop->addOptionLine(option);
147
148   Remote::getInstance()->addOptionsToPanes(1,&options,wop);
149   Video::getInstance()->addOptionsToPanes(1,&options,wop);
150   Audio::getInstance()->addOptionsToPanes(1,&options,wop);
151
152     
153   wop = new WOptionPane(); 
154   tabbar.addTab(tr("Advanced"), wop);
155   panes[2] = wop;
156   
157   option = new Option(8, "VDR-Pri 0=OK !See forums!",  "General",  "Live priority",      Option::TYPE_INT,  100, 0, 0, NULL);
158   options.push_back(option);
159   wop->addOptionLine(option);
160   option = new Option(13, "TCP receive window size",   "Advanced", "TCP receive window", Option::TYPE_TEXT, 7, 1, 0, options13);
161   options.push_back(option);
162   wop->addOptionLine(option);
163   option = new Option(14, "Use WSS (PAL only)",        "General",  "WSS",                Option::TYPE_TEXT, 2, 0, 0, options14);
164   options.push_back(option);
165   wop->addOptionLine(option);  
166
167   Remote::getInstance()->addOptionsToPanes(2,&options,wop);
168   Video::getInstance()->addOptionsToPanes(2,&options,wop);
169   Audio::getInstance()->addOptionsToPanes(2,&options,wop);
170 }
171
172 VOpts::~VOpts()
173 {
174  // for (int i = 0; i < numPanes; i++) delete panes[i]; //Move to TabBar, Marten
175   delete[] panes;
176
177   for(vector<Option*>::iterator j = options.begin(); j != options.end(); j++) delete *j;
178   delete[] options2;
179   delete[] options2keys;
180 }
181
182 int VOpts::handleCommand(int command)
183 {
184   // either is active, handle back
185   if (command == Remote::BACK)
186   {
187     doSave();
188     return 4;
189   }
190   else
191   {
192     int retval = tabbar.handleCommand(command);
193     if (retval == 1)
194     {
195       BoxStack::getInstance()->update(this);
196       return 2;
197     }
198     else if (retval == 2)
199     {
200       // command was taken and actively ignored
201       return 2;
202     }
203     else
204     {
205       return 1; // ???
206     }
207   }
208 }
209
210 void VOpts::doSave()
211 {
212   VDR* vdr = VDR::getInstance();
213
214   Remote::getInstance()->saveOptionstoServer(); //Remote
215   Video::getInstance()->saveOptionstoServer(); //Video
216   Audio::getInstance()->saveOptionstoServer(); //Remote
217   MediaOptions::getInstance()->saveOptionstoServer(); //Media
218
219   // Damn, and the dynamic idea was going *so* well...
220   //Whats about a check with typeid operator?
221   WOptionPane* wop;
222   wop = (WOptionPane*)panes[0];
223   wop->saveOpts();  
224   wop = (WOptionPane*)panes[1];
225   wop->saveOpts();  
226   wop = (WOptionPane*)panes[2];
227   wop->saveOpts();  
228
229
230   for (UINT i = 0; i < options.size(); i++)
231   {
232     if (options[i]->configChoice == options[i]->userSetChoice) continue; // no change
233
234     Log::getInstance()->log("Options", Log::DEBUG, "Option %i has changed", i);
235
236     // Save to vdr
237
238     if (options[i]->optionType == Option::TYPE_TEXT)
239     {
240       vdr->configSave(options[i]->configSection, options[i]->configKey, options[i]->options[options[i]->userSetChoice]);
241     }
242     else if (options[i]->optionType == Option::TYPE_KEYED_TEXT)
243     {
244       vdr->configSave(options[i]->configSection, options[i]->configKey, options[i]->optionkeys[options[i]->userSetChoice]);
245     }
246     else
247     {
248       char buffer[20];
249       sprintf(buffer, "%i", options[i]->userSetChoice);
250       vdr->configSave(options[i]->configSection, options[i]->configKey, buffer);
251     }
252     
253     // Set new setting
254     if (options[i]->opthandler == NULL) //Ok, noone else is handling this, we are doing it
255     {
256       switch(options[i]->id)
257       {
258         case 1:
259         {
260           if (options[i]->userSetChoice == 1)
261           {
262             Log::getInstance()->log("Options", Log::DEBUG, "Setting New Remote");
263             Remote::getInstance()->setRemoteType(Remote::NEWREMOTE);
264           }
265           else
266           {
267             Log::getInstance()->log("Options", Log::DEBUG, "Setting Old Remote");
268             Remote::getInstance()->setRemoteType(Remote::OLDREMOTE);
269           }
270           break;
271         }
272         case 2:
273         {
274           Message* m = new Message();
275           m->message = Message::CHANGE_LANGUAGE;
276           m->to = Command::getInstance();
277           Command::getInstance()->postMessageNoLock(m);
278           break;
279         }
280         case 3:
281         {
282           if (options[i]->userSetChoice == 1)
283           {
284             Log::getInstance()->log("Options", Log::DEBUG, "Setting S-Video");
285             Video::getInstance()->setConnection(Video::SVIDEO);
286           }
287           else
288           {
289             Log::getInstance()->log("Options", Log::DEBUG, "Setting RGB/Composite");
290             Video::getInstance()->setConnection(Video::COMPOSITERGB);
291           }
292           break;
293         }
294         case 4:
295         {
296           if (options[i]->userSetChoice == 1)
297           {
298             Log::getInstance()->log("Options", Log::DEBUG, "Setting 16:9 TV");
299             Video::getInstance()->setTVsize(Video::ASPECT16X9);
300           }
301           else
302           {
303             Log::getInstance()->log("Options", Log::DEBUG, "Setting 4:3 TV");
304             Video::getInstance()->setTVsize(Video::ASPECT4X3);
305           }
306           break;
307         }
308         case 5:
309         {
310           if (options[i]->userSetChoice == 1)
311           {
312             Log::getInstance()->log("Options", Log::DEBUG, "Setting letterbox");
313             Video::getInstance()->setMode(Video::LETTERBOX);
314           }
315           else
316           {
317             Log::getInstance()->log("Options", Log::DEBUG, "Setting chop-sides");
318             Video::getInstance()->setMode(Video::NORMAL);
319           }
320           break;
321         }
322         case 13:
323         {
324           size_t newTCPsize = 2048;
325           if (options[i]->userSetChoice == 0) newTCPsize = 1024;
326           else if (options[i]->userSetChoice == 1) newTCPsize = 2048;
327           else if (options[i]->userSetChoice == 2) newTCPsize = 4096;
328           else if (options[i]->userSetChoice == 3) newTCPsize = 8192;
329           else if (options[i]->userSetChoice == 4) newTCPsize = 16384;
330           else if (options[i]->userSetChoice == 5) newTCPsize = 32768;
331           else if (options[i]->userSetChoice == 6) newTCPsize = 65536;
332           Log::getInstance()->log("Options", Log::DEBUG, "Setting TCP window size %i", newTCPsize);
333           VDR::getInstance()->setReceiveWindow(newTCPsize);
334           break;
335         }
336       }
337     }
338     else
339     {
340       options[i]->opthandler->handleOptionChanges(options[i]);
341     }
342   }
343 }
344
345 void VOpts::processMessage(Message* m)
346 {
347   if (m->message == Message::MOUSE_MOVE)
348   {
349     int x=(m->parameter>>16)-getScreenX();
350     int y=(m->parameter&0xFFFF)-getScreenY();
351     if (tabbar.mouseMove(x,y))
352     {
353       BoxStack::getInstance()->update(this);
354     }
355     
356   }
357   else if (m->message == Message::MOUSE_LBDOWN)
358   {
359     int x=(m->parameter>>16)-getScreenX();
360     int y=(m->parameter&0xFFFF)-getScreenY();
361     if (tabbar.mouseLBDOWN(x,y)) 
362     {
363       BoxStack::getInstance()->update(this);
364     } 
365     else if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
366     {
367       BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
368     }
369   }
370 }
371