open_panels.cpp 42.6 KB
Newer Older
Pierre's avatar
Pierre committed
1
/*****************************************************************************
zorglub's avatar
zorglub committed
2 3
 * open.cpp : Panels for the open dialogs
 ****************************************************************************
4
 * Copyright (C) 2006-2009 the VideoLAN team
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
5 6
 * Copyright (C) 2007 Société des arts technologiques
 * Copyright (C) 2007 Savoir-faire Linux
7
 *
8
 * $Id$
zorglub's avatar
zorglub committed
9 10
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
zorglub's avatar
zorglub committed
11
 *          Jean-Baptiste Kempf <jb@videolan.org>
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
12
 *          Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
zorglub's avatar
zorglub committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

29 30 31
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
32 33

#include "qt4.hpp"
34
#include "components/open_panels.hpp"
35
#include "dialogs/open.hpp"
36
#include "dialogs_provider.hpp" /* Open Subtitle file */
37
#include "util/qt_dirs.hpp"
38

39 40 41
#include <QFileDialog>
#include <QDialogButtonBox>
#include <QLineEdit>
42
#include <QStackedLayout>
43
#include <QListView>
44
#include <QCompleter>
45
#include <QDirModel>
46
#include <QScrollArea>
47
#include <QUrl>
48
#include <QStringListModel>
49

50
#define I_DEVICE_TOOLTIP N_("Select the device or the VIDEO_TS directory")
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
51

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
52 53 54
static const char *psz_devModule[] = { "v4l", "v4l2", "pvr", "dvb", "bda",
                                       "dshow", "screen", "jack" };

zorglub's avatar
zorglub committed
55
/**************************************************************************
56
 * Open Files and subtitles                                               *
zorglub's avatar
zorglub committed
57 58 59 60
 **************************************************************************/
FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
                                OpenPanel( _parent, _p_intf )
{
61
    /* Classic UI Setup */
zorglub's avatar
zorglub committed
62
    ui.setupUi( this );
63

64
#if 0
65
    /** BEGIN QFileDialog tweaking **/
66 67 68 69
    /* Use a QFileDialog and customize it because we don't want to
       rewrite it all. Be careful to your eyes cause there are a few hacks.
       Be very careful and test correctly when you modify this. */

70 71 72 73 74 75 76
    /* Set Filters for file selection */
    QString fileTypes = "";
    ADD_FILTER_MEDIA( fileTypes );
    ADD_FILTER_VIDEO( fileTypes );
    ADD_FILTER_AUDIO( fileTypes );
    ADD_FILTER_PLAYLIST( fileTypes );
    ADD_FILTER_ALL( fileTypes );
77
    fileTypes.replace( QString(";*"), QString(" *"));
78

79
    // Make this QFileDialog a child of tempWidget from the ui.
80
    dialogBox = new FileOpenBox( ui.tempWidget, NULL,
81
            qfu( p_intf->p_sys->psz_filepath ), fileTypes );
82

83
    dialogBox->setFileMode( QFileDialog::ExistingFiles );
84
    dialogBox->setAcceptMode( QFileDialog::AcceptOpen );
85
    dialogBox->restoreState(
86
            getSettings()->value( "file-dialog-state" ).toByteArray() );
87

88 89
    /* We don't want to see a grip in the middle of the window, do we? */
    dialogBox->setSizeGripEnabled( false );
90 91

    /* Add a tooltip */
92
    dialogBox->setToolTip( qtr( "Select one or multiple files" ) );
93
    dialogBox->setMinimumHeight( 250 );
94 95

    // But hide the two OK/Cancel buttons. Enable them for debug.
96
    QDialogButtonBox *fileDialogAcceptBox =
97
                      dialogBox->findChildren<QDialogButtonBox*>()[0];
98
    fileDialogAcceptBox->hide();
99 100 101

    /* Ugly hacks to get the good Widget */
    //This lineEdit is the normal line in the fileDialog.
102
    lineFileEdit = dialogBox->findChildren<QLineEdit*>()[0];
103
    /* Make a list of QLabel inside the QFileDialog to access the good ones */
104
    QList<QLabel *> listLabel = dialogBox->findChildren<QLabel*>();
105 106

    /* Hide the FileNames one. Enable it for debug */
107
    listLabel[1]->setText( qtr( "File names:" ) );
108
    /* Change the text that was uncool in the usual box */
109
    listLabel[2]->setText( qtr( "Filter:" ) );
zorglub's avatar
zorglub committed
110

111
    dialogBox->layout()->setMargin( 0 );
112
    dialogBox->layout()->setSizeConstraint( QLayout::SetNoConstraint );
113

114 115 116 117
    /** END of QFileDialog tweaking **/

    // Add the DialogBox to the layout
    ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
118
#endif
119

120
/*    lineFileEdit = ui.fileEdit;
121 122 123
    //TODO later: fill the fileCompleteList with previous items played.
    QCompleter *fileCompleter = new QCompleter( fileCompleteList, this );
    fileCompleter->setModel( new QDirModel( fileCompleter ) );
124
    lineFileEdit->setCompleter( fileCompleter );*/
125

126
    // Hide the subtitles control by default.
127
    ui.subFrame->setEnabled( false );
128

129
    /* Build the subs size combo box */
130
    setfillVLCConfigCombo( "freetype-rel-fontsize" , p_intf,
131
                            ui.sizeSubComboBox );
132

yoann's avatar
yoann committed
133
    /* Build the subs align combo box */
134
    setfillVLCConfigCombo( "subsdec-align", p_intf, ui.alignSubComboBox );
yoann's avatar
yoann committed
135

136
    /* Connects  */
137
    BUTTONACT( ui.fileBrowseButton, browseFile() );
138
    BUTTONACT( ui.delFileButton, deleteFile() );
139
    BUTTONACT( ui.subBrowseButton, browseFileSub() );
140
    CONNECT( ui.subCheckBox, toggled( bool ), this, toggleSubtitleFrame( bool ) );
zorglub's avatar
zorglub committed
141

142
    CONNECT( ui.fileListWidg, itemChanged( QListWidgetItem * ), this, updateMRL() );
143
    CONNECT( ui.subInput, textChanged( QString ), this, updateMRL() );
144 145
    CONNECT( ui.alignSubComboBox, currentIndexChanged( int ), this, updateMRL() );
    CONNECT( ui.sizeSubComboBox, currentIndexChanged( int ), this, updateMRL() );
146 147
}

