Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

pda.c

00001 /*****************************************************************************
00002  * pda.c : PDA Gtk2 plugin for vlc
00003  *****************************************************************************
00004  * Copyright (C) 2002 the VideoLAN team
00005  * $Id: pda.c 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Jean-Paul Saman <[email protected]>
00008  *          Marc Ariberti <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 /*****************************************************************************
00026  * Preamble
00027  *****************************************************************************/
00028 #include <stdlib.h>                                      /* malloc(), free() */
00029 #include <errno.h>                                                 /* ENOMEM */
00030 #include <string.h>                                            /* strerror() */
00031 #include <stdio.h>
00032 
00033 #include <vlc/vlc.h>
00034 #include <vlc/intf.h>
00035 
00036 #include <gtk/gtk.h>
00037 
00038 #include "pda_callbacks.h"
00039 #include "pda_interface.h"
00040 #include "pda_support.h"
00041 #include "pda.h"
00042 
00043 /*****************************************************************************
00044  * Local prototypes.
00045  *****************************************************************************/
00046 static int  Open         ( vlc_object_t * );
00047 static void Close        ( vlc_object_t * );
00048 static void Run          ( intf_thread_t * );
00049 
00050 void GtkAutoPlayFile     ( vlc_object_t * );
00051 static int Manage        ( intf_thread_t *p_intf );
00052 void E_(GtkDisplayDate)  ( GtkAdjustment *p_adj, gpointer userdata );
00053 gint E_(GtkModeManage)   ( intf_thread_t * p_intf );
00054 
00055 /*****************************************************************************
00056  * Module descriptor
00057  *****************************************************************************/
00058 #define AUTOPLAYFILE_TEXT  N_("Autoplay selected file")
00059 #define AUTOPLAYFILE_LONGTEXT N_("Automatically play a file when selected in the "\
00060         "file selection list")
00061 
00062 /*****************************************************************************
00063  * Module descriptor
00064  *****************************************************************************/
00065 vlc_module_begin();
00066     set_description( N_("PDA Linux Gtk2+ interface") );
00067     set_category( CAT_INTERFACE );
00068     set_subcategory( SUBCAT_INTERFACE_GENERAL );
00069 //    add_bool( "pda-autoplayfile", 1, GtkAutoPlayFile, AUTOPLAYFILE_TEXT, AUTOPLAYFILE_LONGTEXT, VLC_TRUE );
00070     set_capability( "interface", 70 );
00071     set_callbacks( Open, Close );
00072     add_shortcut( "pda" );
00073 vlc_module_end();
00074 
00075 /*****************************************************************************
00076  * Open: initialize and create window
00077  *****************************************************************************/
00078 static int Open( vlc_object_t *p_this )
00079 {
00080     intf_thread_t *p_intf = (intf_thread_t *)p_this;
00081 
00082     /* Allocate instance and initialize some members */
00083     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
00084     if( p_intf->p_sys == NULL )
00085     {
00086         msg_Err( p_intf, "out of memory" );
00087         return VLC_ENOMEM;
00088     }
00089 
00090 #ifdef NEED_GTK2_MAIN
00091     msg_Dbg( p_intf, "Using gui-helper" );
00092     p_intf->p_sys->p_gtk_main =
00093         module_Need( p_this, "gui-helper", "gtk2", VLC_TRUE );
00094     if( p_intf->p_sys->p_gtk_main == NULL )
00095     {
00096         free( p_intf->p_sys );
00097         return VLC_ENOMOD;
00098     }
00099 #endif
00100 
00101     /* Initialize Gtk+ thread */
00102     p_intf->p_sys->p_input = NULL;
00103 
00104     p_intf->p_sys->b_autoplayfile = 1;
00105     p_intf->p_sys->b_playing = 0;
00106     p_intf->p_sys->b_slider_free = 1;
00107 
00108     p_intf->pf_run = Run;
00109 
00110     return VLC_SUCCESS;
00111 }
00112 
00113 /*****************************************************************************
00114  * Close: destroy interface window
00115  *****************************************************************************/
00116 static void Close( vlc_object_t *p_this )
00117 {
00118     intf_thread_t *p_intf = (intf_thread_t *)p_this;
00119 
00120     if( p_intf->p_sys->p_input )
00121     {
00122         vlc_object_release( p_intf->p_sys->p_input );
00123     }
00124 
00125 #ifdef NEED_GTK2_MAIN
00126     msg_Dbg( p_intf, "Releasing gui-helper" );
00127     module_Unneed( p_intf, p_intf->p_sys->p_gtk_main );
00128 #endif
00129 
00130     /* Destroy structure */
00131     free( p_intf->p_sys );
00132 }
00133 
00134 /*****************************************************************************
00135  * Run: Gtk+ thread
00136  *****************************************************************************
00137  * this part of the interface is in a separate thread so that we can call
00138  * gtk_main() from within it without annoying the rest of the program.
00139  *****************************************************************************/
00140 static void Run( intf_thread_t *p_intf )
00141 {
00142 #ifndef NEED_GTK2_MAIN
00143     /* gtk_init needs to know the command line. We don't care, so we
00144      * give it an empty one */
00145     char  *p_args[] = { "", NULL };
00146     char **pp_args  = p_args;
00147     int    i_args   = 1;
00148     int    i_dummy;
00149 #endif
00150     playlist_t        *p_playlist;
00151     GtkCellRenderer   *p_renderer = NULL;
00152     GtkTreeViewColumn *p_column   = NULL;
00153     GtkListStore      *p_filelist = NULL;
00154     GtkListStore      *p_playlist_store = NULL;
00155 
00156 #ifndef NEED_GTK2_MAIN
00157     gtk_set_locale ();
00158     msg_Dbg( p_intf, "Starting pda GTK2+ interface" );
00159     gtk_init( &i_args, &pp_args );
00160 #else
00161     /* Initialize Gtk+ */
00162     msg_Dbg( p_intf, "Starting pda GTK2+ interface thread" );
00163     gdk_threads_enter();
00164 #endif
00165 
00166     /* Create some useful widgets that will certainly be used */
00167 /* FIXME: magic path */
00168     add_pixmap_directory("share");
00169     add_pixmap_directory("/usr/share/vlc");
00170 
00171     /* Path for pixmaps under linupy 1.4 */
00172     add_pixmap_directory("/usr/local/share/pixmaps/vlc");
00173     /* Path for pixmaps under linupy 2.0 */
00174     add_pixmap_directory("/usr/share/pixmaps/vlc");
00175 
00176     p_intf->p_sys->p_window = create_pda();
00177     if (p_intf->p_sys->p_window == NULL)
00178     {
00179         msg_Err( p_intf, "unable to create pda interface" );
00180     }
00181 
00182     /* Store p_intf to keep an eye on it */
00183     gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
00184                          "p_intf", p_intf );
00185 
00186     /* Set the title of the main window */
00187     gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_window),
00188                           VOUT_TITLE " (PDA Linux interface)");
00189 
00190     /* Get the notebook object */
00191     p_intf->p_sys->p_notebook = GTK_NOTEBOOK( gtk_object_get_data(
00192         GTK_OBJECT( p_intf->p_sys->p_window ), "notebook" ) );
00193 
00194     /* Get the slider object */
00195     p_intf->p_sys->p_slider = (GtkHScale*) lookup_widget( p_intf->p_sys->p_window, "timeSlider" );
00196     p_intf->p_sys->p_slider_label = (GtkLabel*) lookup_widget( p_intf->p_sys->p_window, "timeLabel" );
00197     if (p_intf->p_sys->p_slider == NULL)
00198         msg_Err( p_intf, "Time slider widget not found." );
00199     if (p_intf->p_sys->p_slider_label == NULL)
00200         msg_Err( p_intf, "Time label widget not found." );
00201 
00202     /* Connect the date display to the slider */
00203     p_intf->p_sys->p_adj = gtk_range_get_adjustment( GTK_RANGE(p_intf->p_sys->p_slider) );
00204     if (p_intf->p_sys->p_adj == NULL)
00205         msg_Err( p_intf, "Adjustment range not found." );
00206     g_signal_connect( GTK_OBJECT( p_intf->p_sys->p_adj ), "value_changed",
00207                          G_CALLBACK( E_(GtkDisplayDate) ), p_intf );
00208     p_intf->p_sys->f_adj_oldvalue = 0;
00209     p_intf->p_sys->i_adj_oldvalue = 0;
00210 
00211     /* BEGIN OF FILEVIEW GTK_TREE_VIEW */
00212     p_intf->p_sys->p_tvfile = NULL;
00213     p_intf->p_sys->p_tvfile = (GtkTreeView *) lookup_widget( p_intf->p_sys->p_window,
00214                                                              "tvFileList");
00215     if (NULL == p_intf->p_sys->p_tvfile)
00216        msg_Err(p_intf, "Error obtaining pointer to File List");
00217 
00218     /* Insert columns 0 */
00219     p_renderer = gtk_cell_renderer_text_new ();
00220     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 0, (gchar *) N_("Filename"), p_renderer, NULL);
00221     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 0 );
00222     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 0 );
00223     gtk_tree_view_column_set_sort_column_id(p_column, 0);
00224     /* Insert columns 1 */
00225     p_renderer = gtk_cell_renderer_text_new ();
00226     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 1, (gchar *) N_("Permissions"), p_renderer, NULL);
00227     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 1 );
00228     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 1 );
00229     gtk_tree_view_column_set_sort_column_id(p_column, 1);
00230     /* Insert columns 2 */
00231     p_renderer = gtk_cell_renderer_text_new ();
00232     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 2, (gchar *) N_("Size"), p_renderer, NULL);
00233     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 2 );
00234     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 2 );
00235     gtk_tree_view_column_set_sort_column_id(p_column, 2);
00236     /* Insert columns 3 */
00237     p_renderer = gtk_cell_renderer_text_new ();
00238     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 3, (gchar *) N_("Owner"), p_renderer, NULL);
00239     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 3 );
00240     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 3 );
00241     gtk_tree_view_column_set_sort_column_id(p_column, 3);
00242     /* Insert columns 4 */
00243     p_renderer = gtk_cell_renderer_text_new ();
00244     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 4, (gchar *) N_("Group"), p_renderer, NULL);
00245     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 4 );
00246     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 4 );
00247     gtk_tree_view_column_set_sort_column_id(p_column, 4);
00248 
00249     /* Get new directory listing */
00250     p_filelist = gtk_list_store_new (5,
00251                 G_TYPE_STRING, /* Filename */
00252                 G_TYPE_STRING, /* permissions */
00253                 G_TYPE_UINT64, /* File size */
00254                 G_TYPE_STRING, /* Owner */
00255                 G_TYPE_STRING);/* Group */
00256     ReadDirectory(p_intf, p_filelist, ".");
00257     gtk_tree_view_set_model(GTK_TREE_VIEW(p_intf->p_sys->p_tvfile), GTK_TREE_MODEL(p_filelist));
00258     g_object_unref(p_filelist);     /* Model will be released by GtkTreeView */
00259     gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(p_intf->p_sys->p_tvfile)),GTK_SELECTION_MULTIPLE);
00260 
00261     /* Column properties */
00262     gtk_tree_view_set_headers_visible(p_intf->p_sys->p_tvfile, TRUE);
00263     gtk_tree_view_columns_autosize(p_intf->p_sys->p_tvfile);
00264     gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(p_intf->p_sys->p_tvfile),TRUE);
00265     /* END OF FILEVIEW GTK_TREE_VIEW */
00266 
00267     /* BEGIN OF PLAYLIST GTK_TREE_VIEW */
00268     p_intf->p_sys->p_tvplaylist = NULL;
00269     p_intf->p_sys->p_tvplaylist = (GtkTreeView *) lookup_widget( p_intf->p_sys->p_window, "tvPlaylist");
00270     if (NULL == p_intf->p_sys->p_tvplaylist)
00271        msg_Err(p_intf, "Error obtaining pointer to Play List");
00272 
00273     /* Columns 1 */
00274     p_renderer = gtk_cell_renderer_text_new ();
00275     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 0, (gchar *) N_("Filename"), p_renderer, NULL);
00276     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvplaylist, 0 );
00277     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 0 );
00278     gtk_tree_view_column_set_sort_column_id(p_column, 0);
00279     /* Column 2 */
00280     p_renderer = gtk_cell_renderer_text_new ();
00281     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 1, (gchar *) N_("Time"), p_renderer, NULL);
00282     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvplaylist, 1 );
00283     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 1 );
00284     gtk_tree_view_column_set_sort_column_id(p_column, 1);
00285 #if 0
00286     /* Column 3 - is a hidden column used for reliable deleting items from the underlying playlist */
00287     p_renderer = gtk_cell_renderer_text_new ();
00288     gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 2, (gchar *) N_("Index"), p_renderer, NULL);
00289     p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvplaylist, 2 );
00290     gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 2 );
00291     gtk_tree_view_column_set_sort_column_id(p_column, 2);
00292 #endif
00293     /* update the playlist */
00294     p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
00295     p_playlist_store = gtk_list_store_new (3,
00296                 G_TYPE_STRING, /* Filename */
00297                 G_TYPE_STRING, /* Time */
00298                 G_TYPE_UINT);  /* Hidden index */
00299     PlaylistRebuildListStore(p_playlist_store, p_playlist);
00300     gtk_tree_view_set_model(GTK_TREE_VIEW(p_intf->p_sys->p_tvplaylist), GTK_TREE_MODEL(p_playlist_store));
00301     g_object_unref(p_playlist_store);
00302     vlc_object_release(p_playlist); /* Free the playlist */
00303     gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(p_intf->p_sys->p_tvplaylist)),GTK_SELECTION_MULTIPLE);
00304 
00305     /* Column properties */
00306     gtk_tree_view_set_headers_visible(p_intf->p_sys->p_tvplaylist, TRUE);
00307     gtk_tree_view_columns_autosize(p_intf->p_sys->p_tvplaylist);
00308     gtk_tree_view_set_headers_clickable(p_intf->p_sys->p_tvplaylist, TRUE);
00309     /* END OF PLAYLIST GTK_TREE_VIEW */
00310 
00311     /* Hide the Preference TAB for now. */
00312     GtkWidget *p_preference_tab = NULL;
00313     p_preference_tab = gtk_notebook_get_nth_page(p_intf->p_sys->p_notebook,5);
00314     if (p_preference_tab != NULL)
00315       gtk_widget_hide(p_preference_tab);
00316 
00317     /* Show the control window */
00318     gtk_widget_show( p_intf->p_sys->p_window );
00319 
00320 #ifdef NEED_GTK2_MAIN
00321     msg_Dbg( p_intf, "Manage GTK keyboard events using threads" );
00322     while( !p_intf->b_die )
00323     {
00324         Manage( p_intf );
00325 
00326         /* Sleep to avoid using all CPU - since some interfaces need to
00327          * access keyboard events, a 100ms delay is a good compromise */
00328         gdk_threads_leave();
00329         if (p_intf->p_libvlc->i_cpu & CPU_CAPABILITY_FPU)
00330             msleep( INTF_IDLE_SLEEP );
00331         else
00332             msleep( 1000 );
00333         gdk_threads_enter();
00334     }
00335 #else
00336     msg_Dbg( p_intf, "Manage GTK keyboard events using timeouts" );
00337     /* Sleep to avoid using all CPU - since some interfaces needs to access
00338      * keyboard events, a 1000ms delay is a good compromise */
00339     if (p_intf->p_libvlc->i_cpu & CPU_CAPABILITY_FPU)
00340         i_dummy = gtk_timeout_add( INTF_IDLE_SLEEP / 1000, (GtkFunction)Manage, p_intf );
00341     else
00342         i_dummy = gtk_timeout_add( 1000, (GtkFunction)Manage, p_intf );
00343 
00344     /* Enter Gtk mode */
00345     gtk_main();
00346     /* Remove the timeout */
00347     gtk_timeout_remove( i_dummy );
00348 #endif
00349 
00350     gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_window) );
00351 #ifdef NEED_GTK2_MAIN
00352     gdk_threads_leave();
00353 #endif
00354 }
00355 
00356 /*****************************************************************************
00357  * GtkAutoplayFile: Autoplay file depending on configuration settings
00358  *****************************************************************************/
00359 void GtkAutoPlayFile( vlc_object_t *p_this )
00360 {
00361     GtkWidget *cbautoplay;
00362     intf_thread_t *p_intf;
00363     int i_index;
00364     vlc_list_t *p_list = vlc_list_find( p_this, VLC_OBJECT_INTF,
00365                                         FIND_ANYWHERE );
00366 
00367     for( i_index = 0; i_index < p_list->i_count; i_index++ )
00368     {
00369         p_intf = (intf_thread_t *)p_list->p_values[i_index].p_object ;
00370 
00371         if( strcmp( MODULE_STRING, p_intf->p_module->psz_object_name ) )
00372         {
00373             continue;
00374         }
00375         cbautoplay = GTK_WIDGET( gtk_object_get_data(
00376                             GTK_OBJECT( p_intf->p_sys->p_window ),
00377                             "cbautoplay" ) );
00378 
00379         if( !config_GetInt( p_this, "pda-autoplayfile" ) )
00380         {
00381             p_intf->p_sys->b_autoplayfile = VLC_FALSE;
00382         }
00383         else
00384         {
00385             p_intf->p_sys->b_autoplayfile = VLC_TRUE;
00386         }
00387         gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( cbautoplay ),
00388                                       p_intf->p_sys->b_autoplayfile );
00389     }
00390     vlc_list_release( p_list );
00391 }
00392 
00393 /* following functions are local */
00394 
00395 /*****************************************************************************
00396  * Manage: manage main thread messages
00397  *****************************************************************************
00398  * In this function, called approx. 10 times a second, we check what the
00399  * main program wanted to tell us.
00400  *****************************************************************************/
00401 static int Manage( intf_thread_t *p_intf )
00402 {
00403     GtkListStore *p_liststore;
00404     vlc_mutex_lock( &p_intf->change_lock );
00405 
00406     /* Update the input */
00407     if( p_intf->p_sys->p_input == NULL )
00408     {
00409         p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
00410                                                           FIND_ANYWHERE );
00411     }
00412     else if( p_intf->p_sys->p_input->b_dead )
00413     {
00414         vlc_object_release( p_intf->p_sys->p_input );
00415         p_intf->p_sys->p_input = NULL;
00416     }
00417 
00418     if( p_intf->p_sys->p_input )
00419     {
00420         input_thread_t *p_input = p_intf->p_sys->p_input;
00421 
00422         vlc_mutex_lock( &p_input->object_lock );
00423         if( !p_input->b_die )
00424         {
00425             {
00426                 playlist_t *p_playlist;
00427 
00428                 E_(GtkModeManage)( p_intf );
00429                 p_intf->p_sys->b_playing = 1;
00430 
00431                 /* update playlist interface */
00432                 p_playlist = (playlist_t *) vlc_object_find(
00433                         p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
00434                 if (p_playlist != NULL)
00435                 {
00436                     p_liststore = gtk_list_store_new (3,
00437                                                G_TYPE_STRING,
00438                                                G_TYPE_STRING,
00439                                                G_TYPE_UINT);  /* Hidden index */
00440                     PlaylistRebuildListStore(p_liststore, p_playlist);
00441                     gtk_tree_view_set_model(p_intf->p_sys->p_tvplaylist, (GtkTreeModel*) p_liststore);
00442                     g_object_unref(p_liststore);
00443                     vlc_object_release( p_playlist );
00444                 }
00445             }
00446 
00447             /* Manage the slider */
00448 #if 0
00449 #define p_area p_input->p_selected_area
00450             if (p_intf->p_libvlc->i_cpu & CPU_CAPABILITY_FPU)
00451             {
00452                 /* Manage the slider for CPU_CAPABILITY_FPU hardware */
00453                 if( p_intf->p_sys->b_playing )
00454                 {
00455                     float newvalue = p_intf->p_sys->p_adj->value;
00456 
00457                     /* If the user hasn't touched the slider since the last time,
00458                      * then the input can safely change it */
00459                     if( newvalue == p_intf->p_sys->f_adj_oldvalue )
00460                     {
00461                         /* Update the value */
00462                         p_intf->p_sys->p_adj->value =
00463                         p_intf->p_sys->f_adj_oldvalue =
00464                             ( 100. * p_area->i_tell ) / p_area->i_size;
00465                         g_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
00466                                                  "value_changed" );
00467                     }
00468                     /* Otherwise, send message to the input if the user has
00469                      * finished dragging the slider */
00470                     else if( p_intf->p_sys->b_slider_free )
00471                     {
00472                         double f_pos = (double)newvalue / 100.0;
00473 
00474                         /* release the lock to be able to seek */
00475                         vlc_mutex_unlock( &p_input->object_lock );
00476                         var_SetFloat( p_input, "position", f_pos );
00477                         vlc_mutex_lock( &p_input->object_lock );
00478 
00479                         /* Update the old value */
00480                         p_intf->p_sys->f_adj_oldvalue = newvalue;
00481                     }
00482                 }
00483             }
00484             else
00485             {
00486                 /* Manage the slider without CPU_CAPABILITY_FPU hardware */
00487                 if( p_intf->p_sys->b_playing )
00488                 {
00489                     off_t newvalue = p_intf->p_sys->p_adj->value;
00490 
00491                     /* If the user hasn't touched the slider since the last time,
00492                      * then the input can safely change it */
00493                     if( newvalue == p_intf->p_sys->i_adj_oldvalue )
00494                     {
00495                         /* Update the value */
00496                         p_intf->p_sys->p_adj->value =
00497                         p_intf->p_sys->i_adj_oldvalue =
00498                             ( 100 * p_area->i_tell ) / p_area->i_size;
00499                         g_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
00500                                                  "value_changed" );
00501                     }
00502                     /* Otherwise, send message to the input if the user has
00503                      * finished dragging the slider */
00504                     else if( p_intf->p_sys->b_slider_free )
00505                     {
00506                         double f_pos = (double)newvalue / 100.0;
00507 
00508                         /* release the lock to be able to seek */
00509                         vlc_mutex_unlock( &p_input->object_lock );
00510                         var_SetFloat( p_input, "position", f_pos );
00511                         vlc_mutex_lock( &p_input->object_lock );
00512 
00513                         /* Update the old value */
00514                         p_intf->p_sys->i_adj_oldvalue = newvalue;
00515                     }
00516                 }
00517             }
00518 #undef p_area
00519 #endif
00520         }
00521         vlc_mutex_unlock( &p_input->object_lock );
00522     }
00523     else if( p_intf->p_sys->b_playing && !p_intf->b_die )
00524     {
00525         E_(GtkModeManage)( p_intf );
00526         p_intf->p_sys->b_playing = 0;
00527     }
00528 
00529 #ifndef NEED_GTK2_MAIN
00530     if( p_intf->b_die )
00531     {
00532         vlc_mutex_unlock( &p_intf->change_lock );
00533 
00534         /* Prepare to die, young Skywalker */
00535         gtk_main_quit();
00536 
00537         return FALSE;
00538     }
00539 #endif
00540 
00541     vlc_mutex_unlock( &p_intf->change_lock );
00542 
00543     return TRUE;
00544 }
00545 
00546 /*****************************************************************************
00547  * GtkDisplayDate: display stream date
00548  *****************************************************************************
00549  * This function displays the current date related to the position in
00550  * the stream. It is called whenever the slider changes its value.
00551  * The lock has to be taken before you call the function.
00552  *****************************************************************************/
00553 void E_(GtkDisplayDate)( GtkAdjustment *p_adj, gpointer userdata )
00554 {
00555     intf_thread_t *p_intf;
00556 
00557     p_intf = (intf_thread_t*) userdata;
00558     if (p_intf == NULL)
00559         return;
00560 
00561     if( p_intf->p_sys->p_input )
00562     {
00563         char psz_time[ MSTRTIME_MAX_SIZE ];
00564         int64_t i_seconds;
00565 
00566         i_seconds = var_GetTime( p_intf->p_sys->p_input, "time" ) / I64C(1000000 );
00567         secstotimestr( psz_time, i_seconds );
00568 
00569         gtk_label_set_text( GTK_LABEL( p_intf->p_sys->p_slider_label ),
00570                             psz_time );
00571      }
00572 }
00573 
00574 /*****************************************************************************
00575  * GtkModeManage: actualize the aspect of the interface whenever the input
00576  *                changes.
00577  *****************************************************************************
00578  * The lock has to be taken before you call the function.
00579  *****************************************************************************/
00580 gint E_(GtkModeManage)( intf_thread_t * p_intf )
00581 {
00582     GtkWidget *     p_slider = NULL;
00583     vlc_bool_t      b_control;
00584 
00585     if ( p_intf->p_sys->p_window == NULL )
00586         msg_Err( p_intf, "Main widget not found" );
00587 
00588     p_slider = lookup_widget( p_intf->p_sys->p_window, "timeSlider");
00589     if (p_slider == NULL)
00590         msg_Err( p_intf, "Slider widget not found" );
00591 
00592     /* controls unavailable */
00593     b_control = 0;
00594 
00595     /* show the box related to current input mode */
00596     if( p_intf->p_sys->p_input )
00597     {
00598         /* initialize and show slider for seekable streams */
00599         {
00600             gtk_widget_show( GTK_WIDGET( p_slider ) );
00601         }
00602 
00603         /* control buttons for free pace streams */
00604         b_control = p_intf->p_sys->p_input->b_can_pace_control;
00605 
00606         msg_Dbg( p_intf, "stream has changed, refreshing interface" );
00607     }
00608 
00609     /* set control items */
00610     gtk_widget_set_sensitive( lookup_widget( p_intf->p_sys->p_window, "tbRewind"), b_control );
00611     gtk_widget_set_sensitive( lookup_widget( p_intf->p_sys->p_window, "tbPause"), b_control );
00612     gtk_widget_set_sensitive( lookup_widget( p_intf->p_sys->p_window, "tbForward"), b_control );
00613     return TRUE;
00614 }
00615 

Generated on Tue Dec 20 10:14:39 2005 for vlc-0.8.4a by  doxygen 1.4.2