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