ncurses.c 41.6 KB
Newer Older
1 2 3
/*****************************************************************************
 * ncurses.c : NCurses plugin for vlc
 *****************************************************************************
4
 * Copyright (C) 2001-2004 VideoLAN
5
 * $Id$
6
 *
7
 * Authors: Sam Hocevar <sam@zoy.org>
8
 *          Laurent Aimar <fenrir@via.ecp.fr>
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
9 10
 *          Yoann Peronneau <yoann@videolan.org>
 *          Derk-Jan Hartman <hartman at videolan dot org>
11
 *
12 13 14 15
 * 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.
16
 *
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
 * 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 <stdlib.h>                                      /* malloc(), free() */
#include <string.h>
#include <errno.h>                                                 /* ENOMEM */
#include <stdio.h>
#include <time.h>

#include <curses.h>

#include <vlc/vlc.h>
#include <vlc/intf.h>
#include <vlc/vout.h>
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
41
#include <vlc/aout.h>
42

43 44
#ifdef HAVE_CDDAX
#define CDDA_MRL "cddax://"
45
#else
46 47 48 49 50 51 52 53 54
#define CDDA_MRL "cdda://"
#endif

#ifdef HAVE_VCDX
#define VCD_MRL "vcdx://"
#else
#define VCD_MRL "vcdx://"
#endif

55 56 57
#define SEARCH_CHAIN_SIZE 20
#define OPEN_CHAIN_SIZE 50

58 59 60 61
/*****************************************************************************
 * Local prototypes.
 *****************************************************************************/
static int  Open           ( vlc_object_t * );
62
static void Close          ( vlc_object_t * );
63

64
static void Run            ( intf_thread_t * );
65
static void PlayPause      ( intf_thread_t * );
66 67 68
static void Eject          ( intf_thread_t * );

static int  HandleKey      ( intf_thread_t *, int );
69 70
static void Redraw         ( intf_thread_t *, time_t * );
static void SearchPlaylist ( intf_thread_t *, char * );
71 72 73 74 75 76
static void ManageSlider   ( intf_thread_t * );

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
vlc_module_begin();
Gildas Bazin's avatar
 
Gildas Bazin committed
77
    set_description( _("ncurses interface") );
78 79 80 81 82 83 84 85
    set_capability( "interface", 10 );
    set_callbacks( Open, Close );
    add_shortcut( "curses" );
vlc_module_end();

/*****************************************************************************
 * intf_sys_t: description and status of ncurses interface
 *****************************************************************************/
86 87 88 89 90 91
enum
{
    BOX_NONE,
    BOX_HELP,
    BOX_INFO,
    BOX_LOG,
92 93 94
    BOX_PLAYLIST,
    BOX_SEARCH,
    BOX_OPEN
95
};
96 97
struct intf_sys_t
{
98 99 100 101 102 103 104 105 106 107 108 109 110 111
    playlist_t     *p_playlist;
    input_thread_t *p_input;

    float           f_slider;
    float           f_slider_old;

    WINDOW          *w;

    int             i_box_type;
    int             i_box_y;
    int             i_box_lines;
    int             i_box_lines_total;
    int             i_box_start;

112 113 114
    int             i_box_plidx;    /* Playlist index */
    int             b_box_plidx_follow;

115
    int             b_box_cleared;
116

117
    msg_subscription_t* p_sub;                  /* message bank subscription */
118 119 120 121 122 123

    char            *psz_search_chain;          /* for playlist searching    */
    char            *psz_old_search;            /* for searching next        */
    int             i_before_search;

    char            *psz_open_chain;
124 125
};

126 127 128 129
static void DrawBox( WINDOW *win, int y, int x, int h, int w, char *title );
static void DrawLine( WINDOW *win, int y, int x, int w );
static void DrawEmptyLine( WINDOW *win, int y, int x, int w );

130 131 132 133
/*****************************************************************************
 * Open: initialize and create window
 *****************************************************************************/
static int Open( vlc_object_t *p_this )
134
{
135
    intf_thread_t *p_intf = (intf_thread_t *)p_this;
136
    intf_sys_t    *p_sys;
137
    vlc_value_t    val;
138 139

    /* Allocate instance and initialize some members */
140 141 142 143 144 145 146 147 148
    p_sys = p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
    p_sys->p_playlist = NULL;
    p_sys->p_input = NULL;
    p_sys->f_slider = 0.0;
    p_sys->f_slider_old = 0.0;
    p_sys->i_box_type = BOX_PLAYLIST;
    p_sys->i_box_lines = 0;
    p_sys->i_box_start= 0;
    p_sys->i_box_lines_total = 0;
149
    p_sys->b_box_plidx_follow = VLC_TRUE;
150
    p_sys->b_box_cleared = VLC_FALSE;
151
    p_sys->i_box_plidx = 0;
152
    p_sys->p_sub = msg_Subscribe( p_intf );
153 154

    /* Initialize the curses library */
155 156
    p_sys->w = initscr();
    keypad( p_sys->w, TRUE );
157 158 159 160 161 162 163 164 165 166 167 168
    /* Don't do NL -> CR/NL */
    nonl();
    /* Take input chars one at a time */
    cbreak();
    /* Don't echo */
    noecho();

    curs_set(0);
    timeout(0);

    clear();

169 170 171
    /* exported function */
    p_intf->pf_run = Run;

172 173 174 175
    /* Set quiet mode */
    val.i_int = -1;
    var_Set( p_intf->p_vlc, "verbose", val );

176 177 178 179 180 181 182 183
    /* Initialize search chain */
    p_sys->psz_search_chain = (char *)malloc( SEARCH_CHAIN_SIZE + 1 );
    p_sys->psz_old_search = NULL;
    p_sys->i_before_search = 0;

    /* Initialize open chain */
    p_sys->psz_open_chain = (char *)malloc( OPEN_CHAIN_SIZE + 1 );

184
    return VLC_SUCCESS;
185 186 187 188 189 190
}

/*****************************************************************************
 * Close: destroy interface window
 *****************************************************************************/
