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