2 Copyright 2004-2005 Chris Tallon, Andreas Vogel
4 This file is part of VOMP.
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.
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.
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.
22 #include "mediaoptions.h"
23 #include "woptionpane.h"
31 MediaOptions * MediaOptions::instance=NULL;
33 static const char * option1[]={"clip","letter","clipfactor"};
34 static const char * option2[]={"count","audio","picture","none"};
36 static const char * msection="Media";
38 MediaOptions::MediaOptions()
40 myOptions.push_back( new Option(1,"Slide Show Interval",msection,"SlideShowInterval",Option::TYPE_INT,20,5,1,NULL));
41 myOptions.push_back( new Option(2,"Picture Mode",msection,"PictureMode",Option::TYPE_TEXT,3,0,0,option1));
42 myOptions.push_back( new Option(3,"max. Scale Factor",msection,"ScaleFactor",Option::TYPE_INT,5,0,1,NULL));
43 myOptions.push_back( new Option(4,"Picture Size %(10...150)",msection,"PictureSize",Option::TYPE_INT,150,90,10,NULL));
44 myOptions.push_back( new Option(5,"Factor Red",msection,"FactorRed",Option::TYPE_INT,180,100,20,NULL));
45 myOptions.push_back( new Option(6,"Factor Green",msection,"FactorGreen",Option::TYPE_INT,180,100,20,NULL));
46 myOptions.push_back( new Option(7,"Factor Blue",msection,"FactorBlue",Option::TYPE_INT,180,100,20,NULL));
47 myOptions.push_back( new Option(8,"DirectoryPlayMode",msection,"DirectoryPlayMode",Option::TYPE_TEXT,4,0,0,option2));
48 //strange: Option ctor only sets configChoice - maybe this should set both...
49 for(vector<Option*>::iterator j = myOptions.begin(); j != myOptions.end(); j++) {
50 (*j)->userSetChoice=(*j)->configChoice;
52 Log::getInstance()->log("MediaOptions",Log::DEBUG,"ctor %d options",myOptions.size());
56 MediaOptions::~MediaOptions()
58 for(vector<Option*>::iterator j = myOptions.begin(); j != myOptions.end(); j++) delete *j;
62 bool MediaOptions::loadOptionsfromServer(VDR* vdr)
67 bool MediaOptions::saveOptionstoServer()
70 return externSaveOptionstoServer();
72 bool MediaOptions::externSaveOptionstoServer()
75 Log::getInstance()->log("MediaOptions", Log::DEBUG, "save for %i options", myOptions.size());
76 for (UINT i = 0; i < myOptions.size(); i++)
78 if (! saveOption(myOptions[i])) rt=false;
84 bool MediaOptions::saveOption(Option *o)
86 if (o->configChoice == o->userSetChoice) return true; // no change
88 Log::getInstance()->log("MediaOptions", Log::DEBUG, "Option %s has changed", o->configKey);
90 o->configChoice=o->userSetChoice;
94 if (o->optionType == Option::TYPE_TEXT)
96 VDR::getInstance()->configSave(o->configSection, o->configKey, o->options[o->userSetChoice]);
101 sprintf(buffer, "%i", o->userSetChoice);
102 VDR::getInstance()->configSave(o->configSection, o->configKey, buffer);
108 bool MediaOptions::addOptionPagesToWTB(WTabBar *wtb)
110 pane=new WOptionPane();
111 for(vector<Option*>::iterator j = myOptions.begin(); j != myOptions.end(); j++) {
112 pane->addOptionLine(*j);
114 //we have to be carefull here
115 //the pane will get deleted when the tabbar is deleted
116 //but the options will not be deleted
117 wtb->addTab(tr("Media"),pane);
121 MediaOptions * MediaOptions::getInstance() {
123 instance=new MediaOptions();
128 Option * MediaOptions::findOption(const char * name){
129 for(vector<Option*>::iterator j = myOptions.begin(); j != myOptions.end(); j++) {
130 if (strcmp((*j)->configKey,name) == 0) {
137 const char * MediaOptions::getStringOption(const char * name) {
138 const char * rt=NULL;
139 Option *o=findOption(name);
141 if (! o->optionType == Option::TYPE_TEXT) return NULL;
142 rt=o->options[o->userSetChoice];
143 Log::getInstance()->log("MediaOptions",Log::DEBUG,"option value for %s is %s",name,rt);
146 int MediaOptions::getIntOption(const char * name) {
147 Option *o=findOption(name);
149 if (! o->optionType == Option::TYPE_INT) return -1;
150 int rt=o->userSetChoice;
151 Log::getInstance()->log("MediaOptions",Log::DEBUG,"option value for %s is %d",name,rt);
154 bool MediaOptions::setIntOption(const char * name, UINT value) {
155 Option *o=findOption(name);
156 if (!o) return false;
157 if (! o->optionType == Option::TYPE_INT) return false;
158 o->userSetChoice=value;
159 Log::getInstance()->log("MediaOptions",Log::DEBUG,"option value for %s set to %d",name,value);
160 return saveOption(o);
162 bool MediaOptions::setStringOption(const char * name, const char * value) {
163 Option *o=findOption(name);
164 if (!o) return false;
165 if (! o->optionType == Option::TYPE_TEXT) return false;
167 for (UINT i = 0; i < o->numChoices; i++) {
168 if (!STRCASECMP(value, o->options[i]))
175 if (rt) Log::getInstance()->log("MediaOptions",Log::DEBUG,"option value for %s set to %d",name,value);
176 return saveOption(o);