* src/misc/configuration.c, include/configuration.h, src/audio_output/intf.c, include...
[vlc.git] / modules / gui / gtk / display.c
1 /*****************************************************************************
2  * display.c: Gtk+ tools for main interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  * $Id: display.c,v 1.11 2003/08/03 23:11:21 gbazin Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *          St├ęphane 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 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <stdlib.h>                                                /* free() */
30 #include <string.h>                                            /* strerror() */
31 #include <stdio.h>
32
33 #include <vlc/vlc.h>
34 #include <vlc/intf.h>
35
36 #ifdef MODULE_NAME_IS_gnome
37 #   include <gnome.h>
38 #else
39 #   include <gtk/gtk.h>
40 #endif
41
42 #include "gtk_callbacks.h"
43 #include "gtk_interface.h"
44 #include "gtk_support.h"
45
46 #include "menu.h"
47 #include "display.h"
48 #include "common.h"
49
50 /*****************************************************************************
51  * GtkDisplayDate: display stream date
52  *****************************************************************************
53  * This function displays the current date related to the position in
54  * the stream. It is called whenever the slider changes its value.
55  * The lock has to be taken before you call the function.
56  *****************************************************************************/
57 void E_(GtkDisplayDate)( GtkAdjustment *p_adj )
58 {
59     intf_thread_t *p_intf;
60
61     p_intf = gtk_object_get_data( GTK_OBJECT( p_adj ), "p_intf" );
62
63     if( p_intf->p_sys->p_input )
64     {
65 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
66         char psz_time[ OFFSETTOTIME_MAX_SIZE ];
67
68         gtk_frame_set_label( GTK_FRAME( p_intf->p_sys->p_slider_frame ),
69                         input_OffsetToTime( p_intf->p_sys->p_input, psz_time,
70                                    ( p_area->i_size * p_adj->value ) / 100 ) );
71 #undef p_area
72      }
73 }
74
75
76 /*****************************************************************************
77  * GtkModeManage: actualize the aspect of the interface whenever the input
78  *                changes.
79  *****************************************************************************
80  * The lock has to be taken before you call the function.
81  *****************************************************************************/
82 gint E_(GtkModeManage)( intf_thread_t * p_intf )
83 {
84     GtkWidget *     p_dvd_box;
85     GtkWidget *     p_file_box;
86     GtkWidget *     p_network_box;
87     GtkWidget *     p_slider;
88     GtkWidget *     p_label;
89     vlc_bool_t      b_control;
90
91 #define GETWIDGET( ptr, name ) GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( \
92                            p_intf->p_sys->ptr ) , ( name ) ) )
93     /* hide all boxes except default file box */
94     p_file_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
95                  p_intf->p_sys->p_window ), "file_box" ) );
96     gtk_widget_hide( GTK_WIDGET( p_file_box ) );
97
98     p_network_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
99                  p_intf->p_sys->p_window ), "network_box" ) );
100     gtk_widget_hide( GTK_WIDGET( p_network_box ) );
101
102     p_dvd_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
103                  p_intf->p_sys->p_window ), "dvd_box" ) );
104     gtk_widget_hide( GTK_WIDGET( p_dvd_box ) );
105
106     /* hide slider */
107     p_slider = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
108                            p_intf->p_sys->p_window ), "slider_frame" ) );
109     gtk_widget_hide( GTK_WIDGET( p_slider ) );
110
111     /* controls unavailable */
112     b_control = 0;
113
114     /* show the box related to current input mode */
115     if( p_intf->p_sys->p_input )
116     {
117         switch( p_intf->p_sys->p_input->stream.i_method & 0xf0 )
118         {
119             case INPUT_METHOD_FILE:
120                 gtk_widget_show( GTK_WIDGET( p_file_box ) );
121                 p_label = gtk_object_get_data( GTK_OBJECT(
122                             p_intf->p_sys->p_window ),
123                             "label_status" );
124                 gtk_label_set_text( GTK_LABEL( p_label ),
125                                     p_intf->p_sys->p_input->psz_source );
126                 break;
127             case INPUT_METHOD_DISC:
128                 gtk_widget_show( GTK_WIDGET( p_dvd_box ) );
129                 break;
130             case INPUT_METHOD_NETWORK:
131                 gtk_widget_show( GTK_WIDGET( p_network_box ) );
132                 p_label = gtk_object_get_data( GTK_OBJECT(
133                             p_intf->p_sys->p_window ),
134                             "network_address_label" );
135                 gtk_label_set_text( GTK_LABEL( p_label ),
136                                     p_intf->p_sys->p_input->psz_source );
137                 break;
138             default:
139                 msg_Warn( p_intf, "cannot determine input method" );
140                 gtk_widget_show( GTK_WIDGET( p_file_box ) );
141                 p_label = gtk_object_get_data( GTK_OBJECT(
142                             p_intf->p_sys->p_window ),
143                             "label_status" );
144                 gtk_label_set_text( GTK_LABEL( p_label ),
145                                     p_intf->p_sys->p_input->psz_source );
146                 break;
147         }
148
149         /* initialize and show slider for seekable streams */
150         if( p_intf->p_sys->p_input->stream.b_seekable )
151         {
152             p_intf->p_sys->p_adj->value = p_intf->p_sys->f_adj_oldvalue = 0;
153             gtk_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
154                                      "value_changed" );
155             gtk_widget_show( GTK_WIDGET( p_slider ) );
156         }
157
158         /* control buttons for free pace streams */
159         b_control = p_intf->p_sys->p_input->stream.b_pace_control;
160
161         /* get ready for menu regeneration */
162         p_intf->p_sys->b_program_update = 1;
163         p_intf->p_sys->b_title_update = 1;
164         p_intf->p_sys->b_chapter_update = 1;
165         p_intf->p_sys->b_audio_update = 1;
166         p_intf->p_sys->b_spu_update = 1;
167         p_intf->p_sys->i_part = 0;
168 #if 0
169         p_intf->p_sys->b_aout_update = 1;
170         p_intf->p_sys->b_vout_update = 1;
171 #endif
172         p_intf->p_sys->p_input->stream.b_changed = 0;
173         msg_Dbg( p_intf, "stream has changed, refreshing interface" );
174     }
175     else
176     {
177         /* default mode */
178         p_label = gtk_object_get_data(
179                   GTK_OBJECT( p_intf->p_sys->p_window ), "label_status" );
180         gtk_label_set_text( GTK_LABEL( p_label ), "" );
181         gtk_widget_show( GTK_WIDGET( p_file_box ) );
182
183         /* unsensitize menus */
184         gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_program"),
185                                   FALSE );
186         gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_title"), FALSE );
187         gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_chapter"),
188                                   FALSE );
189         gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_audio"), FALSE );
190         gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_subpictures"),
191                                   FALSE );
192         gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_navigation"),
193                                   FALSE );
194         gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_language"), FALSE );
195         gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_subpictures"),
196                                   FALSE );
197     }
198
199     /* set control items */
200     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_back"), FALSE );
201     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_eject"), !b_control);
202     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_pause"), b_control );
203     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_slow"), b_control );
204     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_fast"), b_control );
205     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_back"), FALSE );
206     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_pause"), b_control );
207     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_slow"), b_control );
208     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_fast"), b_control );
209
210 #undef GETWIDGET
211     return TRUE;
212 }
213
214 /*****************************************************************************
215  * GtkHideTooltips: show or hide the tooltips depending on the configuration
216  *                  option gnome-tooltips
217  *****************************************************************************/
218 int E_(GtkHideTooltips)( vlc_object_t *p_this, const char *psz_name,
219                          vlc_value_t oldval, vlc_value_t val, void *p_data )
220 {
221     intf_thread_t *p_intf;
222     int i_index;
223     vlc_list_t *p_list = vlc_list_find( p_this, VLC_OBJECT_INTF,
224                                         FIND_ANYWHERE );
225
226     vlc_bool_t b_enable = config_GetInt( p_this, "gnome-tooltips" );
227
228     for( i_index = 0; i_index < p_list->i_count; i_index++ )
229     {
230         p_intf = (intf_thread_t *)p_list->p_values[i_index].p_object ;
231
232         if( strcmp( MODULE_STRING, p_intf->p_module->psz_object_name ) )
233         {
234             continue;
235         }
236
237         if( b_enable )
238         {
239             gtk_tooltips_enable( p_intf->p_sys->p_tooltips );
240         }
241         else
242         {
243             gtk_tooltips_disable( p_intf->p_sys->p_tooltips );
244         }
245     }
246
247     vlc_list_release( p_list );
248     return VLC_SUCCESS;
249 }
250
251 #ifdef MODULE_NAME_IS_gnome
252 /*****************************************************************************
253  * GtkHideToolbartext: show or hide the tooltips depending on the
254  *                     configuration option gnome-toolbartext
255  *****************************************************************************
256  * FIXME: GNOME only because of missing icons in gtk interface
257  *****************************************************************************/
258 int GtkHideToolbarText( vlc_object_t *p_this, const char *psz_name,
259                         vlc_value_t oldval, vlc_value_t val, void *p_data )
260 {
261     GtkToolbarStyle style;
262     GtkToolbar * p_toolbar;
263     intf_thread_t *p_intf;
264     int i_index;
265     vlc_list_t *p_list = vlc_list_find( p_this, VLC_OBJECT_INTF,
266                                         FIND_ANYWHERE );
267
268     style = config_GetInt( p_this, "gnome-toolbartext" )
269             ? GTK_TOOLBAR_BOTH
270             : GTK_TOOLBAR_ICONS;
271
272     for( i_index = 0; i_index < p_list->i_count; i_index++ )
273     {
274         p_intf = (intf_thread_t *)p_list->p_values[i_index].p_object ;
275
276         if( strcmp( MODULE_STRING, p_intf->p_module->psz_object_name ) )
277         {
278             continue;
279         }
280
281         p_toolbar = GTK_TOOLBAR(lookup_widget( p_intf->p_sys->p_window,
282                                                "toolbar" ));
283         gtk_toolbar_set_style( p_toolbar, style );
284     }
285
286     vlc_list_release( p_list );
287     return VLC_SUCCESS;
288 }
289 #endif