]> git.vomp.tv Git - vompclient-marten.git/blob - vopts.cc
0.2.7 readiness patches for Windows
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "vopts.h"
22
23 #include "colour.h"
24 #include "video.h"
25 #include "audio.h"
26 #include "i18n.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 //#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   numPanes = 4;
73   panes = new Boxx*[numPanes];
74  
75   wop = new WOptionPane(); 
76   tabbar.addTab(tr("General"), wop);
77   panes[0] = wop;
78   
79   option = new Option(1, "Remote control type",      "General", "Remote type",           Option::TYPE_TEXT, 2, 0, 0, options1);
80   options.push_back(option);
81   wop->addOptionLine(option);
82   option = new Option(2, "Language",                 "General", "Language",              Option::TYPE_TEXT, I18n::NumLanguages, 0, 0, I18n::Languages);
83   options.push_back(option);
84   wop->addOptionLine(option);
85   option = new Option(3, "TV connection type",       "TV",      "Connection",            Option::TYPE_TEXT, 2, 0, 0, options3);
86   options.push_back(option);
87   wop->addOptionLine(option);
88   option = new Option(4, "TV aspect ratio",          "TV",      "Aspect",                Option::TYPE_TEXT, 2, 0, 0, options4);
89   options.push_back(option);
90   wop->addOptionLine(option);
91   option = new Option(5, "16:9 on 4:3 display mode", "TV",      "Widemode",              Option::TYPE_TEXT, 2, 0, 0, options5);
92   options.push_back(option);
93   wop->addOptionLine(option);
94   option = new Option(6, "Power state after bootup", "General", "Power After Boot",      Option::TYPE_TEXT, 3, 0, 0, options6);
95   options.push_back(option);
96   wop->addOptionLine(option);
97   option = new Option(7, "Display channels",         "General", "Channels",              Option::TYPE_TEXT, 2, 0, 0, options7);
98   options.push_back(option);
99   wop->addOptionLine(option);
100   option = new Option(15, "Recordings sort order",   "General", "Recordings Sort Order", Option::TYPE_TEXT, 2, 0, 0, options15);
101   options.push_back(option);
102   wop->addOptionLine(option);
103   
104     
105 /*  WRemoteConfig* wrc = new WRemoteConfig();
106   tabbar.addTab(tr("Remote Control"), wrc);*/
107   Remote::getInstance()->addOptionPagesToWTB(&tabbar);
108  // panes[1] = wrc;
109
110   Video::getInstance()->addOptionPagesToWTB(&tabbar);
111   Audio::getInstance()->addOptionPagesToWTB(&tabbar);
112   
113   
114   wop = new WOptionPane(); 
115   tabbar.addTab(tr("Timers"), wop);
116   panes[1] = wop;
117   
118   option = new Option(9, "Default start margin (minutes)",  "Timers", "Start margin",  Option::TYPE_INT, 20, 5, 0, NULL);
119   options.push_back(option);
120   wop->addOptionLine(option);
121   option = new Option(10, "Default end margin (minutes)",   "Timers", "End margin",    Option::TYPE_INT, 20, 5, 0, NULL);
122   options.push_back(option);
123   wop->addOptionLine(option);
124   option = new Option(11, "Default priority",               "Timers", "Priority",      Option::TYPE_INT, 100, 99, 0, NULL);
125   options.push_back(option);
126   wop->addOptionLine(option);
127   option = new Option(12, "Default lifetime",               "Timers", "Lifetime",      Option::TYPE_INT, 100, 99, 0, NULL);
128   options.push_back(option);
129   wop->addOptionLine(option);
130
131     
132   wop = new WOptionPane(); 
133   tabbar.addTab(tr("Advanced"), wop);
134   panes[2] = wop;
135   
136   option = new Option(8, "VDR-Pri 0=OK !See forums!",  "General",  "Live priority",      Option::TYPE_INT,  100, 0, 0, NULL);
137   options.push_back(option);
138   wop->addOptionLine(option);
139   option = new Option(13, "TCP receive window size",   "Advanced", "TCP receive window", Option::TYPE_TEXT, 7, 1, 0, options13);
140   options.push_back(option);
141   wop->addOptionLine(option);
142   option = new Option(14, "Use WSS (PAL only)",        "General",  "WSS",                Option::TYPE_TEXT, 2, 0, 0, options14);
143   options.push_back(option);
144   wop->addOptionLine(option);  
145 }
146
147 VOpts::~VOpts()
148 {
149  // for (int i = 0; i < numPanes; i++) delete panes[i]; //Move to TabBar, Marten
150   delete[] panes;
151
152   for(vector<Option*>::iterator j = options.begin(); j != options.end(); j++) delete *j;
153 }
154
155 int VOpts::handleCommand(int command)
156 {
157   // either is active, handle back
158   if (command == Remote::BACK)
159   {
160     doSave();
161     return 4;
162   }
163   else
164   {
165     int retval = tabbar.handleCommand(command);
166     if (retval == 1)
167     {
168       BoxStack::getInstance()->update(this);
169       return 2;
170     }
171     else
172     {
173       return 1; // ???
174     }
175   }
176 }
177
178 void VOpts::doSave()
179 {
180   VDR* vdr = VDR::getInstance();
181
182   Remote::getInstance()->saveOptionstoServer(); //Remote
183   Video::getInstance()->saveOptionstoServer(); //Video
184   Audio::getInstance()->saveOptionstoServer(); //Remote
185
186   // Damn, and the dynamic idea was going *so* well...
187   //Whats about a check with typeid operator?
188   WOptionPane* wop;
189   wop = (WOptionPane*)panes[0];
190   wop->saveOpts();  
191   wop = (WOptionPane*)panes[1];
192   wop->saveOpts();  
193   wop = (WOptionPane*)panes[2];
194   wop->saveOpts();  
195
196
197   for (UINT i = 0; i < options.size(); i++)
198   {
199     if (options[i]->configChoice == options[i]->userSetChoice) continue; // no change
200
201     Log::getInstance()->log("Options", Log::DEBUG, "Option %i has changed", i);
202
203     // Save to vdr
204
205     if (options[i]->optionType == Option::TYPE_TEXT)
206     {
207       vdr->configSave(options[i]->configSection, options[i]->configKey, options[i]->options[options[i]->userSetChoice]);
208     }
209     else
210     {
211       char buffer[20];
212       sprintf(buffer, "%i", options[i]->userSetChoice);
213       vdr->configSave(options[i]->configSection, options[i]->configKey, buffer);
214     }
215     
216     // Set new setting
217     
218     switch(options[i]->id)
219     {
220       case 1:
221       {
222         if (options[i]->userSetChoice == 1)
223         {
224           Log::getInstance()->log("Options", Log::DEBUG, "Setting New Remote");
225           Remote::getInstance()->setRemoteType(Remote::NEWREMOTE);
226         }
227         else
228         {
229           Log::getInstance()->log("Options", Log::DEBUG, "Setting Old Remote");
230           Remote::getInstance()->setRemoteType(Remote::OLDREMOTE);
231         }
232         break;
233       }
234       case 2:
235       {
236         Message* m = new Message();
237         m->message = Message::CHANGE_LANGUAGE;
238         m->to = Command::getInstance();
239         Command::getInstance()->postMessageNoLock(m);
240         break;
241       }
242       case 3:
243       {
244         if (options[i]->userSetChoice == 1)
245         {
246           Log::getInstance()->log("Options", Log::DEBUG, "Setting S-Video");
247           Video::getInstance()->setConnection(Video::SVIDEO);
248         }
249         else
250         {
251           Log::getInstance()->log("Options", Log::DEBUG, "Setting RGB/Composite");
252           Video::getInstance()->setConnection(Video::COMPOSITERGB);
253         }
254         break;
255       }
256       case 4:
257       {
258         if (options[i]->userSetChoice == 1)
259         {
260           Log::getInstance()->log("Options", Log::DEBUG, "Setting 16:9 TV");
261           Video::getInstance()->setTVsize(Video::ASPECT16X9);
262         }
263         else
264         {
265           Log::getInstance()->log("Options", Log::DEBUG, "Setting 4:3 TV");
266           Video::getInstance()->setTVsize(Video::ASPECT4X3);
267         }
268         break;
269       }
270       case 5:
271       {
272         if (options[i]->userSetChoice == 1)
273         {
274           Log::getInstance()->log("Options", Log::DEBUG, "Setting letterbox");
275           Video::getInstance()->setMode(Video::LETTERBOX);
276         }
277         else
278         {
279           Log::getInstance()->log("Options", Log::DEBUG, "Setting chop-sides");
280           Video::getInstance()->setMode(Video::NORMAL);
281         }
282         break;
283       }
284       case 13:
285       {
286         size_t newTCPsize = 2048;
287
288         if (options[i]->userSetChoice == 0) newTCPsize = 1024;
289         else if (options[i]->userSetChoice == 1) newTCPsize = 2048;
290         else if (options[i]->userSetChoice == 2) newTCPsize = 4096;
291         else if (options[i]->userSetChoice == 3) newTCPsize = 8192;
292         else if (options[i]->userSetChoice == 4) newTCPsize = 16384;
293         else if (options[i]->userSetChoice == 5) newTCPsize = 32768;
294         else if (options[i]->userSetChoice == 6) newTCPsize = 65536;
295
296         Log::getInstance()->log("Options", Log::DEBUG, "Setting TCP window size %i", newTCPsize);
297         VDR::getInstance()->setReceiveWindow(newTCPsize);
298         break;
299       }
300     }
301   }
302 }
303
304 void VOpts::processMessage(Message* m)
305 {
306   if (m->message == Message::MOUSE_MOVE)
307   {
308     int x=(m->parameter>>16)-getScreenX();
309     int y=(m->parameter&0xFFFF)-getScreenY();
310     if (tabbar.mouseMove(x,y)) {
311         BoxStack::getInstance()->update(this);
312     }
313     
314   }
315   else if (m->message == Message::MOUSE_LBDOWN)
316   {
317     int x=(m->parameter>>16)-getScreenX();
318     int y=(m->parameter&0xFFFF)-getScreenY();
319     if (tabbar.mouseLBDOWN(x,y)) {
320         BoxStack::getInstance()->update(this);
321     } else if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
322     {
323         BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
324     }
325
326     
327   }
328 }
329