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.20 2003/11/30 21:21:20 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 */
47 #include "pda_callbacks.h"
48 #include "pda_interface.h"
49 #include "pda_support.h"
52 #define VLC_MAX_MRL 256
54 static char *get_file_perms(struct stat st);
56 /*****************************************************************************
57 * Useful function to retrieve p_intf
58 ****************************************************************************/
59 void * E_(__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 void PlaylistAddItem(GtkWidget *widget, gchar *name, char **ppsz_options, int i_size)
92 intf_thread_t *p_intf = GtkGetIntf( widget );
93 playlist_t *p_playlist;
94 GtkTreeView *p_tvplaylist = NULL;
96 p_playlist = (playlist_t *)
97 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
99 if( p_playlist == NULL)
100 { /* Bail out when VLC's playlist object is not found. */
104 /* Add to playlist object. */
105 p_tvplaylist = (GtkTreeView *) lookup_widget( GTK_WIDGET(widget), "tvPlaylist");
108 GtkTreeModel *p_play_model;
109 GtkTreeIter p_play_iter;
111 p_play_model = gtk_tree_view_get_model(p_tvplaylist);
117 /* Add a new row to the playlist treeview model */
118 gtk_list_store_append (GTK_LIST_STORE(p_play_model), &p_play_iter);
119 gtk_list_store_set (GTK_LIST_STORE(p_play_model), &p_play_iter,
120 0, name, /* Add path to it !!! */
122 2, p_playlist->i_size, /* Hidden index. */
125 /* Add to VLC's playlist */
127 if (p_intf->p_sys->b_autoplayfile)
129 playlist_Add( p_playlist, (const char*)name, (const char**)ppsz_options, i_size,
130 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END);
135 playlist_Add( p_playlist, (const char*)name, (const char**)ppsz_options, i_size,
136 PLAYLIST_APPEND, PLAYLIST_END );
140 for (i=0; i<i_size; i++)
141 free(ppsz_options[i]);
145 vlc_object_release( p_playlist );
148 void PlaylistRebuildListStore( GtkListStore * p_list, playlist_t * p_playlist )
152 gchar * ppsz_text[2];
159 vlc_mutex_lock( &p_playlist->object_lock );
160 for( i_dummy = 0; i_dummy < p_playlist->i_size ; i_dummy++ )
162 ppsz_text[0] = p_playlist->pp_items[i_dummy]->psz_name;
163 ppsz_text[1] = "no info";
164 gtk_list_store_append (p_list, &iter);
165 gtk_list_store_set (p_list, &iter,
168 2, i_dummy, /* Hidden index */
171 vlc_mutex_unlock( &p_playlist->object_lock );
174 /*****************************************************************
175 * Read directory helper function.
176 ****************************************************************/
177 void ReadDirectory(intf_thread_t *p_intf, GtkListStore *p_list, char *psz_dir )
180 struct dirent **pp_namelist;
186 msg_Dbg(p_intf, "Changing to dir %s", psz_dir);
189 status = chdir(psz_dir);
191 msg_Dbg(p_intf, "permision denied" );
193 n = scandir(".", &pp_namelist, 0, alphasort);
202 if (lstat("..", &st)==0)
205 p_pw = getpwuid(st.st_uid);
206 p_grp = getgrgid(st.st_gid);
208 /* XXX : kludge temporaire pour yopy */
210 ppsz_text[1] = get_file_perms(st);
211 ppsz_text[2] = p_pw->pw_name;
212 ppsz_text[3] = p_grp->gr_name;
214 /* Add a new row to the model */
215 gtk_list_store_append (p_list, &iter);
216 gtk_list_store_set (p_list, &iter,
224 if (ppsz_text[1]) free(ppsz_text[1]);
229 if ((pp_namelist[i]->d_name[0] != '.') &&
230 (lstat(pp_namelist[i]->d_name, &st)==0))
233 p_pw = getpwuid(st.st_uid);
234 p_grp = getgrgid(st.st_gid);
236 /* This is a list of strings. */
237 ppsz_text[0] = pp_namelist[i]->d_name;
238 ppsz_text[1] = get_file_perms(st);
239 ppsz_text[2] = p_pw->pw_name;
240 ppsz_text[3] = p_grp->gr_name;
242 msg_Dbg(p_intf, "(%d) file: %s permission: %s user: %s group: %s", i, ppsz_text[0], ppsz_text[1], ppsz_text[2], ppsz_text[3] );
244 gtk_list_store_append (p_list, &iter);
245 gtk_list_store_set (p_list, &iter,
253 if (ppsz_text[1]) free(ppsz_text[1]);
260 static char *get_file_perms(const struct stat st)
264 psz_perm = (char *) malloc(sizeof(char)*10);
265 strncpy( psz_perm, "----------", sizeof("----------"));
267 /* determine permission modes */
268 if (S_ISLNK(st.st_mode))
270 else if (S_ISDIR(st.st_mode))
272 else if (S_ISCHR(st.st_mode))
274 else if (S_ISBLK(st.st_mode))
276 else if (S_ISFIFO(st.st_mode))
278 else if (S_ISSOCK(st.st_mode))
280 else if (S_ISREG(st.st_mode))
282 else /* Unknown type is an error */
284 /* Get file permissions */
286 if (st.st_mode & S_IRUSR)
288 if (st.st_mode & S_IWUSR)
290 if (st.st_mode & S_IXUSR)
292 if (st.st_mode & S_ISUID)
297 else if (st.st_mode & S_ISUID)
300 if (st.st_mode & S_IRGRP)
302 if (st.st_mode & S_IWGRP)
304 if (st.st_mode & S_IXGRP)
306 if (st.st_mode & S_ISGID)
311 else if (st.st_mode & S_ISGID)
314 if (st.st_mode & S_IROTH)
316 if (st.st_mode & S_IWOTH)
318 if (st.st_mode & S_IXOTH)
321 if (st.st_mode &S_ISVTX)
326 else if (st.st_mode &S_ISVTX)
333 * Main interface callbacks
336 gboolean onPDADeleteEvent(GtkWidget *widget, GdkEvent *event, gpointer user_data)
338 intf_thread_t *p_intf = GtkGetIntf( widget );
340 vlc_mutex_lock( &p_intf->change_lock );
341 p_intf->p_vlc->b_die = VLC_TRUE;
342 vlc_mutex_unlock( &p_intf->change_lock );
343 msg_Dbg( p_intf, "about to exit vlc ... signalled" );
349 void onRewind(GtkButton *button, gpointer user_data)
351 intf_thread_t *p_intf = GtkGetIntf( button );
353 if (p_intf->p_sys->p_input != NULL)
355 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_SLOWER );
360 void onPause(GtkButton *button, gpointer user_data)
362 intf_thread_t *p_intf = GtkGetIntf( button );
364 if (p_intf->p_sys->p_input != NULL)
366 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
371 void onPlay(GtkButton *button, gpointer user_data)
373 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) );
374 playlist_t *p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
378 vlc_mutex_lock( &p_playlist->object_lock );
379 if (p_playlist->i_size)
381 vlc_mutex_unlock( &p_playlist->object_lock );
382 playlist_Play( p_playlist );
386 vlc_mutex_unlock( &p_playlist->object_lock );
388 vlc_object_release( p_playlist );
393 void onStop(GtkButton *button, gpointer user_data)
395 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) );
396 playlist_t *p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
400 playlist_Stop( p_playlist );
401 vlc_object_release( p_playlist );
406 void onForward(GtkButton *button, gpointer user_data)
408 intf_thread_t *p_intf = GtkGetIntf( button );
410 if (p_intf->p_sys->p_input != NULL)
412 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_FASTER );
417 void onAbout(GtkButton *button, gpointer user_data)
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,6);
430 gboolean SliderRelease(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
432 intf_thread_t *p_intf = GtkGetIntf( widget );
434 vlc_mutex_lock( &p_intf->change_lock );
435 p_intf->p_sys->b_slider_free = 1;
436 vlc_mutex_unlock( &p_intf->change_lock );
442 gboolean SliderPress(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
444 intf_thread_t *p_intf = GtkGetIntf( widget );
446 vlc_mutex_lock( &p_intf->change_lock );
447 p_intf->p_sys->b_slider_free = 0;
448 vlc_mutex_unlock( &p_intf->change_lock );
453 void addSelectedToPlaylist(GtkTreeModel *model, GtkTreePath *path,
454 GtkTreeIter *iter, gpointer *userdata)
458 gtk_tree_model_get(model, iter, 0, &psz_filename, -1);
460 PlaylistAddItem(GTK_WIDGET(userdata), psz_filename, 0, 0);
463 void onFileListRow(GtkTreeView *treeview, GtkTreePath *path,
464 GtkTreeViewColumn *column, gpointer user_data)
466 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(treeview) );
467 GtkTreeSelection *p_selection = gtk_tree_view_get_selection(treeview);
469 if (gtk_tree_selection_count_selected_rows(p_selection) == 1)
472 GtkTreeModel *p_model;
476 /* This might be a directory selection */
477 p_model = gtk_tree_view_get_model(treeview);
480 msg_Err(p_intf, "PDA: Filelist model contains a NULL pointer\n" );
483 if (!gtk_tree_model_get_iter(p_model, &iter, path))
485 msg_Err( p_intf, "PDA: Could not get iter from model" );
489 gtk_tree_model_get(p_model, &iter, 0, &psz_filename, -1);
490 if (stat((char*)psz_filename, &st)==0)
492 if (S_ISDIR(st.st_mode))
494 GtkListStore *p_store = NULL;
496 /* Get new directory listing */
497 p_store = gtk_list_store_new (5,
505 ReadDirectory(p_intf, p_store, psz_filename);
507 /* Update TreeView with new model */
508 gtk_tree_view_set_model(treeview, (GtkTreeModel*) p_store);
509 g_object_unref(p_store);
514 gtk_tree_selection_selected_foreach(p_selection, (GtkTreeSelectionForeachFunc) &addSelectedToPlaylist, (gpointer) treeview);
520 gtk_tree_selection_selected_foreach(p_selection, (GtkTreeSelectionForeachFunc) &addSelectedToPlaylist, (gpointer) treeview);
524 void onAddFileToPlaylist(GtkButton *button, gpointer user_data)
526 GtkTreeView *p_treeview = NULL;
528 p_treeview = (GtkTreeView *) lookup_widget( GTK_WIDGET(button), "tvFileList");
531 GtkTreeSelection *p_selection = gtk_tree_view_get_selection(p_treeview);
533 gtk_tree_selection_selected_foreach(p_selection, (GtkTreeSelectionForeachFunc) &addSelectedToPlaylist, (gpointer) p_treeview);
538 void NetworkBuildMRL(GtkEditable *editable, gpointer user_data)
540 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(editable) );
541 GtkSpinButton *networkPort = NULL;
542 GtkEntry *entryMRL = NULL;
543 GtkEntry *networkType = NULL;
544 GtkEntry *networkAddress = NULL;
545 GtkEntry *networkProtocol = NULL;
546 const gchar *psz_mrlNetworkType;
547 const gchar *psz_mrlAddress;
548 const gchar *psz_mrlProtocol;
550 char text[VLC_MAX_MRL];
553 entryMRL = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryMRL" );
555 networkType = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryNetworkType" );
556 networkAddress = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryNetworkAddress" );
557 networkPort = (GtkSpinButton*) lookup_widget( GTK_WIDGET(editable), "entryNetworkPort" );
558 networkProtocol = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryNetworkProtocolType" );
560 psz_mrlNetworkType = gtk_entry_get_text(GTK_ENTRY(networkType));
561 psz_mrlAddress = gtk_entry_get_text(GTK_ENTRY(networkAddress));
562 i_mrlPort = gtk_spin_button_get_value_as_int(networkPort);
563 psz_mrlProtocol = gtk_entry_get_text(GTK_ENTRY(networkProtocol));
565 /* Build MRL from parts ;-) */
566 i_pos = snprintf( &text[0], VLC_MAX_MRL, "%s://", (char*)psz_mrlProtocol);
567 if (strncasecmp( (char*)psz_mrlNetworkType, "multicast",9)==0)
569 i_pos += snprintf( &text[i_pos], VLC_MAX_MRL - i_pos, "@" );
571 i_pos += snprintf( &text[i_pos], VLC_MAX_MRL - i_pos, "%s:%d", (char*)psz_mrlAddress, (int)i_mrlPort );
573 if (i_pos >= VLC_MAX_MRL)
575 text[VLC_MAX_MRL-1]='\0';
576 msg_Err( p_intf, "Media Resource Locator is truncated to: %s", text);
579 gtk_entry_set_text(entryMRL,text);
583 onAddNetworkPlaylist (GtkButton *button,
586 GtkEntry *p_mrl = NULL;
587 const gchar *psz_mrl_name;
589 p_mrl = (GtkEntry*) lookup_widget(GTK_WIDGET(button),"entryMRL" );
592 psz_mrl_name = gtk_entry_get_text(p_mrl);
594 PlaylistAddItem(GTK_WIDGET(button), (gchar *)psz_mrl_name, 0, 0);
600 onAddCameraToPlaylist (GtkButton *button,
603 intf_thread_t *p_intf = GtkGetIntf( button );
605 GtkSpinButton *entryV4LChannel = NULL;
606 GtkSpinButton *entryV4LFrequency = NULL;
607 GtkSpinButton *entryV4LSampleRate = NULL;
608 GtkSpinButton *entryV4LQuality = NULL;
609 GtkSpinButton *entryV4LTuner = NULL;
611 gint i_v4l_frequency;
612 gint i_v4l_samplerate;
616 GtkEntry *entryV4LVideoDevice = NULL;
617 GtkEntry *entryV4LAudioDevice = NULL;
618 GtkEntry *entryV4LNorm = NULL;
619 GtkEntry *entryV4LSize = NULL;
620 GtkEntry *entryV4LSoundDirection = NULL;
621 const gchar *p_v4l_video_device;
622 const gchar *p_v4l_audio_device;
623 const gchar *p_v4l_norm;
624 const gchar *p_v4l_size;
625 const gchar *p_v4l_sound_direction;
628 GtkCheckButton *checkV4LMJPEG = NULL;
629 GtkSpinButton *entryV4LDecimation = NULL;
630 gboolean b_v4l_mjpeg;
631 gint i_v4l_decimation;
634 char **ppsz_options = NULL; /* list of options */
640 ppsz_options = (char **) malloc(11 *sizeof(char*));
641 if (ppsz_options == NULL)
643 msg_Err(p_intf, "No memory to allocate for v4l options.");
648 ppsz_options[i] = (char *) malloc(VLC_MAX_MRL * sizeof(char));
649 if (ppsz_options[i] == NULL)
651 msg_Err(p_intf, "No memory to allocate for v4l options string %i.", i);
652 for (i-=1; i>=0; i--)
653 free(ppsz_options[i]);
659 i_pos = snprintf( &v4l_mrl[0], 6, "v4l");
662 entryV4LChannel = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LChannel" );
663 entryV4LFrequency = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LFrequency" );
664 entryV4LSampleRate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LSampleRate" );
665 entryV4LQuality = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LQuality" );
666 entryV4LTuner = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LTuner" );
668 entryV4LVideoDevice = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LVideoDevice" );
669 entryV4LAudioDevice = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LAudioDevice" );
670 entryV4LNorm = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LNorm" );
671 entryV4LSize = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LSize" );
672 entryV4LSoundDirection = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LSoundDirection" );
674 i_v4l_channel = gtk_spin_button_get_value_as_int(entryV4LChannel);
675 i_v4l_frequency = gtk_spin_button_get_value_as_int(entryV4LFrequency);
676 i_v4l_samplerate = gtk_spin_button_get_value_as_int(entryV4LSampleRate);
677 i_v4l_quality = gtk_spin_button_get_value_as_int(entryV4LQuality);
678 i_v4l_tuner = gtk_spin_button_get_value_as_int(entryV4LTuner);
680 p_v4l_video_device = gtk_entry_get_text(GTK_ENTRY(entryV4LVideoDevice));
681 p_v4l_audio_device = gtk_entry_get_text(GTK_ENTRY(entryV4LAudioDevice));
682 p_v4l_norm = gtk_entry_get_text(GTK_ENTRY(entryV4LNorm));
683 p_v4l_size = gtk_entry_get_text(GTK_ENTRY(entryV4LSize));
684 p_v4l_sound_direction = gtk_entry_get_text(GTK_ENTRY(entryV4LSoundDirection));
686 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "%s", (char*)p_v4l_video_device );
687 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
688 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "adev=%s", (char*)p_v4l_audio_device );
689 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
690 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "norm=%s", (char*)p_v4l_norm );
691 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
692 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "size=%s", (char*)p_v4l_size );
693 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
694 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "%s", (char*)p_v4l_sound_direction );
695 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
697 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "channel=%d", (int)i_v4l_channel );
698 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
699 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "frequency=%d", (int)i_v4l_frequency );
700 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
701 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "samplerate=%d", (int)i_v4l_samplerate );
702 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
703 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "quality=%d", (int)i_v4l_quality );
704 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
705 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "tuner=%d", (int)i_v4l_tuner );
706 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
709 checkV4LMJPEG = (GtkCheckButton*) lookup_widget( GTK_WIDGET(button), "checkV4LMJPEG" );
710 b_v4l_mjpeg = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkV4LMJPEG));
713 entryV4LDecimation = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LDecimation" );
714 i_v4l_decimation = gtk_spin_button_get_value_as_int(entryV4LDecimation);
716 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "mjpeg:%d", (int)i_v4l_decimation );
717 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
721 PlaylistAddItem(GTK_WIDGET(button), (gchar*) &v4l_mrl, ppsz_options, i_options);
726 PlaylistEvent (GtkWidget *widget,
735 onPlaylistColumnsChanged (GtkTreeView *treeview,
742 onPlaylistRowSelected (GtkTreeView *treeview,
743 gboolean start_editing,
751 onPlaylistRow (GtkTreeView *treeview,
753 GtkTreeViewColumn *column,
760 onUpdatePlaylist (GtkButton *button,
763 intf_thread_t * p_intf = GtkGetIntf( button );
764 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
766 GtkTreeView *p_tvplaylist = NULL;
768 if( p_playlist == NULL )
773 p_tvplaylist = (GtkTreeView*) lookup_widget( GTK_WIDGET(button), "tvPlaylist");
776 GtkListStore *p_model = NULL;
778 /* Rebuild the playlist then. */
779 p_model = gtk_list_store_new (3,
780 G_TYPE_STRING, /* Filename */
781 G_TYPE_STRING, /* Time */
782 G_TYPE_UINT); /* Hidden field */
785 PlaylistRebuildListStore(p_model, p_playlist);
786 gtk_tree_view_set_model(GTK_TREE_VIEW(p_tvplaylist), GTK_TREE_MODEL(p_model));
787 g_object_unref(p_model);
790 vlc_object_release( p_playlist );
794 onDeletePlaylist (GtkButton *button,
797 intf_thread_t *p_intf = GtkGetIntf( button );
798 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
800 GtkTreeView *p_tvplaylist;
802 /* Delete an arbitrary item from the playlist */
803 p_tvplaylist = (GtkTreeView *) lookup_widget( GTK_WIDGET(button), "tvPlaylist" );
804 if (p_tvplaylist != NULL)
806 GList *p_rows = NULL;
808 GtkTreeModel *p_model = NULL;
809 GtkListStore *p_store = NULL;
810 GtkTreeSelection *p_selection = gtk_tree_view_get_selection(p_tvplaylist);
812 p_model = gtk_tree_view_get_model(p_tvplaylist);
815 p_rows = gtk_tree_selection_get_selected_rows(p_selection, &p_model);
817 if( g_list_length( p_rows ) )
819 /* reverse-sort so that we can delete from the furthest
820 * to the closest item to delete...
822 p_rows = g_list_reverse( p_rows );
825 for (p_node=p_rows; p_node!=NULL; p_node = p_node->next)
828 GtkTreePath *p_path = NULL;
830 p_path = (GtkTreePath *)p_node->data;
833 if (gtk_tree_model_get_iter(p_model, &iter, p_path))
837 gtk_tree_model_get(p_model, &iter, 2, &item, -1);
838 playlist_Delete(p_playlist, item);
842 g_list_foreach (p_rows, (GFunc*)gtk_tree_path_free, NULL);
843 g_list_free (p_rows);
846 /* Rebuild the playlist then. */
847 p_store = gtk_list_store_new (3,
848 G_TYPE_STRING, /* Filename */
849 G_TYPE_STRING, /* Time */
850 G_TYPE_UINT); /* Hidden field */
853 PlaylistRebuildListStore(p_store, p_playlist);
854 gtk_tree_view_set_model(GTK_TREE_VIEW(p_tvplaylist), GTK_TREE_MODEL(p_store));
855 g_object_unref(p_store);
858 vlc_object_release( p_playlist );
863 onClearPlaylist (GtkButton *button,
866 intf_thread_t *p_intf = GtkGetIntf( button );
867 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
869 GtkTreeView *p_tvplaylist;
872 if( p_playlist == NULL )
877 for(item = p_playlist->i_size - 1; item >= 0 ;item-- )
879 playlist_Delete( p_playlist, item);
881 vlc_object_release( p_playlist );
883 // Remove all entries from the Playlist widget.
884 p_tvplaylist = (GtkTreeView*) lookup_widget( GTK_WIDGET(button), "tvPlaylist");
887 GtkTreeModel *p_play_model;
889 p_play_model = gtk_tree_view_get_model(p_tvplaylist);
892 gtk_list_store_clear(GTK_LIST_STORE(p_play_model));
899 onPreferenceSave (GtkButton *button,
903 intf_thread_t *p_intf = GtkGetIntf( button );
905 msg_Dbg(p_intf, "Preferences Save" );
906 config_SaveConfigFile( p_intf, NULL );
912 onPreferenceApply (GtkButton *button,
916 intf_thread_t *p_intf = GtkGetIntf( button );
918 msg_Dbg(p_intf, "Preferences Apply" );
924 onPreferenceCancel (GtkButton *button,
928 intf_thread_t *p_intf = GtkGetIntf( button );
930 msg_Dbg(p_intf, "Preferences Cancel" );
931 config_ResetAll( p_intf );
932 /* Cancel interface changes. */
933 config_SaveConfigFile( p_intf, NULL );
938 void onAddTranscodeToPlaylist (GtkButton *button,
941 intf_thread_t *p_intf = GtkGetIntf( button );
943 GtkEntry *p_entryVideoCodec = NULL;
944 GtkSpinButton *p_entryVideoBitrate = NULL;
945 GtkSpinButton *p_entryVideoBitrateTolerance = NULL;
946 GtkSpinButton *p_entryVideoKeyFrameInterval = NULL;
947 GtkCheckButton *p_checkVideoDeinterlace = NULL;
948 GtkEntry *p_entryAudioCodec = NULL;
949 GtkSpinButton *p_entryAudioBitrate = NULL;
950 const gchar *p_video_codec;
951 gint i_video_bitrate;
952 gint i_video_bitrate_tolerance;
953 gint i_video_keyframe_interval;
954 gboolean b_video_deinterlace;
955 const gchar *p_audio_codec;
956 gint i_audio_bitrate;
958 GtkEntry *p_entryStdAccess = NULL;
959 GtkEntry *p_entryStdMuxer = NULL;
960 GtkEntry *p_entryStdURL = NULL;
961 GtkSpinButton *p_entryStdTTL = NULL;
962 const gchar *p_std_access;
963 const gchar *p_std_muxer;
964 const gchar *p_std_url;
967 char **ppsz_options = NULL; /* list of options */
974 ppsz_options = (char **) malloc(15 *sizeof(char*));
975 if (ppsz_options == NULL)
977 msg_Err(p_intf, "No memory to allocate for v4l options.");
982 ppsz_options[i] = (char *) malloc(VLC_MAX_MRL * sizeof(char));
983 if (ppsz_options[i] == NULL)
985 msg_Err(p_intf, "No memory to allocate for v4l options string %i.", i);
986 for (i-=1; i>=0; i--)
987 free(ppsz_options[i]);
993 i_pos = snprintf( &mrl[0], VLC_MAX_MRL, "sout");
996 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "'#transcode{");
997 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
999 p_entryVideoCodec = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryVideoCodec" );
1000 p_entryVideoBitrate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoBitrate" );
1001 p_entryVideoBitrateTolerance = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoBitrateTolerance" );
1002 p_entryVideoKeyFrameInterval = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoKeyFrameInterval" );
1004 p_video_codec = gtk_entry_get_text(GTK_ENTRY(p_entryVideoCodec));
1005 i_video_bitrate = gtk_spin_button_get_value_as_int(p_entryVideoBitrate);
1006 i_video_bitrate_tolerance = gtk_spin_button_get_value_as_int(p_entryVideoBitrateTolerance);
1007 i_video_keyframe_interval = gtk_spin_button_get_value_as_int(p_entryVideoKeyFrameInterval);
1009 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "vcodec=%s,", (char*)p_video_codec );
1010 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1011 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "vb=%d,", (int)i_video_bitrate );
1012 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1013 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "vt=%d,", (int)i_video_bitrate_tolerance );
1014 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1015 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "keyint=%d,", (int)i_video_keyframe_interval );
1016 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1018 p_checkVideoDeinterlace = (GtkCheckButton*) lookup_widget( GTK_WIDGET(button), "checkVideoDeinterlace" );
1019 b_video_deinterlace = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_checkVideoDeinterlace));
1020 if (b_video_deinterlace)
1022 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "deinterlace," );
1023 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1025 p_entryAudioCodec = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryAudioCodec" );
1026 p_entryAudioBitrate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryAudioBitrate" );
1028 p_audio_codec = gtk_entry_get_text(GTK_ENTRY(p_entryAudioCodec));
1029 i_audio_bitrate = gtk_spin_button_get_value_as_int(p_entryAudioBitrate);
1031 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "acodec=%s,", (char*)p_audio_codec );
1032 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1033 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "ab=%d", (int)i_audio_bitrate );
1034 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1036 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "}:std{" );
1037 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1039 p_entryStdAccess = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdAccess" );
1040 p_entryStdMuxer = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdMuxer" );
1041 p_entryStdURL = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdURL" );
1042 p_entryStdTTL = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryStdTTL" );
1044 p_std_access = gtk_entry_get_text(GTK_ENTRY(p_entryStdAccess));
1045 p_std_muxer = gtk_entry_get_text(GTK_ENTRY(p_entryStdMuxer));
1046 p_std_url = gtk_entry_get_text(GTK_ENTRY(p_entryStdURL));
1048 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "access=%s,", (char*)p_std_access);
1049 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1050 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "mux=%s,", (char*)p_std_muxer);
1051 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1052 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "url=%s}'", (char*)p_std_url);
1053 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1054 // i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "}'");
1055 // if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1057 i_std_ttl = gtk_spin_button_get_value_as_int(p_entryStdTTL);
1059 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "ttl=%d", (int)i_std_ttl);
1060 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1062 PlaylistAddItem(GTK_WIDGET(button), (gchar*) &mrl, ppsz_options, i_options);