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