pda.c 24.4 KB
Newer Older
1 2 3
/*****************************************************************************
 * pda.c : PDA Gtk2 plugin for vlc
 *****************************************************************************
4
 * Copyright (C) 2002 the VideoLAN team
5
 * $Id$
6
 *
Jean-Paul Saman's avatar
Jean-Paul Saman committed
7
 * Authors: Jean-Paul Saman <jpsaman  _at_ videolan _dot_ org>
8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *          Marc Ariberti <marcari@videolan.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
dionoea's avatar
dionoea committed
22
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#include <stdlib.h>                                      /* malloc(), free() */
#include <errno.h>                                                 /* ENOMEM */
#include <string.h>                                            /* strerror() */
#include <stdio.h>

#include <vlc/vlc.h>
#include <vlc/intf.h>

#include <gtk/gtk.h>

38 39 40
#include "pda_callbacks.h"
#include "pda_interface.h"
#include "pda_support.h"
41 42 43 44 45 46 47 48 49 50 51
#include "pda.h"

/*****************************************************************************
 * Local prototypes.
 *****************************************************************************/
static int  Open         ( vlc_object_t * );
static void Close        ( vlc_object_t * );
static void Run          ( intf_thread_t * );

void GtkAutoPlayFile     ( vlc_object_t * );
static int Manage        ( intf_thread_t *p_intf );
Jean-Paul Saman's avatar
Jean-Paul Saman committed
52
void E_(GtkDisplayDate)  ( GtkAdjustment *p_adj, gpointer userdata );
53 54 55 56 57 58 59 60 61 62 63 64 65
gint E_(GtkModeManage)   ( intf_thread_t * p_intf );

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
#define AUTOPLAYFILE_TEXT  N_("Autoplay selected file")
#define AUTOPLAYFILE_LONGTEXT N_("Automatically play a file when selected in the "\
        "file selection list")

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
vlc_module_begin();
Jean-Paul Saman's avatar
Jean-Paul Saman committed
66
    set_description( N_("PDA Linux Gtk2+ interface") );
zorglub's avatar
zorglub committed
67
    set_category( CAT_INTERFACE );
zorglub's avatar
zorglub committed
68
    set_subcategory( SUBCAT_INTERFACE_MAIN );
gbazin's avatar
 
gbazin committed
69
//    add_bool( "pda-autoplayfile", 1, GtkAutoPlayFile, AUTOPLAYFILE_TEXT, AUTOPLAYFILE_LONGTEXT, VLC_TRUE );
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    set_capability( "interface", 70 );
    set_callbacks( Open, Close );
    add_shortcut( "pda" );
vlc_module_end();

/*****************************************************************************
 * Open: initialize and create window
 *****************************************************************************/
static int Open( vlc_object_t *p_this )
{
    intf_thread_t *p_intf = (intf_thread_t *)p_this;

    /* Allocate instance and initialize some members */
    p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
    if( p_intf->p_sys == NULL )
    {
        msg_Err( p_intf, "out of memory" );
        return VLC_ENOMEM;
    }

90
#ifdef NEED_GTK2_MAIN
91
    msg_Dbg( p_intf, "Using gui-helper" );
gbazin's avatar
 
gbazin committed
92 93
    p_intf->p_sys->p_gtk_main =
        module_Need( p_this, "gui-helper", "gtk2", VLC_TRUE );
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
    if( p_intf->p_sys->p_gtk_main == NULL )
    {
        free( p_intf->p_sys );
        return VLC_ENOMOD;
    }
#endif

    /* Initialize Gtk+ thread */
    p_intf->p_sys->p_input = NULL;

    p_intf->p_sys->b_autoplayfile = 1;
    p_intf->p_sys->b_playing = 0;
    p_intf->p_sys->b_slider_free = 1;

    p_intf->pf_run = Run;

    return VLC_SUCCESS;
}

/*****************************************************************************
 * Close: destroy interface window
 *****************************************************************************/
