v4l: support libv4l
[vlc/solaris.git] / modules / gui / hildon / maemo_callbacks.c
blobcf6395171a416da39af41974bed7a7ddf75bd506
1 /*****************************************************************************
2 * maemo_callbacks.c : Callbacks for the maemo plugin.
3 *****************************************************************************
4 * Copyright (C) 2008 the VideoLAN team
5 * $Id$
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>
26 #include "maemo.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 ),
46 "p_intf" );
49 gboolean delete_event_cb( GtkWidget *widget,
50 GdkEvent *event,
51 gpointer user_data )
53 (void)event; (void)user_data;
54 intf_thread_t *p_intf = get_intf_from_widget( widget );
56 libvlc_Quit( p_intf->p_libvlc );
57 gtk_main_quit();
59 return TRUE;
62 void play_cb( GtkButton *button, gpointer user_data )
64 (void)user_data;
65 intf_thread_t *p_intf = get_intf_from_widget( GTK_WIDGET( button ) );
67 // If there is no input, we ask the playlist to play
68 if( p_intf->p_sys->p_input == NULL )
70 playlist_Play( p_intf->p_sys->p_playlist );
71 return;
74 // If there is an input, we toggle its state
75 vlc_value_t state;
76 var_Get( p_intf->p_sys->p_input, "state", &state );
77 state.i_int = ( state.i_int != PLAYING_S ) ? PLAYING_S : PAUSE_S;
78 var_Set( p_intf->p_sys->p_input, "state", state );
81 void stop_cb( GtkButton *button, gpointer user_data )
83 (void)user_data;
84 intf_thread_t *p_intf = get_intf_from_widget( GTK_WIDGET( button ) );
85 playlist_Stop( p_intf->p_sys->p_playlist );
88 void prev_cb( GtkButton *button, gpointer user_data )
90 (void)user_data;
91 intf_thread_t *p_intf = get_intf_from_widget( GTK_WIDGET( button ) );
92 playlist_Prev( p_intf->p_sys->p_playlist );
95 void next_cb( GtkButton *button, gpointer user_data )
97 (void)user_data;
98 intf_thread_t *p_intf = get_intf_from_widget( GTK_WIDGET( button ) );
99 playlist_Next( p_intf->p_sys->p_playlist );
102 void seekbar_changed_cb( GtkRange *range, GtkScrollType scroll,
103 gdouble value, gpointer data )
105 (void)scroll; (void)data;
106 intf_thread_t *p_intf = get_intf_from_widget( GTK_WIDGET( range ) );
107 if( p_intf->p_sys->p_input )
109 int i_length = hildon_seekbar_get_total_time( p_intf->p_sys->p_seekbar );
110 var_SetFloat( p_intf->p_sys->p_input, "position", (float)(value/i_length) );
114 void pl_row_activated_cb( GtkTreeView *tree_view , GtkTreePath *path,
115 GtkTreeViewColumn *column, gpointer user_data )
117 (void)column; (void)user_data;
118 intf_thread_t *p_intf = get_intf_from_widget( GTK_WIDGET( tree_view ) );
119 input_item_t *p_input;
120 GtkTreeModel *model = gtk_tree_view_get_model( tree_view );
121 GtkTreeIter iter;
122 gchar *filename = NULL;
124 gtk_tree_model_get_iter( model, &iter, path );
125 gtk_tree_model_get( model, &iter, 0, &filename, -1 );
127 gtk_notebook_set_current_page( GTK_NOTEBOOK( p_intf->p_sys->p_tabs ), 0 );
129 p_input = input_item_New( p_intf, filename, NULL );
130 playlist_AddInput( p_intf->p_sys->p_playlist, p_input,
131 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END, true, false );
132 vlc_gc_decref( p_input );
135 void open_cb( GtkMenuItem *menuitem, gpointer user_data )
137 (void)menuitem;
138 intf_thread_t *p_intf = (intf_thread_t *)user_data;
139 input_item_t *p_input;
140 GtkWidget *dialog;
141 char *psz_filename = NULL;
143 dialog = hildon_file_chooser_dialog_new( GTK_WINDOW( p_intf->p_sys->p_main_window ),
144 GTK_FILE_CHOOSER_ACTION_OPEN );
145 gtk_widget_show_all( GTK_WIDGET( dialog ) );
147 if( gtk_dialog_run( GTK_DIALOG( dialog ) ) == GTK_RESPONSE_OK )
149 psz_filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( dialog ) );
151 else
153 gtk_widget_destroy( dialog );
154 return;
157 gtk_widget_destroy( dialog );
159 p_input = input_item_New( p_intf, psz_filename, NULL );
160 playlist_AddInput( p_intf->p_sys->p_playlist, p_input,
161 PLAYLIST_APPEND | PLAYLIST_GO,
162 PLAYLIST_END, true, false );
163 vlc_gc_decref( p_input );
166 void open_address_cb( GtkMenuItem *menuitem, gpointer user_data )
168 (void)menuitem;
169 intf_thread_t *p_intf = (intf_thread_t *)user_data;
170 input_item_t *p_input;
171 GtkWidget *dialog, *hbox, *label, *entry;
173 dialog = gtk_dialog_new_with_buttons( "Open Address",
174 GTK_WINDOW( p_intf->p_sys->p_main_window ),
175 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
176 GTK_STOCK_OK, GTK_RESPONSE_OK,
177 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
178 NULL );
179 label = gtk_label_new( "Address :" );
180 entry = gtk_entry_new();
181 gtk_entry_set_width_chars( GTK_ENTRY( entry ), 30 );
182 hbox = gtk_hbox_new( FALSE, 0 );
183 gtk_box_pack_start( GTK_BOX( hbox ), label, FALSE, FALSE, 0 );
184 gtk_box_pack_start( GTK_BOX( hbox ), entry, TRUE, TRUE, 0 );
185 gtk_container_add( GTK_CONTAINER( GTK_DIALOG( dialog )->vbox ), hbox );
187 gtk_widget_show_all( dialog );
188 if( gtk_dialog_run( GTK_DIALOG( dialog ) ) == GTK_RESPONSE_CANCEL )
190 gtk_widget_destroy( dialog );
191 return;
194 p_input = input_item_New( p_intf,
195 gtk_entry_get_text( GTK_ENTRY( entry ) ),
196 NULL );
197 playlist_AddInput( p_intf->p_sys->p_playlist, p_input,
198 PLAYLIST_APPEND | PLAYLIST_GO,
199 PLAYLIST_END, true, false );
200 vlc_gc_decref( p_input );
202 gtk_widget_destroy( dialog );
205 void open_webcam_cb( GtkMenuItem *menuitem, gpointer user_data )
207 (void)menuitem;
208 intf_thread_t *p_intf = (intf_thread_t *)user_data;
209 input_item_t *p_input;
211 p_input = input_item_New( p_intf, "v4l2://", NULL );
212 playlist_AddInput( p_intf->p_sys->p_playlist, p_input,
213 PLAYLIST_APPEND | PLAYLIST_GO,
214 PLAYLIST_END, true, false );
215 vlc_gc_decref( p_input );
218 void snapshot_cb( GtkMenuItem *menuitem, gpointer user_data )
220 (void)menuitem;
221 intf_thread_t *p_intf = (intf_thread_t *)user_data;
223 if( !p_intf->p_sys->p_vout )
225 hildon_banner_show_information(
226 GTK_WIDGET( p_intf->p_sys->p_main_window ),
227 "gtk-dialog-error",
228 "There is no video" );
229 return;
232 var_TriggerCallback( p_intf->p_sys->p_vout, "video-snapshot" );
233 hildon_banner_show_information( GTK_WIDGET( p_intf->p_sys->p_main_window ),
234 NULL,
235 "Snapshot taken" );
238 void dropframe_cb( GtkMenuItem *menuitem, gpointer user_data )
240 intf_thread_t *p_intf = (intf_thread_t *)user_data;
242 if( gtk_check_menu_item_get_active( GTK_CHECK_MENU_ITEM( menuitem ) ) )
243 config_PutInt( p_intf, "ffmpeg-skip-frame", 1 );
244 else
245 config_PutInt( p_intf, "ffmpeg-skip-frame", 0 );