]> git.sesse.net Git - vlc/blob - plugins/gtk/gtk_display.c
* ./include/modules_inner.h: replaced _X with __VLC_SYMBOL because _X was
[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.12 2002/01/09 02:01:14 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 <videolan/vlc.h>
34
35 #ifdef MODULE_NAME_IS_gnome
36 #   include <gnome.h>
37 #else
38 #   include <gtk/gtk.h>
39 #endif
40
41 #include "stream_control.h"
42 #include "input_ext-intf.h"
43
44 #include "interface.h"
45 #include "intf_playlist.h"
46
47 #include "video.h"
48 #include "video_output.h"
49
50 #include "gtk_callbacks.h"
51 #include "gtk_interface.h"
52 #include "gtk_support.h"
53 #include "gtk_menu.h"
54 #include "gtk_display.h"
55 #include "gtk_common.h"
56
57 /*****************************************************************************
58  * GtkDisplayDate: display stream date
59  *****************************************************************************
60  * This function displays the current date related to the position in
61  * the stream. It is called whenever the slider changes its value.
62  * The lock has to be taken before you call the function.
63  *****************************************************************************/
64 void GtkDisplayDate( GtkAdjustment *p_adj )
65 {
66     intf_thread_t *p_intf;
67    
68     p_intf = gtk_object_get_data( GTK_OBJECT( p_adj ), "p_intf" );
69
70     if( p_input_bank->pp_input[0] != NULL )
71     {
72 #define p_area p_input_bank->pp_input[0]->stream.p_selected_area
73         char psz_time[ OFFSETTOTIME_MAX_SIZE ];
74
75         gtk_frame_set_label( GTK_FRAME( p_intf->p_sys->p_slider_frame ),
76                             input_OffsetToTime( p_input_bank->pp_input[0], psz_time,
77                                    ( p_area->i_size * p_adj->value ) / 100 ) );
78 #undef p_area
79      }
80 }
81
82
83 /*****************************************************************************
84  * GtkModeManage: actualise the aspect of the interface whenever the input
85  *                changes.
86  *****************************************************************************
87  * The lock has to be taken before you call the function.
88  *****************************************************************************/
89 gint GtkModeManage( intf_thread_t * p_intf )
90 {
91     GtkWidget *     p_dvd_box;
92     GtkWidget *     p_file_box;
93     GtkWidget *     p_network_box;
94     GtkWidget *     p_slider;
95     GtkWidget *     p_label;
96     GtkWidget *     p_channel;
97     boolean_t       b_control;
98
99 #define GETWIDGET( ptr, name ) GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( \
100                            p_intf->p_sys->ptr ) , ( name ) ) )
101     /* hide all boxes except default file box */
102     p_file_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
103                  p_intf->p_sys->p_window ), "file_box" ) );
104     gtk_widget_hide( GTK_WIDGET( p_file_box ) );
105
106     p_network_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
107                  p_intf->p_sys->p_window ), "network_box" ) );
108     gtk_widget_hide( GTK_WIDGET( p_network_box ) );
109
110     p_dvd_box = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
111                  p_intf->p_sys->p_window ), "dvd_box" ) );
112     gtk_widget_hide( GTK_WIDGET( p_dvd_box ) );
113
114     /* hide slider */
115     p_slider = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
116                            p_intf->p_sys->p_window ), "slider_frame" ) );
117     gtk_widget_hide( GTK_WIDGET( p_slider ) );
118
119     /* controls unavailable */
120     b_control = 0;
121
122     /* show the box related to current input mode */
123     if( p_input_bank->pp_input[0] != NULL )
124     {
125         switch( p_input_bank->pp_input[0]->stream.i_method & 0xf0 )
126         {
127             case INPUT_METHOD_FILE:
128 //intf_WarnMsg( 2, "intf info: file method" );
129                 gtk_widget_show( GTK_WIDGET( p_file_box ) );
130                 p_label = gtk_object_get_data( GTK_OBJECT(
131                             p_intf->p_sys->p_window ),
132                             "label_status" );
133                 gtk_label_set_text( GTK_LABEL( p_label ),
134                                     p_input_bank->pp_input[0]->p_source );
135                 break;
136             case INPUT_METHOD_DISC:
137 //intf_WarnMsg( 2, "intf info: disc method" );
138                 gtk_widget_show( GTK_WIDGET( p_dvd_box ) );
139                 break;
140             case INPUT_METHOD_NETWORK:
141 //intf_WarnMsg( 2, "intf info: network method" );
142                 gtk_widget_show( GTK_WIDGET( p_network_box ) );
143                 p_label = gtk_object_get_data( GTK_OBJECT(
144                             p_intf->p_sys->p_window ),
145                             "network_address_label" );
146                 gtk_label_set_text( GTK_LABEL( p_label ),
147                                     p_input_bank->pp_input[0]->p_source );
148                 p_channel = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
149                            p_intf->p_sys->p_window ), "network_channel_box" ) );
150                 if( main_GetIntVariable( INPUT_NETWORK_CHANNEL_VAR,
151                                          INPUT_NETWORK_CHANNEL_DEFAULT  ) )
152                 {
153                     gtk_widget_show( GTK_WIDGET( p_channel ) );
154                 }
155                 else
156                 {
157                     gtk_widget_hide( GTK_WIDGET( p_channel ) );
158                 }
159
160                 break;
161             default:
162                 intf_ErrMsg( "intf error: can't determine input method" );
163                 break;
164         }
165     
166         /* initialize and show slider for seekable streams */
167         if( p_input_bank->pp_input[0]->stream.b_seekable )
168         {
169             p_intf->p_sys->p_adj->value = p_intf->p_sys->f_adj_oldvalue = 0;
170             gtk_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
171                                      "value_changed" );
172             gtk_widget_show( GTK_WIDGET( p_slider ) );
173         }
174     
175         /* control buttons for free pace streams */
176         b_control = p_input_bank->pp_input[0]->stream.b_pace_control;
177
178         /* get ready for menu regeneration */
179         p_intf->p_sys->b_title_update = 1;
180         p_intf->p_sys->b_chapter_update = 1;
181         p_intf->p_sys->b_angle_update = 1;
182         p_intf->p_sys->b_audio_update = 1;
183         p_intf->p_sys->b_spu_update = 1;
184         p_intf->p_sys->i_part = 0;
185     
186         p_input_bank->pp_input[0]->stream.b_changed = 0;
187         intf_WarnMsg( 3, "intf: stream has changed, refreshing interface" );
188     }
189     else
190     {
191         if( main_GetIntVariable( INPUT_NETWORK_CHANNEL_VAR,
192                                  INPUT_NETWORK_CHANNEL_DEFAULT  ) )
193         {
194             gtk_widget_show( GTK_WIDGET( p_network_box ) );
195
196             p_channel = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
197                        p_intf->p_sys->p_window ), "network_channel_box" ) );
198             gtk_widget_show( GTK_WIDGET( p_channel ) );
199         }
200         else
201         {
202 //intf_WarnMsg( 2, "intf info: default to file method" );
203             /* default mode */
204             p_label = gtk_object_get_data(
205                     GTK_OBJECT( p_intf->p_sys->p_window ), "label_status" );
206             gtk_label_set_text( GTK_LABEL( p_label ), "" );
207             gtk_widget_show( GTK_WIDGET( p_file_box ) );
208
209             /* unsensitize menus */
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_angle"), FALSE );
214             gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_audio"), FALSE );
215             gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_subpictures"),
216                                       FALSE );
217             gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_navigation"),
218                                       FALSE );
219             gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_angle"), FALSE );
220             gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_audio"), FALSE );
221             gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_subpictures"),
222                                       FALSE );
223         }
224     }
225
226     /* set control items */
227     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_back"), FALSE );
228     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_eject"), !b_control);
229     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_pause"), b_control );
230     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_slow"), b_control );
231     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_fast"), b_control );
232     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_back"), FALSE );
233     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_pause"), b_control );
234     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_slow"), b_control );
235     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_fast"), b_control );
236
237 #undef GETWIDGET
238     return TRUE;
239 }