]> git.sesse.net Git - vlc/blob - modules/gui/hildon/maemo_callbacks.c
Maemo: rename plugin to Hildon
[vlc] / modules / gui / hildon / 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     libvlc_Quit( p_intf->p_libvlc );
57     gtk_main_quit();
58
59     return TRUE;
60 }
61
62 void play_cb( GtkButton *button, gpointer user_data )
63 {
64     (void)user_data;
65     intf_thread_t *p_intf = get_intf_from_widget( GTK_WIDGET( button ) );
66
67     // If there is no input, we ask the playlist to play
68     if( p_intf->p_sys->p_input == NULL )
69     {
70         playlist_Play( p_intf->p_sys->p_playlist );
71         return;
72     }
73
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 );
79 }
80
81 void stop_cb( GtkButton *button, gpointer user_data )
82 {
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 );
86 }
87
88 void prev_cb( GtkButton *button, gpointer user_data )
89 {
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 );
93 }
94
95 void next_cb( GtkButton *button, gpointer user_data )
96 {
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 );
100 }
101
102 void seekbar_changed_cb( GtkRange *range, GtkScrollType scroll,
103                          gdouble value, gpointer data )
104 {
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 )
108     {
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) );
111     }
112 }
113
114 void pl_row_activated_cb( GtkTreeView *tree_view , GtkTreePath *path,
115                           GtkTreeViewColumn *column, gpointer user_data )
116 {
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;
123
124     gtk_tree_model_get_iter( model, &iter, path );
125     gtk_tree_model_get( model, &iter, 0, &filename, -1 );
126
127     gtk_notebook_set_current_page( GTK_NOTEBOOK( p_intf->p_sys->p_tabs ), 0 );
128
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 );
133 }
134
135 void open_cb( GtkMenuItem *menuitem, gpointer user_data )
136 {
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;
142
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 ) );
146
147     if( gtk_dialog_run( GTK_DIALOG( dialog ) ) == GTK_RESPONSE_OK )
148     {
149         psz_filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( dialog ) );
150     }
151     else
152     {
153         gtk_widget_destroy( dialog );
154         return;
155     }
156
157     gtk_widget_destroy( dialog );
158
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 );
164 }
165
166 void open_address_cb( GtkMenuItem *menuitem, gpointer user_data )
167 {
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;
172
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 );
186
187     gtk_widget_show_all( dialog );
188     if( gtk_dialog_run( GTK_DIALOG( dialog ) ) == GTK_RESPONSE_CANCEL )
189     {
190         gtk_widget_destroy( dialog );
191         return;
192     }
193
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 );
201
202     gtk_widget_destroy( dialog );
203 }
204
205 void open_webcam_cb( GtkMenuItem *menuitem, gpointer user_data )
206 {
207     (void)menuitem;
208     intf_thread_t *p_intf = (intf_thread_t *)user_data;
209     input_item_t *p_input;
210
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 );
216 }
217
218 void snapshot_cb( GtkMenuItem *menuitem, gpointer user_data )
219 {
220     (void)menuitem;
221     intf_thread_t *p_intf = (intf_thread_t *)user_data;
222
223     if( !p_intf->p_sys->p_vout )
224     {
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;
230     }
231
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" );
236 }
237
238 void dropframe_cb( GtkMenuItem *menuitem, gpointer user_data )
239 {
240     intf_thread_t *p_intf = (intf_thread_t *)user_data;
241
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 );
246 }