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 $
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Stéphane Borel <stef@via.ecp.fr>
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.
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.
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 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <sys/types.h> /* off_t */
31 #include <videolan/vlc.h>
33 #ifdef MODULE_NAME_IS_gnome
41 #include "stream_control.h"
42 #include "input_ext-intf.h"
44 #include "interface.h"
45 #include "intf_playlist.h"
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"
53 /****************************************************************************
54 * GtkPreferencesShow: display interface window after initialization
56 ****************************************************************************/
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 ) )
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 ) )
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 ) )
74 gboolean GtkPreferencesShow( GtkWidget *widget,
75 GdkEventButton *event,
78 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
80 /* If we have never used the file selector, open it */
81 if( !GTK_IS_WIDGET( p_intf->p_sys->p_preferences ) )
83 p_intf->p_sys->p_preferences = create_intf_preferences();
84 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_preferences ),
88 ASSIGN_PSZ_ENTRY( INTF_PATH_VAR, INTF_PATH_DEFAULT,
89 "preferences_file_path_entry" );
92 ASSIGN_PSZ_ENTRY( INPUT_DVD_DEVICE_VAR,DVD_DEVICE,
93 "preferences_disc_dvd_entry" );
96 ASSIGN_PSZ_ENTRY( INPUT_VCD_DEVICE_VAR, VCD_DEVICE,
97 "preferences_disc_vcd_entry" );
100 ASSIGN_PSZ_ENTRY( INPUT_SERVER_VAR, INPUT_SERVER_DEFAULT,
101 "preferences_network_server_entry" );
104 ASSIGN_INT_VALUE( INPUT_PORT_VAR, INPUT_PORT_DEFAULT,
105 "preferences_network_port_spinbutton" );
107 /* Broadcast address */
108 ASSIGN_PSZ_ENTRY( INPUT_BCAST_ADDR_VAR, INPUT_BCAST_ADDR_DEFAULT,
109 "preferences_network_broadcast_entry" );
111 /* Broadcast stream by default ? */
112 ASSIGN_INT_TOGGLE( INPUT_BROADCAST_VAR, INPUT_BROADCAST_DEFAULT,
113 "preferences_network_broadcast_checkbutton" );
117 /* Default interface */
118 ASSIGN_PSZ_ENTRY( INTF_METHOD_VAR, INTF_METHOD_DEFAULT,
119 "preferences_interface_entry" );
121 /* Default video output */
122 ASSIGN_PSZ_ENTRY( VOUT_METHOD_VAR, VOUT_METHOD_DEFAULT,
123 "preferences_video_output_entry" );
125 /* Default output width */
126 ASSIGN_INT_VALUE( VOUT_WIDTH_VAR, VOUT_WIDTH_DEFAULT,
127 "preferences_video_width_spinbutton" );
129 /* Default output height */
130 ASSIGN_INT_VALUE( VOUT_HEIGHT_VAR, VOUT_HEIGHT_DEFAULT,
131 "preferences_video_height_spinbutton" );
133 /* XXX Default screen depth */
135 /* XXX Default fullscreen depth */
137 /* XXX Default gamma */
139 /* Fullscreen on play */
140 ASSIGN_INT_TOGGLE( VOUT_FULLSCREEN_VAR, VOUT_FULLSCREEN_DEFAULT,
141 "preferences_video_fullscreen_checkbutton" );
143 /* Grayscale display */
144 ASSIGN_INT_TOGGLE( VOUT_GRAYSCALE_VAR, VOUT_GRAYSCALE_DEFAULT,
145 "preferences_video_grayscale_checkbutton" );
147 /* Default audio output */
148 ASSIGN_PSZ_ENTRY( AOUT_METHOD_VAR, AOUT_METHOD_DEFAULT,
149 "preferences_audio_output_entry" );
151 /* Default audio device */
152 ASSIGN_PSZ_ENTRY( AOUT_DSP_VAR, AOUT_DSP_DEFAULT,
153 "preferences_audio_device_entry" );
155 /* XXX Default frequency */
157 /* XXX Default quality */
159 /* XXX Default number of channels */
161 /* Use spdif output ? */
162 ASSIGN_INT_TOGGLE( AOUT_SPDIF_VAR, AOUT_SPDIF_DEFAULT,
163 "preferences_audio_spdif_checkbutton" );
165 /* Launch playlist on startup */
166 ASSIGN_INT_TOGGLE( PLAYLIST_STARTUP_VAR, PLAYLIST_STARTUP_DEFAULT,
167 "preferences_playlist_startup_checkbutton" );
169 /* Enqueue drag'n dropped item as default */
170 ASSIGN_INT_TOGGLE( PLAYLIST_ENQUEUE_VAR, PLAYLIST_ENQUEUE_DEFAULT,
171 "preferences_playlist_enqueue_checkbutton" );
173 /* Loop on playlist end */
174 ASSIGN_INT_TOGGLE( PLAYLIST_LOOP_VAR, PLAYLIST_LOOP_DEFAULT,
175 "preferences_playlist_loop_checkbutton" );
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
185 gtk_widget_show( p_intf->p_sys->p_preferences );
186 gdk_window_raise( p_intf->p_sys->p_preferences->window );
191 /****************************************************************************
192 * GtkPreferencesApply: store the values into the environnement variables
193 ****************************************************************************/
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 ) ) ) )
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 ), \
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 ), \
210 void GtkPreferencesApply( GtkButton * button, gpointer user_data )
212 GtkWidget * p_preferences;
214 /* get preferences window */
215 p_preferences = gtk_widget_get_toplevel( GTK_WIDGET( button ) );
218 ASSIGN_PSZ_ENTRY( INTF_PATH_VAR, "preferences_file_path_entry" );
221 ASSIGN_PSZ_ENTRY( INPUT_DVD_DEVICE_VAR, "preferences_disc_dvd_entry" );
224 ASSIGN_PSZ_ENTRY( INPUT_VCD_DEVICE_VAR, "preferences_disc_vcd_entry" );
227 ASSIGN_PSZ_ENTRY( INPUT_SERVER_VAR, "preferences_network_server_entry" );
230 ASSIGN_INT_VALUE( INPUT_PORT_VAR, "preferences_network_port_spinbutton" );
232 /* Broadcast address */
233 ASSIGN_PSZ_ENTRY( INPUT_BCAST_ADDR_VAR,
234 "preferences_network_broadcast_entry" );
236 /* Broadcast stream by default ? */
237 ASSIGN_INT_TOGGLE( INPUT_BROADCAST_VAR,
238 "preferences_network_broadcast_checkbutton" );
242 /* Default interface */
243 ASSIGN_PSZ_ENTRY( INTF_METHOD_VAR, "preferences_interface_entry" );
245 /* Default video output */
246 ASSIGN_PSZ_ENTRY( VOUT_METHOD_VAR, "preferences_video_output_entry" );
248 /* Default output width */
249 ASSIGN_INT_VALUE( VOUT_WIDTH_VAR, "preferences_video_width_spinbutton" );
251 /* Default output height */
252 ASSIGN_INT_VALUE( VOUT_HEIGHT_VAR, "preferences_video_height_spinbutton" );
254 /* XXX Default screen depth */
256 /* XXX Default fullscreen depth */
258 /* XXX Default gamma */
260 /* Fullscreen on play */
261 ASSIGN_INT_TOGGLE( VOUT_FULLSCREEN_VAR,
262 "preferences_video_fullscreen_checkbutton" );
264 /* Grayscale display */
265 ASSIGN_INT_TOGGLE( VOUT_GRAYSCALE_VAR,
266 "preferences_video_grayscale_checkbutton" );
268 /* Default audio output */
269 ASSIGN_PSZ_ENTRY( AOUT_METHOD_VAR, "preferences_audio_output_entry" );
271 /* Default audio device */
272 ASSIGN_PSZ_ENTRY( AOUT_DSP_VAR, "preferences_audio_device_entry" );
274 /* XXX Default frequency */
276 /* XXX Default quality */
278 /* XXX Default number of channels */
280 /* Use spdif output ? */
281 ASSIGN_INT_TOGGLE( AOUT_SPDIF_VAR, "preferences_audio_spdif_checkbutton" );
283 /* Launch playlist on startup */
284 ASSIGN_INT_TOGGLE( PLAYLIST_STARTUP_VAR,
285 "preferences_playlist_startup_checkbutton" );
287 /* Enqueue drag'n dropped item as default */
288 ASSIGN_INT_TOGGLE( PLAYLIST_ENQUEUE_VAR,
289 "preferences_playlist_enqueue_checkbutton" );
291 /* Loop on playlist end */
292 ASSIGN_INT_TOGGLE( PLAYLIST_LOOP_VAR,
293 "preferences_playlist_loop_checkbutton" );
295 /* Verbosity of warning messages */
296 ASSIGN_INT_VALUE( INTF_WARNING_VAR,
297 "preferences_misc_messages_spinbutton" );
299 #undef ASSIGN_PSZ_ENTRY
300 #undef ASSIGN_INT_VALUE
301 #undef ASSIGN_INT_TOGGLE
304 void GtkPreferencesOk( GtkButton * button, gpointer user_data )
306 GtkPreferencesApply( button, user_data );
307 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
311 void GtkPreferencesCancel( GtkButton * button, gpointer user_data )
313 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
316 /****************************************************************************
317 * Callbacks for menuitems
318 ****************************************************************************/
319 void GtkPreferencesActivate( GtkMenuItem * menuitem, gpointer user_data )
321 GtkPreferencesShow( GTK_WIDGET( menuitem ), NULL, user_data );