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