1 /*****************************************************************************
2 * callbacks.c : Callbacks for the Familiar Linux Gtk+ plugin.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: callbacks.c,v 1.10 2002/09/30 11:05:38 sam Exp $
7 * Authors: Jean-Paul Saman <jpsaman@wxs.nl>
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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <sys/types.h> /* off_t */
46 #include "callbacks.h"
47 #include "interface.h"
51 /*#include "netutils.h"*/
53 static void MediaURLOpenChanged( GtkWidget *widget, gchar *psz_url );
54 static char* get_file_perm(const char *path);
56 /*****************************************************************************
57 * Useful function to retrieve p_intf
58 ****************************************************************************/
59 void * __GtkGetIntf( GtkWidget * widget )
63 if( GTK_IS_MENU_ITEM( widget ) )
65 /* Look for a GTK_MENU */
66 while( widget->parent && !GTK_IS_MENU( widget ) )
68 widget = widget->parent;
71 /* Maybe this one has the data */
72 p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" );
78 /* Otherwise, the parent widget has it */
79 widget = gtk_menu_get_attach_widget( GTK_MENU( widget ) );
82 /* We look for the top widget */
83 widget = gtk_widget_get_toplevel( GTK_WIDGET( widget ) );
85 p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" );
90 /*****************************************************************************
91 * Helper functions for URL changes in Media and Preferences notebook pages.
92 ****************************************************************************/
93 static void MediaURLOpenChanged( GtkWidget *widget, gchar *psz_url )
95 intf_thread_t *p_intf = GtkGetIntf( widget );
96 playlist_t *p_playlist;
98 g_print( "%s\n",psz_url );
100 // Add p_url to playlist .... but how ?
101 p_playlist = (playlist_t *)
102 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
105 playlist_Add( p_playlist, (char*)psz_url,
106 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
107 vlc_object_release( p_playlist );
111 /*****************************************************************
112 * Read directory helper function.
113 ****************************************************************/
114 void ReadDirectory( GtkCList *clist, char *psz_dir )
116 intf_thread_t *p_intf = GtkGetIntf( clist );
117 struct dirent **namelist;
122 n = scandir(".", &namelist, 0, NULL);
130 gtk_clist_freeze( clist );
131 gtk_clist_clear( clist );
135 /* This is a list of strings. */
136 ppsz_text[0] = namelist[i]->d_name;
137 ppsz_text[1] = get_file_perm(namelist[i]->d_name);
138 if (strcmp(ppsz_text[1],"") == 0)
139 msg_Err( p_intf->p_sys->p_input, "File system error unknown filetype encountered.");
140 gtk_clist_insert( clist, i, ppsz_text );
144 gtk_clist_thaw( clist );
148 static char* get_file_perm(const char *path)
153 perm = (char *) malloc(sizeof(char)*10);
154 strncpy( perm, "----------", sizeof("----------"));
155 if (lstat(path, &st)==0)
157 if (S_ISLNK(st.st_mode))
159 else if (S_ISDIR(st.st_mode))
161 else if (S_ISCHR(st.st_mode))
163 else if (S_ISBLK(st.st_mode))
165 else if (S_ISFIFO(st.st_mode))
167 else if (S_ISSOCK(st.st_mode))
169 else if (S_ISREG(st.st_mode))
171 else /* Unknown type is an error */
173 /* Get file permissions */
175 if (st.st_mode & S_IRUSR)
177 if (st.st_mode & S_IWUSR)
179 if (st.st_mode & S_IXUSR)
181 if (st.st_mode & S_ISUID)
186 else if (st.st_mode & S_ISUID)
189 if (st.st_mode & S_IRGRP)
191 if (st.st_mode & S_IWGRP)
193 if (st.st_mode & S_IXGRP)
195 if (st.st_mode & S_ISGID)
200 else if (st.st_mode & S_ISGID)
203 if (st.st_mode & S_IROTH)
205 if (st.st_mode & S_IWOTH)
207 if (st.st_mode & S_IXOTH)
210 if (st.st_mode &S_ISVTX)
215 else if (st.st_mode &S_ISVTX)
222 * Main interface callbacks
225 gboolean FamiliarExit( GtkWidget *widget,
228 intf_thread_t *p_intf = GtkGetIntf( widget );
230 vlc_mutex_lock( &p_intf->change_lock );
231 p_intf->p_vlc->b_die = VLC_TRUE;
232 vlc_mutex_unlock( &p_intf->change_lock );
238 on_toolbar_open_clicked (GtkButton *button,
241 intf_thread_t *p_intf = GtkGetIntf( button );
243 /* Testing routine */
245 GtkCList *clistmedia = NULL;
246 clistmedia = GTK_CLIST( lookup_widget( p_intf->p_sys->p_window,
248 if (GTK_CLIST(clistmedia))
250 ReadDirectory(clistmedia, ".");
253 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
254 gdk_window_raise( p_intf->p_sys->p_window->window );
259 on_toolbar_preferences_clicked (GtkButton *button,
262 intf_thread_t *p_intf = GtkGetIntf( button );
264 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
265 gdk_window_raise( p_intf->p_sys->p_window->window );
270 on_toolbar_rewind_clicked (GtkButton *button,
273 intf_thread_t * p_intf = GtkGetIntf( button );
275 if( p_intf->p_sys->p_input )
277 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_SLOWER );
283 on_toolbar_pause_clicked (GtkButton *button,
286 intf_thread_t * p_intf = GtkGetIntf( button );
288 if( p_intf->p_sys->p_input )
290 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
296 on_toolbar_play_clicked (GtkButton *button,
299 intf_thread_t * p_intf = GtkGetIntf( button );
300 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
302 if( p_playlist == NULL )
304 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
305 gdk_window_raise( p_intf->p_sys->p_window->window );
306 /* Display open page */
309 /* If the playlist is empty, open a file requester instead */
310 vlc_mutex_lock( &p_playlist->object_lock );
311 if( p_playlist->i_size )
313 vlc_mutex_unlock( &p_playlist->object_lock );
314 playlist_Play( p_playlist );
315 vlc_object_release( p_playlist );
316 gdk_window_lower( p_intf->p_sys->p_window->window );
320 vlc_mutex_unlock( &p_playlist->object_lock );
321 vlc_object_release( p_playlist );
322 /* Display open page */
328 on_toolbar_stop_clicked (GtkButton *button,
331 intf_thread_t * p_intf = GtkGetIntf( button );
332 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
336 playlist_Stop( p_playlist );
337 vlc_object_release( p_playlist );
338 gdk_window_raise( p_intf->p_sys->p_window->window );
344 on_toolbar_forward_clicked (GtkButton *button,
347 intf_thread_t * p_intf = GtkGetIntf( button );
349 if( p_intf->p_sys->p_input )
351 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_FASTER );
357 on_toolbar_about_clicked (GtkButton *button,
360 intf_thread_t *p_intf = GtkGetIntf( button );
363 if (p_intf->p_sys->p_notebook)
365 /* if ( gtk_get_data( GTK_WIDGET(p_intf->p_sys->p_notebook), "visible" ) )
366 * gtk_widget_hide( GTK_WIDGET(p_intf->p_sys->p_notebook) );
368 */ gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
370 gdk_window_raise( p_intf->p_sys->p_window->window );
375 on_comboURL_entry_changed (GtkEditable *editable,
378 intf_thread_t * p_intf = GtkGetIntf( editable );
381 if (p_intf->p_sys->b_autoplayfile == 1)
383 psz_url = gtk_entry_get_text(GTK_ENTRY(editable));
384 MediaURLOpenChanged( GTK_WIDGET(editable), psz_url );
389 on_clistmedia_click_column (GtkCList *clist,
393 static GtkSortType sort_type = GTK_SORT_ASCENDING;
395 // Should sort on column
398 case GTK_SORT_ASCENDING:
399 sort_type = GTK_SORT_DESCENDING;
401 case GTK_SORT_DESCENDING:
402 sort_type = GTK_SORT_ASCENDING;
405 gtk_clist_freeze( clist );
406 gtk_clist_set_sort_type( clist, sort_type );
407 gtk_clist_sort( clist );
408 gtk_clist_thaw( clist );
413 on_clistmedia_select_row (GtkCList *clist,
423 ret = gtk_clist_get_text (clist, row, 0, text);
426 if (lstat((char*)text[0], &st)==0)
428 if (S_ISDIR(st.st_mode))
429 ReadDirectory(clist, text[0]);
431 MediaURLOpenChanged(GTK_WIDGET(clist), text[0]);
438 on_cbautoplay_toggled (GtkToggleButton *togglebutton,
441 intf_thread_t * p_intf = GtkGetIntf( togglebutton );
443 if (p_intf->p_sys->b_autoplayfile == 1)
444 p_intf->p_sys->b_autoplayfile = 0;
446 p_intf->p_sys->b_autoplayfile = 1;
451 on_familiar_delete_event (GtkWidget *widget,
455 FamiliarExit( GTK_WIDGET( widget ), user_data );