148 149
FileOpenPanel::~FileOpenPanel()
{
150 151 152 153 154 155 156 157 158 159 160 161 162
//  getSettings()->setValue( "file-dialog-state", dialogBox->saveState() );
}

void FileOpenPanel::browseFile()
{
    QStringList files = QFileDialog::getOpenFileNames( this );
    foreach( const QString &file, files)
    {
        QListWidgetItem *item = new QListWidgetItem( file, ui.fileListWidg );
        item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
        ui.fileListWidg->addItem( item );
    }
    updateMRL();
163
}
164

165 166 167 168 169 170 171 172 173 174 175 176
void FileOpenPanel::deleteFile()
{
    int i = ui.fileListWidg->currentRow();
    if( i != -1 )
    {
        QListWidgetItem *temp = ui.fileListWidg->takeItem( i );
        delete temp;
    }

    updateMRL();
}

177
/* Show a fileBrowser to select a subtitle */
178 179
void FileOpenPanel::browseFileSub()
{
180
    // TODO Handle selection of more than one subtitles file
181
    QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
182 183
                           EXT_FILTER_SUBTITLE, p_intf->p_sys->psz_filepath );

184
    if( files.isEmpty() ) return;
185
    ui.subInput->setText( files.join(" ") );
zorglub's avatar
zorglub committed
186
    updateMRL();
187 188
}

189 190 191 192 193 194 195 196 197
void FileOpenPanel::toggleSubtitleFrame( bool b )
{
    ui.subFrame->setEnabled( b );

    /* Update the MRL */
    updateMRL();
}


198
/* Update the current MRL */
199 200
void FileOpenPanel::updateMRL()
{
201 202
    QStringList fileList;
    QString mrl;
zorglub's avatar
zorglub committed
203

204
    for( int i = 0; i < ui.fileListWidg->count(); i++ )
205 206 207 208
    {
        if( !ui.fileListWidg->item( i )->text().isEmpty() )
            fileList << ui.fileListWidg->item( i )->text();
    }
209 210

    if( ui.subCheckBox->isChecked() &&  !ui.subInput->text().isEmpty() ) {
211
        mrl.append( " :sub-file=" + colon_escape( ui.subInput->text() ) );
212 213
        int align = ui.alignSubComboBox->itemData(
                    ui.alignSubComboBox->currentIndex() ).toInt();
214
        mrl.append( " :subsdec-align=" + QString().setNum( align ) );
215 216
        int size = ui.sizeSubComboBox->itemData(
                   ui.sizeSubComboBox->currentIndex() ).toInt();
217
        mrl.append( " :freetype-rel-fontsize=" + QString().setNum( size ) );
zorglub's avatar
zorglub committed
218
    }
219

220
    emit mrlUpdated( fileList, mrl );
221 222 223 224 225 226
    emit methodChanged( "file-caching" );
}

