pda_callbacks.c 29.4 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * pda_callbacks.c : Callbacks for the pda Linux Gtk+ plugin.
 *****************************************************************************
 * Copyright (C) 2000, 2001 VideoLAN
Jean-Paul Saman's avatar
Jean-Paul Saman committed
5
 * $Id: pda_callbacks.c,v 1.16 2003/11/25 20:01:08 jpsaman Exp $
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
 *
 * Authors: Jean-Paul Saman <jpsaman@wxs.nl>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#include <sys/types.h>                                              /* off_t */
#include <stdlib.h>
#include <vlc/vlc.h>
#include <vlc/intf.h>
#include <vlc/vout.h>

#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
Jean-Paul Saman's avatar
Jean-Paul Saman committed
38 39
#include <pwd.h>
#include <grp.h>
40 41 42 43 44 45 46 47 48 49 50 51

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <gtk/gtk.h>

#include "pda_callbacks.h"
#include "pda_interface.h"
#include "pda_support.h"
#include "pda.h"

Jean-Paul Saman's avatar
Jean-Paul Saman committed
52 53
#define VLC_MAX_MRL     256

Jean-Paul Saman's avatar
Jean-Paul Saman committed
54
static char *get_file_perms(struct stat st);
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89

/*****************************************************************************
 * Useful function to retrieve p_intf
 ****************************************************************************/
void * E_(__GtkGetIntf)( GtkWidget * widget )
{
    void *p_data;

    if( GTK_IS_MENU_ITEM( widget ) )
    {
        /* Look for a GTK_MENU */
        while( widget->parent && !GTK_IS_MENU( widget ) )
        {
            widget = widget->parent;
        }

        /* Maybe this one has the data */
        p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" );
        if( p_data )
        {
            return p_data;
        }

        /* Otherwise, the parent widget has it */
        widget = gtk_menu_get_attach_widget( GTK_MENU( widget ) );
    }

    /* We look for the top widget */
    widget = gtk_widget_get_toplevel( GTK_WIDGET( widget ) );

    p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" );

    return p_data;
}

Jean-Paul Saman's avatar
Jean-Paul Saman committed
90
void PlaylistAddItem(GtkWidget *widget, gchar *name)
Jean-Paul Saman's avatar
Jean-Paul Saman committed
91
{
Jean-Paul Saman's avatar
Jean-Paul Saman committed
92 93 94 95 96 97 98 99 100 101 102
    intf_thread_t *p_intf = GtkGetIntf( widget );
    playlist_t    *p_playlist;
    GtkTreeView   *p_tvplaylist = NULL;

    p_playlist = (playlist_t *)
             vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );

    if( p_playlist ==  NULL)
    {   /* Bail out when VLC's playlist object is not found. */
        return;
    }
Jean-Paul Saman's avatar
Jean-Paul Saman committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120

    /* Add to playlist object. */
    p_tvplaylist = (GtkTreeView *) lookup_widget( GTK_WIDGET(widget), "tvPlaylist");
    if (p_tvplaylist)
    {
        GtkTreeModel *p_play_model;
        GtkTreeIter   p_play_iter;

        p_play_model = gtk_tree_view_get_model(p_tvplaylist);

        if (p_play_model)
        {
            /* Add a new row to the playlist treeview model */
            gtk_list_store_append (GTK_LIST_STORE(p_play_model), &p_play_iter);
            gtk_list_store_set (GTK_LIST_STORE(p_play_model), &p_play_iter,
                                    0, name,   /* Add path to it !!! */
                                    1, "no info",
                                    -1 );
Jean-Paul Saman's avatar
Jean-Paul Saman committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

            msg_Dbg( p_intf, "Adding files to playlist ...");
            /* Add to VLC's playlist */
#if 0
            if (p_intf->p_sys->b_autoplayfile)
            {
                playlist_Add( p_playlist, (char*)name, 0, 0,
                              PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END);
            }
            else
            {
                playlist_Add( p_playlist, (char*)name, 0, 0,
                              PLAYLIST_APPEND, PLAYLIST_END );
            }
#endif
            msg_Dbg( p_intf, "done");
Jean-Paul Saman's avatar
Jean-Paul Saman committed
137 138
        }
    }
Jean-Paul Saman's avatar
Jean-Paul Saman committed
139
    vlc_object_release(  p_playlist );
Jean-Paul Saman's avatar
Jean-Paul Saman committed
140 141
}

142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
void PlaylistRebuildListStore( GtkListStore * p_list, playlist_t * p_playlist )
{
    GtkTreeIter iter;
    int         i_dummy;
    gchar *     ppsz_text[2];
    GdkColor    red;
    red.red     = 65535;
    red.blue    = 0;
    red.green   = 0;

    vlc_mutex_lock( &p_playlist->object_lock );
    for( i_dummy = p_playlist->i_size ; i_dummy-- ; )
    {
        ppsz_text[0] = p_playlist->pp_items[i_dummy]->psz_name;
        ppsz_text[1] = "no info";
        gtk_list_store_append (p_list, &iter);
        gtk_list_store_set (p_list, &iter,
                            0, ppsz_text[0],
                            1, ppsz_text[1],
                            -1);
    }
    vlc_mutex_unlock( &p_playlist->object_lock );
}

