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