/* Function called by Open Dialog when clicke on Play/Enqueue */
void FileOpenPanel::accept()
{
227 228
    //FIXME
 //   p_intf->p_sys->psz_filepath = qtu( dialogBox->directory().absolutePath() );
229
    ui.fileListWidg->clear();
230
}
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
231

232
/* Function called by Open Dialog when clicked on cancel */
233 234
void FileOpenPanel::clear()
{
235
    ui.fileListWidg->clear();
236
    ui.subInput->clear();
237 238
}

zorglub's avatar
zorglub committed
239
/**************************************************************************
240
 * Open Discs ( DVD, CD, VCD and similar devices )                        *
zorglub's avatar
zorglub committed
241
 **************************************************************************/
242
DiscOpenPanel::DiscOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
zorglub's avatar
zorglub committed
243 244 245
                                OpenPanel( _parent, _p_intf )
{
    ui.setupUi( this );
zorglub's avatar
zorglub committed
246

247 248 249 250 251 252 253 254 255
    /* Get the default configuration path for the devices */
    psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
    psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
    psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );

    /* State to avoid overwritting the users changes with the configuration */
    b_firstdvd = true;
    b_firstvcd = true;
    b_firstcdda = true;
256

257
    ui.browseDiscButton->setToolTip( qtr( I_DEVICE_TOOLTIP ));
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
258 259
    ui.deviceCombo->setToolTip( I_DEVICE_TOOLTIP );

Jean-Baptiste Kempf's avatar
Typo.  
Jean-Baptiste Kempf committed
260
#ifdef WIN32 /* Disc drives probing for Windows */
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
    char szDrives[512];
    szDrives[0] = '\0';
    if( GetLogicalDriveStringsA( sizeof( szDrives ) - 1, szDrives ) )
    {
        char *drive = szDrives;
        UINT oldMode = SetErrorMode( SEM_FAILCRITICALERRORS );
        while( *drive )
        {
            if( GetDriveTypeA(drive) == DRIVE_CDROM )
                ui.deviceCombo->addItem( drive );

            /* go to next drive */
            while( *(drive++) );
        }
        SetErrorMode(oldMode);
    }
277
#else /* Use a Completer under Linux */
278 279 280 281
    QCompleter *discCompleter = new QCompleter( this );
    discCompleter->setModel( new QDirModel( discCompleter ) );
    ui.deviceCombo->setCompleter( discCompleter );
#endif
282

283
    /* CONNECTs */
284 285 286 287 288
    BUTTONACT( ui.dvdRadioButton, updateButtons() );
    BUTTONACT( ui.vcdRadioButton, updateButtons() );
    BUTTONACT( ui.audioCDRadioButton, updateButtons() );
    BUTTONACT( ui.dvdsimple, updateButtons() );
    BUTTONACT( ui.browseDiscButton, browseDevice() );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
289 290
    BUTTON_SET_ACT_I( ui.ejectButton, "", eject, qtr( "Eject the disc" ),
            eject() );
zorglub's avatar
zorglub committed
291

292 293 294 295 296
    CONNECT( ui.deviceCombo, editTextChanged( QString ), this, updateMRL());
    CONNECT( ui.titleSpin, valueChanged( int ), this, updateMRL());
    CONNECT( ui.chapterSpin, valueChanged( int ), this, updateMRL());
    CONNECT( ui.audioSpin, valueChanged( int ), this, updateMRL());
    CONNECT( ui.subtitlesSpin, valueChanged( int ), this, updateMRL());
297

298
    /* Run once the updateButtons function in order to fill correctly the comboBoxes */
299
    updateButtons();
zorglub's avatar
zorglub committed
300 301
}

302
DiscOpenPanel::~DiscOpenPanel()
303
{
ivoire's avatar
ivoire committed
304 305 306
    free( psz_dvddiscpath );
    free( psz_vcddiscpath );
    free( psz_cddadiscpath );
307
}
308

309
void DiscOpenPanel::clear()
zorglub's avatar
zorglub committed
310
{
311 312
    ui.titleSpin->setValue( 0 );
    ui.chapterSpin->setValue( 0 );
313 314
    ui.subtitlesSpin->setValue( -1 );
    ui.audioSpin->setValue( -1 );
315 316 317
    b_firstcdda = true;
    b_firstdvd = true;
    b_firstvcd = true;
zorglub's avatar
zorglub committed
318
}
319

320 321 322 323 324 325 326 327 328
#ifdef WIN32
    #define setDrive( psz_name ) {\
    int index = ui.deviceCombo->findText( qfu( psz_name ) ); \
    if( index != -1 ) ui.deviceCombo->setCurrentIndex( index );}
#else
    #define setDrive( psz_name ) {\
    ui.deviceCombo->setEditText( qfu( psz_name ) ); }
#endif

