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