]> 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.11 2003/11/25 20:41:35 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
171     /* Path for pixmaps under linupy 2.0 */
172     add_pixmap_directory("/usr/share/pixmaps/vlc");
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     msg_Dbg( p_intf, "trying to store p_intf pointer ... " );
182     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
183                          "p_intf", p_intf );
184     msg_Dbg( p_intf, "trying to store p_intf pointer ... done" );
185
186     /* Set the title of the main window */
187     gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_window),
188                           VOUT_TITLE " (PDA Linux interface)");
189
190     /* Get the notebook object */
191     p_intf->p_sys->p_notebook = GTK_NOTEBOOK( gtk_object_get_data(
192         GTK_OBJECT( p_intf->p_sys->p_window ), "notebook" ) );
193     
194     /* Get the slider object */
195     p_intf->p_sys->p_slider = GTK_HSCALE( gtk_object_get_data(
196         GTK_OBJECT( p_intf->p_sys->p_window ), "slider" ) );
197     p_intf->p_sys->p_slider_label = GTK_LABEL( gtk_object_get_data(
198         GTK_OBJECT( p_intf->p_sys->p_window ), "slider_label" ) );
199
200 #if 0
201     /* Connect the date display to the slider */
202     msg_Dbg( p_intf, "setting slider adjustment ... " );
203 #define P_SLIDER GTK_RANGE( gtk_object_get_data( \
204                          GTK_OBJECT( p_intf->p_sys->p_window ), "slider" ) )
205     p_intf->p_sys->p_adj = gtk_range_get_adjustment( P_SLIDER );
206
207     gtk_signal_connect ( GTK_OBJECT( p_intf->p_sys->p_adj ), "value_changed",
208                          GTK_SIGNAL_FUNC( E_(GtkDisplayDate) ), NULL );
209     p_intf->p_sys->f_adj_oldvalue = 0;
210     p_intf->p_sys->i_adj_oldvalue = 0;
211 #undef P_SLIDER
212     msg_Dbg( p_intf, "setting slider adjustment ... done" );
213 #endif
214
215     /* BEGIN OF FILEVIEW GTK_TREE_VIEW */
216     msg_Dbg(p_intf, "Getting GtkTreeView FileList" );
217     p_intf->p_sys->p_tvfile = NULL;
218     p_intf->p_sys->p_tvfile = (GtkTreeView *) lookup_widget( p_intf->p_sys->p_window,
219                                                              "tvFileList");
220     if (NULL == p_intf->p_sys->p_tvfile)
221        msg_Err(p_intf, "Error obtaining pointer to File List");
222
223     /* Insert columns 0 */
224     renderer = gtk_cell_renderer_text_new ();
225     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 0, _("Filename"), renderer, NULL);
226     column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 0 );
227     gtk_tree_view_column_add_attribute(column, renderer, "text", 0 );
228     gtk_tree_view_column_set_sort_column_id(column, 0);
229     /* Insert columns 1 */
230     renderer = gtk_cell_renderer_text_new ();
231     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 1, _("Permissions"), renderer, NULL);
232     column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 1 );
233     gtk_tree_view_column_add_attribute(column, renderer, "text", 1 );
234     gtk_tree_view_column_set_sort_column_id(column, 1);
235     /* Insert columns 2 */
236     renderer = gtk_cell_renderer_text_new ();
237     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 2, _("Size"), renderer, NULL);
238     column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 2 );
239     gtk_tree_view_column_add_attribute(column, renderer, "text", 2 );
240     gtk_tree_view_column_set_sort_column_id(column, 2);
241     /* Insert columns 3 */
242     renderer = gtk_cell_renderer_text_new ();
243     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 3, _("Owner"), renderer, NULL);
244     column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 3 );
245     gtk_tree_view_column_add_attribute(column, renderer, "text", 3 );
246     gtk_tree_view_column_set_sort_column_id(column, 3);
247     /* Insert columns 4 */
248     renderer = gtk_cell_renderer_text_new ();
249     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 4, _("Group"), renderer, NULL);
250     column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 4 );
251     gtk_tree_view_column_add_attribute(column, renderer, "text", 4 );
252     gtk_tree_view_column_set_sort_column_id(column, 4);
253
254     /* Get new directory listing */
255     msg_Dbg(p_intf, "Populating GtkTreeView FileList" );
256     filelist = gtk_list_store_new (5,
257                 G_TYPE_STRING, /* Filename */
258                 G_TYPE_STRING, /* permissions */
259                 G_TYPE_UINT64, /* File size */
260                 G_TYPE_STRING, /* Owner */
261                 G_TYPE_STRING);/* Group */
262     ReadDirectory(p_intf, filelist, ".");
263     msg_Dbg(p_intf, "Showing GtkTreeView 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     msg_Dbg(p_intf, "Getting GtkTreeView PlayList" );
276     p_intf->p_sys->p_tvplaylist = NULL;
277     p_intf->p_sys->p_tvplaylist = (GtkTreeView *) lookup_widget( p_intf->p_sys->p_window, "tvPlaylist");   
278     if (NULL == p_intf->p_sys->p_tvplaylist)
279        msg_Err(p_intf, "Error obtaining pointer to Play List");
280
281     /* Columns 1 */
282     renderer = gtk_cell_renderer_text_new ();
283     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 0, _("Filename"), renderer, NULL);
284     column = gtk_tree_view_get_column(p_intf->p_sys->p_tvplaylist, 0 );
285     gtk_tree_view_column_add_attribute(column, renderer, "text", 0 );
286     gtk_tree_view_column_set_sort_column_id(column, 0);
287     /* Column 2 */
288     renderer = gtk_cell_renderer_text_new ();
289     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 1, _("Time"), renderer, NULL);
290     column = gtk_tree_view_get_column(p_intf->p_sys->p_tvplaylist, 1 );
291     gtk_tree_view_column_add_attribute(column, renderer, "text", 1 );
292     gtk_tree_view_column_set_sort_column_id(column, 1);
293
294     /* update the playlist */
295     msg_Dbg(p_intf, "Populating GtkTreeView Playlist" );
296     playlist = gtk_list_store_new (2,
297                 G_TYPE_STRING, /* Filename */
298                 G_TYPE_STRING);/* Time */
299     PlaylistRebuildListStore( playlist, vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ));
300     msg_Dbg(p_intf, "Showing GtkTreeView Playlist" );
301     gtk_tree_view_set_model(GTK_TREE_VIEW(p_intf->p_sys->p_tvplaylist), GTK_TREE_MODEL(playlist));
302     g_object_unref(playlist);
303     gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(p_intf->p_sys->p_tvplaylist)),GTK_SELECTION_MULTIPLE);
304
305     /* Column properties */
306     gtk_tree_view_set_headers_visible(p_intf->p_sys->p_tvplaylist, TRUE);
307     gtk_tree_view_columns_autosize(p_intf->p_sys->p_tvplaylist);
308     gtk_tree_view_set_headers_clickable(p_intf->p_sys->p_tvplaylist, TRUE);
309     /* END OF PLAYLIST GTK_TREE_VIEW */
310
311     /* Show the control window */
312     gtk_widget_show( p_intf->p_sys->p_window );
313
314 #ifdef NEED_GTK2_MAIN
315     msg_Dbg( p_intf, "Manage GTK keyboard events using threads" );
316     while( !p_intf->b_die )
317     {
318         Manage( p_intf );
319
320         /* Sleep to avoid using all CPU - since some interfaces need to
321          * access keyboard events, a 100ms delay is a good compromise */
322         gdk_threads_leave();
323         if (p_intf->p_libvlc->i_cpu & CPU_CAPABILITY_FPU)
324             msleep( INTF_IDLE_SLEEP );
325         else
326             msleep( 1000 );
327         gdk_threads_enter();
328     }
329 #else
330     msg_Dbg( p_intf, "Manage GTK keyboard events using timeouts" );
331     /* Sleep to avoid using all CPU - since some interfaces needs to access
332      * keyboard events, a 1000ms delay is a good compromise */
333     if (p_intf->p_libvlc->i_cpu & CPU_CAPABILITY_FPU)
334         i_dummy = gtk_timeout_add( INTF_IDLE_SLEEP / 1000, (GtkFunction)Manage, p_intf );
335     else
336         i_dummy = gtk_timeout_add( 1000, (GtkFunction)Manage, p_intf );
337
338     /* Enter Gtk mode */
339     gtk_main();
340     /* Remove the timeout */
341     gtk_timeout_remove( i_dummy );
342 #endif
343
344     gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_window) );
345 #ifdef NEED_GTK2_MAIN
346     gdk_threads_leave();
347 #endif
348 }
349
350 /*****************************************************************************
351  * GtkAutoplayFile: Autoplay file depending on configuration settings
352  *****************************************************************************/
353 void GtkAutoPlayFile( vlc_object_t *p_this )
354 {
355     GtkWidget *cbautoplay;
356     intf_thread_t *p_intf;
357     int i_index;
358     vlc_list_t *p_list = vlc_list_find( p_this, VLC_OBJECT_INTF,
359                                         FIND_ANYWHERE );
360
361     for( i_index = 0; i_index < p_list->i_count; i_index++ )
362     {
363         p_intf = (intf_thread_t *)p_list->p_values[i_index].p_object ;
364
365         if( strcmp( MODULE_STRING, p_intf->p_module->psz_object_name ) )
366         {
367             continue;
368         }
369         cbautoplay = GTK_WIDGET( gtk_object_get_data(
370                             GTK_OBJECT( p_intf->p_sys->p_window ),
371                             "cbautoplay" ) );
372
373         if( !config_GetInt( p_this, "pda-autoplayfile" ) )
374         {
375             p_intf->p_sys->b_autoplayfile = VLC_FALSE;
376         }
377         else
378         {
379             p_intf->p_sys->b_autoplayfile = VLC_TRUE;
380         }
381         gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( cbautoplay ),
382                                       p_intf->p_sys->b_autoplayfile );
383     }
384     vlc_list_release( p_list );
385 }
386
387 /* following functions are local */
388
389 /*****************************************************************************
390  * Manage: manage main thread messages
391  *****************************************************************************
392  * In this function, called approx. 10 times a second, we check what the
393  * main program wanted to tell us.
394  *****************************************************************************/
395 static int Manage( intf_thread_t *p_intf )
396 {
397     GtkListStore *p_liststore;
398     vlc_mutex_lock( &p_intf->change_lock );
399
400     /* Update the input */
401     if( p_intf->p_sys->p_input == NULL )
402     {
403         p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
404                                                           FIND_ANYWHERE );
405     }
406     else if( p_intf->p_sys->p_input->b_dead )
407     {
408         vlc_object_release( p_intf->p_sys->p_input );
409         p_intf->p_sys->p_input = NULL;
410     }
411
412     if( p_intf->p_sys->p_input )
413     {
414         input_thread_t *p_input = p_intf->p_sys->p_input;
415
416         vlc_mutex_lock( &p_input->stream.stream_lock );
417         if( !p_input->b_die )
418         {
419             /* New input or stream map change */
420             if( p_input->stream.b_changed )
421             {
422                 playlist_t *p_playlist;
423
424                 E_(GtkModeManage)( p_intf );
425                 p_intf->p_sys->b_playing = 1;
426
427                 /* update playlist interface */
428                 p_playlist = (playlist_t *) vlc_object_find( 
429                         p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
430                 if (p_playlist != NULL)
431                 {
432                     msg_Dbg(p_intf, "Manage: Populating GtkTreeView Playlist" );
433                     p_liststore = gtk_list_store_new (2,
434                                                G_TYPE_STRING,
435                                                G_TYPE_STRING);
436                     PlaylistRebuildListStore(p_liststore, p_playlist);
437                     msg_Dbg(p_intf, "Manage: Updating GtkTreeView Playlist" );
438                     gtk_tree_view_set_model(p_intf->p_sys->p_tvplaylist, (GtkTreeModel*) p_liststore);
439                     vlc_object_release( p_playlist );
440                 }
441             }
442
443             /* Manage the slider */
444             if (p_intf->p_libvlc->i_cpu & CPU_CAPABILITY_FPU)
445             {
446                 /* Manage the slider for CPU_CAPABILITY_FPU hardware */ 
447                 if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
448                 {
449                     float newvalue = p_intf->p_sys->p_adj->value;
450
451 #define p_area p_input->stream.p_selected_area
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. * p_area->i_tell ) / p_area->i_size;
460                         gtk_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                         off_t i_seek = ( newvalue * p_area->i_size ) / 100;
468
469                         /* release the lock to be able to seek */
470                         vlc_mutex_unlock( &p_input->stream.stream_lock );
471                         input_Seek( p_input, i_seek, INPUT_SEEK_SET );
472                         vlc_mutex_lock( &p_input->stream.stream_lock );
473
474                         /* Update the old value */
475                         p_intf->p_sys->f_adj_oldvalue = newvalue;
476                     }
477 #undef p_area
478                 }
479             }
480             else
481             {
482                 /* Manage the slider without CPU_CAPABILITY_FPU hardware */
483                 if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
484                 {
485                     off_t newvalue = p_intf->p_sys->p_adj->value;
486
487 #define p_area p_input->stream.p_selected_area
488                     /* If the user hasn't touched the slider since the last time,
489                      * then the input can safely change it */
490                     if( newvalue == p_intf->p_sys->i_adj_oldvalue )
491                     {
492                         /* Update the value */
493                         p_intf->p_sys->p_adj->value =
494                         p_intf->p_sys->i_adj_oldvalue =
495                             ( 100 * p_area->i_tell ) / p_area->i_size;
496                         gtk_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
497                                                  "value_changed" );
498                     }
499                     /* Otherwise, send message to the input if the user has
500                      * finished dragging the slider */
501                     else if( p_intf->p_sys->b_slider_free )
502                     {
503                         off_t i_seek = ( newvalue * p_area->i_size ) / 100;
504
505                         /* release the lock to be able to seek */
506                         vlc_mutex_unlock( &p_input->stream.stream_lock );
507                         input_Seek( p_input, i_seek, INPUT_SEEK_SET );
508                         vlc_mutex_lock( &p_input->stream.stream_lock );
509
510                         /* Update the old value */
511                         p_intf->p_sys->i_adj_oldvalue = newvalue;
512                     }
513 #undef p_area
514                 }
515             }
516         }
517         vlc_mutex_unlock( &p_input->stream.stream_lock );
518     }
519     else if( p_intf->p_sys->b_playing && !p_intf->b_die )
520     {
521         E_(GtkModeManage)( p_intf );
522         p_intf->p_sys->b_playing = 0;
523     }
524
525 #ifndef NEED_GTK2_MAIN
526     if( p_intf->b_die )
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 E_(GtkDisplayDate)( GtkAdjustment *p_adj )
550 {
551     intf_thread_t *p_intf;
552
553     p_intf = gtk_object_get_data( GTK_OBJECT( p_adj ), "p_intf" );
554
555     if( p_intf->p_sys->p_input )
556     {
557 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
558         char psz_time[ OFFSETTOTIME_MAX_SIZE ];
559
560         gtk_label_set_text( GTK_LABEL( p_intf->p_sys->p_slider_label ),
561                         input_OffsetToTime( p_intf->p_sys->p_input, psz_time,
562                                    ( p_area->i_size * p_adj->value ) / 100 ) );
563 #undef p_area
564      }
565 }
566
567 /*****************************************************************************
568  * GtkModeManage: actualize the aspect of the interface whenever the input
569  *                changes.
570  *****************************************************************************
571  * The lock has to be taken before you call the function.
572  *****************************************************************************/
573 gint E_(GtkModeManage)( intf_thread_t * p_intf )
574 {
575     GtkWidget *     p_slider;
576     vlc_bool_t      b_control;
577
578 #define GETWIDGET( ptr, name ) GTK_WIDGET( gtk_object_get_data( GTK_OBJECT( \
579                            p_intf->p_sys->ptr ) , ( name ) ) )
580     /* hide slider */
581     p_slider = GTK_WIDGET( gtk_object_get_data( GTK_OBJECT(
582                            p_intf->p_sys->p_window ), "slider" ) );
583     gtk_widget_hide( GTK_WIDGET( p_slider ) );
584
585     /* controls unavailable */
586     b_control = 0;
587
588     /* show the box related to current input mode */
589     if( p_intf->p_sys->p_input )
590     {
591         /* initialize and show slider for seekable streams */
592         if( p_intf->p_sys->p_input->stream.b_seekable )
593         {
594             if (p_intf->p_libvlc->i_cpu & CPU_CAPABILITY_FPU)
595                 p_intf->p_sys->p_adj->value = p_intf->p_sys->f_adj_oldvalue = 0;
596             else
597                 p_intf->p_sys->p_adj->value = p_intf->p_sys->i_adj_oldvalue = 0;
598             gtk_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
599                                      "value_changed" );
600             gtk_widget_show( GTK_WIDGET( p_slider ) );
601         }
602
603         /* control buttons for free pace streams */
604         b_control = p_intf->p_sys->p_input->stream.b_pace_control;
605
606         p_intf->p_sys->p_input->stream.b_changed = 0;
607         msg_Dbg( p_intf, "stream has changed, refreshing interface" );
608     }
609
610     /* set control items */
611     gtk_widget_set_sensitive( GETWIDGET(p_window, "tbRewind"), b_control );
612     gtk_widget_set_sensitive( GETWIDGET(p_window, "tbPause"), b_control );
613     gtk_widget_set_sensitive( GETWIDGET(p_window, "tbForward"), b_control );
614
615 #undef GETWIDGET
616     return TRUE;
617 }
618