Add const where appropriate, also gets rid of a compiler warning.
[mplayer/glamo.git] / gui / cfg.c
bloba57fa3db9d32ea915dc148fdecc0930d86f51766
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <string.h>
23 #include "config.h"
24 #include "mp_msg.h"
25 #include "help_mp.h"
26 #include "mixer.h"
27 #include "mplayer.h"
28 #include "m_config.h"
29 #include "m_option.h"
30 #include "get_path.h"
31 #include "libvo/sub.h"
32 #include "libvo/video_out.h"
33 #include "stream/stream.h"
34 #include "libmpdemux/demuxer.h"
35 #include "libass/ass.h"
36 #include "libass/ass_mp.h"
38 #include "cfg.h"
39 #include "app.h"
40 #include "interface.h"
41 #include "mplayer/play.h"
43 // --- params
45 int gtkEnableAudioEqualizer = 0;
47 int gtkVfPP = 0;
48 #ifdef CONFIG_LIBAVCODEC
49 int gtkVfLAVC = 0;
50 #endif
52 int gtkAONorm = 0;
53 int gtkAOSurround = 0;
54 int gtkAOExtraStereo = 0;
55 float gtkAOExtraStereoMul = 1.0;
56 #ifdef CONFIG_OSS_AUDIO
57 char * gtkAOOSSMixer;
58 char * gtkAOOSSMixerChannel;
59 char * gtkAOOSSDevice;
60 #endif
61 #ifdef CONFIG_ALSA
62 char * gtkAOALSAMixer;
63 char * gtkAOALSAMixerChannel;
64 char * gtkAOALSADevice;
65 #endif
66 #ifdef CONFIG_SDL
67 char * gtkAOSDLDriver;
68 #endif
69 #ifdef CONFIG_ESD
70 char * gtkAOESDDevice;
71 #endif
73 int gtkCacheOn = 0;
74 int gtkCacheSize = 2048;
76 int gtkAutoSyncOn = 0;
77 int gtkAutoSync = 0;
79 #ifdef CONFIG_DXR3
80 char * gtkDXR3Device;
81 #endif
83 int gtkSubDumpMPSub = 0;
84 int gtkSubDumpSrt = 0;
86 int gtkLoadFullscreen = 0;
87 int gtkShowVideoWindow = 1;
88 int gtkEnablePlayBar = 1;
90 int gui_save_pos = 1;
91 int gui_main_pos_x = -2;
92 int gui_main_pos_y = -2;
93 int gui_sub_pos_x = -1;
94 int gui_sub_pos_y = -1;
96 #ifdef CONFIG_ASS
97 gtkASS_t gtkASS;
98 #endif
99 // ---
101 extern int stop_xscreensaver;
102 extern int disable_gui_conf;
103 int m_config_parse_config_file(m_config_t* config, char *conffile);
105 static m_config_t * gui_conf;
106 static const m_option_t gui_opts[] =
108 { "enable_audio_equ",&gtkEnableAudioEqualizer,CONF_TYPE_FLAG,0,0,1,NULL },
110 { "vo_driver",&video_driver_list,CONF_TYPE_STRING_LIST,0,0,0,NULL },
111 { "vo_panscan",&vo_panscan,CONF_TYPE_FLOAT,CONF_RANGE,0.0,1.0,NULL },
112 { "vo_doublebuffering",&vo_doublebuffering,CONF_TYPE_FLAG,0,0,1,NULL },
113 { "vo_direct_render",&vo_directrendering,CONF_TYPE_FLAG,0,0,1,NULL },
114 #ifdef CONFIG_DXR3
115 { "vo_dxr3_device",&gtkDXR3Device,CONF_TYPE_STRING,0,0,0,NULL },
116 #endif
118 { "v_framedrop",&frame_dropping,CONF_TYPE_INT,CONF_RANGE,0,2,NULL },
119 { "v_flip",&flip,CONF_TYPE_INT,CONF_RANGE,-1,1,NULL },
120 { "v_ni",&force_ni,CONF_TYPE_FLAG,0,0,1,NULL },
121 { "v_idx",&index_mode,CONF_TYPE_INT,CONF_RANGE,-1,2,NULL },
122 { "v_vfm",&video_fm_list,CONF_TYPE_STRING_LIST,0,0,0,NULL },
123 { "a_afm",&audio_fm_list,CONF_TYPE_STRING_LIST,0,0,0,NULL },
125 { "vf_pp",&gtkVfPP,CONF_TYPE_FLAG,0,0,1,NULL },
126 { "vf_autoq",&auto_quality,CONF_TYPE_INT,CONF_RANGE,0,100,NULL },
127 #ifdef CONFIG_LIBAVCODEC
128 { "vf_lavc",&gtkVfLAVC,CONF_TYPE_FLAG,0,0,1,NULL },
129 #endif
131 { "ao_driver",&audio_driver_list,CONF_TYPE_STRING_LIST,0,0,0,NULL },
132 { "ao_volnorm",&gtkAONorm,CONF_TYPE_FLAG,0,0,1,NULL },
133 { "softvol",&soft_vol,CONF_TYPE_FLAG,0,0,1,NULL },
134 { "ao_surround",&gtkAOSurround,CONF_TYPE_FLAG,0,0,1,NULL },
135 { "ao_extra_stereo",&gtkAOExtraStereo,CONF_TYPE_FLAG,0,0,1,NULL },
136 { "ao_extra_stereo_coefficient",&gtkAOExtraStereoMul,CONF_TYPE_FLOAT,CONF_RANGE,-10,10,NULL },
137 #ifdef CONFIG_OSS_AUDIO
138 { "ao_oss_mixer",&gtkAOOSSMixer,CONF_TYPE_STRING,0,0,0,NULL },
139 { "ao_oss_mixer_channel",&gtkAOOSSMixerChannel,CONF_TYPE_STRING,0,0,0,NULL },
140 { "ao_oss_device",&gtkAOOSSDevice,CONF_TYPE_STRING,0,0,0,NULL },
141 #endif
142 #ifdef CONFIG_ALSA
143 { "ao_alsa_mixer",&gtkAOALSAMixer,CONF_TYPE_STRING,0,0,0,NULL },
144 { "ao_alsa_mixer_channel",&gtkAOALSAMixerChannel,CONF_TYPE_STRING,0,0,0,NULL },
145 { "ao_alsa_device",&gtkAOALSADevice,CONF_TYPE_STRING,0,0,0,NULL },
146 #endif
147 #ifdef CONFIG_SDL
148 { "ao_sdl_subdriver",&gtkAOSDLDriver,CONF_TYPE_STRING,0,0,0,NULL },
149 #endif
150 #ifdef CONFIG_ESD
151 { "ao_esd_device",&gtkAOESDDevice,CONF_TYPE_STRING,0,0,0,NULL },
152 #endif
154 { "dvd_device",&dvd_device,CONF_TYPE_STRING,0,0,0,NULL },
155 { "cdrom_device",&cdrom_device,CONF_TYPE_STRING,0,0,0,NULL },
157 { "osd_level",&osd_level,CONF_TYPE_INT,CONF_RANGE,0,3,NULL },
158 { "sub_auto_load",&sub_auto,CONF_TYPE_FLAG,0,0,1,NULL },
159 { "sub_unicode",&sub_unicode,CONF_TYPE_FLAG,0,0,1,NULL },
160 #ifdef CONFIG_ASS
161 { "ass_enabled",&ass_enabled,CONF_TYPE_FLAG,0,0,1,NULL },
162 { "ass_use_margins",&ass_use_margins,CONF_TYPE_FLAG,0,0,1,NULL },
163 { "ass_top_margin",&ass_top_margin,CONF_TYPE_INT,CONF_RANGE,0,512,NULL },
164 { "ass_bottom_margin",&ass_bottom_margin,CONF_TYPE_INT,CONF_RANGE,0,512,NULL },
165 #endif
166 { "sub_pos",&sub_pos,CONF_TYPE_INT,CONF_RANGE,0,200,NULL },
167 { "sub_overlap",&suboverlap_enabled,CONF_TYPE_FLAG,0,0,0,NULL },
168 #ifdef CONFIG_ICONV
169 { "sub_cp",&sub_cp,CONF_TYPE_STRING,0,0,0,NULL },
170 #endif
171 { "font_factor",&font_factor,CONF_TYPE_FLOAT,CONF_RANGE,0.0,10.0,NULL },
172 { "font_name",&font_name,CONF_TYPE_STRING,0,0,0,NULL },
173 #ifdef CONFIG_FREETYPE
174 { "font_encoding",&subtitle_font_encoding,CONF_TYPE_STRING,0,0,0,NULL },
175 { "font_text_scale",&text_font_scale_factor,CONF_TYPE_FLOAT,CONF_RANGE,0,100,NULL },
176 { "font_osd_scale",&osd_font_scale_factor,CONF_TYPE_FLOAT,CONF_RANGE,0,100,NULL },
177 { "font_blur",&subtitle_font_radius,CONF_TYPE_FLOAT,CONF_RANGE,0,8,NULL },
178 { "font_outline",&subtitle_font_thickness,CONF_TYPE_FLOAT,CONF_RANGE,0,8,NULL },
179 { "font_autoscale",&subtitle_autoscale,CONF_TYPE_INT,CONF_RANGE,0,3,NULL },
180 #endif
182 { "cache",&gtkCacheOn,CONF_TYPE_FLAG,0,0,1,NULL },
183 { "cache_size",&gtkCacheSize,CONF_TYPE_INT,CONF_RANGE,-1,65535,NULL },
185 { "playbar",&gtkEnablePlayBar,CONF_TYPE_FLAG,0,0,1,NULL },
186 { "load_fullscreen",&gtkLoadFullscreen,CONF_TYPE_FLAG,0,0,1,NULL },
187 { "show_videowin", &gtkShowVideoWindow,CONF_TYPE_FLAG,0,0,1,NULL },
188 { "stopxscreensaver",&stop_xscreensaver,CONF_TYPE_FLAG,0,0,1,NULL },
190 { "autosync",&gtkAutoSyncOn,CONF_TYPE_FLAG,0,0,1,NULL },
191 { "autosync_size",&gtkAutoSync,CONF_TYPE_INT,CONF_RANGE,0,10000,NULL },
193 { "gui_skin",&skinName,CONF_TYPE_STRING,0,0,0,NULL },
195 { "gui_save_pos", &gui_save_pos, CONF_TYPE_FLAG,0,0,1,NULL},
196 { "gui_main_pos_x", &gui_main_pos_x, CONF_TYPE_INT,0,0,0,NULL},
197 { "gui_main_pos_y", &gui_main_pos_y, CONF_TYPE_INT,0,0,0,NULL},
198 { "gui_video_out_pos_x", &gui_sub_pos_x, CONF_TYPE_INT,0,0,0,NULL},
199 { "gui_video_out_pos_y", &gui_sub_pos_y, CONF_TYPE_INT,0,0,0,NULL},
201 { "equ_channel_1",&gtkEquChannel1,CONF_TYPE_STRING,0,0,0,NULL },
202 { "equ_channel_2",&gtkEquChannel2,CONF_TYPE_STRING,0,0,0,NULL },
203 { "equ_channel_3",&gtkEquChannel3,CONF_TYPE_STRING,0,0,0,NULL },
204 { "equ_channel_4",&gtkEquChannel4,CONF_TYPE_STRING,0,0,0,NULL },
205 { "equ_channel_5",&gtkEquChannel5,CONF_TYPE_STRING,0,0,0,NULL },
206 { "equ_channel_6",&gtkEquChannel6,CONF_TYPE_STRING,0,0,0,NULL },
208 #if 1
209 #define audio_equ_row( i,j ) { "equ_band_"#i#j,&gtkEquChannels[i][j],CONF_TYPE_FLOAT,CONF_RANGE,-15.0,15.0,NULL },
210 audio_equ_row( 0,0 ) audio_equ_row( 0,1 ) audio_equ_row( 0,2 ) audio_equ_row( 0,3 ) audio_equ_row( 0,4 ) audio_equ_row( 0,5 ) audio_equ_row( 0,6 ) audio_equ_row( 0,7 ) audio_equ_row( 0,8 ) audio_equ_row( 0,9 )
211 audio_equ_row( 1,0 ) audio_equ_row( 1,1 ) audio_equ_row( 1,2 ) audio_equ_row( 1,3 ) audio_equ_row( 1,4 ) audio_equ_row( 1,5 ) audio_equ_row( 1,6 ) audio_equ_row( 1,7 ) audio_equ_row( 1,8 ) audio_equ_row( 1,9 )
212 audio_equ_row( 2,0 ) audio_equ_row( 2,1 ) audio_equ_row( 2,2 ) audio_equ_row( 2,3 ) audio_equ_row( 2,4 ) audio_equ_row( 2,5 ) audio_equ_row( 2,6 ) audio_equ_row( 2,7 ) audio_equ_row( 2,8 ) audio_equ_row( 2,9 )
213 audio_equ_row( 3,0 ) audio_equ_row( 3,1 ) audio_equ_row( 3,2 ) audio_equ_row( 3,3 ) audio_equ_row( 3,4 ) audio_equ_row( 3,5 ) audio_equ_row( 3,6 ) audio_equ_row( 3,7 ) audio_equ_row( 3,8 ) audio_equ_row( 3,9 )
214 audio_equ_row( 4,0 ) audio_equ_row( 4,1 ) audio_equ_row( 4,2 ) audio_equ_row( 4,3 ) audio_equ_row( 4,4 ) audio_equ_row( 4,5 ) audio_equ_row( 4,6 ) audio_equ_row( 4,7 ) audio_equ_row( 4,8 ) audio_equ_row( 4,9 )
215 audio_equ_row( 5,0 ) audio_equ_row( 5,1 ) audio_equ_row( 5,2 ) audio_equ_row( 5,3 ) audio_equ_row( 5,4 ) audio_equ_row( 5,5 ) audio_equ_row( 5,6 ) audio_equ_row( 5,7 ) audio_equ_row( 5,8 ) audio_equ_row( 5,9 )
216 #undef audio_equ_row
217 #endif
219 { NULL, NULL, 0, 0, 0, 0, NULL }
222 char * gfgets( char * str, int size, FILE * f )
224 char * s = fgets( str,size,f );
225 char c;
226 if ( s )
228 c=s[ strlen( s ) - 1 ]; if ( c == '\n' || c == '\r' ) s[ strlen( s ) - 1 ]=0;
229 c=s[ strlen( s ) - 1 ]; if ( c == '\n' || c == '\r' ) s[ strlen( s ) - 1 ]=0;
231 return s;
234 int cfg_read( void )
236 char * cfg = get_path( "gui.conf" );
237 FILE * f;
239 // -- read configuration
240 mp_msg( MSGT_GPLAYER,MSGL_V,"[cfg] reading config file: %s\n",cfg );
241 gui_conf=m_config_new();
242 m_config_register_options( gui_conf,gui_opts );
243 if ( !disable_gui_conf && m_config_parse_config_file( gui_conf,cfg ) < 0 )
245 mp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_ConfigFileError );
246 // exit( 1 );
248 free( cfg );
250 // -- read pl
251 cfg=get_path( "gui.pl" );
252 if ( (f=fopen( cfg,"rt" )) )
254 while ( !feof( f ) )
256 char tmp[512]; plItem * item;
257 if ( gfgets( tmp,512,f ) == NULL ) continue;
258 item=calloc( 1,sizeof( plItem ) );
259 item->path=strdup( tmp );
260 gfgets( tmp,512,f );
261 item->name=strdup( tmp );
262 gtkSet( gtkAddPlItem,0,(void*)item );
264 fclose( f );
266 free( cfg );
268 //-- read previously visited urls
269 cfg=get_path( "gui.url" );
270 if ( (f=fopen( cfg,"rt" )) )
272 while ( !feof( f ) )
274 char tmp[512]; URLItem * item;
275 if ( gfgets( tmp,512,f ) == NULL ) continue;
276 item=calloc( 1,sizeof( URLItem ) );
277 item->url=strdup( tmp );
278 gtkSet( gtkAddURLItem,0,(void*)item );
280 fclose( f );
282 free( cfg );
284 // -- reade file loader history
285 cfg=get_path( "gui.history" );
286 if ( (f=fopen( cfg,"rt+" )) )
288 int i = 0;
289 while ( !feof( f ) )
291 char tmp[512];
292 if ( gfgets( tmp,512,f ) == NULL ) continue;
293 fsHistory[i++]=gstrdup( tmp );
295 fclose( f );
297 free( cfg );
299 return 0;
302 int cfg_write( void )
304 char * cfg = get_path( "gui.conf" );
305 FILE * f;
306 int i;
308 // -- save configuration
309 if ( (f=fopen( cfg,"wt+" )) )
311 for ( i=0;gui_opts[i].name;i++ )
313 char* v = m_option_print(&gui_opts[i],gui_opts[i].p);
314 if(v == (char *)-1) {
315 mp_msg(MSGT_GPLAYER,MSGL_WARN,MSGTR_UnableToSaveOption, gui_opts[i].name);
316 v = NULL;
318 if(v) {
319 fprintf( f,"%s = \"%s\"\n",gui_opts[i].name, v);
320 free(v);
323 fclose( f );
325 free( cfg );
327 // -- save playlist
328 cfg=get_path( "gui.pl" );
329 if ( (f=fopen( cfg,"wt+" )) )
331 plCurrent=plList;
332 while ( plCurrent )
334 if ( plCurrent->path && plCurrent->name )
336 fprintf( f,"%s\n",plCurrent->path );
337 fprintf( f,"%s\n",plCurrent->name );
339 plCurrent=plCurrent->next;
341 fclose( f );
343 free( cfg );
345 // -- save URL's
346 cfg=get_path( "gui.url" );
347 if ( (f=fopen( cfg,"wt+" )) )
349 while ( URLList )
351 if ( URLList->url ) fprintf( f,"%s\n",URLList->url );
352 URLList=URLList->next;
354 fclose( f );
356 free( cfg );
358 // -- save file loader history
359 cfg=get_path( "gui.history" );
360 if ( (f=fopen( cfg,"wt+" )) )
362 int i = 0;
363 // while ( fsHistory[i] != NULL )
364 for ( i=0;i < 5; i++)
365 if( fsHistory[i] ) fprintf( f,"%s\n",fsHistory[i] );
366 fclose( f );
368 free( cfg );
370 return 0;