static void Close( vlc_object_t *p_this )
191
{
192
    intf_thread_t *p_intf = (intf_thread_t *)p_this;
193
    intf_sys_t    *p_sys = p_intf->p_sys;
194

195 196 197 198
    if( p_sys->psz_search_chain ) free( p_sys->psz_search_chain );
    if( p_sys->psz_old_search ) free( p_sys->psz_old_search );
    if( p_sys->psz_open_chain ) free( p_sys->psz_open_chain );

199 200 201 202 203
    if( p_sys->p_input )
    {
        vlc_object_release( p_sys->p_input );
    }
    if( p_sys->p_playlist )
204
    {
205
        vlc_object_release( p_sys->p_playlist );
206 207 208 209 210
    }

    /* Close the ncurses interface */
    endwin();

211 212
    msg_Unsubscribe( p_intf, p_sys->p_sub );

213
    /* Destroy structure */
214
    free( p_sys );
215 216 217 218 219 220 221
}

/*****************************************************************************
 * Run: ncurses thread
 *****************************************************************************/
static void Run( intf_thread_t *p_intf )
{
222 223 224
    intf_sys_t    *p_sys = p_intf->p_sys;

    int i_key;
225 226 227 228 229 230 231 232 233 234 235
    time_t t_last_refresh;

    /*
     * force drawing the interface for the first time
     */
    t_last_refresh = ( time( 0 ) - 1);

    while( !p_intf->b_die )
    {
        msleep( INTF_IDLE_SLEEP );

236
        /* Update the input */
237
        if( p_sys->p_playlist == NULL )
238
        {
239 240
            p_sys->p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
        }
241
        if( p_sys->p_playlist )
242
        {
243 244
            vlc_mutex_lock( &p_sys->p_playlist->object_lock );
            if( p_sys->p_input == NULL )
245
            {
246 247 248 249 250 251 252 253
                p_sys->p_input = p_sys->p_playlist->p_input;
                if( p_sys->p_input )
                {
                    if( !p_sys->p_input->b_dead )
                    {
                        vlc_object_yield( p_sys->p_input );
                    }
                }
254
            }
255
            else if( p_sys->p_input->b_dead )
256
            {
257 258 259 260
                vlc_object_release( p_sys->p_input );
                p_sys->p_input = NULL;
                p_sys->f_slider = p_sys->f_slider_old = 0.0;
                p_sys->b_box_cleared = VLC_FALSE;
261
            }
262
            vlc_mutex_unlock( &p_sys->p_playlist->object_lock );
263
        }
264

265
        if( p_sys->b_box_plidx_follow && p_sys->p_playlist->i_index >= 0 )
266
        {
267
            p_sys->i_box_plidx = p_sys->p_playlist->i_index;
268
        }
269

270

271
        while( ( i_key = getch()) != -1 )
272 273 274 275 276 277 278 279 280
        {
            /*
             * HandleKey returns 1 if the screen needs to be redrawn
             */
            if ( HandleKey( p_intf, i_key ) )
            {
                Redraw( p_intf, &t_last_refresh );
            }
        }
281 282 283 284 285 286 287
        /* Hack */
        if( p_sys->f_slider > 0.0001 && !p_sys->b_box_cleared )
        {
            clear();
            Redraw( p_intf, &t_last_refresh );
            p_sys->b_box_cleared = VLC_TRUE;
        }
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303

        /*
         * redraw the screen every second
         */
        if ( (time(0) - t_last_refresh) >= 1 )
        {
            ManageSlider ( p_intf );
            Redraw( p_intf, &t_last_refresh );
        }
    }
}

/* following functions are local */

