maemo_callbacks.c
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:8k
源码类别:

midi

开发平台:

Unix_Linux

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