]> git.vomp.tv Git - vompclient.git/blob - voptionsmenu.cc
Fix for possible crash when removing bar
[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   setBackgroundColour(Colour::VIEWBACKGROUND);
28   setTitleBarOn(1);
29   setTitleBarColour(Colour::TITLEBARBACKGROUND);
30   setTitleText(tr("Options"));
31
32 //  int fontHeight = surface->getFontHeight();
33
34   doGeneral();
35   doRemoteConfig();
36   doTimers();
37   doAdvanced();
38
39   create();
40   draw();
41 }
42
43 VOptionsMenu::~VOptionsMenu()
44 {
45 }
46
47 void VOptionsMenu::draw()
48 {
49   VTabsViewMan::draw();
50 }
51
52 int VOptionsMenu::handleCommand(int command)
53 {
54   return VTabsViewMan::handleCommand(command);
55 }
56
57 void VOptionsMenu::processMessage(Message* m)
58 {
59   if (m->message == Message::CHANGED_OPTIONS)
60   {
61     doApplyChanges((map<int,int>*)m->parameter);
62     //viewman->removeView(this);
63
64     if (!VDR::getInstance()->isConnected()) Command::getInstance()->connectionLost();
65   }
66   else if (m->message == Message::CHANGED_REMOTECONTROL)
67   {
68     char* remote = Remote::getInstance()->SaveKeysConfig(); //FIXME
69     VDR::getInstance()->configSave("General","Remote keys",remote);
70     delete[] remote;
71   }
72   else
73   {
74     VTabsViewMan::processMessage(m);
75   }
76 }
77
78 void VOptionsMenu::doApplyChanges(map<int,int>* changedOptions)
79 {
80   Video* video = Video::getInstance();
81   map<int,int>::iterator i;
82
83   for(i = changedOptions->begin(); i != changedOptions->end(); i++)
84   {
85 //    printf("I FIRST = %i SECOND = %i\n", i->first, i->second);
86
87     switch(i->first)
88     {
89       case 1:
90       {
91         if (i->second == 1)
92         {
93           Log::getInstance()->log("Options", Log::DEBUG, "Setting New Remote");
94           Remote::getInstance()->setRemoteType(Remote::NEWREMOTE);
95         }
96         else
97         {
98           Log::getInstance()->log("Options", Log::DEBUG, "Setting Old Remote");
99           Remote::getInstance()->setRemoteType(Remote::OLDREMOTE);
100         }
101         break;
102       }
103       case 2:
104       {
105         Message* m = new Message();
106         m->message = Message::CHANGE_LANGUAGE;
107         m->to = Command::getInstance();
108         Command::getInstance()->postMessageNoLock(m);
109         break;
110       }
111       case 3:
112       {
113         if (i->second == 1)
114         {
115           Log::getInstance()->log("Options", Log::DEBUG, "Setting S-Video");
116           video->setConnection(Video::SVIDEO);
117         }
118         else
119         {
120           Log::getInstance()->log("Options", Log::DEBUG, "Setting RGB/Composite");
121           video->setConnection(Video::COMPOSITERGB);
122         }
123         break;
124       }
125       case 4:
126       {
127         if (i->second == 1)
128         {
129           Log::getInstance()->log("Options", Log::DEBUG, "Setting 16:9 TV");
130           video->setTVsize(Video::ASPECT16X9);
131         }
132         else
133         {
134           Log::getInstance()->log("Options", Log::DEBUG, "Setting 4:3 TV");
135           video->setTVsize(Video::ASPECT4X3);
136         }
137         break;
138       }
139       case 5:
140       {
141         if (i->second == 1)
142         {
143           Log::getInstance()->log("Options", Log::DEBUG, "Setting letterbox");
144           video->setMode(Video::LETTERBOX);
145         }
146         else
147         {
148           Log::getInstance()->log("Options", Log::DEBUG, "Setting chop-sides");
149           video->setMode(Video::NORMAL);
150         }
151         break;
152       }
153       case 13:
154       {
155         size_t newTCPsize = 2048;
156
157         if (i->second == 0) newTCPsize = 1024;
158         else if (i->second == 1) newTCPsize = 2048;
159         else if (i->second == 2) newTCPsize = 4096;
160         else if (i->second == 3) newTCPsize = 8192;
161         else if (i->second == 4) newTCPsize = 16384;
162         else if (i->second == 5) newTCPsize = 32768;
163         else if (i->second == 6) newTCPsize = 65536;
164
165         Log::getInstance()->log("Options", Log::DEBUG, "Setting TCP window size %i", newTCPsize);
166         VDR::getInstance()->setReceiveWindow(newTCPsize);
167         break;
168       }
169     }
170   }
171
172   delete changedOptions;
173
174 }
175
176 void VOptionsMenu::doGeneral()
177 {
178   static const int numOptions = 8;
179
180   static const char* options1[] = {"Old", "New"};
181   static const char* options3[] = {"RGB+composite", "S-Video"};
182   static const char* options4[] = {"4:3", "16:9"};
183   static const char* options5[] = {"Chop sides", "Letterbox"};
184   static const char* options6[] = {"On", "Off", "Last state"};
185   static const char* options7[] = {"All", "FTA only"};
186   static const char* options15[] = {"Alphabetical", "Chronological"};
187
188   const static OPTIONDATA optionData[numOptions] =
189   {
190     {1, "Remote control type",      "General", "Remote type",      OPTIONTYPE_TEXT, 2, 0, 0, options1 },
191     {2, "Language",                 "General", "Language",         OPTIONTYPE_TEXT, I18n::NumLanguages, 0, 0, I18n::Languages },
192     {3, "TV connection type",       "TV",      "Connection",       OPTIONTYPE_TEXT, 2, 0, 0, options3 },
193     {4, "TV aspect ratio",          "TV",      "Aspect",           OPTIONTYPE_TEXT, 2, 0, 0, options4 },
194     {5, "16:9 on 4:3 display mode", "TV",      "Widemode",         OPTIONTYPE_TEXT, 2, 0, 0, options5 },
195     {6, "Power state after bootup", "General", "Power After Boot", OPTIONTYPE_TEXT, 3, 0, 0, options6 },
196     {7, "Display channels",         "General", "Channels",         OPTIONTYPE_TEXT, 2, 0, 0, options7 },
197     {15, "Recordings sort order",   "General", "Recordings Sort Order", OPTIONTYPE_TEXT, 2, 0, 0, options15 },
198   };
199
200   // As all the above data is const static, it can be sent to the new View, this stack frame can
201   // quit and the pointers will all still be valid. I think. (Hope).
202
203   VOptions* v = new VOptions(this, tr("General"), optionData, numOptions);
204   v->draw();
205   add(v);
206   //viewman->updateView(v);
207 }
208
209 void VOptionsMenu::doRemoteConfig()
210 {
211   VRemoteConfig* v = new VRemoteConfig(this);
212   v->draw();
213   add(v);
214 }
215
216 void VOptionsMenu::doTimers()
217 {
218   static const int numOptions = 4;
219
220   const static OPTIONDATA optionData[numOptions] =
221   {
222     {9, "Default start margin (minutes)",  "Timers", "Start margin",  OPTIONTYPE_INT, 20, 5, 0, NULL },
223     {10, "Default end margin (minutes)",   "Timers", "End margin",    OPTIONTYPE_INT, 20, 5, 0, NULL },
224     {11, "Default priority",               "Timers", "Priority",      OPTIONTYPE_INT, 100, 99, 0, NULL },
225     {12, "Default lifetime",               "Timers", "Lifetime",      OPTIONTYPE_INT, 100, 99, 0, NULL },
226   };
227
228   // As all the above data is const static, it can be sent to the new View, this stack frame can
229   // quit and the pointers will all still be valid. I think. (Hope).
230
231   VOptions* v = new VOptions(this, tr("Timers"), optionData, numOptions);
232   v->draw();
233   add(v);
234   //viewman->updateView(v);
235 }
236
237 void VOptionsMenu::doAdvanced()
238 {
239   static const int numOptions = 3;
240
241   static const char* options13[] = {"1024", "2048", "4096", "8192", "16384", "32768", "65536"};
242   static const char* options14[] = {"No", "Yes"};
243
244   const static OPTIONDATA optionData[numOptions] =
245   {
246     {8, "VDR-Pri 0=OK !See forums!",  "General",  "Live priority",      OPTIONTYPE_INT,  100, 0, 0, NULL },
247     {13, "TCP receive window size",   "Advanced", "TCP receive window", OPTIONTYPE_TEXT, 7, 1, 0, options13 },
248     {14, "Use WSS (PAL only)",        "General",  "WSS",                OPTIONTYPE_TEXT, 2, 0, 0, options14 }
249   };
250
251   // As all the above data is const static, it can be sent to the new View, this stack frame can
252   // quit and the pointers will all still be valid. I think. (Hope).
253
254   VOptions* v = new VOptions(this, tr("Advanced"), optionData, numOptions);
255   v->draw();
256   add(v);
257   //viewman->updateView(v);
258 }