1 /*****************************************************************************
2 * gtk_open.c : functions to handle file/disc/network open widgets.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: gtk_open.c,v 1.2 2001/05/15 14:49:48 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 #define MODULE_NAME gtk
26 #include "modules_inner.h"
28 /*****************************************************************************
30 *****************************************************************************/
32 #include <sys/types.h> /* off_t */
44 #include "stream_control.h"
45 #include "input_ext-intf.h"
47 #include "interface.h"
48 #include "intf_playlist.h"
51 #include "gtk_callbacks.h"
52 #include "gtk_interface.h"
53 #include "gtk_support.h"
54 #include "gtk_playlist.h"
59 /*****************************************************************************
61 *****************************************************************************
62 * The following callbacks are related to the file requester.
63 *****************************************************************************/
64 gboolean GtkFileOpenShow( GtkWidget *widget,
65 GdkEventButton *event,
68 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
70 /* If we have never used the file selector, open it */
71 if( !GTK_IS_WIDGET( p_intf->p_sys->p_fileopen ) )
73 p_intf->p_sys->p_fileopen = create_intf_fileopen();
74 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
77 gtk_file_selection_set_filename( GTK_FILE_SELECTION(
78 p_intf->p_sys->p_fileopen ),
79 main_GetPszVariable( INTF_PATH_VAR, INTF_PATH_DEFAULT ) );
82 gtk_widget_show( p_intf->p_sys->p_fileopen );
83 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
89 void GtkFileOpenCancel( GtkButton * button, gpointer user_data )
91 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
94 void GtkFileOpenOk( GtkButton * button, gpointer user_data )
96 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_fileopen" );
97 GtkCList * p_playlist_clist;
98 GtkWidget * p_filesel;
100 int i_end = p_main->p_playlist->i_size;
102 /* hide the file selector */
103 p_filesel = gtk_widget_get_toplevel( GTK_WIDGET(button) );
104 gtk_widget_hide( p_filesel );
106 /* add the new file to the interface playlist */
108 gtk_file_selection_get_filename( GTK_FILE_SELECTION( p_filesel ) );
109 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, (char*)psz_filename );
111 /* catch the GTK CList */
112 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
113 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
114 /* update the plugin display */
115 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
117 /* end current item, select added item */
118 if( p_intf->p_input != NULL )
120 p_intf->p_input->b_eof = 1;
123 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
126 /*****************************************************************************
127 * Open disc callbacks
128 *****************************************************************************
129 * The following callbacks are related to the disc manager.
130 *****************************************************************************/
131 gboolean GtkDiscOpenShow( GtkWidget *widget,
132 GdkEventButton *event,
135 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
137 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
139 p_intf->p_sys->p_disc = create_intf_disc();
140 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
144 gtk_widget_show( p_intf->p_sys->p_disc );
145 gdk_window_raise( p_intf->p_sys->p_disc->window );
151 void GtkDiscOpenDvd( GtkToggleButton * togglebutton, gpointer user_data )
153 if( togglebutton->active )
156 GTK_ENTRY( lookup_widget( GTK_WIDGET(togglebutton), "disc_name" ) ),
157 main_GetPszVariable( INPUT_DVD_DEVICE_VAR, INPUT_DVD_DEVICE_DEFAULT )
162 void GtkDiscOpenVcd( GtkToggleButton * togglebutton, gpointer user_data )
164 if( togglebutton->active )
167 GTK_ENTRY( lookup_widget( GTK_WIDGET(togglebutton), "disc_name" ) ),
168 main_GetPszVariable( INPUT_VCD_DEVICE_VAR, INPUT_VCD_DEVICE_DEFAULT )
173 void GtkDiscOpenOk( GtkButton * button, gpointer user_data )
175 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
176 GtkCList * p_playlist_clist;
177 char * psz_device, *psz_source, *psz_method;
178 int i_end = p_main->p_playlist->i_size;
180 gtk_widget_hide( p_intf->p_sys->p_disc );
181 psz_device = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
182 GTK_WIDGET(button), "disc_name" ) ) );
184 /* "dvd:foo" has size 5 + strlen(foo) */
185 psz_source = malloc( 3 /* "dvd" */ + 1 /* ":" */
186 + strlen( psz_device ) + 1 /* "\0" */ );
187 if( psz_source == NULL )
192 /* Check which method was activated */
193 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
194 "disc_dvd" ) )->active )
198 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
199 "disc_vcd" ) )->active )
205 intf_ErrMsg( "intf error: unknown disc type toggle button position" );
210 /* Select title and chapter */
211 main_PutIntVariable( INPUT_TITLE_VAR, gtk_spin_button_get_value_as_int(
212 GTK_SPIN_BUTTON( lookup_widget(
213 GTK_WIDGET(button), "disc_title" ) ) ) );
215 main_PutIntVariable( INPUT_CHAPTER_VAR, gtk_spin_button_get_value_as_int(
216 GTK_SPIN_BUTTON( lookup_widget(
217 GTK_WIDGET(button), "disc_chapter" ) ) ) );
219 /* Build source name and add it to playlist */
220 sprintf( psz_source, "%s:%s", psz_method, psz_device );
221 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
224 /* catch the GTK CList */
225 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
226 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
228 /* update the display */
229 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
231 /* stop current item, select added item */
232 if( p_intf->p_input != NULL )
234 p_intf->p_input->b_eof = 1;
237 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
241 void GtkDiscOpenCancel( GtkButton * button, gpointer user_data )
243 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
247 /*****************************************************************************
248 * Network stream callbacks
249 *****************************************************************************
250 * The following callbacks are related to the network stream manager.
251 *****************************************************************************/
252 gboolean GtkNetworkOpenShow( GtkWidget *widget,
253 GdkEventButton *event,
256 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
258 if( !GTK_IS_WIDGET( p_intf->p_sys->p_network ) )
260 p_intf->p_sys->p_network = create_intf_network();
261 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_network ),
265 gtk_widget_show( p_intf->p_sys->p_network );
266 gdk_window_raise( p_intf->p_sys->p_network->window );
272 void GtkNetworkOpenOk( GtkButton *button, gpointer user_data )
274 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_network" );
275 GtkCList * p_playlist_clist;
276 char * psz_source, *psz_server, *psz_protocol;
278 boolean_t b_broadcast;
279 int i_end = p_main->p_playlist->i_size;
281 gtk_widget_hide( p_intf->p_sys->p_network );
282 psz_server = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
283 GTK_WIDGET(button), "network_server" ) ) );
285 /* Check which protocol was activated */
286 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
287 "network_ts" ) )->active )
291 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
292 "network_rtp" ) )->active )
294 psz_protocol = "rtp";
298 intf_ErrMsg( "intf error: unknown protocol toggle button position" );
302 /* Get the port number and make sure it will not overflow 5 characters */
303 i_port = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(
304 lookup_widget( GTK_WIDGET(button), "network_port" ) ) );
307 intf_ErrMsg( "intf error: invalid port %i", i_port );
310 /* do we have a broadcast address */
311 b_broadcast = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(
312 lookup_widget( GTK_WIDGET(button), "broadcast_check" ) ) );
315 char * psz_broadcast;
316 psz_broadcast = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
317 GTK_WIDGET(button), "network_broadcast" ) ) );
318 /* Allocate room for "protocol://server:port" */
319 psz_source = malloc( strlen( psz_protocol ) + 3 /* "://" */
320 + strlen( psz_server ) + 1 /* ":" */
322 + strlen( psz_broadcast ) + 2 /* "::" */
324 if( psz_source == NULL )
329 /* Build source name and add it to playlist */
330 sprintf( psz_source, "%s://%s:%i::%s", psz_protocol,
337 /* Allocate room for "protocol://server:port" */
338 psz_source = malloc( strlen( psz_protocol ) + 3 /* "://" */
339 + strlen( psz_server ) + 1 /* ":" */
340 + 5 /* 0-65535 */ + 1 /* "\0" */ );
341 if( psz_source == NULL )
346 /* Build source name and add it to playlist */
347 sprintf( psz_source, "%s://%s:%i", psz_protocol, psz_server, i_port );
350 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
353 /* catch the GTK CList */
354 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
355 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
356 /* update the display */
357 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
359 /* select added item */
360 if( p_intf->p_input != NULL )
362 p_intf->p_input->b_eof = 1;
365 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
368 void GtkNetworkOpenCancel( GtkButton * button, gpointer user_data)
370 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
374 void GtkNetworkOpenBroadcast( GtkToggleButton * togglebutton,
377 GtkWidget * p_network;
379 p_network = gtk_widget_get_toplevel( GTK_WIDGET (togglebutton) );
381 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
382 "network_broadcast_combo" ),
383 gtk_toggle_button_get_active( togglebutton ) );
385 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
386 "network_broadcast" ),
387 gtk_toggle_button_get_active( togglebutton ) );
392 /****************************************************************************
393 * Callbacks for menuitem
394 ****************************************************************************/
395 void GtkFileOpenActivate( GtkMenuItem * menuitem, gpointer user_data )
397 GtkFileOpenShow( GTK_WIDGET( menuitem ), NULL, user_data );
401 void GtkDiscOpenActivate( GtkMenuItem * menuitem, gpointer user_data )
403 GtkDiscOpenShow( GTK_WIDGET( menuitem ), NULL, user_data );
407 void GtkNetworkOpenActivate( GtkMenuItem * menuitem, gpointer user_data )
409 GtkNetworkOpenShow( GTK_WIDGET( menuitem ), NULL, user_data );