]> git.sesse.net Git - vlc/blob - modules/gui/gtk/display.c
* ./modules/*: moved plugins to the new tree. Yet untested builds include
[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.1 2002/08/04 17:23:43 sam 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 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: actualise 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 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 //intf_WarnMsg( 2, "intf info: file method" );
122                 gtk_widget_show( GTK_WIDGET( p_file_box ) );
123                 p_label = gtk_object_get_data( GTK_OBJECT(
124                             p_intf->p_sys->p_window ),
125                             "label_status" );
126                 gtk_label_set_text( GTK_LABEL( p_label ),
127                                     p_intf->p_sys->p_input->psz_source );
128                 break;
129             case INPUT_METHOD_DISC:
130 //intf_WarnMsg( 2, "intf info: disc method" );
131                 gtk_widget_show( GTK_WIDGET( p_dvd_box ) );
132                 break;
133             case INPUT_METHOD_NETWORK:
134 //intf_WarnMsg( 2, "intf info: network method" );
135                 gtk_widget_show( GTK_WIDGET( p_network_box ) );
136                 p_label = gtk_object_get_data( GTK_OBJECT(
137                             p_intf->p_sys->p_window ),
138                             "network_address_label" );
139                 gtk_label_set_text( GTK_LABEL( p_label ),
140                                     p_intf->p_sys->p_input->psz_source );
141                 p_channel = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
142                            p_intf->p_sys->p_window ), "network_channel_box" ) );
143                 if( config_GetInt( p_intf, "network-channel" ) )
144                 {
145                     gtk_widget_show( GTK_WIDGET( p_channel ) );
146                 }
147                 else
148                 {
149                     gtk_widget_hide( GTK_WIDGET( p_channel ) );
150                 }
151
152                 break;
153             default:
154                 msg_Warn( p_intf, "cannot determine input method" );
155                 gtk_widget_show( GTK_WIDGET( p_file_box ) );
156                 p_label = gtk_object_get_data( GTK_OBJECT(
157                             p_intf->p_sys->p_window ),
158                             "label_status" );
159                 gtk_label_set_text( GTK_LABEL( p_label ),
160                                     p_intf->p_sys->p_input->psz_source );
161                 break;
162         }
163
164         /* initialize and show slider for seekable streams */
165         if( p_intf->p_sys->p_input->stream.b_seekable )
166         {
167             p_intf->p_sys->p_adj->value = p_intf->p_sys->f_adj_oldvalue = 0;
168             gtk_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
169                                      "value_changed" );
170             gtk_widget_show( GTK_WIDGET( p_slider ) );
171         }
172
173         /* control buttons for free pace streams */
174         b_control = p_intf->p_sys->p_input->stream.b_pace_control;
175
176         /* get ready for menu regeneration */
177         p_intf->p_sys->b_program_update = 1;
178         p_intf->p_sys->b_title_update = 1;
179         p_intf->p_sys->b_chapter_update = 1;
180         p_intf->p_sys->b_audio_update = 1;
181         p_intf->p_sys->b_spu_update = 1;
182         p_intf->p_sys->i_part = 0;
183     
184         p_intf->p_sys->p_input->stream.b_changed = 0;
185         msg_Dbg( p_intf, "stream has changed, refreshing interface" );
186     }
187     else
188     {
189         if( config_GetInt( p_intf, "network-channel" ) )
190         {
191             gtk_widget_show( GTK_WIDGET( p_network_box ) );
192
193             p_channel = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
194                        p_intf->p_sys->p_window ), "network_channel_box" ) );
195             gtk_widget_show( GTK_WIDGET( p_channel ) );
196         }
197         else
198         {
199 //intf_WarnMsg( 2, "intf info: default to file method" );
200             /* default mode */
201             p_label = gtk_object_get_data(
202                     GTK_OBJECT( p_intf->p_sys->p_window ), "label_status" );
203             gtk_label_set_text( GTK_LABEL( p_label ), "" );
204             gtk_widget_show( GTK_WIDGET( p_file_box ) );
205         }
206
207         /* unsensitize menus */
208         gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_program"),
209                                   FALSE );
210         gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_title"), FALSE );
211         gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_chapter"),
212                                   FALSE );
213         gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_audio"), FALSE );
214         gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_subpictures"),
215                                   FALSE );
216         gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_navigation"),
217                                   FALSE );
218         gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_audio"), FALSE );
219         gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_subpictures"),
220                                   FALSE );
221     }
222
223     /* set control items */
224     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_back"), FALSE );
225     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_eject"), !b_control);
226     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_pause"), b_control );
227     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_slow"), b_control );
228     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_fast"), b_control );
229     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_back"), FALSE );
230     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_pause"), b_control );
231     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_slow"), b_control );
232     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_fast"), b_control );
233
234 #undef GETWIDGET
235     return TRUE;
236 }
237
238 /*****************************************************************************
239  * GtkHideTooltips: show or hide the tooltips depending on the configuration
240  *                  option gnome-tooltips
241  *****************************************************************************/
242 void GtkHideTooltips( vlc_object_t *p_this )
243 {
244     intf_thread_t *p_intf = vlc_object_find( p_this, VLC_OBJECT_INTF,
245                                                      FIND_ANYWHERE );
246
247     if( !p_intf )
248     {
249         return;
250     }
251
252     if( config_GetInt( p_this, "gnome-tooltips" ) )
253     {
254         gtk_tooltips_enable( p_intf->p_sys->p_tooltips );
255     }
256     else
257     {
258         gtk_tooltips_disable( p_intf->p_sys->p_tooltips );
259     }
260
261     vlc_object_release( p_intf );
262 }
263
264 #ifdef MODULE_NAME_IS_gnome
265 /*****************************************************************************
266  * GtkHideToolbartext: show or hide the tooltips depending on the
267  *                     configuration option gnome-toolbartext
268  *****************************************************************************
269  * FIXME: GNOME only because of missing icons in gtk interface
270  *****************************************************************************/
271 void GtkHideToolbarText( vlc_object_t *p_this )
272 {
273     GtkToolbarStyle style;
274     GtkToolbar * p_toolbar;
275
276     intf_thread_t *p_intf = vlc_object_find( p_this, VLC_OBJECT_INTF,
277                                                      FIND_ANYWHERE );
278
279     if( !p_intf )
280     {
281         return;
282     }
283
284     style = config_GetInt( p_this, "gnome-toolbartext" )
285             ? GTK_TOOLBAR_BOTH
286             : GTK_TOOLBAR_ICONS;
287
288     p_toolbar = GTK_TOOLBAR(lookup_widget( p_intf->p_sys->p_window,
289                                            "toolbar" ));
290     gtk_toolbar_set_style( p_toolbar, style );
291
292     vlc_object_release( p_intf );
293 }
294 #endif