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