1 /*****************************************************************************
2 * callbacks.c : Callbacks for the Familiar Linux Gtk+ plugin.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: callbacks.c,v 1.24 2003/07/31 20:47:09 reno 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 static char* get_file_perm(const char *path);
53 /*****************************************************************************
54 * Useful function to retrieve p_intf
55 ****************************************************************************/
56 void * E_(__GtkGetIntf)( GtkWidget * widget )
60 if( GTK_IS_MENU_ITEM( widget ) )
62 /* Look for a GTK_MENU */
63 while( widget->parent && !GTK_IS_MENU( widget ) )
65 widget = widget->parent;
68 /* Maybe this one has the data */
69 p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" );
75 /* Otherwise, the parent widget has it */
76 widget = gtk_menu_get_attach_widget( GTK_MENU( widget ) );
79 /* We look for the top widget */
80 widget = gtk_widget_get_toplevel( GTK_WIDGET( widget ) );
82 p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" );
87 /*****************************************************************************
88 * Helper functions for URL changes in Media and Preferences notebook pages.
89 ****************************************************************************/
90 void MediaURLOpenChanged( GtkWidget *widget, gchar *psz_url )
92 intf_thread_t *p_intf = GtkGetIntf( widget );
93 playlist_t *p_playlist;
95 // Add p_url to playlist .... but how ?
96 p_playlist = (playlist_t *)
97 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
99 if( p_playlist == NULL)
106 if (p_intf->p_sys->b_autoplayfile)
108 playlist_Add( p_playlist, (char*)psz_url, 0, 0,
109 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
113 playlist_Add( p_playlist, (char*)psz_url, 0, 0,
114 PLAYLIST_APPEND, PLAYLIST_END );
116 vlc_object_release( p_playlist );
117 FamiliarRebuildCList( p_intf->p_sys->p_clistplaylist, p_playlist);
121 /*****************************************************************
122 * Read directory helper function.
123 ****************************************************************/
124 void ReadDirectory( GtkCList *clist, char *psz_dir )
126 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(clist) );
127 struct dirent **namelist;
130 msg_Dbg(p_intf, "changing to dir %s", psz_dir);
133 status = chdir(psz_dir);
135 msg_Err( p_intf, "permision denied" );
137 n = scandir(".", &namelist, 0, alphasort);
146 msg_Dbg( p_intf, "updating interface" );
147 gtk_clist_freeze( clist );
148 gtk_clist_clear( clist );
150 /* XXX : kludge temporaire pour yopy */
152 ppsz_text[1] = get_file_perm("..");
156 gtk_clist_insert( GTK_CLIST(clist), ctr++, ppsz_text );
161 if (namelist[i]->d_name[0] != '.')
163 /* This is a list of strings. */
164 ppsz_text[0] = namelist[i]->d_name;
165 ppsz_text[1] = get_file_perm(namelist[i]->d_name);
169 // msg_Dbg(p_intf, "(%d) file: %s permission: %s", i, ppsz_text[0], ppsz_text[1] );
170 gtk_clist_insert( GTK_CLIST(clist), ctr++, ppsz_text );
173 gtk_clist_thaw( clist );
177 /* now switch to the "file" tab */
178 if (p_intf->p_sys->p_mediabook)
180 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_mediabook) );
181 gtk_notebook_set_page(p_intf->p_sys->p_mediabook,0);
185 static char* get_file_perm(const char *path)
190 perm = (char *) malloc(sizeof(char)*10);
191 strncpy( perm, "----------", sizeof("----------"));
192 if (lstat(path, &st)==0)
194 if (S_ISLNK(st.st_mode))
196 else if (S_ISDIR(st.st_mode))
198 else if (S_ISCHR(st.st_mode))
200 else if (S_ISBLK(st.st_mode))
202 else if (S_ISFIFO(st.st_mode))
204 else if (S_ISSOCK(st.st_mode))
206 else if (S_ISREG(st.st_mode))
208 else /* Unknown type is an error */
210 /* Get file permissions */
212 if (st.st_mode & S_IRUSR)
214 if (st.st_mode & S_IWUSR)
216 if (st.st_mode & S_IXUSR)
218 if (st.st_mode & S_ISUID)
223 else if (st.st_mode & S_ISUID)
226 if (st.st_mode & S_IRGRP)
228 if (st.st_mode & S_IWGRP)
230 if (st.st_mode & S_IXGRP)
232 if (st.st_mode & S_ISGID)
237 else if (st.st_mode & S_ISGID)
240 if (st.st_mode & S_IROTH)
242 if (st.st_mode & S_IWOTH)
244 if (st.st_mode & S_IXOTH)
247 if (st.st_mode &S_ISVTX)
252 else if (st.st_mode &S_ISVTX)
259 * Main interface callbacks
262 gboolean FamiliarExit( GtkWidget *widget,
265 intf_thread_t *p_intf = GtkGetIntf( widget );
267 vlc_mutex_lock( &p_intf->change_lock );
268 p_intf->p_vlc->b_die = VLC_TRUE;
269 vlc_mutex_unlock( &p_intf->change_lock );
275 on_toolbar_open_clicked (GtkButton *button,
278 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) );
280 if (p_intf->p_sys->p_notebook)
282 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
283 gtk_notebook_set_page(p_intf->p_sys->p_notebook,0);
285 if (p_intf->p_sys->p_mediabook)
287 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_mediabook) );
288 gtk_notebook_set_page(p_intf->p_sys->p_mediabook,0);
290 gdk_window_raise( p_intf->p_sys->p_window->window );
291 if (p_intf->p_sys->p_clist)
293 ReadDirectory(p_intf->p_sys->p_clist, ".");
299 on_toolbar_preferences_clicked (GtkButton *button,
302 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) );
304 if (p_intf->p_sys->p_notebook)
306 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
307 gtk_notebook_set_page(p_intf->p_sys->p_notebook,2);
309 gdk_window_raise( p_intf->p_sys->p_window->window );
314 on_toolbar_rewind_clicked (GtkButton *button,
317 intf_thread_t * p_intf = GtkGetIntf( button );
319 if( p_intf->p_sys->p_input != NULL )
321 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_SLOWER );
327 on_toolbar_pause_clicked (GtkButton *button,
330 intf_thread_t * p_intf = GtkGetIntf( button );
332 if( p_intf->p_sys->p_input != NULL )
334 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
340 on_toolbar_play_clicked (GtkButton *button,
343 intf_thread_t * p_intf = GtkGetIntf( GTK_WIDGET( button ) );
344 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
346 if( p_playlist == NULL )
348 /* Display open page */
349 on_toolbar_open_clicked(button,user_data);
352 /* If the playlist is empty, open a file requester instead */
353 vlc_mutex_lock( &p_playlist->object_lock );
354 if( p_playlist->i_size )
356 vlc_mutex_unlock( &p_playlist->object_lock );
357 playlist_Play( p_playlist );
358 vlc_object_release( p_playlist );
359 gdk_window_lower( p_intf->p_sys->p_window->window );
363 vlc_mutex_unlock( &p_playlist->object_lock );
364 vlc_object_release( p_playlist );
365 /* Display open page */
366 on_toolbar_open_clicked(button,user_data);
372 on_toolbar_stop_clicked (GtkButton *button,
375 intf_thread_t * p_intf = GtkGetIntf( GTK_WIDGET( button ) );
376 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
380 playlist_Stop( p_playlist );
381 vlc_object_release( p_playlist );
382 gdk_window_raise( p_intf->p_sys->p_window->window );
388 on_toolbar_forward_clicked (GtkButton *button,
391 intf_thread_t * p_intf = GtkGetIntf( button );
393 if( p_intf->p_sys->p_input != NULL )
395 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_FASTER );
400 on_toolbar_playlist_clicked (GtkButton *button,
403 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(button) );
406 if (p_intf->p_sys->p_notebook)
408 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
409 gtk_notebook_set_page(p_intf->p_sys->p_notebook,1);
411 gdk_window_raise( p_intf->p_sys->p_window->window );
416 on_toolbar_about_clicked (GtkButton *button,
419 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(button) );
422 if (p_intf->p_sys->p_notebook)
424 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
425 gtk_notebook_set_page(p_intf->p_sys->p_notebook,3);
427 gdk_window_raise( p_intf->p_sys->p_window->window );
432 on_comboURL_entry_changed (GtkEditable *editable,
435 intf_thread_t * p_intf = GtkGetIntf( GTK_WIDGET(editable) );
440 psz_url = gtk_entry_get_text(GTK_ENTRY(editable));
441 /* if( (strncmp("file://",(const char *) psz_url,7)==0) ||
442 (strncmp("udp://",(const char *) psz_url,6)==0) ||
443 (strncmp("udp4://",(const char *) psz_url,7)==0) ||
444 (strncmp("udp6://",(const char *) psz_url,7)==0) ||
445 (strncmp("udpstream://",(const char *) psz_url,12)==0) ||
446 (strncmp("rtp://",(const char *) psz_url,6)==0) ||
447 (strncmp("rtp4://",(const char *) psz_url,7)==0) ||
448 (strncmp("rtp6://",(const char *) psz_url,7)==0) ||
449 (strncmp("rtpstream://",(const char *) psz_url,12)==0) ||
450 (strncmp("ftp://",(const char *) psz_url,6)==0) ||
451 (strncmp("mms://",(const char *) psz_url,6)==0) ||
452 (strncmp("http://",(const char *) psz_url,7)==0) )
454 MediaURLOpenChanged(GTK_WIDGET(editable), psz_url);
457 if (stat((char*)psz_url, &st)==0)
459 if (S_ISDIR(st.st_mode))
461 if (!p_intf->p_sys->p_clist)
462 msg_Err(p_intf, "p_clist pointer invalid!!" );
463 ReadDirectory(p_intf->p_sys->p_clist, psz_url);
465 else if( (S_ISLNK(st.st_mode)) || (S_ISCHR(st.st_mode)) ||
466 (S_ISBLK(st.st_mode)) || (S_ISFIFO(st.st_mode))||
467 (S_ISSOCK(st.st_mode))|| (S_ISREG(st.st_mode)) )
469 MediaURLOpenChanged(GTK_WIDGET(editable), psz_url);
476 on_clistmedia_click_column (GtkCList *clist,
480 static GtkSortType sort_type = GTK_SORT_ASCENDING;
482 // Should sort on column
485 case GTK_SORT_ASCENDING:
486 sort_type = GTK_SORT_DESCENDING;
488 case GTK_SORT_DESCENDING:
489 sort_type = GTK_SORT_ASCENDING;
492 gtk_clist_freeze( clist );
493 gtk_clist_set_sort_type( clist, sort_type );
494 gtk_clist_sort( clist );
495 gtk_clist_thaw( clist );
500 on_clistmedia_select_row (GtkCList *clist,
506 intf_thread_t * p_intf = GtkGetIntf( GTK_WIDGET(clist) );
511 if (!p_intf->p_sys->p_clist)
512 msg_Err(p_intf, "p_clist pointer is invalid.");
513 ret = gtk_clist_get_text (p_intf->p_sys->p_clist, row, 0, text);
516 if (stat((char*)text[0], &st)==0)
518 if (S_ISDIR(st.st_mode))
519 ReadDirectory(p_intf->p_sys->p_clist, text[0]);
520 else if( (S_ISLNK(st.st_mode)) || (S_ISCHR(st.st_mode)) ||
521 (S_ISBLK(st.st_mode)) || (S_ISFIFO(st.st_mode))||
522 (S_ISSOCK(st.st_mode))|| (S_ISREG(st.st_mode)) )
524 MediaURLOpenChanged(GTK_WIDGET(p_intf->p_sys->p_clist), text[0]);
532 on_cbautoplay_toggled (GtkToggleButton *togglebutton,
539 on_familiar_delete_event (GtkWidget *widget,
543 FamiliarExit( GTK_WIDGET( widget ), user_data );
547 /* Slider Management */
550 FamiliarSliderRelease (GtkWidget *widget,
551 GdkEventButton *event,
554 intf_thread_t *p_intf = GtkGetIntf( widget );
556 vlc_mutex_lock( &p_intf->change_lock );
557 p_intf->p_sys->b_slider_free = 1;
558 vlc_mutex_unlock( &p_intf->change_lock );
565 FamiliarSliderPress (GtkWidget *widget,
566 GdkEventButton *event,
569 intf_thread_t *p_intf = GtkGetIntf( widget );
571 vlc_mutex_lock( &p_intf->change_lock );
572 p_intf->p_sys->b_slider_free = 0;
573 vlc_mutex_unlock( &p_intf->change_lock );
582 FamiliarMrlGo (GtkButton *button,
585 intf_thread_t * p_intf = GtkGetIntf( button );
587 MediaURLOpenChanged( GTK_WIDGET( button ),
588 gtk_entry_get_text(p_intf->p_sys->p_mrlentry ) );
594 FamiliarPreferencesApply (GtkButton *button,
597 intf_thread_t * p_intf = GtkGetIntf( GTK_WIDGET(button) );
599 GtkToggleButton * p_autopl_button = GTK_GET( TOGGLE_BUTTON, "cbautoplay" );
600 if (gtk_toggle_button_get_active(p_autopl_button))
602 p_intf->p_sys->b_autoplayfile = 1;
606 p_intf->p_sys->b_autoplayfile = 0;