1 /*****************************************************************************
2 * pda_callbacks.c : Callbacks for the pda Linux Gtk+ plugin.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 the VideoLAN team
7 * Authors: Jean-Paul Saman <jpsaman _at_ videolan _dot_ org>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <sys/types.h> /* off_t */
29 #include <vlc_interface.h>
30 #include <vlc_playlist.h>
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;
95 GtkTreeView *p_tvplaylist = NULL;
97 p_playlist = (playlist_t *)
98 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
100 if( p_playlist == NULL)
101 { /* Bail out when VLC's playlist object is not found. */
105 /* Add to playlist object. */
106 p_tvplaylist = (GtkTreeView *) lookup_widget( GTK_WIDGET(widget), "tvPlaylist");
109 GtkTreeModel *p_play_model;
110 GtkTreeIter p_play_iter;
112 p_play_model = gtk_tree_view_get_model(p_tvplaylist);
118 /* Add a new row to the playlist treeview model */
119 gtk_list_store_append (GTK_LIST_STORE(p_play_model), &p_play_iter);
120 gtk_list_store_set (GTK_LIST_STORE(p_play_model), &p_play_iter,
121 0, name, /* Add path to it !!! */
123 2, p_playlist->i_size, /* Hidden index. */
126 /* Add to VLC's playlist */
128 if (p_intf->p_sys->b_autoplayfile)
130 playlist_Add( p_playlist, (const char*)name, (const char**)ppsz_options, i_size,
131 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END);
136 i_id = playlist_AddExt( p_playlist, (const char*)name,
138 PLAYLIST_APPEND, PLAYLIST_END,
140 (const char **) ppsz_options, i_pos );
144 for (i=0; i<i_size; i++)
145 free(ppsz_options[i]);
149 vlc_object_release( p_playlist );
152 void PlaylistRebuildListStore( GtkListStore * p_list, playlist_t * p_playlist )
156 gchar * ppsz_text[2];
163 vlc_mutex_lock( &p_playlist->object_lock );
164 for( i_dummy = 0; i_dummy < p_playlist->i_size ; i_dummy++ )
166 ppsz_text[0] = p_playlist->pp_items[i_dummy]->input.psz_name;
167 ppsz_text[1] = "no info";
168 gtk_list_store_append (p_list, &iter);
169 gtk_list_store_set (p_list, &iter,
172 2, i_dummy, /* Hidden index */
175 vlc_mutex_unlock( &p_playlist->object_lock );
178 /*****************************************************************
179 * Read directory helper function.
180 ****************************************************************/
181 void ReadDirectory(intf_thread_t *p_intf, GtkListStore *p_list, char *psz_dir )
184 struct dirent **pp_namelist;
190 msg_Dbg(p_intf, "Changing to dir %s", psz_dir);
193 status = chdir(psz_dir);
195 msg_Dbg(p_intf, "permision denied" );
197 n = scandir(".", &pp_namelist, 0, alphasort);
206 if (lstat("..", &st)==0)
209 p_pw = getpwuid(st.st_uid);
210 p_grp = getgrgid(st.st_gid);
212 /* XXX : kludge temporaire pour yopy */
214 ppsz_text[1] = get_file_perms(st);
215 ppsz_text[2] = p_pw->pw_name;
216 ppsz_text[3] = p_grp->gr_name;
218 /* Add a new row to the model */
219 gtk_list_store_append (p_list, &iter);
220 gtk_list_store_set (p_list, &iter,
228 if (ppsz_text[1]) free(ppsz_text[1]);
233 if ((pp_namelist[i]->d_name[0] != '.') &&
234 (lstat(pp_namelist[i]->d_name, &st)==0))
237 p_pw = getpwuid(st.st_uid);
238 p_grp = getgrgid(st.st_gid);
240 /* This is a list of strings. */
241 ppsz_text[0] = pp_namelist[i]->d_name;
242 ppsz_text[1] = get_file_perms(st);
243 ppsz_text[2] = p_pw->pw_name;
244 ppsz_text[3] = p_grp->gr_name;
246 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] );
248 gtk_list_store_append (p_list, &iter);
249 gtk_list_store_set (p_list, &iter,
257 if (ppsz_text[1]) free(ppsz_text[1]);
264 static char *get_file_perms(const struct stat st)
268 psz_perm = (char *) malloc(sizeof(char)*10);
269 strncpy( psz_perm, "----------", sizeof("----------"));
271 /* determine permission modes */
272 if (S_ISLNK(st.st_mode))
274 else if (S_ISDIR(st.st_mode))
276 else if (S_ISCHR(st.st_mode))
278 else if (S_ISBLK(st.st_mode))
280 else if (S_ISFIFO(st.st_mode))
282 else if (S_ISSOCK(st.st_mode))
284 else if (S_ISREG(st.st_mode))
286 else /* Unknown type is an error */
288 /* Get file permissions */
290 if (st.st_mode & S_IRUSR)
292 if (st.st_mode & S_IWUSR)
294 if (st.st_mode & S_IXUSR)
296 if (st.st_mode & S_ISUID)
301 else if (st.st_mode & S_ISUID)
304 if (st.st_mode & S_IRGRP)
306 if (st.st_mode & S_IWGRP)
308 if (st.st_mode & S_IXGRP)
310 if (st.st_mode & S_ISGID)
315 else if (st.st_mode & S_ISGID)
318 if (st.st_mode & S_IROTH)
320 if (st.st_mode & S_IWOTH)
322 if (st.st_mode & S_IXOTH)
325 if (st.st_mode &S_ISVTX)
330 else if (st.st_mode &S_ISVTX)
337 * Main interface callbacks
340 gboolean onPDADeleteEvent(GtkWidget *widget, GdkEvent *event, gpointer user_data)
342 intf_thread_t *p_intf = GtkGetIntf( widget );
344 vlc_mutex_lock( &p_intf->change_lock );
345 vlc_object_kill( p_intf->p_libvlc );
346 vlc_mutex_unlock( &p_intf->change_lock );
347 msg_Dbg( p_intf, "about to exit vlc ... signaled" );
352 void onRewind(GtkButton *button, gpointer user_data)
354 intf_thread_t *p_intf = GtkGetIntf( button );
356 if (p_intf->p_sys->p_input != NULL)
358 var_SetVoid( p_intf->p_sys->p_input, "rate-slower" );
362 void onPause(GtkButton *button, gpointer user_data)
364 intf_thread_t *p_intf = GtkGetIntf( button );
366 if (p_intf->p_sys->p_input != NULL)
368 var_SetInteger( p_intf->p_sys->p_input, "state", PAUSE_S );
373 void onPlay(GtkButton *button, gpointer user_data)
375 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) );
376 playlist_t *p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
380 vlc_mutex_lock( &p_playlist->object_lock );
381 if (p_playlist->i_size)
383 vlc_mutex_unlock( &p_playlist->object_lock );
384 playlist_Play( p_playlist );
385 gdk_window_lower( p_intf->p_sys->p_window->window );
389 vlc_mutex_unlock( &p_playlist->object_lock );
391 vlc_object_release( p_playlist );
395 void onStop(GtkButton *button, gpointer user_data)
397 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) );
398 playlist_t *p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
402 playlist_Stop( p_playlist );
403 vlc_object_release( p_playlist );
404 gdk_window_raise( p_intf->p_sys->p_window->window );
408 void onForward(GtkButton *button, gpointer user_data)
410 intf_thread_t *p_intf = GtkGetIntf( button );
412 if (p_intf->p_sys->p_input != NULL)
414 var_SetVoid( p_intf->p_sys->p_input, "rate-faster" );
419 void onAbout(GtkButton *button, gpointer user_data)
421 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(button) );
423 /* Toggle notebook */
424 if (p_intf->p_sys->p_notebook)
426 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
427 gtk_notebook_set_page(p_intf->p_sys->p_notebook,6);
431 gboolean SliderRelease(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
433 intf_thread_t *p_intf = GtkGetIntf( widget );
435 msg_Dbg( p_intf, "SliderButton Release" );
436 vlc_mutex_lock( &p_intf->change_lock );
437 p_intf->p_sys->b_slider_free = 1;
438 vlc_mutex_unlock( &p_intf->change_lock );
443 gboolean SliderPress(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
445 intf_thread_t *p_intf = GtkGetIntf( widget );
447 msg_Dbg( p_intf, "SliderButton Press" );
448 vlc_mutex_lock( &p_intf->change_lock );
449 p_intf->p_sys->b_slider_free = 0;
450 vlc_mutex_unlock( &p_intf->change_lock );
455 void SliderMove(GtkRange *range, GtkScrollType scroll, gpointer user_data)
457 intf_thread_t *p_intf = GtkGetIntf( range );
458 msg_Dbg( p_intf, "SliderButton Move" );
462 void addSelectedToPlaylist(GtkTreeModel *model, GtkTreePath *path,
463 GtkTreeIter *iter, gpointer *userdata)
467 gtk_tree_model_get(model, iter, 0, &psz_filename, -1);
469 PlaylistAddItem(GTK_WIDGET(userdata), psz_filename, 0, 0);
472 void onFileListRow(GtkTreeView *treeview, GtkTreePath *path,
473 GtkTreeViewColumn *column, gpointer user_data)
475 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(treeview) );
476 GtkTreeSelection *p_selection = gtk_tree_view_get_selection(treeview);
478 if (gtk_tree_selection_count_selected_rows(p_selection) == 1)
481 GtkTreeModel *p_model;
485 /* This might be a directory selection */
486 p_model = gtk_tree_view_get_model(treeview);
489 msg_Err(p_intf, "PDA: Filelist model contains a NULL pointer\n" );
492 if (!gtk_tree_model_get_iter(p_model, &iter, path))
494 msg_Err( p_intf, "PDA: Could not get iter from model" );
498 gtk_tree_model_get(p_model, &iter, 0, &psz_filename, -1);
499 if (stat((char*)psz_filename, &st)==0)
501 if (S_ISDIR(st.st_mode))
503 GtkListStore *p_store = NULL;
505 /* Get new directory listing */
506 p_store = gtk_list_store_new (5,
514 ReadDirectory(p_intf, p_store, psz_filename);
516 /* Update TreeView with new model */
517 gtk_tree_view_set_model(treeview, (GtkTreeModel*) p_store);
518 g_object_unref(p_store);
525 void onAddFileToPlaylist(GtkButton *button, gpointer user_data)
527 GtkTreeView *p_treeview = NULL;
529 p_treeview = (GtkTreeView *) lookup_widget( GTK_WIDGET(button), "tvFileList");
532 GtkTreeSelection *p_selection = gtk_tree_view_get_selection(p_treeview);
534 gtk_tree_selection_selected_foreach(p_selection, (GtkTreeSelectionForeachFunc) &addSelectedToPlaylist, (gpointer) p_treeview);
539 void NetworkBuildMRL(GtkEditable *editable, gpointer user_data)
541 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(editable) );
542 GtkSpinButton *p_networkPort = NULL;
543 GtkEntry *p_entryMRL = NULL;
544 GtkEntry *p_networkType = NULL;
545 GtkEntry *p_networkAddress = NULL;
546 GtkEntry *p_networkProtocol = NULL;
547 const gchar *psz_mrlNetworkType;
548 const gchar *psz_mrlAddress;
549 const gchar *psz_mrlProtocol;
551 char text[VLC_MAX_MRL];
554 p_entryMRL = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryMRL" );
556 p_networkType = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryNetworkType" );
557 p_networkAddress = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryNetworkAddress" );
558 p_networkPort = (GtkSpinButton*) lookup_widget( GTK_WIDGET(editable), "entryNetworkPort" );
559 p_networkProtocol = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryNetworkProtocolType" );
561 psz_mrlNetworkType = gtk_entry_get_text(GTK_ENTRY(p_networkType));
562 psz_mrlAddress = gtk_entry_get_text(GTK_ENTRY(p_networkAddress));
563 i_mrlPort = gtk_spin_button_get_value_as_int(p_networkPort);
564 psz_mrlProtocol = gtk_entry_get_text(GTK_ENTRY(p_networkProtocol));
566 /* Build MRL from parts ;-) */
567 i_pos = snprintf( &text[0], VLC_MAX_MRL, "%s://", (char*)psz_mrlProtocol);
568 if (strncasecmp( (char*)psz_mrlNetworkType, "multicast",9)==0)
570 i_pos += snprintf( &text[i_pos], VLC_MAX_MRL - i_pos, "@" );
572 i_pos += snprintf( &text[i_pos], VLC_MAX_MRL - i_pos, "%s:%d", (char*)psz_mrlAddress, (int)i_mrlPort );
574 if (i_pos >= VLC_MAX_MRL)
576 text[VLC_MAX_MRL-1]='\0';
577 msg_Err( p_intf, "Media Resource Locator is truncated to: %s", text);
580 gtk_entry_set_text(p_entryMRL,text);
583 void onAddNetworkPlaylist(GtkButton *button, gpointer user_data)
585 intf_thread_t *p_intf = GtkGetIntf( button );
587 GtkEntry *p_mrl = NULL;
588 GtkCheckButton *p_network_transcode = NULL;
589 gboolean b_network_transcode;
590 const gchar *psz_mrl_name;
592 p_mrl = (GtkEntry*) lookup_widget(GTK_WIDGET(button),"entryMRL" );
593 psz_mrl_name = gtk_entry_get_text(p_mrl);
595 p_network_transcode = (GtkCheckButton*) lookup_widget(GTK_WIDGET(button), "checkNetworkTranscode" );
596 b_network_transcode = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_network_transcode));
597 if (b_network_transcode)
599 msg_Dbg( p_intf, "Network transcode option selected." );
600 onAddTranscodeToPlaylist(GTK_WIDGET(button), (gchar *)psz_mrl_name);
604 msg_Dbg( p_intf, "Network receiving selected." );
605 PlaylistAddItem(GTK_WIDGET(button), (gchar *)psz_mrl_name, 0, 0);
610 void onAddCameraToPlaylist(GtkButton *button, gpointer user_data)
612 intf_thread_t *p_intf = GtkGetIntf( button );
614 GtkSpinButton *entryV4LChannel = NULL;
615 GtkSpinButton *entryV4LFrequency = NULL;
616 GtkSpinButton *entryV4LSampleRate = NULL;
617 GtkSpinButton *entryV4LQuality = NULL;
618 GtkSpinButton *entryV4LTuner = NULL;
620 gint i_v4l_frequency;
621 gint i_v4l_samplerate;
625 GtkEntry *entryV4LVideoDevice = NULL;
626 GtkEntry *entryV4LAudioDevice = NULL;
627 GtkEntry *entryV4LNorm = NULL;
628 GtkEntry *entryV4LSize = NULL;
629 GtkEntry *entryV4LSoundDirection = NULL;
630 const gchar *p_v4l_video_device;
631 const gchar *p_v4l_audio_device;
632 const gchar *p_v4l_norm;
633 const gchar *p_v4l_size;
634 const gchar *p_v4l_sound_direction;
637 GtkCheckButton *checkV4LMJPEG = NULL;
638 GtkSpinButton *entryV4LDecimation = NULL;
639 gboolean b_v4l_mjpeg;
640 gint i_v4l_decimation;
643 GtkCheckButton *p_check_v4l_transcode = NULL;
644 gboolean b_v4l_transcode;
646 char **ppsz_options = NULL; /* list of options */
652 ppsz_options = (char **) malloc(11 *sizeof(char*));
653 if (ppsz_options == NULL)
655 msg_Err(p_intf, "No memory to allocate for v4l options.");
660 ppsz_options[i] = (char *) malloc(VLC_MAX_MRL * sizeof(char));
661 if (ppsz_options[i] == NULL)
663 msg_Err(p_intf, "No memory to allocate for v4l options string %i.", i);
664 for (i-=1; i>=0; i--)
665 free(ppsz_options[i]);
671 i_pos = snprintf( &v4l_mrl[0], 6, "v4l");
674 entryV4LChannel = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LChannel" );
675 entryV4LFrequency = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LFrequency" );
676 entryV4LSampleRate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LSampleRate" );
677 entryV4LQuality = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LQuality" );
678 entryV4LTuner = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LTuner" );
680 entryV4LVideoDevice = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LVideoDevice" );
681 entryV4LAudioDevice = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LAudioDevice" );
682 entryV4LNorm = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LNorm" );
683 entryV4LSize = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LSize" );
684 entryV4LSoundDirection = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LSoundDirection" );
686 i_v4l_channel = gtk_spin_button_get_value_as_int(entryV4LChannel);
687 i_v4l_frequency = gtk_spin_button_get_value_as_int(entryV4LFrequency);
688 i_v4l_samplerate = gtk_spin_button_get_value_as_int(entryV4LSampleRate);
689 i_v4l_quality = gtk_spin_button_get_value_as_int(entryV4LQuality);
690 i_v4l_tuner = gtk_spin_button_get_value_as_int(entryV4LTuner);
692 p_v4l_video_device = gtk_entry_get_text(GTK_ENTRY(entryV4LVideoDevice));
693 p_v4l_audio_device = gtk_entry_get_text(GTK_ENTRY(entryV4LAudioDevice));
694 p_v4l_norm = gtk_entry_get_text(GTK_ENTRY(entryV4LNorm));
695 p_v4l_size = gtk_entry_get_text(GTK_ENTRY(entryV4LSize));
696 p_v4l_sound_direction = gtk_entry_get_text(GTK_ENTRY(entryV4LSoundDirection));
698 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "%s", (char*)p_v4l_video_device );
699 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
700 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "adev=%s", (char*)p_v4l_audio_device );
701 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
702 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "norm=%s", (char*)p_v4l_norm );
703 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
704 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "size=%s", (char*)p_v4l_size );
705 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
706 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "%s", (char*)p_v4l_sound_direction );
707 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
709 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "channel=%d", (int)i_v4l_channel );
710 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
711 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "frequency=%d", (int)i_v4l_frequency );
712 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
713 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "samplerate=%d", (int)i_v4l_samplerate );
714 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
715 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "quality=%d", (int)i_v4l_quality );
716 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
717 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "tuner=%d", (int)i_v4l_tuner );
718 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
721 checkV4LMJPEG = (GtkCheckButton*) lookup_widget( GTK_WIDGET(button), "checkV4LMJPEG" );
722 b_v4l_mjpeg = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkV4LMJPEG));
725 entryV4LDecimation = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LDecimation" );
726 i_v4l_decimation = gtk_spin_button_get_value_as_int(entryV4LDecimation);
728 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "mjpeg:%d", (int)i_v4l_decimation );
729 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
733 p_check_v4l_transcode = (GtkCheckButton*) lookup_widget(GTK_WIDGET(button), "checkV4LTranscode" );
734 b_v4l_transcode = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_check_v4l_transcode));
737 msg_Dbg( p_intf, "Camera transcode option selected." );
738 onAddTranscodeToPlaylist(GTK_WIDGET(button), (gchar *)v4l_mrl);
742 msg_Dbg( p_intf, "Camera reception option selected." );
743 PlaylistAddItem(GTK_WIDGET(button), (gchar*) &v4l_mrl, ppsz_options, i_options);
748 gboolean PlaylistEvent(GtkWidget *widget, GdkEvent *event, gpointer user_data)
754 void onPlaylistColumnsChanged(GtkTreeView *treeview, gpointer user_data)
759 gboolean onPlaylistRowSelected(GtkTreeView *treeview, gboolean start_editing, gpointer user_data)
765 void onPlaylistRow(GtkTreeView *treeview, GtkTreePath *path,
766 GtkTreeViewColumn *column, gpointer user_data)
768 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(treeview) );
769 GtkTreeSelection *p_selection = gtk_tree_view_get_selection(treeview);
770 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
773 if( p_playlist == NULL )
778 if (gtk_tree_selection_count_selected_rows(p_selection) == 1)
780 GtkTreeModel *p_model;
784 /* This might be a directory selection */
785 p_model = gtk_tree_view_get_model(treeview);
788 msg_Err(p_intf, "PDA: Playlist model contains a NULL pointer\n" );
791 if (!gtk_tree_model_get_iter(p_model, &iter, path))
793 msg_Err( p_intf, "PDA: Playlist could not get iter from model" );
797 gtk_tree_model_get(p_model, &iter, 2, &i_row, -1);
798 playlist_Goto( p_playlist, i_row );
800 vlc_object_release( p_playlist );
804 void onUpdatePlaylist(GtkButton *button, gpointer user_data)
806 intf_thread_t * p_intf = GtkGetIntf( button );
807 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
809 GtkTreeView *p_tvplaylist = NULL;
811 if( p_playlist == NULL )
816 p_tvplaylist = (GtkTreeView*) lookup_widget( GTK_WIDGET(button), "tvPlaylist");
819 GtkListStore *p_model = NULL;
821 /* Rebuild the playlist then. */
822 p_model = gtk_list_store_new (3,
823 G_TYPE_STRING, /* Filename */
824 G_TYPE_STRING, /* Time */
825 G_TYPE_UINT); /* Hidden field */
828 PlaylistRebuildListStore(p_model, p_playlist);
829 gtk_tree_view_set_model(GTK_TREE_VIEW(p_tvplaylist), GTK_TREE_MODEL(p_model));
830 g_object_unref(p_model);
833 vlc_object_release( p_playlist );
836 void deleteItemFromPlaylist(gpointer data, gpointer user_data)
838 gtk_tree_path_free((GtkTreePath*) data); // removing an item.
841 void onDeletePlaylist(GtkButton *button, gpointer user_data)
843 intf_thread_t *p_intf = GtkGetIntf( button );
844 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
846 GtkTreeView *p_tvplaylist;
848 /* Delete an arbitrary item from the playlist */
849 p_tvplaylist = (GtkTreeView *) lookup_widget( GTK_WIDGET(button), "tvPlaylist" );
850 if (p_tvplaylist != NULL)
852 GList *p_rows = NULL;
854 GtkTreeModel *p_model = NULL;
855 GtkListStore *p_store = NULL;
856 GtkTreeSelection *p_selection = gtk_tree_view_get_selection(p_tvplaylist);
858 p_model = gtk_tree_view_get_model(p_tvplaylist);
861 p_rows = gtk_tree_selection_get_selected_rows(p_selection, &p_model);
863 if( g_list_length( p_rows ) )
865 /* reverse-sort so that we can delete from the furthest
866 * to the closest item to delete...
868 p_rows = g_list_reverse( p_rows );
871 for (p_node=p_rows; p_node!=NULL; p_node = p_node->next)
874 GtkTreePath *p_path = NULL;
876 p_path = (GtkTreePath *)p_node->data;
879 if (gtk_tree_model_get_iter(p_model, &iter, p_path))
883 gtk_tree_model_get(p_model, &iter, 2, &item, -1);
884 msg_Err( p_playlist, "PDA delete broken");
889 g_list_foreach (p_rows, (GFunc*)gtk_tree_path_free, NULL);
890 #endif /* Testing the next line */
891 g_list_foreach (p_rows, deleteItemFromPlaylist, NULL);
892 g_list_free (p_rows);
895 /* Rebuild the playlist then. */
896 p_store = gtk_list_store_new (3,
897 G_TYPE_STRING, /* Filename */
898 G_TYPE_STRING, /* Time */
899 G_TYPE_UINT); /* Hidden field */
902 PlaylistRebuildListStore(p_store, p_playlist);
903 gtk_tree_view_set_model(GTK_TREE_VIEW(p_tvplaylist), GTK_TREE_MODEL(p_store));
904 g_object_unref(p_store);
907 vlc_object_release( p_playlist );
911 void onClearPlaylist(GtkButton *button, gpointer user_data)
913 intf_thread_t *p_intf = GtkGetIntf( button );
914 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
916 GtkTreeView *p_tvplaylist;
919 if( p_playlist == NULL )
924 for(item = p_playlist->i_size - 1; item >= 0 ;item-- )
926 msg_Err( p_playlist "fix pda delete");
928 vlc_object_release( p_playlist );
930 // Remove all entries from the Playlist widget.
931 p_tvplaylist = (GtkTreeView*) lookup_widget( GTK_WIDGET(button), "tvPlaylist");
934 GtkTreeModel *p_play_model;
936 p_play_model = gtk_tree_view_get_model(p_tvplaylist);
939 gtk_list_store_clear(GTK_LIST_STORE(p_play_model));
945 void onPreferenceSave(GtkButton *button, gpointer user_data)
948 intf_thread_t *p_intf = GtkGetIntf( button );
950 msg_Dbg(p_intf, "Preferences Save" );
951 config_SaveConfigFile( p_intf, NULL );
956 void onPreferenceApply(GtkButton *button, gpointer user_data)
959 intf_thread_t *p_intf = GtkGetIntf( button );
961 msg_Dbg(p_intf, "Preferences Apply" );
966 void onPreferenceCancel(GtkButton *button, gpointer user_data)
969 intf_thread_t *p_intf = GtkGetIntf( button );
971 msg_Dbg(p_intf, "Preferences Cancel" );
972 config_ResetAll( p_intf );
973 /* Cancel interface changes. */
974 config_SaveConfigFile( p_intf, NULL );
979 void onAddTranscodeToPlaylist(GtkButton *button, gpointer user_data)
981 intf_thread_t *p_intf = GtkGetIntf( button );
983 GtkEntry *p_entryVideoCodec = NULL;
984 GtkSpinButton *p_entryVideoBitrate = NULL;
985 GtkSpinButton *p_entryVideoBitrateTolerance = NULL;
986 GtkSpinButton *p_entryVideoKeyFrameInterval = NULL;
987 GtkCheckButton *p_checkVideoDeinterlace = NULL;
988 GtkEntry *p_entryAudioCodec = NULL;
989 GtkSpinButton *p_entryAudioBitrate = NULL;
990 const gchar *p_video_codec;
991 gint i_video_bitrate;
992 gint i_video_bitrate_tolerance;
993 gint i_video_keyframe_interval;
994 gboolean b_video_deinterlace;
995 const gchar *p_audio_codec;
996 gint i_audio_bitrate;
998 GtkEntry *p_entryStdAccess = NULL;
999 GtkEntry *p_entryStdMuxer = NULL;
1000 GtkEntry *p_entryStdURL = NULL;
1001 GtkEntry *p_entryStdAnnounce = NULL;
1002 GtkSpinButton *p_entryStdTTL = NULL;
1003 GtkCheckButton *p_checkSAP = NULL;
1004 GtkCheckButton *p_checkSLP = NULL;
1005 const gchar *p_std_announce;
1006 const gchar *p_std_access;
1007 const gchar *p_std_muxer;
1008 const gchar *p_std_url;
1009 gboolean b_sap_announce;
1010 gboolean b_slp_announce;
1013 char **ppsz_options = NULL; /* list of options */
1020 ppsz_options = (char **) malloc(3 *sizeof(char*));
1021 if (ppsz_options == NULL)
1023 msg_Err(p_intf, "No memory to allocate for v4l options.");
1028 ppsz_options[i] = (char *) malloc(VLC_MAX_MRL * sizeof(char));
1029 if (ppsz_options[i] == NULL)
1031 msg_Err(p_intf, "No memory to allocate for v4l options string %i.", i);
1032 for (i-=1; i>=0; i--)
1033 free(ppsz_options[i]);
1039 /* Update the playlist */
1040 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1041 if( p_playlist == NULL ) return;
1043 /* Get all the options. */
1044 i_pos = snprintf( &mrl[0], VLC_MAX_MRL, "sout");
1047 i_pos = snprintf( &ppsz_options[i_options][0], VLC_MAX_MRL, "sout='#transcode{");
1048 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1050 p_entryVideoCodec = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryVideoCodec" );
1051 p_entryVideoBitrate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoBitrate" );
1052 p_entryVideoBitrateTolerance = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoBitrateTolerance" );
1053 p_entryVideoKeyFrameInterval = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoKeyFrameInterval" );
1055 p_video_codec = gtk_entry_get_text(GTK_ENTRY(p_entryVideoCodec));
1056 i_video_bitrate = gtk_spin_button_get_value_as_int(p_entryVideoBitrate);
1057 i_video_bitrate_tolerance = gtk_spin_button_get_value_as_int(p_entryVideoBitrateTolerance);
1058 i_video_keyframe_interval = gtk_spin_button_get_value_as_int(p_entryVideoKeyFrameInterval);
1060 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "vcodec=%s,", (char*)p_video_codec );
1061 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1062 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "vb=%d,", (int)i_video_bitrate );
1063 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1064 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "vt=%d,", (int)i_video_bitrate_tolerance );
1065 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1066 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "keyint=%d,", (int)i_video_keyframe_interval );
1067 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1069 p_checkVideoDeinterlace = (GtkCheckButton*) lookup_widget( GTK_WIDGET(button), "checkVideoDeinterlace" );
1070 b_video_deinterlace = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_checkVideoDeinterlace));
1071 if (b_video_deinterlace)
1073 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "deinterlace," );
1074 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1076 p_entryAudioCodec = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryAudioCodec" );
1077 p_entryAudioBitrate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryAudioBitrate" );
1079 p_audio_codec = gtk_entry_get_text(GTK_ENTRY(p_entryAudioCodec));
1080 i_audio_bitrate = gtk_spin_button_get_value_as_int(p_entryAudioBitrate);
1082 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "acodec=%s,", (char*)p_audio_codec );
1083 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1084 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "ab=%d,", (int)i_audio_bitrate );
1085 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1086 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "channels=1}"/*, (int)i_audio_channels*/ );
1087 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1091 i_pos = snprintf( &ppsz_options[i_options++][i_pos], VLC_MAX_MRL - i_pos, "#" );
1092 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1094 p_entryStdAccess = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdAccess" );
1095 p_entryStdMuxer = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdMuxer" );
1096 p_entryStdURL = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdURL" );
1097 p_entryStdAnnounce = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryAnnounceChannel" );
1098 p_entryStdTTL = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryStdTTL" );
1100 p_std_access = gtk_entry_get_text(GTK_ENTRY(p_entryStdAccess));
1101 p_std_muxer = gtk_entry_get_text(GTK_ENTRY(p_entryStdMuxer));
1102 p_std_url = gtk_entry_get_text(GTK_ENTRY(p_entryStdURL));
1103 p_std_announce = gtk_entry_get_text(GTK_ENTRY(p_entryStdAnnounce));
1104 b_sap_announce = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_checkSAP));
1105 b_slp_announce = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_checkSLP));
1107 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "std{access=%s,", (char*)p_std_access);
1108 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1109 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "mux=%s,", (char*)p_std_muxer);
1110 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1111 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "dst=%s", (char*)p_std_url);
1112 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1114 if (strncasecmp( (const char*)p_std_access, "udp", 3)==0)
1118 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "sap=%s", (char*)p_std_announce);
1119 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1123 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "slp=%s", (char*)p_std_announce);
1124 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1128 i_std_ttl = gtk_spin_button_get_value_as_int(p_entryStdTTL);
1130 i_pos += snprintf( &ppsz_options[i_options++][i_pos], VLC_MAX_MRL - i_pos, "ttl=%d}", (int)i_std_ttl);
1131 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1133 if (user_data != NULL)
1135 msg_Dbg(p_intf, "Adding transcoding options to playlist item." );
1139 msg_Dbg(p_intf, "Adding --sout to playlist." );
1140 PlaylistAddItem(GTK_WIDGET(button), (gchar*) &mrl, ppsz_options, i_options);
1144 void onEntryStdAccessChanged(GtkEditable *editable, gpointer user_data)
1146 intf_thread_t *p_intf = GtkGetIntf( editable );
1148 GtkCheckButton *p_checkSAP = NULL;
1149 GtkCheckButton *p_checkSLP = NULL;
1150 GtkEntry *p_entryStdAccess = NULL;
1151 const gchar *p_std_access = NULL;
1152 gboolean b_announce = FALSE;
1154 p_entryStdAccess = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryStdAccess" );
1155 p_checkSAP = (GtkCheckButton*) lookup_widget( GTK_WIDGET(editable), "checkSAP" );
1156 p_checkSLP = (GtkCheckButton*) lookup_widget( GTK_WIDGET(editable), "checkSLP" );
1158 if ( (p_std_access == NULL) || (p_checkSAP == NULL) || (p_checkSLP == NULL))
1160 msg_Err( p_intf, "Access, SAP and SLP widgets not found." );
1163 p_std_access = gtk_entry_get_text(GTK_ENTRY(p_entryStdAccess));
1165 b_announce = (strncasecmp( (const char*)p_std_access, "udp", 3) == 0);
1166 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_checkSAP), b_announce);
1167 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_checkSLP), b_announce);