/*****************************************************************
 * Read directory helper function.
 ****************************************************************/
Jean-Paul Saman's avatar
Jean-Paul Saman committed
169
void ReadDirectory(intf_thread_t *p_intf, GtkListStore *p_list, char *psz_dir )
170
{
Jean-Paul Saman's avatar
Jean-Paul Saman committed
171
    GtkTreeIter    iter;
172
    struct dirent **namelist;
Jean-Paul Saman's avatar
Jean-Paul Saman committed
173 174 175
    struct passwd *pw;
    struct group  *grp;
    struct stat    st;
176 177
    int n=-1, status=-1;

Jean-Paul Saman's avatar
Jean-Paul Saman committed
178
    msg_Dbg(p_intf, "Changing to dir %s", psz_dir);
179 180 181 182
    if (psz_dir)
    {
       status = chdir(psz_dir);
       if (status<0)
Jean-Paul Saman's avatar
Jean-Paul Saman committed
183
          msg_Dbg(p_intf, "permision denied" );
184 185 186 187 188 189 190 191
    }
    n = scandir(".", &namelist, 0, alphasort);

    if (n<0)
        perror("scandir");
    else
    {
        int i;
Jean-Paul Saman's avatar
Jean-Paul Saman committed
192
        gchar *ppsz_text[4];
193

Jean-Paul Saman's avatar
Jean-Paul Saman committed
194
        if (lstat("..", &st)==0)
195
        {
Jean-Paul Saman's avatar
Jean-Paul Saman committed
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
            /* user, group  */
            pw  = getpwuid(st.st_uid);
            grp = getgrgid(st.st_gid);

            /* XXX : kludge temporaire pour yopy */
            ppsz_text[0] = "..";
            ppsz_text[1] = get_file_perms(st);
            ppsz_text[2] = pw->pw_name;
            ppsz_text[3] = grp->gr_name;

            /* Add a new row to the model */
            gtk_list_store_append (p_list, &iter);
            gtk_list_store_set (p_list, &iter,
                                0, ppsz_text[0],
                                1, ppsz_text[1],
                                2, st.st_size,
                                3, ppsz_text[2],
                                4, ppsz_text[3],
                                -1);

            if (ppsz_text[1]) free(ppsz_text[1]);
        }
            /* kludge */
        for (i=0; i<n; i++)
        {           
            if ((namelist[i]->d_name[0] != '.') &&
                (lstat(namelist[i]->d_name, &st)==0))
223
            {
Jean-Paul Saman's avatar
Jean-Paul Saman committed
224 225 226 227
                /* user, group  */
                pw  = getpwuid(st.st_uid);
                grp = getgrgid(st.st_gid);

228 229
                /* This is a list of strings. */
                ppsz_text[0] = namelist[i]->d_name;
Jean-Paul Saman's avatar
Jean-Paul Saman committed
230 231 232 233 234
                ppsz_text[1] = get_file_perms(st);
                ppsz_text[2] = pw->pw_name;
                ppsz_text[3] = grp->gr_name;
#if 0
                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] );
Jean-Paul Saman's avatar
Jean-Paul Saman committed
235
#endif
236 237 238 239
                gtk_list_store_append (p_list, &iter);
                gtk_list_store_set (p_list, &iter,
                                    0, ppsz_text[0],
                                    1, ppsz_text[1],
Jean-Paul Saman's avatar
Jean-Paul Saman committed
240
                                    2, st.st_size,
Jean-Paul Saman's avatar
Jean-Paul Saman committed
241 242
                                    3, ppsz_text[2],
                                    4, ppsz_text[3],
243
                                    -1);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
244 245

                if (ppsz_text[1]) free(ppsz_text[1]);
246 247 248 249 250 251
            }
        }
        free(namelist);
    }
}

