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.25 2004/01/25 14:15:21 kuehne 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;
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_Add( p_playlist, (const char*)name,
138 PLAYLIST_APPEND, PLAYLIST_END );
140 i_pos = playlist_GetPositionById( p_playlist, i_id );
142 for( i = 0 ; i< i_size ; i++ )
144 playlist_AddOption( p_playlist, i_pos , ppsz_options[i] );
149 for (i=0; i<i_size; i++)
150 free(ppsz_options[i]);
154 vlc_object_release( p_playlist );
157 void PlaylistRebuildListStore( GtkListStore * p_list, playlist_t * p_playlist )
161 gchar * ppsz_text[2];
168 vlc_mutex_lock( &p_playlist->object_lock );
169 for( i_dummy = 0; i_dummy < p_playlist->i_size ; i_dummy++ )
171 ppsz_text[0] = p_playlist->pp_items[i_dummy]->psz_name;
172 ppsz_text[1] = "no info";
173 gtk_list_store_append (p_list, &iter);
174 gtk_list_store_set (p_list, &iter,
177 2, i_dummy, /* Hidden index */
180 vlc_mutex_unlock( &p_playlist->object_lock );
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,
233 if (ppsz_text[1]) free(ppsz_text[1]);
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,
262 if (ppsz_text[1]) free(ppsz_text[1]);
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 p_intf->p_vlc->b_die = VLC_TRUE;
351 vlc_mutex_unlock( &p_intf->change_lock );
352 msg_Dbg( p_intf, "about to exit vlc ... signaled" );
358 void onRewind(GtkButton *button, gpointer user_data)
360 intf_thread_t *p_intf = GtkGetIntf( button );
362 if (p_intf->p_sys->p_input != NULL)
364 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_SLOWER );
369 void onPause(GtkButton *button, gpointer user_data)
371 intf_thread_t *p_intf = GtkGetIntf( button );
373 if (p_intf->p_sys->p_input != NULL)
375 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
380 void onPlay(GtkButton *button, gpointer user_data)
382 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) );
383 playlist_t *p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
387 vlc_mutex_lock( &p_playlist->object_lock );
388 if (p_playlist->i_size)
390 vlc_mutex_unlock( &p_playlist->object_lock );
391 playlist_Play( p_playlist );
392 gdk_window_lower( p_intf->p_sys->p_window->window );
396 vlc_mutex_unlock( &p_playlist->object_lock );
398 vlc_object_release( p_playlist );
403 void onStop(GtkButton *button, gpointer user_data)
405 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) );
406 playlist_t *p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
410 playlist_Stop( p_playlist );
411 vlc_object_release( p_playlist );
412 gdk_window_raise( p_intf->p_sys->p_window->window );
417 void onForward(GtkButton *button, gpointer user_data)
419 intf_thread_t *p_intf = GtkGetIntf( button );
421 if (p_intf->p_sys->p_input != NULL)
423 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_FASTER );
428 void onAbout(GtkButton *button, gpointer user_data)
430 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(button) );
433 if (p_intf->p_sys->p_notebook)
435 gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
436 gtk_notebook_set_page(p_intf->p_sys->p_notebook,6);
441 gboolean SliderRelease(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
443 intf_thread_t *p_intf = GtkGetIntf( widget );
445 msg_Dbg( p_intf, "SliderButton Release" );
446 vlc_mutex_lock( &p_intf->change_lock );
447 p_intf->p_sys->b_slider_free = 1;
448 vlc_mutex_unlock( &p_intf->change_lock );
454 gboolean SliderPress(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
456 intf_thread_t *p_intf = GtkGetIntf( widget );
458 msg_Dbg( p_intf, "SliderButton Press" );
459 vlc_mutex_lock( &p_intf->change_lock );
460 p_intf->p_sys->b_slider_free = 0;
461 vlc_mutex_unlock( &p_intf->change_lock );
466 void SliderMove(GtkRange *range, GtkScrollType scroll, gpointer user_data)
468 intf_thread_t *p_intf = GtkGetIntf( range );
469 msg_Dbg( p_intf, "SliderButton Move" );
473 void addSelectedToPlaylist(GtkTreeModel *model, GtkTreePath *path,
474 GtkTreeIter *iter, gpointer *userdata)
478 gtk_tree_model_get(model, iter, 0, &psz_filename, -1);
480 PlaylistAddItem(GTK_WIDGET(userdata), psz_filename, 0, 0);
483 void onFileListRow(GtkTreeView *treeview, GtkTreePath *path,
484 GtkTreeViewColumn *column, gpointer user_data)
486 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(treeview) );
487 GtkTreeSelection *p_selection = gtk_tree_view_get_selection(treeview);
489 if (gtk_tree_selection_count_selected_rows(p_selection) == 1)
492 GtkTreeModel *p_model;
496 /* This might be a directory selection */
497 p_model = gtk_tree_view_get_model(treeview);
500 msg_Err(p_intf, "PDA: Filelist model contains a NULL pointer\n" );
503 if (!gtk_tree_model_get_iter(p_model, &iter, path))
505 msg_Err( p_intf, "PDA: Could not get iter from model" );
509 gtk_tree_model_get(p_model, &iter, 0, &psz_filename, -1);
510 if (stat((char*)psz_filename, &st)==0)
512 if (S_ISDIR(st.st_mode))
514 GtkListStore *p_store = NULL;
516 /* Get new directory listing */
517 p_store = gtk_list_store_new (5,
525 ReadDirectory(p_intf, p_store, psz_filename);
527 /* Update TreeView with new model */
528 gtk_tree_view_set_model(treeview, (GtkTreeModel*) p_store);
529 g_object_unref(p_store);
536 void onAddFileToPlaylist(GtkButton *button, gpointer user_data)
538 GtkTreeView *p_treeview = NULL;
540 p_treeview = (GtkTreeView *) lookup_widget( GTK_WIDGET(button), "tvFileList");
543 GtkTreeSelection *p_selection = gtk_tree_view_get_selection(p_treeview);
545 gtk_tree_selection_selected_foreach(p_selection, (GtkTreeSelectionForeachFunc) &addSelectedToPlaylist, (gpointer) p_treeview);
550 void NetworkBuildMRL(GtkEditable *editable, gpointer user_data)
552 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(editable) );
553 GtkSpinButton *p_networkPort = NULL;
554 GtkEntry *p_entryMRL = NULL;
555 GtkEntry *p_networkType = NULL;
556 GtkEntry *p_networkAddress = NULL;
557 GtkEntry *p_networkProtocol = NULL;
558 const gchar *psz_mrlNetworkType;
559 const gchar *psz_mrlAddress;
560 const gchar *psz_mrlProtocol;
562 char text[VLC_MAX_MRL];
565 p_entryMRL = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryMRL" );
567 p_networkType = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryNetworkType" );
568 p_networkAddress = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryNetworkAddress" );
569 p_networkPort = (GtkSpinButton*) lookup_widget( GTK_WIDGET(editable), "entryNetworkPort" );
570 p_networkProtocol = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryNetworkProtocolType" );
572 psz_mrlNetworkType = gtk_entry_get_text(GTK_ENTRY(p_networkType));
573 psz_mrlAddress = gtk_entry_get_text(GTK_ENTRY(p_networkAddress));
574 i_mrlPort = gtk_spin_button_get_value_as_int(p_networkPort);
575 psz_mrlProtocol = gtk_entry_get_text(GTK_ENTRY(p_networkProtocol));
577 /* Build MRL from parts ;-) */
578 i_pos = snprintf( &text[0], VLC_MAX_MRL, "%s://", (char*)psz_mrlProtocol);
579 if (strncasecmp( (char*)psz_mrlNetworkType, "multicast",9)==0)
581 i_pos += snprintf( &text[i_pos], VLC_MAX_MRL - i_pos, "@" );
583 i_pos += snprintf( &text[i_pos], VLC_MAX_MRL - i_pos, "%s:%d", (char*)psz_mrlAddress, (int)i_mrlPort );
585 if (i_pos >= VLC_MAX_MRL)
587 text[VLC_MAX_MRL-1]='\0';
588 msg_Err( p_intf, "Media Resource Locator is truncated to: %s", text);
591 gtk_entry_set_text(p_entryMRL,text);
594 void onAddNetworkPlaylist(GtkButton *button, gpointer user_data)
596 GtkEntry *p_mrl = NULL;
597 const gchar *psz_mrl_name;
599 p_mrl = (GtkEntry*) lookup_widget(GTK_WIDGET(button),"entryMRL" );
602 psz_mrl_name = gtk_entry_get_text(p_mrl);
603 if (psz_mrl_name != NULL)
605 PlaylistAddItem(GTK_WIDGET(button), (gchar *)psz_mrl_name, 0, 0);
611 void onAddCameraToPlaylist(GtkButton *button, gpointer user_data)
613 intf_thread_t *p_intf = GtkGetIntf( button );
615 GtkSpinButton *entryV4LChannel = NULL;
616 GtkSpinButton *entryV4LFrequency = NULL;
617 GtkSpinButton *entryV4LSampleRate = NULL;
618 GtkSpinButton *entryV4LQuality = NULL;
619 GtkSpinButton *entryV4LTuner = NULL;
621 gint i_v4l_frequency;
622 gint i_v4l_samplerate;
626 GtkEntry *entryV4LVideoDevice = NULL;
627 GtkEntry *entryV4LAudioDevice = NULL;
628 GtkEntry *entryV4LNorm = NULL;
629 GtkEntry *entryV4LSize = NULL;
630 GtkEntry *entryV4LSoundDirection = NULL;
631 const gchar *p_v4l_video_device;
632 const gchar *p_v4l_audio_device;
633 const gchar *p_v4l_norm;
634 const gchar *p_v4l_size;
635 const gchar *p_v4l_sound_direction;
638 GtkCheckButton *checkV4LMJPEG = NULL;
639 GtkSpinButton *entryV4LDecimation = NULL;
640 gboolean b_v4l_mjpeg;
641 gint i_v4l_decimation;
644 char **ppsz_options = NULL; /* list of options */
650 ppsz_options = (char **) malloc(11 *sizeof(char*));
651 if (ppsz_options == NULL)
653 msg_Err(p_intf, "No memory to allocate for v4l options.");
658 ppsz_options[i] = (char *) malloc(VLC_MAX_MRL * sizeof(char));
659 if (ppsz_options[i] == NULL)
661 msg_Err(p_intf, "No memory to allocate for v4l options string %i.", i);
662 for (i-=1; i>=0; i--)
663 free(ppsz_options[i]);
669 i_pos = snprintf( &v4l_mrl[0], 6, "v4l");
672 entryV4LChannel = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LChannel" );
673 entryV4LFrequency = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LFrequency" );
674 entryV4LSampleRate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LSampleRate" );
675 entryV4LQuality = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LQuality" );
676 entryV4LTuner = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LTuner" );
678 entryV4LVideoDevice = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LVideoDevice" );
679 entryV4LAudioDevice = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LAudioDevice" );
680 entryV4LNorm = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LNorm" );
681 entryV4LSize = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LSize" );
682 entryV4LSoundDirection = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LSoundDirection" );
684 i_v4l_channel = gtk_spin_button_get_value_as_int(entryV4LChannel);
685 i_v4l_frequency = gtk_spin_button_get_value_as_int(entryV4LFrequency);
686 i_v4l_samplerate = gtk_spin_button_get_value_as_int(entryV4LSampleRate);
687 i_v4l_quality = gtk_spin_button_get_value_as_int(entryV4LQuality);
688 i_v4l_tuner = gtk_spin_button_get_value_as_int(entryV4LTuner);
690 p_v4l_video_device = gtk_entry_get_text(GTK_ENTRY(entryV4LVideoDevice));
691 p_v4l_audio_device = gtk_entry_get_text(GTK_ENTRY(entryV4LAudioDevice));
692 p_v4l_norm = gtk_entry_get_text(GTK_ENTRY(entryV4LNorm));
693 p_v4l_size = gtk_entry_get_text(GTK_ENTRY(entryV4LSize));
694 p_v4l_sound_direction = gtk_entry_get_text(GTK_ENTRY(entryV4LSoundDirection));
696 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "%s", (char*)p_v4l_video_device );
697 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
698 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "adev=%s", (char*)p_v4l_audio_device );
699 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
700 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "norm=%s", (char*)p_v4l_norm );
701 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
702 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "size=%s", (char*)p_v4l_size );
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, "%s", (char*)p_v4l_sound_direction );
705 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
707 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "channel=%d", (int)i_v4l_channel );
708 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
709 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "frequency=%d", (int)i_v4l_frequency );
710 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
711 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "samplerate=%d", (int)i_v4l_samplerate );
712 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
713 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "quality=%d", (int)i_v4l_quality );
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, "tuner=%d", (int)i_v4l_tuner );
716 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
719 checkV4LMJPEG = (GtkCheckButton*) lookup_widget( GTK_WIDGET(button), "checkV4LMJPEG" );
720 b_v4l_mjpeg = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkV4LMJPEG));
723 entryV4LDecimation = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LDecimation" );
724 i_v4l_decimation = gtk_spin_button_get_value_as_int(entryV4LDecimation);
726 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "mjpeg:%d", (int)i_v4l_decimation );
727 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
731 PlaylistAddItem(GTK_WIDGET(button), (gchar*) &v4l_mrl, ppsz_options, i_options);
735 gboolean PlaylistEvent(GtkWidget *widget, GdkEvent *event, gpointer user_data)
741 void onPlaylistColumnsChanged(GtkTreeView *treeview, gpointer user_data)
746 gboolean onPlaylistRowSelected(GtkTreeView *treeview, gboolean start_editing, gpointer user_data)
752 void onPlaylistRow(GtkTreeView *treeview, GtkTreePath *path,
753 GtkTreeViewColumn *column, gpointer user_data)
755 intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(treeview) );
756 GtkTreeSelection *p_selection = gtk_tree_view_get_selection(treeview);
757 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
760 if( p_playlist == NULL )
765 if (gtk_tree_selection_count_selected_rows(p_selection) == 1)
767 GtkTreeModel *p_model;
771 /* This might be a directory selection */
772 p_model = gtk_tree_view_get_model(treeview);
775 msg_Err(p_intf, "PDA: Playlist model contains a NULL pointer\n" );
778 if (!gtk_tree_model_get_iter(p_model, &iter, path))
780 msg_Err( p_intf, "PDA: Playlist could not get iter from model" );
784 gtk_tree_model_get(p_model, &iter, 2, &i_row, -1);
785 playlist_Goto( p_playlist, i_row );
787 vlc_object_release( p_playlist );
791 void onUpdatePlaylist(GtkButton *button, gpointer user_data)
793 intf_thread_t * p_intf = GtkGetIntf( button );
794 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
796 GtkTreeView *p_tvplaylist = NULL;
798 if( p_playlist == NULL )
803 p_tvplaylist = (GtkTreeView*) lookup_widget( GTK_WIDGET(button), "tvPlaylist");
806 GtkListStore *p_model = NULL;
808 /* Rebuild the playlist then. */
809 p_model = gtk_list_store_new (3,
810 G_TYPE_STRING, /* Filename */
811 G_TYPE_STRING, /* Time */
812 G_TYPE_UINT); /* Hidden field */
815 PlaylistRebuildListStore(p_model, p_playlist);
816 gtk_tree_view_set_model(GTK_TREE_VIEW(p_tvplaylist), GTK_TREE_MODEL(p_model));
817 g_object_unref(p_model);
820 vlc_object_release( p_playlist );
823 void onDeletePlaylist(GtkButton *button, gpointer user_data)
825 intf_thread_t *p_intf = GtkGetIntf( button );
826 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
828 GtkTreeView *p_tvplaylist;
830 /* Delete an arbitrary item from the playlist */
831 p_tvplaylist = (GtkTreeView *) lookup_widget( GTK_WIDGET(button), "tvPlaylist" );
832 if (p_tvplaylist != NULL)
834 GList *p_rows = NULL;
836 GtkTreeModel *p_model = NULL;
837 GtkListStore *p_store = NULL;
838 GtkTreeSelection *p_selection = gtk_tree_view_get_selection(p_tvplaylist);
840 p_model = gtk_tree_view_get_model(p_tvplaylist);
843 p_rows = gtk_tree_selection_get_selected_rows(p_selection, &p_model);
845 if( g_list_length( p_rows ) )
847 /* reverse-sort so that we can delete from the furthest
848 * to the closest item to delete...
850 p_rows = g_list_reverse( p_rows );
853 for (p_node=p_rows; p_node!=NULL; p_node = p_node->next)
856 GtkTreePath *p_path = NULL;
858 p_path = (GtkTreePath *)p_node->data;
861 if (gtk_tree_model_get_iter(p_model, &iter, p_path))
865 gtk_tree_model_get(p_model, &iter, 2, &item, -1);
866 playlist_Delete(p_playlist, item);
870 g_list_foreach (p_rows, (GFunc*)gtk_tree_path_free, NULL);
871 g_list_free (p_rows);
874 /* Rebuild the playlist then. */
875 p_store = gtk_list_store_new (3,
876 G_TYPE_STRING, /* Filename */
877 G_TYPE_STRING, /* Time */
878 G_TYPE_UINT); /* Hidden field */
881 PlaylistRebuildListStore(p_store, p_playlist);
882 gtk_tree_view_set_model(GTK_TREE_VIEW(p_tvplaylist), GTK_TREE_MODEL(p_store));
883 g_object_unref(p_store);
886 vlc_object_release( p_playlist );
890 void onClearPlaylist(GtkButton *button, gpointer user_data)
892 intf_thread_t *p_intf = GtkGetIntf( button );
893 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
895 GtkTreeView *p_tvplaylist;
898 if( p_playlist == NULL )
903 for(item = p_playlist->i_size - 1; item >= 0 ;item-- )
905 playlist_Delete( p_playlist, item);
907 vlc_object_release( p_playlist );
909 // Remove all entries from the Playlist widget.
910 p_tvplaylist = (GtkTreeView*) lookup_widget( GTK_WIDGET(button), "tvPlaylist");
913 GtkTreeModel *p_play_model;
915 p_play_model = gtk_tree_view_get_model(p_tvplaylist);
918 gtk_list_store_clear(GTK_LIST_STORE(p_play_model));
924 void onPreferenceSave(GtkButton *button, gpointer user_data)
927 intf_thread_t *p_intf = GtkGetIntf( button );
929 msg_Dbg(p_intf, "Preferences Save" );
930 config_SaveConfigFile( p_intf, NULL );
935 void onPreferenceApply(GtkButton *button, gpointer user_data)
938 intf_thread_t *p_intf = GtkGetIntf( button );
940 msg_Dbg(p_intf, "Preferences Apply" );
945 void onPreferenceCancel(GtkButton *button, gpointer user_data)
948 intf_thread_t *p_intf = GtkGetIntf( button );
950 msg_Dbg(p_intf, "Preferences Cancel" );
951 config_ResetAll( p_intf );
952 /* Cancel interface changes. */
953 config_SaveConfigFile( p_intf, NULL );
958 void onAddTranscodeToPlaylist(GtkButton *button, gpointer user_data)
960 intf_thread_t *p_intf = GtkGetIntf( button );
962 GtkEntry *p_entryVideoCodec = NULL;
963 GtkSpinButton *p_entryVideoBitrate = NULL;
964 GtkSpinButton *p_entryVideoBitrateTolerance = NULL;
965 GtkSpinButton *p_entryVideoKeyFrameInterval = NULL;
966 GtkCheckButton *p_checkVideoDeinterlace = NULL;
967 GtkEntry *p_entryAudioCodec = NULL;
968 GtkSpinButton *p_entryAudioBitrate = NULL;
969 const gchar *p_video_codec;
970 gint i_video_bitrate;
971 gint i_video_bitrate_tolerance;
972 gint i_video_keyframe_interval;
973 gboolean b_video_deinterlace;
974 const gchar *p_audio_codec;
975 gint i_audio_bitrate;
977 GtkEntry *p_entryStdAccess = NULL;
978 GtkEntry *p_entryStdMuxer = NULL;
979 GtkEntry *p_entryStdURL = NULL;
980 GtkEntry *p_entryStdAnnounce = NULL;
981 GtkSpinButton *p_entryStdTTL = NULL;
982 GtkCheckButton *p_checkSAP = NULL;
983 GtkCheckButton *p_checkSLP = NULL;
984 const gchar *p_std_announce;
985 const gchar *p_std_access;
986 const gchar *p_std_muxer;
987 const gchar *p_std_url;
988 gboolean b_sap_announce;
989 gboolean b_slp_announce;
992 char **ppsz_options = NULL; /* list of options */
999 ppsz_options = (char **) malloc(3 *sizeof(char*));
1000 if (ppsz_options == NULL)
1002 msg_Err(p_intf, "No memory to allocate for v4l options.");
1007 ppsz_options[i] = (char *) malloc(VLC_MAX_MRL * sizeof(char));
1008 if (ppsz_options[i] == NULL)
1010 msg_Err(p_intf, "No memory to allocate for v4l options string %i.", i);
1011 for (i-=1; i>=0; i--)
1012 free(ppsz_options[i]);
1018 i_pos = snprintf( &mrl[0], VLC_MAX_MRL, "sout");
1021 i_pos = snprintf( &ppsz_options[i_options][0], VLC_MAX_MRL, "sout='#transcode{");
1022 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1024 p_entryVideoCodec = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryVideoCodec" );
1025 p_entryVideoBitrate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoBitrate" );
1026 p_entryVideoBitrateTolerance = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoBitrateTolerance" );
1027 p_entryVideoKeyFrameInterval = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoKeyFrameInterval" );
1029 p_video_codec = gtk_entry_get_text(GTK_ENTRY(p_entryVideoCodec));
1030 i_video_bitrate = gtk_spin_button_get_value_as_int(p_entryVideoBitrate);
1031 i_video_bitrate_tolerance = gtk_spin_button_get_value_as_int(p_entryVideoBitrateTolerance);
1032 i_video_keyframe_interval = gtk_spin_button_get_value_as_int(p_entryVideoKeyFrameInterval);
1034 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "vcodec=%s,", (char*)p_video_codec );
1035 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1036 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "vb=%d,", (int)i_video_bitrate );
1037 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1038 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "vt=%d,", (int)i_video_bitrate_tolerance );
1039 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1040 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "keyint=%d,", (int)i_video_keyframe_interval );
1041 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1043 p_checkVideoDeinterlace = (GtkCheckButton*) lookup_widget( GTK_WIDGET(button), "checkVideoDeinterlace" );
1044 b_video_deinterlace = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_checkVideoDeinterlace));
1045 if (b_video_deinterlace)
1047 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "deinterlace," );
1048 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1050 p_entryAudioCodec = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryAudioCodec" );
1051 p_entryAudioBitrate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryAudioBitrate" );
1053 p_audio_codec = gtk_entry_get_text(GTK_ENTRY(p_entryAudioCodec));
1054 i_audio_bitrate = gtk_spin_button_get_value_as_int(p_entryAudioBitrate);
1056 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "acodec=%s,", (char*)p_audio_codec );
1057 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1058 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "ab=%d,", (int)i_audio_bitrate );
1059 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1060 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "channels=1}"/*, (int)i_audio_channels*/ );
1061 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1065 i_pos = snprintf( &ppsz_options[i_options++][i_pos], VLC_MAX_MRL - i_pos, "dst=" );
1066 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1068 p_entryStdAccess = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdAccess" );
1069 p_entryStdMuxer = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdMuxer" );
1070 p_entryStdURL = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdURL" );
1071 p_entryStdAnnounce = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryAnnounceChannel" );
1072 p_entryStdTTL = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryStdTTL" );
1074 p_std_access = gtk_entry_get_text(GTK_ENTRY(p_entryStdAccess));
1075 p_std_muxer = gtk_entry_get_text(GTK_ENTRY(p_entryStdMuxer));
1076 p_std_url = gtk_entry_get_text(GTK_ENTRY(p_entryStdURL));
1077 p_std_announce = gtk_entry_get_text(GTK_ENTRY(p_entryStdAnnounce));
1078 b_sap_announce = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_checkSAP));
1079 b_slp_announce = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_checkSLP));
1081 if ( strncasecmp( (const char*)p_std_access, "display", 7 ) == 0)
1083 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "%s,", (char*)p_std_access);
1084 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, "std{access=%s,", (char*)p_std_access);
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, "mux=%s,", (char*)p_std_muxer);
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, "url=%s", (char*)p_std_url);
1093 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1095 if (strncasecmp( (const char*)p_std_access, "udp", 3)==0)
1099 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "sap=%s", (char*)p_std_announce);
1100 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1104 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "slp=%s", (char*)p_std_announce);
1105 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1108 i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "}");
1109 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1111 i_std_ttl = gtk_spin_button_get_value_as_int(p_entryStdTTL);
1113 i_pos = snprintf( &ppsz_options[i_options++][0], VLC_MAX_MRL, "ttl=%d", (int)i_std_ttl);
1114 if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1117 PlaylistAddItem(GTK_WIDGET(button), (gchar*) &mrl, ppsz_options, i_options);
1122 void onEntryStdAccessChanged(GtkEditable *editable, gpointer user_data)
1124 intf_thread_t *p_intf = GtkGetIntf( editable );
1126 GtkCheckButton *p_checkSAP = NULL;
1127 GtkCheckButton *p_checkSLP = NULL;
1128 GtkEntry *p_entryStdAccess = NULL;
1129 const gchar *p_std_access = NULL;
1130 gboolean b_announce = FALSE;
1132 p_entryStdAccess = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryStdAccess" );
1133 p_checkSAP = (GtkCheckButton*) lookup_widget( GTK_WIDGET(editable), "checkSAP" );
1134 p_checkSLP = (GtkCheckButton*) lookup_widget( GTK_WIDGET(editable), "checkSLP" );
1136 if ( (p_std_access == NULL) || (p_checkSAP == NULL) || (p_checkSLP == NULL))
1138 msg_Err( p_intf, "Access, SAP and SLP widgets not found." );
1141 p_std_access = gtk_entry_get_text(GTK_ENTRY(p_entryStdAccess));
1143 b_announce = (strncasecmp( (const char*)p_std_access, "udp", 3) == 0);
1144 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_checkSAP), b_announce);
1145 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_checkSLP), b_announce);