]> git.sesse.net Git - vlc/blob - plugins/gtk/gtk_open.c
* Fixed the BeOS compile typo.
[vlc] / plugins / gtk / gtk_open.c
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 $
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  * Fileopen callbacks
60  *****************************************************************************
61  * The following callbacks are related to the file requester.
62  *****************************************************************************/
63 gboolean GtkFileOpenShow( GtkWidget       *widget,
64                           GdkEventButton  *event,
65                           gpointer         user_data )
66 {
67     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
68
69     /* If we have never used the file selector, open it */
70     if( !GTK_IS_WIDGET( p_intf->p_sys->p_fileopen ) )
71     {
72         p_intf->p_sys->p_fileopen = create_intf_fileopen();
73         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
74                              "p_intf", p_intf );
75
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 ) );
79     }
80
81     gtk_widget_show( p_intf->p_sys->p_fileopen );
82     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
83
84     return TRUE;
85 }
86
87
88 void GtkFileOpenCancel( GtkButton * button, gpointer user_data )
89 {
90     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
91 }
92
93 void GtkFileOpenOk( GtkButton * button, gpointer user_data )
94 {
95     intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_fileopen" );
96     GtkCList *      p_playlist_clist;
97     GtkWidget *     p_filesel;
98     gchar *         psz_filename;
99     int             i_end = p_main->p_playlist->i_size;
100
101     /* hide the file selector */
102     p_filesel = gtk_widget_get_toplevel( GTK_WIDGET(button) );
103     gtk_widget_hide( p_filesel );
104
105     /* add the new file to the interface playlist */
106     psz_filename =
107         gtk_file_selection_get_filename( GTK_FILE_SELECTION( p_filesel ) );
108     intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, (char*)psz_filename );
109
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 );
115
116     /* end current item, select added item  */
117     if( p_intf->p_input != NULL )
118     {
119         p_intf->p_input->b_eof = 1;
120     }
121
122     intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
123 }
124
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,
132                           gpointer         user_data)
133 {
134     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
135
136     if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
137     {
138         p_intf->p_sys->p_disc = create_intf_disc();
139         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
140                              "p_intf", p_intf );
141     }
142
143     gtk_widget_show( p_intf->p_sys->p_disc );
144     gdk_window_raise( p_intf->p_sys->p_disc->window );
145
146     return TRUE;
147 }
148
149
150 void GtkDiscOpenDvd( GtkToggleButton * togglebutton, gpointer user_data )
151 {
152     if( togglebutton->active )
153     {
154         gtk_entry_set_text(
155           GTK_ENTRY( lookup_widget( GTK_WIDGET(togglebutton), "disc_name" ) ),
156           main_GetPszVariable( INPUT_DVD_DEVICE_VAR, INPUT_DVD_DEVICE_DEFAULT )
157         );
158     }
159 }
160
161 void GtkDiscOpenVcd( GtkToggleButton * togglebutton, gpointer user_data )
162 {
163     if( togglebutton->active )
164     {
165         gtk_entry_set_text(
166           GTK_ENTRY( lookup_widget( GTK_WIDGET(togglebutton), "disc_name" ) ),
167           main_GetPszVariable( INPUT_VCD_DEVICE_VAR, INPUT_VCD_DEVICE_DEFAULT )
168         );
169     }
170 }
171
172 void GtkDiscOpenOk( GtkButton * button, gpointer user_data )
173 {
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;
178
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" ) ) );
182
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 )
187     {
188         return;
189     }
190
191     /* Check which method was activated */
192     if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
193                                           "disc_dvd" ) )->active )
194     {
195         psz_method = "dvd";
196     }
197     else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
198                                                "disc_vcd" ) )->active )
199     {
200         psz_method = "vcd";
201     }
202     else
203     {
204         intf_ErrMsg( "intf error: unknown disc type toggle button position" );
205         free( psz_source );
206         return;
207     }
208     
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" ) ) ) );
213
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" ) ) ) );
217
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 );
221     free( psz_source );
222
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" ) );
226
227     /* update the display */
228     GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
229
230     /* stop current item, select added item */
231     if( p_intf->p_input != NULL )
232     {
233         p_intf->p_input->b_eof = 1;
234     }
235
236     intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
237 }
238
239
240 void GtkDiscOpenCancel( GtkButton * button, gpointer user_data )
241 {
242     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
243 }
244
245
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,
253                              gpointer         user_data )
254 {
255     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
256
257     if( !GTK_IS_WIDGET( p_intf->p_sys->p_network ) )
258     {
259         p_intf->p_sys->p_network = create_intf_network();
260         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_network ),
261                              "p_intf", p_intf );
262     }
263
264     gtk_widget_show( p_intf->p_sys->p_network );
265     gdk_window_raise( p_intf->p_sys->p_network->window );
266
267     return TRUE;
268 }
269
270
271 void GtkNetworkOpenOk( GtkButton *button, gpointer user_data )
272 {
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;
276     unsigned int    i_port;
277     boolean_t       b_broadcast;
278     int             i_end = p_main->p_playlist->i_size;
279
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" ) ) );
283
284     /* Check which protocol was activated */
285     if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
286                                           "network_ts" ) )->active )
287     {
288         psz_protocol = "ts";
289     }
290     else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
291                                                "network_rtp" ) )->active )
292     {
293         psz_protocol = "rtp";
294     }
295     else
296     {
297         intf_ErrMsg( "intf error: unknown protocol toggle button position" );
298         return;
299     }
300
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" ) ) );
304     if( i_port > 65535 )
305     {
306         intf_ErrMsg( "intf error: invalid port %i", i_port );
307     }
308
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" ) ) );
312     if( b_broadcast )
313     {
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 /* ":" */
320                                + 5 /* 0-65535 */
321                                + strlen( psz_broadcast ) + 2 /* "::" */ 
322                                + 1 /* "\0" */ );
323         if( psz_source == NULL )
324         {
325             return;
326         }
327
328         /* Build source name and add it to playlist */
329         sprintf( psz_source, "%s://%s:%i::%s", psz_protocol,
330                                                psz_server,
331                                                i_port,
332                                                psz_broadcast );
333     }
334     else
335     {
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 )
341         {
342             return;
343         }
344        
345         /* Build source name and add it to playlist */
346         sprintf( psz_source, "%s://%s:%i", psz_protocol, psz_server, i_port );
347     }
348
349     intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
350     free( psz_source );
351
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 );
357
358     /* select added item */
359     if( p_intf->p_input != NULL )
360     {
361         p_intf->p_input->b_eof = 1;
362     }
363
364     intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
365 }
366
367 void GtkNetworkOpenCancel( GtkButton * button, gpointer user_data)
368 {
369     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
370 }
371
372
373 void GtkNetworkOpenBroadcast( GtkToggleButton * togglebutton,
374                               gpointer user_data )
375 {
376     GtkWidget *     p_network;
377
378     p_network = gtk_widget_get_toplevel( GTK_WIDGET (togglebutton) );
379
380     gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
381             "network_broadcast_combo" ),
382             gtk_toggle_button_get_active( togglebutton ) );
383
384     gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
385             "network_broadcast" ),
386             gtk_toggle_button_get_active( togglebutton ) );
387 }
388
389
390
391 /****************************************************************************
392  * Callbacks for menuitem
393  ****************************************************************************/
394 void GtkFileOpenActivate( GtkMenuItem * menuitem, gpointer user_data )
395 {
396     GtkFileOpenShow( GTK_WIDGET( menuitem ), NULL, user_data );
397 }
398
399
400 void GtkDiscOpenActivate( GtkMenuItem * menuitem, gpointer user_data )
401 {
402     GtkDiscOpenShow( GTK_WIDGET( menuitem ), NULL, user_data );
403 }
404
405
406 void GtkNetworkOpenActivate( GtkMenuItem * menuitem, gpointer user_data )
407 {
408     GtkNetworkOpenShow( GTK_WIDGET( menuitem ), NULL, user_data );
409 }
410