1 /*
2 * MPlayer GUI for Win32
3 * Copyright (C) 2003 Sascha Sommer <saschasommer@freenet.de>
4 * Copyright (C) 2006 Erik Augustson <erik_27can@yahoo.com>
5 * Copyright (C) 2006 Gianluigi Tiesi <sherpya@netfarm.it>
6 *
7 * This file is part of MPlayer.
8 *
9 * MPlayer is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MPlayer is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #include <windows.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include "path.h"
28 #include "mplayer.h"
29 #include "mp_msg.h"
30 #include "help_mp.h"
31 #include "m_config.h"
32 #include "m_option.h"
33 #include "parser-cfg.h"
34 #include "libvo/video_out.h"
35 #include "osdep/priority.h"
36 #include "mixer.h"
37 #include "gui/ui/ui.h"
38 #include "gui/interface.h"
39 #include "gui.h"
40
41 static const char gui_configuration[] = "gui.conf";
42
43 /* params */
44 int gtkAONorm = FALSE;
45 int gtkAOExtraStereo = FALSE;
46 float gtkAOExtraStereoMul = 1.0f;
47 int gtkCacheOn = FALSE;
48 int gtkCacheSize = 2048;
49 int gtkAutoSyncOn = FALSE;
50 int gtkAutoSync = 0;
51
52 int video_window = TRUE;
53 int console = FALSE;
54
55 int gui_save_pos = TRUE;
56 int gui_main_pos_x = -2;
57 int gui_main_pos_y = -2;
58 int gui_video_pos_x = -1;
59 int gui_video_pos_y = -1;
60
61 m_config_t *gui_conf;
62 static const m_option_t gui_opts[] =
63 {
64 { "priority", &proc_priority, CONF_TYPE_STRING, 0, 0, 0, NULL},
65 { "vo_driver", &video_driver_list, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL },
66 { "v_framedrop", &frame_dropping, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL },
67 { "vo_doublebuffering", &vo_doublebuffering, CONF_TYPE_FLAG, 0, 0, 1, NULL },
68 { "vo_direct_render", &vo_directrendering, CONF_TYPE_FLAG, 0, 0, 1, NULL },
69 { "ao_driver", &audio_driver_list, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL },
70 { "ao_volnorm", >kAONorm, CONF_TYPE_FLAG, 0, 0, 1, NULL },
71 { "softvol", &soft_vol, CONF_TYPE_FLAG, 0, 0, 1, NULL },
72 { "ao_extra_stereo", >kAOExtraStereo, CONF_TYPE_FLAG, 0, 0, 1, NULL },
73 { "ao_extra_stereo_coefficient", >kAOExtraStereoMul, CONF_TYPE_FLOAT, CONF_RANGE, -10, 10, NULL },
74 { "delay", &audio_delay, CONF_TYPE_FLOAT, CONF_RANGE, -100.0, 100.0, NULL},
75 { "osd_level", &osd_level, CONF_TYPE_INT, CONF_RANGE, 0, 3, NULL },
76 { "cache", >kCacheOn, CONF_TYPE_FLAG, 0, 0, 1, NULL },
77 { "cache_size", >kCacheSize, CONF_TYPE_INT, CONF_RANGE, 32, 0x7fffffff, NULL },
78 { "autosync", >kAutoSyncOn, CONF_TYPE_FLAG, 0, 0, 1, NULL },
79 { "autosync_size", >kAutoSync, CONF_TYPE_INT, CONF_RANGE, 0, 10000, NULL },
80 { "gui_skin", &skinName, CONF_TYPE_STRING, 0, 0, 0, NULL },
81 { "gui_main_pos_x", &gui_main_pos_x, CONF_TYPE_INT, 0, 0, 0, NULL },
82 { "gui_main_pos_y", &gui_main_pos_y, CONF_TYPE_INT, 0, 0, 0, NULL },
83 { "gui_sub_pos_x", &gui_video_pos_x, CONF_TYPE_INT, 0, 0, 0, NULL },
84 { "gui_sub_pos_y", &gui_video_pos_y, CONF_TYPE_INT, 0, 0, 0, NULL },
85 { "sub_window", &video_window, CONF_TYPE_FLAG, 0, 0, 1, NULL},
86 { "console", &console, CONF_TYPE_FLAG, 0, 0, 1, NULL},
87 { "idle", &player_idle_mode, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL},
88 { NULL, NULL, 0, 0, 0, 0, NULL }
89 };
90
cfg_gui_include(m_option_t * conf,const char * filename)91 int cfg_gui_include(m_option_t *conf, const char *filename)
92 {
93 (void)conf;
94
95 return m_config_parse_config_file(gui_conf, filename, 0);
96 }
97
cfg_read(void)98 void cfg_read(void)
99 {
100 char *cfg = get_path(gui_configuration);
101
102 player_idle_mode = TRUE; // GUI is in idle mode by default
103
104 /* read configuration */
105 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] [cfg] reading config file: %s\n", cfg);
106 gui_conf = m_config_new();
107 m_config_register_options(gui_conf, gui_opts);
108 if (m_config_parse_config_file(gui_conf, cfg, 1) < 0)
109 mp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_GUI_WIN32_ConfigFileError);
110 free(cfg);
111 }
112
cfg_write(void)113 void cfg_write(void)
114 {
115 char *cfg = get_path(gui_configuration);
116 FILE *f;
117 int i;
118
119 /* save configuration */
120 if ((f = fopen(cfg, "wt+")))
121 {
122 for (i=0; gui_opts[i].name; i++)
123 {
124 char *v = m_option_print(&gui_opts[i], gui_opts[i].p);
125 if(v == (char *)-1) {
126 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_GUI_MSG_UnableToSaveOption, gui_opts[i].name);
127 v = NULL;
128 }
129 if(v)
130 {
131 char delim[] = "\"";
132
133 if (!strchr(v, ' ')) *delim = 0;
134
135 fprintf(f, "%s=%s%s%s\n", gui_opts[i].name, delim, v, delim);
136 free(v);
137 }
138 }
139 fclose(f);
140 }
141 free(cfg);
142 }
143