329
/* update the buttons according the type of device */
330 331 332 333
void DiscOpenPanel::updateButtons()
{
    if ( ui.dvdRadioButton->isChecked() )
    {
334 335 336 337 338
        if( b_firstdvd )
        {
            setDrive( psz_dvddiscpath );
            b_firstdvd = false;
        }
339 340 341 342
        ui.titleLabel->setText( qtr("Title") );
        ui.chapterLabel->show();
        ui.chapterSpin->show();
        ui.diskOptionBox_2->show();
343
        ui.dvdsimple->setEnabled( true );
344 345 346
    }
    else if ( ui.vcdRadioButton->isChecked() )
    {
347 348 349 350 351
        if( b_firstvcd )
        {
            setDrive( psz_vcddiscpath );
            b_firstvcd = false;
        }
352 353 354 355
        ui.titleLabel->setText( qtr("Entry") );
        ui.chapterLabel->hide();
        ui.chapterSpin->hide();
        ui.diskOptionBox_2->show();
356
        ui.dvdsimple->setEnabled( false );
357
    }
358
    else /* CDDA */
359
    {
360 361 362 363 364
        if( b_firstcdda )
        {
            setDrive( psz_cddadiscpath );
            b_firstcdda = false;
        }
365 366 367 368
        ui.titleLabel->setText( qtr("Track") );
        ui.chapterLabel->hide();
        ui.chapterSpin->hide();
        ui.diskOptionBox_2->hide();
369
        ui.dvdsimple->setEnabled( false );
370 371 372 373 374
    }

    updateMRL();
}

375
/* Update the current MRL */
376
void DiscOpenPanel::updateMRL()
zorglub's avatar
zorglub committed
377 378
{
    QString mrl = "";
379
    QStringList fileList;
380

381
    /* CDDAX and VCDX not implemented. TODO ? No. */
zorglub's avatar
zorglub committed
382 383
    /* DVD */
    if( ui.dvdRadioButton->isChecked() ) {
384
        if( !ui.dvdsimple->isChecked() )
385
            mrl = "dvd://";
386
        else
387
            mrl = "dvdsimple://";
388
        mrl += ui.deviceCombo->currentText();
zorglub's avatar
zorglub committed
389 390 391
        emit methodChanged( "dvdnav-caching" );

        if ( ui.titleSpin->value() > 0 ) {
392
            mrl += QString("@%1").arg( ui.titleSpin->value() );
zorglub's avatar
zorglub committed
393
            if ( ui.chapterSpin->value() > 0 ) {
394
                mrl+= QString(":%1").arg( ui.chapterSpin->value() );
zorglub's avatar
zorglub committed
395 396 397 398
            }
        }

    /* VCD */
399
    } else if ( ui.vcdRadioButton->isChecked() ) {
400
        mrl = "vcd://" + ui.deviceCombo->currentText();
zorglub's avatar
zorglub committed
401 402 403
        emit methodChanged( "vcd-caching" );

        if( ui.titleSpin->value() > 0 ) {
404
            mrl += QString("@E%1").arg( ui.titleSpin->value() );
zorglub's avatar
zorglub committed
405 406 407 408
        }

    /* CDDA */
    } else {
409
        mrl = "cdda://" + ui.deviceCombo->currentText();
410
        if( ui.titleSpin->value() > 0 ) {
411
            mrl += QString(" :cdda-track=%1").arg( ui.titleSpin->value() );
412 413 414
        }
    }

415
    fileList << mrl; mrl = "";
416

417 418 419
    if ( ui.dvdRadioButton->isChecked() || ui.vcdRadioButton->isChecked() )
    {
        if ( ui.audioSpin->value() >= 0 ) {
420 421
            mrl += " :audio-track=" +
                QString("%1").arg( ui.audioSpin->value() );
422 423 424
        }
        if ( ui.subtitlesSpin->value() >= 0 ) {
            mrl += " :sub-track=" +
425
                QString("%1").arg( ui.subtitlesSpin->value() );
426
        }
zorglub's avatar
zorglub committed
427
    }
428
    emit mrlUpdated( fileList, mrl );
429 430
}

431 432
void DiscOpenPanel::browseDevice()
{
433
    QString dir = QFileDialog::getExistingDirectory( this,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
434
            qtr( I_DEVICE_TOOLTIP ) );
435 436 437
    if (!dir.isEmpty())
        ui.deviceCombo->setEditText( toNativeSepNoSlash( dir ) );

438 439
    updateMRL();
}
440

441 442 443 444 445
void DiscOpenPanel::eject()
{
    intf_Eject( p_intf, qtu( ui.deviceCombo->currentText() ) );
}

446
void DiscOpenPanel::accept()
447
{}
448

