]> git.sesse.net Git - vlc/blob - plugins/gtk/gtk_display.c
* ALL: the first libvlc commit.
[vlc] / plugins / gtk / gtk_display.c
1 /*****************************************************************************
2  * gtk_display.c: Gtk+ tools for main interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  * $Id: gtk_display.c,v 1.23 2002/06/01 12:31:59 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 #include "gtk_menu.h"
46 #include "gtk_display.h"
47 #include "gtk_common.h"
48
49 /*****************************************************************************
50  * GtkDisplayDate: display stream date
51  *****************************************************************************
52  * This function displays the current date related to the position in
53  * the stream. It is called whenever the slider changes its value.
54  * The lock has to be taken before you call the function.
55  *****************************************************************************/
56 void GtkDisplayDate( GtkAdjustment *p_adj )
57 {
58     intf_thread_t *p_intf;
59
60     p_intf = gtk_object_get_data( GTK_OBJECT( p_adj ), "p_intf" );
61
62     if( p_intf->p_sys->p_input )
63     {
64 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
65         char psz_time[ OFFSETTOTIME_MAX_SIZE ];
66
67         gtk_frame_set_label( GTK_FRAME( p_intf->p_sys->p_slider_frame ),
68                         input_OffsetToTime( p_intf->p_sys->p_input, psz_time,
69                                    ( p_area->i_size * p_adj->value ) / 100 ) );
70 #undef p_area
71      }
72 }
73
74
75 /*****************************************************************************
76  * GtkModeManage: actualise the aspect of the interface whenever the input
77  *                changes.
78  *****************************************************************************
79  * The lock has to be taken before you call the function.
80  *****************************************************************************/
81 gint GtkModeManage( intf_thread_t * p_intf )
82 {
83     GtkWidget *     p_dvd_box;
84     GtkWidget *     p_file_box;
85     GtkWidget *     p_network_box;
86     GtkWidget *     p_slider;
87     GtkWidget *     p_label;
88     GtkWidget *     p_channel;
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 //intf_WarnMsg( 2, "intf info: file method" );
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 //intf_WarnMsg( 2, "intf info: disc method" );
130                 gtk_widget_show( GTK_WIDGET( p_dvd_box ) );
131                 break;
132             case INPUT_METHOD_NETWORK:
133 //intf_WarnMsg( 2, "intf info: network method" );
134                 gtk_widget_show( GTK_WIDGET( p_network_box ) );
135                 p_label = gtk_object_get_data( GTK_OBJECT(
136                             p_intf->p_sys->p_window ),
137                             "network_address_label" );
138                 gtk_label_set_text( GTK_LABEL( p_label ),
139                                     p_intf->p_sys->p_input->psz_source );
140                 p_channel = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
141                            p_intf->p_sys->p_window ), "network_channel_box" ) );
142                 if( config_GetInt( p_intf, "network-channel" ) )
143                 {
144                     gtk_widget_show( GTK_WIDGET( p_channel ) );
145                 }
146                 else
147                 {
148                     gtk_widget_hide( GTK_WIDGET( p_channel ) );
149                 }
150
151                 break;
152             default:
153                 msg_Warn( p_intf, "cannot determine input method" );
154                 gtk_widget_show( GTK_WIDGET( p_file_box ) );
155                 p_label = gtk_object_get_data( GTK_OBJECT(
156                             p_intf->p_sys->p_window ),
157                             "label_status" );
158                 gtk_label_set_text( GTK_LABEL( p_label ),
159                                     p_intf->p_sys->p_input->psz_source );
160                 break;
161         }
162
163         /* initialize and show slider for seekable streams */
164         if( p_intf->p_sys->p_input->stream.b_seekable )
165         {
166             p_intf->p_sys->p_adj->value = p_intf->p_sys->f_adj_oldvalue = 0;
167             gtk_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
168                                      "value_changed" );
169             gtk_widget_show( GTK_WIDGET( p_slider ) );
170         }
171
172         /* control buttons for free pace streams */
173         b_control = p_intf->p_sys->p_input->stream.b_pace_control;
174
175         /* get ready for menu regeneration */
176         p_intf->p_sys->b_program_update = 1;
177         p_intf->p_sys->b_title_update = 1;
178         p_intf->p_sys->b_chapter_update = 1;
179         p_intf->p_sys->b_audio_update = 1;
180         p_intf->p_sys->b_spu_update = 1;
181         p_intf->p_sys->i_part = 0;
182     
183         p_intf->p_sys->p_input->stream.b_changed = 0;
184         msg_Dbg( p_intf, "stream has changed, refreshing interface" );
185     }
186     else
187     {
188         if( config_GetInt( p_intf, "network-channel" ) )
189         {
190             gtk_widget_show( GTK_WIDGET( p_network_box ) );
191
192             p_channel = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
193                        p_intf->p_sys->p_window ), "network_channel_box" ) );
194             gtk_widget_show( GTK_WIDGET( p_channel ) );
195         }
196         else
197         {
198 //intf_WarnMsg( 2, "intf info: default to file method" );
199             /* default mode */
200             p_label = gtk_object_get_data(
201                     GTK_OBJECT( p_intf->p_sys->p_window ), "label_status" );
202             gtk_label_set_text( GTK_LABEL( p_label ), "" );
203             gtk_widget_show( GTK_WIDGET( p_file_box ) );
204
205             /* unsensitize menus */
206             gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_program"),
207                     FALSE );
208             gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_title"), FALSE );
209             gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_chapter"),
210                                       FALSE );
211             gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_audio"), FALSE );
212             gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_subpictures"),
213                                       FALSE );
214             gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_navigation"),
215                                       FALSE );
216             gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_audio"), FALSE );
217             gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_subpictures"),
218                                       FALSE );
219         }
220     }
221
222     /* set control items */
223     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_back"), FALSE );
224     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_eject"), !b_control);
225     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_pause"), b_control );
226     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_slow"), b_control );
227     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_fast"), b_control );
228     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_back"), FALSE );
229     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_pause"), b_control );
230     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_slow"), b_control );
231     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_fast"), b_control );
232
233 #undef GETWIDGET
234     return TRUE;
235 }
236
237 /*****************************************************************************
238  * GtkHideTooltips: show or hide the tooltips depending on the configuration
239  *                  option gnome-tooltips
240  *****************************************************************************/
241 void GtkHideTooltips( vlc_object_t *p_this )
242 {
243     intf_thread_t *p_intf = vlc_object_find( p_this->p_vlc,
244                                              VLC_OBJECT_INTF, FIND_CHILD );
245
246     if( !p_intf )
247     {
248         return;
249     }
250
251     if( config_GetInt( p_this, "gnome-tooltips" ) )
252     {
253         gtk_tooltips_enable( p_intf->p_sys->p_tooltips );
254     }
255     else
256     {
257         gtk_tooltips_disable( p_intf->p_sys->p_tooltips );
258     }
259
260     vlc_object_release( p_intf );
261 }
262
263 #ifdef MODULE_NAME_IS_gnome
264 /*****************************************************************************
265  * GtkHideToolbartext: show or hide the tooltips depending on the
266  *                     configuration option gnome-toolbartext
267  *****************************************************************************
268  * FIXME: GNOME only because of missing icons in gtk interface
269  *****************************************************************************/
270 void GtkHideToolbarText( vlc_object_t *p_this )
271 {
272     GtkToolbarStyle style;
273     GtkToolbar * p_toolbar;
274
275     intf_thread_t *p_intf = vlc_object_find( p_this->p_vlc,
276                                              VLC_OBJECT_INTF, FIND_CHILD );
277
278     if( !p_intf )
279     {
280         return;
281     }
282
283     style = config_GetInt( p_this, "gnome-toolbartext" )
284             ? GTK_TOOLBAR_BOTH
285             : GTK_TOOLBAR_ICONS;
286
287     p_toolbar = GTK_TOOLBAR(lookup_widget( p_intf->p_sys->p_window,
288                                            "toolbar" ));
289     gtk_toolbar_set_style( p_toolbar, style );
290
291     vlc_object_release( p_intf );
292 }
293 #endif