open.cpp 12.5 KB
Newer Older
zorglub's avatar
zorglub committed
1 2 3
/*****************************************************************************
 * open.cpp : Panels for the open dialogs
 ****************************************************************************
4 5
 * Copyright (C) 2006 the VideoLAN team
 * $Id$
zorglub's avatar
zorglub committed
6 7
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
zorglub's avatar
zorglub committed
8
 *          Jean-Baptiste Kempf <jb@videolan.org>
zorglub's avatar
zorglub committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * 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.
 *****************************************************************************/

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
25 26

#include "qt4.hpp"
zorglub's avatar
zorglub committed
27
#include "components/open.hpp"
28
#include "dialogs/open.hpp"
29
#include "dialogs_provider.hpp"
30 31 32 33 34
#include "util/customwidgets.hpp"

#include <QFileDialog>
#include <QDialogButtonBox>
#include <QLineEdit>
35

zorglub's avatar
zorglub committed
36 37 38 39 40 41
/**************************************************************************
 * File open
 **************************************************************************/
FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
                                OpenPanel( _parent, _p_intf )
{
42
    /* Classic UI Setup */
zorglub's avatar
zorglub committed
43
    ui.setupUi( this );
44

45 46 47 48
    /* 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. */

49 50 51 52 53 54 55 56 57
    /* 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 );
    fileTypes.replace(QString(";*"), QString(" *"));

58
    // Make this QFileDialog a child of tempWidget from the ui.
59
    dialogBox = new FileOpenBox( ui.tempWidget, NULL,
60
            qfu( p_intf->p_libvlc->psz_homedir ), fileTypes );
61
/*    dialogBox->setFileMode( QFileDialog::ExistingFiles );*/
62 63
    dialogBox->setAcceptMode( QFileDialog::AcceptOpen );

64 65 66
    /* We don't want to see a grip in the middle of the window, do we? */
    dialogBox->setSizeGripEnabled( false );
    dialogBox->setToolTip( qtr( "Select one or multiple files, or a folder" ));
67 68 69 70 71

    // Add it to the layout
    ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );

    // But hide the two OK/Cancel buttons. Enable them for debug.
72 73
    QDialogButtonBox *fileDialogAcceptBox =
                        findChildren<QDialogButtonBox*>()[0];
74
    fileDialogAcceptBox->hide();
75 76 77 78 79 80 81 82 83 84 85 86 87

    /* Ugly hacks to get the good Widget */
    //This lineEdit is the normal line in the fileDialog.
    lineFileEdit = findChildren<QLineEdit*>()[3];
    lineFileEdit->hide();

    /* Make a list of QLabel inside the QFileDialog to access the good ones */
    QList<QLabel *> listLabel = findChildren<QLabel*>();

    /* Hide the FileNames one. Enable it for debug */
    listLabel[4]->hide();
    /* Change the text that was uncool in the usual box */
    listLabel[5]->setText( qtr( "Filter:" ) );
zorglub's avatar
zorglub committed
88

89 90 91
    // Hide the subtitles control by default.
    ui.subFrame->hide();

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    /* Build the subs size combo box */
    module_config_t *p_item =
        config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
    if( p_item )
    {
        for( int i_index = 0; i_index < p_item->i_list; i_index++ )
        {
            ui.sizeSubComboBox->addItem(
                qfu( p_item->ppsz_list_text[i_index] ),
                QVariant( p_item->pi_list[i_index] ) );
            if( p_item->value.i == p_item->pi_list[i_index] )
            {
                ui.sizeSubComboBox->setCurrentIndex( i_index );
            }
        }
    }
108

yoann's avatar
yoann committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
    /* Build the subs align combo box */
    p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
    if( p_item )
    {
        for( int i_index = 0; i_index < p_item->i_list; i_index++ )
        {
            ui.alignSubComboBox->addItem(
                qfu( p_item->ppsz_list_text[i_index] ),
                QVariant( p_item->pi_list[i_index] ) );
            if( p_item->value.i == p_item->pi_list[i_index] )
            {
                ui.alignSubComboBox->setCurrentIndex( i_index );
            }
        }
    }

125
    BUTTONACT( ui.subBrowseButton, browseFileSub() );
126
    BUTTONACT( ui.subCheckBox, toggleSubtitleFrame());
zorglub's avatar
zorglub committed
127

128
    CONNECT( ui.fileInput, editTextChanged(QString ), this, updateMRL());
zorglub's avatar
zorglub committed
129 130 131
    CONNECT( ui.subInput, editTextChanged(QString ), this, updateMRL());
    CONNECT( ui.alignSubComboBox, currentIndexChanged(int), this, updateMRL());
    CONNECT( ui.sizeSubComboBox, currentIndexChanged(int), this, updateMRL());
132
    CONNECT( lineFileEdit, textChanged( QString ), this, browseFile());
zorglub's avatar
zorglub committed
133 134 135 136 137
}