449
/**************************************************************************
450
 * Open Network streams and URL pages                                     *
451 452 453 454 455
 **************************************************************************/
NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
                                OpenPanel( _parent, _p_intf )
{
    ui.setupUi( this );
zorglub's avatar
zorglub committed
456

457
    /* CONNECTs */
458
    CONNECT( ui.protocolCombo, activated( int ),
459 460
             this, updateProtocol( int ) );
    CONNECT( ui.portSpin, valueChanged( int ), this, updateMRL() );
461
    CONNECT( ui.addressText, textChanged( QString ), this, updateMRL());
zorglub's avatar
zorglub committed
462

463 464 465 466
    ui.protocolCombo->addItem( "" );
    ui.protocolCombo->addItem("HTTP", QVariant("http"));
    ui.protocolCombo->addItem("HTTPS", QVariant("https"));
    ui.protocolCombo->addItem("MMS", QVariant("mms"));
467
    ui.protocolCombo->addItem("FTP", QVariant("ftp"));
468
    ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
469 470
    ui.protocolCombo->addItem("RTP", QVariant("rtp"));
    ui.protocolCombo->addItem("UDP", QVariant("udp"));
471
    ui.protocolCombo->addItem("RTMP", QVariant("rtmp"));
472 473

    updateProtocol( ui.protocolCombo->currentIndex() );
474 475 476 477 478 479 480 481 482 483 484 485

    if( config_GetInt( p_intf, "qt-recentplay" ) )
    {
        mrlList = new QStringListModel(
                getSettings()->value( "Open/netMRL" ).toStringList() );
        QCompleter *completer = new QCompleter( mrlList, this );
        ui.addressText->setCompleter( completer );

        CONNECT( ui.addressText, editingFinished(), this, updateCompleter() );
    }
    else
        mrlList = NULL;
zorglub's avatar
zorglub committed
486 487
}

488
NetOpenPanel::~NetOpenPanel()
489 490 491 492 493 494 495 496
{
    if( !mrlList ) return;

    QStringList tempL = mrlList->stringList();
    while( tempL.size() > 8 ) tempL.removeFirst();

    getSettings()->setValue( "Open/netMRL", tempL );
}
497

zorglub's avatar
zorglub committed
498
void NetOpenPanel::clear()
499 500
{}

501
/* update the widgets according the type of protocol */
502
void NetOpenPanel::updateProtocol( int idx_proto ) {
zorglub's avatar
zorglub committed
503
    QString addr = ui.addressText->text();
504
    QString proto = ui.protocolCombo->itemData( idx_proto ).toString();
zorglub's avatar
zorglub committed
505

506
    ui.portSpin->setEnabled( idx_proto == UDP_PROTO ||
507
                             idx_proto == RTP_PROTO );
508 509

    if( idx_proto == NO_PROTO ) return;
zorglub's avatar
zorglub committed
510 511

    /* If we already have a protocol in the address, replace it */
512 513
    if( addr.contains( "://"))
    {
514
        if( idx_proto != UDP_PROTO && idx_proto != RTP_PROTO )
515
            addr.replace( QRegExp("^.*://@*"), proto + "://");
516 517 518
        else if ( ( addr.contains(QRegExp("://((22[4-9])|(23\\d)|(\\[?[fF]{2}[0-9a-fA-F]{2}:))"))) ||
                ( !addr.contains(QRegExp("^\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}")) &&
                !addr.contains(QRegExp(":[a-fA-F0-9]{1,4}:")) ) )
519
             addr.replace( QRegExp("^.*://"), proto + "://@");
520 521 522
    else
             addr.replace( QRegExp("^.*://"), proto + "://");
        addr.replace( QRegExp("@+"), "@");
523
        ui.addressText->setText( addr );
zorglub's avatar
zorglub committed
524 525
    }
    updateMRL();
zorglub's avatar
zorglub committed
526
}
527

