]> git.sesse.net Git - vlc/blob - modules/gui/pda/pda_callbacks.c
b0cc1d1f92cefcd3fc7afa08353e4a7f881ac86f
[vlc] / modules / gui / pda / pda_callbacks.c
1 /*****************************************************************************
2  * pda_callbacks.c : Callbacks for the pda Linux Gtk+ plugin.
3  *****************************************************************************
4  * Copyright (C) 2000, 2001 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Jean-Paul Saman <jpsaman _at_ videolan _dot_ org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <sys/types.h>                                              /* off_t */
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <vlc_common.h>
34 #include <vlc_input.h>
35 #include <vlc_interface.h>
36 #include <vlc_playlist.h>
37 #include <vlc_vout.h>
38
39 #include <dirent.h>
40 #include <sys/stat.h>
41 #include <unistd.h>
42 #include <pwd.h>
43 #include <grp.h>
44
45 #include <gtk/gtk.h>
46
47 #include "pda_callbacks.h"
48 #include "pda_interface.h"
49 #include "pda_support.h"
50 #include "pda.h"
51
52 #define VLC_MAX_MRL     256
53
54 static char *get_file_perms(struct stat st);
55
56 /*****************************************************************************
57  * Useful function to retrieve p_intf
58  ****************************************************************************/
59 void * __GtkGetIntf( GtkWidget * widget )
60 {
61     void *p_data;
62
63     if( GTK_IS_MENU_ITEM( widget ) )
64     {
65         /* Look for a GTK_MENU */
66         while( widget->parent && !GTK_IS_MENU( widget ) )
67         {
68             widget = widget->parent;
69         }
70
71         /* Maybe this one has the data */
72         p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" );
73         if( p_data )
74         {
75             return p_data;
76         }
77
78         /* Otherwise, the parent widget has it */
79         widget = gtk_menu_get_attach_widget( GTK_MENU( widget ) );
80     }
81
82     /* We look for the top widget */
83     widget = gtk_widget_get_toplevel( GTK_WIDGET( widget ) );
84
85     p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" );
86
87     return p_data;
88 }
89
90 static void PlaylistAddItem(GtkWidget *widget, gchar *name, char **ppsz_options, int i_size)
91 {
92     intf_thread_t *p_intf = GtkGetIntf( widget );
93     playlist_t    *p_playlist;
94     int           i_id , i_pos=0;
95     GtkTreeView   *p_tvplaylist = NULL;
96
97     p_playlist = (playlist_t *)
98              vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
99
100     if( p_playlist ==  NULL)
101     {   /* Bail out when VLC's playlist object is not found. */
102         return;
103     }
104
105     /* Add to playlist object. */
106     p_tvplaylist = (GtkTreeView *) lookup_widget( GTK_WIDGET(widget), "tvPlaylist");
107     if (p_tvplaylist)
108     {
109         GtkTreeModel *p_play_model;
110         GtkTreeIter   p_play_iter;
111
112         p_play_model = gtk_tree_view_get_model(p_tvplaylist);
113  
114         if (p_play_model)
115         {
116             int i;
117
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 !!! */
122                                     1, "no info",
123                                     2, playlist_CurrentSize(p_playlist), /* Hidden index. */
124                                     -1 );
125
126             /* Add to VLC's playlist */
127 #if 0
128             if (p_intf->p_sys->b_autoplayfile)
129             {
130                 playlist_Add( p_playlist, (const char*)name, (const char**)ppsz_options, i_size,
131                               PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END);
132             }
133             else
134 #endif
135             {
136                 i_id = playlist_AddExt( p_playlist, (const char*)name,
137                               (const char*)name,
138                               PLAYLIST_APPEND, PLAYLIST_END,
139                               (mtime_t) 0,
140                               (const char **) ppsz_options, i_pos,
141                               true, pl_Unlocked );
142             }
143
144             /* Cleanup memory */
145             for (i=0; i<i_size; i++)
146                 free(ppsz_options[i]);
147             free(ppsz_options);
148         }
149     }
150     vlc_object_release( p_playlist );
151 }
152
153 void PlaylistRebuildListStore( intf_thread_t *p_intf,
154     GtkListStore * p_list, playlist_t * p_playlist )
155 {
156     GtkTreeIter iter;
157     int         i_dummy;
158     gchar *     ppsz_text[2];
159 #if 0
160     GdkColor    red;
161     red.red     = 65535;
162     red.blue    = 0;
163     red.green   = 0;
164 #endif
165     vlc_object_lock( p_playlist );
166     for( i_dummy = 0; i_dummy < playlist_CurrentSize(p_playlist) ; i_dummy++ )
167     {
168         playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_dummy, pl_Locked );
169         if( p_item )
170         {
171             ppsz_text[0] = p_item->p_input->psz_name;
172             ppsz_text[1] = "no info";
173             gtk_list_store_append (p_list, &iter);
174             gtk_list_store_set (p_list, &iter,
175                                 0, ppsz_text[0],
176                                 1, ppsz_text[1],
177                                 2, i_dummy, /* Hidden index */
178                                 -1);
179         }
180     }
181     vlc_object_unlock( p_playlist );
182 }
183
184 /*****************************************************************
185  * Read directory helper function.
186  ****************************************************************/
187 void ReadDirectory(intf_thread_t *p_intf, GtkListStore *p_list, char *psz_dir )
188 {
189     GtkTreeIter    iter;
190     struct dirent **pp_namelist;
191     struct passwd *p_pw;
192     struct group  *p_grp;
193     struct stat    st;
194     int n=-1, status=-1;
195
196     msg_Dbg(p_intf, "Changing to dir %s", psz_dir);
197     if (psz_dir)
198     {
199        status = chdir(psz_dir);
200        if (status<0)
201           msg_Dbg(p_intf, "permision denied" );
202     }
203     n = scandir(".", &pp_namelist, 0, alphasort);
204
205     if (n<0)
206         perror("scandir");
207     else
208     {
209         int i;
210         gchar *ppsz_text[4];
211
212         if (lstat("..", &st)==0)
213         {
214             /* user, group  */
215             p_pw  = getpwuid(st.st_uid);
216             p_grp = getgrgid(st.st_gid);
217
218             /* XXX : kludge temporaire pour yopy */
219             ppsz_text[0] = "..";
220             ppsz_text[1] = get_file_perms(st);
221             ppsz_text[2] = p_pw->pw_name;
222             ppsz_text[3] = p_grp->gr_name;
223
224             /* Add a new row to the model */
225             gtk_list_store_append (p_list, &iter);
226             gtk_list_store_set (p_list, &iter,
227                                 0, ppsz_text[0],
228                                 1, ppsz_text[1],
229                                 2, st.st_size,
230                                 3, ppsz_text[2],
231                                 4, ppsz_text[3],
232                                 -1);
233
234             free(ppsz_text[1]);
235         }
236             /* kludge */
237         for (i=0; i<n; i++)
238         {
239             if ((pp_namelist[i]->d_name[0] != '.') &&
240                 (lstat(pp_namelist[i]->d_name, &st)==0))
241             {
242                 /* user, group  */
243                 p_pw  = getpwuid(st.st_uid);
244                 p_grp = getgrgid(st.st_gid);
245
246                 /* This is a list of strings. */
247                 ppsz_text[0] = pp_namelist[i]->d_name;
248                 ppsz_text[1] = get_file_perms(st);
249                 ppsz_text[2] = p_pw->pw_name;
250                 ppsz_text[3] = p_grp->gr_name;
251 #if 0
252                 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 #endif
254                 gtk_list_store_append (p_list, &iter);
255                 gtk_list_store_set (p_list, &iter,
256                                     0, ppsz_text[0],
257                                     1, ppsz_text[1],
258                                     2, st.st_size,
259                                     3, ppsz_text[2],
260                                     4, ppsz_text[3],
261                                     -1);
262
263                 free(ppsz_text[1]);
264             }
265         }
266         free(pp_namelist);
267     }
268 }
269
270 static char *get_file_perms(const struct stat st)
271 {
272     char  *psz_perm;
273
274     psz_perm = (char *) malloc(sizeof(char)*10);
275     strncpy( psz_perm, "----------", sizeof("----------"));
276
277     /* determine permission modes */
278     if (S_ISLNK(st.st_mode))
279         psz_perm[0]= 'l';
280     else if (S_ISDIR(st.st_mode))
281         psz_perm[0]= 'd';
282     else if (S_ISCHR(st.st_mode))
283         psz_perm[0]= 'c';
284     else if (S_ISBLK(st.st_mode))
285         psz_perm[0]= 'b';
286     else if (S_ISFIFO(st.st_mode))
287         psz_perm[0]= 'f';
288     else if (S_ISSOCK(st.st_mode))
289         psz_perm[0]= 's';
290     else if (S_ISREG(st.st_mode))
291         psz_perm[0]= '-';
292     else /* Unknown type is an error */
293         psz_perm[0]= '?';
294     /* Get file permissions */
295     /* User */
296     if (st.st_mode & S_IRUSR)
297         psz_perm[1]= 'r';
298     if (st.st_mode & S_IWUSR)
299         psz_perm[2]= 'w';
300     if (st.st_mode & S_IXUSR)
301     {
302         if (st.st_mode & S_ISUID)
303             psz_perm[3] = 's';
304         else
305             psz_perm[3]= 'x';
306     }
307     else if (st.st_mode & S_ISUID)
308         psz_perm[3] = 'S';
309     /* Group */
310     if (st.st_mode & S_IRGRP)
311         psz_perm[4]= 'r';
312     if (st.st_mode & S_IWGRP)
313         psz_perm[5]= 'w';
314     if (st.st_mode & S_IXGRP)
315     {
316         if (st.st_mode & S_ISGID)
317             psz_perm[6] = 's';
318         else
319             psz_perm[6]= 'x';
320     }
321     else if (st.st_mode & S_ISGID)
322         psz_perm[6] = 'S';
323     /* Other */
324     if (st.st_mode & S_IROTH)
325         psz_perm[7]= 'r';
326     if (st.st_mode & S_IWOTH)
327         psz_perm[8]= 'w';
328     if (st.st_mode & S_IXOTH)
329     {
330         /* 'sticky' bit */
331         if (st.st_mode &S_ISVTX)
332             psz_perm[9] = 't';
333         else
334             psz_perm[9]= 'x';
335     }
336     else if (st.st_mode &S_ISVTX)
337         psz_perm[9]= 'T';
338
339     return psz_perm;
340 }
341
342 /*
343  * Main interface callbacks
344  */
345
346 gboolean onPDADeleteEvent(GtkWidget *widget, GdkEvent *event, gpointer user_data)
347 {
348     intf_thread_t *p_intf = GtkGetIntf( widget );
349
350     vlc_mutex_lock( &p_intf->change_lock );
351     vlc_object_kill( p_intf->p_libvlc );
352     vlc_mutex_unlock( &p_intf->change_lock );
353     msg_Dbg( p_intf, "about to exit vlc ... signaled" );
354
355     return TRUE;
356 }
357
358 void onRewind(GtkButton *button, gpointer user_data)
359 {
360     intf_thread_t *p_intf = GtkGetIntf( button );
361
362     if (p_intf->p_sys->p_input != NULL)
363     {
364         var_SetVoid( p_intf->p_sys->p_input, "rate-slower" );
365     }
366 }
367
368 void onPause(GtkButton *button, gpointer user_data)
369 {
370     intf_thread_t *p_intf = GtkGetIntf( button );
371
372     if (p_intf->p_sys->p_input != NULL)
373     {
374         var_SetInteger( p_intf->p_sys->p_input, "state", PAUSE_S );
375     }
376 }
377
378
379 void onPlay(GtkButton *button, gpointer user_data)
380 {
381     intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) );
382     playlist_t *p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
383
384     if (p_playlist)
385     {
386         vlc_object_lock( p_playlist );
387         if (playlist_CurrentSize(p_playlist))
388         {
389             vlc_object_unlock( p_playlist );
390             playlist_Play( p_playlist );
391             gdk_window_lower( p_intf->p_sys->p_window->window );
392         }
393         else
394         {
395             vlc_object_unlock( p_playlist );
396         }
397         vlc_object_release( p_playlist );
398     }
399 }
400
401 void onStop(GtkButton *button, gpointer user_data)
402 {
403     intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) );
404     playlist_t *p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
405                                                        FIND_ANYWHERE );
406     if (p_playlist)
407     {
408         playlist_Stop( p_playlist );
409         vlc_object_release( p_playlist );
410         gdk_window_raise( p_intf->p_sys->p_window->window );
411     }
412 }
413
414 void onForward(GtkButton *button, gpointer user_data)
415 {
416     intf_thread_t *p_intf = GtkGetIntf( button );
417
418     if (p_intf->p_sys->p_input != NULL)
419     {
420         var_SetVoid( p_intf->p_sys->p_input, "rate-faster" );
421     }
422 }
423
424
425 void onAbout(GtkButton *button, gpointer user_data)
426 {
427     intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(button) );
428
429     /* Toggle notebook */
430     if (p_intf->p_sys->p_notebook)
431     {
432         gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
433         gtk_notebook_set_page(p_intf->p_sys->p_notebook,6);
434     }
435 }
436
437 gboolean SliderRelease(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
438 {
439     intf_thread_t *p_intf = GtkGetIntf( widget );
440
441     msg_Dbg( p_intf, "SliderButton Release" );
442     vlc_mutex_lock( &p_intf->change_lock );
443     p_intf->p_sys->b_slider_free = 1;
444     vlc_mutex_unlock( &p_intf->change_lock );
445
446     return TRUE;
447 }
448
449 gboolean SliderPress(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
450 {
451     intf_thread_t *p_intf = GtkGetIntf( widget );
452
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 );
457
458     return FALSE;
459 }
460
461 void SliderMove(GtkRange *range, GtkScrollType scroll, gpointer user_data)
462 {
463     intf_thread_t *p_intf = GtkGetIntf( range );
464     msg_Dbg( p_intf, "SliderButton Move" );
465 }
466
467
468 static void addSelectedToPlaylist(GtkTreeModel *model, GtkTreePath *path,
469                            GtkTreeIter *iter, gpointer *userdata)
470 {
471     gchar *psz_filename;
472
473     gtk_tree_model_get(model, iter, 0, &psz_filename, -1);
474
475     PlaylistAddItem(GTK_WIDGET(userdata), psz_filename, 0, 0);
476 }
477
478 void onFileListRow(GtkTreeView *treeview, GtkTreePath *path,
479                    GtkTreeViewColumn *column, gpointer user_data)
480 {
481     intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(treeview) );
482     GtkTreeSelection *p_selection = gtk_tree_view_get_selection(treeview);
483
484     if (gtk_tree_selection_count_selected_rows(p_selection) == 1)
485     {
486         struct stat   st;
487         GtkTreeModel *p_model;
488         GtkTreeIter   iter;
489         char         *psz_filename;
490
491         /* This might be a directory selection */
492         p_model = gtk_tree_view_get_model(treeview);
493         if (!p_model)
494         {
495             msg_Err(p_intf, "PDA: Filelist model contains a NULL pointer\n" );
496             return;
497         }
498         if (!gtk_tree_model_get_iter(p_model, &iter, path))
499         {
500             msg_Err( p_intf, "PDA: Could not get iter from model" );
501             return;
502         }
503
504         gtk_tree_model_get(p_model, &iter, 0, &psz_filename, -1);
505         if (stat((char*)psz_filename, &st)==0)
506         {
507             if (S_ISDIR(st.st_mode))
508             {
509                 GtkListStore *p_store = NULL;
510
511                 /* Get new directory listing */
512                 p_store = gtk_list_store_new (5,
513                                            G_TYPE_STRING,
514                                            G_TYPE_STRING,
515                                            G_TYPE_UINT64,
516                                            G_TYPE_STRING,
517                                            G_TYPE_STRING);
518                 if (p_store)
519                 {
520                     ReadDirectory(p_intf, p_store, psz_filename);
521
522                     /* Update TreeView with new model */
523                     gtk_tree_view_set_model(treeview, (GtkTreeModel*) p_store);
524                     g_object_unref(p_store);
525                 }
526             }
527         }
528     }
529 }
530
531 void onAddFileToPlaylist(GtkButton *button, gpointer user_data)
532 {
533     GtkTreeView       *p_treeview = NULL;
534
535     p_treeview = (GtkTreeView *) lookup_widget( GTK_WIDGET(button), "tvFileList");
536     if (p_treeview)
537     {
538         GtkTreeSelection *p_selection = gtk_tree_view_get_selection(p_treeview);
539
540         gtk_tree_selection_selected_foreach(p_selection, (GtkTreeSelectionForeachFunc) &addSelectedToPlaylist, (gpointer) p_treeview);
541     }
542 }
543
544
545 void NetworkBuildMRL(GtkEditable *editable, gpointer user_data)
546 {
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;
556     gint           i_mrlPort;
557     char           text[VLC_MAX_MRL];
558     int            i_pos = 0;
559
560     p_entryMRL = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryMRL" );
561
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" );
566
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));
571
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)
575     {
576         i_pos += snprintf( &text[i_pos], VLC_MAX_MRL - i_pos, "@" );
577     }
578     i_pos += snprintf( &text[i_pos], VLC_MAX_MRL - i_pos, "%s:%d", (char*)psz_mrlAddress, (int)i_mrlPort );
579
580     if (i_pos >= VLC_MAX_MRL)
581     {
582         text[VLC_MAX_MRL-1]='\0';
583         msg_Err( p_intf, "Media Resource Locator is truncated to: %s", text);
584     }
585
586     gtk_entry_set_text(p_entryMRL,text);
587 }
588
589 void onAddNetworkPlaylist(GtkButton *button, gpointer user_data)
590 {
591     intf_thread_t  *p_intf = GtkGetIntf( button );
592
593     GtkEntry       *p_mrl = NULL;
594     GtkCheckButton *p_network_transcode = NULL;
595     gboolean        b_network_transcode;
596     const gchar    *psz_mrl_name;
597
598     p_mrl = (GtkEntry*) lookup_widget(GTK_WIDGET(button),"entryMRL" );
599     psz_mrl_name = gtk_entry_get_text(p_mrl);
600
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)
604     {
605         msg_Dbg( p_intf, "Network transcode option selected." );
606         onAddTranscodeToPlaylist(button, (gchar *)psz_mrl_name);
607     }
608     else
609     {
610         msg_Dbg( p_intf, "Network receiving selected." );
611         PlaylistAddItem(GTK_WIDGET(button), (gchar *)psz_mrl_name, 0, 0);
612     }
613 }
614
615
616 void onAddCameraToPlaylist(GtkButton *button, gpointer user_data)
617 {
618     intf_thread_t *p_intf = GtkGetIntf( button );
619
620     GtkSpinButton *entryV4LChannel = NULL;
621     GtkSpinButton *entryV4LFrequency = NULL;
622     GtkSpinButton *entryV4LSampleRate = NULL;
623     GtkSpinButton *entryV4LQuality = NULL;
624     GtkSpinButton *entryV4LTuner = NULL;
625     gint    i_v4l_channel;
626     gint    i_v4l_frequency;
627     gint    i_v4l_samplerate;
628     gint    i_v4l_quality;
629     gint    i_v4l_tuner;
630
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;
641
642     /* MJPEG only */
643     GtkCheckButton *checkV4LMJPEG = NULL;
644     GtkSpinButton  *entryV4LDecimation = NULL;
645     gboolean        b_v4l_mjpeg;
646     gint            i_v4l_decimation;
647     /* end MJPEG only */
648
649     GtkCheckButton  *p_check_v4l_transcode = NULL;
650     gboolean         b_v4l_transcode;
651  
652     char **ppsz_options = NULL; /* list of options */
653     int  i_options=0;
654     char v4l_mrl[6];
655     int i_pos;
656     int i;
657
658     ppsz_options = (char **) malloc(11 *sizeof(char*));
659     if (ppsz_options == NULL)
660     {
661         msg_Err(p_intf, "No memory to allocate for v4l options.");
662         return;
663     }
664     for (i=0; i<11; i++)
665     {
666         ppsz_options[i] = (char *) malloc(VLC_MAX_MRL * sizeof(char));
667         if (ppsz_options[i] == NULL)
668         {
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]);
672             free(ppsz_options);
673             return;
674         }
675     }
676
677     i_pos = snprintf( &v4l_mrl[0], 6, "v4l");
678     v4l_mrl[5]='\0';
679
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" );
685
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" );
691
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);
697
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));
703
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';
714
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';
725
726     /* MJPEG only */
727     checkV4LMJPEG      = (GtkCheckButton*) lookup_widget( GTK_WIDGET(button), "checkV4LMJPEG" );
728     b_v4l_mjpeg = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkV4LMJPEG));
729     if (b_v4l_mjpeg)
730     {
731         entryV4LDecimation = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LDecimation" );
732         i_v4l_decimation = gtk_spin_button_get_value_as_int(entryV4LDecimation);
733
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';
736     }
737     /* end MJPEG only */
738
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));
741     if (b_v4l_transcode)
742     {
743         msg_Dbg( p_intf, "Camera transcode option selected." );
744         onAddTranscodeToPlaylist(button, (gchar *)v4l_mrl);
745     }
746     else
747     {
748         msg_Dbg( p_intf, "Camera reception option selected." );
749         PlaylistAddItem(GTK_WIDGET(button), (gchar*) &v4l_mrl, ppsz_options, i_options);
750     }
751 }
752
753
754 gboolean PlaylistEvent(GtkWidget *widget, GdkEvent *event, gpointer user_data)
755 {
756     return FALSE;
757 }
758
759
760 void onPlaylistColumnsChanged(GtkTreeView *treeview, gpointer user_data)
761 {
762 }
763
764
765 gboolean onPlaylistRowSelected(GtkTreeView *treeview, gboolean start_editing, gpointer user_data)
766 {
767     return FALSE;
768 }
769
770
771 void onPlaylistRow(GtkTreeView *treeview, GtkTreePath *path,
772                    GtkTreeViewColumn *column, gpointer user_data)
773 {
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,
777                                                        FIND_ANYWHERE );
778
779     if( p_playlist == NULL )
780     {
781         return; // FALSE;
782     }
783
784     if (gtk_tree_selection_count_selected_rows(p_selection) == 1)
785     {
786         GtkTreeModel *p_model;
787         GtkTreeIter   iter;
788         int           i_row;
789         int           i_skip;
790
791         /* This might be a directory selection */
792         p_model = gtk_tree_view_get_model(treeview);
793         if (!p_model)
794         {
795             msg_Err(p_intf, "PDA: Playlist model contains a NULL pointer\n" );
796             return;
797         }
798         if (!gtk_tree_model_get_iter(p_model, &iter, path))
799         {
800             msg_Err( p_intf, "PDA: Playlist could not get iter from model" );
801             return;
802         }
803
804         gtk_tree_model_get(p_model, &iter, 2, &i_row, -1);
805         i_skip = i_row - p_playlist->i_current_index;
806         playlist_Skip( p_playlist, i_skip );
807     }
808     vlc_object_release( p_playlist );
809 }
810
811
812 void onUpdatePlaylist(GtkButton *button, gpointer user_data)
813 {
814     intf_thread_t *  p_intf = GtkGetIntf( button );
815     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
816                                                        FIND_ANYWHERE );
817     GtkTreeView *p_tvplaylist = NULL;
818
819     if( p_playlist == NULL )
820     {
821         return;
822     }
823
824     p_tvplaylist = (GtkTreeView*) lookup_widget( GTK_WIDGET(button), "tvPlaylist");
825     if (p_tvplaylist)
826     {
827         GtkListStore *p_model = NULL;
828
829         /* Rebuild the playlist then. */
830         p_model = gtk_list_store_new (3,
831                     G_TYPE_STRING, /* Filename */
832                     G_TYPE_STRING, /* Time */
833                     G_TYPE_UINT);  /* Hidden field */
834         if (p_model)
835         {
836             PlaylistRebuildListStore(p_intf, p_model, p_playlist);
837             gtk_tree_view_set_model(GTK_TREE_VIEW(p_tvplaylist), GTK_TREE_MODEL(p_model));
838             g_object_unref(p_model);
839         }
840     }
841     vlc_object_release( p_playlist );
842 }
843
844 static void deleteItemFromPlaylist(gpointer data, gpointer user_data)
845 {
846     gtk_tree_path_free((GtkTreePath*) data); // removing an item.
847 }
848
849 void onDeletePlaylist(GtkButton *button, gpointer user_data)
850 {
851     intf_thread_t *p_intf = GtkGetIntf( button );
852     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
853                                                        FIND_ANYWHERE );
854     GtkTreeView    *p_tvplaylist;
855
856     /* Delete an arbitrary item from the playlist */
857     p_tvplaylist = (GtkTreeView *) lookup_widget( GTK_WIDGET(button), "tvPlaylist" );
858     if (p_tvplaylist != NULL)
859     {
860         GList *p_rows = NULL;
861         GList *p_node;
862         GtkTreeModel *p_model = NULL;
863         GtkListStore *p_store = NULL;
864         GtkTreeSelection *p_selection = gtk_tree_view_get_selection(p_tvplaylist);
865
866         p_model = gtk_tree_view_get_model(p_tvplaylist);
867         if (p_model)
868         {
869             p_rows = gtk_tree_selection_get_selected_rows(p_selection, &p_model);
870
871             if( g_list_length( p_rows ) )
872             {
873                 /* reverse-sort so that we can delete from the furthest
874                  * to the closest item to delete...
875                  */
876                 p_rows = g_list_reverse( p_rows );
877             }
878
879             for (p_node=p_rows; p_node!=NULL; p_node = p_node->next)
880             {
881                 GtkTreeIter iter;
882                 GtkTreePath *p_path = NULL;
883
884                 p_path = (GtkTreePath *)p_node->data;
885                 if (p_path)
886                 {
887                     if (gtk_tree_model_get_iter(p_model, &iter, p_path))
888                     {
889                         gint item;
890
891                         gtk_tree_model_get(p_model, &iter, 2, &item, -1);
892                         msg_Err( p_playlist, "PDA delete broken");
893                     }
894                 }
895             }
896 #if 0
897             g_list_foreach (p_rows, (GFunc*)gtk_tree_path_free, NULL);
898 #endif /* Testing the next line */
899             g_list_foreach (p_rows, deleteItemFromPlaylist, NULL);
900             g_list_free (p_rows);
901         }
902
903         /* Rebuild the playlist then. */
904         p_store = gtk_list_store_new (3,
905                     G_TYPE_STRING, /* Filename */
906                     G_TYPE_STRING, /* Time */
907                     G_TYPE_UINT);  /* Hidden field */
908         if (p_store)
909         {
910             PlaylistRebuildListStore(p_intf, p_store, p_playlist);
911             gtk_tree_view_set_model(GTK_TREE_VIEW(p_tvplaylist), GTK_TREE_MODEL(p_store));
912             g_object_unref(p_store);
913         }
914     }
915     vlc_object_release( p_playlist );
916 }
917
918
919 void onClearPlaylist(GtkButton *button, gpointer user_data)
920 {
921     intf_thread_t *p_intf = GtkGetIntf( button );
922     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
923                                                        FIND_ANYWHERE );
924     GtkTreeView    *p_tvplaylist;
925     int item;
926
927     if( p_playlist == NULL )
928     {
929         return;
930     }
931
932     for(item = playlist_CurrentSize(p_playlist) - 1; item >= 0 ;item-- )
933     {
934         msg_Err( p_playlist, "fix pda delete" );
935     }
936     vlc_object_release( p_playlist );
937
938     // Remove all entries from the Playlist widget.
939     p_tvplaylist = (GtkTreeView*) lookup_widget( GTK_WIDGET(button), "tvPlaylist");
940     if (p_tvplaylist)
941     {
942         GtkTreeModel *p_play_model;
943
944         p_play_model = gtk_tree_view_get_model(p_tvplaylist);
945         if (p_play_model)
946         {
947             gtk_list_store_clear(GTK_LIST_STORE(p_play_model));
948         }
949     }
950 }
951
952
953 void onPreferenceSave(GtkButton *button, gpointer user_data)
954 {
955 #if 0
956     intf_thread_t *p_intf = GtkGetIntf( button );
957
958     msg_Dbg(p_intf, "Preferences Save" );
959     config_SaveConfigFile( p_intf, NULL );
960 #endif
961 }
962
963
964 void onPreferenceApply(GtkButton *button, gpointer user_data)
965 {
966 #if 0
967     intf_thread_t *p_intf = GtkGetIntf( button );
968
969     msg_Dbg(p_intf, "Preferences Apply" );
970 #endif
971 }
972
973
974 void onPreferenceCancel(GtkButton *button, gpointer user_data)
975 {
976 #if 0
977     intf_thread_t *p_intf = GtkGetIntf( button );
978
979     msg_Dbg(p_intf, "Preferences Cancel" );
980     config_ResetAll( p_intf );
981     /* Cancel interface changes. */
982     config_SaveConfigFile( p_intf, NULL );
983 #endif
984 }
985
986
987 void onAddTranscodeToPlaylist(GtkButton *button, gpointer user_data)
988 {
989     intf_thread_t *p_intf = GtkGetIntf( button );
990
991     GtkEntry       *p_entryVideoCodec = NULL;
992     GtkSpinButton  *p_entryVideoBitrate = NULL;
993     GtkSpinButton  *p_entryVideoBitrateTolerance = NULL;
994     GtkSpinButton  *p_entryVideoKeyFrameInterval = NULL;
995     GtkCheckButton *p_checkVideoDeinterlace = NULL;
996     GtkEntry       *p_entryAudioCodec = NULL;
997     GtkSpinButton  *p_entryAudioBitrate = NULL;
998     const gchar    *p_video_codec;
999     gint            i_video_bitrate;
1000     gint            i_video_bitrate_tolerance;
1001     gint            i_video_keyframe_interval;
1002     gboolean        b_video_deinterlace;
1003     const gchar    *p_audio_codec;
1004     gint            i_audio_bitrate;
1005
1006     GtkEntry       *p_entryStdAccess = NULL;
1007     GtkEntry       *p_entryStdMuxer = NULL;
1008     GtkEntry       *p_entryStdURL = NULL;
1009     GtkEntry       *p_entryStdAnnounce = NULL;
1010     GtkSpinButton  *p_entryStdTTL = NULL;
1011     GtkCheckButton *p_checkSAP = NULL;
1012     GtkCheckButton *p_checkSLP = NULL;
1013     const gchar    *p_std_announce;
1014     const gchar    *p_std_access;
1015     const gchar    *p_std_muxer;
1016     const gchar    *p_std_url;
1017     gboolean        b_sap_announce;
1018     gboolean        b_slp_announce;
1019     gint            i_std_ttl;
1020
1021     char **ppsz_options = NULL; /* list of options */
1022     int  i_options=0;
1023     int  i;
1024
1025     gchar mrl[7];
1026     int   i_pos;
1027
1028     ppsz_options = (char **) malloc(3 *sizeof(char*));
1029     if (ppsz_options == NULL)
1030     {
1031         msg_Err(p_intf, "No memory to allocate for v4l options.");
1032         return;
1033     }
1034     for (i=0; i<3; i++)
1035     {
1036         ppsz_options[i] = (char *) malloc(VLC_MAX_MRL * sizeof(char));
1037         if (ppsz_options[i] == NULL)
1038         {
1039             msg_Err(p_intf, "No memory to allocate for v4l options string %i.", i);
1040             for (i-=1; i>=0; i--)
1041                 free(ppsz_options[i]);
1042             free(ppsz_options);
1043             return;
1044         }
1045     }
1046
1047     /* Update the playlist */
1048     playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1049     if( p_playlist == NULL ) return;
1050
1051     /* Get all the options. */
1052     i_pos = snprintf( &mrl[0], VLC_MAX_MRL, "sout");
1053     mrl[6] = '\0';
1054     /* option 1 */
1055     i_pos = snprintf( &ppsz_options[i_options][0], VLC_MAX_MRL, "sout='#transcode{");
1056     if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1057
1058     p_entryVideoCodec   = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryVideoCodec" );
1059     p_entryVideoBitrate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoBitrate" );
1060     p_entryVideoBitrateTolerance = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoBitrateTolerance" );
1061     p_entryVideoKeyFrameInterval = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoKeyFrameInterval" );
1062  
1063     p_video_codec = gtk_entry_get_text(GTK_ENTRY(p_entryVideoCodec));
1064     i_video_bitrate = gtk_spin_button_get_value_as_int(p_entryVideoBitrate);
1065     i_video_bitrate_tolerance = gtk_spin_button_get_value_as_int(p_entryVideoBitrateTolerance);
1066     i_video_keyframe_interval = gtk_spin_button_get_value_as_int(p_entryVideoKeyFrameInterval);
1067  
1068     i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "vcodec=%s,", (char*)p_video_codec );
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, "vb=%d,", (int)i_video_bitrate );
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, "vt=%d,", (int)i_video_bitrate_tolerance );
1073     if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1074     i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "keyint=%d,", (int)i_video_keyframe_interval );
1075     if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1076
1077     p_checkVideoDeinterlace = (GtkCheckButton*) lookup_widget( GTK_WIDGET(button), "checkVideoDeinterlace" );
1078     b_video_deinterlace = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_checkVideoDeinterlace));
1079     if (b_video_deinterlace)
1080     {
1081         i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "deinterlace," );
1082         if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1083     }
1084     p_entryAudioCodec   = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryAudioCodec" );
1085     p_entryAudioBitrate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryAudioBitrate" );
1086
1087     p_audio_codec = gtk_entry_get_text(GTK_ENTRY(p_entryAudioCodec));
1088     i_audio_bitrate = gtk_spin_button_get_value_as_int(p_entryAudioBitrate);
1089
1090     i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "acodec=%s,", (char*)p_audio_codec );
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, "ab=%d,", (int)i_audio_bitrate );
1093     if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1094     i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "channels=1}"/*, (int)i_audio_channels*/ );
1095     if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1096
1097     /* option 2 */
1098     i_pos = 0;
1099     i_pos = snprintf( &ppsz_options[i_options++][i_pos], VLC_MAX_MRL - i_pos, "#" );
1100     if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1101
1102     p_entryStdAccess = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdAccess" );
1103     p_entryStdMuxer  = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdMuxer" );
1104     p_entryStdURL = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdURL" );
1105     p_entryStdAnnounce = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryAnnounceChannel" );
1106     p_entryStdTTL = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryStdTTL" );
1107
1108     p_std_access = gtk_entry_get_text(GTK_ENTRY(p_entryStdAccess));
1109     p_std_muxer = gtk_entry_get_text(GTK_ENTRY(p_entryStdMuxer));
1110     p_std_url = gtk_entry_get_text(GTK_ENTRY(p_entryStdURL));
1111     p_std_announce = gtk_entry_get_text(GTK_ENTRY(p_entryStdAnnounce));
1112     b_sap_announce = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_checkSAP));
1113     b_slp_announce = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_checkSLP));
1114
1115     i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "std{access=%s,", (char*)p_std_access);
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, "mux=%s,", (char*)p_std_muxer);
1118     if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1119     i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "dst=%s", (char*)p_std_url);
1120     if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1121
1122     if (strncasecmp( (const char*)p_std_access, "udp", 3)==0)
1123     {
1124         if (b_sap_announce)
1125         {
1126             i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "sap=%s", (char*)p_std_announce);
1127             if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1128         }
1129         if (b_slp_announce)
1130         {
1131             i_pos += snprintf( &ppsz_options[i_options][i_pos], VLC_MAX_MRL - i_pos, "slp=%s", (char*)p_std_announce);
1132             if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1133         }
1134     }
1135
1136     i_std_ttl = gtk_spin_button_get_value_as_int(p_entryStdTTL);
1137
1138     i_pos += snprintf( &ppsz_options[i_options++][i_pos], VLC_MAX_MRL - i_pos, "ttl=%d}", (int)i_std_ttl);
1139     if (i_pos>=VLC_MAX_MRL) ppsz_options[i_options][VLC_MAX_MRL-1] = '\0';
1140
1141     if (user_data != NULL)
1142     {
1143       msg_Dbg(p_intf, "Adding transcoding options to playlist item." );
1144     }
1145     else
1146     {
1147       msg_Dbg(p_intf, "Adding --sout to playlist." );
1148       PlaylistAddItem(GTK_WIDGET(button), (gchar*) &mrl, ppsz_options, i_options);
1149     }
1150 }
1151
1152 void onEntryStdAccessChanged(GtkEditable *editable, gpointer user_data)
1153 {
1154     intf_thread_t *p_intf = GtkGetIntf( editable );
1155
1156     GtkCheckButton *p_checkSAP = NULL;
1157     GtkCheckButton *p_checkSLP = NULL;
1158     GtkEntry       *p_entryStdAccess = NULL;
1159     const gchar    *p_std_access = NULL;
1160     gboolean        b_announce = FALSE;
1161
1162     p_entryStdAccess = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryStdAccess" );
1163     p_checkSAP = (GtkCheckButton*) lookup_widget( GTK_WIDGET(editable), "checkSAP" );
1164     p_checkSLP = (GtkCheckButton*) lookup_widget( GTK_WIDGET(editable), "checkSLP" );
1165
1166     if ( (p_std_access == NULL) || (p_checkSAP == NULL) || (p_checkSLP == NULL))
1167     {
1168         msg_Err( p_intf, "Access, SAP and SLP widgets not found." );
1169         return;
1170     }
1171     p_std_access = gtk_entry_get_text(GTK_ENTRY(p_entryStdAccess));
1172
1173     b_announce = (strncasecmp( (const char*)p_std_access, "udp", 3) == 0);
1174     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_checkSAP), b_announce);
1175     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p_checkSLP), b_announce);
1176 }
1177