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 */
33 #include <vlc_common.h>
34 #include <vlc_input.h>
35 #include <vlc_interface.h>
36 #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 * __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 static 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 = pl_Yield( p_intf );
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, playlist_CurrentSize(p_playlist), /* 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 i_id = playlist_AddExt( p_playlist, (const char*)name,
137 PLAYLIST_APPEND, PLAYLIST_END,
139 (const char **) ppsz_options, i_pos,
144 for (i=0; i<i_size; i++)
145 free(ppsz_options[i]);
149 pl_Release( p_intf );
152 void PlaylistRebuildListStore( intf_thread_t *p_intf,
153 GtkListStore * p_list, playlist_t * p_playlist )
157 gchar * ppsz_text[2];
165 for( i_dummy = 0; i_dummy < playlist_CurrentSize(p_playlist) ; i_dummy++ )
167 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_dummy, pl_Locked );
170 ppsz_text[0] = p_item->p_input->psz_name;
171 ppsz_text[1] = "no info";
172 gtk_list_store_append (p_list, &iter);
173 gtk_list_store_set (p_list, &iter,
176 2, i_dummy, /* Hidden index */
183 /*****************************************************************
184 * Read directory helper function.
185 ****************************************************************/
186 void ReadDirectory(intf_thread_t *p_intf, GtkListStore *p_list, char *psz_dir )
189 struct dirent **pp_namelist;
195 msg_Dbg(p_intf, "Changing to dir %s", psz_dir);
198 status = chdir(psz_dir);
200 msg_Dbg(p_intf, "permision denied" );
202 n = scandir(".", &pp_namelist, 0, alphasort);
211 if (lstat("..", &st)==0)
214 p_pw = getpwuid(st.st_uid);
215 p_grp = getgrgid(st.st_gid);
217 /* XXX : kludge temporaire pour yopy */
219 ppsz_text[1] = get_file_perms(st);
220 ppsz_text[2] = p_pw->pw_name;
221 ppsz_text[3] = p_grp->gr_name;
223 /* Add a new row to the model */
224 gtk_list_store_append (p_list, &iter);
225 gtk_list_store_set (p_list, &iter,
238 if ((pp_namelist[i]->d_name[0] != '.') &&
239 (lstat(pp_namelist[i]->d_name, &st)==0))
242 p_pw = getpwuid(st.st_uid);
243 p_grp = getgrgid(st.st_gid);
245 /* This is a list of strings. */
246 ppsz_text[0] = pp_namelist[i]->d_name;
247 ppsz_text[1] = get_file_perms(st);
248 ppsz_text[2] = p_pw->pw_name;
249 ppsz_text[3] = p_grp->gr_name;
251 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] );
253 gtk_list_store_append (p_list, &iter);
254 gtk_list_store_set (p_list, &iter,
269 static char *get_file_perms(const struct stat st)
273 psz_perm = (char *) malloc(sizeof(char)*10);
274 strncpy( psz_perm, "----------", sizeof("----------"));
276 /* determine permission modes */
277 if (S_ISLNK(st.st_mode))
279 else if (S_ISDIR(st.st_mode))
281 else if (S_ISCHR(st.st_mode))
283 else if (S_ISBLK(st.st_mode))
285 else if (S_ISFIFO(st.st_mode))
287 else if (S_ISSOCK(st.st_mode))
289 else if (S_ISREG(st.st_mode))
291 else /* Unknown type is an error */
293 /* Get file permissions */
295 if (st.st_mode & S_IRUSR)
297 if (st.st_mode & S_IWUSR)
299 if (st.st_mode & S_IXUSR)
301 if (st.st_mode & S_ISUID)
306 else if (st.st_mode & S_ISUID)
309 if (st.st_mode & S_IRGRP)
311 if (st.st_mode & S_IWGRP)
313 if (st.st_mode & S_IXGRP)
315 if (st.st_mode & S_ISGID)
320 else if (st.st_mode & S_ISGID)
323 if (st.st_mode & S_IROTH)
325 if (st.st_mode & S_IWOTH)
327 if (st.st_mode & S_IXOTH)
330 if (st.st_mode &S_ISVTX)
335 else if (st.st_mode &S_ISVTX)
342 * Main interface callbacks
345 gboolean onPDADeleteEvent(GtkWidget *widget, GdkEvent *event, gpointer user_data)
347 intf_thread_t *p_intf = GtkGetIntf( widget );
349 vlc_mutex_lock( &p_intf->change_lock );
350 vlc_object_kill( p_intf->p_libvlc );
351 vlc_mutex_unlock( &p_intf->change_lock );
352 msg_Dbg( p_intf, "about to exit vlc ... signaled" );
357 void onRewind(GtkButton *button, gpointer user_data)
359 intf_thread_t *p_intf = GtkGetIntf( button );
361 if (p_intf->p_sys->p_input != NULL)
363 var_SetVoid( p_intf->p_sys->p_input, "rate-slower" );
367 void onPause(GtkButton *button, gpointer user_data)
369 intf_thread_t *p_intf = GtkGetIntf( button );
371 if (p_intf->p_sys->p_input != NULL)
373 var_SetInteger( p_intf->p_sys->p_input, "state", PAUSE_S );
378 void onPlay(GtkButton *button, gpointer user_data)
380 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) );
381 playlist_t *p_playlist = pl_Yield( p_intf );
388 s = playlist_CurrentSize(p_playlist);
390 /* FIXME: This is racy... */
393 playlist_Play( p_playlist );
394 gdk_window_lower( p_intf->p_sys->p_window->window );
396 pl_Release( p_intf );
400 void onStop(GtkButton *button, gpointer user_data)
402 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) );
403 playlist_t *p_playlist = pl_Yield( p_intf );
406 playlist_Stop( p_playlist );
407 pl_Release( p_intf );
408 gdk_window_raise( p_intf->p_sys->p_window->window );
412 void onForward(GtkButton *button, gpointer user_data)
414 intf_thread_t *p_intf = GtkGetIntf( button );
416 if (p_intf->p_sys->p_input != NULL)
418 var_SetVoid( p_intf->p_sys->p_input, "rate-faster" );
423 void onAbout(GtkButton *button, gpointer user_data)
425 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(button) );
427 /* Toggle notebook */
428 if (p_intf->p_sys->p_notebook)
430 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
431 gtk_notebook_set_page(p_intf->p_sys->p_notebook,6);
435 gboolean SliderRelease(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
437 intf_thread_t *p_intf = GtkGetIntf( widget );
439 msg_Dbg( p_intf, "SliderButton Release" );
440 vlc_mutex_lock( &p_intf->change_lock );
441 p_intf->p_sys->b_slider_free = 1;
442 vlc_mutex_unlock( &p_intf->change_lock );
447 gboolean SliderPress(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
449 intf_thread_t *p_intf = GtkGetIntf( widget );
451 msg_Dbg( p_intf, "SliderButton Press" );
452 vlc_mutex_lock( &p_intf->change_lock );
453 p_intf->p_sys->b_slider_free = 0;
454 vlc_mutex_unlock( &p_intf->change_lock );
459 void SliderMove(GtkRange *range, GtkScrollType scroll, gpointer user_data)
461 intf_thread_t *p_intf = GtkGetIntf( range );
462 msg_Dbg( p_intf, "SliderButton Move" );
466 static void addSelectedToPlaylist(GtkTreeModel *model, GtkTreePath *path,
467 GtkTreeIter *iter, gpointer *userdata)
471 gtk_tree_model_get(model, iter, 0, &psz_filename, -1);
473 PlaylistAddItem(GTK_WIDGET(userdata), psz_filename, 0, 0);
476 void onFileListRow(GtkTreeView *treeview, GtkTreePath *path,
477 GtkTreeViewColumn *column, gpointer user_data)
479 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(treeview) );
480 GtkTreeSelection *p_selection = gtk_tree_view_get_selection(treeview);
482 if (gtk_tree_selection_count_selected_rows(p_selection) == 1)
485 GtkTreeModel *p_model;
489 /* This might be a directory selection */
490 p_model = gtk_tree_view_get_model(treeview);
493 msg_Err(p_intf, "PDA: Filelist model contains a NULL pointer\n" );
496 if (!gtk_tree_model_get_iter(p_model, &iter, path))
498 msg_Err( p_intf, "PDA: Could not get iter from model" );
502 gtk_tree_model_get(p_model, &iter, 0, &psz_filename, -1);
503 if (stat((char*)psz_filename, &st)==0)
505 if (S_ISDIR(st.st_mode))
507 GtkListStore *p_store = NULL;
509 /* Get new directory listing */
510 p_store = gtk_list_store_new (5,
518 ReadDirectory(p_intf, p_store, psz_filename);
520 /* Update TreeView with new model */
521 gtk_tree_view_set_model(treeview, (GtkTreeModel*) p_store);
522 g_object_unref(p_store);
529 void onAddFileToPlaylist(GtkButton *button, gpointer user_data)
531 GtkTreeView *p_treeview = NULL;
533 p_treeview = (GtkTreeView *) lookup_widget( GTK_WIDGET(button), "tvFileList");
536 GtkTreeSelection *p_selection = gtk_tree_view_get_selection(p_treeview);
538 gtk_tree_selection_selected_foreach(p_selection, (GtkTreeSelectionForeachFunc) &addSelectedToPlaylist, (gpointer) p_treeview);
543 void NetworkBuildMRL(GtkEditable *editable, gpointer user_data)
545 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(editable) );
546 GtkSpinButton *p_networkPort = NULL;
547 GtkEntry *p_entryMRL = NULL;
548 GtkEntry *p_networkType = NULL;
549 GtkEntry *p_networkAddress = NULL;
550 GtkEntry *p_networkProtocol = NULL;
551 const gchar *psz_mrlNetworkType;
552 const gchar *psz_mrlAddress;
553 const gchar *psz_mrlProtocol;
555 char text[VLC_MAX_MRL];
558 p_entryMRL = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryMRL" );
560 p_networkType = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryNetworkType" );
561 p_networkAddress = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryNetworkAddress" );
562 p_networkPort = (GtkSpinButton*) lookup_widget( GTK_WIDGET(editable), "entryNetworkPort" );
563 p_networkProtocol = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryNetworkProtocolType" );
565 psz_mrlNetworkType = gtk_entry_get_text(GTK_ENTRY(p_networkType));
566 psz_mrlAddress = gtk_entry_get_text(GTK_ENTRY(p_networkAddress));
567 i_mrlPort = gtk_spin_button_get_value_as_int(p_networkPort);
568 psz_mrlProtocol = gtk_entry_get_text(GTK_ENTRY(p_networkProtocol));
570 /* Build MRL from parts ;-) */
571 i_pos = snprintf( &text[0], VLC_MAX_MRL, "%s://", (char*)psz_mrlProtocol);
572 if (strncasecmp( (char*)psz_mrlNetworkType, "multicast",9)==0)
574 i_pos += snprintf( &text[i_pos], VLC_MAX_MRL - i_pos, "@" );
576 i_pos += snprintf( &text[i_pos], VLC_MAX_MRL - i_pos, "%s:%d", (char*)psz_mrlAddress, (int)i_mrlPort );
578 if (i_pos >= VLC_MAX_MRL)
580 text[VLC_MAX_MRL-1]='\0';
581 msg_Err( p_intf, "Media Resource Locator is truncated to: %s", text);
584 gtk_entry_set_text(p_entryMRL,text);
587 void onAddNetworkPlaylist(GtkButton *button, gpointer user_data)
589 intf_thread_t *p_intf = GtkGetIntf( button );
591 GtkEntry *p_mrl = NULL;
592 GtkCheckButton *p_network_transcode = NULL;
593 gboolean b_network_transcode;
594 const gchar *psz_mrl_name;
596 p_mrl = (GtkEntry*) lookup_widget(GTK_WIDGET(button),"entryMRL" );
597 psz_mrl_name = gtk_entry_get_text(p_mrl);
599 p_network_transcode = (GtkCheckButton*) lookup_widget(GTK_WIDGET(button), "checkNetworkTranscode" );
600 b_network_transcode = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_network_transcode));
601 if (b_network_transcode)
603 msg_Dbg( p_intf, "Network transcode option selected." );
604 onAddTranscodeToPlaylist(button, (gchar *)psz_mrl_name);
608 msg_Dbg( p_intf, "Network receiving selected." );
609 PlaylistAddItem(GTK_WIDGET(button), (gchar *)psz_mrl_name, 0, 0);
614 void onAddCameraToPlaylist(GtkButton *button, gpointer user_data)
616 intf_thread_t *p_intf = GtkGetIntf( button );
618 GtkSpinButton *entryV4LChannel = NULL;
619 GtkSpinButton *entryV4LFrequency = NULL;
620 GtkSpinButton *entryV4LSampleRate = NULL;
621 GtkSpinButton *entryV4LQuality = NULL;
622 GtkSpinButton *entryV4LTuner = NULL;
624 gint i_v4l_frequency;
625 gint i_v4l_samplerate;
629 GtkEntry *entryV4LVideoDevice = NULL;
630 GtkEntry *entryV4LAudioDevice = NULL;
631 GtkEntry *entryV4LNorm = NULL;
632 GtkEntry *entryV4LSize = NULL;
633 GtkEntry *entryV4LSoundDirection = NULL;
634 const gchar *p_v4l_video_device;
635 const gchar *p_v4l_audio_device;
636 const gchar *p_v4l_norm;
637 const gchar *p_v4l_size;
638 const gchar *p_v4l_sound_direction;
641 GtkCheckButton *checkV4LMJPEG = NULL;
642 GtkSpinButton *entryV4LDecimation = NULL;
643 gboolean b_v4l_mjpeg;
644 gint i_v4l_decimation;
647 GtkCheckButton *p_check_v4l_transcode = NULL;
648 gboolean b_v4l_transcode;
650 char **ppsz_options = NULL; /* list of options */
656 ppsz_options = (char **) malloc(11 *sizeof(char*));
657 if (ppsz_options == NULL)
659 msg_Err(p_intf, "No memory to allocate for v4l options.");
664 ppsz_options[i] = (char *) malloc(VLC_MAX_MRL * sizeof(char));
665 if (ppsz_options[i] == NULL)
667 msg_Err(p_intf, "No memory to allocate for v4l options string %i.", i);
668 for (i-=1; i>=0; i--)
669 free(ppsz_options[i]);
675 i_pos = snprintf( &v4l_mrl[0], 6, "v4l");
678 entryV4LChannel = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LChannel" );
679 entryV4LFrequency = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LFrequency" );
680 entryV4LSampleRate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LSampleRate" );
681 entryV4LQuality = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LQuality" );
682 entryV4LTuner = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LTuner" );
684 entryV4LVideoDevice = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LVideoDevice" );
685 entryV4LAudioDevice = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LAudioDevice" );
686 entryV4LNorm = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LNorm" );
687 entryV4LSize = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LSize" );
688 entryV4LSoundDirection = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LSoundDirection" );
690 i_v4l_channel = gtk_spin_button_get_value_as_int(entryV4LChannel);
691 i_v4l_frequency = gtk_spin_button_get_value_as_int(entryV4LFrequency);
692 i_v4l_samplerate = gtk_spin_button_get_value_as_int(entryV4LSampleRate);
693 i_v4l_quality = gtk_spin_button_get_value_as_int(entryV4LQuality);
694 i_v4l_tuner = gtk_spin_button_get_value_as_int(entryV4LTuner);
696 p_v4l_video_device = gtk_entry_get_text(GTK_ENTRY(entryV4LVideoDevice));
697 p_v4l_audio_device = gtk_entry_get_text(GTK_ENTRY(entryV4LAudioDevice));
698 p_v4l_norm = gtk_entry_get_text(GTK_ENTRY(entryV4LNorm));
699 p_v4l_size = gtk_entry_get_text(GTK_ENTRY(entryV4LSize));
700 p_v4l_sound_direction = gtk_entry_get_text(GTK_ENTRY(entryV4LSoundDirection));
702 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "%s", (char*)p_v4l_video_device );
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, "adev=%s", (char*)p_v4l_audio_device );
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, "norm=%s", (char*)p_v4l_norm );
707 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
708 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "size=%s", (char*)p_v4l_size );
709 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
710 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "%s", (char*)p_v4l_sound_direction );
711 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, "channel=%d", (int)i_v4l_channel );
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, "frequency=%d", (int)i_v4l_frequency );
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, "samplerate=%d", (int)i_v4l_samplerate );
718 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
719 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "quality=%d", (int)i_v4l_quality );
720 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
721 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "tuner=%d", (int)i_v4l_tuner );
722 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
725 checkV4LMJPEG = (GtkCheckButton*) lookup_widget( GTK_WIDGET(button), "checkV4LMJPEG" );
726 b_v4l_mjpeg = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkV4LMJPEG));
729 entryV4LDecimation = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LDecimation" );
730 i_v4l_decimation = gtk_spin_button_get_value_as_int(entryV4LDecimation);
732 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "mjpeg:%d", (int)i_v4l_decimation );
733 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
737 p_check_v4l_transcode = (GtkCheckButton*) lookup_widget(GTK_WIDGET(button), "checkV4LTranscode" );
738 b_v4l_transcode = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_check_v4l_transcode));
741 msg_Dbg( p_intf, "Camera transcode option selected." );
742 onAddTranscodeToPlaylist(button, (gchar *)v4l_mrl);
746 msg_Dbg( p_intf, "Camera reception option selected." );
747 PlaylistAddItem(GTK_WIDGET(button), (gchar*) &v4l_mrl, ppsz_options, i_options);
752 gboolean PlaylistEvent(GtkWidget *widget, GdkEvent *event, gpointer user_data)
758 void onPlaylistColumnsChanged(GtkTreeView *treeview, gpointer user_data)
763 gboolean onPlaylistRowSelected(GtkTreeView *treeview, gboolean start_editing, gpointer user_data)
769 void onPlaylistRow(GtkTreeView *treeview, GtkTreePath *path,
770 GtkTreeViewColumn *column, gpointer user_data)
772 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(treeview) );
773 GtkTreeSelection *p_selection = gtk_tree_view_get_selection(treeview);
774 playlist_t * p_playlist = pl_Yield( p_intf );
776 if( p_playlist == NULL )
781 if (gtk_tree_selection_count_selected_rows(p_selection) == 1)
783 GtkTreeModel *p_model;
788 /* This might be a directory selection */
789 p_model = gtk_tree_view_get_model(treeview);
792 msg_Err(p_intf, "PDA: Playlist model contains a NULL pointer\n" );
795 if (!gtk_tree_model_get_iter(p_model, &iter, path))
797 msg_Err( p_intf, "PDA: Playlist could not get iter from model" );
801 gtk_tree_model_get(p_model, &iter, 2, &i_row, -1);
802 i_skip = i_row - p_playlist->i_current_index;
803 playlist_Skip( p_playlist, i_skip );
805 pl_Release( p_intf );
809 void onUpdatePlaylist(GtkButton *button, gpointer user_data)
811 intf_thread_t * p_intf = GtkGetIntf( button );
812 playlist_t * p_playlist = pl_Yield( p_intf );
813 GtkTreeView *p_tvplaylist = NULL;
815 if( p_playlist == NULL )
820 p_tvplaylist = (GtkTreeView*) lookup_widget( GTK_WIDGET(button), "tvPlaylist");
823 GtkListStore *p_model = NULL;
825 /* Rebuild the playlist then. */
826 p_model = gtk_list_store_new (3,
827 G_TYPE_STRING, /* Filename */
828 G_TYPE_STRING, /* Time */
829 G_TYPE_UINT); /* Hidden field */
832 PlaylistRebuildListStore(p_intf, p_model, p_playlist);
833 gtk_tree_view_set_model(GTK_TREE_VIEW(p_tvplaylist), GTK_TREE_MODEL(p_model));
834 g_object_unref(p_model);
837 pl_Release( p_intf );
840 static void deleteItemFromPlaylist(gpointer data, gpointer user_data)
842 gtk_tree_path_free((GtkTreePath*) data); // removing an item.
845 void onDeletePlaylist(GtkButton *button, gpointer user_data)
847 intf_thread_t *p_intf = GtkGetIntf( button );
848 playlist_t * p_playlist = pl_Yield( p_intf );
849 GtkTreeView *p_tvplaylist;
851 /* Delete an arbitrary item from the playlist */
852 p_tvplaylist = (GtkTreeView *) lookup_widget( GTK_WIDGET(button), "tvPlaylist" );
853 if (p_tvplaylist != NULL)
855 GList *p_rows = NULL;
857 GtkTreeModel *p_model = NULL;
858 GtkListStore *p_store = NULL;
859 GtkTreeSelection *p_selection = gtk_tree_view_get_selection(p_tvplaylist);
861 p_model = gtk_tree_view_get_model(p_tvplaylist);
864 p_rows = gtk_tree_selection_get_selected_rows(p_selection, &p_model);
866 if( g_list_length( p_rows ) )
868 /* reverse-sort so that we can delete from the furthest
869 * to the closest item to delete...
871 p_rows = g_list_reverse( p_rows );
874 for (p_node=p_rows; p_node!=NULL; p_node = p_node->next)
877 GtkTreePath *p_path = NULL;
879 p_path = (GtkTreePath *)p_node->data;
882 if (gtk_tree_model_get_iter(p_model, &iter, p_path))
886 gtk_tree_model_get(p_model, &iter, 2, &item, -1);
887 msg_Err( p_playlist, "PDA delete broken");
892 g_list_foreach (p_rows, (GFunc*)gtk_tree_path_free, NULL);
893 #endif /* Testing the next line */
894 g_list_foreach (p_rows, deleteItemFromPlaylist, NULL);
895 g_list_free (p_rows);
898 /* Rebuild the playlist then. */
899 p_store = gtk_list_store_new (3,
900 G_TYPE_STRING, /* Filename */
901 G_TYPE_STRING, /* Time */
902 G_TYPE_UINT); /* Hidden field */
905 PlaylistRebuildListStore(p_intf, p_store, p_playlist);
906 gtk_tree_view_set_model(GTK_TREE_VIEW(p_tvplaylist), GTK_TREE_MODEL(p_store));
907 g_object_unref(p_store);
910 pl_Release( p_intf );
914 void onClearPlaylist(GtkButton *button, gpointer user_data)
916 intf_thread_t *p_intf = GtkGetIntf( button );
917 playlist_t * p_playlist = pl_Yield( p_intf );
918 GtkTreeView *p_tvplaylist;
921 if( p_playlist == NULL )
926 for(item = playlist_CurrentSize(p_playlist) - 1; item >= 0 ;item-- )
928 msg_Err( p_playlist, "fix pda delete" );
930 pl_Release( p_intf );
932 // Remove all entries from the Playlist widget.
933 p_tvplaylist = (GtkTreeView*) lookup_widget( GTK_WIDGET(button), "tvPlaylist");
936 GtkTreeModel *p_play_model;
938 p_play_model = gtk_tree_view_get_model(p_tvplaylist);
941 gtk_list_store_clear(GTK_LIST_STORE(p_play_model));
947 void onPreferenceSave(GtkButton *button, gpointer user_data)
950 intf_thread_t *p_intf = GtkGetIntf( button );
952 msg_Dbg(p_intf, "Preferences Save" );
953 config_SaveConfigFile( p_intf, NULL );
958 void onPreferenceApply(GtkButton *button, gpointer user_data)
961 intf_thread_t *p_intf = GtkGetIntf( button );
963 msg_Dbg(p_intf, "Preferences Apply" );
968 void onPreferenceCancel(GtkButton *button, gpointer user_data)
971 intf_thread_t *p_intf = GtkGetIntf( button );
973 msg_Dbg(p_intf, "Preferences Cancel" );
974 config_ResetAll( p_intf );
975 /* Cancel interface changes. */
976 config_SaveConfigFile( p_intf, NULL );
981 void onAddTranscodeToPlaylist(GtkButton *button, gpointer user_data)
983 intf_thread_t *p_intf = GtkGetIntf( button );
985 GtkEntry *p_entryVideoCodec = NULL;
986 GtkSpinButton *p_entryVideoBitrate = NULL;
987 GtkSpinButton *p_entryVideoBitrateTolerance = NULL;
988 GtkSpinButton *p_entryVideoKeyFrameInterval = NULL;
989 GtkCheckButton *p_checkVideoDeinterlace = NULL;
990 GtkEntry *p_entryAudioCodec = NULL;
991 GtkSpinButton *p_entryAudioBitrate = NULL;
992 const gchar *p_video_codec;
993 gint i_video_bitrate;
994 gint i_video_bitrate_tolerance;
995 gint i_video_keyframe_interval;
996 gboolean b_video_deinterlace;
997 const gchar *p_audio_codec;
998 gint i_audio_bitrate;
1000 GtkEntry *p_entryStdAccess = NULL;
1001 GtkEntry *p_entryStdMuxer = NULL;
1002 GtkEntry *p_entryStdURL = NULL;
1003 GtkEntry *p_entryStdAnnounce = NULL;
1004 GtkSpinButton *p_entryStdTTL = NULL;
1005 GtkCheckButton *p_checkSAP = NULL;
1006 GtkCheckButton *p_checkSLP = NULL;
1007 const gchar *p_std_announce;
1008 const gchar *p_std_access;
1009 const gchar *p_std_muxer;
1010 const gchar *p_std_url;
1011 gboolean b_sap_announce;
1012 gboolean b_slp_announce;
1015 char **ppsz_options = NULL; /* list of options */
1022 ppsz_options = (char **) malloc(3 *sizeof(char*));
1023 if (ppsz_options == NULL)
1025 msg_Err(p_intf, "No memory to allocate for v4l options.");
1030 ppsz_options[i] = (char *) malloc(VLC_MAX_MRL * sizeof(char));
1031 if (ppsz_options[i] == NULL)
1033 msg_Err(p_intf, "No memory to allocate for v4l options string %i.", i);
1034 for (i-=1; i>=0; i--)
1035 free(ppsz_options[i]);
1041 /* Update the playlist */
1042 playlist_t *p_playlist = pl_Yield( p_intf );
1043 if( p_playlist == NULL ) return;
1045 /* Get all the options. */
1046 i_pos = snprintf( &mrl[0], VLC_MAX_MRL, "sout");
1049 i_pos = snprintf( &ppsz_options[i_options][0], VLC_MAX_MRL, "sout='#transcode{");
1050 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1052 p_entryVideoCodec = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryVideoCodec" );
1053 p_entryVideoBitrate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoBitrate" );
1054 p_entryVideoBitrateTolerance = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoBitrateTolerance" );
1055 p_entryVideoKeyFrameInterval = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoKeyFrameInterval" );
1057 p_video_codec = gtk_entry_get_text(GTK_ENTRY(p_entryVideoCodec));
1058 i_video_bitrate = gtk_spin_button_get_value_as_int(p_entryVideoBitrate);
1059 i_video_bitrate_tolerance = gtk_spin_button_get_value_as_int(p_entryVideoBitrateTolerance);
1060 i_video_keyframe_interval = gtk_spin_button_get_value_as_int(p_entryVideoKeyFrameInterval);
1062 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "vcodec=%s,", (char*)p_video_codec );
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, "vb=%d,", (int)i_video_bitrate );
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, "vt=%d,", (int)i_video_bitrate_tolerance );
1067 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1068 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "keyint=%d,", (int)i_video_keyframe_interval );
1069 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1071 p_checkVideoDeinterlace = (GtkCheckButton*) lookup_widget( GTK_WIDGET(button), "checkVideoDeinterlace" );
1072 b_video_deinterlace = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_checkVideoDeinterlace));
1073 if (b_video_deinterlace)
1075 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "deinterlace," );
1076 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1078 p_entryAudioCodec = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryAudioCodec" );
1079 p_entryAudioBitrate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryAudioBitrate" );
1081 p_audio_codec = gtk_entry_get_text(GTK_ENTRY(p_entryAudioCodec));
1082 i_audio_bitrate = gtk_spin_button_get_value_as_int(p_entryAudioBitrate);
1084 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "acodec=%s,", (char*)p_audio_codec );
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, "ab=%d,", (int)i_audio_bitrate );
1087 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1088 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "channels=1}"/*, (int)i_audio_channels*/ );
1089 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1093 i_pos = snprintf( &ppsz_options[i_options++][i_pos], VLC_MAX_MRL - i_pos, "#" );
1094 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1096 p_entryStdAccess = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdAccess" );
1097 p_entryStdMuxer = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdMuxer" );
1098 p_entryStdURL = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdURL" );
1099 p_entryStdAnnounce = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryAnnounceChannel" );
1100 p_entryStdTTL = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryStdTTL" );
1102 p_std_access = gtk_entry_get_text(GTK_ENTRY(p_entryStdAccess));
1103 p_std_muxer = gtk_entry_get_text(GTK_ENTRY(p_entryStdMuxer));
1104 p_std_url = gtk_entry_get_text(GTK_ENTRY(p_entryStdURL));
1105 p_std_announce = gtk_entry_get_text(GTK_ENTRY(p_entryStdAnnounce));
1106 b_sap_announce = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_checkSAP));
1107 b_slp_announce = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_checkSLP));
1109 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "std{access=%s,", (char*)p_std_access);
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, "mux=%s,", (char*)p_std_muxer);
1112 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1113 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "dst=%s", (char*)p_std_url);
1114 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1116 if (strncasecmp( (const char*)p_std_access, "udp", 3)==0)
1120 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "sap=%s", (char*)p_std_announce);
1121 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1125 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "slp=%s", (char*)p_std_announce);
1126 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1130 i_std_ttl = gtk_spin_button_get_value_as_int(p_entryStdTTL);
1132 i_pos += snprintf( &ppsz_options[i_options++][i_pos], VLC_MAX_MRL - i_pos, "ttl=%d}", (int)i_std_ttl);
1133 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1135 if (user_data != NULL)
1137 msg_Dbg(p_intf, "Adding transcoding options to playlist item." );
1141 msg_Dbg(p_intf, "Adding --sout to playlist." );
1142 PlaylistAddItem(GTK_WIDGET(button), (gchar*) &mrl, ppsz_options, i_options);
1146 void onEntryStdAccessChanged(GtkEditable *editable, gpointer user_data)
1148 intf_thread_t *p_intf = GtkGetIntf( editable );
1150 GtkCheckButton *p_checkSAP = NULL;
1151 GtkCheckButton *p_checkSLP = NULL;
1152 GtkEntry *p_entryStdAccess = NULL;
1153 const gchar *p_std_access = NULL;
1154 gboolean b_announce = FALSE;
1156 p_entryStdAccess = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryStdAccess" );
1157 p_checkSAP = (GtkCheckButton*) lookup_widget( GTK_WIDGET(editable), "checkSAP" );
1158 p_checkSLP = (GtkCheckButton*) lookup_widget( GTK_WIDGET(editable), "checkSLP" );
1160 if ( (p_std_access == NULL) || (p_checkSAP == NULL) || (p_checkSLP == NULL))
1162 msg_Err( p_intf, "Access, SAP and SLP widgets not found." );
1165 p_std_access = gtk_entry_get_text(GTK_ENTRY(p_entryStdAccess));
1167 b_announce = (strncasecmp( (const char*)p_std_access, "udp", 3) == 0);
1168 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_checkSAP), b_announce);
1169 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_checkSLP), b_announce);