e8cf376c095cb3a12e672ad563e7792aab398124
[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.4 2002/07/24 20:46:08 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 /*****************************************************************************
51  * Useful function to retrieve p_intf
52  ****************************************************************************/
53 void * __GtkGetIntf( GtkWidget * widget )
54 {
55     void *p_data;
56
57     if( GTK_IS_MENU_ITEM( widget ) )
58     {
59         /* Look for a GTK_MENU */
60         while( widget->parent && !GTK_IS_MENU( widget ) )
61         {
62             widget = widget->parent;
63         }
64
65         /* Maybe this one has the data */
66         p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" );
67         if( p_data )
68         {
69             return p_data;
70         }
71
72         /* Otherwise, the parent widget has it */
73         widget = gtk_menu_get_attach_widget( GTK_MENU( widget ) );
74     }
75
76     /* We look for the top widget */
77     widget = gtk_widget_get_toplevel( GTK_WIDGET( widget ) );
78
79     p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" );
80
81     return p_data;
82 }
83
84 /*
85  * Main interface callbacks
86  */
87
88 gboolean GtkExit( GtkWidget       *widget,
89                   gpointer         user_data )
90 {
91     intf_thread_t *p_intf = GtkGetIntf( widget );
92
93     vlc_mutex_lock( &p_intf->change_lock );
94     p_intf->p_vlc->b_die = VLC_TRUE;
95     vlc_mutex_unlock( &p_intf->change_lock );
96
97     return TRUE;
98 }
99
100 gboolean
101 on_familiar_destroy_event              (GtkWidget       *widget,
102                                         GdkEvent        *event,
103                                         gpointer         user_data)
104 {
105     GtkExit( GTK_WIDGET( widget ), user_data );
106     return TRUE;
107 }
108
109
110 void
111 on_toolbar_open_clicked                (GtkButton       *button,
112                                         gpointer         user_data)
113 {
114     intf_thread_t *p_intf = GtkGetIntf( button );
115     if (p_intf)
116         gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
117 }
118
119
120 void
121 on_toolbar_preferences_clicked         (GtkButton       *button,
122                                         gpointer         user_data)
123 {
124     intf_thread_t *p_intf = GtkGetIntf( button );
125     if (p_intf)
126         gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
127 }
128
129
130 void
131 on_toolbar_rewind_clicked              (GtkButton       *button,
132                                         gpointer         user_data)
133 {
134     intf_thread_t *  p_intf = GtkGetIntf( button );
135
136     if( p_intf )
137     {
138         if( p_intf->p_sys->p_input )
139         {
140             input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_SLOWER );
141         }
142     }
143 }
144
145
146 void
147 on_toolbar_pause_clicked               (GtkButton       *button,
148                                         gpointer         user_data)
149 {
150     intf_thread_t *  p_intf = GtkGetIntf( button );
151
152     if( p_intf )
153     {
154         if( p_intf->p_sys->p_input )
155         {
156             input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
157         }
158     }
159 }
160
161
162 void
163 on_toolbar_play_clicked                (GtkButton       *button,
164                                         gpointer         user_data)
165 {
166     intf_thread_t *  p_intf = GtkGetIntf( button );
167     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
168                                                        FIND_ANYWHERE );
169     if( p_playlist == NULL )
170     {
171         // Display open page
172     }
173
174     /* If the playlist is empty, open a file requester instead */
175     vlc_mutex_lock( &p_playlist->object_lock );
176     if( p_playlist->i_size )
177     {
178         vlc_mutex_unlock( &p_playlist->object_lock );
179         playlist_Play( p_playlist );
180         vlc_object_release( p_playlist );
181     }
182     else
183     {
184         vlc_mutex_unlock( &p_playlist->object_lock );
185         vlc_object_release( p_playlist );
186         // Display open page
187     }
188 }
189
190
191 void
192 on_toolbar_stop_clicked                (GtkButton       *button,
193                                         gpointer         user_data)
194 {
195     intf_thread_t *  p_intf = GtkGetIntf( button );
196     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
197                                                        FIND_ANYWHERE );
198     if( p_playlist == NULL )
199     {
200         playlist_Stop( p_playlist );
201         vlc_object_release( p_playlist );
202     }
203 }
204
205
206 void
207 on_toolbar_forward_clicked             (GtkButton       *button,
208                                         gpointer         user_data)
209 {
210     intf_thread_t *  p_intf = GtkGetIntf( button );
211
212     if( p_intf )
213     {
214         if( p_intf->p_sys->p_input )
215         {
216             input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_FASTER );
217         }
218     }
219 }
220
221
222 void
223 on_toolbar_about_clicked               (GtkButton       *button,
224                                         gpointer         user_data)
225 {
226     intf_thread_t *p_intf = GtkGetIntf( button );
227     if (p_intf)
228     { // Toggle notebook
229 //        if ( gtk_get_data(  GTK_WIDGET(p_intf->p_sys->p_notebook), "visible" ) )
230 //           gtk_widget_hide( GTK_WIDGET(p_intf->p_sys->p_notebook) );
231 //        else
232            gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
233     }
234 }
235