FileOpenPanel::~FileOpenPanel()
{}

zorglub's avatar
zorglub committed
138
QStringList FileOpenPanel::browse(QString help)
139
{
140
    return THEDP->showSimpleOpen( help );
141 142 143 144
}

void FileOpenPanel::browseFile()
{
zorglub's avatar
zorglub committed
145
    QString fileString = "";
146
    foreach( QString file, dialogBox->selectedFiles() ) {
147
         fileString += "\"" + file + "\" ";
zorglub's avatar
zorglub committed
148 149
    }
    ui.fileInput->setEditText( fileString );
150 151 152 153 154
    updateMRL();
}

void FileOpenPanel::browseFileSub()
{
155
    // FIXME Handle selection of more than one subtitles file
156
    QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
157 158
                            EXT_FILTER_SUBTITLE,
                            dialogBox->directory().absolutePath() );
159
    if( files.isEmpty() ) return;
160
    ui.subInput->setEditText( files.join(" ") );
zorglub's avatar
zorglub committed
161
    updateMRL();
162 163 164 165
}

void FileOpenPanel::updateMRL()
{
zorglub's avatar
zorglub committed
166 167
    QString mrl = ui.fileInput->currentText();

168
    if( ui.subCheckBox->isChecked() ) {
zorglub's avatar
zorglub committed
169
        mrl.append( " :sub-file=" + ui.subInput->currentText() );
170 171 172
        int align = ui.alignSubComboBox->itemData( ui.alignSubComboBox->currentIndex() ).toInt();
        mrl.append( " :subsdec-align=" + QString().setNum( align ) );
        int size = ui.sizeSubComboBox->itemData( ui.sizeSubComboBox->currentIndex() ).toInt();
173
        mrl.append( " :freetype-rel-fontsize=" + QString().setNum( size ) );
zorglub's avatar
zorglub committed
174
    }
175
    emit mrlUpdated( mrl );
zorglub's avatar
zorglub committed
176
    emit methodChanged( "file-caching" );
zorglub's avatar
zorglub committed
177 178
}

179 180 181 182 183 184 185 186

/* Function called by Open Dialog when clicke on Play/Enqueue */
void FileOpenPanel::accept()
{
    ui.fileInput->addItem(ui.fileInput->currentText());
    if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem(0);
}

187 188 189 190
void FileOpenBox::accept()
{
    OpenDialog::getInstance( NULL, NULL )->play();
}
191 192

/* Function called by Open Dialog when clicked on cancel */
193 194
void FileOpenPanel::clear()
{
195 196
    ui.fileInput->setEditText( "" );
    ui.subInput->setEditText( "" );
197 198
}

