Playing video from within the interface works.
[vlc.git] / plugins / familiar / familiar_callbacks.c
1 /*****************************************************************************
2  * familiar_callbacks.c : Callbacks for the Familiar Linux Gtk+ plugin.
3  *****************************************************************************
4  * Copyright (C) 2000, 2001 VideoLAN
5  * $Id: familiar_callbacks.c,v 1.5 2002/08/06 19:12:07 jpsaman Exp $
6  *
7  * Authors: Jean-Paul Saman <jpsaman@wxs.nl>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <sys/types.h>                                              /* off_t */
28 #include <stdlib.h>
29
30 #include <vlc/vlc.h>
31 #include <vlc/intf.h>
32 #include <vlc/vout.h>
33
34 #include <unistd.h>
35 #include <string.h>
36
37 #ifdef HAVE_CONFIG_H
38 #  include <config.h>
39 #endif
40
41 #include <gtk/gtk.h>
42
43 #include "familiar_callbacks.h"
44 #include "familiar_interface.h"
45 #include "familiar_support.h"
46 #include "familiar.h"
47
48 //#include "netutils.h"
49
50 static void MediaURLOpenChanged( GtkEditable *editable, gpointer user_data );
51 static void PreferencesURLOpenChanged( GtkEditable *editable, gpointer user_data );
52
53 /*****************************************************************************
54  * Useful function to retrieve p_intf
55  ****************************************************************************/
56 void * __GtkGetIntf( GtkWidget * widget )
57 {
58     void *p_data;
59
60     if( GTK_IS_MENU_ITEM( widget ) )
61     {
62         /* Look for a GTK_MENU */
63         while( widget->parent && !GTK_IS_MENU( widget ) )
64         {
65             widget = widget->parent;
66         }
67
68         /* Maybe this one has the data */
69         p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" );
70         if( p_data )
71         {
72             return p_data;
73         }
74
75         /* Otherwise, the parent widget has it */
76         widget = gtk_menu_get_attach_widget( GTK_MENU( widget ) );
77     }
78
79     /* We look for the top widget */
80     widget = gtk_widget_get_toplevel( GTK_WIDGET( widget ) );
81
82     p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" );
83
84     return p_data;
85 }
86
87 /*****************************************************************************
88  * Helper functions for URL changes in Media and Preferences notebook pages.
89  ****************************************************************************/
90 static void MediaURLOpenChanged( GtkEditable *editable, gpointer user_data )
91 {
92     intf_thread_t *p_intf = GtkGetIntf( editable );
93     playlist_t *p_playlist;
94     gchar *       psz_url;
95
96     psz_url = gtk_entry_get_text(GTK_ENTRY(editable));
97     g_print( "%s\n",psz_url );
98 //    p_url = gtk_editable_get_chars(editable,0,-1);
99
100     // Add p_url to playlist .... but how ?
101     if (p_intf)
102     {
103         p_playlist = (playlist_t *)
104                  vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
105         if( p_playlist )
106         {
107            playlist_Add( p_playlist, (char*)psz_url,
108                          PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
109            vlc_object_release( p_playlist );
110         }
111     }
112 }
113
114 static void PreferencesURLOpenChanged( GtkEditable *editable, gpointer user_data )
115 {
116     gchar *       p_url;
117 //    GtkWidget *   item;
118
119     p_url = gtk_entry_get_text(GTK_ENTRY(editable) );
120     g_print( "%s\n",p_url );
121
122 //    p_url = gtk_editable_get_chars(editable,0,-1);
123 //    item = gtk_list_item_new();
124 //    gtk_widget_show (item);
125 //    gtk_combo_set_item_string (GTK_COMBO (combo), GTK_ITEM (item), p_url);
126 //    /* Now we simply add the item to the combo's list. */
127 //    gtk_container_add (GTK_CONTAINER (GTK_COMBO (combo)->list), item);
128 }
129
130
131 /*
132  * Main interface callbacks
133  */
134
135 gboolean GtkExit( GtkWidget       *widget,
136                   gpointer         user_data )
137 {
138     intf_thread_t *p_intf = GtkGetIntf( widget );
139
140     vlc_mutex_lock( &p_intf->change_lock );
141     p_intf->p_vlc->b_die = VLC_TRUE;
142     vlc_mutex_unlock( &p_intf->change_lock );
143
144     return TRUE;
145 }
146
147 gboolean
148 on_familiar_destroy_event              (GtkWidget       *widget,
149                                         GdkEvent        *event,
150                                         gpointer         user_data)
151 {
152     GtkExit( GTK_WIDGET( widget ), user_data );
153     return TRUE;
154 }
155
156
157 void
158 on_toolbar_open_clicked                (GtkButton       *button,
159                                         gpointer         user_data)
160 {
161     intf_thread_t *p_intf = GtkGetIntf( button );
162     if (p_intf)
163     {
164         gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
165         gdk_window_raise( p_intf->p_sys->p_window->window );
166     }
167 }
168
169
170 void
171 on_toolbar_preferences_clicked         (GtkButton       *button,
172                                         gpointer         user_data)
173 {
174     intf_thread_t *p_intf = GtkGetIntf( button );
175     if (p_intf) {
176         gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
177         gdk_window_raise( p_intf->p_sys->p_window->window );
178     }
179 }
180
181
182 void
183 on_toolbar_rewind_clicked              (GtkButton       *button,
184                                         gpointer         user_data)
185 {
186     intf_thread_t *  p_intf = GtkGetIntf( button );
187
188     if( p_intf )
189     {
190         if( p_intf->p_sys->p_input )
191         {
192             input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_SLOWER );
193         }
194     }
195 }
196
197
198 void
199 on_toolbar_pause_clicked               (GtkButton       *button,
200                                         gpointer         user_data)
201 {
202     intf_thread_t *  p_intf = GtkGetIntf( button );
203
204     if( p_intf )
205     {
206         if( p_intf->p_sys->p_input )
207         {
208             input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
209         }
210     }
211 }
212
213
214 void
215 on_toolbar_play_clicked                (GtkButton       *button,
216                                         gpointer         user_data)
217 {
218     intf_thread_t *  p_intf = GtkGetIntf( button );
219     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
220                                                        FIND_ANYWHERE );
221     if( p_playlist == NULL )
222     {
223         if( p_intf )
224         {
225            gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
226            gdk_window_raise( p_intf->p_sys->p_window->window );
227         }
228         // Display open page
229     }
230
231     /* If the playlist is empty, open a file requester instead */
232     vlc_mutex_lock( &p_playlist->object_lock );
233     if( p_playlist->i_size )
234     {
235         vlc_mutex_unlock( &p_playlist->object_lock );
236         playlist_Play( p_playlist );
237         vlc_object_release( p_playlist );
238         gdk_window_lower( p_intf->p_sys->p_window->window );
239     }
240     else
241     {
242         vlc_mutex_unlock( &p_playlist->object_lock );
243         vlc_object_release( p_playlist );
244         // Display open page
245     }
246 }
247
248
249 void
250 on_toolbar_stop_clicked                (GtkButton       *button,
251                                         gpointer         user_data)
252 {
253     intf_thread_t *  p_intf = GtkGetIntf( button );
254     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
255                                                        FIND_ANYWHERE );
256     if( p_playlist)
257     {
258         playlist_Stop( p_playlist );
259         vlc_object_release( p_playlist );
260         gdk_window_raise( p_intf->p_sys->p_window->window );
261     }
262 }
263
264
265 void
266 on_toolbar_forward_clicked             (GtkButton       *button,
267                                         gpointer         user_data)
268 {
269     intf_thread_t *  p_intf = GtkGetIntf( button );
270
271     if( p_intf )
272     {
273         if( p_intf->p_sys->p_input )
274         {
275             input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_FASTER );
276         }
277     }
278 }
279
280
281 void
282 on_toolbar_about_clicked               (GtkButton       *button,
283                                         gpointer         user_data)
284 {
285     intf_thread_t *p_intf = GtkGetIntf( button );
286     if (p_intf)
287     {// Toggle notebook
288         if (p_intf->p_sys->p_notebook)
289         {
290 //        if ( gtk_get_data(  GTK_WIDGET(p_intf->p_sys->p_notebook), "visible" ) )
291 //           gtk_widget_hide( GTK_WIDGET(p_intf->p_sys->p_notebook) );
292 //        else
293            gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
294         }
295         gdk_window_raise( p_intf->p_sys->p_window->window );
296     }
297 }
298
299
300 void
301 on_comboURL_entry_changed              (GtkEditable     *editable,
302                                         gpointer         user_data)
303 {
304     intf_thread_t * p_intf = GtkGetIntf( editable );
305
306     if (p_intf)
307     {
308         MediaURLOpenChanged( editable, NULL );
309     }
310 }
311
312
313 void
314 on_comboPrefs_entry_changed            (GtkEditable     *editable,
315                                         gpointer         user_data)
316 {
317     intf_thread_t * p_intf = GtkGetIntf( editable );
318
319     if (p_intf)
320     {
321         PreferencesURLOpenChanged( editable, NULL );
322     }
323 }
324