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