static void Close( vlc_object_t *p_this )
{
    intf_thread_t *p_intf = (intf_thread_t *)p_this;

    if( p_intf->p_sys->p_input )
    {
        vlc_object_release( p_intf->p_sys->p_input );
    }

125
#ifdef NEED_GTK2_MAIN
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
    msg_Dbg( p_intf, "Releasing gui-helper" );
    module_Unneed( p_intf, p_intf->p_sys->p_gtk_main );
#endif

    /* Destroy structure */
    free( p_intf->p_sys );
}

/*****************************************************************************
 * Run: Gtk+ thread
 *****************************************************************************
 * this part of the interface is in a separate thread so that we can call
 * gtk_main() from within it without annoying the rest of the program.
 *****************************************************************************/
static void Run( intf_thread_t *p_intf )
{
142
#ifndef NEED_GTK2_MAIN
143 144 145 146 147 148 149
    /* gtk_init needs to know the command line. We don't care, so we
     * give it an empty one */
    char  *p_args[] = { "", NULL };
    char **pp_args  = p_args;
    int    i_args   = 1;
    int    i_dummy;
#endif
Jean-Paul Saman's avatar
Jean-Paul Saman committed
150 151 152 153 154
    playlist_t        *p_playlist;
    GtkCellRenderer   *p_renderer = NULL;
    GtkTreeViewColumn *p_column   = NULL;
    GtkListStore      *p_filelist = NULL;
    GtkListStore      *p_playlist_store = NULL;
155

Jean-Paul Saman's avatar
Jean-Paul Saman committed
156
#ifndef NEED_GTK2_MAIN
Jean-Paul Saman's avatar
Jean-Paul Saman committed
157
    gtk_set_locale ();
158 159
    msg_Dbg( p_intf, "Starting pda GTK2+ interface" );
    gtk_init( &i_args, &pp_args );
Jean-Paul Saman's avatar
Jean-Paul Saman committed
160
#else
161
    /* Initialize Gtk+ */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
162
    msg_Dbg( p_intf, "Starting pda GTK2+ interface thread" );
163 164 165 166
    gdk_threads_enter();
#endif

    /* Create some useful widgets that will certainly be used */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
167
/* FIXME: magic path */
168 169 170 171 172 173 174 175 176 177 178 179 180
    add_pixmap_directory("share");
    add_pixmap_directory("/usr/share/vlc");

    /* Path for pixmaps under linupy 1.4 */
    add_pixmap_directory("/usr/local/share/pixmaps/vlc");
    /* Path for pixmaps under linupy 2.0 */
    add_pixmap_directory("/usr/share/pixmaps/vlc");

    p_intf->p_sys->p_window = create_pda();
    if (p_intf->p_sys->p_window == NULL)
    {
        msg_Err( p_intf, "unable to create pda interface" );
    }
181

Jean-Paul Saman's avatar
Jean-Paul Saman committed
182 183 184 185
    /* Store p_intf to keep an eye on it */
    gtk_object_set_data( GTK_OBJECT(p_intf->p_sys->p_window),
                         "p_intf", p_intf );

186 187
    /* Set the title of the main window */
    gtk_window_set_title( GTK_WINDOW(p_intf->p_sys->p_window),
188
                          VOUT_TITLE " (PDA Linux interface)");
189

190
    /* Get the notebook object */
191 192
    p_intf->p_sys->p_notebook = GTK_NOTEBOOK( gtk_object_get_data(
        GTK_OBJECT( p_intf->p_sys->p_window ), "notebook" ) );
193

194
    /* Get the slider object */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
195 196
    p_intf->p_sys->p_slider = (GtkHScale*) lookup_widget( p_intf->p_sys->p_window, "timeSlider" );
    p_intf->p_sys->p_slider_label = (GtkLabel*) lookup_widget( p_intf->p_sys->p_window, "timeLabel" );
Jean-Paul Saman's avatar
Jean-Paul Saman committed
197 198 199 200
    if (p_intf->p_sys->p_slider == NULL)
        msg_Err( p_intf, "Time slider widget not found." );
    if (p_intf->p_sys->p_slider_label == NULL)
        msg_Err( p_intf, "Time label widget not found." );
201 202

    /* Connect the date display to the slider */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
203
    p_intf->p_sys->p_adj = gtk_range_get_adjustment( GTK_RANGE(p_intf->p_sys->p_slider) );
Jean-Paul Saman's avatar
Jean-Paul Saman committed
204 205
    if (p_intf->p_sys->p_adj == NULL)
        msg_Err( p_intf, "Adjustment range not found." );
Jean-Paul Saman's avatar
Jean-Paul Saman committed
206 207
    g_signal_connect( GTK_OBJECT( p_intf->p_sys->p_adj ), "value_changed",
                         G_CALLBACK( E_(GtkDisplayDate) ), p_intf );
208 209 210
    p_intf->p_sys->f_adj_oldvalue = 0;
    p_intf->p_sys->i_adj_oldvalue = 0;

Jean-Paul Saman's avatar
Jean-Paul Saman committed
211
    /* BEGIN OF FILEVIEW GTK_TREE_VIEW */
212 213 214 215 216
    p_intf->p_sys->p_tvfile = NULL;
    p_intf->p_sys->p_tvfile = (GtkTreeView *) lookup_widget( p_intf->p_sys->p_window,
                                                             "tvFileList");
    if (NULL == p_intf->p_sys->p_tvfile)
       msg_Err(p_intf, "Error obtaining pointer to File List");
Jean-Paul Saman's avatar
Jean-Paul Saman committed
217 218

    /* Insert columns 0 */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
219
    p_renderer = gtk_cell_renderer_text_new ();
Jean-Paul Saman's avatar
Jean-Paul Saman committed
220
    gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 0, (gchar *) N_("Filename"), p_renderer, NULL);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
