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