199 200 201 202 203
void FileOpenPanel::toggleSubtitleFrame()
{
    if (ui.subFrame->isVisible())
    {
        ui.subFrame->hide();
204 205
        updateGeometry();
    /* FiXME Size */
206 207 208 209 210 211 212 213 214 215
    }
    else
    {
        ui.subFrame->show();
    }

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

zorglub's avatar
zorglub committed
216
/**************************************************************************
217
 * Disk open
zorglub's avatar
zorglub committed
218
 **************************************************************************/
219
DiscOpenPanel::DiscOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
zorglub's avatar
zorglub committed
220 221 222
                                OpenPanel( _parent, _p_intf )
{
    ui.setupUi( this );
zorglub's avatar
zorglub committed
223 224 225 226 227 228 229 230

    CONNECT( ui.deviceCombo, editTextChanged(QString ), this, updateMRL());
    BUTTONACT( ui.dvdRadioButton, updateMRL());
    BUTTONACT( ui.vcdRadioButton, updateMRL());
    BUTTONACT( ui.audioCDRadioButton, updateMRL());

    CONNECT( ui.titleSpin, valueChanged(int), this, updateMRL());
    CONNECT( ui.chapterSpin, valueChanged(int), this, updateMRL());
zorglub's avatar
zorglub committed
231 232
}

233
DiscOpenPanel::~DiscOpenPanel()
234 235
{}

236
void DiscOpenPanel::clear()
zorglub's avatar
zorglub committed
237
{
zorglub's avatar
zorglub committed
238 239 240
    ui.titleSpin->setValue(0);
    ui.chapterSpin->setValue(0);
}
241

242
void DiscOpenPanel::updateMRL()
zorglub's avatar
zorglub committed
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
{
    QString mrl = "";
    /* DVD */
    if( ui.dvdRadioButton->isChecked() ) {
        mrl = "dvd://" + ui.deviceCombo->currentText();
        emit methodChanged( "dvdnav-caching" );

        if ( ui.titleSpin->value() > 0 ) {
            mrl += QString("@%1").arg(ui.titleSpin->value());
            if ( ui.chapterSpin->value() > 0 ) {
                mrl+= QString(":%1").arg(ui.chapterSpin->value());
            }
        }

    /* VCD */
    } else if (ui.vcdRadioButton->isChecked() ) {
        mrl = "vcd://" + ui.deviceCombo->currentText();
        emit methodChanged( "vcd-caching" );

        if( ui.titleSpin->value() > 0 ) {
            mrl += QString("@%1").arg(ui.titleSpin->value());
        }

    /* CDDA */
    } else {
        mrl = "cdda://" + ui.deviceCombo->currentText();
    }

    emit mrlUpdated(mrl);
272 273 274
}


zorglub's avatar
zorglub committed
275

276 277 278 279 280 281 282
/**************************************************************************
 * Net open
 **************************************************************************/
NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
                                OpenPanel( _parent, _p_intf )
{
    ui.setupUi( this );
zorglub's avatar
zorglub committed
283 284 285 286 287 288 289 290 291 292 293 294 295 296

    CONNECT( ui.protocolCombo, currentIndexChanged(int),
             this, updateProtocol(int) );
    CONNECT( ui.portSpin, valueChanged(int), this, updateMRL());
    CONNECT( ui.addressText, textChanged(QString), this, updateAddress());
    CONNECT( ui.timeShift, clicked(), this, updateMRL());
    CONNECT( ui.ipv6, clicked(), this, updateMRL());

    ui.protocolCombo->addItem("HTTP", QVariant("http"));
    ui.protocolCombo->addItem("FTP", QVariant("ftp"));
    ui.protocolCombo->addItem("MMS", QVariant("mms"));
    ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
    ui.protocolCombo->addItem("UDP/RTP (unicast)", QVariant("udp"));
    ui.protocolCombo->addItem("UDP/RTP (multicast)", QVariant("udp"));
zorglub's avatar
zorglub committed
297 298
}

299 300 301
NetOpenPanel::~NetOpenPanel()
{}

zorglub's avatar
zorglub committed
302
void NetOpenPanel::clear()
303 304
{}

zorglub's avatar
zorglub committed
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
void NetOpenPanel::updateProtocol(int idx) {
    QString addr = ui.addressText->text();
    QString proto = ui.protocolCombo->itemData(idx).toString();

    ui.timeShift->setEnabled( idx >= 4);
    ui.ipv6->setEnabled( idx == 4 );
    ui.addressText->setEnabled( idx != 4 );
    ui.portSpin->setEnabled( idx >= 4 );

    /* If we already have a protocol in the address, replace it */
    if( addr.contains( "://")) {
        msg_Err( p_intf, "replace");
        addr.replace(QRegExp("^.*://"), proto + "://");
        ui.addressText->setText(addr);
    }

    updateMRL();
zorglub's avatar
zorglub committed
322
}
323

zorglub's avatar
zorglub committed
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
void NetOpenPanel::updateAddress() {
    updateMRL();
}

void NetOpenPanel::updateMRL() {
    QString mrl = "";
    QString addr = ui.addressText->text();
    int proto = ui.protocolCombo->currentIndex();

    if( addr.contains( "://") && proto != 4 ) {
        mrl = addr;
    } else {
        switch(proto) {
        case 0:
            mrl = "http://" + addr;
            emit methodChanged("http-caching");
            break;
        case 2:
            mrl = "mms://" + addr;
            emit methodChanged("mms-caching");
            break;
        case 1:
            mrl = "ftp://" + addr;
            emit methodChanged("ftp-caching");
            break;
        case 3: /* RTSP */
            mrl = "rtsp://" + addr;
            emit methodChanged("rtsp-caching");
            break;
        case 4:
            mrl = "udp://@";
            if( ui.ipv6->isEnabled() && ui.ipv6->isChecked() ) {
                mrl += "[::]";
            }
            mrl += QString(":%1").arg(ui.portSpin->value());
            emit methodChanged("udp-caching");
            break;
        case 5: /* UDP multicast */
            mrl = "udp://@";
            /* Add [] to IPv6 */
            if ( addr.contains(':') && !addr.contains('[') ) {
                mrl += "[" + addr + "]";
            } else mrl += addr;
            mrl += QString(":%1").arg(ui.portSpin->value());
            emit methodChanged("udp-caching");
        }
    }
    if( ui.timeShift->isEnabled() && ui.timeShift->isChecked() ) {
        mrl += " :access-filter=timeshift";
    }
    emit mrlUpdated(mrl);
}
376 377 378 379 380 381 382 383 384 385 386 387 388

/**************************************************************************
 * Capture open
 **************************************************************************/
CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
                                OpenPanel( _parent, _p_intf )
{
    ui.setupUi( this );
}

CaptureOpenPanel::~CaptureOpenPanel()
{}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
389
void CaptureOpenPanel::clear()
390 391
{}

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
392
void CaptureOpenPanel::updateMRL()
393 394 395 396
{
    QString mrl = "";
    emit mrlUpdated(mrl);
}