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