1 /*****************************************************************************
2 * playlist.c : Playlist interface of the gtk-familiar plugin.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: playlist.c,v 1.1 2003/03/13 15:50:17 marcari Exp $
7 * Authors: Marc Ariberti <marcari@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <sys/types.h> /* off_t */
46 #include "interface.h"
52 FamiliarPlaylistEvent (GtkWidget *widget,
56 intf_thread_t * p_intf = GtkGetIntf( widget );
57 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
59 if( p_playlist == NULL )
64 if( ( event->button ).type == GDK_2BUTTON_PRESS )
70 p_clist = p_intf->p_sys->p_clistplaylist;
72 if( gtk_clist_get_selection_info( p_clist, (event->button).x,
73 (event->button).y, &i_row, &i_col ) == 1 )
75 playlist_Goto( p_playlist, i_row );
78 vlc_object_release( p_playlist );
79 FamiliarRebuildCList( p_clist, p_playlist );
83 vlc_object_release( p_playlist );
89 FamiliarPlaylistClear (GtkButton *button,
92 intf_thread_t * p_intf = GtkGetIntf( button );
93 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
97 if( p_playlist == NULL )
102 for(item = p_playlist->i_size - 1 ; item >= 0 ; item-- )
104 playlist_Delete( p_playlist, item);
107 vlc_object_release( p_playlist );
108 FamiliarRebuildCList( p_intf->p_sys->p_clistplaylist, p_playlist);
111 void FamiliarRebuildCList( GtkCList * p_clist, playlist_t * p_playlist )
114 gchar * ppsz_text[2];
120 gtk_clist_freeze( p_clist );
121 gtk_clist_clear( p_clist );
123 vlc_mutex_lock( &p_playlist->object_lock );
124 for( i_dummy = p_playlist->i_size ; i_dummy-- ; )
126 ppsz_text[0] = p_playlist->pp_items[i_dummy]->psz_name;
127 ppsz_text[1] = "no info";
128 gtk_clist_insert( p_clist, 0, ppsz_text );
130 vlc_mutex_unlock( &p_playlist->object_lock );
132 gtk_clist_set_background( p_clist, p_playlist->i_index, &red);
133 gtk_clist_thaw( p_clist );
138 FamiliarPlaylistUpdate (GtkButton *button,
141 intf_thread_t * p_intf = GtkGetIntf( button );
142 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
144 if( p_playlist == NULL )
150 FamiliarRebuildCList( p_intf->p_sys->p_clistplaylist, p_playlist );
153 static void FamiliarDeleteGListItem( gpointer data, gpointer param )
155 int i_cur_row = (long)data;
156 playlist_t * p_playlist = param;
158 playlist_Delete( p_playlist, i_cur_row );
161 static gint FamiliarCompareItems( gconstpointer a, gconstpointer b )
163 return (ptrdiff_t) ( (int *)b - (int *)a );
168 FamiliarPlaylistDel (GtkButton *button,
171 /* user wants to delete a file in the queue */
174 intf_thread_t * p_intf = GtkGetIntf( button );
175 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
177 if( p_playlist == NULL )
183 /* lock the struct */
184 vlc_mutex_lock( &p_intf->change_lock );
186 p_selection = p_intf->p_sys->p_clistplaylist->selection;
188 if( g_list_length( p_selection ) )
190 /* reverse-sort so that we can delete from the furthest
191 * to the closest item to delete...
193 p_selection = g_list_sort( p_selection, FamiliarCompareItems );
194 g_list_foreach( p_selection, FamiliarDeleteGListItem, p_playlist );
197 vlc_mutex_unlock( &p_intf->change_lock );
200 vlc_object_release( p_playlist );
201 FamiliarRebuildCList( p_intf->p_sys->p_clistplaylist, p_playlist );