]> git.sesse.net Git - vlc/blob - plugins/gtk/gtk_open.c
*initialization bugfixes in input_dvd
[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.1 2001/05/15 01:01:44 stef 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 #define MODULE_NAME gtk
26 #include "modules_inner.h"
27
28 /*****************************************************************************
29  * Preamble
30  *****************************************************************************/
31 #include "defs.h"
32 #include <sys/types.h>                                              /* off_t */
33 #include <stdlib.h>
34
35 #include <gtk/gtk.h>
36
37 #include <string.h>
38
39 #include "config.h"
40 #include "common.h"
41 #include "threads.h"
42 #include "mtime.h"
43
44 #include "stream_control.h"
45 #include "input_ext-intf.h"
46
47 #include "interface.h"
48 #include "intf_playlist.h"
49 #include "intf_msg.h"
50
51 #include "gtk_callbacks.h"
52 #include "gtk_interface.h"
53 #include "gtk_support.h"
54 #include "gtk_playlist.h"
55 #include "intf_gtk.h"
56
57 #include "main.h"
58
59 /*****************************************************************************
60  * Fileopen callbacks
61  *****************************************************************************
62  * The following callbacks are related to the file requester.
63  *****************************************************************************/
64 #if 0
65 void GtkFileOpenShow( GtkMenuItem * menuitem, gpointer user_data)
66 {
67     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), (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 #else
85
86 gboolean
87 GtkFileOpenShow                        (GtkWidget       *widget,
88                                         GdkEventButton  *event,
89                                         gpointer         user_data)
90 {
91     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
92
93     /* If we have never used the file selector, open it */
94     if( !GTK_IS_WIDGET( p_intf->p_sys->p_fileopen ) )
95     {
96         p_intf->p_sys->p_fileopen = create_intf_fileopen();
97         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_fileopen ),
98                              "p_intf", p_intf );
99
100         gtk_file_selection_set_filename( GTK_FILE_SELECTION(
101             p_intf->p_sys->p_fileopen ),
102             main_GetPszVariable( INTF_PATH_VAR, INTF_PATH_DEFAULT ) );
103     }
104
105     gtk_widget_show( p_intf->p_sys->p_fileopen );
106     gdk_window_raise( p_intf->p_sys->p_fileopen->window );
107
108     return FALSE;
109 }
110
111
112 #endif
113 void GtkFileOpenCancel( GtkButton * button, gpointer user_data)
114 {
115     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
116 }
117
118 void GtkFileOpenOk( GtkButton * button, gpointer user_data )
119 {
120     intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_fileopen" );
121     GtkCList *      p_playlist_clist;
122     GtkWidget *     p_filesel;
123     gchar *         psz_filename;
124     int             i_end = p_main->p_playlist->i_size;
125
126     /* hide the file selector */
127     p_filesel = gtk_widget_get_toplevel( GTK_WIDGET(button) );
128     gtk_widget_hide( p_filesel );
129
130     /* add the new file to the interface playlist */
131     psz_filename =
132         gtk_file_selection_get_filename( GTK_FILE_SELECTION( p_filesel ) );
133     intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, (char*)psz_filename );
134
135     /* catch the GTK CList */
136     p_playlist_clist = GTK_CLIST( gtk_object_get_data(
137         GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
138     /* update the plugin display */
139     GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
140
141     /* end current item, select added item  */
142     if( p_intf->p_input != NULL )
143     {
144         p_intf->p_input->b_eof = 1;
145     }
146
147     intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
148     p_main->p_playlist->b_stopped = 0;
149 }
150
151 /*****************************************************************************
152  * Open disc callbacks
153  *****************************************************************************
154  * The following callbacks are related to the disc manager.
155  *****************************************************************************/
156 #if 0
157 void GtkDiscOpenShow( GtkMenuItem * menuitem, gpointer user_data)
158 {
159     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), (char*)user_data );
160
161     if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
162     {
163         p_intf->p_sys->p_disc = create_intf_disc();
164         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
165                              "p_intf", p_intf );
166     }
167
168     gtk_widget_show( p_intf->p_sys->p_disc );
169     gdk_window_raise( p_intf->p_sys->p_disc->window );
170 }
171 #else
172 gboolean
173 GtkDiscOpenShow                        (GtkWidget       *widget,
174                                         GdkEventButton  *event,
175                                         gpointer         user_data)
176 {
177     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
178
179     if( !GTK_IS_WIDGET( p_intf->p_sys->p_disc ) )
180     {
181         p_intf->p_sys->p_disc = create_intf_disc();
182         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_disc ),
183                              "p_intf", p_intf );
184     }
185
186     gtk_widget_show( p_intf->p_sys->p_disc );
187     gdk_window_raise( p_intf->p_sys->p_disc->window );
188
189     return FALSE;
190 }
191
192 #endif
193 void GtkDiscOpenDvd( GtkToggleButton * togglebutton, gpointer user_data )
194 {
195     if( togglebutton->active )
196     {
197         gtk_entry_set_text(
198           GTK_ENTRY( lookup_widget( GTK_WIDGET(togglebutton), "disc_name" ) ),
199           main_GetPszVariable( INPUT_DVD_DEVICE_VAR, INPUT_DVD_DEVICE_DEFAULT )
200         );
201     }
202 }
203
204 void GtkDiscOpenVcd( GtkToggleButton *togglebutton, gpointer user_data )
205 {
206     if( togglebutton->active )
207     {
208         gtk_entry_set_text(
209           GTK_ENTRY( lookup_widget( GTK_WIDGET(togglebutton), "disc_name" ) ),
210           main_GetPszVariable( INPUT_VCD_DEVICE_VAR, INPUT_VCD_DEVICE_DEFAULT )
211         );
212     }
213 }
214
215 void GtkDiscOpenOk( GtkButton * button, gpointer user_data )
216 {
217     intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_disc" );
218     GtkCList *      p_playlist_clist;
219     char *          psz_device, *psz_source, *psz_method;
220     int             i_end = p_main->p_playlist->i_size;
221
222     gtk_widget_hide( p_intf->p_sys->p_disc );
223     psz_device = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
224                                          GTK_WIDGET(button), "disc_name" ) ) );
225
226     /* "dvd:foo" has size 5 + strlen(foo) */
227     psz_source = malloc( 3 /* "dvd" */ + 1 /* ":" */
228                            + strlen( psz_device ) + 1 /* "\0" */ );
229     if( psz_source == NULL )
230     {
231         return;
232     }
233
234     /* Check which method was activated */
235     if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
236                                           "disc_dvd" ) )->active )
237     {
238         psz_method = "dvd";
239     }
240     else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
241                                                "disc_vcd" ) )->active )
242     {
243         psz_method = "vcd";
244     }
245     else
246     {
247         intf_ErrMsg( "intf error: unknown disc type toggle button position" );
248         free( psz_source );
249         return;
250     }
251     
252     /* Select title and chapter */
253     main_PutIntVariable( INPUT_TITLE_VAR, gtk_spin_button_get_value_as_int(
254                               GTK_SPIN_BUTTON( lookup_widget(
255                                   GTK_WIDGET(button), "disc_title" ) ) ) );
256
257     main_PutIntVariable( INPUT_CHAPTER_VAR, gtk_spin_button_get_value_as_int(
258                               GTK_SPIN_BUTTON( lookup_widget(
259                                   GTK_WIDGET(button), "disc_chapter" ) ) ) );
260
261     /* Build source name and add it to playlist */
262     sprintf( psz_source, "%s:%s", psz_method, psz_device );
263     intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
264     free( psz_source );
265
266     /* catch the GTK CList */
267     p_playlist_clist = GTK_CLIST( gtk_object_get_data(
268         GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
269
270     /* update the display */
271     GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
272
273     /* stop current item, select added item */
274     if( p_intf->p_input != NULL )
275     {
276         p_intf->p_input->b_eof = 1;
277     }
278
279 //    vlc_mutex_lock( &p_main->p_playlist->change_lock );
280
281     intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
282     p_main->p_playlist->b_stopped = 0;
283
284 //    vlc_mutex_unlock( &p_main->p_playlist->change_lock );
285 }
286
287 void GtkDiscOpenCancel( GtkButton * button, gpointer user_data)
288 {
289     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
290 }
291
292 /*****************************************************************************
293  * Network stream callbacks
294  *****************************************************************************
295  * The following callbacks are related to the network stream manager.
296  *****************************************************************************/
297 #if 0
298 void GtkNetworkOpenShow( GtkMenuItem * menuitem, gpointer user_data)
299 {
300     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(menuitem), (char*)user_data );
301
302     if( !GTK_IS_WIDGET( p_intf->p_sys->p_network ) )
303     {
304         p_intf->p_sys->p_disc = create_intf_network();
305         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_network ),
306                              "p_intf", p_intf );
307     }
308
309     gtk_widget_show( p_intf->p_sys->p_network );
310     gdk_window_raise( p_intf->p_sys->p_network->window );
311 }
312 #else
313
314 gboolean
315 GtkNetworkOpenShow                     (GtkWidget       *widget,
316                                         GdkEventButton  *event,
317                                         gpointer         user_data)
318 {
319     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
320
321     if( !GTK_IS_WIDGET( p_intf->p_sys->p_network ) )
322     {
323         p_intf->p_sys->p_network = create_intf_network();
324         gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_network ),
325                              "p_intf", p_intf );
326     }
327
328     gtk_widget_show( p_intf->p_sys->p_network );
329     gdk_window_raise( p_intf->p_sys->p_network->window );
330
331     return FALSE;
332 }
333
334
335
336 #endif
337
338 void GtkNetworkOpenOk( GtkButton *button, gpointer user_data )
339 {
340     intf_thread_t * p_intf = GetIntf( GTK_WIDGET(button), "intf_network" );
341     GtkCList *      p_playlist_clist;
342     char *          psz_source, *psz_server, *psz_protocol;
343     unsigned int    i_port;
344     boolean_t       b_broadcast;
345     int             i_end = p_main->p_playlist->i_size;
346
347     gtk_widget_hide( p_intf->p_sys->p_network );
348     psz_server = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
349                                  GTK_WIDGET(button), "network_server" ) ) );
350
351     /* Check which protocol was activated */
352     if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
353                                           "network_ts" ) )->active )
354     {
355         psz_protocol = "ts";
356     }
357     else if( GTK_TOGGLE_BUTTON( lookup_widget( GTK_WIDGET(button),
358                                                "network_rtp" ) )->active )
359     {
360         psz_protocol = "rtp";
361     }
362     else
363     {
364         intf_ErrMsg( "intf error: unknown protocol toggle button position" );
365         return;
366     }
367
368     /* Get the port number and make sure it will not overflow 5 characters */
369     i_port = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(
370                  lookup_widget( GTK_WIDGET(button), "network_port" ) ) );
371     if( i_port > 65535 )
372     {
373         intf_ErrMsg( "intf error: invalid port %i", i_port );
374     }
375
376     /* do we have a broadcast address */
377     b_broadcast = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(
378         lookup_widget( GTK_WIDGET(button), "broadcast_check" ) ) );
379     if( b_broadcast )
380     {
381         char *  psz_broadcast;
382         psz_broadcast = gtk_entry_get_text( GTK_ENTRY( lookup_widget(
383                                  GTK_WIDGET(button), "network_broadcast" ) ) );
384         /* Allocate room for "protocol://server:port" */
385         psz_source = malloc( strlen( psz_protocol ) + 3 /* "://" */
386                                + strlen( psz_server ) + 1 /* ":" */
387                                + 5 /* 0-65535 */
388                                + strlen( psz_broadcast ) + 2 /* "::" */ 
389                                + 1 /* "\0" */ );
390         if( psz_source == NULL )
391         {
392             return;
393         }
394
395         /* Build source name and add it to playlist */
396         sprintf( psz_source, "%s://%s:%i::%s", psz_protocol,
397                                                psz_server,
398                                                i_port,
399                                                psz_broadcast );
400     }
401     else
402     {
403         /* Allocate room for "protocol://server:port" */
404         psz_source = malloc( strlen( psz_protocol ) + 3 /* "://" */
405                                + strlen( psz_server ) + 1 /* ":" */
406                                + 5 /* 0-65535 */ + 1 /* "\0" */ );
407         if( psz_source == NULL )
408         {
409             return;
410         }
411        
412         /* Build source name and add it to playlist */
413         sprintf( psz_source, "%s://%s:%i", psz_protocol, psz_server, i_port );
414     }
415
416     intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, psz_source );
417     free( psz_source );
418
419     /* catch the GTK CList */
420     p_playlist_clist = GTK_CLIST( gtk_object_get_data(
421         GTK_OBJECT( p_intf->p_sys->p_playlist ), "playlist_clist" ) );
422     /* update the display */
423     GtkRebuildCList( p_playlist_clist, p_main->p_playlist );
424
425     /* select added item */
426     if( p_intf->p_input != NULL )
427     {
428         p_intf->p_input->b_eof = 1;
429     }
430
431 //    vlc_mutex_lock( &p_main->p_playlist->change_lock );
432
433     intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
434     p_main->p_playlist->b_stopped = 0;
435
436 //    vlc_mutex_unlock( &p_main->p_playlist->change_lock );
437 }
438
439 void GtkNetworkOpenCancel( GtkButton * button, gpointer user_data)
440 {
441     gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );
442 }
443
444
445 void GtkNetworkOpenBroadcast( GtkToggleButton * togglebutton,
446                               gpointer user_data )
447 {
448     GtkWidget *     p_network;
449
450     p_network = gtk_widget_get_toplevel( GTK_WIDGET (togglebutton) );
451
452     gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
453             "network_broadcast_combo" ),
454             gtk_toggle_button_get_active( togglebutton ) );
455
456     gtk_widget_set_sensitive( gtk_object_get_data( GTK_OBJECT( p_network ),
457             "network_broadcast" ),
458             gtk_toggle_button_get_active( togglebutton ) );
459 }
460
461
462