]> git.sesse.net Git - vlc/blob - plugins/gtk/gtk_control.c
*Bugfixes, cleanings in gtk.
[vlc] / plugins / gtk / gtk_control.c
1 /*****************************************************************************
2  * gtk_control.c : functions to handle stream control buttons.
3  *****************************************************************************
4  * Copyright (C) 2000, 2001 VideoLAN
5  * $Id: gtk_control.c,v 1.2 2001/05/15 14:49:48 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  * Control functions: this is where the functions are defined
61  ****************************************************************************
62  * These functions are button-items callbacks, and are used
63  * by other callbacks
64  ****************************************************************************/
65 gboolean GtkControlBack( GtkWidget       *widget,
66                          GdkEventButton  *event,
67                          gpointer         user_data )
68 {
69
70     return FALSE;
71 }
72
73
74 gboolean GtkControlStop( GtkWidget       *widget,
75                          GdkEventButton  *event,
76                          gpointer         user_data )
77 {
78     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
79
80     if( p_intf->p_input != NULL )
81     {
82         /* end playing item */
83         p_intf->p_input->b_eof = 1;
84
85         /* update playlist */
86         vlc_mutex_lock( &p_main->p_playlist->change_lock );
87
88         p_main->p_playlist->i_index--;
89         p_main->p_playlist->b_stopped = 1;
90
91         vlc_mutex_unlock( &p_main->p_playlist->change_lock );
92
93     }
94
95     return TRUE;
96 }
97
98
99 gboolean GtkControlPlay( GtkWidget       *widget,
100                          GdkEventButton  *event,
101                          gpointer         user_data )
102 {
103     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
104
105     if( p_intf->p_input != NULL )
106     {
107         input_SetStatus( p_intf->p_input, INPUT_STATUS_PLAY );
108         p_main->p_playlist->b_stopped = 0;
109     }
110     else
111     {
112         vlc_mutex_lock( &p_main->p_playlist->change_lock );
113
114         if( p_main->p_playlist->b_stopped )
115         {
116             if( p_main->p_playlist->i_size )
117             {
118                 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
119                 intf_PlaylistJumpto( p_main->p_playlist,
120                                      p_main->p_playlist->i_index );
121             }
122             else
123             {
124                 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
125                 GtkFileOpenShow( widget, event, user_data );
126             }
127         }
128         else
129         {
130
131             vlc_mutex_unlock( &p_main->p_playlist->change_lock );
132         }
133
134     }
135
136     return TRUE;
137 }
138
139
140 gboolean GtkControlPause( GtkWidget       *widget,
141                           GdkEventButton  *event,
142                           gpointer         user_data )
143 {
144     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
145
146     if( p_intf->p_input != NULL )
147     {
148         input_SetStatus( p_intf->p_input, INPUT_STATUS_PAUSE );
149
150         vlc_mutex_lock( &p_main->p_playlist->change_lock );
151         p_main->p_playlist->b_stopped = 0;
152         vlc_mutex_unlock( &p_main->p_playlist->change_lock );
153     }
154
155     return TRUE;
156 }
157
158
159 gboolean GtkControlSlow( GtkWidget       *widget,
160                          GdkEventButton  *event,
161                          gpointer         user_data )
162 {
163     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
164
165     if( p_intf->p_input != NULL )
166     {
167         input_SetStatus( p_intf->p_input, INPUT_STATUS_SLOWER );
168
169         vlc_mutex_lock( &p_main->p_playlist->change_lock );
170         p_main->p_playlist->b_stopped = 0;
171         vlc_mutex_unlock( &p_main->p_playlist->change_lock );
172     }
173
174     return TRUE;
175 }
176
177
178 gboolean GtkControlFast( GtkWidget       *widget,
179                          GdkEventButton  *event,
180                          gpointer         user_data )
181 {
182     intf_thread_t *p_intf = GetIntf( GTK_WIDGET(widget), (char*)user_data );
183
184     if( p_intf->p_input != NULL )
185     {
186         input_SetStatus( p_intf->p_input, INPUT_STATUS_FASTER );
187
188         vlc_mutex_lock( &p_main->p_playlist->change_lock );
189         p_main->p_playlist->b_stopped = 0;
190         vlc_mutex_unlock( &p_main->p_playlist->change_lock );
191     }
192
193     return TRUE;
194 }
195
196
197 /****************************************************************************
198  * Control callbacks for menuitems
199  ****************************************************************************
200  * We have different callaback for menuitem since we must use the
201  * activate signal toi popdown the menu automatically
202  ****************************************************************************/
203 void GtkPlayActivate( GtkMenuItem * menuitem, gpointer user_data )
204 {
205     GtkControlPlay( GTK_WIDGET( menuitem ), NULL, user_data );
206 }
207
208
209 void GtkPauseActivate( GtkMenuItem * menuitem, gpointer user_data )
210 {
211     GtkControlPause( GTK_WIDGET( menuitem ), NULL, user_data );
212
213 }
214
215
216 void
217 GtKStopActivate                        (GtkMenuItem     *menuitem,
218                                         gpointer         user_data)
219 {
220     GtkControlStop( GTK_WIDGET( menuitem ), NULL, user_data );
221
222 }
223
224
225 void
226 GtkBackActivate                        (GtkMenuItem     *menuitem,
227                                         gpointer         user_data)
228 {
229     GtkControlBack( GTK_WIDGET( menuitem ), NULL, user_data );
230
231 }
232
233
234 void
235 GtkSlowActivate                        (GtkMenuItem     *menuitem,
236                                         gpointer         user_data)
237 {
238     GtkControlSlow( GTK_WIDGET( menuitem ), NULL, user_data );
239
240 }
241
242
243 void
244 GtkFastActivate                        (GtkMenuItem     *menuitem,
245                                         gpointer         user_data)
246 {
247     GtkControlFast( GTK_WIDGET( menuitem ), NULL, user_data );
248 }
249
250