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@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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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;
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 p_intf->p_vlc->b_die = VLC_TRUE;
346 vlc_mutex_unlock( &p_intf->change_lock );
347 msg_Dbg( p_intf, "about to exit vlc ... signaled" );
353 void onRewind(GtkButton *button, gpointer user_data)
355 intf_thread_t *p_intf = GtkGetIntf( button );
357 if (p_intf->p_sys->p_input != NULL)
359 var_SetVoid( p_intf->p_sys->p_input, "rate-slower" );
364 void onPause(GtkButton *button, gpointer user_data)
366 intf_thread_t *p_intf = GtkGetIntf( button );
368 if (p_intf->p_sys->p_input != NULL)
370 var_SetInteger( p_intf->p_sys->p_input, "state", PAUSE_S );
375 void onPlay(GtkButton *button, gpointer user_data)
377 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) );
378 playlist_t *p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
382 vlc_mutex_lock( &p_playlist->object_lock );
383 if (p_playlist->i_size)
385 vlc_mutex_unlock( &p_playlist->object_lock );
386 playlist_Play( p_playlist );
387 gdk_window_lower( p_intf->p_sys->p_window->window );
391 vlc_mutex_unlock( &p_playlist->object_lock );
393 vlc_object_release( p_playlist );
398 void onStop(GtkButton *button, gpointer user_data)
400 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) );
401 playlist_t *p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
405 playlist_Stop( p_playlist );
406 vlc_object_release( p_playlist );
407 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);
436 gboolean SliderRelease(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
438 intf_thread_t *p_intf = GtkGetIntf( widget );
440 msg_Dbg( p_intf, "SliderButton Release" );
441 vlc_mutex_lock( &p_intf->change_lock );
442 p_intf->p_sys->b_slider_free = 1;
443 vlc_mutex_unlock( &p_intf->change_lock );
449 gboolean SliderPress(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
451 intf_thread_t *p_intf = GtkGetIntf( widget );
453 msg_Dbg( p_intf, "SliderButton Press" );
454 vlc_mutex_lock( &p_intf->change_lock );
455 p_intf->p_sys->b_slider_free = 0;
456 vlc_mutex_unlock( &p_intf->change_lock );
461 void SliderMove(GtkRange *range, GtkScrollType scroll, gpointer user_data)
463 intf_thread_t *p_intf = GtkGetIntf( range );
464 msg_Dbg( p_intf, "SliderButton Move" );
468 void addSelectedToPlaylist(GtkTreeModel *model, GtkTreePath *path,
469 GtkTreeIter *iter, gpointer *userdata)
473 gtk_tree_model_get(model, iter, 0, &psz_filename, -1);
475 PlaylistAddItem(GTK_WIDGET(userdata), psz_filename, 0, 0);
478 void onFileListRow(GtkTreeView *treeview, GtkTreePath *path,
479 GtkTreeViewColumn *column, gpointer user_data)
481 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(treeview) );
482 GtkTreeSelection *p_selection = gtk_tree_view_get_selection(treeview);
484 if (gtk_tree_selection_count_selected_rows(p_selection) == 1)
487 GtkTreeModel *p_model;
491 /* This might be a directory selection */
492 p_model = gtk_tree_view_get_model(treeview);
495 msg_Err(p_intf, "PDA: Filelist model contains a NULL pointer\n" );
498 if (!gtk_tree_model_get_iter(p_model, &iter, path))
500 msg_Err( p_intf, "PDA: Could not get iter from model" );
504 gtk_tree_model_get(p_model, &iter, 0, &psz_filename, -1);
505 if (stat((char*)psz_filename, &st)==0)
507 if (S_ISDIR(st.st_mode))
509 GtkListStore *p_store = NULL;
511 /* Get new directory listing */
512 p_store = gtk_list_store_new (5,
520 ReadDirectory(p_intf, p_store, psz_filename);
522 /* Update TreeView with new model */
523 gtk_tree_view_set_model(treeview, (GtkTreeModel*) p_store);
524 g_object_unref(p_store);
531 void onAddFileToPlaylist(GtkButton *button, gpointer user_data)
533 GtkTreeView *p_treeview = NULL;
535 p_treeview = (GtkTreeView *) lookup_widget( GTK_WIDGET(button), "tvFileList");
538 GtkTreeSelection *p_selection = gtk_tree_view_get_selection(p_treeview);
540 gtk_tree_selection_selected_foreach(p_selection, (GtkTreeSelectionForeachFunc) &addSelectedToPlaylist, (gpointer) p_treeview);
545 void NetworkBuildMRL(GtkEditable *editable, gpointer user_data)
547 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(editable) );
548 GtkSpinButton *p_networkPort = NULL;
549 GtkEntry *p_entryMRL = NULL;
550 GtkEntry *p_networkType = NULL;
551 GtkEntry *p_networkAddress = NULL;
552 GtkEntry *p_networkProtocol = NULL;
553 const gchar *psz_mrlNetworkType;
554 const gchar *psz_mrlAddress;
555 const gchar *psz_mrlProtocol;
557 char text[VLC_MAX_MRL];
560 p_entryMRL = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryMRL" );
562 p_networkType = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryNetworkType" );
563 p_networkAddress = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryNetworkAddress" );
564 p_networkPort = (GtkSpinButton*) lookup_widget( GTK_WIDGET(editable), "entryNetworkPort" );
565 p_networkProtocol = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryNetworkProtocolType" );
567 psz_mrlNetworkType = gtk_entry_get_text(GTK_ENTRY(p_networkType));
568 psz_mrlAddress = gtk_entry_get_text(GTK_ENTRY(p_networkAddress));
569 i_mrlPort = gtk_spin_button_get_value_as_int(p_networkPort);
570 psz_mrlProtocol = gtk_entry_get_text(GTK_ENTRY(p_networkProtocol));
572 /* Build MRL from parts ;-) */
573 i_pos = snprintf( &text[0], VLC_MAX_MRL, "%s://", (char*)psz_mrlProtocol);
574 if (strncasecmp( (char*)psz_mrlNetworkType, "multicast",9)==0)
576 i_pos += snprintf( &text[i_pos], VLC_MAX_MRL - i_pos, "@" );
578 i_pos += snprintf( &text[i_pos], VLC_MAX_MRL - i_pos, "%s:%d", (char*)psz_mrlAddress, (int)i_mrlPort );
580 if (i_pos >= VLC_MAX_MRL)
582 text[VLC_MAX_MRL-1]='\0';
583 msg_Err( p_intf, "Media Resource Locator is truncated to: %s", text);
586 gtk_entry_set_text(p_entryMRL,text);
589 void onAddNetworkPlaylist(GtkButton *button, gpointer user_data)
591 intf_thread_t *p_intf = GtkGetIntf( button );
593 GtkEntry *p_mrl = NULL;
594 GtkCheckButton *p_network_transcode = NULL;
595 gboolean b_network_transcode;
596 const gchar *psz_mrl_name;
598 p_mrl = (GtkEntry*) lookup_widget(GTK_WIDGET(button),"entryMRL" );
599 psz_mrl_name = gtk_entry_get_text(p_mrl);
601 p_network_transcode = (GtkCheckButton*) lookup_widget(GTK_WIDGET(button), "checkNetworkTranscode" );
602 b_network_transcode = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_network_transcode));
603 if (b_network_transcode)
605 msg_Dbg( p_intf, "Network transcode option selected." );
606 onAddTranscodeToPlaylist(GTK_WIDGET(button), (gchar *)psz_mrl_name);
610 msg_Dbg( p_intf, "Network receiving selected." );
611 PlaylistAddItem(GTK_WIDGET(button), (gchar *)psz_mrl_name, 0, 0);
616 void onAddCameraToPlaylist(GtkButton *button, gpointer user_data)
618 intf_thread_t *p_intf = GtkGetIntf( button );
620 GtkSpinButton *entryV4LChannel = NULL;
621 GtkSpinButton *entryV4LFrequency = NULL;
622 GtkSpinButton *entryV4LSampleRate = NULL;
623 GtkSpinButton *entryV4LQuality = NULL;
624 GtkSpinButton *entryV4LTuner = NULL;
626 gint i_v4l_frequency;
627 gint i_v4l_samplerate;
631 GtkEntry *entryV4LVideoDevice = NULL;
632 GtkEntry *entryV4LAudioDevice = NULL;
633 GtkEntry *entryV4LNorm = NULL;
634 GtkEntry *entryV4LSize = NULL;
635 GtkEntry *entryV4LSoundDirection = NULL;
636 const gchar *p_v4l_video_device;
637 const gchar *p_v4l_audio_device;
638 const gchar *p_v4l_norm;
639 const gchar *p_v4l_size;
640 const gchar *p_v4l_sound_direction;
643 GtkCheckButton *checkV4LMJPEG = NULL;
644 GtkSpinButton *entryV4LDecimation = NULL;
645 gboolean b_v4l_mjpeg;
646 gint i_v4l_decimation;
649 GtkCheckButton *p_check_v4l_transcode = NULL;
650 gboolean b_v4l_transcode;
652 char **ppsz_options = NULL; /* list of options */
658 ppsz_options = (char **) malloc(11 *sizeof(char*));
659 if (ppsz_options == NULL)
661 msg_Err(p_intf, "No memory to allocate for v4l options.");
666 ppsz_options[i] = (char *) malloc(VLC_MAX_MRL * sizeof(char));
667 if (ppsz_options[i] == NULL)
669 msg_Err(p_intf, "No memory to allocate for v4l options string %i.", i);
670 for (i-=1; i>=0; i--)
671 free(ppsz_options[i]);
677 i_pos = snprintf( &v4l_mrl[0], 6, "v4l");
680 entryV4LChannel = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LChannel" );
681 entryV4LFrequency = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LFrequency" );
682 entryV4LSampleRate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LSampleRate" );
683 entryV4LQuality = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LQuality" );
684 entryV4LTuner = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LTuner" );
686 entryV4LVideoDevice = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LVideoDevice" );
687 entryV4LAudioDevice = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LAudioDevice" );
688 entryV4LNorm = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LNorm" );
689 entryV4LSize = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LSize" );
690 entryV4LSoundDirection = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LSoundDirection" );
692 i_v4l_channel = gtk_spin_button_get_value_as_int(entryV4LChannel);
693 i_v4l_frequency = gtk_spin_button_get_value_as_int(entryV4LFrequency);
694 i_v4l_samplerate = gtk_spin_button_get_value_as_int(entryV4LSampleRate);
695 i_v4l_quality = gtk_spin_button_get_value_as_int(entryV4LQuality);
696 i_v4l_tuner = gtk_spin_button_get_value_as_int(entryV4LTuner);
698 p_v4l_video_device = gtk_entry_get_text(GTK_ENTRY(entryV4LVideoDevice));
699 p_v4l_audio_device = gtk_entry_get_text(GTK_ENTRY(entryV4LAudioDevice));
700 p_v4l_norm = gtk_entry_get_text(GTK_ENTRY(entryV4LNorm));
701 p_v4l_size = gtk_entry_get_text(GTK_ENTRY(entryV4LSize));
702 p_v4l_sound_direction = gtk_entry_get_text(GTK_ENTRY(entryV4LSoundDirection));
704 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "%s", (char*)p_v4l_video_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, "adev=%s", (char*)p_v4l_audio_device );
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, "norm=%s", (char*)p_v4l_norm );
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, "size=%s", (char*)p_v4l_size );
711 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
712 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "%s", (char*)p_v4l_sound_direction );
713 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, "channel=%d", (int)i_v4l_channel );
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, "frequency=%d", (int)i_v4l_frequency );
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, "samplerate=%d", (int)i_v4l_samplerate );
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, "quality=%d", (int)i_v4l_quality );
722 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
723 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "tuner=%d", (int)i_v4l_tuner );
724 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
727 checkV4LMJPEG = (GtkCheckButton*) lookup_widget( GTK_WIDGET(button), "checkV4LMJPEG" );
728 b_v4l_mjpeg = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkV4LMJPEG));
731 entryV4LDecimation = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LDecimation" );
732 i_v4l_decimation = gtk_spin_button_get_value_as_int(entryV4LDecimation);
734 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "mjpeg:%d", (int)i_v4l_decimation );
735 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
739 p_check_v4l_transcode = (GtkCheckButton*) lookup_widget(GTK_WIDGET(button), "checkV4LTranscode" );
740 b_v4l_transcode = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_check_v4l_transcode));
743 msg_Dbg( p_intf, "Camera transcode option selected." );
744 onAddTranscodeToPlaylist(GTK_WIDGET(button), (gchar *)v4l_mrl);
748 msg_Dbg( p_intf, "Camera reception option selected." );
749 PlaylistAddItem(GTK_WIDGET(button), (gchar*) &v4l_mrl, ppsz_options, i_options);
754 gboolean PlaylistEvent(GtkWidget *widget, GdkEvent *event, gpointer user_data)
760 void onPlaylistColumnsChanged(GtkTreeView *treeview, gpointer user_data)
765 gboolean onPlaylistRowSelected(GtkTreeView *treeview, gboolean start_editing, gpointer user_data)
771 void onPlaylistRow(GtkTreeView *treeview, GtkTreePath *path,
772 GtkTreeViewColumn *column, gpointer user_data)
774 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(treeview) );
775 GtkTreeSelection *p_selection = gtk_tree_view_get_selection(treeview);
776 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
779 if( p_playlist == NULL )
784 if (gtk_tree_selection_count_selected_rows(p_selection) == 1)
786 GtkTreeModel *p_model;
790 /* This might be a directory selection */
791 p_model = gtk_tree_view_get_model(treeview);
794 msg_Err(p_intf, "PDA: Playlist model contains a NULL pointer\n" );
797 if (!gtk_tree_model_get_iter(p_model, &iter, path))
799 msg_Err( p_intf, "PDA: Playlist could not get iter from model" );
803 gtk_tree_model_get(p_model, &iter, 2, &i_row, -1);
804 playlist_Goto( p_playlist, i_row );
806 vlc_object_release( p_playlist );
810 void onUpdatePlaylist(GtkButton *button, gpointer user_data)
812 intf_thread_t * p_intf = GtkGetIntf( button );
813 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
815 GtkTreeView *p_tvplaylist = NULL;
817 if( p_playlist == NULL )
822 p_tvplaylist = (GtkTreeView*) lookup_widget( GTK_WIDGET(button), "tvPlaylist");
825 GtkListStore *p_model = NULL;
827 /* Rebuild the playlist then. */
828 p_model = gtk_list_store_new (3,
829 G_TYPE_STRING, /* Filename */
830 G_TYPE_STRING, /* Time */
831 G_TYPE_UINT); /* Hidden field */
834 PlaylistRebuildListStore(p_model, p_playlist);
835 gtk_tree_view_set_model(GTK_TREE_VIEW(p_tvplaylist), GTK_TREE_MODEL(p_model));
836 g_object_unref(p_model);
839 vlc_object_release( p_playlist );
842 void deleteItemFromPlaylist(gpointer data, gpointer user_data)
844 gtk_tree_path_free((GtkTreePath*) data); // removing an item.
847 void onDeletePlaylist(GtkButton *button, gpointer user_data)
849 intf_thread_t *p_intf = GtkGetIntf( button );
850 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
852 GtkTreeView *p_tvplaylist;
854 /* Delete an arbitrary item from the playlist */
855 p_tvplaylist = (GtkTreeView *) lookup_widget( GTK_WIDGET(button), "tvPlaylist" );
856 if (p_tvplaylist != NULL)
858 GList *p_rows = NULL;
860 GtkTreeModel *p_model = NULL;
861 GtkListStore *p_store = NULL;
862 GtkTreeSelection *p_selection = gtk_tree_view_get_selection(p_tvplaylist);
864 p_model = gtk_tree_view_get_model(p_tvplaylist);
867 p_rows = gtk_tree_selection_get_selected_rows(p_selection, &p_model);
869 if( g_list_length( p_rows ) )
871 /* reverse-sort so that we can delete from the furthest
872 * to the closest item to delete...
874 p_rows = g_list_reverse( p_rows );
877 for (p_node=p_rows; p_node!=NULL; p_node = p_node->next)
880 GtkTreePath *p_path = NULL;
882 p_path = (GtkTreePath *)p_node->data;
885 if (gtk_tree_model_get_iter(p_model, &iter, p_path))
889 gtk_tree_model_get(p_model, &iter, 2, &item, -1);
890 playlist_LockDelete(p_playlist, item);
895 g_list_foreach (p_rows, (GFunc*)gtk_tree_path_free, NULL);
896 #endif /* Testing the next line */
897 g_list_foreach (p_rows, deleteItemFromPlaylist, NULL);
898 g_list_free (p_rows);
901 /* Rebuild the playlist then. */
902 p_store = gtk_list_store_new (3,
903 G_TYPE_STRING, /* Filename */
904 G_TYPE_STRING, /* Time */
905 G_TYPE_UINT); /* Hidden field */
908 PlaylistRebuildListStore(p_store, p_playlist);
909 gtk_tree_view_set_model(GTK_TREE_VIEW(p_tvplaylist), GTK_TREE_MODEL(p_store));
910 g_object_unref(p_store);
913 vlc_object_release( p_playlist );
917 void onClearPlaylist(GtkButton *button, gpointer user_data)
919 intf_thread_t *p_intf = GtkGetIntf( button );
920 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
922 GtkTreeView *p_tvplaylist;
925 if( p_playlist == NULL )
930 for(item = p_playlist->i_size - 1; item >= 0 ;item-- )
932 playlist_LockDelete( p_playlist, item);
934 vlc_object_release( p_playlist );
936 // Remove all entries from the Playlist widget.
937 p_tvplaylist = (GtkTreeView*) lookup_widget( GTK_WIDGET(button), "tvPlaylist");
940 GtkTreeModel *p_play_model;
942 p_play_model = gtk_tree_view_get_model(p_tvplaylist);
945 gtk_list_store_clear(GTK_LIST_STORE(p_play_model));
951 void onPreferenceSave(GtkButton *button, gpointer user_data)
954 intf_thread_t *p_intf = GtkGetIntf( button );
956 msg_Dbg(p_intf, "Preferences Save" );
957 config_SaveConfigFile( p_intf, NULL );
962 void onPreferenceApply(GtkButton *button, gpointer user_data)
965 intf_thread_t *p_intf = GtkGetIntf( button );
967 msg_Dbg(p_intf, "Preferences Apply" );
972 void onPreferenceCancel(GtkButton *button, gpointer user_data)
975 intf_thread_t *p_intf = GtkGetIntf( button );
977 msg_Dbg(p_intf, "Preferences Cancel" );
978 config_ResetAll( p_intf );
979 /* Cancel interface changes. */
980 config_SaveConfigFile( p_intf, NULL );
985 void onAddTranscodeToPlaylist(GtkButton *button, gpointer user_data)
987 intf_thread_t *p_intf = GtkGetIntf( button );
989 GtkEntry *p_entryVideoCodec = NULL;
990 GtkSpinButton *p_entryVideoBitrate = NULL;
991 GtkSpinButton *p_entryVideoBitrateTolerance = NULL;
992 GtkSpinButton *p_entryVideoKeyFrameInterval = NULL;
993 GtkCheckButton *p_checkVideoDeinterlace = NULL;
994 GtkEntry *p_entryAudioCodec = NULL;
995 GtkSpinButton *p_entryAudioBitrate = NULL;
996 const gchar *p_video_codec;
997 gint i_video_bitrate;
998 gint i_video_bitrate_tolerance;
999 gint i_video_keyframe_interval;
1000 gboolean b_video_deinterlace;
1001 const gchar *p_audio_codec;
1002 gint i_audio_bitrate;
1004 GtkEntry *p_entryStdAccess = NULL;
1005 GtkEntry *p_entryStdMuxer = NULL;
1006 GtkEntry *p_entryStdURL = NULL;
1007 GtkEntry *p_entryStdAnnounce = NULL;
1008 GtkSpinButton *p_entryStdTTL = NULL;
1009 GtkCheckButton *p_checkSAP = NULL;
1010 GtkCheckButton *p_checkSLP = NULL;
1011 const gchar *p_std_announce;
1012 const gchar *p_std_access;
1013 const gchar *p_std_muxer;
1014 const gchar *p_std_url;
1015 gboolean b_sap_announce;
1016 gboolean b_slp_announce;
1019 char **ppsz_options = NULL; /* list of options */
1026 ppsz_options = (char **) malloc(3 *sizeof(char*));
1027 if (ppsz_options == NULL)
1029 msg_Err(p_intf, "No memory to allocate for v4l options.");
1034 ppsz_options[i] = (char *) malloc(VLC_MAX_MRL * sizeof(char));
1035 if (ppsz_options[i] == NULL)
1037 msg_Err(p_intf, "No memory to allocate for v4l options string %i.", i);
1038 for (i-=1; i>=0; i--)
1039 free(ppsz_options[i]);
1045 /* Update the playlist */
1046 playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1047 if( p_playlist == NULL ) return;
1049 /* Get all the options. */
1050 i_pos = snprintf( &mrl[0], VLC_MAX_MRL, "sout");
1053 i_pos = snprintf( &ppsz_options[i_options][0], VLC_MAX_MRL, "sout='#transcode{");
1054 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1056 p_entryVideoCodec = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryVideoCodec" );
1057 p_entryVideoBitrate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoBitrate" );
1058 p_entryVideoBitrateTolerance = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoBitrateTolerance" );
1059 p_entryVideoKeyFrameInterval = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoKeyFrameInterval" );
1061 p_video_codec = gtk_entry_get_text(GTK_ENTRY(p_entryVideoCodec));
1062 i_video_bitrate = gtk_spin_button_get_value_as_int(p_entryVideoBitrate);
1063 i_video_bitrate_tolerance = gtk_spin_button_get_value_as_int(p_entryVideoBitrateTolerance);
1064 i_video_keyframe_interval = gtk_spin_button_get_value_as_int(p_entryVideoKeyFrameInterval);
1066 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "vcodec=%s,", (char*)p_video_codec );
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, "vb=%d,", (int)i_video_bitrate );
1069 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1070 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "vt=%d,", (int)i_video_bitrate_tolerance );
1071 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1072 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "keyint=%d,", (int)i_video_keyframe_interval );
1073 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1075 p_checkVideoDeinterlace = (GtkCheckButton*) lookup_widget( GTK_WIDGET(button), "checkVideoDeinterlace" );
1076 b_video_deinterlace = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_checkVideoDeinterlace));
1077 if (b_video_deinterlace)
1079 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "deinterlace," );
1080 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1082 p_entryAudioCodec = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryAudioCodec" );
1083 p_entryAudioBitrate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryAudioBitrate" );
1085 p_audio_codec = gtk_entry_get_text(GTK_ENTRY(p_entryAudioCodec));
1086 i_audio_bitrate = gtk_spin_button_get_value_as_int(p_entryAudioBitrate);
1088 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "acodec=%s,", (char*)p_audio_codec );
1089 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1090 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "ab=%d,", (int)i_audio_bitrate );
1091 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1092 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "channels=1}"/*, (int)i_audio_channels*/ );
1093 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1097 i_pos = snprintf( &ppsz_options[i_options++][i_pos], VLC_MAX_MRL - i_pos, "#" );
1098 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1100 p_entryStdAccess = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdAccess" );
1101 p_entryStdMuxer = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdMuxer" );
1102 p_entryStdURL = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdURL" );
1103 p_entryStdAnnounce = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryAnnounceChannel" );
1104 p_entryStdTTL = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryStdTTL" );
1106 p_std_access = gtk_entry_get_text(GTK_ENTRY(p_entryStdAccess));
1107 p_std_muxer = gtk_entry_get_text(GTK_ENTRY(p_entryStdMuxer));
1108 p_std_url = gtk_entry_get_text(GTK_ENTRY(p_entryStdURL));
1109 p_std_announce = gtk_entry_get_text(GTK_ENTRY(p_entryStdAnnounce));
1110 b_sap_announce = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_checkSAP));
1111 b_slp_announce = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_checkSLP));
1113 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "std{access=%s,", (char*)p_std_access);
1114 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1115 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "mux=%s,", (char*)p_std_muxer);
1116 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1117 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "dst=%s", (char*)p_std_url);
1118 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1120 if (strncasecmp( (const char*)p_std_access, "udp", 3)==0)
1124 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "sap=%s", (char*)p_std_announce);
1125 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1129 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "slp=%s", (char*)p_std_announce);
1130 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1134 i_std_ttl = gtk_spin_button_get_value_as_int(p_entryStdTTL);
1136 i_pos += snprintf( &ppsz_options[i_options++][i_pos], VLC_MAX_MRL - i_pos, "ttl=%d}", (int)i_std_ttl);
1137 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1139 if (user_data != NULL)
1141 msg_Dbg(p_intf, "Adding transcoding options to playlist item." );
1145 msg_Dbg(p_intf, "Adding --sout to playlist." );
1146 PlaylistAddItem(GTK_WIDGET(button), (gchar*) &mrl, ppsz_options, i_options);
1150 void onEntryStdAccessChanged(GtkEditable *editable, gpointer user_data)
1152 intf_thread_t *p_intf = GtkGetIntf( editable );
1154 GtkCheckButton *p_checkSAP = NULL;
1155 GtkCheckButton *p_checkSLP = NULL;
1156 GtkEntry *p_entryStdAccess = NULL;
1157 const gchar *p_std_access = NULL;
1158 gboolean b_announce = FALSE;
1160 p_entryStdAccess = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryStdAccess" );
1161 p_checkSAP = (GtkCheckButton*) lookup_widget( GTK_WIDGET(editable), "checkSAP" );
1162 p_checkSLP = (GtkCheckButton*) lookup_widget( GTK_WIDGET(editable), "checkSLP" );
1164 if ( (p_std_access == NULL) || (p_checkSAP == NULL) || (p_checkSLP == NULL))
1166 msg_Err( p_intf, "Access, SAP and SLP widgets not found." );
1169 p_std_access = gtk_entry_get_text(GTK_ENTRY(p_entryStdAccess));
1171 b_announce = (strncasecmp( (const char*)p_std_access, "udp", 3) == 0);
1172 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_checkSAP), b_announce);
1173 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_checkSLP), b_announce);