]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/open.cpp
Qt4 - Open. Use a Frame and not a QComboBox for subtitles. (lacks still some toggle...
[vlc] / modules / gui / qt4 / components / open.cpp
index 525351ce618b51b0a1d813d4268e3b17279ca8b2..313c827342ef42003e0a6eb9bb63179e64babdef 100644 (file)
@@ -5,7 +5,7 @@
  * $Id$
  *
  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
- *          Jean-Baptiste Kempf <jb@videolan.org> 
+ *          Jean-Baptiste Kempf <jb@videolan.org>
  *
  * 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
 
 #include "qt4.hpp"
 #include "components/open.hpp"
+#include "dialogs_provider.hpp"
+#include "util/customwidgets.hpp"
 
-/**************************************************************************
- * Open panel
- ***************************************************************************/
-
-OpenPanel::~OpenPanel()
-{}
+#include <QFileDialog>
+#include <QDialogButtonBox>
+#include <QLineEdit>
 
 /**************************************************************************
  * File open
@@ -39,34 +38,121 @@ OpenPanel::~OpenPanel()
 FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
                                 OpenPanel( _parent, _p_intf )
 {
+    /* Classic UI Setup */
     ui.setupUi( this );
-    ui.audioGroupBox->hide();
-    BUTTONACT( ui.extraAudioButton, toggleExtraAudio() );
+
+    /* 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. */
+
+    // Make this QFileDialog a child of tempWidget from the ui.
+    dialogBox = new QFileDialog( ui.tempWidget );
+    dialogBox->setFileMode( QFileDialog::ExistingFiles );
+    dialogBox->setDirectory( qfu( p_intf->p_libvlc->psz_homedir ) );
+    /* We don't want to see a grip in the middle of the window, do we? */
+    dialogBox->setSizeGripEnabled( false );
+
+    // Add it to the layout
+    ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
+
+    // But hide the two OK/Cancel buttons. Enable them for debug.
+    findChild<QDialogButtonBox*>()->hide();
+
+    /* 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:" ) );
+
+    /* Hacks Continued Catch the close event */
+    dialogBox->installEventFilter( this );
+
+    // Hide the subtitles control by default.
+    ui.subFrame->hide();
+
+
+    BUTTONACT( ui.subBrowseButton, browseFileSub() );
+    BUTTONACT( ui.subCheckBox, updateMRL());
+
+    CONNECT( ui.fileInput, editTextChanged(QString ), this, updateMRL());
+    CONNECT( ui.subInput, editTextChanged(QString ), this, updateMRL());
+    CONNECT( ui.alignSubComboBox, currentIndexChanged(int), this, updateMRL());
+    CONNECT( ui.sizeSubComboBox, currentIndexChanged(int), this, updateMRL());
+    CONNECT( lineFileEdit, textChanged( QString ), this, browseFile());
 }
 
 FileOpenPanel::~FileOpenPanel()
 {}
 
-void FileOpenPanel::sendUpdate()
-{}
+QStringList FileOpenPanel::browse(QString help)
+{
+    return THEDP->showSimpleOpen( help );
+}
+
+void FileOpenPanel::browseFile()
+{
+    QString fileString = "";
+    foreach( QString file, dialogBox->selectedFiles() ) { 
+         fileString += "\"" + file + "\" ";
+    }
+    ui.fileInput->setEditText( fileString );
+    updateMRL();
+}
+
+void FileOpenPanel::browseFileSub()
+{
+    ui.subInput->setEditText( browse( qtr("Open subtitles file") ).join(" ") );
+    updateMRL();
+}
+
+void FileOpenPanel::updateMRL()
+{
+    QString mrl = ui.fileInput->currentText();
+
+    if( ui.subCheckBox->isChecked() ) {
+        mrl.append( " :sub-file=" + ui.subInput->currentText() );
+        mrl.append( " :subsdec-align=" + ui.alignSubComboBox->currentText() );
+        mrl.append( " :sub-rel-fontsize=" + ui.sizeSubComboBox->currentText() );
+    }
+    emit mrlUpdated( mrl );
+    emit methodChanged( "file-caching" );
+}
+
 
-QString FileOpenPanel::getUpdatedMRL()
+/* Function called by Open Dialog when clicke on Play/Enqueue */
+void FileOpenPanel::accept()
 {
-    return ui.fileInput->currentText();
+    ui.fileInput->addItem(ui.fileInput->currentText());
+    if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem(0);
 }
 
-void FileOpenPanel::toggleExtraAudio()
+
+/* Function called by Open Dialog when clicked on cancel */
+void FileOpenPanel::clear()
 {
-   if (ui.audioGroupBox->isVisible())
-   {
-       ui.audioGroupBox->hide();
-   }
-   else
-   {
-      ui.audioGroupBox->show();
-   }
+    ui.fileInput->setEditText( "" );
+    ui.subInput->setEditText( "" );
 }
 
+bool FileOpenPanel::eventFilter(QObject *object, QEvent *event)
+{
+    printf( "coin\n" );
+    if ( ( object == dialogBox ) && ( event->type() == QEvent::Hide ) )
+    {
+         event->ignore();
+         return true;
+    }
+    // standard event processing
+    else
+        return QObject::eventFilter(object, event);
+}
 
 /**************************************************************************
  * Disk open
@@ -75,18 +161,55 @@ DiskOpenPanel::DiskOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
                                 OpenPanel( _parent, _p_intf )
 {
     ui.setupUi( this );
+
+    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());
 }
 
 DiskOpenPanel::~DiskOpenPanel()
 {}
 
-void DiskOpenPanel::sendUpdate()
-{}
+void DiskOpenPanel::clear()
+{
+    ui.titleSpin->setValue(0);
+    ui.chapterSpin->setValue(0);
+}
 
-QString DiskOpenPanel::getUpdatedMRL()
+void DiskOpenPanel::updateMRL()
 {
-    //return ui.DiskInput->currentText();
-    return NULL;
+    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);
 }
 
 
@@ -98,25 +221,117 @@ NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
                                 OpenPanel( _parent, _p_intf )
 {
     ui.setupUi( this );
+
+    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"));
 }
 
 NetOpenPanel::~NetOpenPanel()
 {}
 
-void NetOpenPanel::sendUpdate()
+void NetOpenPanel::clear()
 {}
-/*
-void NetOpenPanel::sendUpdate()
-{
-    QString *mrl = new QString();
-    QString *cache = new QString();
-    getUpdatedMRL( mrl, cache );,
-    emit dataUpdated( mrl, cache );
-}*/
 
-QString NetOpenPanel::getUpdatedMRL()
+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();
+}
+
+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);
+}
+
+/**************************************************************************
+ * Capture open
+ **************************************************************************/
+CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
+                                OpenPanel( _parent, _p_intf )
 {
-//  return ui.NetInput->currentText();
-    return NULL;
+    ui.setupUi( this );
 }
 
+CaptureOpenPanel::~CaptureOpenPanel()
+{}
+
+void CaptureOpenPanel::clear()
+{}
+
+void CaptureOpenPanel::updateMRL()
+{
+    QString mrl = "";
+    emit mrlUpdated(mrl);
+}