Jean-Paul Saman's avatar
Jean-Paul Saman committed
252
static char *get_file_perms(const struct stat st)
253
{
Jean-Paul Saman's avatar
Jean-Paul Saman committed
254
    char  *perm;
255 256 257

    perm = (char *) malloc(sizeof(char)*10);
    strncpy( perm, "----------", sizeof("----------"));
Jean-Paul Saman's avatar
Jean-Paul Saman committed
258

Jean-Paul Saman's avatar
Jean-Paul Saman committed
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
    /* determine permission modes */
    if (S_ISLNK(st.st_mode))
        perm[0]= 'l';
    else if (S_ISDIR(st.st_mode))
        perm[0]= 'd';
    else if (S_ISCHR(st.st_mode))
        perm[0]= 'c';
    else if (S_ISBLK(st.st_mode))
        perm[0]= 'b';
    else if (S_ISFIFO(st.st_mode))
        perm[0]= 'f';
    else if (S_ISSOCK(st.st_mode))
        perm[0]= 's';
    else if (S_ISREG(st.st_mode))
        perm[0]= '-';
    else /* Unknown type is an error */
        perm[0]= '?';
    /* Get file permissions */
    /* User */
    if (st.st_mode & S_IRUSR)
        perm[1]= 'r';
    if (st.st_mode & S_IWUSR)
        perm[2]= 'w';
    if (st.st_mode & S_IXUSR)
    {
        if (st.st_mode & S_ISUID)
            perm[3] = 's';
        else
            perm[3]= 'x';
    }
    else if (st.st_mode & S_ISUID)
        perm[3] = 'S';
    /* Group */
    if (st.st_mode & S_IRGRP)
        perm[4]= 'r';
    if (st.st_mode & S_IWGRP)
        perm[5]= 'w';
    if (st.st_mode & S_IXGRP)
    {
        if (st.st_mode & S_ISGID)
            perm[6] = 's';
        else
            perm[6]= 'x';
302
    }
Jean-Paul Saman's avatar
Jean-Paul Saman committed
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
    else if (st.st_mode & S_ISGID)
        perm[6] = 'S';
    /* Other */
    if (st.st_mode & S_IROTH)
        perm[7]= 'r';
    if (st.st_mode & S_IWOTH)
        perm[8]= 'w';
    if (st.st_mode & S_IXOTH)
    {
        // 'sticky' bit
        if (st.st_mode &S_ISVTX)
            perm[9] = 't';
        else
            perm[9]= 'x';
    }
    else if (st.st_mode &S_ISVTX)
        perm[9]= 'T';

321 322 323 324 325 326 327 328 329 330 331 332 333 334
    return perm;
}

/*
 * Main interface callbacks
 */

gboolean
onPDADeleteEvent                       (GtkWidget       *widget,
                                        GdkEvent        *event,
                                        gpointer         user_data)
{
    intf_thread_t *p_intf = GtkGetIntf( widget );

Jean-Paul Saman's avatar
Jean-Paul Saman committed
335
    msg_Dbg( p_intf, "about to exit vlc ... " );
336 337 338
    vlc_mutex_lock( &p_intf->change_lock );
    p_intf->p_vlc->b_die = VLC_TRUE;
    vlc_mutex_unlock( &p_intf->change_lock );
Jean-Paul Saman's avatar
Jean-Paul Saman committed
339
    msg_Dbg( p_intf, "about to exit vlc ... signalled" );
340 341 342 343 344 345 346 347 348 349 350

    return TRUE;
}


void
onRewind                               (GtkButton       *button,
                                        gpointer         user_data)
{
    intf_thread_t *  p_intf = GtkGetIntf( button );

Jean-Paul Saman's avatar
Jean-Paul Saman committed
351
    if (p_intf->p_sys->p_input != NULL)
352 353 354 355 356 357 358 359 360 361 362 363
    {
        input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_SLOWER );
    }
}


void
onPause                                (GtkButton       *button,
                                        gpointer         user_data)
{
    intf_thread_t *  p_intf = GtkGetIntf( button );

Jean-Paul Saman's avatar
Jean-Paul Saman committed
364
    if (p_intf->p_sys->p_input != NULL)
365 366 367 368 369 370 371 372 373 374
    {
        input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );
    }
}


void
onPlay                                 (GtkButton       *button,
                                        gpointer         user_data)
{
Jean-Paul Saman's avatar
Jean-Paul Saman committed
375 376 377
    intf_thread_t *  p_intf = GtkGetIntf( GTK_WIDGET( button ) );
    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );

Jean-Paul Saman's avatar
Jean-Paul Saman committed
378
    if (p_playlist)
Jean-Paul Saman's avatar
Jean-Paul Saman committed
379 380
    {
        vlc_mutex_lock( &p_playlist->object_lock );
Jean-Paul Saman's avatar
Jean-Paul Saman committed
381
        if (p_playlist->i_size)
Jean-Paul Saman's avatar
Jean-Paul Saman committed
382 383 384 385 386 387 388 389 390
        {
            vlc_mutex_unlock( &p_playlist->object_lock );
            playlist_Play( p_playlist );
        }
        else
        {
            vlc_mutex_unlock( &p_playlist->object_lock );
        }
        vlc_object_release( p_playlist );
391 392 393 394 395 396 397 398 399 400 401
    }
}


void
onStop                                 (GtkButton       *button,
                                        gpointer         user_data)
{
    intf_thread_t *  p_intf = GtkGetIntf( GTK_WIDGET( button ) );
    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                       FIND_ANYWHERE );
Jean-Paul Saman's avatar
Jean-Paul Saman committed
402
    if (p_playlist)
403 404 405 406 407 408 409 410 411 412 413
    {
        playlist_Stop( p_playlist );
        vlc_object_release( p_playlist );
    }
}


void
onForward                              (GtkButton       *button,
                                        gpointer         user_data)
{
Jean-Paul Saman's avatar
Jean-Paul Saman committed
414
    intf_thread_t *p_intf = GtkGetIntf( button );
415

Jean-Paul Saman's avatar
Jean-Paul Saman committed
416
    if (p_intf->p_sys->p_input != NULL)
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
    {
        input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_FASTER );
    }
}


