Ejemplo n.º 1
0
void onUpdatePlaylist(GtkButton *button, gpointer user_data)
{
    intf_thread_t *  p_intf = GtkGetIntf( button );
    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                       FIND_ANYWHERE );
    GtkTreeView *p_tvplaylist = NULL;

    if( p_playlist == NULL )
    {
        return;
    }

    p_tvplaylist = (GtkTreeView*) lookup_widget( GTK_WIDGET(button), "tvPlaylist");
    if (p_tvplaylist)
    {
        GtkListStore *p_model = NULL;

        /* Rebuild the playlist then. */
        p_model = gtk_list_store_new (3,
                    G_TYPE_STRING, /* Filename */
                    G_TYPE_STRING, /* Time */
                    G_TYPE_UINT);  /* Hidden field */
        if (p_model)
        {
            PlaylistRebuildListStore(p_model, p_playlist);
            gtk_tree_view_set_model(GTK_TREE_VIEW(p_tvplaylist), GTK_TREE_MODEL(p_model));
            g_object_unref(p_model);
        }
    }
    vlc_object_release( p_playlist );
}
Ejemplo n.º 2
0
void onDeletePlaylist(GtkButton *button, gpointer user_data)
{
    intf_thread_t *p_intf = GtkGetIntf( button );
    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                       FIND_ANYWHERE );
    GtkTreeView    *p_tvplaylist;

    /* Delete an arbitrary item from the playlist */
    p_tvplaylist = (GtkTreeView *) lookup_widget( GTK_WIDGET(button), "tvPlaylist" );
    if (p_tvplaylist != NULL)
    {
        GList *p_rows = NULL;
        GList *p_node;
        GtkTreeModel *p_model = NULL;
        GtkListStore *p_store = NULL;
        GtkTreeSelection *p_selection = gtk_tree_view_get_selection(p_tvplaylist);

        p_model = gtk_tree_view_get_model(p_tvplaylist);
        if (p_model)
        {
            p_rows = gtk_tree_selection_get_selected_rows(p_selection, &p_model);

            if( g_list_length( p_rows ) )
            {
                /* reverse-sort so that we can delete from the furthest
                 * to the closest item to delete...
                 */
                p_rows = g_list_reverse( p_rows );
            }

            for (p_node=p_rows; p_node!=NULL; p_node = p_node->next)
            {
                GtkTreeIter iter;
                GtkTreePath *p_path = NULL;

                p_path = (GtkTreePath *)p_node->data;
                if (p_path)
                {
                    if (gtk_tree_model_get_iter(p_model, &iter, p_path))
                    {
                        gint item;

                        gtk_tree_model_get(p_model, &iter, 2, &item, -1);
                        playlist_LockDelete(p_playlist, item);
                    }
                }
            }
#if 0 
            g_list_foreach (p_rows, (GFunc*)gtk_tree_path_free, NULL);
#endif /* Testing the next line */
            g_list_foreach (p_rows, deleteItemFromPlaylist, NULL);
            g_list_free (p_rows);
        }

        /* Rebuild the playlist then. */
        p_store = gtk_list_store_new (3,
                    G_TYPE_STRING, /* Filename */
                    G_TYPE_STRING, /* Time */
                    G_TYPE_UINT);  /* Hidden field */
        if (p_store)
        {
            PlaylistRebuildListStore(p_store, p_playlist);
            gtk_tree_view_set_model(GTK_TREE_VIEW(p_tvplaylist), GTK_TREE_MODEL(p_store));
            g_object_unref(p_store);
        }
    }
    vlc_object_release( p_playlist );
}
Ejemplo n.º 3
0
/*****************************************************************************
 * 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 )
{
    GtkListStore *p_liststore;
    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;
        int64_t i_time = 0, i_length = 0;

        vlc_mutex_lock( &p_input->object_lock );
        if( !p_input->b_die )
        {
            playlist_t *p_playlist;

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

            /* update playlist interface */
            p_playlist = (playlist_t *) vlc_object_find(
                    p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
            if (p_playlist != NULL)
            {
                p_liststore = gtk_list_store_new (3,
                                            G_TYPE_STRING,
                                            G_TYPE_STRING,
                                            G_TYPE_UINT);  /* Hidden index */
                PlaylistRebuildListStore(p_liststore, p_playlist);
                gtk_tree_view_set_model(p_intf->p_sys->p_tvplaylist, (GtkTreeModel*) p_liststore);
                g_object_unref(p_liststore);
                vlc_object_release( p_playlist );
            }

            /* Manage the slider */
            i_time = var_GetTime( p_intf->p_sys->p_input, "time" );
            i_length = var_GetTime( p_intf->p_sys->p_input, "length" );

            if (p_intf->p_libvlc->i_cpu & CPU_CAPABILITY_FPU)
            {
                /* Manage the slider for CPU_CAPABILITY_FPU hardware */
                if( p_intf->p_sys->b_playing )
                {
                    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 * i_time ) / i_length;
                        g_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
                                                 "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 )
                    {
                        double f_pos = (double)newvalue / 100.0;

                        /* release the lock to be able to seek */
                        vlc_mutex_unlock( &p_input->object_lock );
                        var_SetFloat( p_input, "position", f_pos );
                        vlc_mutex_lock( &p_input->object_lock );

                        /* Update the old value */
                        p_intf->p_sys->f_adj_oldvalue = newvalue;
                    }
                }
            }
            else
            {
                /* Manage the slider without CPU_CAPABILITY_FPU hardware */
                if( p_intf->p_sys->b_playing )
                {
                    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 * i_time ) / i_length;
                        g_signal_emit_by_name( GTK_OBJECT( p_intf->p_sys->p_adj ),
                                                 "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 )
                    {
                        double f_pos = (double)newvalue / 100.0;

                        /* release the lock to be able to seek */
                        vlc_mutex_unlock( &p_input->object_lock );
                        var_SetFloat( p_input, "position", f_pos );
                        vlc_mutex_lock( &p_input->object_lock );

                        /* Update the old value */
                        p_intf->p_sys->i_adj_oldvalue = newvalue;
                    }
                }
            }
        }
        vlc_mutex_unlock( &p_input->object_lock );
    }
    else if( p_intf->p_sys->b_playing && !p_intf->b_die )
    {
        E_(GtkModeManage)( p_intf );
        p_intf->p_sys->b_playing = 0;
    }

