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