1 /*****************************************************************************
2 * callbacks.c : Callbacks for the pda Linux Gtk+ plugin.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: callbacks.c,v 1.2 2003/11/07 13:01:51 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 */
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 PDARebuildCList( 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
261 gboolean PDAExit( GtkWidget *widget,
264 intf_thread_t *p_intf = GtkGetIntf( widget );
266 vlc_mutex_lock( &p_intf->change_lock );
267 p_intf->p_vlc->b_die = VLC_TRUE;
268 vlc_mutex_unlock( &p_intf->change_lock );
274 on_toolbar_open_clicked (GtkButton *button,
277 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) );
279 if (p_intf->p_sys->p_notebook)
281 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
282 gtk_notebook_set_page(p_intf->p_sys->p_notebook,0);
284 if (p_intf->p_sys->p_mediabook)
286 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_mediabook) );
287 gtk_notebook_set_page(p_intf->p_sys->p_mediabook,0);
289 gdk_window_raise( p_intf->p_sys->p_window->window );
290 if (p_intf->p_sys->p_clist)
292 ReadDirectory(p_intf->p_sys->p_clist, ".");
297 on_toolbar_preferences_clicked (GtkButton *button,
300 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) );
302 if (p_intf->p_sys->p_notebook)
304 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
305 gtk_notebook_set_page(p_intf->p_sys->p_notebook,2);
307 gdk_window_raise( p_intf->p_sys->p_window->window );
311 on_toolbar_rewind_clicked (GtkButton *button,
314 intf_thread_t * p_intf = GtkGetIntf( button );
316 if( p_intf->p_sys->p_input != NULL )
318 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_SLOWER );
323 on_toolbar_pause_clicked (GtkButton *button,
326 intf_thread_t * p_intf = GtkGetIntf( button );
328 if( p_intf->p_sys->p_input != NULL )
330 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
335 on_toolbar_play_clicked (GtkButton *button,
338 intf_thread_t * p_intf = GtkGetIntf( GTK_WIDGET( button ) );
339 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
341 if( p_playlist == NULL )
343 /* Display open page */
344 on_toolbar_open_clicked(button,user_data);
347 /* If the playlist is empty, open a file requester instead */
348 vlc_mutex_lock( &p_playlist->object_lock );
349 if( p_playlist->i_size )
351 vlc_mutex_unlock( &p_playlist->object_lock );
352 playlist_Play( p_playlist );
353 vlc_object_release( p_playlist );
354 gdk_window_lower( p_intf->p_sys->p_window->window );
358 vlc_mutex_unlock( &p_playlist->object_lock );
359 vlc_object_release( p_playlist );
360 /* Display open page */
361 on_toolbar_open_clicked(button,user_data);
366 on_toolbar_stop_clicked (GtkButton *button,
369 intf_thread_t * p_intf = GtkGetIntf( GTK_WIDGET( button ) );
370 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
374 playlist_Stop( p_playlist );
375 vlc_object_release( p_playlist );
376 gdk_window_raise( p_intf->p_sys->p_window->window );
381 on_toolbar_forward_clicked (GtkButton *button,
384 intf_thread_t * p_intf = GtkGetIntf( button );
386 if( p_intf->p_sys->p_input != NULL )
388 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_FASTER );
393 on_toolbar_playlist_clicked (GtkButton *button,
396 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(button) );
399 if (p_intf->p_sys->p_notebook)
401 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
402 gtk_notebook_set_page(p_intf->p_sys->p_notebook,1);
404 gdk_window_raise( p_intf->p_sys->p_window->window );
408 on_toolbar_about_clicked (GtkButton *button,
411 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(button) );
414 if (p_intf->p_sys->p_notebook)
416 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
417 gtk_notebook_set_page(p_intf->p_sys->p_notebook,3);
419 gdk_window_raise( p_intf->p_sys->p_window->window );
423 on_comboURL_entry_changed (GtkEditable *editable,
426 intf_thread_t * p_intf = GtkGetIntf( GTK_WIDGET(editable) );
430 psz_url = gtk_entry_get_text(GTK_ENTRY(editable));
431 /* if( (strncmp("file://",(const char *) psz_url,7)==0) ||
432 (strncmp("udp://",(const char *) psz_url,6)==0) ||
433 (strncmp("udp4://",(const char *) psz_url,7)==0) ||
434 (strncmp("udp6://",(const char *) psz_url,7)==0) ||
435 (strncmp("udpstream://",(const char *) psz_url,12)==0) ||
436 (strncmp("rtp://",(const char *) psz_url,6)==0) ||
437 (strncmp("rtp4://",(const char *) psz_url,7)==0) ||
438 (strncmp("rtp6://",(const char *) psz_url,7)==0) ||
439 (strncmp("rtpstream://",(const char *) psz_url,12)==0) ||
440 (strncmp("ftp://",(const char *) psz_url,6)==0) ||
441 (strncmp("mms://",(const char *) psz_url,6)==0) ||
442 (strncmp("http://",(const char *) psz_url,7)==0) )
444 MediaURLOpenChanged(GTK_WIDGET(editable), psz_url);
447 if (stat((char*)psz_url, &st)==0)
449 if (S_ISDIR(st.st_mode))
451 if (!p_intf->p_sys->p_clist)
452 msg_Err(p_intf, "p_clist pointer invalid!!" );
453 ReadDirectory(p_intf->p_sys->p_clist, psz_url);
455 else if( (S_ISLNK(st.st_mode)) || (S_ISCHR(st.st_mode)) ||
456 (S_ISBLK(st.st_mode)) || (S_ISFIFO(st.st_mode))||
457 (S_ISSOCK(st.st_mode))|| (S_ISREG(st.st_mode)) )
459 MediaURLOpenChanged(GTK_WIDGET(editable), psz_url);
465 on_clistmedia_click_column (GtkCList *clist,
469 static GtkSortType sort_type = GTK_SORT_ASCENDING;
471 // Should sort on column
474 case GTK_SORT_ASCENDING:
475 sort_type = GTK_SORT_DESCENDING;
477 case GTK_SORT_DESCENDING:
478 sort_type = GTK_SORT_ASCENDING;
481 gtk_clist_freeze( clist );
482 gtk_clist_set_sort_type( clist, sort_type );
483 gtk_clist_sort( clist );
484 gtk_clist_thaw( clist );
488 on_clistmedia_select_row (GtkCList *clist,
494 intf_thread_t * p_intf = GtkGetIntf( GTK_WIDGET(clist) );
499 if (!p_intf->p_sys->p_clist)
500 msg_Err(p_intf, "p_clist pointer is invalid.");
501 ret = gtk_clist_get_text (p_intf->p_sys->p_clist, row, 0, text);
504 if (stat((char*)text[0], &st)==0)
506 if (S_ISDIR(st.st_mode))
507 ReadDirectory(p_intf->p_sys->p_clist, text[0]);
508 else if( (S_ISLNK(st.st_mode)) || (S_ISCHR(st.st_mode)) ||
509 (S_ISBLK(st.st_mode)) || (S_ISFIFO(st.st_mode))||
510 (S_ISSOCK(st.st_mode))|| (S_ISREG(st.st_mode)) )
512 MediaURLOpenChanged(GTK_WIDGET(p_intf->p_sys->p_clist), text[0]);
519 on_cbautoplay_toggled (GtkToggleButton *togglebutton,
525 on_pda_delete_event (GtkWidget *widget,
529 PDAExit( GTK_WIDGET( widget ), user_data );
533 /* Slider Management */
535 PDASliderRelease (GtkWidget *widget,
536 GdkEventButton *event,
539 intf_thread_t *p_intf = GtkGetIntf( widget );
541 vlc_mutex_lock( &p_intf->change_lock );
542 p_intf->p_sys->b_slider_free = 1;
543 vlc_mutex_unlock( &p_intf->change_lock );
549 PDASliderPress (GtkWidget *widget,
550 GdkEventButton *event,
553 intf_thread_t *p_intf = GtkGetIntf( widget );
555 vlc_mutex_lock( &p_intf->change_lock );
556 p_intf->p_sys->b_slider_free = 0;
557 vlc_mutex_unlock( &p_intf->change_lock );
563 PDAMrlGo (GtkButton *button,
566 intf_thread_t * p_intf = GtkGetIntf( button );
568 MediaURLOpenChanged( GTK_WIDGET( button ),
569 gtk_entry_get_text(p_intf->p_sys->p_mrlentry ) );
573 PDAPreferencesApply (GtkButton *button,
576 intf_thread_t * p_intf = GtkGetIntf( GTK_WIDGET(button) );
578 GtkToggleButton * p_autopl_button = GTK_GET( TOGGLE_BUTTON, "cbautoplay" );
579 if (gtk_toggle_button_get_active(p_autopl_button))
581 p_intf->p_sys->b_autoplayfile = 1;
585 p_intf->p_sys->b_autoplayfile = 0;