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 $
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 *****************************************************************************/
29 #include <sys/types.h> /* off_t */
41 #include "stream_control.h"
42 #include "input_ext-intf.h"
44 #include "interface.h"
45 #include "intf_playlist.h"
48 #include "gtk_callbacks.h"
49 #include "gtk_interface.h"
50 #include "gtk_support.h"
51 #include "gtk_playlist.h"
56 /****************************************************************************
57 * GtkPreferencesShow: display interface window after initialization
59 ****************************************************************************/
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 ) )
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 ) )
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 ) )
77 gboolean GtkPreferencesShow( GtkWidget *widget,
78 GdkEventButton *event,
81 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
83 /* If we have never used the file selector, open it */
84 if( !GTK_IS_WIDGET( p_intf->p_sys->p_preferences ) )
86 p_intf->p_sys->p_preferences = create_intf_preferences();
87 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_preferences ),
91 ASSIGN_PSZ_ENTRY( INTF_PATH_VAR, INTF_PATH_DEFAULT,
92 "preferences_file_path_entry" );
95 ASSIGN_PSZ_ENTRY( INPUT_DVD_DEVICE_VAR,INPUT_DVD_DEVICE_DEFAULT,
96 "preferences_disc_dvd_entry" );
99 ASSIGN_PSZ_ENTRY( INPUT_VCD_DEVICE_VAR, INPUT_VCD_DEVICE_DEFAULT,
100 "preferences_disc_vcd_entry" );
103 ASSIGN_PSZ_ENTRY( INPUT_SERVER_VAR, INPUT_SERVER_DEFAULT,
104 "preferences_network_server_entry" );
107 ASSIGN_INT_VALUE( INPUT_PORT_VAR, INPUT_PORT_DEFAULT,
108 "preferences_network_port_spinbutton" );
110 /* Broadcast address */
111 ASSIGN_PSZ_ENTRY( INPUT_BCAST_ADDR_VAR, INPUT_BCAST_ADDR_DEFAULT,
112 "preferences_network_broadcast_entry" );
114 /* Broadcast stream by default ? */
115 ASSIGN_INT_TOGGLE( INPUT_BROADCAST_VAR, INPUT_BROADCAST_DEFAULT,
116 "preferences_network_broadcast_checkbutton" );
120 /* Default interface */
121 ASSIGN_PSZ_ENTRY( INTF_METHOD_VAR, INTF_METHOD_DEFAULT,
122 "preferences_interface_entry" );
124 /* Default video output */
125 ASSIGN_PSZ_ENTRY( VOUT_METHOD_VAR, VOUT_METHOD_DEFAULT,
126 "preferences_video_output_entry" );
128 /* Default output width */
129 ASSIGN_INT_VALUE( VOUT_WIDTH_VAR, VOUT_WIDTH_DEFAULT,
130 "preferences_video_width_spinbutton" );
132 /* Default output height */
133 ASSIGN_INT_VALUE( VOUT_HEIGHT_VAR, VOUT_HEIGHT_DEFAULT,
134 "preferences_video_height_spinbutton" );
136 /* XXX Default screen depth */
138 /* XXX Default fullscreen depth */
140 /* XXX Default gamma */
142 /* Fullscreen on play */
143 ASSIGN_INT_TOGGLE( VOUT_FULLSCREEN_VAR, VOUT_FULLSCREEN_DEFAULT,
144 "preferences_video_fullscreen_checkbutton" );
146 /* Grayscale display */
147 ASSIGN_INT_TOGGLE( VOUT_GRAYSCALE_VAR, VOUT_GRAYSCALE_DEFAULT,
148 "preferences_video_grayscale_checkbutton" );
150 /* Default audio output */
151 ASSIGN_PSZ_ENTRY( AOUT_METHOD_VAR, AOUT_METHOD_DEFAULT,
152 "preferences_audio_output_entry" );
154 /* Default audio device */
155 ASSIGN_PSZ_ENTRY( AOUT_DSP_VAR, AOUT_DSP_DEFAULT,
156 "preferences_audio_device_entry" );
158 /* XXX Default frequency */
160 /* XXX Default quality */
162 /* XXX Default number of channels */
164 /* Use spdif output ? */
165 ASSIGN_INT_TOGGLE( AOUT_SPDIF_VAR, AOUT_SPDIF_DEFAULT,
166 "preferences_audio_spdif_checkbutton" );
168 /* Launch playlist on startup */
169 ASSIGN_INT_TOGGLE( PLAYLIST_STARTUP_VAR, PLAYLIST_STARTUP_DEFAULT,
170 "preferences_playlist_startup_checkbutton" );
172 /* Enqueue drag'n dropped item as default */
173 ASSIGN_INT_TOGGLE( PLAYLIST_ENQUEUE_VAR, PLAYLIST_ENQUEUE_DEFAULT,
174 "preferences_playlist_enqueue_checkbutton" );
176 /* Loop on playlist end */
177 ASSIGN_INT_TOGGLE( PLAYLIST_LOOP_VAR, PLAYLIST_LOOP_DEFAULT,
178 "preferences_playlist_loop_checkbutton" );
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
188 gtk_widget_show( p_intf->p_sys->p_preferences );
189 gdk_window_raise( p_intf->p_sys->p_preferences->window );
194 /****************************************************************************
195 * GtkPreferencesApply: store the values into the environnement variables
196 ****************************************************************************/
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 ) ) ) )
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 ), \
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 ), \
213 void GtkPreferencesApply( GtkButton * button, gpointer user_data )
215 GtkWidget * p_preferences;
217 /* get preferences window */
218 p_preferences = gtk_widget_get_toplevel( GTK_WIDGET( button ) );
221 ASSIGN_PSZ_ENTRY( INTF_PATH_VAR, "preferences_file_path_entry" );
224 ASSIGN_PSZ_ENTRY( INPUT_DVD_DEVICE_VAR, "preferences_disc_dvd_entry" );
227 ASSIGN_PSZ_ENTRY( INPUT_VCD_DEVICE_VAR, "preferences_disc_vcd_entry" );
230 ASSIGN_PSZ_ENTRY( INPUT_SERVER_VAR, "preferences_network_server_entry" );
233 ASSIGN_INT_VALUE( INPUT_PORT_VAR, "preferences_network_port_spinbutton" );
235 /* Broadcast address */
236 ASSIGN_PSZ_ENTRY( INPUT_BCAST_ADDR_VAR,
237 "preferences_network_broadcast_entry" );
239 /* Broadcast stream by default ? */
240 ASSIGN_INT_TOGGLE( INPUT_BROADCAST_VAR,
241 "preferences_network_broadcast_checkbutton" );
245 /* Default interface */
246 ASSIGN_PSZ_ENTRY( INTF_METHOD_VAR, "preferences_interface_entry" );
248 /* Default video output */
249 ASSIGN_PSZ_ENTRY( VOUT_METHOD_VAR, "preferences_video_output_entry" );
251 /* Default output width */
252 ASSIGN_INT_VALUE( VOUT_WIDTH_VAR, "preferences_video_width_spinbutton" );
254 /* Default output height */
255 ASSIGN_INT_VALUE( VOUT_HEIGHT_VAR, "preferences_video_height_spinbutton" );
257 /* XXX Default screen depth */
259 /* XXX Default fullscreen depth */
261 /* XXX Default gamma */
263 /* Fullscreen on play */
264 ASSIGN_INT_TOGGLE( VOUT_FULLSCREEN_VAR,
265 "preferences_video_fullscreen_checkbutton" );
267 /* Grayscale display */
268 ASSIGN_INT_TOGGLE( VOUT_GRAYSCALE_VAR,
269 "preferences_video_grayscale_checkbutton" );
271 /* Default audio output */
272 ASSIGN_PSZ_ENTRY( AOUT_METHOD_VAR, "preferences_audio_output_entry" );
274 /* Default audio device */
275 ASSIGN_PSZ_ENTRY( AOUT_DSP_VAR, "preferences_audio_device_entry" );
277 /* XXX Default frequency */
279 /* XXX Default quality */
281 /* XXX Default number of channels */
283 /* Use spdif output ? */
284 ASSIGN_INT_TOGGLE( AOUT_SPDIF_VAR, "preferences_audio_spdif_checkbutton" );
286 /* Launch playlist on startup */
287 ASSIGN_INT_TOGGLE( PLAYLIST_STARTUP_VAR,
288 "preferences_playlist_startup_checkbutton" );
290 /* Enqueue drag'n dropped item as default */
291 ASSIGN_INT_TOGGLE( PLAYLIST_ENQUEUE_VAR,
292 "preferences_playlist_enqueue_checkbutton" );
294 /* Loop on playlist end */
295 ASSIGN_INT_TOGGLE( PLAYLIST_LOOP_VAR,
296 "preferences_playlist_loop_checkbutton" );
298 /* Verbosity of warning messages */
299 ASSIGN_INT_VALUE( INTF_WARNING_VAR,
300 "preferences_misc_messages_spinbutton" );
302 #undef ASSIGN_PSZ_ENTRY
303 #undef ASSIGN_INT_VALUE
304 #undef ASSIGN_INT_TOGGLE
307 void GtkPreferencesOk( GtkButton * button, gpointer user_data )
309 GtkPreferencesApply( button, user_data );
310 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
314 void GtkPreferencesCancel( GtkButton * button, gpointer user_data )
316 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
319 /****************************************************************************
320 * Callbacks for menuitems
321 ****************************************************************************/
322 void GtkPreferencesActivate( GtkMenuItem * menuitem, gpointer user_data )
324 GtkPreferencesShow( GTK_WIDGET( menuitem ), NULL, user_data );