]> git.sesse.net Git - vlc/blob - plugins/gtk/gtk_display.c
1f9bf793267ec743bc55ad24a7a90134c43666aa
[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.17 2002/03/05 17:46:33 stef 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]->psz_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]->psz_source );
148                 p_channel = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
149                            p_intf->p_sys->p_window ), "network_channel_box" ) );
150                 if( config_GetIntVariable( INPUT_NETWORK_CHANNEL_VAR ) )
151                 {
152                     gtk_widget_show( GTK_WIDGET( p_channel ) );
153                 }
154                 else
155                 {
156                     gtk_widget_hide( GTK_WIDGET( p_channel ) );
157                 }
158
159                 break;
160             default:
161                 intf_WarnMsg( 3, "intf: can't determine input method" );
162                 gtk_widget_show( GTK_WIDGET( p_file_box ) );
163                 p_label = gtk_object_get_data( GTK_OBJECT(
164                             p_intf->p_sys->p_window ),
165                             "label_status" );
166                 gtk_label_set_text( GTK_LABEL( p_label ),
167                                     p_input_bank->pp_input[0]->psz_source );
168                 break;
169         }
170     
171         /* initialize and show slider for seekable streams */
172         if( p_input_bank->pp_input[0]->stream.b_seekable )
173         {
174             p_intf->p_sys->p_adj->value = p_intf->p_sys->f_adj_oldvalue = 0;
175             gtk_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
176                                      "value_changed" );
177             gtk_widget_show( GTK_WIDGET( p_slider ) );
178         }
179     
180         /* control buttons for free pace streams */
181         b_control = p_input_bank->pp_input[0]->stream.b_pace_control;
182
183         /* get ready for menu regeneration */
184         p_intf->p_sys->b_program_update = 1;
185         p_intf->p_sys->b_title_update = 1;
186         p_intf->p_sys->b_chapter_update = 1;
187         p_intf->p_sys->b_audio_update = 1;
188         p_intf->p_sys->b_spu_update = 1;
189         p_intf->p_sys->i_part = 0;
190     
191         p_input_bank->pp_input[0]->stream.b_changed = 0;
192         intf_WarnMsg( 3, "intf: stream has changed, refreshing interface" );
193     }
194     else
195     {
196         if( config_GetIntVariable( INPUT_NETWORK_CHANNEL_VAR ) )
197         {
198             gtk_widget_show( GTK_WIDGET( p_network_box ) );
199
200             p_channel = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
201                        p_intf->p_sys->p_window ), "network_channel_box" ) );
202             gtk_widget_show( GTK_WIDGET( p_channel ) );
203         }
204         else
205         {
206 //intf_WarnMsg( 2, "intf info: default to file method" );
207             /* default mode */
208             p_label = gtk_object_get_data(
209                     GTK_OBJECT( p_intf->p_sys->p_window ), "label_status" );
210             gtk_label_set_text( GTK_LABEL( p_label ), "" );
211             gtk_widget_show( GTK_WIDGET( p_file_box ) );
212
213             /* unsensitize menus */
214             gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_program"),
215                     FALSE );
216             gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_title"), FALSE );
217             gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_chapter"),
218                                       FALSE );
219             gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_angle"), FALSE );
220             gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_audio"), FALSE );
221             gtk_widget_set_sensitive( GETWIDGET(p_window,"menubar_subpictures"),
222                                       FALSE );
223             gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_navigation"),
224                                       FALSE );
225             gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_angle"), FALSE );
226             gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_audio"), FALSE );
227             gtk_widget_set_sensitive( GETWIDGET(p_popup,"popup_subpictures"),
228                                       FALSE );
229         }
230     }
231
232     /* set control items */
233     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_back"), FALSE );
234     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_eject"), !b_control);
235     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_pause"), b_control );
236     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_slow"), b_control );
237     gtk_widget_set_sensitive( GETWIDGET(p_window, "toolbar_fast"), b_control );
238     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_back"), FALSE );
239     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_pause"), b_control );
240     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_slow"), b_control );
241     gtk_widget_set_sensitive( GETWIDGET(p_popup, "popup_fast"), b_control );
242
243 #undef GETWIDGET
244     return TRUE;
245 }