1 /*****************************************************************************
2 * maemo_callbacks.c : Callbacks for the maemo plugin.
3 *****************************************************************************
4 * Copyright (C) 2008 the VideoLAN team
7 * Authors: Antoine Lejeune <phytos@videolan.org>
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.
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.
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 *****************************************************************************/
24 #include <vlc_common.h>
27 #include "maemo_callbacks.h"
30 * Function used to retrieve an intf_thread_t object from a GtkWidget
32 static intf_thread_t *get_intf_from_widget( GtkWidget *widget )
34 if( GTK_IS_MENU_ITEM( widget ) )
36 /* Look for a GTK_MENU */
37 while( widget->parent && !GTK_IS_MENU( widget ) )
39 widget = widget->parent;
42 widget = gtk_menu_get_attach_widget( GTK_MENU( widget ) );
44 widget = gtk_widget_get_toplevel( GTK_WIDGET( widget ) );
45 return (intf_thread_t *)gtk_object_get_data( GTK_OBJECT( widget ),
49 gboolean delete_event_cb( GtkWidget *widget,
53 (void)event; (void)user_data;
54 intf_thread_t *p_intf = get_intf_from_widget( widget );
56 vlc_mutex_lock( &p_intf->change_lock );
57 libvlc_Quit( p_intf->p_libvlc );
58 vlc_mutex_unlock( &p_intf->change_lock );
65 void play_cb( GtkButton *button, gpointer user_data )
68 intf_thread_t *p_intf = get_intf_from_widget( GTK_WIDGET( button ) );
70 // If there is no input, we ask the playlist to play
71 if( p_intf->p_sys->p_input == NULL )
73 playlist_Play( p_intf->p_sys->p_playlist );
77 // If there is an input, we toggle its 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 );
84 void stop_cb( GtkButton *button, gpointer user_data )
87 intf_thread_t *p_intf = get_intf_from_widget( GTK_WIDGET( button ) );
88 playlist_Stop( p_intf->p_sys->p_playlist );
91 void prev_cb( GtkButton *button, gpointer user_data )
94 intf_thread_t *p_intf = get_intf_from_widget( GTK_WIDGET( button ) );
95 playlist_Prev( p_intf->p_sys->p_playlist );
98 void next_cb( GtkButton *button, gpointer user_data )
101 intf_thread_t *p_intf = get_intf_from_widget( GTK_WIDGET( button ) );
102 playlist_Next( p_intf->p_sys->p_playlist );
105 void seekbar_changed_cb( GtkRange *range, GtkScrollType scroll,
106 gdouble value, gpointer data )
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 )
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) );
117 void pl_row_activated_cb( GtkTreeView *tree_view , GtkTreePath *path,
118 GtkTreeViewColumn *column, gpointer user_data )
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 );
125 gchar *filename = NULL;
127 gtk_tree_model_get_iter( model, &iter, path );
128 gtk_tree_model_get( model, &iter, 0, &filename, -1 );
130 gtk_notebook_set_current_page( GTK_NOTEBOOK( p_intf->p_sys->p_tabs ), 0 );
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 );
138 void open_cb( GtkMenuItem *menuitem, gpointer user_data )
141 intf_thread_t *p_intf = (intf_thread_t *)user_data;
142 input_item_t *p_input;
144 char *psz_filename = NULL;
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 ) );
150 if( gtk_dialog_run( GTK_DIALOG( dialog ) ) == GTK_RESPONSE_OK )
152 psz_filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( dialog ) );
156 gtk_widget_destroy( dialog );
160 gtk_widget_destroy( dialog );
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 );
169 void open_address_cb( GtkMenuItem *menuitem, gpointer user_data )
172 intf_thread_t *p_intf = (intf_thread_t *)user_data;
173 input_item_t *p_input;
174 GtkWidget *dialog, *hbox, *label, *entry;
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,
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 );
190 gtk_widget_show_all( dialog );
191 if( gtk_dialog_run( GTK_DIALOG( dialog ) ) == GTK_RESPONSE_CANCEL )
193 gtk_widget_destroy( dialog );
197 p_input = input_item_New( p_intf,
198 gtk_entry_get_text( GTK_ENTRY( entry ) ),
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 );
205 gtk_widget_destroy( dialog );
208 void open_webcam_cb( GtkMenuItem *menuitem, gpointer user_data )
211 intf_thread_t *p_intf = (intf_thread_t *)user_data;
212 input_item_t *p_input;
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 );
221 void snapshot_cb( GtkMenuItem *menuitem, gpointer user_data )
224 intf_thread_t *p_intf = (intf_thread_t *)user_data;
226 if( !p_intf->p_sys->p_vout )
228 hildon_banner_show_information(
229 GTK_WIDGET( p_intf->p_sys->p_main_window ),
231 "There is no video" );
235 vout_Control( p_intf->p_sys->p_vout, VOUT_SNAPSHOT );
236 hildon_banner_show_information( GTK_WIDGET( p_intf->p_sys->p_main_window ),
241 void dropframe_cb( GtkMenuItem *menuitem, gpointer user_data )
243 intf_thread_t *p_intf = (intf_thread_t *)user_data;
245 if( gtk_check_menu_item_get_active( GTK_CHECK_MENU_ITEM( menuitem ) ) )
246 config_PutInt( p_intf, "ffmpeg-skip-frame", 1 );
248 config_PutInt( p_intf, "ffmpeg-skip-frame", 0 );