]> git.sesse.net Git - vlc/blob - modules/gui/gtk/display.c
bf52c248c428cbb05602c80c32a03bee9b1e7910
[vlc] / 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.5 2002/12/13 01:56:29 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     GtkWidget *     p_channel;
90     vlc_bool_t      b_control;
91
92 #define GETWIDGET( ptr, name ) GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( \
93                            p_intf->p_sys->ptr ) , ( name ) ) )
94     /* hide all boxes except default file box */
95     p_file_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
96                  p_intf->p_sys->p_window ), "file_box" ) );
97     gtk_widget_hide( GTK_WIDGET( p_file_box ) );
98
99     p_network_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
100                  p_intf->p_sys->p_window ), "network_box" ) );
101     gtk_widget_hide( GTK_WIDGET( p_network_box ) );
102
103     p_dvd_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
104                  p_intf->p_sys->p_window ), "dvd_box" ) );
105     gtk_widget_hide( GTK_WIDGET( p_dvd_box ) );
106
107     /* hide slider */
108     p_slider = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
109                            p_intf->p_sys->p_window ), "slider_frame" ) );
110     gtk_widget_hide( GTK_WIDGET( p_slider ) );
111
112     /* controls unavailable */
113     b_control = 0;
114
115     /* show the box related to current input mode */
116     if( p_intf->p_sys->p_input )
117     {
118         switch( p_intf->p_sys->p_input->stream.i_method & 0xf0 )
119         {
120             case INPUT_METHOD_FILE:
121                 gtk_widget_show( GTK_WIDGET( p_file_box ) );
122                 p_label = gtk_object_get_data( GTK_OBJECT(
123                             p_intf->p_sys->p_window ),
124                             "label_status" );
125                 gtk_label_set_text( GTK_LABEL( p_label ),
126                                     p_intf->p_sys->p_input->psz_source );
127                 break;
128             case INPUT_METHOD_DISC:
129                 gtk_widget_show( GTK_WIDGET( p_dvd_box ) );
130                 break;
131             case INPUT_METHOD_NETWORK:
132                 gtk_widget_show( GTK_WIDGET( p_network_box ) );
133                 p_label = gtk_object_get_data( GTK_OBJECT(
134                             p_intf->p_sys->p_window ),
135                             "network_address_label" );
136                 gtk_label_set_text( GTK_LABEL( p_label ),
137                                     p_intf->p_sys->p_input->psz_source );
138                 p_channel = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
139                            p_intf->p_sys->p_window ), "network_channel_box" ) );
140                 if( config_GetInt( p_intf, "network-channel" ) )
141                 {
142                     gtk_widget_show( GTK_WIDGET( p_channel ) );
143                 }
144                 else
145                 {
146                     gtk_widget_hide( GTK_WIDGET( p_channel ) );
147                 }
148
149                 break;
150             default:
151                 msg_Warn( p_intf, "cannot determine input method" );
152                 gtk_widget_show( GTK_WIDGET( p_file_box ) );
153                 p_label = gtk_object_get_data( GTK_OBJECT(
154                             p_intf->p_sys->p_window ),
155                             "label_status" );
156                 gtk_label_set_text( GTK_LABEL( p_label ),
157                                     p_intf->p_sys->p_input->psz_source );
158                 break;
159         }
160
161         /* initialize and show slider for seekable streams */
162         if( p_intf->p_sys->p_input->stream.b_seekable )
163         {
164             p_intf->p_sys->p_adj->value = p_intf->p_sys->f_adj_oldvalue = 0;
165             gtk_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
166                                      "value_changed" );
167             gtk_widget_show( GTK_WIDGET( p_slider ) );
168         }
169
170         /* control buttons for free pace streams */
171         b_control = p_intf->p_sys->p_input->stream.b_pace_control;
172
173         /* get ready for menu regeneration */
174         p_intf->p_sys->b_program_update = 1;
175         p_intf->p_sys->b_title_update = 1;
176         p_intf->p_sys->b_chapter_update = 1;
177         p_intf->p_sys->b_audio_update = 1;
178         p_intf->p_sys->b_spu_update = 1;
179         p_intf->p_sys->i_part = 0;
180     
181         p_intf->p_sys->p_input->stream.b_changed = 0;
182         msg_Dbg( p_intf, "stream has changed, refreshing interface" );
183     }
184     else
185     {
186         if( config_GetInt( p_intf, "network-channel" ) )
187         {
188             gtk_widget_show( GTK_WIDGET( p_network_box ) );
189
190             p_channel = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
191                        p_intf->p_sys->p_window ), "network_channel_box" ) );
192             gtk_widget_show( GTK_WIDGET( p_channel ) );
193         }
194         else
195         {
196             /* default mode */
197             p_label = gtk_object_get_data(
198                     GTK_OBJECT( p_intf->p_sys->p_window ), "label_status" );
199             gtk_label_set_text( GTK_LABEL( p_label ), "" );
200             gtk_widget_show( GTK_WIDGET( p_file_box ) );
201         }
202
203         /* unsensitize menus */
204         gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_program"),
205                                   FALSE );
206         gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_title"), FALSE );
207         gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_chapter"),
208                                   FALSE );
209         gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_audio"), FALSE );
210         gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_subpictures"),
211                                   FALSE );
212         gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_navigation"),
213                                   FALSE );
214         gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_audio"), FALSE );
215         gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_subpictures"),
216                                   FALSE );
217     }
218
219     /* set control items */
220     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_back"), FALSE );
221     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_eject"), !b_control);
222     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_pause"), b_control );
223     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_slow"), b_control );
224     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_fast"), b_control );
225     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_back"), FALSE );
226     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_pause"), b_control );
227     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_slow"), b_control );
228     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_fast"), b_control );
229
230 #undef GETWIDGET
231     return TRUE;
232 }
233
234 /*****************************************************************************
235  * GtkHideTooltips: show or hide the tooltips depending on the configuration
236  *                  option gnome-tooltips
237  *****************************************************************************/
238 void E_(GtkHideTooltips)( vlc_object_t *p_this )
239 {
240     intf_thread_t *p_intf;
241     int i_index;
242     vlc_list_t list = vlc_list_find( p_this, VLC_OBJECT_INTF,
243                                              FIND_ANYWHERE );
244
245     vlc_bool_t b_enable = config_GetInt( p_this, "gnome-tooltips" );
246
247     for( i_index = 0; i_index < list.i_count; i_index++ )
248     {
249         p_intf = (intf_thread_t *)list.p_values[i_index].p_object ;
250
251         if( strcmp( MODULE_STRING, p_intf->p_module->psz_object_name ) )
252         {
253             continue;
254         }
255
256         if( b_enable )
257         {
258             gtk_tooltips_enable( p_intf->p_sys->p_tooltips );
259         }
260         else
261         {
262             gtk_tooltips_disable( p_intf->p_sys->p_tooltips );
263         }
264     }
265
266     vlc_list_release( &list );
267 }
268
269 #ifdef MODULE_NAME_IS_gnome
270 /*****************************************************************************
271  * GtkHideToolbartext: show or hide the tooltips depending on the
272  *                     configuration option gnome-toolbartext
273  *****************************************************************************
274  * FIXME: GNOME only because of missing icons in gtk interface
275  *****************************************************************************/
276 void GtkHideToolbarText( vlc_object_t *p_this )
277 {
278     GtkToolbarStyle style;
279     GtkToolbar * p_toolbar;
280     intf_thread_t *p_intf;
281     int i_index;
282     vlc_list_t list = vlc_list_find( p_this, VLC_OBJECT_INTF,
283                                              FIND_ANYWHERE );
284
285     style = config_GetInt( p_this, "gnome-toolbartext" )
286             ? GTK_TOOLBAR_BOTH
287             : GTK_TOOLBAR_ICONS;
288
289     for( i_index = 0; i_index < list.i_count; i_index++ )
290     {
291         p_intf = (module_t *)list.p_values[i_index].p_object ;
292
293         if( strcmp( MODULE_STRING, p_intf->p_module->psz_object_name ) )
294         {
295             continue;
296         }
297
298         p_toolbar = GTK_TOOLBAR(lookup_widget( p_intf->p_sys->p_window,
299                                                "toolbar" ));
300         gtk_toolbar_set_style( p_toolbar, style );
301     }
302
303     vlc_list_release( &list );
304 }
305 #endif