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