221 222 223
    p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 0 );
    gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 0 );
    gtk_tree_view_column_set_sort_column_id(p_column, 0);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
224
    /* Insert columns 1 */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
225
    p_renderer = gtk_cell_renderer_text_new ();
Jean-Paul Saman's avatar
Jean-Paul Saman committed
226
    gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 1, (gchar *) N_("Permissions"), p_renderer, NULL);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
227 228 229
    p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 1 );
    gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 1 );
    gtk_tree_view_column_set_sort_column_id(p_column, 1);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
230
    /* Insert columns 2 */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
231
    p_renderer = gtk_cell_renderer_text_new ();
Jean-Paul Saman's avatar
Jean-Paul Saman committed
232
    gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 2, (gchar *) N_("Size"), p_renderer, NULL);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
233 234 235
    p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 2 );
    gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 2 );
    gtk_tree_view_column_set_sort_column_id(p_column, 2);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
236
    /* Insert columns 3 */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
237
    p_renderer = gtk_cell_renderer_text_new ();
Jean-Paul Saman's avatar
Jean-Paul Saman committed
238
    gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 3, (gchar *) N_("Owner"), p_renderer, NULL);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
239 240 241
    p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 3 );
    gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 3 );
    gtk_tree_view_column_set_sort_column_id(p_column, 3);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
242
    /* Insert columns 4 */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
243
    p_renderer = gtk_cell_renderer_text_new ();
Jean-Paul Saman's avatar
Jean-Paul Saman committed
244
    gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 4, (gchar *) N_("Group"), p_renderer, NULL);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
245 246 247
    p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvfile, 4 );
    gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 4 );
    gtk_tree_view_column_set_sort_column_id(p_column, 4);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
248 249

    /* Get new directory listing */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
250
    p_filelist = gtk_list_store_new (5,
Jean-Paul Saman's avatar
Jean-Paul Saman committed
251 252 253 254 255
                G_TYPE_STRING, /* Filename */
                G_TYPE_STRING, /* permissions */
                G_TYPE_UINT64, /* File size */
                G_TYPE_STRING, /* Owner */
                G_TYPE_STRING);/* Group */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