zorglub's avatar
zorglub committed
528 529 530
void NetOpenPanel::updateMRL() {
    QString mrl = "";
    QString addr = ui.addressText->text();
531
    addr = QUrl::toPercentEncoding( addr, ":/?#@!$&'()*+,;=" );
532
    int idx_proto = ui.protocolCombo->currentIndex();
533 534 535 536
    int addr_is_multicast = addr.contains(QRegExp("^(22[4-9])|(23\\d)|(\\[?[fF]{2}[0-9a-fA-F]{2}:)"))?1:0;
    int addr_is_ipv4 = addr.contains(QRegExp("^\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}"))?1:0;
    int addr_is_ipv6 = addr.contains(QRegExp(":[a-fA-F0-9]{1,4}:"))?1:0;
    int addr_has_port = addr.contains(QRegExp("[^:]{5}:\\d{1,5}$"))?1:0;
537
    if( addr.contains( "://"))
538
    {
539 540 541
        /* Match the correct item in the comboBox */
        ui.protocolCombo->setCurrentIndex(
                ui.protocolCombo->findData( addr.section( ':', 0, 0 ) ) );
542
        mrl = addr;
543 544 545
    }
    else
    {
546 547
        switch( idx_proto ) {
        case HTTP_PROTO:
zorglub's avatar
zorglub committed
548
            mrl = "http://" + addr;
549 550
            emit methodChanged("http-caching");
            break;
551
        case HTTPS_PROTO:
552
            mrl = "https://" + addr;
zorglub's avatar
zorglub committed
553 554
            emit methodChanged("http-caching");
            break;
555
        case MMS_PROTO:
zorglub's avatar
zorglub committed
556 557 558
            mrl = "mms://" + addr;
            emit methodChanged("mms-caching");
            break;
559
        case FTP_PROTO:
zorglub's avatar
zorglub committed
560 561 562
            mrl = "ftp://" + addr;
            emit methodChanged("ftp-caching");
            break;
563
        case RTSP_PROTO:
zorglub's avatar
zorglub committed
564 565 566
            mrl = "rtsp://" + addr;
            emit methodChanged("rtsp-caching");
            break;
567
        case UDP_PROTO:
568 569 570 571
            if(( addr_is_multicast ) || ( !addr_is_ipv4 && !addr_is_ipv6 ))
                mrl = "udp://@";
        else
                    mrl = "udp://";
zorglub's avatar
zorglub committed
572
            /* Add [] to IPv6 */
573
            if ( addr_is_ipv6  && !addr.contains('[') )
574
            {
zorglub's avatar
zorglub committed
575
                mrl += "[" + addr + "]";
576 577
            }
            else mrl += addr;
578 579
            if(!addr_has_port)
                mrl += QString(":%1").arg( ui.portSpin->value() );
zorglub's avatar
zorglub committed
580
            emit methodChanged("udp-caching");
581
            break;
582
        case RTP_PROTO:
583 584 585 586 587
            if(( addr_is_multicast ) || ( !addr_is_ipv4 && !addr_is_ipv6 ))
                    mrl = "rtp://@";
            else
                    mrl = "rtp://";
            if ( addr_is_ipv6 && !addr.contains('[') )
588 589 590
                mrl += "[" + addr + "]"; /* Add [] to IPv6 */
            else
                mrl += addr;
591 592
            if(!addr_has_port)
                mrl += QString(":%1").arg( ui.portSpin->value() );
593 594
            emit methodChanged("rtp-caching");
            break;
595 596 597 598
        case RTMP_PROTO:
            mrl = "rtmp://" + addr;
            emit methodChanged("rtmp-caching");
            break;
zorglub's avatar
zorglub committed
599 600
        }
    }
601

602 603
    QStringList qsl; qsl<< mrl;
    emit mrlUpdated( qsl, "" );
zorglub's avatar
zorglub committed
604
}
605

606 607 608 609 610 611 612 613
void NetOpenPanel::updateCompleter()
{
    assert( mrlList );
    QStringList tempL = mrlList->stringList();
    tempL.append( ui.addressText->text() );
    mrlList->setStringList( tempL );
}

614
/**************************************************************************
615
 * Open Capture device ( DVB, PVR, V4L, and similar )                     *
616 617 618 619
 **************************************************************************/
CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
                                OpenPanel( _parent, _p_intf )
{
620 621 622 623 624 625 626 627 628 629
    isInitialized = false;
}

