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.4 2001/05/30 17:03:12 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 *****************************************************************************/
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 #include "modules_export.h"
58 /*****************************************************************************
60 *****************************************************************************
61 * The following callbacks are related to the file requester.
62 *****************************************************************************/
63 gboolean GtkFileOpenShow( GtkWidget *widget,
64 GdkEventButton *event,
67 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
69 /* If we have never used the file selector, open it */
70 if( !GTK_IS_WIDGET( p_intf->p_sys->p_fileopen ) )
72 p_intf->p_sys->p_fileopen = create_intf_fileopen();
73 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
76 gtk_file_selection_set_filename( GTK_FILE_SELECTION(
77 p_intf->p_sys->p_fileopen ),
78 main_GetPszVariable( INTF_PATH_VAR, INTF_PATH_DEFAULT ) );
81 gtk_widget_show( p_intf->p_sys->p_fileopen );
82 gdk_window_raise( p_intf->p_sys->p_fileopen->window );
88 void GtkFileOpenCancel( GtkButton * button, gpointer user_data )
90 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
93 void GtkFileOpenOk( GtkButton * button, gpointer user_data )
95 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_fileopen" );
96 GtkCList * p_playlist_clist;
97 GtkWidget * p_filesel;
99 int i_end = p_main->p_playlist->i_size;
101 /* hide the file selector */
102 p_filesel = gtk_widget_get_toplevel( GTK_WIDGET(button) );
103 gtk_widget_hide( p_filesel );
105 /* add the new file to the interface playlist */
107 gtk_file_selection_get_filename( GTK_FILE_SELECTION( p_filesel ) );
108 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, (char*)psz_filename );
110 /* catch the GTK CList */
111 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
112 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
113 /* update the plugin display */
114 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
116 /* end current item, select added item */
117 if( p_intf->p_input != NULL )
119 p_intf->p_input->b_eof = 1;
122 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
125 /*****************************************************************************
126 * Open disc callbacks
127 *****************************************************************************
128 * The following callbacks are related to the disc manager.
129 *****************************************************************************/
130 gboolean GtkDiscOpenShow( GtkWidget *widget,
131 GdkEventButton *event,
134 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
136 if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
138 p_intf->p_sys->p_disc = create_intf_disc();
139 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
143 gtk_widget_show( p_intf->p_sys->p_disc );
144 gdk_window_raise( p_intf->p_sys->p_disc->window );
150 void GtkDiscOpenDvd( GtkToggleButton * togglebutton, gpointer user_data )
152 if( togglebutton->active )
155 GTK_ENTRY( lookup_widget( GTK_WIDGET(togglebutton), "disc_name" ) ),
156 main_GetPszVariable( INPUT_DVD_DEVICE_VAR, INPUT_DVD_DEVICE_DEFAULT )
161 void GtkDiscOpenVcd( GtkToggleButton * togglebutton, gpointer user_data )
163 if( togglebutton->active )
166 GTK_ENTRY( lookup_widget( GTK_WIDGET(togglebutton), "disc_name" ) ),
167 main_GetPszVariable( INPUT_VCD_DEVICE_VAR, INPUT_VCD_DEVICE_DEFAULT )
172 void GtkDiscOpenOk( GtkButton * button, gpointer user_data )
174 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
175 GtkCList * p_playlist_clist;
176 char * psz_device, *psz_source, *psz_method;
177 int i_end = p_main->p_playlist->i_size;
179 gtk_widget_hide( p_intf->p_sys->p_disc );
180 psz_device = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
181 GTK_WIDGET(button), "disc_name" ) ) );
183 /* "dvd:foo" has size 5 + strlen(foo) */
184 psz_source = malloc( 3 /* "dvd" */ + 1 /* ":" */
185 + strlen( psz_device ) + 1 /* "\0" */ );
186 if( psz_source == NULL )
191 /* Check which method was activated */
192 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
193 "disc_dvd" ) )->active )
197 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
198 "disc_vcd" ) )->active )
204 intf_ErrMsg( "intf error: unknown disc type toggle button position" );
209 /* Select title and chapter */
210 main_PutIntVariable( INPUT_TITLE_VAR, gtk_spin_button_get_value_as_int(
211 GTK_SPIN_BUTTON( lookup_widget(
212 GTK_WIDGET(button), "disc_title" ) ) ) );
214 main_PutIntVariable( INPUT_CHAPTER_VAR, gtk_spin_button_get_value_as_int(
215 GTK_SPIN_BUTTON( lookup_widget(
216 GTK_WIDGET(button), "disc_chapter" ) ) ) );
218 /* Build source name and add it to playlist */
219 sprintf( psz_source, "%s:%s", psz_method, psz_device );
220 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
223 /* catch the GTK CList */
224 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
225 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
227 /* update the display */
228 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
230 /* stop current item, select added item */
231 if( p_intf->p_input != NULL )
233 p_intf->p_input->b_eof = 1;
236 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
240 void GtkDiscOpenCancel( GtkButton * button, gpointer user_data )
242 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
246 /*****************************************************************************
247 * Network stream callbacks
248 *****************************************************************************
249 * The following callbacks are related to the network stream manager.
250 *****************************************************************************/
251 gboolean GtkNetworkOpenShow( GtkWidget *widget,
252 GdkEventButton *event,
255 intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
257 if( !GTK_IS_WIDGET( p_intf->p_sys->p_network ) )
259 p_intf->p_sys->p_network = create_intf_network();
260 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_network ),
264 gtk_widget_show( p_intf->p_sys->p_network );
265 gdk_window_raise( p_intf->p_sys->p_network->window );
271 void GtkNetworkOpenOk( GtkButton *button, gpointer user_data )
273 intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_network" );
274 GtkCList * p_playlist_clist;
275 char * psz_source, *psz_server, *psz_protocol;
277 boolean_t b_broadcast;
278 int i_end = p_main->p_playlist->i_size;
280 gtk_widget_hide( p_intf->p_sys->p_network );
281 psz_server = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
282 GTK_WIDGET(button), "network_server" ) ) );
284 /* Check which protocol was activated */
285 if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
286 "network_ts" ) )->active )
290 else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
291 "network_rtp" ) )->active )
293 psz_protocol = "rtp";
297 intf_ErrMsg( "intf error: unknown protocol toggle button position" );
301 /* Get the port number and make sure it will not overflow 5 characters */
302 i_port = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(
303 lookup_widget( GTK_WIDGET(button), "network_port" ) ) );
306 intf_ErrMsg( "intf error: invalid port %i", i_port );
309 /* do we have a broadcast address */
310 b_broadcast = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(
311 lookup_widget( GTK_WIDGET(button), "broadcast_check" ) ) );
314 char * psz_broadcast;
315 psz_broadcast = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
316 GTK_WIDGET(button), "network_broadcast" ) ) );
317 /* Allocate room for "protocol://server:port" */
318 psz_source = malloc( strlen( psz_protocol ) + 3 /* "://" */
319 + strlen( psz_server ) + 1 /* ":" */
321 + strlen( psz_broadcast ) + 2 /* "::" */
323 if( psz_source == NULL )
328 /* Build source name and add it to playlist */
329 sprintf( psz_source, "%s://%s:%i::%s", psz_protocol,
336 /* Allocate room for "protocol://server:port" */
337 psz_source = malloc( strlen( psz_protocol ) + 3 /* "://" */
338 + strlen( psz_server ) + 1 /* ":" */
339 + 5 /* 0-65535 */ + 1 /* "\0" */ );
340 if( psz_source == NULL )
345 /* Build source name and add it to playlist */
346 sprintf( psz_source, "%s://%s:%i", psz_protocol, psz_server, i_port );
349 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
352 /* catch the GTK CList */
353 p_playlist_clist = GTK_CLIST( gtk_object_get_data(
354 GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
355 /* update the display */
356 GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
358 /* select added item */
359 if( p_intf->p_input != NULL )
361 p_intf->p_input->b_eof = 1;
364 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
367 void GtkNetworkOpenCancel( GtkButton * button, gpointer user_data)
369 gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
373 void GtkNetworkOpenBroadcast( GtkToggleButton * togglebutton,
376 GtkWidget * p_network;
378 p_network = gtk_widget_get_toplevel( GTK_WIDGET (togglebutton) );
380 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
381 "network_broadcast_combo" ),
382 gtk_toggle_button_get_active( togglebutton ) );
384 gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
385 "network_broadcast" ),
386 gtk_toggle_button_get_active( togglebutton ) );
391 /****************************************************************************
392 * Callbacks for menuitem
393 ****************************************************************************/
394 void GtkFileOpenActivate( GtkMenuItem * menuitem, gpointer user_data )
396 GtkFileOpenShow( GTK_WIDGET( menuitem ), NULL, user_data );
400 void GtkDiscOpenActivate( GtkMenuItem * menuitem, gpointer user_data )
402 GtkDiscOpenShow( GTK_WIDGET( menuitem ), NULL, user_data );
406 void GtkNetworkOpenActivate( GtkMenuItem * menuitem, gpointer user_data )
408 GtkNetworkOpenShow( GTK_WIDGET( menuitem ), NULL, user_data );