256 257 258
    ReadDirectory(p_intf, p_filelist, ".");
    gtk_tree_view_set_model(GTK_TREE_VIEW(p_intf->p_sys->p_tvfile), GTK_TREE_MODEL(p_filelist));
    g_object_unref(p_filelist);     /* Model will be released by GtkTreeView */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
259 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 263
    /* Column properties */
    gtk_tree_view_set_headers_visible(p_intf->p_sys->p_tvfile, TRUE);
    gtk_tree_view_columns_autosize(p_intf->p_sys->p_tvfile);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
264 265
    gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(p_intf->p_sys->p_tvfile),TRUE);
    /* END OF FILEVIEW GTK_TREE_VIEW */
266

Jean-Paul Saman's avatar
Jean-Paul Saman committed
267
    /* BEGIN OF PLAYLIST GTK_TREE_VIEW */
268
    p_intf->p_sys->p_tvplaylist = NULL;
269
    p_intf->p_sys->p_tvplaylist = (GtkTreeView *) lookup_widget( p_intf->p_sys->p_window, "tvPlaylist");
270 271
    if (NULL == p_intf->p_sys->p_tvplaylist)
       msg_Err(p_intf, "Error obtaining pointer to Play List");
Jean-Paul Saman's avatar
Jean-Paul Saman committed
272 273

    /* Columns 1 */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
274
    p_renderer = gtk_cell_renderer_text_new ();
Jean-Paul Saman's avatar
Jean-Paul Saman committed
275
    gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 0, (gchar *) N_("Filename"), p_renderer, NULL);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
276 277 278
    p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvplaylist, 0 );
    gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 0 );
    gtk_tree_view_column_set_sort_column_id(p_column, 0);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
279
    /* Column 2 */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
280
    p_renderer = gtk_cell_renderer_text_new ();
Jean-Paul Saman's avatar
Jean-Paul Saman committed
281
    gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 1, (gchar *) N_("Time"), p_renderer, NULL);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
282 283 284
    p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvplaylist, 1 );
    gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 1 );
    gtk_tree_view_column_set_sort_column_id(p_column, 1);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
285 286
#if 0
    /* Column 3 - is a hidden column used for reliable deleting items from the underlying playlist */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
287
    p_renderer = gtk_cell_renderer_text_new ();
Jean-Paul Saman's avatar
Jean-Paul Saman committed
288
    gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 2, (gchar *) N_("Index"), p_renderer, NULL);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
289 290 291
    p_column = gtk_tree_view_get_column(p_intf->p_sys->p_tvplaylist, 2 );
    gtk_tree_view_column_add_attribute(p_column, p_renderer, "text", 2 );
    gtk_tree_view_column_set_sort_column_id(p_column, 2);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
292
#endif
293
    /* update the playlist */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
294 295
    p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
    p_playlist_store = gtk_list_store_new (3,
Jean-Paul Saman's avatar
Jean-Paul Saman committed
296
                G_TYPE_STRING, /* Filename */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
297 298
                G_TYPE_STRING, /* Time */
                G_TYPE_UINT);  /* Hidden index */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
299 300 301 302
    PlaylistRebuildListStore(p_playlist_store, p_playlist);
    gtk_tree_view_set_model(GTK_TREE_VIEW(p_intf->p_sys->p_tvplaylist), GTK_TREE_MODEL(p_playlist_store));
    g_object_unref(p_playlist_store);
    vlc_object_release(p_playlist); /* Free the playlist */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
303 304
    gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(p_intf->p_sys->p_tvplaylist)),GTK_SELECTION_MULTIPLE);

305 306 307 308
    /* Column properties */
    gtk_tree_view_set_headers_visible(p_intf->p_sys->p_tvplaylist, TRUE);
    gtk_tree_view_columns_autosize(p_intf->p_sys->p_tvplaylist);
    gtk_tree_view_set_headers_clickable(p_intf->p_sys->p_tvplaylist, TRUE);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
309
    /* END OF PLAYLIST GTK_TREE_VIEW */
310

311
    /* Hide the Preference TAB for now. */
