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