1 /*****************************************************************************
2 * familiar_callbacks.c : Callbacks for the Familiar Linux Gtk+ plugin.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: familiar_callbacks.c,v 1.6.2.9 2002/10/10 20:33:12 jpsaman 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 */
36 #include <videolan/vlc.h>
38 #include "stream_control.h"
39 #include "input_ext-intf.h"
41 #include "interface.h"
42 #include "intf_playlist.h"
45 #include "video_output.h"
53 #include "familiar_callbacks.h"
54 #include "familiar_interface.h"
55 #include "familiar_support.h"
60 static void MediaURLOpenChanged( GtkWidget *widget, gchar *psz_url );
61 static char* get_file_perm(const char *path);
63 /*****************************************************************************
64 * Useful function to retrieve p_intf
65 ****************************************************************************/
66 void * __GtkGetIntf( GtkWidget * widget )
70 if( GTK_IS_MENU_ITEM( widget ) )
72 /* Look for a GTK_MENU */
73 while( widget->parent && !GTK_IS_MENU( widget ) )
75 widget = widget->parent;
78 /* Maybe this one has the data */
79 p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" );
85 /* Otherwise, the parent widget has it */
86 widget = gtk_menu_get_attach_widget( GTK_MENU( widget ) );
89 /* We look for the top widget */
90 widget = gtk_widget_get_toplevel( GTK_WIDGET( widget ) );
92 p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" );
97 /*****************************************************************************
98 * Helper functions for URL changes in Media and Preferences notebook pages.
99 ****************************************************************************/
100 static void MediaURLOpenChanged( GtkWidget *widget, gchar *psz_url )
102 intf_thread_t *p_intf = GtkGetIntf( widget );
103 int i_end = p_main->p_playlist->i_size;
105 // Add p_url to playlist .... but how ?
106 if( p_main->p_playlist )
108 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END, (char*)psz_url );
111 if (p_intf->p_sys->b_autoplayfile)
113 /* end current item, select added item */
114 if( p_input_bank->pp_input[0] != NULL )
116 p_input_bank->pp_input[0]->b_eof = 1;
118 intf_PlaylistJumpto( p_main->p_playlist, i_end - 1 );
120 if( p_input_bank->pp_input[0] != NULL )
122 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
123 p_main->p_playlist->b_stopped = 0;
128 /*****************************************************************
129 * Read directory helper function.
130 ****************************************************************/
131 void ReadDirectory( GtkCList *clist, char *psz_dir )
133 intf_thread_t *p_intf = GtkGetIntf( clist );
134 struct dirent **namelist;
140 status = chdir(psz_dir);
143 intf_ErrMsg("File is not a directory.");
145 n = scandir(".", &namelist, 0, NULL);
154 if( p_intf->p_sys->p_clist == NULL )
155 intf_ErrMsg("ReadDirectory - ERROR p_intf->p_sys->p_clist == NULL");
156 gtk_clist_freeze( p_intf->p_sys->p_clist );
157 gtk_clist_clear( p_intf->p_sys->p_clist );
160 /* This is a list of strings. */
161 ppsz_text[0] = namelist[i]->d_name;
162 ppsz_text[1] = get_file_perm(namelist[i]->d_name);
163 if (strcmp(ppsz_text[1],"") == 0)
164 intf_ErrMsg("File system error unknown filetype encountered.");
165 gtk_clist_insert( p_intf->p_sys->p_clist, i, ppsz_text );
168 gtk_clist_thaw( p_intf->p_sys->p_clist );
173 static char* get_file_perm(const char *path)
178 perm = (char *) malloc(sizeof(char)*10);
179 strncpy( perm, "----------", sizeof("----------"));
180 if (lstat(path, &st)==0)
182 if (S_ISLNK(st.st_mode))
184 else if (S_ISDIR(st.st_mode))
186 else if (S_ISCHR(st.st_mode))
188 else if (S_ISBLK(st.st_mode))
190 else if (S_ISFIFO(st.st_mode))
192 else if (S_ISSOCK(st.st_mode))
194 else if (S_ISREG(st.st_mode))
196 else /* Unknown type is an error */
198 /* Get file permissions */
200 if (st.st_mode & S_IRUSR)
202 if (st.st_mode & S_IWUSR)
204 if (st.st_mode & S_IXUSR)
206 if (st.st_mode & S_ISUID)
211 else if (st.st_mode & S_ISUID)
214 if (st.st_mode & S_IRGRP)
216 if (st.st_mode & S_IWGRP)
218 if (st.st_mode & S_IXGRP)
220 if (st.st_mode & S_ISGID)
225 else if (st.st_mode & S_ISGID)
228 if (st.st_mode & S_IROTH)
230 if (st.st_mode & S_IWOTH)
232 if (st.st_mode & S_IXOTH)
235 if (st.st_mode &S_ISVTX)
240 else if (st.st_mode &S_ISVTX)
247 * Main interface callbacks
250 gboolean GtkExit( GtkWidget *widget,
253 intf_thread_t *p_intf = GtkGetIntf( widget );
255 vlc_mutex_lock( &p_intf->change_lock );
257 vlc_mutex_unlock( &p_intf->change_lock );
263 on_toolbar_open_clicked (GtkButton *button,
266 intf_thread_t *p_intf = GtkGetIntf( button );
268 if (p_intf->p_sys->p_notebook)
270 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
271 gtk_notebook_set_page(p_intf->p_sys->p_notebook,0);
273 gdk_window_raise( p_intf->p_sys->p_window->window );
274 if (p_intf->p_sys->p_clist)
276 ReadDirectory(p_intf->p_sys->p_clist, ".");
282 on_toolbar_preferences_clicked (GtkButton *button,
285 intf_thread_t *p_intf = GtkGetIntf( button );
287 if (p_intf->p_sys->p_notebook)
289 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
290 gtk_notebook_set_page(p_intf->p_sys->p_notebook,1);
292 gdk_window_raise( p_intf->p_sys->p_window->window );
297 on_toolbar_rewind_clicked (GtkButton *button,
300 // intf_thread_t * p_intf = GtkGetIntf( button );
302 if( p_input_bank->pp_input[0] != NULL )
304 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_SLOWER );
310 on_toolbar_pause_clicked (GtkButton *button,
313 // intf_thread_t * p_intf = GtkGetIntf( button );
315 if( p_input_bank->pp_input[0] != NULL )
317 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PAUSE );
323 on_toolbar_play_clicked (GtkButton *button,
326 intf_thread_t * p_intf = GtkGetIntf( button );
328 if( p_input_bank->pp_input[0] != NULL )
330 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_PLAY );
331 p_main->p_playlist->b_stopped = 0;
332 gdk_window_lower( p_intf->p_sys->p_window->window );
336 vlc_mutex_lock( &p_main->p_playlist->change_lock );
338 if( p_main->p_playlist->b_stopped )
340 if( p_main->p_playlist->i_size )
342 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
343 intf_PlaylistJumpto( p_main->p_playlist,
344 p_main->p_playlist->i_index );
348 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
349 /* simulate on open button click */
350 on_toolbar_open_clicked(button,user_data);
355 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
362 on_toolbar_stop_clicked (GtkButton *button,
365 intf_thread_t * p_intf = GtkGetIntf( button );
367 if( p_input_bank->pp_input[0] != NULL )
369 /* end playing item */
370 p_input_bank->pp_input[0]->b_eof = 1;
372 /* update playlist */
373 vlc_mutex_lock( &p_main->p_playlist->change_lock );
375 p_main->p_playlist->i_index--;
376 p_main->p_playlist->b_stopped = 1;
378 vlc_mutex_unlock( &p_main->p_playlist->change_lock );
379 gdk_window_raise( p_intf->p_sys->p_window->window );
385 on_toolbar_forward_clicked (GtkButton *button,
388 // intf_thread_t * p_intf = GtkGetIntf( button );
390 if( p_input_bank->pp_input[0] != NULL )
392 input_SetStatus( p_input_bank->pp_input[0], INPUT_STATUS_FASTER );
398 on_toolbar_about_clicked (GtkButton *button,
401 intf_thread_t *p_intf = GtkGetIntf( button );
404 if (p_intf->p_sys->p_notebook)
406 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
407 gtk_notebook_set_page(p_intf->p_sys->p_notebook,2);
409 gdk_window_raise( p_intf->p_sys->p_window->window );
414 on_comboURL_entry_changed (GtkEditable *editable,
417 intf_thread_t * p_intf = GtkGetIntf( editable );
421 psz_url = gtk_entry_get_text(GTK_ENTRY(editable));
422 if( (strncmp("file://",(const char *) psz_url,7)==0) ||
423 (strncmp("udp://",(const char *) psz_url,6)==0) ||
424 (strncmp("udp4://",(const char *) psz_url,7)==0) ||
425 (strncmp("udp6://",(const char *) psz_url,7)==0) ||
426 (strncmp("udpstream://",(const char *) psz_url,12)==0) ||
427 (strncmp("rtp://",(const char *) psz_url,6)==0) ||
428 (strncmp("rtp4://",(const char *) psz_url,7)==0) ||
429 (strncmp("rtp6://",(const char *) psz_url,7)==0) ||
430 (strncmp("rtpstream://",(const char *) psz_url,12)==0) ||
431 (strncmp("http://",(const char *) psz_url,7)==0) )
433 intf_ErrMsg( "comboURL change event - open URL" );
434 MediaURLOpenChanged(GTK_WIDGET(editable), psz_url);
436 else if (lstat((char*)psz_url, &st)==0)
438 if (S_ISDIR(st.st_mode))
439 ReadDirectory(p_intf->p_sys->p_clist, psz_url);
440 else if( (S_ISLNK(st.st_mode)) || (S_ISCHR(st.st_mode)) ||
441 (S_ISBLK(st.st_mode)) || (S_ISFIFO(st.st_mode))||
442 (S_ISSOCK(st.st_mode))|| (S_ISREG(st.st_mode)) )
444 MediaURLOpenChanged(GTK_WIDGET(editable), psz_url);
450 on_clistmedia_click_column (GtkCList *clist,
454 static GtkSortType sort_type = GTK_SORT_ASCENDING;
456 // Should sort on column
459 case GTK_SORT_ASCENDING:
460 sort_type = GTK_SORT_DESCENDING;
462 case GTK_SORT_DESCENDING:
463 sort_type = GTK_SORT_ASCENDING;
466 gtk_clist_freeze( clist );
467 gtk_clist_set_sort_type( clist, sort_type );
468 gtk_clist_sort( clist );
469 gtk_clist_thaw( clist );
474 on_clistmedia_select_row (GtkCList *clist,
480 // intf_thread_t *p_intf = GtkGetIntf( clist );
481 intf_thread_t *p_intf = p_main->p_intf;
486 ret = gtk_clist_get_text (p_intf->p_sys->p_clist, row, 0, text);
489 if (lstat((char*)text[0], &st)==0)
491 if (S_ISDIR(st.st_mode))
492 ReadDirectory(p_intf->p_sys->p_clist, text[0]);
493 else if( (S_ISLNK(st.st_mode)) || (S_ISCHR(st.st_mode)) ||
494 (S_ISBLK(st.st_mode)) || (S_ISFIFO(st.st_mode))||
495 (S_ISSOCK(st.st_mode))|| (S_ISREG(st.st_mode)) )
497 MediaURLOpenChanged(GTK_WIDGET(p_intf->p_sys->p_clist), text[0]);
504 on_cbautoplay_toggled (GtkToggleButton *togglebutton,
511 on_familiar_delete_event (GtkWidget *widget,
515 GtkExit( GTK_WIDGET( widget ), user_data );
521 on_buttonSave_clicked (GtkButton *button,
524 intf_thread_t * p_intf = GtkGetIntf( button );
525 on_buttonApply_clicked( button, user_data );
526 config_PutIntVariable( "familiar-autoplayfile", p_intf->p_sys->b_autoplayfile );
527 // config_SaveConfigFile( NULL );
532 on_buttonApply_clicked (GtkButton *button,
535 intf_thread_t * p_intf = GtkGetIntf( button );
536 GtkWidget *cbautoplay;
538 cbautoplay = GTK_WIDGET( gtk_object_get_data(
539 GTK_OBJECT( p_intf->p_sys->p_window ), "cbautoplay" ) );
540 p_intf->p_sys->b_autoplayfile = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(cbautoplay));
545 on_buttonCancel_clicked (GtkButton *button,
548 intf_thread_t * p_intf = GtkGetIntf( button );
549 GtkWidget *cbautoplay;
551 cbautoplay = GTK_WIDGET( gtk_object_get_data(
552 GTK_OBJECT( p_intf->p_sys->p_window ), "cbautoplay" ) );
553 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(cbautoplay),p_intf->p_sys->b_autoplayfile);