WinCE: make buildbot happy for now.
[vlc.git] / modules / gui / maemo / maemo_callbacks.c
1 /*****************************************************************************
2 * maemo_callbacks.c : Callbacks for the maemo plugin.
3 *****************************************************************************
4 * Copyright (C) 2008 the VideoLAN team
5 * $Id$
6 *
7 * Authors: Antoine Lejeune <phytos@videolan.org>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
23
24 #include <vlc_common.h>
25
26 #include "maemo.h"
27 #include "maemo_callbacks.h"
28
29 /*
30  * Function used to retrieve an intf_thread_t object from a GtkWidget
31  */
32 static intf_thread_t *get_intf_from_widget( GtkWidget *widget )
33 {
34     if( GTK_IS_MENU_ITEM( widget ) )
35     {
36         /* Look for a GTK_MENU */
37         while( widget->parent && !GTK_IS_MENU( widget ) )
38         {
39             widget = widget->parent;
40         }
41
42         widget = gtk_menu_get_attach_widget( GTK_MENU( widget ) );
43     }
44     widget = gtk_widget_get_toplevel( GTK_WIDGET( widget ) );
45     return (intf_thread_t *)gtk_object_get_data( GTK_OBJECT( widget ),
46                                                  "p_intf" );
47 }
48
49 gboolean delete_event_cb( GtkWidget *widget,
50                           GdkEvent *event,
51                           gpointer user_data )
52 {
53     (void)event; (void)user_data;
54     intf_thread_t *p_intf = get_intf_from_widget( widget );
55
56     vlc_mutex_lock( &p_intf->change_lock );
57     libvlc_Quit( p_intf->p_libvlc );
58     vlc_mutex_unlock( &p_intf->change_lock );
59
60     gtk_main_quit();
61
62     return TRUE;
63 }
64
65 void play_cb( GtkButton *button, gpointer user_data )
66 {
67     (void)user_data;
68     intf_thread_t *p_intf = get_intf_from_widget( GTK_WIDGET( button ) );
69
70     // If there is no input, we ask the playlist to play
71     if( p_intf->p_sys->p_input == NULL )
72     {
73         playlist_Play( p_intf->p_sys->p_playlist );
74         return;
75     }
76
77     // If there is an input, we toggle its state
78     vlc_value_t state;
79     var_Get( p_intf->p_sys->p_input, "state", &state );
80     state.i_int = ( state.i_int != PLAYING_S ) ? PLAYING_S : PAUSE_S;
81     var_Set( p_intf->p_sys->p_input, "state", state );
82 }
83
84 void stop_cb( GtkButton *button, gpointer user_data )
85 {
86     (void)user_data;
87     intf_thread_t *p_intf = get_intf_from_widget( GTK_WIDGET( button ) );
88     playlist_Stop( p_intf->p_sys->p_playlist );
89 }
90
91 void prev_cb( GtkButton *button, gpointer user_data )
92 {
93     (void)user_data;
94     intf_thread_t *p_intf = get_intf_from_widget( GTK_WIDGET( button ) );
95     playlist_Prev( p_intf->p_sys->p_playlist );
96 }
97
98 void next_cb( GtkButton *button, gpointer user_data )
99 {
100     (void)user_data;
101     intf_thread_t *p_intf = get_intf_from_widget( GTK_WIDGET( button ) );
102     playlist_Next( p_intf->p_sys->p_playlist );
103 }
104
105 void seekbar_changed_cb( GtkRange *range, GtkScrollType scroll,
106                          gdouble value, gpointer data )
107 {
108     (void)scroll; (void)data;
109     intf_thread_t *p_intf = get_intf_from_widget( GTK_WIDGET( range ) );
110     if( p_intf->p_sys->p_input )
111     {
112         int i_length = hildon_seekbar_get_total_time( p_intf->p_sys->p_seekbar );
113         var_SetFloat( p_intf->p_sys->p_input, "position", (float)(value/i_length) );
114     }
115 }
116
117 void pl_row_activated_cb( GtkTreeView *tree_view , GtkTreePath *path,
118                           GtkTreeViewColumn *column, gpointer user_data )
119 {
120     (void)column; (void)user_data;
121     intf_thread_t *p_intf = get_intf_from_widget( GTK_WIDGET( tree_view ) );
122     input_item_t *p_input;
123     GtkTreeModel *model = gtk_tree_view_get_model( tree_view );
124     GtkTreeIter iter;
125     gchar *filename = NULL;
126
127     gtk_tree_model_get_iter( model, &iter, path );
128     gtk_tree_model_get( model, &iter, 0, &filename, -1 );
129
130     gtk_notebook_set_current_page( GTK_NOTEBOOK( p_intf->p_sys->p_tabs ), 0 );
131
132     p_input = input_item_New( p_intf, filename, NULL );
133     playlist_AddInput( p_intf->p_sys->p_playlist, p_input,
134                        PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END, true, false );
135     vlc_gc_decref( p_input );
136 }
137
138 void open_cb( GtkMenuItem *menuitem, gpointer user_data )
139 {
140     (void)menuitem;
141     intf_thread_t *p_intf = (intf_thread_t *)user_data;
142     input_item_t *p_input;
143     GtkWidget *dialog;
144     char *psz_filename = NULL;
145
146     dialog = hildon_file_chooser_dialog_new( GTK_WINDOW( p_intf->p_sys->p_main_window ),
147                                              GTK_FILE_CHOOSER_ACTION_OPEN );
148     gtk_widget_show_all( GTK_WIDGET( dialog ) );
149
150     if( gtk_dialog_run( GTK_DIALOG( dialog ) ) == GTK_RESPONSE_OK )
151     {
152         psz_filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( dialog ) );
153     }
154     else
155     {
156         gtk_widget_destroy( dialog );
157         return;
158     }
159
160     gtk_widget_destroy( dialog );
161
162     p_input = input_item_New( p_intf, psz_filename, NULL );
163     playlist_AddInput( p_intf->p_sys->p_playlist, p_input,
164                        PLAYLIST_APPEND | PLAYLIST_GO,
165                        PLAYLIST_END, true, false );
166     vlc_gc_decref( p_input );
167 }
168
169 void open_address_cb( GtkMenuItem *menuitem, gpointer user_data )
170 {
171     (void)menuitem;
172     intf_thread_t *p_intf = (intf_thread_t *)user_data;
173     input_item_t *p_input;
174     GtkWidget *dialog, *hbox, *label, *entry;
175
176     dialog = gtk_dialog_new_with_buttons( "Open Address",
177                 GTK_WINDOW( p_intf->p_sys->p_main_window ),
178                 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
179                 GTK_STOCK_OK, GTK_RESPONSE_OK,
180                 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
181                 NULL );
182     label = gtk_label_new( "Address :" );
183     entry = gtk_entry_new();
184     gtk_entry_set_width_chars( GTK_ENTRY( entry ), 30 );
185     hbox = gtk_hbox_new( FALSE, 0 );
186     gtk_box_pack_start( GTK_BOX( hbox ), label, FALSE, FALSE, 0 );
187     gtk_box_pack_start( GTK_BOX( hbox ), entry, TRUE, TRUE, 0 );
188     gtk_container_add( GTK_CONTAINER( GTK_DIALOG( dialog )->vbox ), hbox );
189
190     gtk_widget_show_all( dialog );
191     if( gtk_dialog_run( GTK_DIALOG( dialog ) ) == GTK_RESPONSE_CANCEL )
192     {
193         gtk_widget_destroy( dialog );
194         return;
195     }
196
197     p_input = input_item_New( p_intf,
198                               gtk_entry_get_text( GTK_ENTRY( entry ) ),
199                               NULL );
200     playlist_AddInput( p_intf->p_sys->p_playlist, p_input,
201                        PLAYLIST_APPEND | PLAYLIST_GO,
202                        PLAYLIST_END, true, false );
203     vlc_gc_decref( p_input );
204
205     gtk_widget_destroy( dialog );
206 }
207
208 void open_webcam_cb( GtkMenuItem *menuitem, gpointer user_data )
209 {
210     (void)menuitem;
211     intf_thread_t *p_intf = (intf_thread_t *)user_data;
212     input_item_t *p_input;
213
214     p_input = input_item_New( p_intf, "v4l2://", NULL );
215     playlist_AddInput( p_intf->p_sys->p_playlist, p_input,
216                        PLAYLIST_APPEND | PLAYLIST_GO,
217                        PLAYLIST_END, true, false );
218     vlc_gc_decref( p_input );
219 }
220
221 void snapshot_cb( GtkMenuItem *menuitem, gpointer user_data )
222 {
223     (void)menuitem;
224     intf_thread_t *p_intf = (intf_thread_t *)user_data;
225
226     if( !p_intf->p_sys->p_vout )
227     {
228         hildon_banner_show_information(
229                                 GTK_WIDGET( p_intf->p_sys->p_main_window ),
230                                 "gtk-dialog-error",
231                                 "There is no video" );
232         return;
233     }
234
235     var_TriggerCallback( p_intf->p_sys->p_vout, "video-snapshot" );
236     hildon_banner_show_information( GTK_WIDGET( p_intf->p_sys->p_main_window ),
237                                     NULL,
238                                     "Snapshot taken" );
239 }
240
241 void dropframe_cb( GtkMenuItem *menuitem, gpointer user_data )
242 {
243     intf_thread_t *p_intf = (intf_thread_t *)user_data;
244
245     if( gtk_check_menu_item_get_active( GTK_CHECK_MENU_ITEM( menuitem ) ) )
246         config_PutInt( p_intf, "ffmpeg-skip-frame", 1 );
247     else
248         config_PutInt( p_intf, "ffmpeg-skip-frame", 0 );
249 }