static int HandleKey( intf_thread_t *p_intf, int i_key )
{
304 305 306 307 308
    intf_sys_t *p_sys = p_intf->p_sys;
    vlc_value_t val;

    if( p_sys->i_box_type == BOX_PLAYLIST && p_sys->p_playlist )
    {
309 310
        int b_ret = VLC_TRUE;

311 312
        switch( i_key )
        {
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
313 314
            vlc_value_t val;
            /* Playlist Settings */
315
            case 'r':
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
316 317 318 319 320 321 322 323
                var_Get( p_sys->p_playlist, "random", &val );
                val.b_bool = !val.b_bool;
                var_Set( p_sys->p_playlist, "random", val );
                return 1;
            case 'l':
                var_Get( p_sys->p_playlist, "loop", &val );
                val.b_bool = !val.b_bool;
                var_Set( p_sys->p_playlist, "loop", val );
324
                return 1;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
325 326 327 328 329 330 331
            case 'R':
                var_Get( p_sys->p_playlist, "repeat", &val );
                val.b_bool = !val.b_bool;
                var_Set( p_sys->p_playlist, "repeat", val );
                return 1;

            /* Playlist sort */
332
            case 'o':
333
                playlist_Sort( p_sys->p_playlist, SORT_TITLE, ORDER_NORMAL );
334 335
                return 1;
            case 'O':
336
                playlist_Sort( p_sys->p_playlist, SORT_TITLE, ORDER_REVERSE );
337 338 339 340
                return 1;

            /* Playlist navigation */
            case KEY_HOME:
341 342
                p_sys->i_box_plidx = 0;
                break;
343
            case KEY_END:
344 345
                p_sys->i_box_plidx = p_sys->p_playlist->i_size - 1;
                break;
346
            case KEY_UP:
347 348
                p_sys->i_box_plidx--;
                break;
349
            case KEY_DOWN:
350 351
                p_sys->i_box_plidx++;
                break;
352
            case KEY_PPAGE:
353 354
                p_sys->i_box_plidx -= p_sys->i_box_lines;
                break;
355
            case KEY_NPAGE:
356 357
                p_sys->i_box_plidx += p_sys->i_box_lines;
                break;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
358
            case 'D':
359 360 361 362
            case KEY_BACKSPACE:
            case KEY_DC:
            {
                int i_item = p_sys->p_playlist->i_index;
363 364 365

                playlist_Delete( p_sys->p_playlist, p_sys->i_box_plidx );
                if( i_item < p_sys->p_playlist->i_size && i_item != p_sys->p_playlist->i_index )
366 367 368
                {
                    playlist_Goto( p_sys->p_playlist, i_item );
                }
369
                break;
370 371
            }

372 373 374 375
            case KEY_ENTER:
            case 0x0d:
                playlist_Goto( p_sys->p_playlist, p_sys->i_box_plidx );
                break;
376
            default:
377
                b_ret = VLC_FALSE;
378 379
                break;
        }
380 381 382 383 384 385 386 387 388 389 390

        if( b_ret )
        {
            if( p_sys->i_box_plidx >= p_sys->p_playlist->i_size ) p_sys->i_box_plidx = p_sys->p_playlist->i_size - 1;
            if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
            if( p_sys->i_box_plidx == p_sys->p_playlist->i_index )
                p_sys->b_box_plidx_follow = VLC_TRUE;
            else
                p_sys->b_box_plidx_follow = VLC_FALSE;
            return 1;
        }
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
    }
    else if( p_sys->i_box_type == BOX_HELP || p_sys->i_box_type == BOX_INFO )
    {
        switch( i_key )
        {
            case KEY_HOME:
                p_sys->i_box_start = 0;
                return 1;
            case KEY_END:
                p_sys->i_box_start = p_sys->i_box_lines_total - 1;
                return 1;
            case KEY_UP:
                if( p_sys->i_box_start > 0 ) p_sys->i_box_start--;
                return 1;
            case KEY_DOWN:
                if( p_sys->i_box_start < p_sys->i_box_lines_total - 1 )
                {
                    p_sys->i_box_start++;
                }
                return 1;
            case KEY_PPAGE:
                p_sys->i_box_start -= p_sys->i_box_lines;
                if( p_sys->i_box_start < 0 ) p_sys->i_box_start = 0;
                return 1;
            case KEY_NPAGE:
                p_sys->i_box_start += p_sys->i_box_lines;
                if( p_sys->i_box_start >= p_sys->i_box_lines_total )
                {
                    p_sys->i_box_start = p_sys->i_box_lines_total - 1;
                }
                return 1;
            default:
                break;
        }
    }
    else if( p_sys->i_box_type == BOX_NONE )
    {
        switch( i_key )
        {
            case KEY_HOME:
                p_sys->f_slider = 0;
                ManageSlider ( p_intf );
                return 1;
            case KEY_END:
                p_sys->f_slider = 99.9;
                ManageSlider ( p_intf );
                return 1;
            case KEY_UP:
439
                p_sys->f_slider += 5.0;
440 441 442 443
                if( p_sys->f_slider >= 99.0 ) p_sys->f_slider = 99.0;
                ManageSlider ( p_intf );
                return 1;
            case KEY_DOWN:
444
                p_sys->f_slider -= 5.0;
445 446 447 448 449 450 451 452
                if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
                ManageSlider ( p_intf );
                return 1;

            default:
                break;
        }
    }
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
    else if( p_sys->i_box_type == BOX_SEARCH && p_sys->psz_search_chain )
    {
        int i_chain_len;
        i_chain_len = strlen( p_sys->psz_search_chain );
        switch( i_key )
        {
            case 0x0c:      /* ^l */
                clear();
                return 1;
            case KEY_ENTER:
            case 0x0d:
                if( i_chain_len > 0 )
                {
                    p_sys->psz_old_search = strdup( p_sys->psz_search_chain );
                }
                else if( p_sys->psz_old_search )
                {
                    SearchPlaylist( p_intf, p_sys->psz_old_search );
                }
                p_sys->i_box_type = BOX_PLAYLIST;
                return 1;
            case 0x1b:      /* Esc. */
                p_sys->i_box_plidx = p_sys->i_before_search;
                p_sys->i_box_type = BOX_PLAYLIST;
                return 1;
            case KEY_BACKSPACE:
                if( i_chain_len > 0 )
                {
                    p_sys->psz_search_chain[ i_chain_len - 1 ] = '\0';
                }
                break;
            default:
                if( i_chain_len < SEARCH_CHAIN_SIZE )
                {
                    p_sys->psz_search_chain[ i_chain_len++ ] = i_key;
                    p_sys->psz_search_chain[ i_chain_len ] = 0;
                }
                break;
        }
        if( p_sys->psz_old_search )
        {
            free( p_sys->psz_old_search );
            p_sys->psz_old_search = NULL;
        }
        SearchPlaylist( p_intf, p_sys->psz_search_chain );
        return 1;
    }
    else if( p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain )
    {
        int i_chain_len;
        i_chain_len = strlen( p_sys->psz_open_chain );
        playlist_t *p_playlist = p_sys->p_playlist;

        switch( i_key )
        {
            case 0x0c:      /* ^l */
                clear();
                return 1;
            case KEY_ENTER:
            case 0x0d:
513
                if( p_playlist && i_chain_len > 0 )
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
                {
                    playlist_Add( p_playlist, p_sys->psz_open_chain,
                                  p_sys->psz_open_chain,
                                  PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
                    p_sys->b_box_plidx_follow = VLC_TRUE;
                }
                p_sys->i_box_type = BOX_PLAYLIST;
                return 1;
            case 0x1b:      /* Esc. */
                p_sys->i_box_type = BOX_PLAYLIST;
                return 1;
            case KEY_BACKSPACE:
                if( i_chain_len > 0 )
                {
                    p_sys->psz_open_chain[ i_chain_len - 1 ] = '\0';
                }
                break;
            default:
                if( i_chain_len < OPEN_CHAIN_SIZE )
                {
                    p_sys->psz_open_chain[ i_chain_len++ ] = i_key;
                    p_sys->psz_open_chain[ i_chain_len ] = 0;
                }
                break;
        }
        return 1;
    }

542 543

    /* Common keys */
544 545 546 547
    switch( i_key )
    {
        case 'q':
        case 'Q':
548
        case 0x1b:  /* Esc */
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
549
            p_intf->p_vlc->b_die = VLC_TRUE;
550 551
            return 0;

552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
        /* Box switching */
        case 'i':
            if( p_sys->i_box_type == BOX_INFO )
                p_sys->i_box_type = BOX_NONE;
            else
                p_sys->i_box_type = BOX_INFO;
            p_sys->i_box_lines_total = 0;
            return 1;
        case 'l':
            if( p_sys->i_box_type == BOX_LOG )
                p_sys->i_box_type = BOX_NONE;
            else
                p_sys->i_box_type = BOX_LOG;
            return 1;
        case 'P':
            if( p_sys->i_box_type == BOX_PLAYLIST )
                p_sys->i_box_type = BOX_NONE;
            else
                p_sys->i_box_type = BOX_PLAYLIST;
            return 1;
        case 'h':
        case 'H':
            if( p_sys->i_box_type == BOX_HELP )
                p_sys->i_box_type = BOX_NONE;
            else
                p_sys->i_box_type = BOX_HELP;
            p_sys->i_box_lines_total = 0;
579
            return 1;
580 581 582 583 584 585 586 587 588 589 590 591 592
        case '/':
            if( p_sys->i_box_type != BOX_SEARCH )
            {
                if( p_sys->psz_search_chain == NULL )
                {
                    return 1;
                }
                p_sys->psz_search_chain[0] = '\0';
                p_sys->b_box_plidx_follow = VLC_FALSE;
                p_sys->i_before_search = p_sys->i_box_plidx;
                p_sys->i_box_type = BOX_SEARCH;
            }
            return 1;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
593
        case 'A': /* Open */
594 595 596 597 598 599 600 601 602 603
            if( p_sys->i_box_type != BOX_OPEN )
            {
                if( p_sys->psz_open_chain == NULL )
                {
                    return 1;
                }
                p_sys->psz_open_chain[0] = '\0';
                p_sys->i_box_type = BOX_OPEN;
            }
            return 1;
604

605 606
        /* Navigation */
        case KEY_RIGHT:
607
            p_sys->f_slider += 1.0;
608 609
            if( p_sys->f_slider > 99.9 ) p_sys->f_slider = 99.9;
            ManageSlider ( p_intf );
610 611
            return 1;

612
        case KEY_LEFT:
613
            p_sys->f_slider -= 1.0;
614 615
            if( p_sys->f_slider < 0.0 ) p_sys->f_slider = 0.0;
            ManageSlider ( p_intf );
616 617
            return 1;

618 619 620 621
        /* Common control */
        case 'f':
        {
            vout_thread_t *p_vout;
622
            if( p_intf->p_sys->p_input )
623
            {
624 625 626 627 628 629 630
                p_vout = vlc_object_find( p_intf->p_sys->p_input,
                                          VLC_OBJECT_VOUT, FIND_CHILD );
                if( p_vout )
                {
                    p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
                    vlc_object_release( p_vout );
                }
631 632 633 634 635 636
            }
            return 0;
        }

        case ' ':
            PlayPause( p_intf );
637 638
            return 1;

639 640 641 642 643
        case 's':
            if( p_intf->p_sys->p_playlist )
            {
                playlist_Stop( p_intf->p_sys->p_playlist );
            }
644 645 646 647 648 649 650
            return 1;

        case 'e':
            Eject( p_intf );
            return 1;

        case '[':
651 652 653 654 655
            if( p_sys->p_input )
            {
                val.b_bool = VLC_TRUE;
                var_Set( p_sys->p_input, "prev-title", val );
            }
656
            return 1;
657 658

        case ']':
659 660 661 662 663
            if( p_sys->p_input )
            {
                val.b_bool = VLC_TRUE;
                var_Set( p_sys->p_input, "next-title", val );
            }
664
            return 1;
665 666

        case '<':
667 668 669 670 671
            if( p_sys->p_input )
            {
                val.b_bool = VLC_TRUE;
                var_Set( p_sys->p_input, "prev-chapter", val );
            }
672
            return 1;
673 674

        case '>':
675 676 677 678 679
            if( p_sys->p_input )
            {
                val.b_bool = VLC_TRUE;
                var_Set( p_sys->p_input, "next-chapter", val );
            }
680
            return 1;
681

682 683 684 685 686 687 688
        case 'p':
            if( p_intf->p_sys->p_playlist )
            {
                playlist_Prev( p_intf->p_sys->p_playlist );
            }
            clear();
            return 1;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
689

690 691 692 693 694 695 696
        case 'n':
            if( p_intf->p_sys->p_playlist )
            {
                playlist_Next( p_intf->p_sys->p_playlist );
            }
            clear();
            return 1;
697

Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
698 699 700 701 702 703 704 705 706 707
        case 'a':
            aout_VolumeUp( p_intf, 1, NULL );
            clear();
            return 1;

        case 'z':
            aout_VolumeDown( p_intf, 1, NULL );
            clear();
            return 1;

708 709 710 711 712 713 714 715
        /*
         * ^l should clear and redraw the screen
         */
        case 0x0c:
            clear();
            return 1;

        default:
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740
            return 0;
    }
}

static void ManageSlider ( intf_thread_t *p_intf )
{
    intf_sys_t     *p_sys = p_intf->p_sys;
    input_thread_t *p_input = p_sys->p_input;
    vlc_value_t     val;

    if( p_input == NULL )
    {
        return;
    }
    var_Get( p_input, "state", &val );
    if( val.i_int != PLAYING_S )
    {
        return;
    }

    var_Get( p_input, "position", &val );
    if( p_sys->f_slider == p_sys->f_slider_old )
    {
        p_sys->f_slider =
        p_sys->f_slider_old = 100 * val.f_float;
741
    }
742 743 744
    else
    {
        p_sys->f_slider_old = p_sys->f_slider;
745

746 747 748
        val.f_float = p_sys->f_slider / 100.0;
        var_Set( p_input, "position", val );
    }
749 750
}

751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
static void SearchPlaylist( intf_thread_t *p_intf, char *psz_searchstring )
{
    bool b_ok = false;
    int i_current;
    int i_first = 0 ;
    int i_item = -1;
    intf_sys_t *p_sys = p_intf->p_sys;
    playlist_t *p_playlist = p_sys->p_playlist;

    if( p_sys->i_before_search >= 0 )
        i_first = p_sys->i_before_search;

    if( ( ! psz_searchstring ) ||  strlen( psz_searchstring ) <= 0 )
    {
        p_sys->i_box_plidx = p_sys->i_before_search;
        return;
    }

    for( i_current = i_first + 1; i_current < p_playlist->i_size;
         i_current++ )
    {
        if( strcasestr( p_playlist->pp_items[i_current]->input.psz_name,
                        psz_searchstring ) != NULL
            || strcasestr( p_playlist->pp_items[i_current]->input.psz_uri,
                           psz_searchstring ) != NULL )
        {
            i_item = i_current;
            b_ok = true;
            break;
        }
    }
    if( !b_ok )
    {
        for( i_current = 0; i_current < i_first; i_current++ )
        {
            if( strcasestr( p_playlist->pp_items[i_current]->input.psz_name,
                            psz_searchstring ) != NULL
                || strcasestr( p_playlist->pp_items[i_current]->input.psz_uri,
                               psz_searchstring ) != NULL )
            {
                i_item = i_current;
                b_ok = true;
                break;
            }
        }
    }

    if( i_item < 0 || i_item >= p_playlist->i_size ) return;

    p_sys->i_box_plidx = i_item;
}


804
static void mvnprintw( int y, int x, int w, const char *p_fmt, ... )
805 806
{
    va_list  vl_args;
807 808
    char    *p_buf = NULL;
    int      i_len;
809 810 811 812 813 814 815

    va_start ( vl_args, p_fmt );
    vasprintf ( &p_buf, p_fmt, vl_args );
    va_end ( vl_args );

    if ( p_buf == NULL )
    {
816
        return;
817
    }
818 819 820 821 822 823 824
    if(  w > 0 )
    {
        if( ( i_len = strlen( p_buf ) ) > w )
        {
            int i_cut = i_len - w;
            int x1 = i_len/2 - i_cut/2;
            int x2 = x1 + i_cut;
825

826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848
            if( i_len > x2 )
            {
                memmove( &p_buf[x1], &p_buf[x2], i_len - x2 );
            }
            p_buf[w] = '\0';
            if( w > 7 )
            {
                p_buf[w/2-1] = '.';
                p_buf[w/2  ] = '.';
                p_buf[w/2+1] = '.';
            }
            mvprintw( y, x, "%s", p_buf );
        }
        else
        {
            mvprintw( y, x, "%s", p_buf );
            mvhline( y, x + i_len, ' ', w - i_len );
        }
    }
}
static void MainBoxWrite( intf_thread_t *p_intf, int l, int x, const char *p_fmt, ... )
{
    intf_sys_t     *p_sys = p_intf->p_sys;
849

850 851 852 853
    va_list  vl_args;
    char    *p_buf = NULL;

    if( l < p_sys->i_box_start || l - p_sys->i_box_start >= p_sys->i_box_lines )
854
    {
855
        return;
856
    }
857 858 859 860 861 862

    va_start ( vl_args, p_fmt );
    vasprintf ( &p_buf, p_fmt, vl_args );
    va_end ( vl_args );

    if( p_buf == NULL )
863
    {
864
        return;
865 866
    }

867
    mvnprintw( p_sys->i_box_y + l - p_sys->i_box_start, x, COLS - x - 1, "%s", p_buf );
868 869
}

870
static void Redraw ( intf_thread_t *p_intf, time_t *t_last_refresh )
871
{
872 873 874 875 876
    intf_sys_t     *p_sys = p_intf->p_sys;
    input_thread_t *p_input = p_sys->p_input;
    int y = 0;
    int h;
    int y_end;
877

878
    //clear();
879

880
    /* Title */
881
    attrset ( A_REVERSE );
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
882
    mvnprintw( y, 0, COLS, "VLC media player" " (ncurses interface) [ h for help ]" );
883
    attroff ( A_REVERSE );
884
    y += 2;
885

886 887 888 889 890 891 892
    /* Infos */
    if( p_input && !p_input->b_dead )
    {
        char buf1[MSTRTIME_MAX_SIZE];
        char buf2[MSTRTIME_MAX_SIZE];
        vlc_value_t val;
        vlc_value_t val_list;
893

894 895
        /* Source */
        mvnprintw( y++, 0, COLS, " Source   : %s", p_input->psz_source );
896

897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912
        /* State */
        var_Get( p_input, "state", &val );
        if( val.i_int == PLAYING_S )
        {
            mvnprintw( y++, 0, COLS, " State    : Playing" );
        }
        else if( val.i_int == PAUSE_S )
        {
            mvnprintw( y++, 0, COLS, " State    : Paused" );
        }
        else
        {
            y++;
        }
        if( val.i_int != INIT_S && val.i_int != END_S )
        {
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
913 914
            audio_volume_t i_volume;

915 916 917 918 919 920 921 922 923
            /* Position */
            var_Get( p_input, "time", &val );
            msecstotimestr( buf1, val.i_time / 1000 );

            var_Get( p_input, "length", &val );
            msecstotimestr( buf2, val.i_time / 1000 );

            mvnprintw( y++, 0, COLS, " Position : %s/%s (%.2f%%)", buf1, buf2, p_sys->f_slider );

Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
924 925 926 927
            /* Volume */
            aout_VolumeGet( p_intf, &i_volume );
            mvnprintw( y++, 0, COLS, " Volume   : %i%%", i_volume*200/AOUT_VOLUME_MAX );

928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955
            /* Title */
            if( !var_Get( p_input, "title", &val ) )
            {
                var_Change( p_input, "title", VLC_VAR_GETCHOICES, &val_list, NULL );
                if( val_list.p_list->i_count > 0 )
                {
                    mvnprintw( y++, 0, COLS, " Title    : %d/%d", val.i_int, val_list.p_list->i_count );
                }
                var_Change( p_input, "title", VLC_VAR_FREELIST, &val_list, NULL );
            }

            /* Chapter */
            if( !var_Get( p_input, "chapter", &val ) )
            {
                var_Change( p_input, "chapter", VLC_VAR_GETCHOICES, &val_list, NULL );
                if( val_list.p_list->i_count > 0 )
                {
                    mvnprintw( y++, 0, COLS, " Chapter  : %d/%d", val.i_int, val_list.p_list->i_count );
                }
                var_Change( p_input, "chapter", VLC_VAR_FREELIST, &val_list, NULL );
            }
        }
        else
        {
            y++;
        }
    }
    else
956
    {
957 958 959
        mvnprintw( y++, 0, COLS, "Source: <no current item>" );
        DrawEmptyLine( p_sys->w, y++, 0, COLS );
        DrawEmptyLine( p_sys->w, y++, 0, COLS );
960 961
    }

962 963 964 965
    DrawBox( p_sys->w, y, 0, 3, COLS, "" );
    DrawEmptyLine( p_sys->w, y+1, 1, COLS-2);
    DrawLine( p_sys->w, y+1, 1, (int)(p_intf->p_sys->f_slider/100.0 * (COLS -2)) );
    y += 3;
966

967 968
    p_sys->i_box_y = y + 1;
    p_sys->i_box_lines = LINES - y - 2;
969

970 971
    h = LINES - y;
    y_end = y + h - 1;
972

973 974 975 976 977 978 979 980
    if( p_sys->i_box_type == BOX_HELP )
    {
        /* Help box */
        int l = 0;
        DrawBox( p_sys->w, y++, 0, h, COLS, " Help " );

        MainBoxWrite( p_intf, l++, 1, "[Display]" );
        MainBoxWrite( p_intf, l++, 1, "     h,H         Show/Hide help box" );
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
981 982
        MainBoxWrite( p_intf, l++, 1, "     i           Show/Hide info box" );
        MainBoxWrite( p_intf, l++, 1, "     l           Show/Hide messages box" );
983 984 985 986 987 988
        MainBoxWrite( p_intf, l++, 1, "     P           Show/Hide playlist box" );
        MainBoxWrite( p_intf, l++, 1, "" );

        MainBoxWrite( p_intf, l++, 1, "[Global]" );
        MainBoxWrite( p_intf, l++, 1, "     q, Q        Quit" );
        MainBoxWrite( p_intf, l++, 1, "     s           Stop" );
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
989 990 991
        MainBoxWrite( p_intf, l++, 1, "     <space>     Pause/Play" );
        MainBoxWrite( p_intf, l++, 1, "     f           Toggle Fullscreen" );
        MainBoxWrite( p_intf, l++, 1, "     n, p        Next/Previous playlist item" );
992
        MainBoxWrite( p_intf, l++, 1, "     [, ]        Next/Previous title" );
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
993
        MainBoxWrite( p_intf, l++, 1, "     <, >        Next/Previous chapter" );
994 995
        MainBoxWrite( p_intf, l++, 1, "     <right>     Seek +1%%" );
        MainBoxWrite( p_intf, l++, 1, "     <left>      Seek -1%%" );
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
996 997
        MainBoxWrite( p_intf, l++, 1, "     a           Volume Up" );
        MainBoxWrite( p_intf, l++, 1, "     z           Volume Down" );
998 999 1000
        MainBoxWrite( p_intf, l++, 1, "" );

        MainBoxWrite( p_intf, l++, 1, "[Playlist]" );
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
1001 1002 1003 1004 1005
        MainBoxWrite( p_intf, l++, 1, "     r           Random" );
        MainBoxWrite( p_intf, l++, 1, "     l           Loop Playlist" );
        MainBoxWrite( p_intf, l++, 1, "     R           Repeat item" );
        MainBoxWrite( p_intf, l++, 1, "     o           Order Playlist by title" );
        MainBoxWrite( p_intf, l++, 1, "     O           Reverse order Playlist by title" );
1006
        MainBoxWrite( p_intf, l++, 1, "     /           Look for an item" );
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
1007 1008 1009
        MainBoxWrite( p_intf, l++, 1, "     A           Add an entry" );
        MainBoxWrite( p_intf, l++, 1, "     D, <del>    Delete an entry" );
        MainBoxWrite( p_intf, l++, 1, "     <backspace> Delete an entry" );
1010 1011 1012
        MainBoxWrite( p_intf, l++, 1, "" );

        MainBoxWrite( p_intf, l++, 1, "[Boxes]" );
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
1013 1014
        MainBoxWrite( p_intf, l++, 1, "     <up>,<down>     Navigate through the box line by line" );
        MainBoxWrite( p_intf, l++, 1, "     <pgup>,<pgdown> Navigate through the box page by page" );
1015 1016 1017
        MainBoxWrite( p_intf, l++, 1, "" );

        MainBoxWrite( p_intf, l++, 1, "[Player]" );
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
1018
        MainBoxWrite( p_intf, l++, 1, "     <up>,<down>     Seek +/-5%%" );
1019 1020 1021
        MainBoxWrite( p_intf, l++, 1, "" );

        MainBoxWrite( p_intf, l++, 1, "[Miscellaneous]" );
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
1022
        MainBoxWrite( p_intf, l++, 1, "     Ctrl-l          Refresh the screen" );
1023 1024 1025 1026 1027 1028

        p_sys->i_box_lines_total = l;
        if( p_sys->i_box_start >= p_sys->i_box_lines_total )
        {
            p_sys->i_box_start = p_sys->i_box_lines_total - 1;
        }
1029

1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
        if( l - p_sys->i_box_start < p_sys->i_box_lines )
        {
            y += l - p_sys->i_box_start;
        }
        else
        {
            y += p_sys->i_box_lines;
        }
    }
    else if( p_sys->i_box_type == BOX_INFO )
    {
        /* Info box */
        int l = 0;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
1043
        DrawBox( p_sys->w, y++, 0, h, COLS, " Information " );
1044

1045 1046
        if( p_input )
        {
Anil Daoud's avatar
Anil Daoud committed
1047
            int i,j;
Derk-Jan Hartman's avatar
Derk-Jan Hartman committed
1048
            vlc_mutex_lock( &p_input->p_item->lock );
Anil Daoud's avatar
Anil Daoud committed
1049
            for ( i = 0; i < p_input->p_item->i_categories; i++ )
1050
            {
Anil Daoud's avatar
Anil Daoud committed
1051
                info_category_t *p_category = p_input->p_item->pp_categories[i];
1052 1053
                if( y >= y_end ) break;
                MainBoxWrite( p_intf, l++, 1, "  [%s]", p_category->psz_name );
Anil Daoud's avatar
Anil Daoud committed
1054
                for ( j = 0; j < p_category->i_infos; j++ )
1055
                {
Anil Daoud's avatar
Anil Daoud committed
1056
                    info_t *p_info = p_category->pp_infos[j];
1057 1058 1059 1060
                    if( y >= y_end ) break;
                    MainBoxWrite( p_intf, l++, 1, "      %s: %s", p_info->psz_name, p_info->psz_value );
                }
            }
Anil Daoud's avatar
Anil Daoud committed
1061
            vlc_mutex_unlock( &p_input->p_item->lock );
1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
        }
        else
        {
            MainBoxWrite( p_intf, l++, 1, "No item currently playing" );
        }
        p_sys->i_box_lines_total = l;
        if( p_sys->i_box_start >= p_sys->i_box_lines_total )
        {
            p_sys->i_box_start = p_sys->i_box_lines_total - 1;
        }

        if( l - p_sys->i_box_start < p_sys->i_box_lines )
        {
            y += l - p_sys->i_box_start;
        }
        else
        {
            y += p_sys->i_box_lines;
        }
    }
    else if( p_sys->i_box_type == BOX_LOG )
    {
        int i_line = 0;
        int i_stop;
        int i_start;

        DrawBox( p_sys->w, y++, 0, h, COLS, " Logs " );

        i_start = p_intf->p_sys->p_sub->i_start;
1091

1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119
        vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
        i_stop = *p_intf->p_sys->p_sub->pi_stop;
        vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );

        for( ;; )
        {
            static const char *ppsz_type[4] = { "", "error", "warning", "debug" };
            if( i_line >= h - 2 )
            {
                break;
            }
            i_stop--;
            i_line++;
            if( i_stop < 0 ) i_stop += VLC_MSG_QSIZE;
            if( i_stop == i_start )
            {
                break;
            }
            mvnprintw( y + h-2-i_line, 1, COLS - 2, "   [%s] %s",
                      ppsz_type[p_sys->p_sub->p_msg[i_stop].i_type],
                      p_sys->p_sub->p_msg[i_stop].psz_msg );
        }

        vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
        p_intf->p_sys->p_sub->i_start = i_stop;
        vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
        y = y_end;
    }
1120 1121 1122
    else if( ( p_sys->i_box_type == BOX_PLAYLIST ||
               p_sys->i_box_type == BOX_SEARCH ||
               p_sys->i_box_type == BOX_OPEN  ) && p_sys->p_playlist )
1123
    {
1124 1125 1126 1127 1128 1129
        /* Playlist box */
        playlist_t *p_playlist = p_sys->p_playlist;
        int        i_start, i_stop;
        int        i_item;
        DrawBox( p_sys->w, y++, 0, h, COLS, " Playlist " );

1130 1131 1132 1133
        if( p_sys->i_box_plidx >= p_playlist->i_size ) p_sys->i_box_plidx = p_playlist->i_size - 1;
        if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;

        if( p_sys->i_box_plidx < (h - 2)/2 )
1134 1135 1136 1137
        {
            i_start = 0;
            i_stop = h - 2;
        }
1138
        else if( p_playlist->i_size - p_sys->i_box_plidx > (h - 2)/2 )
1139
        {
1140
            i_start = p_sys->i_box_plidx - (h - 2)/2;
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158
            i_stop = i_start + h - 2;
        }
        else
        {
            i_stop = p_playlist->i_size;
            i_start = p_playlist->i_size - (h - 2);
        }
        if( i_start < 0 )
        {
            i_start = 0;
        }
        if( i_stop > p_playlist->i_size )
        {
            i_stop = p_playlist->i_size;
        }

        for( i_item = i_start; i_item < i_stop; i_item++ )
        {
1159 1160 1161
            vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item );
            int c = p_playlist->i_index == i_item ? '>' : ' ';

1162 1163 1164 1165 1166
            if( y >= y_end ) break;
            if( b_selected )
            {
                attrset( A_REVERSE );
            }
1167 1168
            if( !strcmp( p_playlist->pp_items[i_item]->input.psz_name,
                         p_playlist->pp_items[i_item]->input.psz_uri ) )
1169
            {
1170 1171
                mvnprintw( y++, 1, COLS - 2, "%c %d - '%s'",
                           c,
1172
                           i_item,
1173
                           p_playlist->pp_items[i_item]->input.psz_uri );
1174 1175 1176
            }
            else
            {
1177 1178
                mvnprintw( y++, 1, COLS - 2, "%c %d - '%s' (%s)",
                          c,
1179
                          i_item,
1180 1181
                          p_playlist->pp_items[i_item]->input.psz_uri,
                          p_playlist->pp_items[i_item]->input.psz_name );
1182 1183 1184 1185 1186 1187 1188 1189 1190 1191
            }
            if( b_selected )
            {
                attroff ( A_REVERSE );
            }
        }
    }
    else
    {
        y++;
1192
    }
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217
    if( p_sys->i_box_type == BOX_SEARCH )
    {
        DrawEmptyLine( p_sys->w, 6, 1, COLS-2 );
        if( p_sys->psz_search_chain )
        {
            if( strlen( p_sys->psz_search_chain ) == 0 &&
                p_sys->psz_old_search != NULL )
            {
                /* Searching next entry */
                mvnprintw( 6, 1, COLS-2, "Find: %s", p_sys->psz_old_search );
            }
            else
            {
                mvnprintw( 6, 1, COLS-2, "Find: %s", p_sys->psz_search_chain );
            }
        }
    }
    if( p_sys->i_box_type == BOX_OPEN )
    {
        DrawEmptyLine( p_sys->w, 6, 1, COLS-2 );
        if( p_sys->psz_open_chain )
        {
            mvnprintw( 6, 1, COLS-2, "Open: %s", p_sys->psz_open_chain );
        }
    }
