]> git.sesse.net Git - vlc/blob - modules/gui/pda/pda.c
Pull cancellation into (most) remaining interfaces
[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_common.h>
35 #include <vlc_plugin.h>
36 #include <vlc_input.h>
37 #include <vlc_interface.h>
38 #include <vlc_playlist.h>
39
40 #include <gtk/gtk.h>
41
42 #include "pda_callbacks.h"
43 #include "pda_interface.h"
44 #include "pda_support.h"
45 #include "pda.h"
46
47 /*****************************************************************************
48  * Local prototypes.
49  *****************************************************************************/
50 static int  Open         ( vlc_object_t * );
51 static void Close        ( vlc_object_t * );
52 static void Run          ( intf_thread_t * );
53
54 void GtkAutoPlayFile     ( vlc_object_t * );
55 static int Manage        ( intf_thread_t *p_intf );
56 void GtkDisplayDate  ( GtkAdjustment *p_adj, gpointer userdata );
57 gint GtkModeManage   ( intf_thread_t * p_intf );
58
59 /*****************************************************************************
60  * Module descriptor
61  *****************************************************************************/
62 #define AUTOPLAYFILE_TEXT  N_("Autoplay selected file")
63 #define AUTOPLAYFILE_LONGTEXT N_("Automatically play a file when selected in the "\
64         "file selection list")
65
66 /*****************************************************************************
67  * Module descriptor
68  *****************************************************************************/
69 vlc_module_begin();
70     set_description( N_("PDA Linux Gtk2+ interface") );
71     set_category( CAT_INTERFACE );
72     set_subcategory( SUBCAT_INTERFACE_MAIN );
73 //    add_bool( "pda-autoplayfile", 1, GtkAutoPlayFile, AUTOPLAYFILE_TEXT, AUTOPLAYFILE_LONGTEXT, true );
74     set_capability( "interface", 0 );
75     set_callbacks( Open, Close );
76     add_shortcut( "pda" );
77 vlc_module_end();
78
79 /*****************************************************************************
80  * Open: initialize and create window
81  *****************************************************************************/
82 static int Open( vlc_object_t *p_this )
83 {
84     intf_thread_t *p_intf = (intf_thread_t *)p_this;
85
86     /* Allocate instance and initialize some members */
87     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
88     if( p_intf->p_sys == NULL )
89     {
90         msg_Err( p_intf, "out of memory" );
91         return VLC_ENOMEM;
92     }
93
94 #ifdef NEED_GTK2_MAIN
95     msg_Dbg( p_intf, "Using gui-helper" );
96     p_intf->p_sys->p_gtk_main =
97         module_Need( p_this, "gui-helper", "gtk2", true );
98     if( p_intf->p_sys->p_gtk_main == NULL )
99     {
100         free( p_intf->p_sys );
101         return VLC_ENOMOD;
102     }
103 #endif
104
105     /* Initialize Gtk+ thread */
106     p_intf->p_sys->p_input = NULL;
107
108     p_intf->p_sys->b_autoplayfile = 1;
109     p_intf->p_sys->b_playing = 0;
110     p_intf->p_sys->b_slider_free = 1;
111
112     p_intf->pf_run = Run;
113
114     return VLC_SUCCESS;
115 }
116
117 /*****************************************************************************
118  * Close: destroy interface window
119  *****************************************************************************/
120 static void Close( vlc_object_t *p_this )
121 {
122     intf_thread_t *p_intf = (intf_thread_t *)p_this;
123
124     if( p_intf->p_sys->p_input )
125     {
126         vlc_object_release( p_intf->p_sys->p_input );
127     }
128
129 #ifdef NEED_GTK2_MAIN
130     msg_Dbg( p_intf, "Releasing gui-helper" );
131     module_Unneed( p_intf, p_intf->p_sys->p_gtk_main );
132 #endif
133
134     /* Destroy structure */
135     free( p_intf->p_sys );
136 }
137
138 /*****************************************************************************
139  * Run: Gtk+ thread
140  *****************************************************************************
141  * this part of the interface is in a separate thread so that we can call
142  * gtk_main() from within it without annoying the rest of the program.
143  *****************************************************************************/
144 static void Run( intf_thread_t *p_intf )
145 {
146 #ifndef NEED_GTK2_MAIN
147     /* gtk_init needs to know the command line. We don't care, so we
148      * give it an empty one */
149     char  *p_args[] = { "", NULL };
150     char **pp_args  = p_args;
151     int    i_args   = 1;
152     int    i_dummy;
153 #endif
154     playlist_t        *p_playlist;
155     GtkCellRenderer   *p_renderer = NULL;
156     GtkTreeViewColumn *p_column   = NULL;
157     GtkListStore      *p_filelist = NULL;
158     GtkListStore      *p_playlist_store = NULL;
159     int canc = vlc_savecancel();
160
161 #ifndef NEED_GTK2_MAIN
162     gtk_set_locale ();
163     msg_Dbg( p_intf, "Starting pda GTK2+ interface" );
164     gtk_init( &i_args, &pp_args );
165 #else
166     /* Initialize Gtk+ */
167     msg_Dbg( p_intf, "Starting pda GTK2+ interface thread" );
168     gdk_threads_enter();
169 #endif
170
171     /* Create some useful widgets that will certainly be used */
172     add_pixmap_directory(config_GetDataDir());
173
174     p_intf->p_sys->p_window = create_pda();
175     if (p_intf->p_sys->p_window == NULL)
176     {
177         msg_Err( p_intf, "unable to create pda interface" );
178     }
179
180     /* Store p_intf to keep an eye on it */
181     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
182                          "p_intf", p_intf );
183
184     /* Set the title of the main window */
185     gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_window),
186                           VOUT_TITLE " (PDA Linux interface)");
187
188     /* Get the notebook object */
189     p_intf->p_sys->p_notebook = GTK_NOTEBOOK( gtk_object_get_data(
190         GTK_OBJECT( p_intf->p_sys->p_window ), "notebook" ) );
191
192     /* Get the slider object */
193     p_intf->p_sys->p_slider = (GtkHScale*) lookup_widget( p_intf->p_sys->p_window, "timeSlider" );
194     p_intf->p_sys->p_slider_label = (GtkLabel*) lookup_widget( p_intf->p_sys->p_window, "timeLabel" );
195     if (p_intf->p_sys->p_slider == NULL)
196         msg_Err( p_intf, "Time slider widget not found." );
197     if (p_intf->p_sys->p_slider_label == NULL)
198         msg_Err( p_intf, "Time label widget not found." );
199
200     /* Connect the date display to the slider */
201     p_intf->p_sys->p_adj = gtk_range_get_adjustment( GTK_RANGE(p_intf->p_sys->p_slider) );
202     if (p_intf->p_sys->p_adj == NULL)
203         msg_Err( p_intf, "Adjustment range not found." );
204     g_signal_connect( GTK_OBJECT( p_intf->p_sys->p_adj ), "value_changed",
205                          G_CALLBACK( GtkDisplayDate ), p_intf );
206     p_intf->p_sys->f_adj_oldvalue = 0;
207     p_intf->p_sys->i_adj_oldvalue = 0;
208
209     /* BEGIN OF FILEVIEW GTK_TREE_VIEW */
210     p_intf->p_sys->p_tvfile = NULL;
211     p_intf->p_sys->p_tvfile = (GtkTreeView *) lookup_widget( p_intf->p_sys->p_window,
212                                                              "tvFileList");
213     if (NULL == p_intf->p_sys->p_tvfile)
214        msg_Err(p_intf, "Error obtaining pointer to File List");
215
216     /* Insert columns 0 */
217     p_renderer = gtk_cell_renderer_text_new ();
218     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 0, (gchar *) N_("Filename"), p_renderer, NULL);
219     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 0 );
220     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 0 );
221     gtk_tree_view_column_set_sort_column_id(p_column, 0);
222     /* Insert columns 1 */
223     p_renderer = gtk_cell_renderer_text_new ();
224     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 1, (gchar *) N_("Permissions"), p_renderer, NULL);
225     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 1 );
226     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 1 );
227     gtk_tree_view_column_set_sort_column_id(p_column, 1);
228     /* Insert columns 2 */
229     p_renderer = gtk_cell_renderer_text_new ();
230     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 2, (gchar *) N_("Size"), p_renderer, NULL);
231     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 2 );
232     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 2 );
233     gtk_tree_view_column_set_sort_column_id(p_column, 2);
234     /* Insert columns 3 */
235     p_renderer = gtk_cell_renderer_text_new ();
236     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 3, (gchar *) N_("Owner"), p_renderer, NULL);
237     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 3 );
238     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 3 );
239     gtk_tree_view_column_set_sort_column_id(p_column, 3);
240     /* Insert columns 4 */
241     p_renderer = gtk_cell_renderer_text_new ();
242     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 4, (gchar *) N_("Group"), p_renderer, NULL);
243     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 4 );
244     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 4 );
245     gtk_tree_view_column_set_sort_column_id(p_column, 4);
246
247     /* Get new directory listing */
248     p_filelist = gtk_list_store_new (5,
249                 G_TYPE_STRING, /* Filename */
250                 G_TYPE_STRING, /* permissions */
251                 G_TYPE_UINT64, /* File size */
252                 G_TYPE_STRING, /* Owner */
253                 G_TYPE_STRING);/* Group */
254     ReadDirectory(p_intf, p_filelist, (char*)".");
255     gtk_tree_view_set_model(GTK_TREE_VIEW(p_intf->p_sys->p_tvfile), GTK_TREE_MODEL(p_filelist));
256     g_object_unref(p_filelist);     /* Model will be released by GtkTreeView */
257     gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(p_intf->p_sys->p_tvfile)),GTK_SELECTION_MULTIPLE);
258
259     /* Column properties */
260     gtk_tree_view_set_headers_visible(p_intf->p_sys->p_tvfile, TRUE);
261     gtk_tree_view_columns_autosize(p_intf->p_sys->p_tvfile);
262     gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(p_intf->p_sys->p_tvfile),TRUE);
263     /* END OF FILEVIEW GTK_TREE_VIEW */
264
265     /* BEGIN OF PLAYLIST GTK_TREE_VIEW */
266     p_intf->p_sys->p_tvplaylist = NULL;
267     p_intf->p_sys->p_tvplaylist = (GtkTreeView *) lookup_widget( p_intf->p_sys->p_window, "tvPlaylist");
268     if (NULL == p_intf->p_sys->p_tvplaylist)
269        msg_Err(p_intf, "Error obtaining pointer to Play List");
270
271     /* Columns 1 */
272     p_renderer = gtk_cell_renderer_text_new ();
273     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 0, (gchar *) N_("Filename"), p_renderer, NULL);
274     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvplaylist, 0 );
275     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 0 );
276     gtk_tree_view_column_set_sort_column_id(p_column, 0);
277     /* Column 2 */
278     p_renderer = gtk_cell_renderer_text_new ();
279     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 1, (gchar *) N_("Time"), p_renderer, NULL);
280     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvplaylist, 1 );
281     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 1 );
282     gtk_tree_view_column_set_sort_column_id(p_column, 1);
283 #if 0
284     /* Column 3 - is a hidden column used for reliable deleting items from the underlying playlist */
285     p_renderer = gtk_cell_renderer_text_new ();
286     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 2, (gchar *) N_("Index"), p_renderer, NULL);
287     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvplaylist, 2 );
288     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 2 );
289     gtk_tree_view_column_set_sort_column_id(p_column, 2);
290 #endif
291     /* update the playlist */
292     p_playlist = pl_Yield( p_intf );
293     p_playlist_store = gtk_list_store_new (3,
294                 G_TYPE_STRING, /* Filename */
295                 G_TYPE_STRING, /* Time */
296                 G_TYPE_UINT);  /* Hidden index */
297     PlaylistRebuildListStore(p_intf,p_playlist_store, p_playlist);
298     gtk_tree_view_set_model(GTK_TREE_VIEW(p_intf->p_sys->p_tvplaylist), GTK_TREE_MODEL(p_playlist_store));
299     g_object_unref(p_playlist_store);
300     pl_Release( p_intf ); /* Free the playlist */
301     gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(p_intf->p_sys->p_tvplaylist)),GTK_SELECTION_MULTIPLE);
302
303     /* Column properties */
304     gtk_tree_view_set_headers_visible(p_intf->p_sys->p_tvplaylist, TRUE);
305     gtk_tree_view_columns_autosize(p_intf->p_sys->p_tvplaylist);
306     gtk_tree_view_set_headers_clickable(p_intf->p_sys->p_tvplaylist, TRUE);
307     /* END OF PLAYLIST GTK_TREE_VIEW */
308
309     /* Hide the Preference TAB for now. */
310     GtkWidget *p_preference_tab = NULL;
311     p_preference_tab = gtk_notebook_get_nth_page(p_intf->p_sys->p_notebook,5);
312     if (p_preference_tab != NULL)
313       gtk_widget_hide(p_preference_tab);
314
315     /* Show the control window */
316     gtk_widget_show( p_intf->p_sys->p_window );
317
318 #ifdef NEED_GTK2_MAIN
319     msg_Dbg( p_intf, "Manage GTK keyboard events using threads" );
320     while( !intf_ShouldDie( p_intf ) )
321     {
322         Manage( p_intf );
323
324         /* Sleep to avoid using all CPU - since some interfaces need to
325          * access keyboard events, a 100ms delay is a good compromise */
326         gdk_threads_leave();
327         if (vlc_CPU() & CPU_CAPABILITY_FPU)
328             msleep( INTF_IDLE_SLEEP );
329         else
330             msleep( 1000 );
331         gdk_threads_enter();
332     }
333 #else
334     msg_Dbg( p_intf, "Manage GTK keyboard events using timeouts" );
335     /* Sleep to avoid using all CPU - since some interfaces needs to access
336      * keyboard events, a 1000ms delay is a good compromise */
337     if (vlc_CPU() & CPU_CAPABILITY_FPU)
338         i_dummy = gtk_timeout_add( INTF_IDLE_SLEEP / 1000, (GtkFunction)Manage, p_intf );
339     else
340         i_dummy = gtk_timeout_add( 1000, (GtkFunction)Manage, p_intf );
341
342     /* Enter Gtk mode */
343     gtk_main();
344     /* Remove the timeout */
345     gtk_timeout_remove( i_dummy );
346 #endif
347
348     gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_window) );
349 #ifdef NEED_GTK2_MAIN
350     gdk_threads_leave();
351 #endif
352     vlc_restorecancel(canc);
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 = false;
381         }
382         else
383         {
384             p_intf->p_sys->b_autoplayfile = 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_object_lock( p_input );
423         if( vlc_object_alive (p_input) )
424         {
425             playlist_t *p_playlist;
426
427             GtkModeManage( p_intf );
428             p_intf->p_sys->b_playing = 1;
429
430             /* update playlist interface */
431             p_playlist = pl_Yield( p_intf );
432             if (p_playlist != NULL)
433             {
434                 p_liststore = gtk_list_store_new (3,
435                                             G_TYPE_STRING,
436                                             G_TYPE_STRING,
437                                             G_TYPE_UINT);  /* Hidden index */
438                 PlaylistRebuildListStore(p_intf, p_liststore, p_playlist);
439                 gtk_tree_view_set_model(p_intf->p_sys->p_tvplaylist, (GtkTreeModel*) p_liststore);
440                 g_object_unref(p_liststore);
441                 pl_Release( p_intf );
442             }
443
444             /* Manage the slider */
445             i_time = var_GetTime( p_intf->p_sys->p_input, "time" );
446             i_length = var_GetTime( p_intf->p_sys->p_input, "length" );
447
448             if (vlc_CPU() & CPU_CAPABILITY_FPU)
449             {
450                 /* Manage the slider for CPU_CAPABILITY_FPU hardware */
451                 if( p_intf->p_sys->b_playing )
452                 {
453                     float newvalue = p_intf->p_sys->p_adj->value;
454
455                     /* If the user hasn't touched the slider since the last time,
456                      * then the input can safely change it */
457                     if( newvalue == p_intf->p_sys->f_adj_oldvalue )
458                     {
459                         /* Update the value */
460                         p_intf->p_sys->p_adj->value =
461                         p_intf->p_sys->f_adj_oldvalue =
462                             ( 100 * i_time ) / i_length;
463                         g_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
464                                                  "value_changed" );
465                     }
466                     /* Otherwise, send message to the input if the user has
467                      * finished dragging the slider */
468                     else if( p_intf->p_sys->b_slider_free )
469                     {
470                         double f_pos = (double)newvalue / 100.0;
471
472                         /* release the lock to be able to seek */
473                         vlc_object_unlock( p_input );
474                         var_SetFloat( p_input, "position", f_pos );
475                         vlc_object_lock( p_input );
476
477                         /* Update the old value */
478                         p_intf->p_sys->f_adj_oldvalue = newvalue;
479                     }
480                 }
481             }
482             else
483             {
484                 /* Manage the slider without CPU_CAPABILITY_FPU hardware */
485                 if( p_intf->p_sys->b_playing )
486                 {
487                     off_t newvalue = p_intf->p_sys->p_adj->value;
488
489                     /* If the user hasn't touched the slider since the last time,
490                      * then the input can safely change it */
491                     if( newvalue == p_intf->p_sys->i_adj_oldvalue )
492                     {
493                         /* Update the value */
494                         p_intf->p_sys->p_adj->value =
495                         p_intf->p_sys->i_adj_oldvalue =
496                             ( 100 * i_time ) / i_length;
497                         g_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
498                                                  "value_changed" );
499                     }
500                     /* Otherwise, send message to the input if the user has
501                      * finished dragging the slider */
502                     else if( p_intf->p_sys->b_slider_free )
503                     {
504                         double f_pos = (double)newvalue / 100.0;
505
506                         /* release the lock to be able to seek */
507                         vlc_object_unlock( p_input );
508                         var_SetFloat( p_input, "position", f_pos );
509                         vlc_object_lock( p_input );
510
511                         /* Update the old value */
512                         p_intf->p_sys->i_adj_oldvalue = newvalue;
513                     }
514                 }
515             }
516         }
517         vlc_object_unlock( p_input );
518     }
519     else if( p_intf->p_sys->b_playing && !intf_ShouldDie( p_intf ) )
520     {
521         GtkModeManage( p_intf );
522         p_intf->p_sys->b_playing = 0;
523     }
524
525 #ifndef NEED_GTK2_MAIN
526     if( intf_ShouldDie( p_intf ) )
527     {
528         vlc_mutex_unlock( &p_intf->change_lock );
529
530         /* Prepare to die, young Skywalker */
531         gtk_main_quit();
532
533         return FALSE;
534     }
535 #endif
536
537     vlc_mutex_unlock( &p_intf->change_lock );
538
539     return TRUE;
540 }
541
542 /*****************************************************************************
543  * GtkDisplayDate: display stream date
544  *****************************************************************************
545  * This function displays the current date related to the position in
546  * the stream. It is called whenever the slider changes its value.
547  * The lock has to be taken before you call the function.
548  *****************************************************************************/
549 void GtkDisplayDate( GtkAdjustment *p_adj, gpointer userdata )
550 {
551     (void)p_adj;
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" ) / INT64_C(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 GtkModeManage( intf_thread_t * p_intf )
579 {
580     GtkWidget *     p_slider = NULL;
581     bool      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 }