]> git.sesse.net Git - vlc/blob - modules/gui/familiar/playlist.c
Fixed superflous tuning ;-)
[vlc] / modules / gui / familiar / playlist.c
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 $
6  *
7  * Authors: Marc Ariberti <marcari@videolan.org>
8  *      
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.
13  * 
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.
18  *
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  *****************************************************************************/
23
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <sys/types.h>                                              /* off_t */
29 #include <stdlib.h>
30
31 #include <vlc/vlc.h>
32 #include <vlc/intf.h>
33 #include <vlc/vout.h>
34
35 #include <stdio.h>
36 #include <string.h>
37 #include <dirent.h>
38 #include <sys/stat.h>
39 #include <unistd.h>
40
41 #ifdef HAVE_CONFIG_H
42 #  include <config.h>
43 #endif
44 #include <gtk/gtk.h>
45
46 #include "interface.h"
47 #include "support.h"
48 #include "familiar.h"
49 #include "playlist.h"
50
51 gboolean
52 FamiliarPlaylistEvent                  (GtkWidget       *widget,
53                                         GdkEvent        *event,
54                                         gpointer         user_data)
55 {
56     intf_thread_t *  p_intf = GtkGetIntf( widget );
57     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
58                                                        FIND_ANYWHERE );
59     if( p_playlist == NULL )
60     {
61         return FALSE;
62     }
63
64     if( ( event->button ).type == GDK_2BUTTON_PRESS )
65     {
66         GtkCList *  p_clist;
67         gint        i_row;
68         gint        i_col;
69
70         p_clist = p_intf->p_sys->p_clistplaylist;
71
72         if( gtk_clist_get_selection_info( p_clist, (event->button).x,
73                     (event->button).y, &i_row, &i_col ) == 1 )
74         {
75             playlist_Goto( p_playlist, i_row );
76         }
77
78         vlc_object_release( p_playlist );
79         FamiliarRebuildCList( p_clist, p_playlist );
80         return TRUE;
81     }
82
83     vlc_object_release( p_playlist );
84
85   return FALSE;
86 }
87
88 void
89 FamiliarPlaylistClear                  (GtkButton       *button,
90                                         gpointer         user_data)
91 {
92     intf_thread_t *  p_intf = GtkGetIntf( button );
93     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
94                                                        FIND_ANYWHERE );
95     int item;
96     
97     if( p_playlist == NULL )
98     {
99         return;
100     }
101
102     for(item = p_playlist->i_size - 1 ; item >= 0 ; item-- )
103     {
104         playlist_Delete( p_playlist, item);
105     }
106     
107     vlc_object_release( p_playlist );
108     FamiliarRebuildCList( p_intf->p_sys->p_clistplaylist, p_playlist);
109 }
110
111 void FamiliarRebuildCList( GtkCList * p_clist, playlist_t * p_playlist )
112 {
113     int         i_dummy;
114     gchar *     ppsz_text[2];
115     GdkColor    red;
116     red.red     = 65535;
117     red.blue    = 0;
118     red.green   = 0;
119
120     gtk_clist_freeze( p_clist );
121     gtk_clist_clear( p_clist );
122
123     vlc_mutex_lock( &p_playlist->object_lock );
124     for( i_dummy = p_playlist->i_size ; i_dummy-- ; )
125     {
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 );
129     }
130     vlc_mutex_unlock( &p_playlist->object_lock );
131
132     gtk_clist_set_background( p_clist, p_playlist->i_index, &red);
133     gtk_clist_thaw( p_clist );
134 }
135
136
137 void
138 FamiliarPlaylistUpdate                 (GtkButton       *button,
139                                         gpointer         user_data)
140 {
141     intf_thread_t *  p_intf = GtkGetIntf( button );
142     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
143                                                        FIND_ANYWHERE );
144     if( p_playlist == NULL )
145     {
146         return;
147     }
148
149
150     FamiliarRebuildCList( p_intf->p_sys->p_clistplaylist, p_playlist );
151 }
152
153 static void FamiliarDeleteGListItem( gpointer data, gpointer param )
154 {
155     int i_cur_row = (long)data;
156     playlist_t * p_playlist = param;
157
158     playlist_Delete( p_playlist, i_cur_row );
159 }
160
161 static gint FamiliarCompareItems( gconstpointer a, gconstpointer b )
162 {
163     return (ptrdiff_t) ( (int *)b - (int *)a );
164 }
165
166
167 void
168 FamiliarPlaylistDel                    (GtkButton       *button,
169                                         gpointer         user_data)
170 {
171     /* user wants to delete a file in the queue */
172     GList *     p_selection;
173     
174     intf_thread_t *  p_intf = GtkGetIntf( button );
175     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
176                                                        FIND_ANYWHERE );
177     if( p_playlist == NULL )
178     {
179         return;
180     }
181
182     
183     /* lock the struct */
184     vlc_mutex_lock( &p_intf->change_lock );
185
186     p_selection = p_intf->p_sys->p_clistplaylist->selection;
187
188     if( g_list_length( p_selection ) )
189     {
190         /* reverse-sort so that we can delete from the furthest
191          * to the closest item to delete...
192          */
193         p_selection = g_list_sort( p_selection, FamiliarCompareItems );
194         g_list_foreach( p_selection, FamiliarDeleteGListItem, p_playlist );
195     }
196
197     vlc_mutex_unlock( &p_intf->change_lock );
198
199
200     vlc_object_release( p_playlist );
201     FamiliarRebuildCList( p_intf->p_sys->p_clistplaylist, p_playlist );
202 }
203