1218

1219 1220 1221 1222 1223 1224 1225 1226
    while( y < y_end )
    {
        DrawEmptyLine( p_sys->w, y++, 1, COLS - 2 );
    }

    refresh();

    *t_last_refresh = time( 0 );
1227 1228 1229 1230 1231 1232 1233 1234
}

static void Eject ( intf_thread_t *p_intf )
{
    char *psz_device = NULL, *psz_parser, *psz_name;

    /*
     * Get the active input
1235 1236
     * Determine whether we can eject a media, ie it's a DVD, VCD or CD-DA
     * If it's neither of these, then return
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249
     */

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

    if( p_playlist == NULL )
    {
        return;
    }

    vlc_mutex_lock( &p_playlist->object_lock );

    if( p_playlist->i_index < 0 )
1250
    {
1251 1252
        vlc_mutex_unlock( &p_playlist->object_lock );
        vlc_object_release( p_playlist );
1253
        return;
1254 1255
    }

1256
    psz_name = p_playlist->pp_items[ p_playlist->i_index ]->input.psz_name;
1257 1258 1259

    if( psz_name )
    {
1260 1261
        if( !strncmp(psz_name, "dvd://", 4) )
        {
1262
            switch( psz_name[strlen("dvd://")] )
1263 1264 1265 1266 1267 1268 1269
            {
            case '\0':
            case '@':
                psz_device = config_GetPsz( p_intf, "dvd" );
                break;
            default:
                /* Omit the first MRL-selector characters */
1270
                psz_device = strdup( psz_name + strlen("dvd://" ) );
1271 1272 1273 1274
                break;
            }
        }
        else if( !strncmp(psz_name, VCD_MRL, strlen(VCD_MRL)) )
1275
        {
1276
            switch( psz_name[strlen(VCD_MRL)] )
1277 1278 1279
            {
            case '\0':
            case '@':
1280
                psz_device = config_GetPsz( p_intf, VCD_MRL );
1281 1282
                break;
            default:
1283
                /* Omit the beginning MRL-selector characters */
1284
                psz_device = strdup( psz_name + strlen(VCD_MRL) );
1285 1286 1287
                break;
            }
        }
1288
        else if( !strncmp(psz_name, CDDA_MRL, strlen(CDDA_MRL) ) )
1289
        {
1290
            switch( psz_name[strlen(CDDA_MRL)] )
1291 1292 1293
            {
            case '\0':
            case '@':
1294
                psz_device = config_GetPsz( p_intf, "cd-audio" );
1295 1296
                break;
            default:
1297
                /* Omit the beginning MRL-selector characters */
1298
                psz_device = strdup( psz_name + strlen(CDDA_MRL) );
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329
                break;
            }
        }
        else
        {
            psz_device = strdup( psz_name );
        }
    }

    vlc_mutex_unlock( &p_playlist->object_lock );
    vlc_object_release( p_playlist );

    if( psz_device == NULL )
    {
        return;
    }

    /* Remove what we have after @ */
    psz_parser = psz_device;
    for( psz_parser = psz_device ; *psz_parser ; psz_parser++ )
    {
        if( *psz_parser == '@' )
        {
            *psz_parser = '\0';
            break;
        }
    }

    /* If there's a stream playing, we aren't allowed to eject ! */
    if( p_intf->p_sys->p_input == NULL )
    {
1330
        msg_Dbg( p_intf, "ejecting %s", psz_device );
1331 1332 1333 1334 1335 1336 1337 1338

        intf_Eject( p_intf, psz_device );
    }

    free(psz_device);
    return;
}

