1 /*****************************************************************************
2 * pda_callbacks.c : Callbacks for the pda Linux Gtk+ plugin.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: pda_callbacks.c,v 1.6 2003/11/07 14:15:23 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 */
45 #include "pda_callbacks.h"
46 #include "pda_interface.h"
47 #include "pda_support.h"
50 static char* get_file_stat(const char *path, uid_t *uid, gid_t *gid, off_t *size);
52 /*****************************************************************************
53 * Useful function to retrieve p_intf
54 ****************************************************************************/
55 void * E_(__GtkGetIntf)( GtkWidget * widget )
59 if( GTK_IS_MENU_ITEM( widget ) )
61 /* Look for a GTK_MENU */
62 while( widget->parent && !GTK_IS_MENU( widget ) )
64 widget = widget->parent;
67 /* Maybe this one has the data */
68 p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" );
74 /* Otherwise, the parent widget has it */
75 widget = gtk_menu_get_attach_widget( GTK_MENU( widget ) );
78 /* We look for the top widget */
79 widget = gtk_widget_get_toplevel( GTK_WIDGET( widget ) );
81 p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" );
86 void PlaylistRebuildListStore( GtkListStore * p_list, playlist_t * p_playlist )
96 vlc_mutex_lock( &p_playlist->object_lock );
97 for( i_dummy = p_playlist->i_size ; i_dummy-- ; )
99 ppsz_text[0] = p_playlist->pp_items[i_dummy]->psz_name;
100 ppsz_text[1] = "no info";
101 gtk_list_store_append (p_list, &iter);
102 gtk_list_store_set (p_list, &iter,
107 vlc_mutex_unlock( &p_playlist->object_lock );
110 /*****************************************************************************
111 * Helper functions for URL changes in Media and Preferences notebook pages.
112 ****************************************************************************/
113 void MediaURLOpenChanged( GtkWidget *widget, gchar *psz_url )
115 intf_thread_t *p_intf = GtkGetIntf( widget );
116 playlist_t *p_playlist;
117 GtkTreeView *p_tvplaylist;
119 p_playlist = (playlist_t *)
120 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
122 if( p_playlist == NULL)
129 if (p_intf->p_sys->b_autoplayfile)
131 playlist_Add( p_playlist, (char*)psz_url, 0, 0,
132 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END);
136 playlist_Add( p_playlist, (char*)psz_url, 0, 0,
137 PLAYLIST_APPEND, PLAYLIST_END );
139 vlc_object_release( p_playlist );
141 p_tvplaylist = (GtkTreeView*) lookup_widget( GTK_WIDGET(widget), "tvPlaylist" );
144 GtkListStore *p_liststore;
145 p_liststore = (GtkListStore *) gtk_tree_view_get_model(p_tvplaylist);
146 PlaylistRebuildListStore(p_liststore, p_playlist);
151 /*****************************************************************
152 * Read directory helper function.
153 ****************************************************************/
154 void ReadDirectory(GtkListStore *p_list, char *psz_dir )
157 struct dirent **namelist;
160 g_print("changing to dir %s\n", psz_dir);
163 status = chdir(psz_dir);
165 g_print( "permision denied\n" );
167 n = scandir(".", &namelist, 0, alphasort);
179 /* XXX : kludge temporaire pour yopy */
181 ppsz_text[1] = get_file_stat("..", &uid, &gid, &size);
186 /* Add a new row to the model */
187 gtk_list_store_append (p_list, &iter);
188 gtk_list_store_set (p_list, &iter,
196 if (ppsz_text[1]) free(ppsz_text[1]);
201 if (namelist[i]->d_name[0] != '.')
203 /* This is a list of strings. */
204 ppsz_text[0] = namelist[i]->d_name;
205 ppsz_text[1] = get_file_stat(namelist[i]->d_name, &uid, &gid, &size);
210 g_print( "(%d) file: %s permission: %s user: %ull group: %ull size: %ull\n", i, ppsz_text[0], ppsz_text[1], uid, gid, size );
212 gtk_list_store_append (p_list, &iter);
213 gtk_list_store_set (p_list, &iter,
221 if (ppsz_text[1]) free(ppsz_text[1]);
228 static char* get_file_stat(const char *path, uid_t *uid, gid_t *gid, off_t *size)
233 perm = (char *) malloc(sizeof(char)*10);
234 strncpy( perm, "----------", sizeof("----------"));
235 if (lstat(path, &st)==0)
237 /* user, group, filesize */
241 /* determine permission modes */
242 if (S_ISLNK(st.st_mode))
244 else if (S_ISDIR(st.st_mode))
246 else if (S_ISCHR(st.st_mode))
248 else if (S_ISBLK(st.st_mode))
250 else if (S_ISFIFO(st.st_mode))
252 else if (S_ISSOCK(st.st_mode))
254 else if (S_ISREG(st.st_mode))
256 else /* Unknown type is an error */
258 /* Get file permissions */
260 if (st.st_mode & S_IRUSR)
262 if (st.st_mode & S_IWUSR)
264 if (st.st_mode & S_IXUSR)
266 if (st.st_mode & S_ISUID)
271 else if (st.st_mode & S_ISUID)
274 if (st.st_mode & S_IRGRP)
276 if (st.st_mode & S_IWGRP)
278 if (st.st_mode & S_IXGRP)
280 if (st.st_mode & S_ISGID)
285 else if (st.st_mode & S_ISGID)
288 if (st.st_mode & S_IROTH)
290 if (st.st_mode & S_IWOTH)
292 if (st.st_mode & S_IXOTH)
295 if (st.st_mode &S_ISVTX)
300 else if (st.st_mode &S_ISVTX)
307 * Main interface callbacks
311 onPDADeleteEvent (GtkWidget *widget,
315 intf_thread_t *p_intf = GtkGetIntf( widget );
317 msg_Dbg( p_intf, "about to exit vlc ... " );
318 vlc_mutex_lock( &p_intf->change_lock );
319 p_intf->p_vlc->b_die = VLC_TRUE;
320 vlc_mutex_unlock( &p_intf->change_lock );
321 msg_Dbg( p_intf, "about to exit vlc ... signalled" );
328 onRewind (GtkButton *button,
331 intf_thread_t * p_intf = GtkGetIntf( button );
333 if( p_intf->p_sys->p_input != NULL )
335 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_SLOWER );
341 onPause (GtkButton *button,
344 intf_thread_t * p_intf = GtkGetIntf( button );
346 if( p_intf->p_sys->p_input != NULL )
348 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
354 onPlay (GtkButton *button,
357 intf_thread_t * p_intf = GtkGetIntf( GTK_WIDGET( button ) );
358 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
362 vlc_mutex_lock( &p_playlist->object_lock );
363 if( p_playlist->i_size )
365 vlc_mutex_unlock( &p_playlist->object_lock );
366 playlist_Play( p_playlist );
370 vlc_mutex_unlock( &p_playlist->object_lock );
372 vlc_object_release( p_playlist );
378 onStop (GtkButton *button,
381 intf_thread_t * p_intf = GtkGetIntf( GTK_WIDGET( button ) );
382 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
386 playlist_Stop( p_playlist );
387 vlc_object_release( p_playlist );
393 onForward (GtkButton *button,
396 intf_thread_t * p_intf = GtkGetIntf( button );
398 if( p_intf->p_sys->p_input != NULL )
400 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_FASTER );
406 onAbout (GtkButton *button,
409 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(button) );
412 if (p_intf->p_sys->p_notebook)
414 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
415 gtk_notebook_set_page(p_intf->p_sys->p_notebook,6);
421 SliderRelease (GtkWidget *widget,
422 GdkEventButton *event,
425 intf_thread_t *p_intf = GtkGetIntf( widget );
427 vlc_mutex_lock( &p_intf->change_lock );
428 p_intf->p_sys->b_slider_free = 1;
429 vlc_mutex_unlock( &p_intf->change_lock );
436 SliderPress (GtkWidget *widget,
437 GdkEventButton *event,
440 intf_thread_t *p_intf = GtkGetIntf( widget );
442 vlc_mutex_lock( &p_intf->change_lock );
443 p_intf->p_sys->b_slider_free = 0;
444 vlc_mutex_unlock( &p_intf->change_lock );
449 void addSelectedToPlaylist(GtkTreeModel *model,
454 GtkTreeView *p_tvplaylist = NULL;
457 gtk_tree_model_get(model, iter, 0, &filename, -1);
459 /* Add to playlist object. */
460 p_tvplaylist = (GtkTreeView *) lookup_widget( GTK_WIDGET(userdata), "tvPlaylist");
463 GtkTreeModel *p_play_model;
464 GtkTreeIter p_play_iter;
466 p_play_model = gtk_tree_view_get_model(p_tvplaylist);
468 /* Add a new row to the playlist treeview model */
469 gtk_list_store_append (GTK_LIST_STORE(p_play_model), &p_play_iter);
470 gtk_list_store_set (GTK_LIST_STORE(p_play_model), &p_play_iter,
471 0, filename, /* Add path to it !!! */
476 g_print("Error obtaining pointer to Play List");
480 onFileListRow (GtkTreeView *treeview,
482 GtkTreeViewColumn *column,
485 GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
487 if (gtk_tree_selection_count_selected_rows(selection) == 1)
494 /* This might be a directory selection */
495 model = gtk_tree_view_get_model(treeview);
497 g_print( "Error: model is a null pointer\n" );
498 if (!gtk_tree_model_get_iter(model, &iter, path))
499 g_print( "Error: could not get iter from model\n" );
501 gtk_tree_model_get(model, &iter, 0, &filename, -1);
503 if (stat((char*)filename, &st)==0)
505 if (S_ISDIR(st.st_mode))
507 GtkListStore *p_model = NULL;
509 /* Get new directory listing */
510 p_model = gtk_list_store_new (5,
517 g_print( "ERROR: model has a NULL pointer\n" );
518 ReadDirectory(p_model, filename);
520 /* Update TreeView with new model */
521 gtk_tree_view_set_model(treeview, (GtkTreeModel*) p_model);
522 g_object_unref(p_model);
526 gtk_tree_selection_selected_foreach(selection, (GtkTreeSelectionForeachFunc) &addSelectedToPlaylist, (gpointer) treeview);
532 gtk_tree_selection_selected_foreach(selection, (GtkTreeSelectionForeachFunc) &addSelectedToPlaylist, (gpointer) treeview);
538 onFileListColumns (GtkTreeView *treeview,
541 g_print("onFileListColumn\n");
546 onFileListRowSelected (GtkTreeView *treeview,
547 gboolean start_editing,
550 g_print("onFileListRowSelected\n");
556 onAddFileToPlaylist (GtkButton *button,
559 GtkTreeView *treeview = NULL;
561 treeview = (GtkTreeView *) lookup_widget( GTK_WIDGET(button), "tvFileList");
564 onFileListRow(treeview, NULL, NULL, NULL );
570 onEntryMRLChanged (GtkEditable *editable,
573 g_print("onMRLChanged\n");
578 onEntryMRLEditingDone (GtkCellEditable *celleditable,
581 g_print("onMRLEditingDone\n");
586 onNetworkPortChanged (GtkEditable *editable,
594 onEntryNetworkPortEditingDone (GtkCellEditable *celleditable,
602 onNetworkAddressChanged (GtkEditable *editable,
610 onEntryNetworkAddressEditingDone (GtkCellEditable *celleditable,
618 onNetworkTypeChanged (GtkEditable *editable,
626 onEntryNetworkTypeEditingDone (GtkCellEditable *celleditable,
634 onProtocolTypeChanged (GtkEditable *editable,
642 onEntryProtocolTypeEditingDone (GtkCellEditable *celleditable,
650 onMRLTypeChanged (GtkEditable *editable,
658 onEntryMRLTypeEditingDone (GtkCellEditable *celleditable,
666 onStreamTypeChanged (GtkEditable *editable,
674 onEntryStreamTypeEditingDone (GtkCellEditable *celleditable,
682 onAddNetworkPlaylist (GtkButton *button,
688 p_mrl = (GtkEntry*) lookup_widget(GTK_WIDGET(button),"" );
691 GtkTreeView *p_tvplaylist = NULL;
692 GtkTreeModel *p_play_model;
693 GtkTreeIter p_play_iter;
696 p_tvplaylist = (GtkTreeView *) lookup_widget( GTK_WIDGET(button), "tvPlaylist");
699 p_play_model = gtk_tree_view_get_model(p_tvplaylist);
700 /* Add a new row to the playlist treeview model */
701 gtk_list_store_append (p_play_model, &p_play_iter);
702 gtk_list_store_set (p_play_model, &p_play_iter,
703 0, name, /* Add path to it !!! */
706 /* do we need to unref ?? */
709 // msg_Err(p_intf, "Error obtaining pointer to Play List");
710 g_print("Error obtaining pointer to Play List");
717 onV4LAudioChanged (GtkEditable *editable,
725 onEntryV4LAudioEditingDone (GtkCellEditable *celleditable,
733 onV4LVideoChanged (GtkEditable *editable,
741 onEntryV4LVideoEditingDone (GtkCellEditable *celleditable,
749 onAddCameraToPlaylist (GtkButton *button,
757 onVideoDeviceChanged (GtkEditable *editable,
765 onEntryVideoDeviceEditingDone (GtkCellEditable *celleditable,
773 onVideoCodecChanged (GtkEditable *editable,
781 onEntryVideoCodecEditingDone (GtkCellEditable *celleditable,
789 onVideoBitrateChanged (GtkEditable *editable,
797 onVideoBitrateEditingDone (GtkCellEditable *celleditable,
805 onAudioDeviceChanged (GtkEditable *editable,
813 onEntryAudioDeviceEditingDone (GtkCellEditable *celleditable,
821 onAudioCodecChanged (GtkEditable *editable,
829 onEntryAudioCodecEditingDone (GtkCellEditable *celleditable,
837 onAudioBitrateChanged (GtkEditable *editable,
845 onAudioBitrateEditingDone (GtkCellEditable *celleditable,
853 onAddServerToPlaylist (GtkButton *button,
861 PlaylistEvent (GtkWidget *widget,
865 g_print("onPlaylistEvent\n");
871 onPlaylistColumnsChanged (GtkTreeView *treeview,
874 g_print("onPlaylistColumnsChanged\n");
879 onPlaylistRowSelected (GtkTreeView *treeview,
880 gboolean start_editing,
883 g_print("onPlaylistRowSelected\n");
889 onPlaylistRow (GtkTreeView *treeview,
891 GtkTreeViewColumn *column,
894 g_print("onPlaylistRow\n");
899 onUpdatePlaylist (GtkButton *button,
907 onDeletePlaylist (GtkButton *button,
915 onClearPlaylist (GtkButton *button,
923 onPreferenceSave (GtkButton *button,
931 onPreferenceApply (GtkButton *button,
939 onPreferenceCancel (GtkButton *button,