#ifndef NEED_GTK2_MAIN
    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;
}
Ejemplo n.º 4
0
/*****************************************************************************
 * 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 )
{
#ifndef NEED_GTK2_MAIN
    /* 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
    playlist_t        *p_playlist;
    GtkCellRenderer   *p_renderer = NULL;
    GtkTreeViewColumn *p_column   = NULL;
    GtkListStore      *p_filelist = NULL;
    GtkListStore      *p_playlist_store = NULL;

#ifndef NEED_GTK2_MAIN
    gtk_set_locale ();
    msg_Dbg( p_intf, "Starting pda GTK2+ interface" );
    gtk_init( &i_args, &pp_args );
#else
    /* Initialize Gtk+ */
    msg_Dbg( p_intf, "Starting pda GTK2+ interface thread" );
    gdk_threads_enter();
#endif

    /* Create some useful widgets that will certainly be used */
/* FIXME: magic path */
    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" );
    }

    /* 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 );

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

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

    /* Get the slider object */
    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" );
    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." );

    /* Connect the date display to the slider */
    p_intf->p_sys->p_adj = gtk_range_get_adjustment( GTK_RANGE(p_intf->p_sys->p_slider) );
    if (p_intf->p_sys->p_adj == NULL)
        msg_Err( p_intf, "Adjustment range not found." );
    g_signal_connect( GTK_OBJECT( p_intf->p_sys->p_adj ), "value_changed",
                         G_CALLBACK( E_(GtkDisplayDate) ), p_intf );
    p_intf->p_sys->f_adj_oldvalue = 0;
    p_intf->p_sys->i_adj_oldvalue = 0;

    /* BEGIN OF FILEVIEW GTK_TREE_VIEW */
    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");

    /* Insert columns 0 */
    p_renderer = gtk_cell_renderer_text_new ();
    gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 0, (gchar *) N_("Filename"), p_renderer, NULL);
    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);
    /* Insert columns 1 */
    p_renderer = gtk_cell_renderer_text_new ();
    gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 1, (gchar *) N_("Permissions"), p_renderer, NULL);
    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);
    /* Insert columns 2 */
    p_renderer = gtk_cell_renderer_text_new ();
    gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 2, (gchar *) N_("Size"), p_renderer, NULL);
    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);
    /* Insert columns 3 */
    p_renderer = gtk_cell_renderer_text_new ();
    gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 3, (gchar *) N_("Owner"), p_renderer, NULL);
    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);
    /* Insert columns 4 */
    p_renderer = gtk_cell_renderer_text_new ();
    gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvfile, 4, (gchar *) N_("Group"), p_renderer, NULL);
    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);

    /* Get new directory listing */
    p_filelist = gtk_list_store_new (5,
                G_TYPE_STRING, /* Filename */
                G_TYPE_STRING, /* permissions */
                G_TYPE_UINT64, /* File size */
                G_TYPE_STRING, /* Owner */
                G_TYPE_STRING);/* Group */
    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 */
    gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(p_intf->p_sys->p_tvfile)),GTK_SELECTION_MULTIPLE);

    /* 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);
    gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(p_intf->p_sys->p_tvfile),TRUE);
    /* END OF FILEVIEW GTK_TREE_VIEW */

    /* BEGIN OF PLAYLIST GTK_TREE_VIEW */
    p_intf->p_sys->p_tvplaylist = NULL;
    p_intf->p_sys->p_tvplaylist = (GtkTreeView *) lookup_widget( p_intf->p_sys->p_window, "tvPlaylist");
    if (NULL == p_intf->p_sys->p_tvplaylist)
       msg_Err(p_intf, "Error obtaining pointer to Play List");

    /* Columns 1 */
    p_renderer = gtk_cell_renderer_text_new ();
    gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 0, (gchar *) N_("Filename"), p_renderer, NULL);
    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);
    /* Column 2 */
    p_renderer = gtk_cell_renderer_text_new ();
    gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 1, (gchar *) N_("Time"), p_renderer, NULL);
    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);
#if 0
    /* Column 3 - is a hidden column used for reliable deleting items from the underlying playlist */
    p_renderer = gtk_cell_renderer_text_new ();
    gtk_tree_view_insert_column_with_attributes(p_intf->p_sys->p_tvplaylist, 2, (gchar *) N_("Index"), p_renderer, NULL);
    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);
#endif
    /* update the playlist */
    p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
    p_playlist_store = gtk_list_store_new (3,
                G_TYPE_STRING, /* Filename */
                G_TYPE_STRING, /* Time */
                G_TYPE_UINT);  /* Hidden index */
    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 */
    gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(p_intf->p_sys->p_tvplaylist)),GTK_SELECTION_MULTIPLE);

    /* 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);
    /* END OF PLAYLIST GTK_TREE_VIEW */

    /* Hide the Preference TAB for now. */
    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);

    /* Show the control window */
    gtk_widget_show( p_intf->p_sys->p_window );

#ifdef NEED_GTK2_MAIN
    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) );
#ifdef NEED_GTK2_MAIN
    gdk_threads_leave();
#endif
}