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