void
onAbout                                (GtkButton       *button,
                                        gpointer         user_data)
{
    intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(button) );

    // Toggle notebook
    if (p_intf->p_sys->p_notebook)
    {
        gtk_widget_show( GTK_WIDGET(p_intf->p_sys->p_notebook) );
Jean-Paul Saman's avatar
Jean-Paul Saman committed
433
        gtk_notebook_set_page(p_intf->p_sys->p_notebook,6);
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
    }
}


gboolean
SliderRelease                          (GtkWidget       *widget,
                                        GdkEventButton  *event,
                                        gpointer         user_data)
{
    intf_thread_t *p_intf = GtkGetIntf( widget );

    vlc_mutex_lock( &p_intf->change_lock );
    p_intf->p_sys->b_slider_free = 1;
    vlc_mutex_unlock( &p_intf->change_lock );

    return TRUE;
}


gboolean
SliderPress                            (GtkWidget       *widget,
                                        GdkEventButton  *event,
                                        gpointer         user_data)
{
    intf_thread_t *p_intf = GtkGetIntf( widget );

    vlc_mutex_lock( &p_intf->change_lock );
    p_intf->p_sys->b_slider_free = 0;
    vlc_mutex_unlock( &p_intf->change_lock );

    return TRUE;
}

Jean-Paul Saman's avatar
Jean-Paul Saman committed
467
void addSelectedToPlaylist(GtkTreeModel *model,
Jean-Paul Saman's avatar
Jean-Paul Saman committed
468 469 470 471 472
                               GtkTreePath *path,
                               GtkTreeIter *iter,
                               gpointer *userdata)
{
    gchar *filename;
Jean-Paul Saman's avatar
Jean-Paul Saman committed
473

Jean-Paul Saman's avatar
Jean-Paul Saman committed
474 475
    gtk_tree_model_get(model, iter, 0, &filename, -1);

Jean-Paul Saman's avatar
Jean-Paul Saman committed
476
    PlaylistAddItem(GTK_WIDGET(userdata), filename);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
477
}
478 479 480 481 482 483 484

void
onFileListRow                          (GtkTreeView     *treeview,
                                        GtkTreePath     *path,
                                        GtkTreeViewColumn *column,
                                        gpointer         user_data)
{
Jean-Paul Saman's avatar
Jean-Paul Saman committed
485
    intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET(treeview) );
Jean-Paul Saman's avatar
Jean-Paul Saman committed
486 487 488 489
    GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);

    if (gtk_tree_selection_count_selected_rows(selection) == 1)
    {
Jean-Paul Saman's avatar
Jean-Paul Saman committed
490
        struct stat   st;
Jean-Paul Saman's avatar
Jean-Paul Saman committed
491 492 493 494 495 496 497 498
        GtkTreeModel *model;
        GtkTreeIter   iter;
        gchar        *filename;

        /* This might be a directory selection */
        model = gtk_tree_view_get_model(treeview);
        if (!model)
        {
Jean-Paul Saman's avatar
Jean-Paul Saman committed
499 500
            msg_Err(p_intf, "PDA: Filelist model contains a NULL pointer\n" );
            return;
Jean-Paul Saman's avatar
Jean-Paul Saman committed
501
        }
Jean-Paul Saman's avatar
Jean-Paul Saman committed
502
        if (!gtk_tree_model_get_iter(model, &iter, path))
Jean-Paul Saman's avatar
Jean-Paul Saman committed
503
        {
Jean-Paul Saman's avatar
Jean-Paul Saman committed
504 505 506
            msg_Err( p_intf, "PDA: Could not get iter from model" );
            return;
        }
Jean-Paul Saman's avatar
Jean-Paul Saman committed
507

Jean-Paul Saman's avatar
Jean-Paul Saman committed
508 509 510 511
        gtk_tree_model_get(model, &iter, 0, &filename, -1);
        if (stat((char*)filename, &st)==0)
        {
            if (S_ISDIR(st.st_mode))
Jean-Paul Saman's avatar
Jean-Paul Saman committed
512
            {
Jean-Paul Saman's avatar
Jean-Paul Saman committed
513 514 515 516 517 518 519 520 521 522
                GtkListStore *p_model = NULL;

                /* Get new directory listing */
                p_model = gtk_list_store_new (5,
                                           G_TYPE_STRING,
                                           G_TYPE_STRING,
                                           G_TYPE_UINT64,
                                           G_TYPE_STRING,
                                           G_TYPE_STRING);
                if (p_model)
Jean-Paul Saman's avatar
Jean-Paul Saman committed
523
                {
Jean-Paul Saman's avatar
Jean-Paul Saman committed
524 525 526 527 528
                    ReadDirectory(p_intf, p_model, filename);

                    /* Update TreeView with new model */
                    gtk_tree_view_set_model(treeview, (GtkTreeModel*) p_model);
                    g_object_unref(p_model);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
529
                }
Jean-Paul Saman's avatar
Jean-Paul Saman committed
530
            }
Jean-Paul Saman's avatar
Jean-Paul Saman committed
531 532 533 534
            else
            {
                gtk_tree_selection_selected_foreach(selection, (GtkTreeSelectionForeachFunc) &addSelectedToPlaylist, (gpointer) treeview);
            }
Jean-Paul Saman's avatar
Jean-Paul Saman committed
535 536 537 538 539 540
        }
    }
    else
    {
        gtk_tree_selection_selected_foreach(selection, (GtkTreeSelectionForeachFunc) &addSelectedToPlaylist, (gpointer) treeview);
    }
