]> git.vomp.tv Git - vompclient-marten.git/blob - vopts.cc
Detect mpeg audio frame header changes, and wait at least 4 packets after a change...
[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 "osd.h"
26 #include "audio.h"
27 #include "remote.h"
28 #include "boxstack.h"
29 #include "woptionpane.h"
30 #include "wremoteconfig.h"
31 #include "log.h"
32 #include "option.h"
33 #include "vdr.h"
34 #include "command.h"
35
36 #ifdef VOMP_PLATTFORM_MVP
37 #include "mediaoptions.h"
38 #endif
39 //#include "vdr.h"
40 //#include "command.h"
41
42 VOpts::VOpts()
43 {
44   setTitleBarOn(1);
45   setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
46   setTitleText(tr("Options"));
47
48
49   setSize(520, 360);
50   createBuffer();
51   if (Video::getInstance()->getFormat() == Video::PAL)
52     setPosition(100, 110);
53   else
54     setPosition(90, 90);
55   
56   tabbar.setPosition(6, 32);
57   tabbar.setSize(getWidth() - 12, getHeight() - 34);
58   add(&tabbar);
59   
60   Option* option;
61   WOptionPane* wop;
62   
63   //  --- edit options start here
64   
65   static const char* options1[] = {"Old", "New"};
66
67   static const char* options5[] = {"Chop sides", "Letterbox"};
68   static const char* options6[] = {"On", "Off", "Last state"};
69   static const char* options7[] = {"All", "FTA only"};
70   static const char* options15[] = {"Alphabetical", "Chronological"};
71
72   static const char* options13[] = {"Auto","1024", "2048", "4096", "8192", "16384", "32768", "65536"};
73   static const char* options14[] = {"No", "Yes"};
74   static const char* options18[] = {"Off", "On"};
75   // Get list of languages from VDR and construct options table
76   LangCode = VDR::getInstance()->getLanguageList();
77   options2 = new const char*[LangCode.size()];
78   options2keys = new const char*[LangCode.size()];
79   I18n::lang_code_list::const_iterator iter;
80   UINT LangNumber = 0;
81   for (iter = LangCode.begin(); iter != LangCode.end(); ++iter,++LangNumber)
82   {
83     options2[LangNumber] = iter->second.c_str();
84     options2keys[LangNumber] = iter->first.c_str();
85   }
86
87   numPanes = 4;
88   panes = new Boxx*[numPanes];
89
90   wop = new WOptionPane();
91   tabbar.addTab(tr("General"), wop);
92   panes[0] = wop;
93 #ifdef MVP_REMOTE_TYPES
94   option = new Option(1, "Remote control type",      "General", "Remote type",           Option::TYPE_TEXT, 2, 0, 0, options1);
95   options.push_back(option);
96   wop->addOptionLine(option);
97 #endif
98   option = new Option(2, "Language",                 "General", "LangCode",              Option::TYPE_KEYED_TEXT, LangCode.size(), 0, 0, options2, options2keys);
99   options.push_back(option);
100   wop->addOptionLine(option);
101
102
103   UINT suppconn = Video::getInstance()->getSupportedFormats();
104   if (suppconn) {
105           int defaultch = 0;
106           if (suppconn & Video::COMPOSITERGB) {
107                   defaultch = 0;
108                   options3.push_back("RGB+composite");
109                   options3keys.push_back("RGB+composite");
110           }
111           if (Video::SVIDEO & suppconn) {
112                   options3.push_back("S-Video");
113                   options3keys.push_back("S-Video");
114           }
115           if (Video::HDMI & suppconn) {
116                   defaultch = options3.size();
117                   options3.push_back("HDMI");
118                   options3keys.push_back("HDMI");
119           }
120           if (Video::HDMI3D & suppconn) {
121                   options3.push_back("HDMI3D");
122                   options3keys.push_back("HDMI3D");
123           }
124           option = new Option(3, "TV connection type", "TV", "Connection",
125                           Option::TYPE_KEYED_TEXT, options3.size(), defaultch, 0,
126                           &(options3[0]), &(options3keys[0]));
127
128           options.push_back(option);
129           wop->addOptionLine(option);
130   }
131
132   UINT suppformats = Video::getInstance()->supportedTVFormats();
133   if (suppformats) {
134           int defaultch = 0;
135           options16.push_back("NTSC");
136           options16keys.push_back("NTSC");
137           if (suppformats & Video::PAL) {
138                   defaultch = 1;
139                   options16.push_back("PAL");
140                   options16keys.push_back("PAL");
141           }
142           if (Video::NTSC_J & suppformats) {
143                   options16.push_back("NTSC-J");
144                   options16keys.push_back("NTSC-J");
145           }
146           if (Video::PAL_M & suppformats) {
147                   options16.push_back("PAL-M");
148                   options16keys.push_back("PAL-M");
149           }
150
151           option = new Option(16, "TV standard (needs restart)", "General", "Override Video Format",
152                           Option::TYPE_KEYED_TEXT, options16.size(), defaultch, 0,
153                           &(options16[0]), &(options16keys[0]));
154
155           options.push_back(option);
156           wop->addOptionLine(option);
157   }
158
159   UINT supptvsize=Video::getInstance()->supportedTVsize();
160   if (supptvsize) {
161           int defaultch=0;
162           options4.push_back("4:3");
163           options4keys.push_back("4:3");
164       if (Video::ASPECT16X9 & supptvsize) {
165           options4.push_back("16:9");
166           options4keys.push_back("16:9");
167 //        defaultch=1;
168       }
169       if (Video::ASPECT14X9 & supptvsize) {
170           options4.push_back("14:9");
171           options4keys.push_back("14:9");
172       }
173           option = new Option(4, "TV aspect ratio", "TV", "Aspect",
174                                 Option::TYPE_KEYED_TEXT, options4.size(), defaultch, 0,
175                                 &(options4[0]), &(options4keys[0]));
176           options.push_back(option);
177           wop->addOptionLine(option);
178   }
179
180   option = new Option(5, "16:9 on 4:3 display mode", "TV",      "Widemode",              Option::TYPE_TEXT, 2, 0, 0, options5);
181   options.push_back(option);
182   wop->addOptionLine(option);
183   option = new Option(6, "Power state after bootup", "General", "Power After Boot",      Option::TYPE_TEXT, 3, 0, 0, options6);
184   options.push_back(option);
185   wop->addOptionLine(option);
186   option = new Option(7, "Display channels",         "General", "Channels",              Option::TYPE_TEXT, 2, 0, 0, options7);
187   options.push_back(option);
188   wop->addOptionLine(option);
189   option = new Option(15, "Recordings sort order",   "General", "Recordings Sort Order", Option::TYPE_TEXT, 2, 0, 0, options15);
190   options.push_back(option);
191   wop->addOptionLine(option);
192   option = new Option(18, "Automatic VDR shutdown",  "General", "VDR shutdown",          Option::TYPE_TEXT, 2, 0, 0, options18);
193   options.push_back(option);
194   wop->addOptionLine(option);
195
196   Remote::getInstance()->addOptionsToPanes(0,&options,wop);
197   Video::getInstance()->addOptionsToPanes(0,&options,wop);
198   Audio::getInstance()->addOptionsToPanes(0,&options,wop);
199
200     
201 /*  WRemoteConfig* wrc = new WRemoteConfig();
202   tabbar.addTab(tr("Remote Control"), wrc);*/
203   Remote::getInstance()->addOptionPagesToWTB(&tabbar);
204  // panes[1] = wrc;
205
206   Video::getInstance()->addOptionPagesToWTB(&tabbar);
207   Audio::getInstance()->addOptionPagesToWTB(&tabbar);
208 #ifdef VOMP_PLATTFORM_MVP
209   MediaOptions::getInstance()->addOptionPagesToWTB(&tabbar);
210 #endif
211
212
213   wop = new WOptionPane(); 
214   tabbar.addTab(tr("Timers"), wop);
215   panes[1] = wop;
216   
217   option = new Option(9, "Default start margin (minutes)",  "Timers", "Start margin",  Option::TYPE_INT, 20, 5, 0, NULL);
218   options.push_back(option);
219   wop->addOptionLine(option);
220   option = new Option(10, "Default end margin (minutes)",   "Timers", "End margin",    Option::TYPE_INT, 20, 5, 0, NULL);
221   options.push_back(option);
222   wop->addOptionLine(option);
223   option = new Option(11, "Default priority",               "Timers", "Priority",      Option::TYPE_INT, 100, 99, 0, NULL);
224   options.push_back(option);
225   wop->addOptionLine(option);
226   option = new Option(12, "Default lifetime",               "Timers", "Lifetime",      Option::TYPE_INT, 100, 99, 0, NULL);
227   options.push_back(option);
228   wop->addOptionLine(option);
229
230   Remote::getInstance()->addOptionsToPanes(1,&options,wop);
231   Video::getInstance()->addOptionsToPanes(1,&options,wop);
232   Audio::getInstance()->addOptionsToPanes(1,&options,wop);
233
234     
235   wop = new WOptionPane(); 
236   tabbar.addTab(tr("Advanced"), wop);
237   panes[2] = wop;
238   
239   option = new Option(8, "VDR-Pri 0=OK !See forums!",  "General",  "Live priority",      Option::TYPE_INT,  199, -1, -99, NULL);
240   options.push_back(option);
241   wop->addOptionLine(option);
242   option = new Option(13, "TCP receive window size",   "Advanced", "TCP receive window", Option::TYPE_TEXT, 8, /*1*/DEFAULT_TCP_WINDOWSIZENR, 0, options13);
243   options.push_back(option);
244   wop->addOptionLine(option);
245 #ifdef PAL_WSS
246   option = new Option(14, "Use WSS (PAL only)",        "General",  "WSS",                Option::TYPE_TEXT, 2, 0, 0, options14);
247   options.push_back(option);
248   wop->addOptionLine(option);
249 #endif
250   const char * * fontnames;
251   const char * * fontnames_keys;
252   int numfonts=Osd::getInstance()->getFontNames(&fontnames,&fontnames_keys);
253   if (numfonts) {
254           option = new Option(17, "Font Name",   "Advanced", "Font Name",  Option::TYPE_KEYED_TEXT, numfonts, 1, 0, fontnames,fontnames_keys);
255           options.push_back(option);
256           wop->addOptionLine(option);
257   }
258
259   Remote::getInstance()->addOptionsToPanes(2,&options,wop);
260   Video::getInstance()->addOptionsToPanes(2,&options,wop);
261   Audio::getInstance()->addOptionsToPanes(2,&options,wop);
262 }
263
264 VOpts::~VOpts()
265 {
266  // for (int i = 0; i < numPanes; i++) delete panes[i]; //Move to TabBar, Marten
267   delete[] panes;
268
269   for(vector<Option*>::iterator j = options.begin(); j != options.end(); j++) delete *j;
270   delete[] options2;
271   delete[] options2keys;
272 }
273
274 int VOpts::handleCommand(int command)
275 {
276   // either is active, handle back
277   if (command == Remote::BACK)
278   {
279     doSave();
280     return 4;
281   }
282   else
283   {
284     int retval = tabbar.handleCommand(command);
285     if (retval == 1)
286     {
287       BoxStack::getInstance()->update(this);
288       return 2;
289     }
290     else if (retval == 2)
291     {
292       // command was taken and actively ignored
293       return 2;
294     }
295     else
296     {
297       return 1; // ???
298     }
299   }
300 }
301
302 void VOpts::doSave()
303 {
304   VDR* vdr = VDR::getInstance();
305
306   Remote::getInstance()->saveOptionstoServer(); //Remote
307   Video::getInstance()->saveOptionstoServer(); //Video
308   Audio::getInstance()->saveOptionstoServer(); //Remote
309 #ifdef VOMP_PLATTFORM_MVP
310   MediaOptions::getInstance()->saveOptionstoServer(); //Media
311 #endif
312
313   // Damn, and the dynamic idea was going *so* well...
314   //Whats about a check with typeid operator?
315   WOptionPane* wop;
316   wop = (WOptionPane*)panes[0];
317   wop->saveOpts();  
318   wop = (WOptionPane*)panes[1];
319   wop->saveOpts();  
320   wop = (WOptionPane*)panes[2];
321   wop->saveOpts();  
322
323
324   for (UINT i = 0; i < options.size(); i++)
325   {
326     if (options[i]->configChoice == options[i]->userSetChoice) continue; // no change
327
328     Log::getInstance()->log("Options", Log::DEBUG, "Option %i has changed", i);
329
330     // Save to vdr
331
332     if (options[i]->optionType == Option::TYPE_TEXT)
333     {
334       vdr->configSave(options[i]->configSection, options[i]->configKey, options[i]->options[options[i]->userSetChoice]);
335     }
336     else if (options[i]->optionType == Option::TYPE_KEYED_TEXT)
337     {
338       vdr->configSave(options[i]->configSection, options[i]->configKey, options[i]->optionkeys[options[i]->userSetChoice]);
339     }
340     else
341     {
342       char buffer[20];
343       sprintf(buffer, "%i", options[i]->userSetChoice);
344       vdr->configSave(options[i]->configSection, options[i]->configKey, buffer);
345     }
346     
347     // Set new setting
348     if (options[i]->opthandler == NULL) //Ok, noone else is handling this, we are doing it
349     {
350       switch(options[i]->id)
351       {
352         case 1:
353         {
354 #ifdef MVP_REMOTE_TYPES
355           if (options[i]->userSetChoice == 1)
356           {
357             Log::getInstance()->log("Options", Log::DEBUG, "Setting New Remote");
358             Remote::getInstance()->setRemoteType(Remote::NEWREMOTE);
359           }
360           else
361           {
362             Log::getInstance()->log("Options", Log::DEBUG, "Setting Old Remote");
363             Remote::getInstance()->setRemoteType(Remote::OLDREMOTE);
364           }
365 #endif
366           break;
367         }
368         case 2:
369         {
370           Message* m = new Message();
371           m->message = Message::CHANGE_LANGUAGE;
372           m->to = Command::getInstance();
373           Command::getInstance()->postMessageNoLock(m);
374           break;
375         }
376         case 3:
377         {
378                 if (STRCASECMP(options[i]->optionkeys[options[i]->userSetChoice], "RGB+composite")==0)
379                 {
380                         Log::getInstance()->log("Options", Log::DEBUG, "Setting RGB/Composite");
381                         Video::getInstance()->setConnection(Video::COMPOSITERGB);
382                 }
383                 else  if (STRCASECMP(options[i]->optionkeys[options[i]->userSetChoice], "S-Video")==0)
384                 {
385                         Log::getInstance()->log("Options", Log::DEBUG, "Setting S-Video");
386                         Video::getInstance()->setConnection(Video::SVIDEO);
387                 }
388                 else  if (STRCASECMP(options[i]->optionkeys[options[i]->userSetChoice], "HDMI")==0)
389                 {
390                         Log::getInstance()->log("Options", Log::DEBUG, "Setting HDMI");
391                         Video::getInstance()->setConnection(Video::HDMI);
392                 }
393                 else  if (STRCASECMP(options[i]->optionkeys[options[i]->userSetChoice], "HDMI3D")==0)
394                 {
395                         Log::getInstance()->log("Options", Log::DEBUG, "Setting HDMI");
396                         Video::getInstance()->setConnection(Video::HDMI3D);
397                 }
398                 break;
399         }
400         case 4:
401         {
402           if (STRCASECMP(options[i]->optionkeys[options[i]->userSetChoice], "16:9")==0)
403           {
404             Log::getInstance()->log("Options", Log::DEBUG, "Setting 16:9 TV");
405             Video::getInstance()->setTVsize(Video::ASPECT16X9);
406           }
407           else  if (STRCASECMP(options[i]->optionkeys[options[i]->userSetChoice], "4:3")==0)
408           {
409             Log::getInstance()->log("Options", Log::DEBUG, "Setting 4:3 TV");
410             Video::getInstance()->setTVsize(Video::ASPECT4X3);
411           }
412           else  if (STRCASECMP(options[i]->optionkeys[options[i]->userSetChoice], "14:9")==0)
413           {
414                   Log::getInstance()->log("Options", Log::DEBUG, "Setting 14:9 TV");
415                   Video::getInstance()->setTVsize(Video::ASPECT14X9);
416           }
417           break;
418         }
419         case 5:
420         {
421           if (options[i]->userSetChoice == 1)
422           {
423             Log::getInstance()->log("Options", Log::DEBUG, "Setting letterbox");
424             Video::getInstance()->setMode(Video::LETTERBOX);
425           }
426           else
427           {
428             Log::getInstance()->log("Options", Log::DEBUG, "Setting chop-sides");
429             Video::getInstance()->setMode(Video::NORMAL);
430           }
431           break;
432         }
433         case 13:
434         {
435           size_t newTCPsize = 2048;
436           if (options[i]->userSetChoice == 0) newTCPsize = 0; //zero means auto
437           else if (options[i]->userSetChoice == 1) newTCPsize = 1024;
438           else if (options[i]->userSetChoice == 2) newTCPsize = 2048;
439           else if (options[i]->userSetChoice == 3) newTCPsize = 4096;
440           else if (options[i]->userSetChoice == 4) newTCPsize = 8192;
441           else if (options[i]->userSetChoice == 5) newTCPsize = 16384;
442           else if (options[i]->userSetChoice == 6) newTCPsize = 32768;
443           else if (options[i]->userSetChoice == 7) newTCPsize = 65536;
444           Log::getInstance()->log("Options", Log::DEBUG, "Setting TCP window size %i", newTCPsize);
445           VDR::getInstance()->setReceiveWindow(newTCPsize);
446           break;
447         }
448         case 17:
449         {
450           Osd::getInstance()->setFont(options[i]->optionkeys[options[i]->userSetChoice]);
451           break;
452         }
453         case 18:
454         {
455           if (options[i]->userSetChoice == 1)
456           {
457             Log::getInstance()->log("Options", Log::DEBUG, "Setting automatic vdr shutdown");
458             VDR::getInstance()->setVDRShutdown(true);
459           }
460           else
461           {
462             Log::getInstance()->log("Options", Log::DEBUG, "Setting local shutdown");
463             VDR::getInstance()->setVDRShutdown(false);
464           }
465           break;
466         }
467       }
468     }
469     else
470     {
471       options[i]->opthandler->handleOptionChanges(options[i]);
472     }
473   }
474 }
475
476 void VOpts::processMessage(Message* m)
477 {
478   if (m->message == Message::MOUSE_MOVE)
479   {
480     int x=(m->parameter>>16)-getScreenX();
481     int y=(m->parameter&0xFFFF)-getScreenY();
482     if (tabbar.mouseMove(x,y))
483     {
484       BoxStack::getInstance()->update(this);
485     }
486     
487   }
488   else if (m->message == Message::MOUSE_LBDOWN)
489   {
490     int x=(m->parameter>>16)-getScreenX();
491     int y=(m->parameter&0xFFFF)-getScreenY();
492     if (tabbar.mouseLBDOWN(x,y)) 
493     {
494       BoxStack::getInstance()->update(this);
495     } 
496     else if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
497     {
498       BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
499     }
500   }
501 }
502