]> git.sesse.net Git - vlc/blob - plugins/gtk/gtk_preferences.c
f7cd18e36a3b61c5441d9cf3e457efbd4fa82c31
[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.10 2002/01/02 14:37:42 sam 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 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <sys/types.h>                                              /* off_t */
29 #include <stdlib.h>
30
31 #include <videolan/vlc.h>
32
33 #ifdef MODULE_NAME_IS_gnome
34 #   include <gnome.h>
35 #else
36 #   include <gtk/gtk.h>
37 #endif
38
39 #include <string.h>
40
41 #include "stream_control.h"
42 #include "input_ext-intf.h"
43
44 #include "interface.h"
45 #include "intf_playlist.h"
46
47 #include "gtk_callbacks.h"
48 #include "gtk_interface.h"
49 #include "gtk_support.h"
50 #include "gtk_playlist.h"
51 #include "gtk_common.h"
52
53 /****************************************************************************
54  * GtkPreferencesShow: display interface window after initialization
55  * if necessary
56  ****************************************************************************/
57
58 /* macros to create preference box */
59 #define ASSIGN_PSZ_ENTRY( var, default, name )                               \
60     gtk_entry_set_text( GTK_ENTRY( gtk_object_get_data( GTK_OBJECT(          \
61         p_intf->p_sys->p_preferences ), name ) ),                            \
62                         main_GetPszVariable( var, default ) )
63
64 #define ASSIGN_INT_VALUE( var, default, name )                                        \
65     gtk_spin_button_set_value( GTK_SPIN_BUTTON( gtk_object_get_data(         \
66         GTK_OBJECT( p_intf->p_sys->p_preferences ), name ) ),                \
67                                main_GetIntVariable( var, default ) )
68
69 #define ASSIGN_INT_TOGGLE( var, default, name )                                       \
70     gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( gtk_object_get_data(    \
71         GTK_OBJECT( p_intf->p_sys->p_preferences ), name ) ),                \
72                                main_GetIntVariable( var, default ) )
73
74 gboolean GtkPreferencesShow( GtkWidget       *widget,
75                              GdkEventButton  *event,
76                              gpointer         user_data )
77 {
78     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
79
80     /* If we have never used the file selector, open it */
81     if( !GTK_IS_WIDGET( p_intf->p_sys->p_preferences ) )
82     {
83         p_intf->p_sys->p_preferences = create_intf_preferences();
84         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_preferences ),
85                              "p_intf", p_intf );
86
87         /* Default path */
88         ASSIGN_PSZ_ENTRY( INTF_PATH_VAR, INTF_PATH_DEFAULT,
89                           "preferences_file_path_entry" );
90     
91         /* Default DVD */
92         ASSIGN_PSZ_ENTRY( INPUT_DVD_DEVICE_VAR,DVD_DEVICE,
93                           "preferences_disc_dvd_entry" );
94     
95         /* Default VCD */
96         ASSIGN_PSZ_ENTRY( INPUT_VCD_DEVICE_VAR, VCD_DEVICE,
97                           "preferences_disc_vcd_entry" );
98     
99         /* Default server */
100         ASSIGN_PSZ_ENTRY( INPUT_SERVER_VAR, INPUT_SERVER_DEFAULT,
101                           "preferences_network_server_entry" );
102     
103         /* Default port */
104         ASSIGN_INT_VALUE( INPUT_PORT_VAR, INPUT_PORT_DEFAULT,
105                           "preferences_network_port_spinbutton" );
106     
107         /* Broadcast address */
108         ASSIGN_PSZ_ENTRY( INPUT_BCAST_ADDR_VAR, INPUT_BCAST_ADDR_DEFAULT,
109                           "preferences_network_broadcast_entry" );
110     
111         /* Broadcast stream by default ? */
112         ASSIGN_INT_TOGGLE( INPUT_BROADCAST_VAR, INPUT_BROADCAST_DEFAULT,
113                            "preferences_network_broadcast_checkbutton" );
114     
115         /* XXX Protocol */
116     
117         /* Default interface */
118         ASSIGN_PSZ_ENTRY( INTF_METHOD_VAR, INTF_METHOD_DEFAULT,
119                           "preferences_interface_entry" );
120     
121         /* Default video output */
122         ASSIGN_PSZ_ENTRY( VOUT_METHOD_VAR, VOUT_METHOD_DEFAULT,
123                           "preferences_video_output_entry" );
124     
125         /* Default output width */
126         ASSIGN_INT_VALUE( VOUT_WIDTH_VAR, VOUT_WIDTH_DEFAULT,
127                           "preferences_video_width_spinbutton" );
128     
129         /* Default output height */
130         ASSIGN_INT_VALUE( VOUT_HEIGHT_VAR, VOUT_HEIGHT_DEFAULT,
131                           "preferences_video_height_spinbutton" );
132     
133         /* XXX Default screen depth */
134     
135         /* XXX Default fullscreen depth */
136     
137         /* XXX Default gamma */
138         
139         /* Fullscreen on play */
140         ASSIGN_INT_TOGGLE( VOUT_FULLSCREEN_VAR, VOUT_FULLSCREEN_DEFAULT,
141                            "preferences_video_fullscreen_checkbutton" );
142     
143         /* Grayscale display */
144         ASSIGN_INT_TOGGLE( VOUT_GRAYSCALE_VAR, VOUT_GRAYSCALE_DEFAULT,
145                            "preferences_video_grayscale_checkbutton" );
146     
147         /* Default audio output */
148         ASSIGN_PSZ_ENTRY( AOUT_METHOD_VAR, AOUT_METHOD_DEFAULT,
149                           "preferences_audio_output_entry" );
150     
151         /* Default audio device */
152         ASSIGN_PSZ_ENTRY( AOUT_DSP_VAR, AOUT_DSP_DEFAULT,
153                           "preferences_audio_device_entry" );
154     
155         /* XXX Default frequency */
156     
157         /* XXX Default quality */
158     
159         /* XXX Default number of channels */
160     
161         /* Use spdif output ? */
162         ASSIGN_INT_TOGGLE( AOUT_SPDIF_VAR, AOUT_SPDIF_DEFAULT,
163                            "preferences_audio_spdif_checkbutton" );
164     
165         /* Launch playlist on startup */
166         ASSIGN_INT_TOGGLE( PLAYLIST_STARTUP_VAR, PLAYLIST_STARTUP_DEFAULT,
167                         "preferences_playlist_startup_checkbutton" );
168     
169         /* Enqueue drag'n dropped item as default */
170         ASSIGN_INT_TOGGLE( PLAYLIST_ENQUEUE_VAR, PLAYLIST_ENQUEUE_DEFAULT,
171                            "preferences_playlist_enqueue_checkbutton" );
172     
173         /* Loop on playlist end */
174         ASSIGN_INT_TOGGLE( PLAYLIST_LOOP_VAR, PLAYLIST_LOOP_DEFAULT,
175                            "preferences_playlist_loop_checkbutton" );
176     
177         /* Verbosity of warning messages */
178         ASSIGN_INT_VALUE( INTF_WARNING_VAR, INTF_WARNING_DEFAULT,
179                           "preferences_misc_messages_spinbutton" );
180 #undef ASSIGN_PSZ_ENTRY
181 #undef ASSIGN_INT_VALUE
182 #undef ASSIGN_INT_TOGGLE
183     }
184
185     gtk_widget_show( p_intf->p_sys->p_preferences );
186     gdk_window_raise( p_intf->p_sys->p_preferences->window );
187
188     return TRUE;
189 }
190
191 /****************************************************************************
192  * GtkPreferencesApply: store the values into the environnement variables
193  ****************************************************************************/
194
195 /* macros to read value frfom preference box */
196 #define ASSIGN_PSZ_ENTRY( var, name )                                        \
197     main_PutPszVariable( var, gtk_entry_get_text(                            \
198     GTK_ENTRY( gtk_object_get_data( GTK_OBJECT( p_preferences ), name ) ) ) )
199
200 #define ASSIGN_INT_VALUE( var, name )                                        \
201     main_PutIntVariable( var, gtk_spin_button_get_value_as_int(              \
202         GTK_SPIN_BUTTON( gtk_object_get_data( GTK_OBJECT( p_preferences ),   \
203         name ) ) ) )
204
205 #define ASSIGN_INT_TOGGLE( var, name )                                       \
206     main_PutIntVariable( var, gtk_toggle_button_get_active(                  \
207         GTK_TOGGLE_BUTTON( gtk_object_get_data( GTK_OBJECT( p_preferences ), \
208         name ) ) ) )
209
210 void GtkPreferencesApply( GtkButton * button, gpointer user_data )
211 {
212     GtkWidget *     p_preferences;
213
214     /* get preferences window */
215     p_preferences = gtk_widget_get_toplevel( GTK_WIDGET( button ) );
216
217     /* Default path */
218     ASSIGN_PSZ_ENTRY( INTF_PATH_VAR, "preferences_file_path_entry" );
219
220     /* Default DVD */
221     ASSIGN_PSZ_ENTRY( INPUT_DVD_DEVICE_VAR, "preferences_disc_dvd_entry" );
222
223     /* Default VCD */
224     ASSIGN_PSZ_ENTRY( INPUT_VCD_DEVICE_VAR, "preferences_disc_vcd_entry" );
225
226     /* Default server */
227     ASSIGN_PSZ_ENTRY( INPUT_SERVER_VAR, "preferences_network_server_entry" );
228
229     /* Default port */
230     ASSIGN_INT_VALUE( INPUT_PORT_VAR, "preferences_network_port_spinbutton" );
231
232     /* Broadcast address */
233     ASSIGN_PSZ_ENTRY( INPUT_BCAST_ADDR_VAR,
234                       "preferences_network_broadcast_entry" );
235
236     /* Broadcast stream by default ? */
237     ASSIGN_INT_TOGGLE( INPUT_BROADCAST_VAR,
238                        "preferences_network_broadcast_checkbutton" );
239
240     /* XXX Protocol */
241
242     /* Default interface */
243     ASSIGN_PSZ_ENTRY( INTF_METHOD_VAR, "preferences_interface_entry" );
244
245     /* Default video output */
246     ASSIGN_PSZ_ENTRY( VOUT_METHOD_VAR, "preferences_video_output_entry" );
247
248     /* Default output width */
249     ASSIGN_INT_VALUE( VOUT_WIDTH_VAR, "preferences_video_width_spinbutton" );
250
251     /* Default output height */
252     ASSIGN_INT_VALUE( VOUT_HEIGHT_VAR, "preferences_video_height_spinbutton" );
253
254     /* XXX Default screen depth */
255
256     /* XXX Default fullscreen depth */
257
258     /* XXX Default gamma */
259     
260     /* Fullscreen on play */
261     ASSIGN_INT_TOGGLE( VOUT_FULLSCREEN_VAR,
262                        "preferences_video_fullscreen_checkbutton" );
263
264     /* Grayscale display */
265     ASSIGN_INT_TOGGLE( VOUT_GRAYSCALE_VAR,
266                        "preferences_video_grayscale_checkbutton" );
267
268     /* Default audio output */
269     ASSIGN_PSZ_ENTRY( AOUT_METHOD_VAR, "preferences_audio_output_entry" );
270
271     /* Default audio device */
272     ASSIGN_PSZ_ENTRY( AOUT_DSP_VAR, "preferences_audio_device_entry" );
273
274     /* XXX Default frequency */
275
276     /* XXX Default quality */
277
278     /* XXX Default number of channels */
279
280     /* Use spdif output ? */
281     ASSIGN_INT_TOGGLE( AOUT_SPDIF_VAR, "preferences_audio_spdif_checkbutton" );
282
283     /* Launch playlist on startup */
284     ASSIGN_INT_TOGGLE( PLAYLIST_STARTUP_VAR,
285                        "preferences_playlist_startup_checkbutton" );
286
287     /* Enqueue drag'n dropped item as default */
288     ASSIGN_INT_TOGGLE( PLAYLIST_ENQUEUE_VAR,
289                        "preferences_playlist_enqueue_checkbutton" );
290
291     /* Loop on playlist end */
292     ASSIGN_INT_TOGGLE( PLAYLIST_LOOP_VAR,
293                        "preferences_playlist_loop_checkbutton" );
294
295     /* Verbosity of warning messages */
296     ASSIGN_INT_VALUE( INTF_WARNING_VAR,
297                       "preferences_misc_messages_spinbutton" );
298 }
299 #undef ASSIGN_PSZ_ENTRY
300 #undef ASSIGN_INT_VALUE
301 #undef ASSIGN_INT_TOGGLE
302
303
304 void GtkPreferencesOk( GtkButton * button, gpointer user_data )
305 {
306     GtkPreferencesApply( button, user_data );
307     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
308 }
309
310
311 void GtkPreferencesCancel( GtkButton * button, gpointer user_data )
312 {
313     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
314 }
315
316 /****************************************************************************
317  * Callbacks for menuitems
318  ****************************************************************************/
319 void GtkPreferencesActivate( GtkMenuItem * menuitem, gpointer user_data )
320 {
321     GtkPreferencesShow( GTK_WIDGET( menuitem ), NULL, user_data );
322 }