541 542 543 544 545 546
}

void
onAddFileToPlaylist                    (GtkButton       *button,
                                        gpointer         user_data)
{
547
    GtkTreeView       *treeview = NULL;
548

549 550 551
    treeview = (GtkTreeView *) lookup_widget( GTK_WIDGET(button), "tvFileList");
    if (treeview)
    {
Jean-Paul Saman's avatar
Jean-Paul Saman committed
552 553 554
        GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);

        gtk_tree_selection_selected_foreach(selection, (GtkTreeSelectionForeachFunc) &addSelectedToPlaylist, (gpointer) treeview);    
555
    }
556 557 558 559
}


void
Jean-Paul Saman's avatar
Jean-Paul Saman committed
560
NetworkBuildMRL                        (GtkEditable     *editable,
561 562
                                        gpointer         user_data)
{
Jean-Paul Saman's avatar
Jean-Paul Saman committed
563 564
    GtkSpinButton *networkPort = NULL;
    GtkEntry      *entryMRL = NULL;
Jean-Paul Saman's avatar
Jean-Paul Saman committed
565
    GtkEntry      *networkType = NULL;
Jean-Paul Saman's avatar
Jean-Paul Saman committed
566 567
    GtkEntry      *networkAddress = NULL;
    GtkEntry      *networkProtocol = NULL;
Jean-Paul Saman's avatar
Jean-Paul Saman committed
568
    const gchar   *mrlNetworkType;
Jean-Paul Saman's avatar
Jean-Paul Saman committed
569 570
    const gchar   *mrlAddress;
    const gchar   *mrlProtocol;
Jean-Paul Saman's avatar
Jean-Paul Saman committed
571
    gint           mrlPort;
Jean-Paul Saman's avatar
Jean-Paul Saman committed
572 573
    char           text[VLC_MAX_MRL];
    int            pos = 0;
574

Jean-Paul Saman's avatar
Jean-Paul Saman committed
575
    entryMRL = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryMRL" );
576

Jean-Paul Saman's avatar
Jean-Paul Saman committed
577
    networkType     = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryNetworkType" );
Jean-Paul Saman's avatar
Jean-Paul Saman committed
578 579 580
    networkAddress  = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryNetworkAddress" );
    networkPort     = (GtkSpinButton*) lookup_widget( GTK_WIDGET(editable), "entryNetworkPort" );
    networkProtocol = (GtkEntry*) lookup_widget( GTK_WIDGET(editable), "entryNetworkProtocolType" );
581

Jean-Paul Saman's avatar
Jean-Paul Saman committed
582
    mrlNetworkType = gtk_entry_get_text(GTK_ENTRY(networkType));
Jean-Paul Saman's avatar
Jean-Paul Saman committed
583 584 585
    mrlAddress     = gtk_entry_get_text(GTK_ENTRY(networkAddress));
    mrlPort        = gtk_spin_button_get_value_as_int(networkPort);
    mrlProtocol    = gtk_entry_get_text(GTK_ENTRY(networkProtocol));
586

Jean-Paul Saman's avatar
Jean-Paul Saman committed
587
    /* Build MRL from parts ;-) */
Jean-Paul Saman's avatar
Jean-Paul Saman committed
588 589
    pos = snprintf( &text[0], VLC_MAX_MRL, "%s://", (char*)mrlProtocol);
    if (strncasecmp( (char*)mrlNetworkType, "multicast",9)==0)
Jean-Paul Saman's avatar
Jean-Paul Saman committed
590
    {
Jean-Paul Saman's avatar
Jean-Paul Saman committed
591
        pos += snprintf( &text[pos], VLC_MAX_MRL - pos, "@" );
Jean-Paul Saman's avatar
Jean-Paul Saman committed
592
    }
Jean-Paul Saman's avatar
Jean-Paul Saman committed
593
    pos += snprintf( &text[pos], VLC_MAX_MRL - pos, "%s:%d", (char*)mrlAddress, (int)mrlPort );
594

Jean-Paul Saman's avatar
Jean-Paul Saman committed
595 596
    if (pos >= VLC_MAX_MRL)
        text[VLC_MAX_MRL-1]='\0';
597

Jean-Paul Saman's avatar
Jean-Paul Saman committed
598
    gtk_entry_set_text(entryMRL,text);
599 600 601 602 603 604
}