312 313 314 315
    GtkWidget *p_preference_tab = NULL;
    p_preference_tab = gtk_notebook_get_nth_page(p_intf->p_sys->p_notebook,5);
    if (p_preference_tab != NULL)
      gtk_widget_hide(p_preference_tab);
316

317 318
    /* Show the control window */
    gtk_widget_show( p_intf->p_sys->p_window );
319 320

#ifdef NEED_GTK2_MAIN
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
    msg_Dbg( p_intf, "Manage GTK keyboard events using threads" );
    while( !p_intf->b_die )
    {
        Manage( p_intf );

        /* Sleep to avoid using all CPU - since some interfaces need to
         * access keyboard events, a 100ms delay is a good compromise */
        gdk_threads_leave();
        if (p_intf->p_libvlc->i_cpu & CPU_CAPABILITY_FPU)
            msleep( INTF_IDLE_SLEEP );
        else
            msleep( 1000 );
        gdk_threads_enter();
    }
#else
    msg_Dbg( p_intf, "Manage GTK keyboard events using timeouts" );
    /* Sleep to avoid using all CPU - since some interfaces needs to access
     * keyboard events, a 1000ms delay is a good compromise */
    if (p_intf->p_libvlc->i_cpu & CPU_CAPABILITY_FPU)
        i_dummy = gtk_timeout_add( INTF_IDLE_SLEEP / 1000, (GtkFunction)Manage, p_intf );
    else
        i_dummy = gtk_timeout_add( 1000, (GtkFunction)Manage, p_intf );

    /* Enter Gtk mode */
    gtk_main();
    /* Remove the timeout */
    gtk_timeout_remove( i_dummy );
#endif

    gtk_object_destroy( GTK_OBJECT(p_intf->p_sys->p_window) );
351
#ifdef NEED_GTK2_MAIN
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
    gdk_threads_leave();
#endif
}

/*****************************************************************************
 * GtkAutoplayFile: Autoplay file depending on configuration settings
 *****************************************************************************/
void GtkAutoPlayFile( vlc_object_t *p_this )
{
    GtkWidget *cbautoplay;
    intf_thread_t *p_intf;
    int i_index;
    vlc_list_t *p_list = vlc_list_find( p_this, VLC_OBJECT_INTF,
                                        FIND_ANYWHERE );

    for( i_index = 0; i_index < p_list->i_count; i_index++ )
    {
        p_intf = (intf_thread_t *)p_list->p_values[i_index].p_object ;

        if( strcmp( MODULE_STRING, p_intf->p_module->psz_object_name ) )
        {
            continue;
        }
        cbautoplay = GTK_WIDGET( gtk_object_get_data(
                            GTK_OBJECT( p_intf->p_sys->p_window ),
                            "cbautoplay" ) );

        if( !config_GetInt( p_this, "pda-autoplayfile" ) )
        {
            p_intf->p_sys->b_autoplayfile = VLC_FALSE;
        }
        else
        {
            p_intf->p_sys->b_autoplayfile = VLC_TRUE;
        }
        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( cbautoplay ),
                                      p_intf->p_sys->b_autoplayfile );
    }
    vlc_list_release( p_list );
}

/* following functions are local */

/*****************************************************************************
 * Manage: manage main thread messages
 *****************************************************************************
 * In this function, called approx. 10 times a second, we check what the
 * main program wanted to tell us.
 *****************************************************************************/
