]> git.sesse.net Git - vlc/blob - modules/gui/pda/pda.c
Don't include config.h from the headers - refs #297.
[vlc] / modules / gui / pda / pda.c
1 /*****************************************************************************
2  * pda.c : PDA Gtk2 plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2002 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Jean-Paul Saman <jpsaman  _at_ videolan _dot_ org>
8  *          Marc Ariberti <marcari@videolan.org>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <errno.h>                                                 /* ENOMEM */
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <vlc/vlc.h>
35 #include <vlc_input.h>
36 #include <vlc_interface.h>
37 #include <vlc_playlist.h>
38
39 #include <gtk/gtk.h>
40
41 #include "pda_callbacks.h"
42 #include "pda_interface.h"
43 #include "pda_support.h"
44 #include "pda.h"
45
46 /*****************************************************************************
47  * Local prototypes.
48  *****************************************************************************/
49 static int  Open         ( vlc_object_t * );
50 static void Close        ( vlc_object_t * );
51 static void Run          ( intf_thread_t * );
52
53 void GtkAutoPlayFile     ( vlc_object_t * );
54 static int Manage        ( intf_thread_t *p_intf );
55 void E_(GtkDisplayDate)  ( GtkAdjustment *p_adj, gpointer userdata );
56 gint E_(GtkModeManage)   ( intf_thread_t * p_intf );
57
58 /*****************************************************************************
59  * Module descriptor
60  *****************************************************************************/
61 #define AUTOPLAYFILE_TEXT  N_("Autoplay selected file")
62 #define AUTOPLAYFILE_LONGTEXT N_("Automatically play a file when selected in the "\
63         "file selection list")
64
65 /*****************************************************************************
66  * Module descriptor
67  *****************************************************************************/
68 vlc_module_begin();
69     set_description( _("PDA Linux Gtk2+ interface") );
70     set_category( CAT_INTERFACE );
71     set_subcategory( SUBCAT_INTERFACE_MAIN );
72 //    add_bool( "pda-autoplayfile", 1, GtkAutoPlayFile, AUTOPLAYFILE_TEXT, AUTOPLAYFILE_LONGTEXT, VLC_TRUE );
73     set_capability( "interface", 70 );
74     set_callbacks( Open, Close );
75     add_shortcut( "pda" );
76 vlc_module_end();
77
78 /*****************************************************************************
79  * Open: initialize and create window
80  *****************************************************************************/
81 static int Open( vlc_object_t *p_this )
82 {
83     intf_thread_t *p_intf = (intf_thread_t *)p_this;
84
85     /* Allocate instance and initialize some members */
86     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
87     if( p_intf->p_sys == NULL )
88     {
89         msg_Err( p_intf, "out of memory" );
90         return VLC_ENOMEM;
91     }
92
93 #ifdef NEED_GTK2_MAIN
94     msg_Dbg( p_intf, "Using gui-helper" );
95     p_intf->p_sys->p_gtk_main =
96         module_Need( p_this, "gui-helper", "gtk2", VLC_TRUE );
97     if( p_intf->p_sys->p_gtk_main == NULL )
98     {
99         free( p_intf->p_sys );
100         return VLC_ENOMOD;
101     }
102 #endif
103
104     /* Initialize Gtk+ thread */
105     p_intf->p_sys->p_input = NULL;
106
107     p_intf->p_sys->b_autoplayfile = 1;
108     p_intf->p_sys->b_playing = 0;
109     p_intf->p_sys->b_slider_free = 1;
110
111     p_intf->pf_run = Run;
112
113     return VLC_SUCCESS;
114 }
115
116 /*****************************************************************************
117  * Close: destroy interface window
118  *****************************************************************************/
119 static void Close( vlc_object_t *p_this )
120 {
121     intf_thread_t *p_intf = (intf_thread_t *)p_this;
122
123     if( p_intf->p_sys->p_input )
124     {
125         vlc_object_release( p_intf->p_sys->p_input );
126     }
127
128 #ifdef NEED_GTK2_MAIN
129     msg_Dbg( p_intf, "Releasing gui-helper" );
130     module_Unneed( p_intf, p_intf->p_sys->p_gtk_main );
131 #endif
132
133     /* Destroy structure */
134     free( p_intf->p_sys );
135 }
136
137 /*****************************************************************************
138  * Run: Gtk+ thread
139  *****************************************************************************
140  * this part of the interface is in a separate thread so that we can call
141  * gtk_main() from within it without annoying the rest of the program.
142  *****************************************************************************/
143 static void Run( intf_thread_t *p_intf )
144 {
145 #ifndef NEED_GTK2_MAIN
146     /* gtk_init needs to know the command line. We don't care, so we
147      * give it an empty one */
148     char  *p_args[] = { "", NULL };
149     char **pp_args  = p_args;
150     int    i_args   = 1;
151     int    i_dummy;
152 #endif
153     playlist_t        *p_playlist;
154     GtkCellRenderer   *p_renderer = NULL;
155     GtkTreeViewColumn *p_column   = NULL;
156     GtkListStore      *p_filelist = NULL;
157     GtkListStore      *p_playlist_store = NULL;
158
159 #ifndef NEED_GTK2_MAIN
160     gtk_set_locale ();
161     msg_Dbg( p_intf, "Starting pda GTK2+ interface" );
162     gtk_init( &i_args, &pp_args );
163 #else
164     /* Initialize Gtk+ */
165     msg_Dbg( p_intf, "Starting pda GTK2+ interface thread" );
166     gdk_threads_enter();
167 #endif
168
169     /* Create some useful widgets that will certainly be used */
170 /* FIXME: magic path */
171     add_pixmap_directory("share");
172     add_pixmap_directory("/usr/share/vlc");
173
174     /* Path for pixmaps under linupy 1.4 */
175     add_pixmap_directory("/usr/local/share/pixmaps/vlc");
176     /* Path for pixmaps under linupy 2.0 */
177     add_pixmap_directory("/usr/share/pixmaps/vlc");
178
179     p_intf->p_sys->p_window = create_pda();
180     if (p_intf->p_sys->p_window == NULL)
181     {
182         msg_Err( p_intf, "unable to create pda interface" );
183     }
184
185     /* Store p_intf to keep an eye on it */
186     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
187                          "p_intf", p_intf );
188
189     /* Set the title of the main window */
190     gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_window),
191                           VOUT_TITLE " (PDA Linux interface)");
192
193     /* Get the notebook object */
194     p_intf->p_sys->p_notebook = GTK_NOTEBOOK( gtk_object_get_data(
195         GTK_OBJECT( p_intf->p_sys->p_window ), "notebook" ) );
196
197     /* Get the slider object */
198     p_intf->p_sys->p_slider = (GtkHScale*) lookup_widget( p_intf->p_sys->p_window, "timeSlider" );
199     p_intf->p_sys->p_slider_label = (GtkLabel*) lookup_widget( p_intf->p_sys->p_window, "timeLabel" );
200     if (p_intf->p_sys->p_slider == NULL)
201         msg_Err( p_intf, "Time slider widget not found." );
202     if (p_intf->p_sys->p_slider_label == NULL)
203         msg_Err( p_intf, "Time label widget not found." );
204
205     /* Connect the date display to the slider */
206     p_intf->p_sys->p_adj = gtk_range_get_adjustment( GTK_RANGE(p_intf->p_sys->p_slider) );
207     if (p_intf->p_sys->p_adj == NULL)
208         msg_Err( p_intf, "Adjustment range not found." );
209     g_signal_connect( GTK_OBJECT( p_intf->p_sys->p_adj ), "value_changed",
210                          G_CALLBACK( E_(GtkDisplayDate) ), p_intf );
211     p_intf->p_sys->f_adj_oldvalue = 0;
212     p_intf->p_sys->i_adj_oldvalue = 0;
213
214     /* BEGIN OF FILEVIEW GTK_TREE_VIEW */
215     p_intf->p_sys->p_tvfile = NULL;
216     p_intf->p_sys->p_tvfile = (GtkTreeView *) lookup_widget( p_intf->p_sys->p_window,
217                                                              "tvFileList");
218     if (NULL == p_intf->p_sys->p_tvfile)
219        msg_Err(p_intf, "Error obtaining pointer to File List");
220
221     /* Insert columns 0 */
222     p_renderer = gtk_cell_renderer_text_new ();
223     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 0, (gchar *) N_("Filename"), p_renderer, NULL);
224     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 0 );
225     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 0 );
226     gtk_tree_view_column_set_sort_column_id(p_column, 0);
227     /* Insert columns 1 */
228     p_renderer = gtk_cell_renderer_text_new ();
229     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 1, (gchar *) N_("Permissions"), p_renderer, NULL);
230     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 1 );
231     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 1 );
232     gtk_tree_view_column_set_sort_column_id(p_column, 1);
233     /* Insert columns 2 */
234     p_renderer = gtk_cell_renderer_text_new ();
235     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 2, (gchar *) N_("Size"), p_renderer, NULL);
236     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 2 );
237     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 2 );
238     gtk_tree_view_column_set_sort_column_id(p_column, 2);
239     /* Insert columns 3 */
240     p_renderer = gtk_cell_renderer_text_new ();
241     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 3, (gchar *) N_("Owner"), p_renderer, NULL);
242     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 3 );
243     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 3 );
244     gtk_tree_view_column_set_sort_column_id(p_column, 3);
245     /* Insert columns 4 */
246     p_renderer = gtk_cell_renderer_text_new ();
247     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 4, (gchar *) N_("Group"), p_renderer, NULL);
248     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 4 );
249     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 4 );
250     gtk_tree_view_column_set_sort_column_id(p_column, 4);
251
252     /* Get new directory listing */
253     p_filelist = gtk_list_store_new (5,
254                 G_TYPE_STRING, /* Filename */
255                 G_TYPE_STRING, /* permissions */
256                 G_TYPE_UINT64, /* File size */
257                 G_TYPE_STRING, /* Owner */
258                 G_TYPE_STRING);/* Group */
259     ReadDirectory(p_intf, p_filelist, ".");
260     gtk_tree_view_set_model(GTK_TREE_VIEW(p_intf->p_sys->p_tvfile), GTK_TREE_MODEL(p_filelist));
261     g_object_unref(p_filelist);     /* Model will be released by GtkTreeView */
262     gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(p_intf->p_sys->p_tvfile)),GTK_SELECTION_MULTIPLE);
263
264     /* Column properties */
265     gtk_tree_view_set_headers_visible(p_intf->p_sys->p_tvfile, TRUE);
266     gtk_tree_view_columns_autosize(p_intf->p_sys->p_tvfile);
267     gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(p_intf->p_sys->p_tvfile),TRUE);
268     /* END OF FILEVIEW GTK_TREE_VIEW */
269
270     /* BEGIN OF PLAYLIST GTK_TREE_VIEW */
271     p_intf->p_sys->p_tvplaylist = NULL;
272     p_intf->p_sys->p_tvplaylist = (GtkTreeView *) lookup_widget( p_intf->p_sys->p_window, "tvPlaylist");
273     if (NULL == p_intf->p_sys->p_tvplaylist)
274        msg_Err(p_intf, "Error obtaining pointer to Play List");
275
276     /* Columns 1 */
277     p_renderer = gtk_cell_renderer_text_new ();
278     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 0, (gchar *) N_("Filename"), p_renderer, NULL);
279     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvplaylist, 0 );
280     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 0 );
281     gtk_tree_view_column_set_sort_column_id(p_column, 0);
282     /* Column 2 */
283     p_renderer = gtk_cell_renderer_text_new ();
284     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 1, (gchar *) N_("Time"), p_renderer, NULL);
285     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvplaylist, 1 );
286     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 1 );
287     gtk_tree_view_column_set_sort_column_id(p_column, 1);
288 #if 0
289     /* Column 3 - is a hidden column used for reliable deleting items from the underlying playlist */
290     p_renderer = gtk_cell_renderer_text_new ();
291     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 2, (gchar *) N_("Index"), p_renderer, NULL);
292     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvplaylist, 2 );
293     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 2 );
294     gtk_tree_view_column_set_sort_column_id(p_column, 2);
295 #endif
296     /* update the playlist */
297     p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
298     p_playlist_store = gtk_list_store_new (3,
299                 G_TYPE_STRING, /* Filename */
300                 G_TYPE_STRING, /* Time */
301                 G_TYPE_UINT);  /* Hidden index */
302     PlaylistRebuildListStore(p_intf,p_playlist_store, p_playlist);
303     gtk_tree_view_set_model(GTK_TREE_VIEW(p_intf->p_sys->p_tvplaylist), GTK_TREE_MODEL(p_playlist_store));
304     g_object_unref(p_playlist_store);
305     vlc_object_release(p_playlist); /* Free the playlist */
306     gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(p_intf->p_sys->p_tvplaylist)),GTK_SELECTION_MULTIPLE);
307
308     /* Column properties */
309     gtk_tree_view_set_headers_visible(p_intf->p_sys->p_tvplaylist, TRUE);
310     gtk_tree_view_columns_autosize(p_intf->p_sys->p_tvplaylist);
311     gtk_tree_view_set_headers_clickable(p_intf->p_sys->p_tvplaylist, TRUE);
312     /* END OF PLAYLIST GTK_TREE_VIEW */
313
314     /* Hide the Preference TAB for now. */
315     GtkWidget *p_preference_tab = NULL;
316     p_preference_tab = gtk_notebook_get_nth_page(p_intf->p_sys->p_notebook,5);
317     if (p_preference_tab != NULL)
318       gtk_widget_hide(p_preference_tab);
319
320     /* Show the control window */
321     gtk_widget_show( p_intf->p_sys->p_window );
322
323 #ifdef NEED_GTK2_MAIN
324     msg_Dbg( p_intf, "Manage GTK keyboard events using threads" );
325     while( !intf_ShouldDie( p_intf ) )
326     {
327         Manage( p_intf );
328
329         /* Sleep to avoid using all CPU - since some interfaces need to
330          * access keyboard events, a 100ms delay is a good compromise */
331         gdk_threads_leave();
332         if (vlc_CPU() & CPU_CAPABILITY_FPU)
333             msleep( INTF_IDLE_SLEEP );
334         else
335             msleep( 1000 );
336         gdk_threads_enter();
337     }
338 #else
339     msg_Dbg( p_intf, "Manage GTK keyboard events using timeouts" );
340     /* Sleep to avoid using all CPU - since some interfaces needs to access
341      * keyboard events, a 1000ms delay is a good compromise */
342     if (vlc_CPU() & CPU_CAPABILITY_FPU)
343         i_dummy = gtk_timeout_add( INTF_IDLE_SLEEP / 1000, (GtkFunction)Manage, p_intf );
344     else
345         i_dummy = gtk_timeout_add( 1000, (GtkFunction)Manage, p_intf );
346
347     /* Enter Gtk mode */
348     gtk_main();
349     /* Remove the timeout */
350     gtk_timeout_remove( i_dummy );
351 #endif
352
353     gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_window) );
354 #ifdef NEED_GTK2_MAIN
355     gdk_threads_leave();
356 #endif
357 }
358
359 /*****************************************************************************
360  * GtkAutoplayFile: Autoplay file depending on configuration settings
361  *****************************************************************************/
362 void GtkAutoPlayFile( vlc_object_t *p_this )
363 {
364     GtkWidget *cbautoplay;
365     intf_thread_t *p_intf;
366     int i_index;
367     vlc_list_t *p_list = vlc_list_find( p_this, VLC_OBJECT_INTF,
368                                         FIND_ANYWHERE );
369
370     for( i_index = 0; i_index < p_list->i_count; i_index++ )
371     {
372         p_intf = (intf_thread_t *)p_list->p_values[i_index].p_object ;
373
374         if( strcmp( MODULE_STRING, module_GetObjName(p_intf->p_module) ) )
375         {
376             continue;
377         }
378         cbautoplay = GTK_WIDGET( gtk_object_get_data(
379                             GTK_OBJECT( p_intf->p_sys->p_window ),
380                             "cbautoplay" ) );
381
382         if( !config_GetInt( p_this, "pda-autoplayfile" ) )
383         {
384             p_intf->p_sys->b_autoplayfile = VLC_FALSE;
385         }
386         else
387         {
388             p_intf->p_sys->b_autoplayfile = VLC_TRUE;
389         }
390         gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( cbautoplay ),
391                                       p_intf->p_sys->b_autoplayfile );
392     }
393     vlc_list_release( p_list );
394 }
395
396 /* following functions are local */
397
398 /*****************************************************************************
399  * Manage: manage main thread messages
400  *****************************************************************************
401  * In this function, called approx. 10 times a second, we check what the
402  * main program wanted to tell us.
403  *****************************************************************************/
404 static int Manage( intf_thread_t *p_intf )
405 {
406     GtkListStore *p_liststore;
407     vlc_mutex_lock( &p_intf->change_lock );
408
409     /* Update the input */
410     if( p_intf->p_sys->p_input == NULL )
411     {
412         p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
413                                                           FIND_ANYWHERE );
414     }
415     else if( p_intf->p_sys->p_input->b_dead )
416     {
417         vlc_object_release( p_intf->p_sys->p_input );
418         p_intf->p_sys->p_input = NULL;
419     }
420
421     if( p_intf->p_sys->p_input )
422     {
423         input_thread_t *p_input = p_intf->p_sys->p_input;
424         int64_t i_time = 0, i_length = 0;
425
426         vlc_mutex_lock( &p_input->object_lock );
427         if( !p_input->b_die )
428         {
429             playlist_t *p_playlist;
430
431             E_(GtkModeManage)( p_intf );
432             p_intf->p_sys->b_playing = 1;
433
434             /* update playlist interface */
435             p_playlist = (playlist_t *) vlc_object_find(
436                     p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
437             if (p_playlist != NULL)
438             {
439                 p_liststore = gtk_list_store_new (3,
440                                             G_TYPE_STRING,
441                                             G_TYPE_STRING,
442                                             G_TYPE_UINT);  /* Hidden index */
443                 PlaylistRebuildListStore(p_intf, p_liststore, p_playlist);
444                 gtk_tree_view_set_model(p_intf->p_sys->p_tvplaylist, (GtkTreeModel*) p_liststore);
445                 g_object_unref(p_liststore);
446                 vlc_object_release( p_playlist );
447             }
448
449             /* Manage the slider */
450             i_time = var_GetTime( p_intf->p_sys->p_input, "time" );
451             i_length = var_GetTime( p_intf->p_sys->p_input, "length" );
452
453             if (vlc_CPU() & CPU_CAPABILITY_FPU)
454             {
455                 /* Manage the slider for CPU_CAPABILITY_FPU hardware */
456                 if( p_intf->p_sys->b_playing )
457                 {
458                     float newvalue = p_intf->p_sys->p_adj->value;
459
460                     /* If the user hasn't touched the slider since the last time,
461                      * then the input can safely change it */
462                     if( newvalue == p_intf->p_sys->f_adj_oldvalue )
463                     {
464                         /* Update the value */
465                         p_intf->p_sys->p_adj->value =
466                         p_intf->p_sys->f_adj_oldvalue =
467                             ( 100 * i_time ) / i_length;
468                         g_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
469                                                  "value_changed" );
470                     }
471                     /* Otherwise, send message to the input if the user has
472                      * finished dragging the slider */
473                     else if( p_intf->p_sys->b_slider_free )
474                     {
475                         double f_pos = (double)newvalue / 100.0;
476
477                         /* release the lock to be able to seek */
478                         vlc_mutex_unlock( &p_input->object_lock );
479                         var_SetFloat( p_input, "position", f_pos );
480                         vlc_mutex_lock( &p_input->object_lock );
481
482                         /* Update the old value */
483                         p_intf->p_sys->f_adj_oldvalue = newvalue;
484                     }
485                 }
486             }
487             else
488             {
489                 /* Manage the slider without CPU_CAPABILITY_FPU hardware */
490                 if( p_intf->p_sys->b_playing )
491                 {
492                     off_t newvalue = p_intf->p_sys->p_adj->value;
493
494                     /* If the user hasn't touched the slider since the last time,
495                      * then the input can safely change it */
496                     if( newvalue == p_intf->p_sys->i_adj_oldvalue )
497                     {
498                         /* Update the value */
499                         p_intf->p_sys->p_adj->value =
500                         p_intf->p_sys->i_adj_oldvalue =
501                             ( 100 * i_time ) / i_length;
502                         g_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
503                                                  "value_changed" );
504                     }
505                     /* Otherwise, send message to the input if the user has
506                      * finished dragging the slider */
507                     else if( p_intf->p_sys->b_slider_free )
508                     {
509                         double f_pos = (double)newvalue / 100.0;
510
511                         /* release the lock to be able to seek */
512                         vlc_mutex_unlock( &p_input->object_lock );
513                         var_SetFloat( p_input, "position", f_pos );
514                         vlc_mutex_lock( &p_input->object_lock );
515
516                         /* Update the old value */
517                         p_intf->p_sys->i_adj_oldvalue = newvalue;
518                     }
519                 }
520             }
521         }
522         vlc_mutex_unlock( &p_input->object_lock );
523     }
524     else if( p_intf->p_sys->b_playing && !intf_ShouldDie( p_intf ) )
525     {
526         E_(GtkModeManage)( p_intf );
527         p_intf->p_sys->b_playing = 0;
528     }
529
530 #ifndef NEED_GTK2_MAIN
531     if( intf_ShouldDie( p_intf ) )
532     {
533         vlc_mutex_unlock( &p_intf->change_lock );
534
535         /* Prepare to die, young Skywalker */
536         gtk_main_quit();
537
538         return FALSE;
539     }
540 #endif
541
542     vlc_mutex_unlock( &p_intf->change_lock );
543
544     return TRUE;
545 }
546
547 /*****************************************************************************
548  * GtkDisplayDate: display stream date
549  *****************************************************************************
550  * This function displays the current date related to the position in
551  * the stream. It is called whenever the slider changes its value.
552  * The lock has to be taken before you call the function.
553  *****************************************************************************/
554 void E_(GtkDisplayDate)( GtkAdjustment *p_adj, gpointer userdata )
555 {
556     intf_thread_t *p_intf;
557
558     p_intf = (intf_thread_t*) userdata;
559     if (p_intf == NULL)
560         return;
561
562     if( p_intf->p_sys->p_input )
563     {
564         char psz_time[ MSTRTIME_MAX_SIZE ];
565         int64_t i_seconds;
566
567         i_seconds = var_GetTime( p_intf->p_sys->p_input, "time" ) / I64C(1000000 );
568         secstotimestr( psz_time, i_seconds );
569
570         gtk_label_set_text( GTK_LABEL( p_intf->p_sys->p_slider_label ),
571                             psz_time );
572      }
573 }
574
575 /*****************************************************************************
576  * GtkModeManage: actualize the aspect of the interface whenever the input
577  *                changes.
578  *****************************************************************************
579  * The lock has to be taken before you call the function.
580  *****************************************************************************/
581 gint E_(GtkModeManage)( intf_thread_t * p_intf )
582 {
583     GtkWidget *     p_slider = NULL;
584     vlc_bool_t      b_control;
585
586     if ( p_intf->p_sys->p_window == NULL )
587         msg_Err( p_intf, "Main widget not found" );
588
589     p_slider = lookup_widget( p_intf->p_sys->p_window, "timeSlider");
590     if (p_slider == NULL)
591         msg_Err( p_intf, "Slider widget not found" );
592
593     /* controls unavailable */
594     b_control = 0;
595
596     /* show the box related to current input mode */
597     if( p_intf->p_sys->p_input )
598     {
599         /* initialize and show slider for seekable streams */
600         {
601             gtk_widget_show( GTK_WIDGET( p_slider ) );
602         }
603
604         /* control buttons for free pace streams */
605         b_control = p_intf->p_sys->p_input->b_can_pace_control;
606
607         msg_Dbg( p_intf, "stream has changed, refreshing interface" );
608     }
609
610     /* set control items */
611     gtk_widget_set_sensitive( lookup_widget( p_intf->p_sys->p_window, "tbRewind"), b_control );
612     gtk_widget_set_sensitive( lookup_widget( p_intf->p_sys->p_window, "tbPause"), b_control );
613     gtk_widget_set_sensitive( lookup_widget( p_intf->p_sys->p_window, "tbForward"), b_control );
614     return TRUE;
615 }