void
onAddNetworkPlaylist                   (GtkButton       *button,
                                        gpointer         user_data)
{
Jean-Paul Saman's avatar
Jean-Paul Saman committed
605 606
    GtkEntry     *p_mrl = NULL;
    const gchar  *mrl_name;
607

Jean-Paul Saman's avatar
Jean-Paul Saman committed
608
    p_mrl = (GtkEntry*) lookup_widget(GTK_WIDGET(button),"entryMRL" );
Jean-Paul Saman's avatar
Jean-Paul Saman committed
609
    if (p_mrl)
Jean-Paul Saman's avatar
Jean-Paul Saman committed
610
    {
Jean-Paul Saman's avatar
Jean-Paul Saman committed
611 612
        mrl_name = gtk_entry_get_text(p_mrl);

Jean-Paul Saman's avatar
Jean-Paul Saman committed
613
        PlaylistAddItem(GTK_WIDGET(button), (gchar *)mrl_name);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
614
    }
615 616 617 618 619 620 621
}


void
onAddCameraToPlaylist                  (GtkButton       *button,
                                        gpointer         user_data)
{
Jean-Paul Saman's avatar
Jean-Paul Saman committed
622 623
    intf_thread_t *p_intf = GtkGetIntf( button );

Jean-Paul Saman's avatar
Jean-Paul Saman committed
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
    GtkSpinButton *entryV4LChannel = NULL;
    GtkSpinButton *entryV4LFrequency = NULL;
    GtkSpinButton *entryV4LSampleRate = NULL;
    GtkSpinButton *entryV4LQuality = NULL;
    GtkSpinButton *entryV4LTuner = NULL;
    gint    i_v4l_channel;
    gint    i_v4l_frequency;
    gint    i_v4l_samplerate;
    gint    i_v4l_quality;
    gint    i_v4l_tuner;

    GtkEntry      *entryV4LVideoDevice = NULL;
    GtkEntry      *entryV4LAudioDevice = NULL;
    GtkEntry      *entryV4LNorm = NULL;
    GtkEntry      *entryV4LSize = NULL;
    GtkEntry      *entryV4LSoundDirection = NULL;
    const gchar   *p_v4l_video_device;
    const gchar   *p_v4l_audio_device;
    const gchar   *p_v4l_norm;
    const gchar   *p_v4l_size;
    const gchar   *p_v4l_sound_direction;

    /* MJPEG only */
    GtkCheckButton *checkV4LMJPEG = NULL;
    GtkSpinButton  *entryV4LDecimation = NULL;
    gboolean        b_v4l_mjpeg;
    gint            i_v4l_decimation;
    /* end MJPEG only */

    char v4l_mrl[VLC_MAX_MRL];
    int pos;

    pos = snprintf( &v4l_mrl[0], VLC_MAX_MRL, "v4l://");

    entryV4LChannel    = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LChannel" );
    entryV4LFrequency  = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LFrequency" );
    entryV4LSampleRate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LSampleRate" );
    entryV4LQuality    = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LQuality" );
    entryV4LTuner      = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LTuner" );

    entryV4LVideoDevice  = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LVideoDevice" );
    entryV4LAudioDevice  = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LAudioDevice" );
    entryV4LNorm  = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LNorm" );
    entryV4LSize  = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LSize" );
    entryV4LSoundDirection  = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryV4LSoundDirection" );

    i_v4l_channel = gtk_spin_button_get_value_as_int(entryV4LChannel);
    i_v4l_frequency = gtk_spin_button_get_value_as_int(entryV4LFrequency);
    i_v4l_samplerate = gtk_spin_button_get_value_as_int(entryV4LSampleRate);
    i_v4l_quality = gtk_spin_button_get_value_as_int(entryV4LQuality);
    i_v4l_tuner = gtk_spin_button_get_value_as_int(entryV4LTuner);

    p_v4l_video_device = gtk_entry_get_text(GTK_ENTRY(entryV4LVideoDevice));
    p_v4l_audio_device = gtk_entry_get_text(GTK_ENTRY(entryV4LAudioDevice));
    p_v4l_norm = gtk_entry_get_text(GTK_ENTRY(entryV4LNorm));
    p_v4l_size  = gtk_entry_get_text(GTK_ENTRY(entryV4LSize));
    p_v4l_sound_direction = gtk_entry_get_text(GTK_ENTRY(entryV4LSoundDirection));

    pos += snprintf( &v4l_mrl[pos], VLC_MAX_MRL - pos, ":%s", (char*)p_v4l_video_device );
    pos += snprintf( &v4l_mrl[pos], VLC_MAX_MRL - pos, ":adev=%s", (char*)p_v4l_audio_device );
    pos += snprintf( &v4l_mrl[pos], VLC_MAX_MRL - pos, ":norm=%s", (char*)p_v4l_norm );
    pos += snprintf( &v4l_mrl[pos], VLC_MAX_MRL - pos, ":size=%s", (char*)p_v4l_size );
    pos += snprintf( &v4l_mrl[pos], VLC_MAX_MRL - pos, ":%s", (char*)p_v4l_sound_direction );

    pos += snprintf( &v4l_mrl[pos], VLC_MAX_MRL - pos, ":channel=%d", (int)i_v4l_channel );
    pos += snprintf( &v4l_mrl[pos], VLC_MAX_MRL - pos, ":frequency=%d", (int)i_v4l_frequency );
    pos += snprintf( &v4l_mrl[pos], VLC_MAX_MRL - pos, ":samplerate=%d", (int)i_v4l_samplerate );
    pos += snprintf( &v4l_mrl[pos], VLC_MAX_MRL - pos, ":quality=%d", (int)i_v4l_quality );
    pos += snprintf( &v4l_mrl[pos], VLC_MAX_MRL - pos, ":tuner=%d", (int)i_v4l_tuner );

    /* MJPEG only */
    checkV4LMJPEG      = (GtkCheckButton*) lookup_widget( GTK_WIDGET(button), "checkV4LMJPEG" );
    b_v4l_mjpeg = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkV4LMJPEG));
    if (b_v4l_mjpeg)
    {
        entryV4LDecimation = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryV4LDecimation" );
        i_v4l_decimation = gtk_spin_button_get_value_as_int(entryV4LDecimation);
        pos += snprintf( &v4l_mrl[pos], VLC_MAX_MRL - pos, ":mjpeg:%d", (int)i_v4l_decimation );
    }
    /* end MJPEG only */

    if (pos >= VLC_MAX_MRL)