static int Manage( intf_thread_t *p_intf )
{
403
    GtkListStore *p_liststore;
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
    vlc_mutex_lock( &p_intf->change_lock );

    /* Update the input */
    if( p_intf->p_sys->p_input == NULL )
    {
        p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
                                                          FIND_ANYWHERE );
    }
    else if( p_intf->p_sys->p_input->b_dead )
    {
        vlc_object_release( p_intf->p_sys->p_input );
        p_intf->p_sys->p_input = NULL;
    }

    if( p_intf->p_sys->p_input )
    {
        input_thread_t *p_input = p_intf->p_sys->p_input;

422
        vlc_mutex_lock( &p_input->object_lock );
423 424 425 426 427 428 429 430 431
        if( !p_input->b_die )
        {
            {
                playlist_t *p_playlist;

                E_(GtkModeManage)( p_intf );
                p_intf->p_sys->b_playing = 1;

                /* update playlist interface */
432
                p_playlist = (playlist_t *) vlc_object_find(
433 434 435
                        p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
                if (p_playlist != NULL)
                {
Jean-Paul Saman's avatar
Jean-Paul Saman committed
436 437
                    p_liststore = gtk_list_store_new (3,
                                               G_TYPE_STRING,
438
                                               G_TYPE_STRING,
Jean-Paul Saman's avatar
Jean-Paul Saman committed
439
                                               G_TYPE_UINT);  /* Hidden index */
440 441
                    PlaylistRebuildListStore(p_liststore, p_playlist);
                    gtk_tree_view_set_model(p_intf->p_sys->p_tvplaylist, (GtkTreeModel*) p_liststore);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
442
                    g_object_unref(p_liststore);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
443
                    vlc_object_release( p_playlist );
444 445 446 447
                }
            }

            /* Manage the slider */
448 449
#if 0
#define p_area p_input->p_selected_area
450 451
            if (p_intf->p_libvlc->i_cpu & CPU_CAPABILITY_FPU)
            {
452
                /* Manage the slider for CPU_CAPABILITY_FPU hardware */
453
                if( p_intf->p_sys->b_playing )
454 455 456 457 458 459 460 461 462 463 464
                {
                    float newvalue = p_intf->p_sys->p_adj->value;

                    /* If the user hasn't touched the slider since the last time,
                     * then the input can safely change it */
                    if( newvalue == p_intf->p_sys->f_adj_oldvalue )
                    {
                        /* Update the value */
                        p_intf->p_sys->p_adj->value =
                        p_intf->p_sys->f_adj_oldvalue =
                            ( 100. * p_area->i_tell ) / p_area->i_size;
Jean-Paul Saman's avatar
Jean-Paul Saman committed
465
                        g_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
466 467 468 469 470 471
                                                 "value_changed" );
                    }
                    /* Otherwise, send message to the input if the user has
                     * finished dragging the slider */
                    else if( p_intf->p_sys->b_slider_free )
                    {
472
                        double f_pos = (double)newvalue / 100.0;
473 474

                        /* release the lock to be able to seek */
475
                        vlc_mutex_unlock( &p_input->object_lock );
476
                        var_SetFloat( p_input, "position", f_pos );
477
                        vlc_mutex_lock( &p_input->object_lock );
478 479 480 481 482 483 484 485 486

                        /* Update the old value */
                        p_intf->p_sys->f_adj_oldvalue = newvalue;
                    }
                }
            }
            else
            {
                /* Manage the slider without CPU_CAPABILITY_FPU hardware */
487
                if( p_intf->p_sys->b_playing )
488 489 490 491 492 493 494 495 496 497 498
                {
                    off_t newvalue = p_intf->p_sys->p_adj->value;

                    /* If the user hasn't touched the slider since the last time,
                     * then the input can safely change it */
                    if( newvalue == p_intf->p_sys->i_adj_oldvalue )
                    {
                        /* Update the value */
                        p_intf->p_sys->p_adj->value =
                        p_intf->p_sys->i_adj_oldvalue =
                            ( 100 * p_area->i_tell ) / p_area->i_size;
Jean-Paul Saman's avatar
Jean-Paul Saman committed
499
                        g_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
500 501 502 503 504 505
                                                 "value_changed" );
                    }
                    /* Otherwise, send message to the input if the user has
                     * finished dragging the slider */
                    else if( p_intf->p_sys->b_slider_free )
                    {
506
                        double f_pos = (double)newvalue / 100.0;
507 508

                        /* release the lock to be able to seek */
509
                        vlc_mutex_unlock( &p_input->object_lock );
510
                        var_SetFloat( p_input, "position", f_pos );
511
                        vlc_mutex_lock( &p_input->object_lock );
512 513 514 515 516 517

                        /* Update the old value */
                        p_intf->p_sys->i_adj_oldvalue = newvalue;
                    }
                }
            }
Jean-Paul Saman's avatar
Jean-Paul Saman committed
518
#undef p_area
519
#endif
520
        }
