]> git.sesse.net Git - vlc/blob - plugins/gtk/gtk_preferences.c
*initialization bugfixes in input_dvd
[vlc] / plugins / gtk / gtk_preferences.c
1 /*****************************************************************************
2  * gtk_control.c : functions to handle stream control buttons.
3  *****************************************************************************
4  * Copyright (C) 2000, 2001 VideoLAN
5  * $Id: gtk_preferences.c,v 1.1 2001/05/15 01:01:44 stef Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *          Stéphane Borel <stef@via.ecp.fr>
9  *      
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 #define MODULE_NAME gtk
26 #include "modules_inner.h"
27
28 /*****************************************************************************
29  * Preamble
30  *****************************************************************************/
31 #include "defs.h"
32 #include <sys/types.h>                                              /* off_t */
33 #include <stdlib.h>
34
35 #include <gtk/gtk.h>
36
37 #include <string.h>
38
39 #include "config.h"
40 #include "common.h"
41 #include "threads.h"
42 #include "mtime.h"
43
44 #include "stream_control.h"
45 #include "input_ext-intf.h"
46
47 #include "interface.h"
48 #include "intf_playlist.h"
49 #include "intf_msg.h"
50
51 #include "gtk_callbacks.h"
52 #include "gtk_interface.h"
53 #include "gtk_support.h"
54 #include "gtk_playlist.h"
55 #include "intf_gtk.h"
56
57 #include "main.h"
58
59 /****************************************************************************
60  * GtkPreferencesShow: display interface window after initialization
61  * if necessary
62  ****************************************************************************/
63
64 /* macros to create preference box */
65 #define ASSIGN_PSZ_ENTRY( var, default, name )                               \
66     gtk_entry_set_text( GTK_ENTRY( gtk_object_get_data( GTK_OBJECT(          \
67         p_intf->p_sys->p_preferences ), name ) ),                            \
68                         main_GetPszVariable( var, default ) )
69
70 #define ASSIGN_INT_VALUE( var, default, name )                                        \
71     gtk_spin_button_set_value( GTK_SPIN_BUTTON( gtk_object_get_data(         \
72         GTK_OBJECT( p_intf->p_sys->p_preferences ), name ) ),                \
73                                main_GetIntVariable( var, default ) )
74
75 #define ASSIGN_INT_TOGGLE( var, default, name )                                       \
76     gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( gtk_object_get_data(    \
77         GTK_OBJECT( p_intf->p_sys->p_preferences ), name ) ),                \
78                                main_GetIntVariable( var, default ) )
79
80 gboolean GtkPreferencesShow( GtkWidget       *widget,
81                              GdkEventButton  *event,
82                              gpointer         user_data )
83 {
84     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
85
86     /* If we have never used the file selector, open it */
87     if( !GTK_IS_WIDGET( p_intf->p_sys->p_preferences ) )
88     {
89         p_intf->p_sys->p_preferences = create_intf_preferences();
90         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_preferences ),
91                              "p_intf", p_intf );
92
93         /* Default path */
94         ASSIGN_PSZ_ENTRY( INTF_PATH_VAR, INTF_PATH_DEFAULT,
95                           "preferences_file_path_entry" );
96     
97         /* Default DVD */
98         ASSIGN_PSZ_ENTRY( INPUT_DVD_DEVICE_VAR,INPUT_DVD_DEVICE_DEFAULT,
99                           "preferences_disc_dvd_entry" );
100     
101         /* Default VCD */
102         ASSIGN_PSZ_ENTRY( INPUT_VCD_DEVICE_VAR, INPUT_VCD_DEVICE_DEFAULT,
103                           "preferences_disc_vcd_entry" );
104     
105         /* Default server */
106         ASSIGN_PSZ_ENTRY( INPUT_SERVER_VAR, INPUT_SERVER_DEFAULT,
107                           "preferences_network_server_entry" );
108     
109         /* Default port */
110         ASSIGN_INT_VALUE( INPUT_PORT_VAR, INPUT_PORT_DEFAULT,
111                           "preferences_network_port_spinbutton" );
112     
113         /* Broadcast address */
114         ASSIGN_PSZ_ENTRY( INPUT_BCAST_ADRR_VAR, INPUT_BCAST_ADDR_DEFAULT,
115                           "preferences_network_broadcast_entry" );
116     
117         /* Broadcast stream by default ? */
118         ASSIGN_INT_TOGGLE( INPUT_BROADCAST_VAR, INPUT_BROADCAST_DEFAULT,
119                            "preferences_network_broadcast_checkbutton" );
120     
121         /* XXX Protocol */
122     
123         /* Default interface */
124         ASSIGN_PSZ_ENTRY( INTF_METHOD_VAR, INTF_METHOD_DEFAULT,
125                           "preferences_interface_entry" );
126     
127         /* Default video output */
128         ASSIGN_PSZ_ENTRY( VOUT_METHOD_VAR, VOUT_METHOD_DEFAULT,
129                           "preferences_video_output_entry" );
130     
131         /* Default output width */
132         ASSIGN_INT_VALUE( VOUT_WIDTH_VAR, VOUT_WIDTH_DEFAULT,
133                           "preferences_video_width_spinbutton" );
134     
135         /* Default output height */
136         ASSIGN_INT_VALUE( VOUT_HEIGHT_VAR, VOUT_HEIGHT_DEFAULT,
137                           "preferences_video_height_spinbutton" );
138     
139         /* XXX Default screen depth */
140     
141         /* XXX Default fullscreen depth */
142     
143         /* XXX Default gamma */
144         
145         /* Fullscreen on play */
146         ASSIGN_INT_TOGGLE( VOUT_FULLSCREEN_VAR, VOUT_FULLSCREEN_DEFAULT,
147                            "preferences_video_fullscreen_checkbutton" );
148     
149         /* Grayscale display */
150         ASSIGN_INT_TOGGLE( VOUT_GRAYSCALE_VAR, VOUT_GRAYSCALE_DEFAULT,
151                            "preferences_video_grayscale_checkbutton" );
152     
153         /* Default audio output */
154         ASSIGN_PSZ_ENTRY( AOUT_METHOD_VAR, AOUT_METHOD_DEFAULT,
155                           "preferences_audio_output_entry" );
156     
157         /* Default audio device */
158         ASSIGN_PSZ_ENTRY( AOUT_DSP_VAR, AOUT_DSP_DEFAULT,
159                           "preferences_audio_device_entry" );
160     
161         /* XXX Default frequency */
162     
163         /* XXX Default quality */
164     
165         /* XXX Default number of channels */
166     
167         /* Use spdif output ? */
168         ASSIGN_INT_TOGGLE( AOUT_SPDIF_VAR, AOUT_SPDIF_DEFAULT,
169                            "preferences_audio_spdif_checkbutton" );
170     
171         /* Launch playlist on startup */
172         ASSIGN_INT_TOGGLE( PLAYLIST_STARTUP_VAR, PLAYLIST_STARTUP_DEFAULT,
173                         "preferences_playlist_startup_checkbutton" );
174     
175         /* Enqueue drag'n dropped item as default */
176         ASSIGN_INT_TOGGLE( PLAYLIST_ENQUEUE_VAR, PLAYLIST_ENQUEUE_DEFAULT,
177                            "preferences_playlist_enqueue_checkbutton" );
178     
179         /* Loop on playlist end */
180         ASSIGN_INT_TOGGLE( PLAYLIST_LOOP_VAR, PLAYLIST_LOOP_DEFAULT,
181                            "preferences_playlist_loop_checkbutton" );
182     
183         /* Verbosity of warning messages */
184         ASSIGN_INT_VALUE( INTF_WARNING_VAR, INTF_WARNING_DEFAULT,
185                           "preferences_misc_messages_spinbutton" );
186 #undef ASSIGN_PSZ_ENTRY
187 #undef ASSIGN_INT_VALUE
188 #undef ASSIGN_INT_TOGGLE
189     }
190
191     gtk_widget_show( p_intf->p_sys->p_preferences );
192     gdk_window_raise( p_intf->p_sys->p_preferences->window );
193
194     return TRUE;
195 }
196
197 /****************************************************************************
198  * GtkPreferencesApply: store the values into the environnement variables
199  ****************************************************************************/
200
201 /* macros to read value frfom preference box */
202 #define ASSIGN_PSZ_ENTRY( var, name )                                        \
203     main_PutPszVariable( var, gtk_entry_get_text(                            \
204     GTK_ENTRY( gtk_object_get_data( GTK_OBJECT( p_preferences ), name ) ) ) )
205
206 #define ASSIGN_INT_VALUE( var, name )                                        \
207     main_PutIntVariable( var, gtk_spin_button_get_value_as_int(              \
208         GTK_SPIN_BUTTON( gtk_object_get_data( GTK_OBJECT( p_preferences ),   \
209         name ) ) ) )
210
211 #define ASSIGN_INT_TOGGLE( var, name )                                       \
212     main_PutIntVariable( var, gtk_toggle_button_get_active(                  \
213         GTK_TOGGLE_BUTTON( gtk_object_get_data( GTK_OBJECT( p_preferences ), \
214         name ) ) ) )
215
216 void GtkPreferencesApply( GtkButton * button, gpointer user_data )
217 {
218     GtkWidget *     p_preferences;
219
220     /* get preferences window */
221     p_preferences = gtk_widget_get_toplevel( GTK_WIDGET( button ) );
222
223     /* Default path */
224     ASSIGN_PSZ_ENTRY( INTF_PATH_VAR, "preferences_file_path_entry" );
225
226     /* Default DVD */
227     ASSIGN_PSZ_ENTRY( INPUT_DVD_DEVICE_VAR, "preferences_disc_dvd_entry" );
228
229     /* Default VCD */
230     ASSIGN_PSZ_ENTRY( INPUT_VCD_DEVICE_VAR, "preferences_disc_vcd_entry" );
231
232     /* Default server */
233     ASSIGN_PSZ_ENTRY( INPUT_SERVER_VAR, "preferences_network_server_entry" );
234
235     /* Default port */
236     ASSIGN_INT_VALUE( INPUT_PORT_VAR, "preferences_network_port_spinbutton" );
237
238     /* Broadcast address */
239     ASSIGN_PSZ_ENTRY( INPUT_BCAST_ADRR_VAR,
240                       "preferences_network_broadcast_entry" );
241
242     /* Broadcast stream by default ? */
243     ASSIGN_INT_TOGGLE( INPUT_BROADCAST_VAR,
244                        "preferences_network_broadcast_checkbutton" );
245
246     /* XXX Protocol */
247
248     /* Default interface */
249     ASSIGN_PSZ_ENTRY( INTF_METHOD_VAR, "preferences_interface_entry" );
250
251     /* Default video output */
252     ASSIGN_PSZ_ENTRY( VOUT_METHOD_VAR, "preferences_video_output_entry" );
253
254     /* Default output width */
255     ASSIGN_INT_VALUE( VOUT_WIDTH_VAR, "preferences_video_width_spinbutton" );
256
257     /* Default output height */
258     ASSIGN_INT_VALUE( VOUT_HEIGHT_VAR, "preferences_video_height_spinbutton" );
259
260     /* XXX Default screen depth */
261
262     /* XXX Default fullscreen depth */
263
264     /* XXX Default gamma */
265     
266     /* Fullscreen on play */
267     ASSIGN_INT_TOGGLE( VOUT_FULLSCREEN_VAR,
268                        "preferences_video_fullscreen_checkbutton" );
269
270     /* Grayscale display */
271     ASSIGN_INT_TOGGLE( VOUT_GRAYSCALE_VAR,
272                        "preferences_video_grayscale_checkbutton" );
273
274     /* Default audio output */
275     ASSIGN_PSZ_ENTRY( AOUT_METHOD_VAR, "preferences_audio_output_entry" );
276
277     /* Default audio device */
278     ASSIGN_PSZ_ENTRY( AOUT_DSP_VAR, "preferences_audio_device_entry" );
279
280     /* XXX Default frequency */
281
282     /* XXX Default quality */
283
284     /* XXX Default number of channels */
285
286     /* Use spdif output ? */
287     ASSIGN_INT_TOGGLE( AOUT_SPDIF_VAR, "preferences_audio_spdif_checkbutton" );
288
289     /* Launch playlist on startup */
290     ASSIGN_INT_TOGGLE( PLAYLIST_STARTUP_VAR,
291                        "preferences_playlist_startup_checkbutton" );
292
293     /* Enqueue drag'n dropped item as default */
294     ASSIGN_INT_TOGGLE( PLAYLIST_ENQUEUE_VAR,
295                        "preferences_playlist_enqueue_checkbutton" );
296
297     /* Loop on playlist end */
298     ASSIGN_INT_TOGGLE( PLAYLIST_LOOP_VAR,
299                        "preferences_playlist_loop_checkbutton" );
300
301     /* Verbosity of warning messages */
302     ASSIGN_INT_VALUE( INTF_WARNING_VAR,
303                       "preferences_misc_messages_spinbutton" );
304 }
305 #undef ASSIGN_PSZ_ENTRY
306 #undef ASSIGN_INT_VALUE
307 #undef ASSIGN_INT_TOGGLE
308
309
310 void GtkPreferencesOk( GtkButton * button, gpointer user_data )
311 {
312     GtkPreferencesApply( button, user_data );
313     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
314 }
315
316
317 void GtkPreferencesCancel( GtkButton * button, gpointer user_data )
318 {
319     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
320 }