display.c
上传用户:riyaled888
上传日期:2009-03-27
资源大小:7338k
文件大小:11k
源码类别:

多媒体

开发平台:

MultiPlatform

  1. /*****************************************************************************
  2.  * display.c: Gtk+ tools for main interface
  3.  *****************************************************************************
  4.  * Copyright (C) 1999, 2000, 2003 VideoLAN
  5.  * $Id: display.c 7945 2004-06-07 21:26:35Z fenrir $
  6.  *
  7.  * Authors: Samuel Hocevar <sam@zoy.org>
  8.  *          St閜hane Borel <stef@via.ecp.fr>
  9.  *
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2 of the License, or
  13.  * (at your option) any later version.
  14.  * 
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  23.  *****************************************************************************/
  24. /*****************************************************************************
  25.  * Preamble
  26.  *****************************************************************************/
  27. #include <errno.h>                                                 /* ENOMEM */
  28. #include <stdlib.h>                                                /* free() */
  29. #include <string.h>                                            /* strerror() */
  30. #include <stdio.h>
  31. #include <vlc/vlc.h>
  32. #include <vlc/intf.h>
  33. #ifdef MODULE_NAME_IS_gnome
  34. #   include <gnome.h>
  35. #else
  36. #   include <gtk/gtk.h>
  37. #endif
  38. #include "gtk_callbacks.h"
  39. #include "gtk_interface.h"
  40. #include "gtk_support.h"
  41. #include "menu.h"
  42. #include "display.h"
  43. #include "common.h"
  44. /*****************************************************************************
  45.  * GtkDisplayDate: display stream date
  46.  *****************************************************************************
  47.  * This function displays the current date related to the position in
  48.  * the stream. It is called whenever the slider changes its value.
  49.  * The lock has to be taken before you call the function.
  50.  *****************************************************************************/
  51. void E_(GtkDisplayDate)( GtkAdjustment *p_adj )
  52. {
  53.     intf_thread_t *p_intf;
  54.     p_intf = gtk_object_get_data( GTK_OBJECT( p_adj ), "p_intf" );
  55.     if( p_intf->p_sys->p_input )
  56.     {
  57.         char psz_time[ MSTRTIME_MAX_SIZE ];
  58.         int64_t i_seconds;
  59.         i_seconds = var_GetTime( p_intf->p_sys->p_input, "time" ) / I64C(1000000 );
  60.         secstotimestr( psz_time, i_seconds );
  61.         gtk_frame_set_label( GTK_FRAME( p_intf->p_sys->p_slider_frame ),
  62.                              psz_time );
  63.      }
  64. }
  65. /*****************************************************************************
  66.  * GtkModeManage: actualize the aspect of the interface whenever the input
  67.  *                changes.
  68.  *****************************************************************************
  69.  * The lock has to be taken before you call the function.
  70.  *****************************************************************************/
  71. gint E_(GtkModeManage)( intf_thread_t * p_intf )
  72. {
  73.     GtkWidget *     p_dvd_box;
  74.     GtkWidget *     p_file_box;
  75.     GtkWidget *     p_network_box;
  76.     GtkWidget *     p_slider;
  77.     GtkWidget *     p_label;
  78.     vlc_bool_t      b_control;
  79. #define GETWIDGET( ptr, name ) GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( 
  80.                            p_intf->p_sys->ptr ) , ( name ) ) )
  81.     /* hide all boxes except default file box */
  82.     p_file_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
  83.                  p_intf->p_sys->p_window ), "file_box" ) );
  84.     gtk_widget_hide( GTK_WIDGET( p_file_box ) );
  85.     p_network_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
  86.                  p_intf->p_sys->p_window ), "network_box" ) );
  87.     gtk_widget_hide( GTK_WIDGET( p_network_box ) );
  88.     p_dvd_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
  89.                  p_intf->p_sys->p_window ), "dvd_box" ) );
  90.     gtk_widget_hide( GTK_WIDGET( p_dvd_box ) );
  91.     /* hide slider */
  92.     p_slider = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
  93.                            p_intf->p_sys->p_window ), "slider_frame" ) );
  94.     gtk_widget_hide( GTK_WIDGET( p_slider ) );
  95.     /* controls unavailable */
  96.     b_control = 0;
  97.     /* show the box related to current input mode */
  98.     if( p_intf->p_sys->p_input )
  99.     {
  100.         switch( p_intf->p_sys->p_input->stream.i_method & 0xf0 )
  101.         {
  102.             case INPUT_METHOD_FILE:
  103.                 gtk_widget_show( GTK_WIDGET( p_file_box ) );
  104.                 p_label = gtk_object_get_data( GTK_OBJECT(
  105.                             p_intf->p_sys->p_window ),
  106.                             "label_status" );
  107.                 gtk_label_set_text( GTK_LABEL( p_label ),
  108.                                     p_intf->p_sys->p_input->psz_source );
  109.                 break;
  110.             case INPUT_METHOD_DISC:
  111.                 gtk_widget_show( GTK_WIDGET( p_dvd_box ) );
  112.                 break;
  113.             case INPUT_METHOD_NETWORK:
  114.                 gtk_widget_show( GTK_WIDGET( p_network_box ) );
  115.                 p_label = gtk_object_get_data( GTK_OBJECT(
  116.                             p_intf->p_sys->p_window ),
  117.                             "network_address_label" );
  118.                 gtk_label_set_text( GTK_LABEL( p_label ),
  119.                                     p_intf->p_sys->p_input->psz_source );
  120.                 break;
  121.             default:
  122.                 msg_Warn( p_intf, "cannot determine input method" );
  123.                 gtk_widget_show( GTK_WIDGET( p_file_box ) );
  124.                 p_label = gtk_object_get_data( GTK_OBJECT(
  125.                             p_intf->p_sys->p_window ),
  126.                             "label_status" );
  127.                 gtk_label_set_text( GTK_LABEL( p_label ),
  128.                                     p_intf->p_sys->p_input->psz_source );
  129.                 break;
  130.         }
  131.         /* initialize and show slider for seekable streams */
  132.         if( p_intf->p_sys->p_input->stream.b_seekable )
  133.         {
  134.             p_intf->p_sys->p_adj->value = p_intf->p_sys->f_adj_oldvalue = 0;
  135.             gtk_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
  136.                                      "value_changed" );
  137.             gtk_widget_show( GTK_WIDGET( p_slider ) );
  138.         }
  139.         /* control buttons for free pace streams */
  140.         b_control = p_intf->p_sys->p_input->stream.b_pace_control;
  141.         /* get ready for menu regeneration */
  142.         p_intf->p_sys->b_program_update = 1;
  143.         p_intf->p_sys->b_title_update = 1;
  144.         p_intf->p_sys->b_chapter_update = 1;
  145.         p_intf->p_sys->b_audio_update = 1;
  146.         p_intf->p_sys->b_spu_update = 1;
  147.         p_intf->p_sys->i_part = 0;
  148. #if 0
  149.         p_intf->p_sys->b_aout_update = 1;
  150.         p_intf->p_sys->b_vout_update = 1;
  151. #endif
  152.         p_intf->p_sys->p_input->stream.b_changed = 0;
  153.         msg_Dbg( p_intf, "stream has changed, refreshing interface" );
  154.     }
  155.     else
  156.     {
  157.         /* default mode */
  158.         p_label = gtk_object_get_data(
  159.                   GTK_OBJECT( p_intf->p_sys->p_window ), "label_status" );
  160.         gtk_label_set_text( GTK_LABEL( p_label ), "" );
  161.         gtk_widget_show( GTK_WIDGET( p_file_box ) );
  162.         /* unsensitize menus */
  163.         gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_program"),
  164.                                   FALSE );
  165.         gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_title"), FALSE );
  166.         gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_chapter"),
  167.                                   FALSE );
  168.         gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_audio"), FALSE );
  169.         gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_subpictures"),
  170.                                   FALSE );
  171.         gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_navigation"),
  172.                                   FALSE );
  173.         gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_language"), FALSE );
  174.         gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_subpictures"),
  175.                                   FALSE );
  176.     }
  177.     /* set control items */
  178.     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_back"), FALSE );
  179.     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_eject"), !b_control);
  180.     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_pause"), b_control );
  181.     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_slow"), b_control );
  182.     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_fast"), b_control );
  183.     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_back"), FALSE );
  184.     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_pause"), b_control );
  185.     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_slow"), b_control );
  186.     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_fast"), b_control );
  187. #undef GETWIDGET
  188.     return TRUE;
  189. }
  190. /*****************************************************************************
  191.  * GtkHideTooltips: show or hide the tooltips depending on the configuration
  192.  *                  option gnome-tooltips
  193.  *****************************************************************************/
  194. int E_(GtkHideTooltips)( vlc_object_t *p_this, const char *psz_name,
  195.                          vlc_value_t oldval, vlc_value_t val, void *p_data )
  196. {
  197.     intf_thread_t *p_intf;
  198.     int i_index;
  199.     vlc_list_t *p_list = vlc_list_find( p_this, VLC_OBJECT_INTF,
  200.                                         FIND_ANYWHERE );
  201.     vlc_bool_t b_enable = config_GetInt( p_this, "gnome-tooltips" );
  202.     for( i_index = 0; i_index < p_list->i_count; i_index++ )
  203.     {
  204.         p_intf = (intf_thread_t *)p_list->p_values[i_index].p_object ;
  205.         if( strcmp( MODULE_STRING, p_intf->p_module->psz_object_name ) )
  206.         {
  207.             continue;
  208.         }
  209.         if( b_enable )
  210.         {
  211.             gtk_tooltips_enable( p_intf->p_sys->p_tooltips );
  212.         }
  213.         else
  214.         {
  215.             gtk_tooltips_disable( p_intf->p_sys->p_tooltips );
  216.         }
  217.     }
  218.     vlc_list_release( p_list );
  219.     return VLC_SUCCESS;
  220. }
  221. #ifdef MODULE_NAME_IS_gnome
  222. /*****************************************************************************
  223.  * GtkHideToolbartext: show or hide the tooltips depending on the
  224.  *                     configuration option gnome-toolbartext
  225.  *****************************************************************************
  226.  * FIXME: GNOME only because of missing icons in gtk interface
  227.  *****************************************************************************/
  228. int GtkHideToolbarText( vlc_object_t *p_this, const char *psz_name,
  229.                         vlc_value_t oldval, vlc_value_t val, void *p_data )
  230. {
  231.     GtkToolbarStyle style;
  232.     GtkToolbar * p_toolbar;
  233.     intf_thread_t *p_intf;
  234.     int i_index;
  235.     vlc_list_t *p_list = vlc_list_find( p_this, VLC_OBJECT_INTF,
  236.                                         FIND_ANYWHERE );
  237.     style = config_GetInt( p_this, "gnome-toolbartext" )
  238.             ? GTK_TOOLBAR_BOTH
  239.             : GTK_TOOLBAR_ICONS;
  240.     for( i_index = 0; i_index < p_list->i_count; i_index++ )
  241.     {
  242.         p_intf = (intf_thread_t *)p_list->p_values[i_index].p_object ;
  243.         if( strcmp( MODULE_STRING, p_intf->p_module->psz_object_name ) )
  244.         {
  245.             continue;
  246.         }
  247.         p_toolbar = GTK_TOOLBAR(lookup_widget( p_intf->p_sys->p_window,
  248.                                                "toolbar" ));
  249.         gtk_toolbar_set_style( p_toolbar, style );
  250.     }
  251.     vlc_list_release( p_list );
  252.     return VLC_SUCCESS;
  253. }
  254. #endif