521
        vlc_mutex_unlock( &p_input->object_lock );
522 523 524 525 526 527 528
    }
    else if( p_intf->p_sys->b_playing && !p_intf->b_die )
    {
        E_(GtkModeManage)( p_intf );
        p_intf->p_sys->b_playing = 0;
    }

529
#ifndef NEED_GTK2_MAIN
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
    if( p_intf->b_die )
    {
        vlc_mutex_unlock( &p_intf->change_lock );

        /* Prepare to die, young Skywalker */
        gtk_main_quit();

        return FALSE;
    }
#endif

    vlc_mutex_unlock( &p_intf->change_lock );

    return TRUE;
}

/*****************************************************************************
 * GtkDisplayDate: display stream date
 *****************************************************************************
 * This function displays the current date related to the position in
 * the stream. It is called whenever the slider changes its value.
 * The lock has to be taken before you call the function.
 *****************************************************************************/
Jean-Paul Saman's avatar
Jean-Paul Saman committed
553
void E_(GtkDisplayDate)( GtkAdjustment *p_adj, gpointer userdata )
554 555 556
{
    intf_thread_t *p_intf;

Jean-Paul Saman's avatar
Jean-Paul Saman committed
557 558 559
    p_intf = (intf_thread_t*) userdata;
    if (p_intf == NULL)
        return;
560 561 562

    if( p_intf->p_sys->p_input )
    {
563
        char psz_time[ MSTRTIME_MAX_SIZE ];
564 565 566 567
        int64_t i_seconds;

        i_seconds = var_GetTime( p_intf->p_sys->p_input, "time" ) / I64C(1000000 );
        secstotimestr( psz_time, i_seconds );
568 569

        gtk_label_set_text( GTK_LABEL( p_intf->p_sys->p_slider_label ),
570
                            psz_time );
571 572 573 574 575 576 577 578 579 580 581
     }
}

/*****************************************************************************
 * GtkModeManage: actualize the aspect of the interface whenever the input
 *                changes.
 *****************************************************************************
 * The lock has to be taken before you call the function.
 *****************************************************************************/
gint E_(GtkModeManage)( intf_thread_t * p_intf )
{
Jean-Paul Saman's avatar
Jean-Paul Saman committed
582
    GtkWidget *     p_slider = NULL;
583 584
    vlc_bool_t      b_control;

Jean-Paul Saman's avatar
Jean-Paul Saman committed
585 586 587 588 589 590
    if ( p_intf->p_sys->p_window == NULL )
        msg_Err( p_intf, "Main widget not found" );

    p_slider = lookup_widget( p_intf->p_sys->p_window, "timeSlider");
    if (p_slider == NULL)
        msg_Err( p_intf, "Slider widget not found" );
591 592 593 594 595 596 597 598 599 600 601 602 603

    /* controls unavailable */
    b_control = 0;

    /* show the box related to current input mode */
    if( p_intf->p_sys->p_input )
    {
        /* initialize and show slider for seekable streams */
        {
            gtk_widget_show( GTK_WIDGET( p_slider ) );
        }

        /* control buttons for free pace streams */
604
        b_control = p_intf->p_sys->p_input->b_can_pace_control;
605 606 607 608 609

        msg_Dbg( p_intf, "stream has changed, refreshing interface" );
    }

    /* set control items */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
610 611 612
    gtk_widget_set_sensitive( lookup_widget( p_intf->p_sys->p_window, "tbRewind"), b_control );
    gtk_widget_set_sensitive( lookup_widget( p_intf->p_sys->p_window, "tbPause"), b_control );
    gtk_widget_set_sensitive( lookup_widget( p_intf->p_sys->p_window, "tbForward"), b_control );
613 614 615
    return TRUE;
}