1 /*****************************************************************************
2 * gnome.c : Gnome plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000 VideoLAN
7 * Authors: Samuel Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
37 #include "gnome_callbacks.h"
38 #include "gnome_interface.h"
39 #include "gnome_support.h"
43 /*****************************************************************************
45 *****************************************************************************/
46 static int Open ( vlc_object_t * );
47 static void Close ( vlc_object_t * );
49 static void Run ( intf_thread_t * );
50 static void Manage ( intf_thread_t * );
52 /*****************************************************************************
54 *****************************************************************************/
55 #define TOOLTIPS_TEXT N_("Show tooltips")
56 #define TOOLTIPS_LONGTEXT N_("Show tooltips for configuration options.")
58 #define TOOLBAR_TEXT N_("Show text on toolbar buttons")
59 #define TOOLBAR_LONGTEXT N_("Show the text below icons on the toolbar.")
61 #define PREFS_MAXH_TEXT N_("Maximum height for the configuration windows")
62 #define PREFS_MAXH_LONGTEXT N_( \
63 "You can set the maximum height that the configuration windows in the " \
64 "preferences menu will occupy.")
66 #define PATH_TEXT N_("Interface default search path")
67 #define PATH_LONGTEXT N_( \
68 "This option allows you to set the default path that the interface will " \
69 "open when looking for a file.")
75 int i = getenv( "DISPLAY" ) == NULL ? 15 : 100;
77 set_description( _("GNOME interface") );
79 add_bool( "gnome-tooltips", 1, E_(GtkHideTooltips),
80 TOOLTIPS_TEXT, TOOLTIPS_LONGTEXT, VLC_FALSE );
81 add_bool( "gnome-toolbartext", 1, GtkHideToolbarText, TOOLBAR_TEXT,
82 TOOLBAR_LONGTEXT, VLC_FALSE );
83 add_integer( "gnome-prefs-maxh", 480, NULL,
84 PREFS_MAXH_TEXT, PREFS_MAXH_LONGTEXT, VLC_TRUE );
85 add_directory( "gnome-search-path", NULL, NULL, PATH_TEXT,
86 PATH_LONGTEXT, VLC_TRUE );
88 set_capability( "interface", i );
89 set_callbacks( Open, Close );
90 set_program( "gnome-vlc" );
93 /*****************************************************************************
94 * Open: initialize and create window
95 *****************************************************************************/
96 static int Open( vlc_object_t *p_this )
98 intf_thread_t *p_intf = (intf_thread_t *)p_this;
100 /* Allocate instance and initialize some members */
101 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
102 if( p_intf->p_sys == NULL )
104 msg_Err( p_intf, "out of memory" );
108 p_intf->p_sys->p_gtk_main =
109 module_Need( p_this, "gui-helper", "gnome", VLC_TRUE );
110 if( p_intf->p_sys->p_gtk_main == NULL )
112 free( p_intf->p_sys );
116 p_intf->pf_run = Run;
118 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
120 /* Initialize Gnome thread */
121 p_intf->p_sys->b_playing = VLC_FALSE;
122 p_intf->p_sys->b_deinterlace_update = VLC_FALSE;
124 p_intf->p_sys->b_aout_update = VLC_FALSE;
125 p_intf->p_sys->b_vout_update = VLC_FALSE;
127 p_intf->p_sys->b_popup_changed = VLC_FALSE;
128 p_intf->p_sys->b_window_changed = VLC_FALSE;
129 p_intf->p_sys->b_playlist_changed = VLC_FALSE;
130 p_intf->p_sys->b_program_update = VLC_FALSE;
131 p_intf->p_sys->b_title_update = VLC_FALSE;
132 p_intf->p_sys->b_chapter_update = VLC_FALSE;
133 p_intf->p_sys->b_spu_update = VLC_FALSE;
134 p_intf->p_sys->b_audio_update = VLC_FALSE;
136 p_intf->p_sys->p_input = NULL;
137 p_intf->p_sys->i_playing = -1;
138 p_intf->p_sys->b_slider_free = VLC_TRUE;
140 p_intf->p_sys->i_part = 0;
141 p_intf->p_sys->b_mute = VLC_FALSE;
146 /*****************************************************************************
147 * Close: destroy interface window
148 *****************************************************************************/
149 static void Close( vlc_object_t *p_this )
151 intf_thread_t *p_intf = (intf_thread_t *)p_this;
153 if( p_intf->p_sys->p_input )
155 vlc_object_release( p_intf->p_sys->p_input );
158 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
160 module_Unneed( p_intf, p_intf->p_sys->p_gtk_main );
162 /* Destroy structure */
163 free( p_intf->p_sys );
166 /*****************************************************************************
168 *****************************************************************************
169 * this part of the interface is in a separate thread so that we can call
170 * gtk_main() from within it without annoying the rest of the program.
171 * XXX: the approach may look kludgy, and probably is, but I could not find
172 * a better way to dynamically load a Gnome interface at runtime.
173 *****************************************************************************/
174 static void Run( intf_thread_t *p_intf )
176 /* The data types we are allowed to receive */
177 static GtkTargetEntry target_table[] =
179 { "STRING", 0, DROP_ACCEPT_STRING },
180 { "text/uri-list", 0, DROP_ACCEPT_TEXT_URI_LIST },
181 { "text/plain", 0, DROP_ACCEPT_TEXT_PLAIN }
188 /* Create some useful widgets that will certainly be used */
189 p_intf->p_sys->p_window = create_intf_window( );
190 p_intf->p_sys->p_popup = create_intf_popup( );
191 p_intf->p_sys->p_playwin = create_intf_playlist();
192 p_intf->p_sys->p_messages = create_intf_messages();
193 p_intf->p_sys->p_tooltips = gtk_tooltips_new();
194 p_intf->p_sys->p_sout = create_intf_sout();
196 /* Set the title of the main window */
197 gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_window),
198 VOUT_TITLE " (Gnome interface)");
200 /* Accept file drops on the main window */
201 gtk_drag_dest_set( GTK_WIDGET( p_intf->p_sys->p_window ),
202 GTK_DEST_DEFAULT_ALL, target_table,
203 DROP_ACCEPT_END, GDK_ACTION_COPY );
204 /* Accept file drops on the playlist window */
205 gtk_drag_dest_set( GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
206 p_intf->p_sys->p_playwin ), "playlist_clist") ),
207 GTK_DEST_DEFAULT_ALL, target_table,
208 DROP_ACCEPT_END, GDK_ACTION_COPY );
210 /* Get the slider object */
211 p_intf->p_sys->p_slider_frame = gtk_object_get_data(
212 GTK_OBJECT( p_intf->p_sys->p_window ), "slider_frame" );
214 /* Configure the log window */
215 p_intf->p_sys->p_messages_text = GTK_TEXT( gtk_object_get_data(
216 GTK_OBJECT(p_intf->p_sys->p_messages ), "messages_textbox" ) );
217 gtk_text_set_line_wrap( p_intf->p_sys->p_messages_text, TRUE);
218 gtk_text_set_word_wrap( p_intf->p_sys->p_messages_text, FALSE);
220 /* Get the interface labels */
221 #define P_LABEL( name ) GTK_LABEL( gtk_object_get_data( \
222 GTK_OBJECT( p_intf->p_sys->p_window ), name ) )
223 p_intf->p_sys->p_label_title = P_LABEL( "title_label" );
224 p_intf->p_sys->p_label_chapter = P_LABEL( "chapter_label" );
227 /* Connect the date display to the slider */
228 #define P_SLIDER GTK_RANGE( gtk_object_get_data( \
229 GTK_OBJECT( p_intf->p_sys->p_window ), "slider" ) )
230 p_intf->p_sys->p_adj = gtk_range_get_adjustment( P_SLIDER );
232 gtk_signal_connect ( GTK_OBJECT( p_intf->p_sys->p_adj ), "value_changed",
233 GTK_SIGNAL_FUNC( E_(GtkDisplayDate) ), NULL );
234 p_intf->p_sys->f_adj_oldvalue = 0;
237 /* We don't create these ones yet because we perhaps won't need them */
238 p_intf->p_sys->p_about = NULL;
239 p_intf->p_sys->p_modules = NULL;
240 p_intf->p_sys->p_open = NULL;
241 p_intf->p_sys->p_jump = NULL;
243 /* Hide tooltips if the option is set */
244 if( !config_GetInt( p_intf, "gnome-tooltips" ) )
246 gtk_tooltips_disable( p_intf->p_sys->p_tooltips );
249 /* Hide toolbar text of the option is set */
250 if( !config_GetInt( p_intf, "gnome-toolbartext" ) )
252 gtk_toolbar_set_style(
253 GTK_TOOLBAR(lookup_widget( p_intf->p_sys->p_window, "toolbar" )),
257 /* Store p_intf to keep an eye on it */
258 gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
261 gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_popup),
263 gtk_object_set_data( GTK_OBJECT( gtk_object_get_data(
264 GTK_OBJECT(p_intf->p_sys->p_popup),
265 "popup_audio" ) ), "p_intf", p_intf );
266 gtk_object_set_data( GTK_OBJECT( gtk_object_get_data(
267 GTK_OBJECT(p_intf->p_sys->p_popup),
268 "popup_video" ) ), "p_intf", p_intf );
270 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_playwin ),
273 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_messages ),
276 gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_adj),
279 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_sout ),
282 psz_sout = config_GetPsz( p_intf, "sout" );
283 p_target = g_string_new( psz_sout ? psz_sout : "" );
284 if( psz_sout ) free( psz_sout );
286 gtk_entry_set_text( gtk_object_get_data( GTK_OBJECT( p_intf->p_sys->p_sout ), "sout_entry_target" ), p_target->str );
287 g_string_free( p_target, TRUE );
289 /* FIXME it's to be sure that only file entry is selected */
290 gtk_toggle_button_set_active( gtk_object_get_data( GTK_OBJECT( p_intf->p_sys->p_sout ),
291 "sout_access_udp" ), TRUE );
293 gtk_toggle_button_set_active( gtk_object_get_data( GTK_OBJECT( p_intf->p_sys->p_sout ),
294 "sout_access_file" ), TRUE );
296 /* Show the control window */
297 gtk_widget_show( p_intf->p_sys->p_window );
299 while( !p_intf->b_die )
303 /* Sleep to avoid using all CPU - since some interfaces need to
304 * access keyboard events, a 100ms delay is a good compromise */
306 msleep( INTF_IDLE_SLEEP );
310 /* Destroy the Tooltips structure */
311 gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_tooltips) );
312 gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_messages) );
313 gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_playwin) );
314 gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_popup) );
315 gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_window) );
320 /* following functions are local */
322 /*****************************************************************************
323 * Manage: manage main thread messages
324 *****************************************************************************
325 * In this function, called approx. 10 times a second, we check what the
326 * main program wanted to tell us.
327 *****************************************************************************/
328 static void Manage( intf_thread_t *p_intf )
332 vlc_mutex_lock( &p_intf->change_lock );
334 /* If the "display popup" flag has changed */
335 if( p_intf->b_menu_change )
337 if( !GTK_IS_WIDGET( p_intf->p_sys->p_popup ) )
339 p_intf->p_sys->p_popup = create_intf_popup();
340 gtk_object_set_data( GTK_OBJECT( p_intf->p_sys->p_popup ),
344 gnome_popup_menu_do_popup( p_intf->p_sys->p_popup,
345 NULL, NULL, NULL, NULL );
346 p_intf->b_menu_change = 0;
349 /* Update the log window */
350 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
351 i_stop = *p_intf->p_sys->p_sub->pi_stop;
352 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
354 if( p_intf->p_sys->p_sub->i_start != i_stop )
356 static GdkColor white = { 0, 0xffff, 0xffff, 0xffff };
357 static GdkColor gray = { 0, 0xaaaa, 0xaaaa, 0xaaaa };
358 static GdkColor yellow = { 0, 0xffff, 0xffff, 0x6666 };
359 static GdkColor red = { 0, 0xffff, 0x6666, 0x6666 };
361 static const char * ppsz_type[4] = { ": ", " error: ", " warning: ",
363 static GdkColor * pp_color[4] = { &white, &red, &yellow, &gray };
365 for( i_start = p_intf->p_sys->p_sub->i_start;
367 i_start = (i_start+1) % VLC_MSG_QSIZE )
369 /* Append all messages to log window */
370 gtk_text_insert( p_intf->p_sys->p_messages_text, NULL, &gray,
371 NULL, p_intf->p_sys->p_sub->p_msg[i_start].psz_module, -1 );
373 gtk_text_insert( p_intf->p_sys->p_messages_text, NULL, &gray,
374 NULL, ppsz_type[p_intf->p_sys->p_sub->p_msg[i_start].i_type],
377 gtk_text_insert( p_intf->p_sys->p_messages_text, NULL,
378 pp_color[p_intf->p_sys->p_sub->p_msg[i_start].i_type], NULL,
379 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg, -1 );
381 gtk_text_insert( p_intf->p_sys->p_messages_text, NULL, &gray,
385 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
386 p_intf->p_sys->p_sub->i_start = i_start;
387 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
389 /* If the messages list becomes too big, just clean half of it. */
390 if( gtk_text_get_length( p_intf->p_sys->p_messages_text ) >
391 VLC_MSG_QSIZE * 1000 )
393 gtk_text_set_point( p_intf->p_sys->p_messages_text, 0 );
394 gtk_text_forward_delete( p_intf->p_sys->p_messages_text,
395 gtk_text_get_length( p_intf->p_sys->p_messages_text ) / 2 );
398 gtk_text_set_point( p_intf->p_sys->p_messages_text,
399 gtk_text_get_length( p_intf->p_sys->p_messages_text ) );
402 /* Update the playlist */
403 GtkPlayListManage( p_intf );
405 /* Update the input */
406 if( p_intf->p_sys->p_input != NULL )
408 if( p_intf->p_sys->p_input->b_dead )
410 vlc_object_release( p_intf->p_sys->p_input );
411 p_intf->p_sys->p_input = NULL;
415 if( p_intf->p_sys->p_input == NULL )
417 p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
421 if( p_intf->p_sys->p_input )
423 input_thread_t *p_input = p_intf->p_sys->p_input;
424 aout_instance_t *p_aout = NULL;
425 vout_thread_t *p_vout = NULL;
426 vlc_bool_t b_need_menus = VLC_FALSE;
428 vlc_mutex_lock( &p_input->stream.stream_lock );
430 if( !p_input->b_die )
432 /* New input or stream map change */
433 if( p_input->stream.b_changed )
435 E_(GtkModeManage)( p_intf );
436 GtkSetupMenus( p_intf );
437 p_intf->p_sys->b_playing = 1;
440 /* Manage the slider */
441 if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
443 float newvalue = p_intf->p_sys->p_adj->value;
445 #define p_area p_input->stream.p_selected_area
446 /* If the user hasn't touched the slider since the last time,
447 * then the input can safely change it */
448 if( newvalue == p_intf->p_sys->f_adj_oldvalue )
450 /* Update the value */
451 p_intf->p_sys->p_adj->value =
452 p_intf->p_sys->f_adj_oldvalue =
453 ( 100. * p_area->i_tell ) / p_area->i_size;
455 gtk_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
458 /* Otherwise, send message to the input if the user has
459 * finished dragging the slider.
460 * Beware, the hack below is needed by the dvdplay plugin! */
461 else if( p_intf->p_sys->b_slider_free
462 /* hack -> */ && (p_intf->p_sys->f_adj_oldvalue < 100.) )
464 if( newvalue >= 0. && newvalue < 100. )
466 double f_fpos = (double)newvalue / 100.0;
468 /* release the lock to be able to seek */
469 vlc_mutex_unlock( &p_input->stream.stream_lock );
470 var_SetFloat( p_input, "position", f_fpos );
471 vlc_mutex_lock( &p_input->stream.stream_lock );
475 /* Update the old value */
476 p_intf->p_sys->f_adj_oldvalue = newvalue;
481 if( p_intf->p_sys->i_part !=
482 p_input->stream.p_selected_area->i_part )
484 p_intf->p_sys->b_chapter_update = 1;
485 b_need_menus = VLC_TRUE;
488 /* Does the audio output require to update the menus ? */
489 p_aout = (aout_instance_t *)vlc_object_find( p_intf, VLC_OBJECT_AOUT,
494 if( var_Get( (vlc_object_t *)p_aout, "intf-change", &val ) >= 0
497 p_intf->p_sys->b_aout_update = 1;
501 vlc_object_release( (vlc_object_t *)p_aout );
505 /* Does the video output require to update the menus ? */
506 p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
511 if( var_Get( (vlc_object_t *)p_vout, "intf-change", &val ) >= 0
514 p_intf->p_sys->b_vout_update = 1;
518 vlc_object_release( (vlc_object_t *)p_vout );
523 GtkSetupMenus( p_intf );
527 vlc_mutex_unlock( &p_input->stream.stream_lock );
529 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
531 E_(GtkModeManage)( p_intf );
532 p_intf->p_sys->b_playing = 0;
535 vlc_mutex_unlock( &p_intf->change_lock );