1 /*****************************************************************************
2 * pda_callbacks.c : Callbacks for the pda Linux Gtk+ plugin.
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: pda_callbacks.c,v 1.22 2003/12/06 22:41:40 jpsaman Exp $
7 * Authors: Jean-Paul Saman <jpsaman@wxs.nl>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <sys/types.h> /* off_t */
47 #include "pda_callbacks.h"
48 #include "pda_interface.h"
49 #include "pda_support.h"
52 #define VLC_MAX_MRL 256
54 static char *get_file_perms(struct stat st);
56 /*****************************************************************************
57 * Useful function to retrieve p_intf
58 ****************************************************************************/
59 void * E_(__GtkGetIntf)( GtkWidget * widget )
63 if( GTK_IS_MENU_ITEM( widget ) )
65 /* Look for a GTK_MENU */
66 while( widget->parent && !GTK_IS_MENU( widget ) )
68 widget = widget->parent;
71 /* Maybe this one has the data */
72 p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" );
78 /* Otherwise, the parent widget has it */
79 widget = gtk_menu_get_attach_widget( GTK_MENU( widget ) );
82 /* We look for the top widget */
83 widget = gtk_widget_get_toplevel( GTK_WIDGET( widget ) );
85 p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" );
90 void PlaylistAddItem(GtkWidget *widget, gchar *name, char **ppsz_options, int i_size)
92 intf_thread_t *p_intf = GtkGetIntf( widget );
93 playlist_t *p_playlist;
94 GtkTreeView *p_tvplaylist = NULL;
96 p_playlist = (playlist_t *)
97 vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
99 if( p_playlist == NULL)
100 { /* Bail out when VLC's playlist object is not found. */
104 /* Add to playlist object. */
105 p_tvplaylist = (GtkTreeView *) lookup_widget( GTK_WIDGET(widget), "tvPlaylist");
108 GtkTreeModel *p_play_model;
109 GtkTreeIter p_play_iter;
111 p_play_model = gtk_tree_view_get_model(p_tvplaylist);
117 /* Add a new row to the playlist treeview model */
118 gtk_list_store_append (GTK_LIST_STORE(p_play_model), &p_play_iter);
119 gtk_list_store_set (GTK_LIST_STORE(p_play_model), &p_play_iter,
120 0, name, /* Add path to it !!! */
122 2, p_playlist->i_size, /* Hidden index. */
125 /* Add to VLC's playlist */
127 if (p_intf->p_sys->b_autoplayfile)
129 playlist_Add( p_playlist, (const char*)name, (const char**)ppsz_options, i_size,
130 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END);
135 playlist_Add( p_playlist, (const char*)name, (const char**)ppsz_options, i_size,
136 PLAYLIST_APPEND, PLAYLIST_END );
140 for (i=0; i<i_size; i++)
141 free(ppsz_options[i]);
145 vlc_object_release( p_playlist );
148 void PlaylistRebuildListStore( GtkListStore * p_list, playlist_t * p_playlist )
152 gchar * ppsz_text[2];
159 vlc_mutex_lock( &p_playlist->object_lock );
160 for( i_dummy = 0; i_dummy < p_playlist->i_size ; i_dummy++ )
162 ppsz_text[0] = p_playlist->pp_items[i_dummy]->psz_name;
163 ppsz_text[1] = "no info";
164 gtk_list_store_append (p_list, &iter);
165 gtk_list_store_set (p_list, &iter,
168 2, i_dummy, /* Hidden index */
171 vlc_mutex_unlock( &p_playlist->object_lock );
174 /*****************************************************************
175 * Read directory helper function.
176 ****************************************************************/
177 void ReadDirectory(intf_thread_t *p_intf, GtkListStore *p_list, char *psz_dir )
180 struct dirent **pp_namelist;
186 msg_Dbg(p_intf, "Changing to dir %s", psz_dir);
189 status = chdir(psz_dir);
191 msg_Dbg(p_intf, "permision denied" );
193 n = scandir(".", &pp_namelist, 0, alphasort);
202 if (lstat("..", &st)==0)
205 p_pw = getpwuid(st.st_uid);
206 p_grp = getgrgid(st.st_gid);
208 /* XXX : kludge temporaire pour yopy */
210 ppsz_text[1] = get_file_perms(st);
211 ppsz_text[2] = p_pw->pw_name;
212 ppsz_text[3] = p_grp->gr_name;
214 /* Add a new row to the model */
215 gtk_list_store_append (p_list, &iter);
216 gtk_list_store_set (p_list, &iter,
224 if (ppsz_text[1]) free(ppsz_text[1]);
229 if ((pp_namelist[i]->d_name[0] != '.') &&
230 (lstat(pp_namelist[i]->d_name, &st)==0))
233 p_pw = getpwuid(st.st_uid);
234 p_grp = getgrgid(st.st_gid);
236 /* This is a list of strings. */
237 ppsz_text[0] = pp_namelist[i]->d_name;
238 ppsz_text[1] = get_file_perms(st);
239 ppsz_text[2] = p_pw->pw_name;
240 ppsz_text[3] = p_grp->gr_name;
242 msg_Dbg(p_intf, "(%d) file: %s permission: %s user: %s group: %s", i, ppsz_text[0], ppsz_text[1], ppsz_text[2], ppsz_text[3] );
244 gtk_list_store_append (p_list, &iter);
245 gtk_list_store_set (p_list, &iter,
253 if (ppsz_text[1]) free(ppsz_text[1]);
260 static char *get_file_perms(const struct stat st)
264 psz_perm = (char *) malloc(sizeof(char)*10);
265 strncpy( psz_perm, "----------", sizeof("----------"));
267 /* determine permission modes */
268 if (S_ISLNK(st.st_mode))
270 else if (S_ISDIR(st.st_mode))
272 else if (S_ISCHR(st.st_mode))
274 else if (S_ISBLK(st.st_mode))
276 else if (S_ISFIFO(st.st_mode))
278 else if (S_ISSOCK(st.st_mode))
280 else if (S_ISREG(st.st_mode))
282 else /* Unknown type is an error */
284 /* Get file permissions */
286 if (st.st_mode & S_IRUSR)
288 if (st.st_mode & S_IWUSR)
290 if (st.st_mode & S_IXUSR)
292 if (st.st_mode & S_ISUID)
297 else if (st.st_mode & S_ISUID)
300 if (st.st_mode & S_IRGRP)
302 if (st.st_mode & S_IWGRP)
304 if (st.st_mode & S_IXGRP)
306 if (st.st_mode & S_ISGID)
311 else if (st.st_mode & S_ISGID)
314 if (st.st_mode & S_IROTH)
316 if (st.st_mode & S_IWOTH)
318 if (st.st_mode & S_IXOTH)
321 if (st.st_mode &S_ISVTX)
326 else if (st.st_mode &S_ISVTX)
333 * Main interface callbacks
336 gboolean onPDADeleteEvent(GtkWidget *widget, GdkEvent *event, gpointer user_data)
338 intf_thread_t *p_intf = GtkGetIntf( widget );
340 vlc_mutex_lock( &p_intf->change_lock );
341 p_intf->p_vlc->b_die = VLC_TRUE;
342 vlc_mutex_unlock( &p_intf->change_lock );
343 msg_Dbg( p_intf, "about to exit vlc ... signalled" );
349 void onRewind(GtkButton *button, gpointer user_data)
351 intf_thread_t *p_intf = GtkGetIntf( button );
353 if (p_intf->p_sys->p_input != NULL)
355 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_SLOWER );
360 void onPause(GtkButton *button, gpointer user_data)
362 intf_thread_t *p_intf = GtkGetIntf( button );
364 if (p_intf->p_sys->p_input != NULL)
366 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
371 void onPlay(GtkButton *button, gpointer user_data)
373 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) );
374 playlist_t *p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
378 vlc_mutex_lock( &p_playlist->object_lock );
379 if (p_playlist->i_size)
381 vlc_mutex_unlock( &p_playlist->object_lock );
382 playlist_Play( p_playlist );
386 vlc_mutex_unlock( &p_playlist->object_lock );
388 vlc_object_release( p_playlist );
393 void onStop(GtkButton *button, gpointer user_data)
395 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) );
396 playlist_t *p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
400 playlist_Stop( p_playlist );
401 vlc_object_release( p_playlist );
406 void onForward(GtkButton *button, gpointer user_data)
408 intf_thread_t *p_intf = GtkGetIntf( button );
410 if (p_intf->p_sys->p_input != NULL)
412 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_FASTER );
417 void onAbout(GtkButton *button, gpointer user_data)
419 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(button) );
422 if (p_intf->p_sys->p_notebook)
424 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
425 gtk_notebook_set_page(p_intf->p_sys->p_notebook,6);
430 gboolean SliderRelease(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
432 intf_thread_t *p_intf = GtkGetIntf( widget );
434 msg_Dbg( p_intf, "SliderButton Release" );
435 vlc_mutex_lock( &p_intf->change_lock );
436 p_intf->p_sys->b_slider_free = 1;
437 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);
523 gtk_tree_selection_selected_foreach(p_selection, (GtkTreeSelectionForeachFunc) &addSelectedToPlaylist, (gpointer) treeview);
529 gtk_tree_selection_selected_foreach(p_selection, (GtkTreeSelectionForeachFunc) &addSelectedToPlaylist, (gpointer) treeview);
533 void onAddFileToPlaylist(GtkButton *button, gpointer user_data)
535 GtkTreeView *p_treeview = NULL;
537 p_treeview = (GtkTreeView *) lookup_widget( GTK_WIDGET(button), "tvFileList");
540 GtkTreeSelection *p_selection = gtk_tree_view_get_selection(p_treeview);
542 gtk_tree_selection_selected_foreach(p_selection, (GtkTreeSelectionForeachFunc) &addSelectedToPlaylist, (gpointer) p_treeview);
547 void NetworkBuildMRL(GtkEditable *editable, gpointer user_data)
549 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(editable) );
550 GtkSpinButton *p_networkPort = NULL;
551 GtkEntry *p_entryMRL = NULL;
552 GtkEntry *p_networkType = NULL;
553 GtkEntry *p_networkAddress = NULL;
554 GtkEntry *p_networkProtocol = NULL;
555 const gchar *psz_mrlNetworkType;
556 const gchar *psz_mrlAddress;
557 const gchar *psz_mrlProtocol;
559 char text[VLC_MAX_MRL];
562 p_entryMRL = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryMRL" );
564 p_networkType = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryNetworkType" );
565 p_networkAddress = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryNetworkAddress" );
566 p_networkPort = (GtkSpinButton*) lookup_widget( GTK_WIDGET(editable), "entryNetworkPort" );
567 p_networkProtocol = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryNetworkProtocolType" );
569 psz_mrlNetworkType = gtk_entry_get_text(GTK_ENTRY(p_networkType));
570 psz_mrlAddress = gtk_entry_get_text(GTK_ENTRY(p_networkAddress));
571 i_mrlPort = gtk_spin_button_get_value_as_int(p_networkPort);
572 psz_mrlProtocol = gtk_entry_get_text(GTK_ENTRY(p_networkProtocol));
574 /* Build MRL from parts ;-) */
575 i_pos = snprintf( &text[0], VLC_MAX_MRL, "%s://", (char*)psz_mrlProtocol);
576 if (strncasecmp( (char*)psz_mrlNetworkType, "multicast",9)==0)
578 i_pos += snprintf( &text[i_pos], VLC_MAX_MRL - i_pos, "@" );
580 i_pos += snprintf( &text[i_pos], VLC_MAX_MRL - i_pos, "%s:%d", (char*)psz_mrlAddress, (int)i_mrlPort );
582 if (i_pos >= VLC_MAX_MRL)
584 text[VLC_MAX_MRL-1]='\0';
585 msg_Err( p_intf, "Media Resource Locator is truncated to: %s", text);
588 gtk_entry_set_text(p_entryMRL,text);
591 void onAddNetworkPlaylist(GtkButton *button, gpointer user_data)
593 GtkEntry *p_mrl = NULL;
594 const gchar *psz_mrl_name;
596 p_mrl = (GtkEntry*) lookup_widget(GTK_WIDGET(button),"entryMRL" );
599 psz_mrl_name = gtk_entry_get_text(p_mrl);
600 if (psz_mrl_name != NULL)
602 PlaylistAddItem(GTK_WIDGET(button), (gchar *)psz_mrl_name, 0, 0);
608 void onAddCameraToPlaylist(GtkButton *button, gpointer user_data)
610 intf_thread_t *p_intf = GtkGetIntf( button );
612 GtkSpinButton *entryV4LChannel = NULL;
613 GtkSpinButton *entryV4LFrequency = NULL;
614 GtkSpinButton *entryV4LSampleRate = NULL;
615 GtkSpinButton *entryV4LQuality = NULL;
616 GtkSpinButton *entryV4LTuner = NULL;
618 gint i_v4l_frequency;
619 gint i_v4l_samplerate;
623 GtkEntry *entryV4LVideoDevice = NULL;
624 GtkEntry *entryV4LAudioDevice = NULL;
625 GtkEntry *entryV4LNorm = NULL;
626 GtkEntry *entryV4LSize = NULL;
627 GtkEntry *entryV4LSoundDirection = NULL;
628 const gchar *p_v4l_video_device;
629 const gchar *p_v4l_audio_device;
630 const gchar *p_v4l_norm;
631 const gchar *p_v4l_size;
632 const gchar *p_v4l_sound_direction;
635 GtkCheckButton *checkV4LMJPEG = NULL;
636 GtkSpinButton *entryV4LDecimation = NULL;
637 gboolean b_v4l_mjpeg;
638 gint i_v4l_decimation;
641 char **ppsz_options = NULL; /* list of options */
647 ppsz_options = (char **) malloc(11 *sizeof(char*));
648 if (ppsz_options == NULL)
650 msg_Err(p_intf, "No memory to allocate for v4l options.");
655 ppsz_options[i] = (char *) malloc(VLC_MAX_MRL * sizeof(char));
656 if (ppsz_options[i] == NULL)
658 msg_Err(p_intf, "No memory to allocate for v4l options string %i.", i);
659 for (i-=1; i>=0; i--)
660 free(ppsz_options[i]);
666 i_pos = snprintf( &v4l_mrl[0], 6, "v4l");
669 entryV4LChannel = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LChannel" );
670 entryV4LFrequency = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LFrequency" );
671 entryV4LSampleRate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LSampleRate" );
672 entryV4LQuality = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LQuality" );
673 entryV4LTuner = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LTuner" );
675 entryV4LVideoDevice = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LVideoDevice" );
676 entryV4LAudioDevice = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LAudioDevice" );
677 entryV4LNorm = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LNorm" );
678 entryV4LSize = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LSize" );
679 entryV4LSoundDirection = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LSoundDirection" );
681 i_v4l_channel = gtk_spin_button_get_value_as_int(entryV4LChannel);
682 i_v4l_frequency = gtk_spin_button_get_value_as_int(entryV4LFrequency);
683 i_v4l_samplerate = gtk_spin_button_get_value_as_int(entryV4LSampleRate);
684 i_v4l_quality = gtk_spin_button_get_value_as_int(entryV4LQuality);
685 i_v4l_tuner = gtk_spin_button_get_value_as_int(entryV4LTuner);
687 p_v4l_video_device = gtk_entry_get_text(GTK_ENTRY(entryV4LVideoDevice));
688 p_v4l_audio_device = gtk_entry_get_text(GTK_ENTRY(entryV4LAudioDevice));
689 p_v4l_norm = gtk_entry_get_text(GTK_ENTRY(entryV4LNorm));
690 p_v4l_size = gtk_entry_get_text(GTK_ENTRY(entryV4LSize));
691 p_v4l_sound_direction = gtk_entry_get_text(GTK_ENTRY(entryV4LSoundDirection));
693 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "%s", (char*)p_v4l_video_device );
694 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
695 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "adev=%s", (char*)p_v4l_audio_device );
696 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
697 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "norm=%s", (char*)p_v4l_norm );
698 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
699 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "size=%s", (char*)p_v4l_size );
700 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
701 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "%s", (char*)p_v4l_sound_direction );
702 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, "channel=%d", (int)i_v4l_channel );
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, "frequency=%d", (int)i_v4l_frequency );
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, "samplerate=%d", (int)i_v4l_samplerate );
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, "quality=%d", (int)i_v4l_quality );
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, "tuner=%d", (int)i_v4l_tuner );
713 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
716 checkV4LMJPEG = (GtkCheckButton*) lookup_widget( GTK_WIDGET(button), "checkV4LMJPEG" );
717 b_v4l_mjpeg = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkV4LMJPEG));
720 entryV4LDecimation = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LDecimation" );
721 i_v4l_decimation = gtk_spin_button_get_value_as_int(entryV4LDecimation);
723 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "mjpeg:%d", (int)i_v4l_decimation );
724 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
728 PlaylistAddItem(GTK_WIDGET(button), (gchar*) &v4l_mrl, ppsz_options, i_options);
732 gboolean PlaylistEvent(GtkWidget *widget, GdkEvent *event, gpointer user_data)
738 void onPlaylistColumnsChanged(GtkTreeView *treeview, gpointer user_data)
743 gboolean onPlaylistRowSelected(GtkTreeView *treeview, gboolean start_editing, gpointer user_data)
749 void onPlaylistRow(GtkTreeView *treeview, GtkTreePath *path,
750 GtkTreeViewColumn *column, gpointer user_data)
755 void onUpdatePlaylist(GtkButton *button, gpointer user_data)
757 intf_thread_t * p_intf = GtkGetIntf( button );
758 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
760 GtkTreeView *p_tvplaylist = NULL;
762 if( p_playlist == NULL )
767 p_tvplaylist = (GtkTreeView*) lookup_widget( GTK_WIDGET(button), "tvPlaylist");
770 GtkListStore *p_model = NULL;
772 /* Rebuild the playlist then. */
773 p_model = gtk_list_store_new (3,
774 G_TYPE_STRING, /* Filename */
775 G_TYPE_STRING, /* Time */
776 G_TYPE_UINT); /* Hidden field */
779 PlaylistRebuildListStore(p_model, p_playlist);
780 gtk_tree_view_set_model(GTK_TREE_VIEW(p_tvplaylist), GTK_TREE_MODEL(p_model));
781 g_object_unref(p_model);
784 vlc_object_release( p_playlist );
787 void onDeletePlaylist(GtkButton *button, gpointer user_data)
789 intf_thread_t *p_intf = GtkGetIntf( button );
790 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
792 GtkTreeView *p_tvplaylist;
794 /* Delete an arbitrary item from the playlist */
795 p_tvplaylist = (GtkTreeView *) lookup_widget( GTK_WIDGET(button), "tvPlaylist" );
796 if (p_tvplaylist != NULL)
798 GList *p_rows = NULL;
800 GtkTreeModel *p_model = NULL;
801 GtkListStore *p_store = NULL;
802 GtkTreeSelection *p_selection = gtk_tree_view_get_selection(p_tvplaylist);
804 p_model = gtk_tree_view_get_model(p_tvplaylist);
807 p_rows = gtk_tree_selection_get_selected_rows(p_selection, &p_model);
809 if( g_list_length( p_rows ) )
811 /* reverse-sort so that we can delete from the furthest
812 * to the closest item to delete...
814 p_rows = g_list_reverse( p_rows );
817 for (p_node=p_rows; p_node!=NULL; p_node = p_node->next)
820 GtkTreePath *p_path = NULL;
822 p_path = (GtkTreePath *)p_node->data;
825 if (gtk_tree_model_get_iter(p_model, &iter, p_path))
829 gtk_tree_model_get(p_model, &iter, 2, &item, -1);
830 playlist_Delete(p_playlist, item);
834 g_list_foreach (p_rows, (GFunc*)gtk_tree_path_free, NULL);
835 g_list_free (p_rows);
838 /* Rebuild the playlist then. */
839 p_store = gtk_list_store_new (3,
840 G_TYPE_STRING, /* Filename */
841 G_TYPE_STRING, /* Time */
842 G_TYPE_UINT); /* Hidden field */
845 PlaylistRebuildListStore(p_store, p_playlist);
846 gtk_tree_view_set_model(GTK_TREE_VIEW(p_tvplaylist), GTK_TREE_MODEL(p_store));
847 g_object_unref(p_store);
850 vlc_object_release( p_playlist );
854 void onClearPlaylist(GtkButton *button, gpointer user_data)
856 intf_thread_t *p_intf = GtkGetIntf( button );
857 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
859 GtkTreeView *p_tvplaylist;
862 if( p_playlist == NULL )
867 for(item = p_playlist->i_size - 1; item >= 0 ;item-- )
869 playlist_Delete( p_playlist, item);
871 vlc_object_release( p_playlist );
873 // Remove all entries from the Playlist widget.
874 p_tvplaylist = (GtkTreeView*) lookup_widget( GTK_WIDGET(button), "tvPlaylist");
877 GtkTreeModel *p_play_model;
879 p_play_model = gtk_tree_view_get_model(p_tvplaylist);
882 gtk_list_store_clear(GTK_LIST_STORE(p_play_model));
888 void onPreferenceSave(GtkButton *button, gpointer user_data)
891 intf_thread_t *p_intf = GtkGetIntf( button );
893 msg_Dbg(p_intf, "Preferences Save" );
894 config_SaveConfigFile( p_intf, NULL );
899 void onPreferenceApply(GtkButton *button, gpointer user_data)
902 intf_thread_t *p_intf = GtkGetIntf( button );
904 msg_Dbg(p_intf, "Preferences Apply" );
909 void onPreferenceCancel(GtkButton *button, gpointer user_data)
912 intf_thread_t *p_intf = GtkGetIntf( button );
914 msg_Dbg(p_intf, "Preferences Cancel" );
915 config_ResetAll( p_intf );
916 /* Cancel interface changes. */
917 config_SaveConfigFile( p_intf, NULL );
922 void onAddTranscodeToPlaylist(GtkButton *button, gpointer user_data)
924 intf_thread_t *p_intf = GtkGetIntf( button );
926 GtkEntry *p_entryVideoCodec = NULL;
927 GtkSpinButton *p_entryVideoBitrate = NULL;
928 GtkSpinButton *p_entryVideoBitrateTolerance = NULL;
929 GtkSpinButton *p_entryVideoKeyFrameInterval = NULL;
930 GtkCheckButton *p_checkVideoDeinterlace = NULL;
931 GtkEntry *p_entryAudioCodec = NULL;
932 GtkSpinButton *p_entryAudioBitrate = NULL;
933 const gchar *p_video_codec;
934 gint i_video_bitrate;
935 gint i_video_bitrate_tolerance;
936 gint i_video_keyframe_interval;
937 gboolean b_video_deinterlace;
938 const gchar *p_audio_codec;
939 gint i_audio_bitrate;
941 GtkEntry *p_entryStdAccess = NULL;
942 GtkEntry *p_entryStdMuxer = NULL;
943 GtkEntry *p_entryStdURL = NULL;
944 GtkEntry *p_entryStdAnnounce = NULL;
945 GtkSpinButton *p_entryStdTTL = NULL;
946 GtkCheckButton *p_checkSAP = NULL;
947 GtkCheckButton *p_checkSLP = NULL;
948 const gchar *p_std_announce;
949 const gchar *p_std_access;
950 const gchar *p_std_muxer;
951 const gchar *p_std_url;
952 gboolean b_sap_announce;
953 gboolean b_slp_announce;
956 char **ppsz_options = NULL; /* list of options */
963 ppsz_options = (char **) malloc(3 *sizeof(char*));
964 if (ppsz_options == NULL)
966 msg_Err(p_intf, "No memory to allocate for v4l options.");
971 ppsz_options[i] = (char *) malloc(VLC_MAX_MRL * sizeof(char));
972 if (ppsz_options[i] == NULL)
974 msg_Err(p_intf, "No memory to allocate for v4l options string %i.", i);
975 for (i-=1; i>=0; i--)
976 free(ppsz_options[i]);
982 i_pos = snprintf( &mrl[0], VLC_MAX_MRL, "sout");
985 i_pos = snprintf( &ppsz_options[i_options][0], VLC_MAX_MRL, "sout='#transcode{");
986 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
988 p_entryVideoCodec = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryVideoCodec" );
989 p_entryVideoBitrate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoBitrate" );
990 p_entryVideoBitrateTolerance = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoBitrateTolerance" );
991 p_entryVideoKeyFrameInterval = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoKeyFrameInterval" );
993 p_video_codec = gtk_entry_get_text(GTK_ENTRY(p_entryVideoCodec));
994 i_video_bitrate = gtk_spin_button_get_value_as_int(p_entryVideoBitrate);
995 i_video_bitrate_tolerance = gtk_spin_button_get_value_as_int(p_entryVideoBitrateTolerance);
996 i_video_keyframe_interval = gtk_spin_button_get_value_as_int(p_entryVideoKeyFrameInterval);
998 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "vcodec=%s,", (char*)p_video_codec );
999 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1000 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "vb=%d,", (int)i_video_bitrate );
1001 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1002 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "vt=%d,", (int)i_video_bitrate_tolerance );
1003 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1004 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "keyint=%d,", (int)i_video_keyframe_interval );
1005 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1007 p_checkVideoDeinterlace = (GtkCheckButton*) lookup_widget( GTK_WIDGET(button), "checkVideoDeinterlace" );
1008 b_video_deinterlace = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_checkVideoDeinterlace));
1009 if (b_video_deinterlace)
1011 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "deinterlace," );
1012 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1014 p_entryAudioCodec = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryAudioCodec" );
1015 p_entryAudioBitrate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryAudioBitrate" );
1017 p_audio_codec = gtk_entry_get_text(GTK_ENTRY(p_entryAudioCodec));
1018 i_audio_bitrate = gtk_spin_button_get_value_as_int(p_entryAudioBitrate);
1020 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "acodec=%s,", (char*)p_audio_codec );
1021 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1022 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "ab=%d,", (int)i_audio_bitrate );
1023 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1024 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "channels=1}"/*, (int)i_audio_channels*/ );
1025 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1029 i_pos = snprintf( &ppsz_options[i_options++][i_pos], VLC_MAX_MRL - i_pos, "dst=" );
1030 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1032 p_entryStdAccess = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdAccess" );
1033 p_entryStdMuxer = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdMuxer" );
1034 p_entryStdURL = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdURL" );
1035 p_entryStdAnnounce = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryAnnounceChannel" );
1036 p_entryStdTTL = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryStdTTL" );
1038 p_std_access = gtk_entry_get_text(GTK_ENTRY(p_entryStdAccess));
1039 p_std_muxer = gtk_entry_get_text(GTK_ENTRY(p_entryStdMuxer));
1040 p_std_url = gtk_entry_get_text(GTK_ENTRY(p_entryStdURL));
1041 p_std_announce = gtk_entry_get_text(GTK_ENTRY(p_entryStdAnnounce));
1042 b_sap_announce = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_checkSAP));
1043 b_slp_announce = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_checkSLP));
1045 if ( strncasecmp( (const char*)p_std_access, "display", 7 ) == 0)
1047 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "%s,", (char*)p_std_access);
1048 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1052 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "std{access=%s,", (char*)p_std_access);
1053 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1054 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "mux=%s,", (char*)p_std_muxer);
1055 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1056 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "url=%s", (char*)p_std_url);
1057 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1059 if (strncasecmp( (const char*)p_std_access, "udp", 3)==0)
1063 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "sap=%s", (char*)p_std_announce);
1064 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, "slp=%s", (char*)p_std_announce);
1069 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, "}");
1073 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1075 i_std_ttl = gtk_spin_button_get_value_as_int(p_entryStdTTL);
1077 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "ttl=%d", (int)i_std_ttl);
1078 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1081 PlaylistAddItem(GTK_WIDGET(button), (gchar*) &mrl, ppsz_options, i_options);
1086 void onEntryStdAccessChanged(GtkEditable *editable, gpointer user_data)
1088 intf_thread_t *p_intf = GtkGetIntf( editable );
1090 GtkCheckButton *p_checkSAP = NULL;
1091 GtkCheckButton *p_checkSLP = NULL;
1092 GtkEntry *p_entryStdAccess = NULL;
1093 const gchar *p_std_access = NULL;
1094 gboolean b_announce = FALSE;
1096 p_entryStdAccess = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryStdAccess" );
1097 p_checkSAP = (GtkCheckButton*) lookup_widget( GTK_WIDGET(editable), "checkSAP" );
1098 p_checkSLP = (GtkCheckButton*) lookup_widget( GTK_WIDGET(editable), "checkSLP" );
1100 if ( (p_std_access == NULL) || (p_checkSAP == NULL) || (p_checkSLP == NULL))
1102 msg_Err( p_intf, "Access, SAP and SLP widgets not found." );
1105 p_std_access = gtk_entry_get_text(GTK_ENTRY(p_entryStdAccess));
1107 b_announce = (strncasecmp( (const char*)p_std_access, "udp", 3) == 0);
1108 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_checkSAP), b_announce);
1109 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_checkSLP), b_announce);