]> git.sesse.net Git - vlc/blob - modules/gui/pda/pda.c
PDA Interface:
[vlc] / modules / gui / pda / pda.c
1 /*****************************************************************************
2  * pda.c : PDA Gtk2 plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id: pda.c,v 1.13 2003/11/30 11:22:29 jpsaman Exp $
6  *
7  * Authors: Jean-Paul Saman <jpsaman@wxs.nl>
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., 59 Temple Place - Suite 330, Boston, MA  02111, 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/intf.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 );
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     add_category_hint( N_("Miscellaneous"), NULL, VLC_TRUE );
67 //    add_bool( "pda-autoplayfile", 1, GtkAutoPlayFile, AUTOPLAYFILE_TEXT, AUTOPLAYFILE_LONGTEXT, VLC_TRUE );
68     set_description( _("PDA Linux Gtk2+ interface") );
69     set_capability( "interface", 70 );
70     set_callbacks( Open, Close );
71     add_shortcut( "pda" );
72 vlc_module_end();
73
74 /*****************************************************************************
75  * Open: initialize and create window
76  *****************************************************************************/
77 static int Open( vlc_object_t *p_this )
78 {
79     intf_thread_t *p_intf = (intf_thread_t *)p_this;
80
81     /* Allocate instance and initialize some members */
82     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
83     if( p_intf->p_sys == NULL )
84     {
85         msg_Err( p_intf, "out of memory" );
86         return VLC_ENOMEM;
87     }
88
89 #ifdef NEED_GTK2_MAIN
90     msg_Dbg( p_intf, "Using gui-helper" );
91     p_intf->p_sys->p_gtk_main = module_Need( p_this, "gui-helper", "gtk2" );
92     if( p_intf->p_sys->p_gtk_main == NULL )
93     {
94         free( p_intf->p_sys );
95         return VLC_ENOMOD;
96     }
97 #endif
98
99     /* Initialize Gtk+ thread */
100     p_intf->p_sys->p_input = NULL;
101
102     p_intf->p_sys->b_autoplayfile = 1;
103     p_intf->p_sys->b_playing = 0;
104     p_intf->p_sys->b_slider_free = 1;
105
106     p_intf->pf_run = Run;
107
108     return VLC_SUCCESS;
109 }
110
111 /*****************************************************************************
112  * Close: destroy interface window
113  *****************************************************************************/
114 static void Close( vlc_object_t *p_this )
115 {
116     intf_thread_t *p_intf = (intf_thread_t *)p_this;
117
118     if( p_intf->p_sys->p_input )
119     {
120         vlc_object_release( p_intf->p_sys->p_input );
121     }
122
123 #ifdef NEED_GTK2_MAIN
124     msg_Dbg( p_intf, "Releasing gui-helper" );
125     module_Unneed( p_intf, p_intf->p_sys->p_gtk_main );
126 #endif
127
128     /* Destroy structure */
129     free( p_intf->p_sys );
130 }
131
132 /*****************************************************************************
133  * Run: Gtk+ thread
134  *****************************************************************************
135  * this part of the interface is in a separate thread so that we can call
136  * gtk_main() from within it without annoying the rest of the program.
137  *****************************************************************************/
138 static void Run( intf_thread_t *p_intf )
139 {
140 #ifndef NEED_GTK2_MAIN
141     /* gtk_init needs to know the command line. We don't care, so we
142      * give it an empty one */
143     char  *p_args[] = { "", NULL };
144     char **pp_args  = p_args;
145     int    i_args   = 1;
146     int    i_dummy;
147 #endif
148     GtkCellRenderer   *renderer = NULL;
149     GtkTreeViewColumn *column   = NULL;
150     GtkListStore      *filelist = NULL;
151     GtkListStore      *playlist = NULL;
152
153 #ifndef NEED_GTK2_MAIN
154     gtk_set_locale ();
155     msg_Dbg( p_intf, "Starting pda GTK2+ interface" );
156     gtk_init( &i_args, &pp_args );
157 #else
158     /* Initialize Gtk+ */
159     msg_Dbg( p_intf, "Starting pda GTK2+ interface thread" );
160     gdk_threads_enter();
161 #endif
162
163     /* Create some useful widgets that will certainly be used */
164 /* FIXME: magic path */
165     add_pixmap_directory("share");
166     add_pixmap_directory("/usr/share/vlc");
167
168     /* Path for pixmaps under linupy 1.4 */
169     add_pixmap_directory("/usr/local/share/pixmaps/vlc");
170     /* Path for pixmaps under linupy 2.0 */
171     add_pixmap_directory("/usr/share/pixmaps/vlc");
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 = GTK_HSCALE( gtk_object_get_data(
193         GTK_OBJECT( p_intf->p_sys->p_window ), "timeSlider" ) );
194     p_intf->p_sys->p_slider_label = GTK_LABEL( gtk_object_get_data(
195         GTK_OBJECT( p_intf->p_sys->p_window ), "timeLabel" ) );
196
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 #if 0
203     /* Connect the date display to the slider */
204     msg_Dbg( p_intf, "setting slider adjustment ... " );
205 #define P_SLIDER GTK_RANGE( gtk_object_get_data( \
206                          GTK_OBJECT( p_intf->p_sys->p_window ), "timeSlider" ) )
207     p_intf->p_sys->p_adj = gtk_range_get_adjustment( P_SLIDER );
208     if (p_intf->p_sys->p_adj == NULL)
209         msg_Err( p_intf, "Adjustment range not found." );
210     gtk_signal_connect ( GTK_OBJECT( p_intf->p_sys->p_adj ), "value_changed",
211                          GTK_SIGNAL_FUNC( E_(GtkDisplayDate) ), NULL );
212     p_intf->p_sys->f_adj_oldvalue = 0;
213     p_intf->p_sys->i_adj_oldvalue = 0;
214 #undef P_SLIDER
215     msg_Dbg( p_intf, "setting slider adjustment ... done" );
216 #endif
217
218     /* BEGIN OF FILEVIEW GTK_TREE_VIEW */
219     p_intf->p_sys->p_tvfile = NULL;
220     p_intf->p_sys->p_tvfile = (GtkTreeView *) lookup_widget( p_intf->p_sys->p_window,
221                                                              "tvFileList");
222     if (NULL == p_intf->p_sys->p_tvfile)
223        msg_Err(p_intf, "Error obtaining pointer to File List");
224
225     /* Insert columns 0 */
226     renderer = gtk_cell_renderer_text_new ();
227     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 0, _("Filename"), renderer, NULL);
228     column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 0 );
229     gtk_tree_view_column_add_attribute(column, renderer, "text", 0 );
230     gtk_tree_view_column_set_sort_column_id(column, 0);
231     /* Insert columns 1 */
232     renderer = gtk_cell_renderer_text_new ();
233     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 1, _("Permissions"), renderer, NULL);
234     column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 1 );
235     gtk_tree_view_column_add_attribute(column, renderer, "text", 1 );
236     gtk_tree_view_column_set_sort_column_id(column, 1);
237     /* Insert columns 2 */
238     renderer = gtk_cell_renderer_text_new ();
239     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 2, _("Size"), renderer, NULL);
240     column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 2 );
241     gtk_tree_view_column_add_attribute(column, renderer, "text", 2 );
242     gtk_tree_view_column_set_sort_column_id(column, 2);
243     /* Insert columns 3 */
244     renderer = gtk_cell_renderer_text_new ();
245     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 3, _("Owner"), renderer, NULL);
246     column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 3 );
247     gtk_tree_view_column_add_attribute(column, renderer, "text", 3 );
248     gtk_tree_view_column_set_sort_column_id(column, 3);
249     /* Insert columns 4 */
250     renderer = gtk_cell_renderer_text_new ();
251     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 4, _("Group"), renderer, NULL);
252     column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 4 );
253     gtk_tree_view_column_add_attribute(column, renderer, "text", 4 );
254     gtk_tree_view_column_set_sort_column_id(column, 4);
255
256     /* Get new directory listing */
257     filelist = gtk_list_store_new (5,
258                 G_TYPE_STRING, /* Filename */
259                 G_TYPE_STRING, /* permissions */
260                 G_TYPE_UINT64, /* File size */
261                 G_TYPE_STRING, /* Owner */
262                 G_TYPE_STRING);/* Group */
263     ReadDirectory(p_intf, filelist, ".");
264     gtk_tree_view_set_model(GTK_TREE_VIEW(p_intf->p_sys->p_tvfile), GTK_TREE_MODEL(filelist));
265     g_object_unref(filelist);     /* Model will be released by GtkTreeView */
266     gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(p_intf->p_sys->p_tvfile)),GTK_SELECTION_MULTIPLE);
267
268     /* Column properties */
269     gtk_tree_view_set_headers_visible(p_intf->p_sys->p_tvfile, TRUE);
270     gtk_tree_view_columns_autosize(p_intf->p_sys->p_tvfile);
271     gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(p_intf->p_sys->p_tvfile),TRUE);
272     /* END OF FILEVIEW GTK_TREE_VIEW */
273
274     /* BEGIN OF PLAYLIST GTK_TREE_VIEW */
275     p_intf->p_sys->p_tvplaylist = NULL;
276     p_intf->p_sys->p_tvplaylist = (GtkTreeView *) lookup_widget( p_intf->p_sys->p_window, "tvPlaylist");   
277     if (NULL == p_intf->p_sys->p_tvplaylist)
278        msg_Err(p_intf, "Error obtaining pointer to Play List");
279
280     /* Columns 1 */
281     renderer = gtk_cell_renderer_text_new ();
282     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 0, _("Filename"), renderer, NULL);
283     column = gtk_tree_view_get_column(p_intf->p_sys->p_tvplaylist, 0 );
284     gtk_tree_view_column_add_attribute(column, renderer, "text", 0 );
285     gtk_tree_view_column_set_sort_column_id(column, 0);
286     /* Column 2 */
287     renderer = gtk_cell_renderer_text_new ();
288     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 1, _("Time"), renderer, NULL);
289     column = gtk_tree_view_get_column(p_intf->p_sys->p_tvplaylist, 1 );
290     gtk_tree_view_column_add_attribute(column, renderer, "text", 1 );
291     gtk_tree_view_column_set_sort_column_id(column, 1);
292 #if 0
293     /* Column 3 - is a hidden column used for reliable deleting items from the underlying playlist */
294     renderer = gtk_cell_renderer_text_new ();
295     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 2, _("Index"), renderer, NULL);
296     column = gtk_tree_view_get_column(p_intf->p_sys->p_tvplaylist, 2 );
297     gtk_tree_view_column_add_attribute(column, renderer, "text", 2 );
298     gtk_tree_view_column_set_sort_column_id(column, 2);
299 #endif
300     /* update the playlist */
301     playlist = gtk_list_store_new (3,
302                 G_TYPE_STRING, /* Filename */
303                 G_TYPE_STRING, /* Time */
304                 G_TYPE_UINT);  /* Hidden index */
305     PlaylistRebuildListStore( playlist, vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ));
306     gtk_tree_view_set_model(GTK_TREE_VIEW(p_intf->p_sys->p_tvplaylist), GTK_TREE_MODEL(playlist));
307     g_object_unref(playlist);
308     gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(p_intf->p_sys->p_tvplaylist)),GTK_SELECTION_MULTIPLE);
309
310     /* Column properties */
311     gtk_tree_view_set_headers_visible(p_intf->p_sys->p_tvplaylist, TRUE);
312     gtk_tree_view_columns_autosize(p_intf->p_sys->p_tvplaylist);
313     gtk_tree_view_set_headers_clickable(p_intf->p_sys->p_tvplaylist, TRUE);
314     /* END OF PLAYLIST GTK_TREE_VIEW */
315
316     /* Show the control window */
317     gtk_widget_show( p_intf->p_sys->p_window );
318
319 #ifdef NEED_GTK2_MAIN
320     msg_Dbg( p_intf, "Manage GTK keyboard events using threads" );
321     while( !p_intf->b_die )
322     {
323         Manage( p_intf );
324
325         /* Sleep to avoid using all CPU - since some interfaces need to
326          * access keyboard events, a 100ms delay is a good compromise */
327         gdk_threads_leave();
328         if (p_intf->p_libvlc->i_cpu & CPU_CAPABILITY_FPU)
329             msleep( INTF_IDLE_SLEEP );
330         else
331             msleep( 1000 );
332         gdk_threads_enter();
333     }
334 #else
335     msg_Dbg( p_intf, "Manage GTK keyboard events using timeouts" );
336     /* Sleep to avoid using all CPU - since some interfaces needs to access
337      * keyboard events, a 1000ms delay is a good compromise */
338     if (p_intf->p_libvlc->i_cpu & CPU_CAPABILITY_FPU)
339         i_dummy = gtk_timeout_add( INTF_IDLE_SLEEP / 1000, (GtkFunction)Manage, p_intf );
340     else
341         i_dummy = gtk_timeout_add( 1000, (GtkFunction)Manage, p_intf );
342
343     /* Enter Gtk mode */
344     gtk_main();
345     /* Remove the timeout */
346     gtk_timeout_remove( i_dummy );
347 #endif
348
349     gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_window) );
350 #ifdef NEED_GTK2_MAIN
351     gdk_threads_leave();
352 #endif
353 }
354
355 /*****************************************************************************
356  * GtkAutoplayFile: Autoplay file depending on configuration settings
357  *****************************************************************************/
358 void GtkAutoPlayFile( vlc_object_t *p_this )
359 {
360     GtkWidget *cbautoplay;
361     intf_thread_t *p_intf;
362     int i_index;
363     vlc_list_t *p_list = vlc_list_find( p_this, VLC_OBJECT_INTF,
364                                         FIND_ANYWHERE );
365
366     for( i_index = 0; i_index < p_list->i_count; i_index++ )
367     {
368         p_intf = (intf_thread_t *)p_list->p_values[i_index].p_object ;
369
370         if( strcmp( MODULE_STRING, p_intf->p_module->psz_object_name ) )
371         {
372             continue;
373         }
374         cbautoplay = GTK_WIDGET( gtk_object_get_data(
375                             GTK_OBJECT( p_intf->p_sys->p_window ),
376                             "cbautoplay" ) );
377
378         if( !config_GetInt( p_this, "pda-autoplayfile" ) )
379         {
380             p_intf->p_sys->b_autoplayfile = VLC_FALSE;
381         }
382         else
383         {
384             p_intf->p_sys->b_autoplayfile = VLC_TRUE;
385         }
386         gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( cbautoplay ),
387                                       p_intf->p_sys->b_autoplayfile );
388     }
389     vlc_list_release( p_list );
390 }
391
392 /* following functions are local */
393
394 /*****************************************************************************
395  * Manage: manage main thread messages
396  *****************************************************************************
397  * In this function, called approx. 10 times a second, we check what the
398  * main program wanted to tell us.
399  *****************************************************************************/
400 static int Manage( intf_thread_t *p_intf )
401 {
402     GtkListStore *p_liststore;
403     vlc_mutex_lock( &p_intf->change_lock );
404
405     /* Update the input */
406     if( p_intf->p_sys->p_input == NULL )
407     {
408         p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
409                                                           FIND_ANYWHERE );
410     }
411     else if( p_intf->p_sys->p_input->b_dead )
412     {
413         vlc_object_release( p_intf->p_sys->p_input );
414         p_intf->p_sys->p_input = NULL;
415     }
416
417     if( p_intf->p_sys->p_input )
418     {
419         input_thread_t *p_input = p_intf->p_sys->p_input;
420
421         vlc_mutex_lock( &p_input->stream.stream_lock );
422         if( !p_input->b_die )
423         {
424             /* New input or stream map change */
425             if( p_input->stream.b_changed )
426             {
427                 playlist_t *p_playlist;
428
429                 E_(GtkModeManage)( p_intf );
430                 p_intf->p_sys->b_playing = 1;
431
432                 /* update playlist interface */
433                 p_playlist = (playlist_t *) vlc_object_find( 
434                         p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
435                 if (p_playlist != NULL)
436                 {
437                     p_liststore = gtk_list_store_new (3,
438                                                G_TYPE_STRING,
439                                                G_TYPE_STRING,
440                                                G_TYPE_UINT);  /* Hidden index */
441                     PlaylistRebuildListStore(p_liststore, p_playlist);
442                     gtk_tree_view_set_model(p_intf->p_sys->p_tvplaylist, (GtkTreeModel*) p_liststore);
443                     g_object_unref(p_liststore);
444                     vlc_object_release( p_playlist );
445                 }
446             }
447
448             /* Manage the slider */
449             if (p_intf->p_libvlc->i_cpu & CPU_CAPABILITY_FPU)
450             {
451                 /* Manage the slider for CPU_CAPABILITY_FPU hardware */ 
452                 if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
453                 {
454                     float newvalue = p_intf->p_sys->p_adj->value;
455
456 #define p_area p_input->stream.p_selected_area
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. * p_area->i_tell ) / p_area->i_size;
465                         gtk_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                         off_t i_seek = ( newvalue * p_area->i_size ) / 100;
473
474                         /* release the lock to be able to seek */
475                         vlc_mutex_unlock( &p_input->stream.stream_lock );
476                         input_Seek( p_input, i_seek, INPUT_SEEK_SET );
477                         vlc_mutex_lock( &p_input->stream.stream_lock );
478
479                         /* Update the old value */
480                         p_intf->p_sys->f_adj_oldvalue = newvalue;
481                     }
482 #undef p_area
483                 }
484             }
485             else
486             {
487                 /* Manage the slider without CPU_CAPABILITY_FPU hardware */
488                 if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
489                 {
490                     off_t newvalue = p_intf->p_sys->p_adj->value;
491
492 #define p_area p_input->stream.p_selected_area
493                     /* If the user hasn't touched the slider since the last time,
494                      * then the input can safely change it */
495                     if( newvalue == p_intf->p_sys->i_adj_oldvalue )
496                     {
497                         /* Update the value */
498                         p_intf->p_sys->p_adj->value =
499                         p_intf->p_sys->i_adj_oldvalue =
500                             ( 100 * p_area->i_tell ) / p_area->i_size;
501                         gtk_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
502                                                  "value_changed" );
503                     }
504                     /* Otherwise, send message to the input if the user has
505                      * finished dragging the slider */
506                     else if( p_intf->p_sys->b_slider_free )
507                     {
508                         off_t i_seek = ( newvalue * p_area->i_size ) / 100;
509
510                         /* release the lock to be able to seek */
511                         vlc_mutex_unlock( &p_input->stream.stream_lock );
512                         input_Seek( p_input, i_seek, INPUT_SEEK_SET );
513                         vlc_mutex_lock( &p_input->stream.stream_lock );
514
515                         /* Update the old value */
516                         p_intf->p_sys->i_adj_oldvalue = newvalue;
517                     }
518 #undef p_area
519                 }
520             }
521         }
522         vlc_mutex_unlock( &p_input->stream.stream_lock );
523     }
524     else if( p_intf->p_sys->b_playing && !p_intf->b_die )
525     {
526         E_(GtkModeManage)( p_intf );
527         p_intf->p_sys->b_playing = 0;
528     }
529
530 #ifndef NEED_GTK2_MAIN
531     if( p_intf->b_die )
532     {
533         vlc_mutex_unlock( &p_intf->change_lock );
534
535         /* Prepare to die, young Skywalker */
536         gtk_main_quit();
537
538         return FALSE;
539     }
540 #endif
541
542     vlc_mutex_unlock( &p_intf->change_lock );
543
544     return TRUE;
545 }
546
547 /*****************************************************************************
548  * GtkDisplayDate: display stream date
549  *****************************************************************************
550  * This function displays the current date related to the position in
551  * the stream. It is called whenever the slider changes its value.
552  * The lock has to be taken before you call the function.
553  *****************************************************************************/
554 void E_(GtkDisplayDate)( GtkAdjustment *p_adj )
555 {
556     intf_thread_t *p_intf;
557
558     p_intf = gtk_object_get_data( GTK_OBJECT( p_adj ), "p_intf" );
559
560     if( p_intf->p_sys->p_input )
561     {
562 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
563         char psz_time[ OFFSETTOTIME_MAX_SIZE ];
564
565         gtk_label_set_text( GTK_LABEL( p_intf->p_sys->p_slider_label ),
566                         input_OffsetToTime( p_intf->p_sys->p_input, psz_time,
567                                    ( p_area->i_size * p_adj->value ) / 100 ) );
568 #undef p_area
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;
581     vlc_bool_t      b_control;
582
583 #define GETWIDGET( ptr, name ) GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( \
584                            p_intf->p_sys->ptr ) , ( name ) ) )
585     /* hide slider */
586     p_slider = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
587                            p_intf->p_sys->p_window ), "slider" ) );
588     gtk_widget_hide( GTK_WIDGET( p_slider ) );
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         if( p_intf->p_sys->p_input->stream.b_seekable )
598         {
599             msg_Dbg( p_intf, "Updating slider widget" );
600             if (p_intf->p_libvlc->i_cpu & CPU_CAPABILITY_FPU)
601                 p_intf->p_sys->p_adj->value = p_intf->p_sys->f_adj_oldvalue = 0;
602             else
603                 p_intf->p_sys->p_adj->value = p_intf->p_sys->i_adj_oldvalue = 0;
604             gtk_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
605                                      "value_changed" );
606             gtk_widget_show( GTK_WIDGET( p_slider ) );
607         }
608
609         /* control buttons for free pace streams */
610         b_control = p_intf->p_sys->p_input->stream.b_pace_control;
611
612         p_intf->p_sys->p_input->stream.b_changed = 0;
613         msg_Dbg( p_intf, "stream has changed, refreshing interface" );
614     }
615
616     /* set control items */
617     gtk_widget_set_sensitive( GETWIDGET(p_window, "tbRewind"), b_control );
618     gtk_widget_set_sensitive( GETWIDGET(p_window, "tbPause"), b_control );
619     gtk_widget_set_sensitive( GETWIDGET(p_window, "tbForward"), b_control );
620
621 #undef GETWIDGET
622     return TRUE;
623 }
624