void CaptureOpenPanel::initialize()
{
    if( isInitialized ) return;

    msg_Dbg( p_intf, "Initialization of Capture device panel" );
    isInitialized = true;

630
    ui.setupUi( this );
631

632 633
    BUTTONACT( ui.advancedButton, advancedDialog() );

634
    /* Create two stacked layouts in the main comboBoxes */
635 636 637 638 639 640
    QStackedLayout *stackedDevLayout = new QStackedLayout;
    ui.cardBox->setLayout( stackedDevLayout );

    QStackedLayout *stackedPropLayout = new QStackedLayout;
    ui.optionsBox->setLayout( stackedPropLayout );

641
    /* Creation and connections of the WIdgets in the stacked layout */
642
#define addModuleAndLayouts( number, name, label )                    \
643 644
    QWidget * name ## DevPage = new QWidget( this );                  \
    QWidget * name ## PropPage = new QWidget( this );                 \
645 646
    stackedDevLayout->addWidget( name ## DevPage );        \
    stackedPropLayout->addWidget( name ## PropPage );      \
647 648 649 650
    QGridLayout * name ## DevLayout = new QGridLayout;                \
    QGridLayout * name ## PropLayout = new QGridLayout;               \
    name ## DevPage->setLayout( name ## DevLayout );                  \
    name ## PropPage->setLayout( name ## PropLayout );                \
651
    ui.deviceCombo->addItem( qtr( label ), QVariant( number ) );
652 653 654

#define CuMRL( widget, slot ) CONNECT( widget , slot , this, updateMRL() );

655 656 657 658
#ifdef WIN32
    /*********************
     * DirectShow Stuffs *
     *********************/
659
    if( module_exists( "dshow" ) ){
660 661
    addModuleAndLayouts( DSHOW_DEVICE, dshow, "DirectShow" );

662 663 664 665 666 667 668 669 670 671 672 673 674
    /* dshow Main */
    int line = 0;
    module_config_t *p_config =
        config_FindConfig( VLC_OBJECT(p_intf), "dshow-vdev" );
    vdevDshowW = new StringListConfigControl(
        VLC_OBJECT(p_intf), p_config, this, false, dshowDevLayout, line );
    line++;

    p_config = config_FindConfig( VLC_OBJECT(p_intf), "dshow-adev" );
    adevDshowW = new StringListConfigControl(
        VLC_OBJECT(p_intf), p_config, this, false, dshowDevLayout, line );
    line++;

675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692
    /* dshow Properties */
    QLabel *dshowVSizeLabel = new QLabel( qtr( "Video size" ) );
    dshowPropLayout->addWidget( dshowVSizeLabel, 0, 0 );

    dshowVSizeLine = new QLineEdit;
    dshowPropLayout->addWidget( dshowVSizeLine, 0, 1);
    dshowPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
            1, 0, 3, 1 );

    /* dshow CONNECTs */
    CuMRL( vdevDshowW->combo, currentIndexChanged ( int ) );
    CuMRL( adevDshowW->combo, currentIndexChanged ( int ) );
    CuMRL( dshowVSizeLine, textChanged( QString ) );
    }

    /**************
     * BDA Stuffs *
     **************/
693
    if( module_exists( "bda" ) ){
694 695 696 697 698 699 700 701 702
    addModuleAndLayouts( BDA_DEVICE, bda, "DVB DirectShow" );

    /* bda Main */
    QLabel *bdaTypeLabel = new QLabel( qtr( "DVB Type:" ) );

    bdas = new QRadioButton( "DVB-S" );
    bdas->setChecked( true );
    bdac = new QRadioButton( "DVB-C" );
    bdat = new QRadioButton( "DVB-T" );
kenself's avatar
kenself committed
703
    bdaa = new QRadioButton( "ATSC" );
704 705 706 707 708

    bdaDevLayout->addWidget( bdaTypeLabel, 0, 0 );
    bdaDevLayout->addWidget( bdas, 0, 1 );
    bdaDevLayout->addWidget( bdac, 0, 2 );
    bdaDevLayout->addWidget( bdat, 0, 3 );
kenself's avatar
kenself committed
709
    bdaDevLayout->addWidget( bdaa, 0, 4 );
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735

    /* bda Props */
    QLabel *bdaFreqLabel =
                    new QLabel( qtr( "Transponder/multiplex frequency" ) );
    bdaPropLayout->addWidget( bdaFreqLabel, 0, 0 );

    bdaFreq = new QSpinBox;
    bdaFreq->setAlignment( Qt::AlignRight );
    bdaFreq->setSuffix(" kHz");
    bdaFreq->setSingleStep( 1000 );
    setSpinBoxFreq( bdaFreq )
    bdaPropLayout->addWidget( bdaFreq, 0, 1 );

    bdaSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
    bdaPropLayout->addWidget( bdaSrateLabel, 1, 0 );

    bdaSrate = new QSpinBox;
    bdaSrate->setAlignment( Qt::AlignRight );
    bdaSrate->setSuffix(" kHz");
    setSpinBoxFreq( bdaSrate );
    bdaPropLayout->addWidget( bdaSrate, 1, 1 );

    bdaBandLabel = new QLabel( qtr( "Bandwidth" ) );
    bdaPropLayout->addWidget( bdaBandLabel, 2, 0 );

    bdaBandBox = new QComboBox;
736
    setfillVLCConfigCombo( "dvb-bandwidth", p_intf, bdaBandBox );
737 738 739 740 741 742 743 744 745 746 747 748 749 750
    bdaPropLayout->addWidget( bdaBandBox, 2, 1 );

    bdaBandLabel->hide();
    bdaBandBox->hide();
    bdaPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
            2, 0, 2, 1 );

    /* bda CONNECTs */
    CuMRL( bdaFreq, valueChanged ( int ) );
    CuMRL( bdaSrate, valueChanged ( int ) );
    CuMRL( bdaBandBox,  currentIndexChanged ( int ) );
    BUTTONACT( bdas, updateButtons() );
    BUTTONACT( bdat, updateButtons() );
    BUTTONACT( bdac, updateButtons() );
kenself's avatar
kenself committed
751
    BUTTONACT( bdaa, updateButtons() );
752 753 754
    BUTTONACT( bdas, updateMRL() );
    BUTTONACT( bdat, updateMRL() );
    BUTTONACT( bdac, updateMRL() );
kenself's avatar
kenself committed
755
    BUTTONACT( bdaa, updateMRL() );
756 757 758
    }

#else /* WIN32 */
759 760 761
    /*******
     * V4L2*
     *******/
762
    if( module_exists( "v4l2" ) ){
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
    addModuleAndLayouts( V4L2_DEVICE, v4l2, "Video for Linux 2" );

    /* V4l Main panel */
    QLabel *v4l2VideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
    v4l2DevLayout->addWidget( v4l2VideoDeviceLabel, 0, 0 );

    v4l2VideoDevice = new QLineEdit;
    v4l2DevLayout->addWidget( v4l2VideoDevice, 0, 1 );

    QLabel *v4l2AudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
    v4l2DevLayout->addWidget( v4l2AudioDeviceLabel, 1, 0 );

    v4l2AudioDevice = new QLineEdit;
    v4l2DevLayout->addWidget( v4l2AudioDevice, 1, 1 );

    /* v4l2 Props panel */
    QLabel *v4l2StdLabel = new QLabel( qtr( "Standard" ) );
    v4l2PropLayout->addWidget( v4l2StdLabel, 0 , 0 );

    v4l2StdBox = new QComboBox;
783
    setfillVLCConfigCombo( "v4l2-standard", p_intf, v4l2StdBox );
784 785 786 787 788 789 790 791 792 793
    v4l2PropLayout->addWidget( v4l2StdBox, 0 , 1 );
    v4l2PropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
            1, 0, 3, 1 );

    /* v4l2 CONNECTs */
    CuMRL( v4l2VideoDevice, textChanged( QString ) );
    CuMRL( v4l2AudioDevice, textChanged( QString ) );
    CuMRL( v4l2StdBox,  currentIndexChanged ( int ) );
    }