1339
static void PlayPause ( intf_thread_t *p_intf )
1340
{
1341 1342
    input_thread_t *p_input = p_intf->p_sys->p_input;
    vlc_value_t val;
1343

1344 1345 1346 1347
    if( p_input )
    {
        var_Get( p_input, "state", &val );
        if( val.i_int != PAUSE_S )
1348
        {
1349
            val.i_int = PAUSE_S;
1350 1351 1352
        }
        else
        {
1353
            val.i_int = PLAYING_S;
1354
        }
1355
        var_Set( p_input, "state", val );
1356
    }
1357
    else if( p_intf->p_sys->p_playlist )
1358
    {
1359
        playlist_Play( p_intf->p_sys->p_playlist );
1360 1361 1362
    }
}

1363 1364 1365 1366
/****************************************************************************
 *
 ****************************************************************************/
static void DrawBox( WINDOW *win, int y, int x, int h, int w, char *title )
1367
{
1368 1369
    int i;
    int i_len;
1370

1371
    if(  w > 3 && h > 2 )
1372
    {
1373 1374
        if( title == NULL ) title = "";
        i_len = strlen( title );
1375

1376
        if( i_len > w - 2 ) i_len = w - 2;
1377

1378 1379 1380 1381 1382
        mvwaddch( win, y, x,    ACS_ULCORNER );
        mvwhline( win, y, x+1,  ACS_HLINE, ( w-i_len-2)/2 );
        mvwprintw( win,y, x+1+(w-i_len-2)/2, "%s", title );
        mvwhline( win, y, x+(w-i_len)/2+i_len,  ACS_HLINE, w - 1 - ((w-i_len)/2+i_len) );
        mvwaddch( win, y, x+w-1,ACS_URCORNER );
1383

1384
        for( i = 0; i < h-2; i++ )
1385
        {
1386 1387
            mvwaddch( win, y+i+1, x,     ACS_VLINE );
            mvwaddch( win, y+i+1, x+w-1, ACS_VLINE );
1388 1389
        }

1390 1391 1392
        mvwaddch( win, y+h-1, x,     ACS_LLCORNER );
        mvwhline( win, y+h-1, x+1,   ACS_HLINE, w - 2 );
        mvwaddch( win, y+h-1, x+w-1, ACS_LRCORNER );
1393 1394 1395
    }
}

1396
static void DrawEmptyLine( WINDOW *win, int y, int x, int w )
1397
{
1398
    if( w > 0 )
1399
    {
1400
        mvhline( y, x, ' ', w );
1401 1402 1403
    }
}

1404
static void DrawLine( WINDOW *win, int y, int x, int w )
1405
{
1406
    if( w > 0 )
1407
    {
1408 1409 1410
        attrset( A_REVERSE );
        mvhline( y, x, ' ', w );
        attroff ( A_REVERSE );
1411 1412
    }
}