Jean-Paul Saman's avatar
Jean-Paul Saman committed
706
    {
Jean-Paul Saman's avatar
Jean-Paul Saman committed
707
        v4l_mrl[VLC_MAX_MRL-1]='\0';
Jean-Paul Saman's avatar
Jean-Paul Saman committed
708 709
        msg_Err(p_intf, "Media Resource Locator is truncated to: %s", v4l_mrl);
    }
Jean-Paul Saman's avatar
Jean-Paul Saman committed
710

Jean-Paul Saman's avatar
Jean-Paul Saman committed
711
    PlaylistAddItem(GTK_WIDGET(button), (gchar*) &v4l_mrl);
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735
}


gboolean
PlaylistEvent                          (GtkWidget       *widget,
                                        GdkEvent        *event,
                                        gpointer         user_data)
{
    return FALSE;
}


void
onPlaylistColumnsChanged               (GtkTreeView     *treeview,
                                        gpointer         user_data)
{
}


gboolean
onPlaylistRowSelected                  (GtkTreeView     *treeview,
                                        gboolean         start_editing,
                                        gpointer         user_data)
{
Jean-Paul Saman's avatar
Jean-Paul Saman committed
736
    return FALSE;
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768
}


void
onPlaylistRow                          (GtkTreeView     *treeview,
                                        GtkTreePath     *path,
                                        GtkTreeViewColumn *column,
                                        gpointer         user_data)
{
}


void
onUpdatePlaylist                       (GtkButton       *button,
                                        gpointer         user_data)
{

}


void
onDeletePlaylist                       (GtkButton       *button,
                                        gpointer         user_data)
{

}


void
onClearPlaylist                        (GtkButton       *button,
                                        gpointer         user_data)
{
Jean-Paul Saman's avatar
Jean-Paul Saman committed
769
    intf_thread_t *p_intf = GtkGetIntf( button );
770

Jean-Paul Saman's avatar
Jean-Paul Saman committed
771
    msg_Dbg(p_intf, "Clear playlist" );
772 773 774 775 776 777 778
}


void
onPreferenceSave                       (GtkButton       *button,
                                        gpointer         user_data)
{
Jean-Paul Saman's avatar
Jean-Paul Saman committed
779
    intf_thread_t *p_intf = GtkGetIntf( button );
780

Jean-Paul Saman's avatar
Jean-Paul Saman committed
781
    msg_Dbg(p_intf, "Preferences Save" );
782 783 784 785 786 787 788
}


void
onPreferenceApply                      (GtkButton       *button,
                                        gpointer         user_data)
{
Jean-Paul Saman's avatar
Jean-Paul Saman committed
789
    intf_thread_t *p_intf = GtkGetIntf( button );
790

Jean-Paul Saman's avatar
Jean-Paul Saman committed
791
    msg_Dbg(p_intf, "Preferences Apply" );
792 793 794 795 796 797 798
}


void
onPreferenceCancel                     (GtkButton       *button,
                                        gpointer         user_data)
{
Jean-Paul Saman's avatar
Jean-Paul Saman committed
799
    intf_thread_t *p_intf = GtkGetIntf( button );
800

Jean-Paul Saman's avatar
Jean-Paul Saman committed
801
    msg_Dbg(p_intf, "Preferences Cancel" );
802 803
}

804