794 795 796
    /*******
     * V4L *
     *******/
797
    if( module_exists( "v4l" ) ){
798
    addModuleAndLayouts( V4L_DEVICE, v4l, "Video for Linux" );
799 800

    /* V4l Main panel */
801 802
    QLabel *v4lVideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
    v4lDevLayout->addWidget( v4lVideoDeviceLabel, 0, 0 );
803

804
    v4lVideoDevice = new QLineEdit;
805
    v4lDevLayout->addWidget( v4lVideoDevice, 0, 1 );
806

807 808
    QLabel *v4lAudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
    v4lDevLayout->addWidget( v4lAudioDeviceLabel, 1, 0 );
809

810
    v4lAudioDevice = new QLineEdit;
811 812
    v4lDevLayout->addWidget( v4lAudioDevice, 1, 1 );

813
    /* V4l Props panel */
814 815 816
    QLabel *v4lNormLabel = new QLabel( qtr( "Norm" ) );
    v4lPropLayout->addWidget( v4lNormLabel, 0 , 0 );

817
    v4lNormBox = new QComboBox;
818
    setfillVLCConfigCombo( "v4l-norm", p_intf, v4lNormBox );
819
    v4lPropLayout->addWidget( v4lNormBox, 0 , 1 );
820

821 822 823
    QLabel *v4lFreqLabel = new QLabel( qtr( "Frequency" ) );
    v4lPropLayout->addWidget( v4lFreqLabel, 1 , 0 );

824
    v4lFreq = new QSpinBox;
825 826
    v4lFreq->setAlignment( Qt::AlignRight );
    v4lFreq->setSuffix(" kHz");
827
    setSpinBoxFreq( v4lFreq );
828
    v4lPropLayout->addWidget( v4lFreq, 1 , 1 );
829 830
    v4lPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
            2, 0, 2, 1 );
831 832 833 834 835 836

    /* v4l CONNECTs */
    CuMRL( v4lVideoDevice, textChanged( QString ) );
    CuMRL( v4lAudioDevice, textChanged( QString ) );
    CuMRL( v4lFreq, valueChanged ( int ) );
    CuMRL( v4lNormBox,  currentIndexChanged ( int ) );
837
    }
838

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
839 840 841
    /*******
     * JACK *
     *******/
842
    if( module_exists( "jack" ) ){
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
843 844 845 846
    addModuleAndLayouts( JACK_DEVICE, jack, "JACK Audio Connection Kit" );

    /* Jack Main panel */
    /* Channels */