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