Jean-Paul Saman's avatar
Jean-Paul Saman committed
805 806 807 808
void
onAddTranscodeToPlaylist               (GtkButton       *button,
                                        gpointer         user_data)
{
Jean-Paul Saman's avatar
Jean-Paul Saman committed
809 810
    intf_thread_t *p_intf = GtkGetIntf( button );

Jean-Paul Saman's avatar
Jean-Paul Saman committed
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890
    GtkEntry       *entryVideoCodec = NULL;
    GtkSpinButton  *entryVideoBitrate = NULL;
    GtkSpinButton  *entryVideoBitrateTolerance = NULL;
    GtkSpinButton  *entryVideoKeyFrameInterval = NULL;
    GtkCheckButton *checkVideoDeinterlace = NULL;
    GtkEntry       *entryAudioCodec = NULL;
    GtkSpinButton  *entryAudioBitrate = NULL;
    const gchar    *p_video_codec;
    gint            i_video_bitrate;
    gint            i_video_bitrate_tolerance;
    gint            i_video_keyframe_interval;
    gboolean        b_video_deinterlace;
    const gchar    *p_audio_codec;
    gint            i_audio_bitrate;

    GtkEntry       *entryStdAccess = NULL;
    GtkEntry       *entryStdMuxer = NULL;
    GtkEntry       *entryStdURL = NULL;
    GtkSpinButton  *entryStdTTL = NULL;
    const gchar    *p_std_access;
    const gchar    *p_std_muxer;
    const gchar    *p_std_url;
    gint            i_std_ttl;

    gchar mrl[VLC_MAX_MRL];
    int   pos;

    pos = snprintf( &mrl[0], VLC_MAX_MRL, "--sout '#transcode{");

    entryVideoCodec   = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryVideoCodec" );
    entryVideoBitrate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoBitrate" );
    entryVideoBitrateTolerance = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoBitrateTolerance" );
    entryVideoKeyFrameInterval = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryVideoKeyFrameInterval" );
    
    p_video_codec = gtk_entry_get_text(GTK_ENTRY(entryVideoCodec));
    i_video_bitrate = gtk_spin_button_get_value_as_int(entryVideoBitrate);
    i_video_bitrate_tolerance = gtk_spin_button_get_value_as_int(entryVideoBitrateTolerance);
    i_video_keyframe_interval = gtk_spin_button_get_value_as_int(entryVideoKeyFrameInterval);
    
    pos += snprintf( &mrl[pos], VLC_MAX_MRL - pos, "vcodec=%s,", (char*)p_video_codec );
    pos += snprintf( &mrl[pos], VLC_MAX_MRL - pos, "vb=%d,", (int)i_video_bitrate );
    pos += snprintf( &mrl[pos], VLC_MAX_MRL - pos, "vt=%d,", (int)i_video_bitrate_tolerance );
    pos += snprintf( &mrl[pos], VLC_MAX_MRL - pos, "keyint=%d,", (int)i_video_keyframe_interval );

    checkVideoDeinterlace = (GtkCheckButton*) lookup_widget( GTK_WIDGET(button), "checkVideoDeinterlace" );
    b_video_deinterlace = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkVideoDeinterlace));
    if (b_video_deinterlace)
    {
        pos += snprintf( &mrl[pos], VLC_MAX_MRL - pos, "deinterlace," );
    }
    entryAudioCodec   = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryAudioCodec" );
    entryAudioBitrate = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryAudioBitrate" );

    p_audio_codec = gtk_entry_get_text(GTK_ENTRY(entryAudioCodec));
    i_audio_bitrate = gtk_spin_button_get_value_as_int(entryAudioBitrate);

    pos += snprintf( &mrl[pos], VLC_MAX_MRL - pos, "acodec=%s,", (char*)p_audio_codec );
    pos += snprintf( &mrl[pos], VLC_MAX_MRL - pos, "ab=%d", (int)i_audio_bitrate );

    pos += snprintf( &mrl[pos], VLC_MAX_MRL - pos, "}:std{" );

    entryStdAccess = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdAccess" );
    entryStdMuxer  = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdMuxer" );
    entryStdURL = (GtkEntry*) lookup_widget( GTK_WIDGET(button), "entryStdURL" );
    entryStdTTL = (GtkSpinButton*) lookup_widget( GTK_WIDGET(button), "entryStdTTL" );

    p_std_access = gtk_entry_get_text(GTK_ENTRY(entryStdAccess));
    p_std_muxer = gtk_entry_get_text(GTK_ENTRY(entryStdMuxer));
    p_std_url = gtk_entry_get_text(GTK_ENTRY(entryStdURL));

    pos += snprintf( &mrl[pos], VLC_MAX_MRL - pos, "access=%s,", (char*)p_std_access);
    pos += snprintf( &mrl[pos], VLC_MAX_MRL - pos, "mux=%s,", (char*)p_std_muxer);
    pos += snprintf( &mrl[pos], VLC_MAX_MRL - pos, "url=%s", (char*)p_std_url);
    pos += snprintf( &mrl[pos], VLC_MAX_MRL - pos, "}'");

    i_std_ttl = gtk_spin_button_get_value_as_int(entryStdTTL);

    pos += snprintf( &mrl[pos], VLC_MAX_MRL - pos, " --ttl=%d", (int)i_std_ttl);

    if (pos >= VLC_MAX_MRL)
Jean-Paul Saman's avatar
Jean-Paul Saman committed
891 892 893 894
    {
        mrl[VLC_MAX_MRL-1]='\0';
        msg_Err(p_intf, "Media Resource Locator is truncated to: %s", mrl );
    }
Jean-Paul Saman's avatar
Jean-Paul Saman committed
895

Jean-Paul Saman's avatar
Jean-Paul Saman committed
896
    PlaylistAddItem(GTK_WIDGET(button), (gchar*) &mrl);
Jean-Paul Saman's avatar
Jean-Paul Saman committed
897 898
}

Jean-Paul Saman's avatar
Jean-Paul Saman committed
899