]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/open.cpp
Qt4 - Open: Capture Tab added. Still almost empty, but well, this is coming after. :D
[vlc] / modules / gui / qt4 / dialogs / open.cpp
index 508d12869edee2594610c3076815a1c639decfd3..4f5bfb45340ee94a777a65ac032cf4174aa823c6 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <QTabWidget>
 #include <QGridLayout>
+#include <QFileDialog>
+#include <QRegExp>
 
 #include "dialogs/open.hpp"
 #include "components/open.hpp"
 
 OpenDialog *OpenDialog::instance = NULL;
 
-OpenDialog::OpenDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
+OpenDialog::OpenDialog( QWidget *parent, intf_thread_t *_p_intf, bool modal ) :
+                                                QVLCDialog( parent, _p_intf )
 {
-    setWindowTitle( _("Open" ) );
+    setModal( modal );
     ui.setupUi( this );
-    fileOpenPanel = new FileOpenPanel(this , _p_intf );
-    ui.Tab->addTab(fileOpenPanel, "Test");
+    setWindowTitle( qtr("Open" ) );
+    fileOpenPanel = new FileOpenPanel( this , p_intf );
+    diskOpenPanel = new DiskOpenPanel( this , p_intf );
+    netOpenPanel = new NetOpenPanel( this , p_intf );
+    captureOpenPanel = new CaptureOpenPanel( this, p_intf );
+
+    ui.Tab->addTab( fileOpenPanel, qtr( "File" ) );
+    ui.Tab->addTab( diskOpenPanel, qtr( "Disc" ) );
+    ui.Tab->addTab( netOpenPanel, qtr( "Network" ) );
+    ui.Tab->addTab( captureOpenPanel, qtr( "Capture" ) );
+
+    ui.advancedFrame->hide();
+
+    /* Force MRL update on tab change */
+    CONNECT( ui.Tab, currentChanged(int), this, signalCurrent());
+
+    CONNECT( fileOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
+    CONNECT( netOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
+    CONNECT( diskOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
+    CONNECT( captureOpenPanel, mrlUpdated( QString ), this,
+            updateMRL(QString) );
+
+
+    CONNECT( fileOpenPanel, methodChanged( QString ),
+             this, newMethod(QString) );
+    CONNECT( netOpenPanel, methodChanged( QString ),
+             this, newMethod(QString) );
+    CONNECT( diskOpenPanel, methodChanged( QString ),
+             this, newMethod(QString) );
+
+    CONNECT( ui.slaveText, textChanged(QString), this, updateMRL());
+    CONNECT( ui.cacheSpinBox, valueChanged(int), this, updateMRL());
+
+    BUTTONACT( ui.closeButton, ok());
+    BUTTONACT( ui.cancelButton, cancel());
+    BUTTONACT( ui.advancedCheckBox , toggleAdvancedPanel() );
+
+    /* Initialize caching */
+    storedMethod = "";
+    newMethod("file-caching");
+
+    mainHeight = advHeight = 0;
 }
 
 OpenDialog::~OpenDialog()
 {
 }
 
+void OpenDialog::showTab(int i_tab=0)
+{
+    printf ( "%i" , i_tab);
+    this->show();
+    ui.Tab->setCurrentIndex(i_tab);
+}
+
+void OpenDialog::signalCurrent() {
+    if (ui.Tab->currentWidget() != NULL) {
+        (dynamic_cast<OpenPanel*>(ui.Tab->currentWidget()))->updateMRL();
+    }
+}
+
 void OpenDialog::cancel()
 {
+    fileOpenPanel->clear();
     this->toggleVisible();
+    if( isModal() )
+        reject();
 }
 
 void OpenDialog::ok()
 {
     this->toggleVisible();
+    mrl = ui.advancedLineInput->text();
+    QStringList tempMRL = mrl.split( QRegExp("\"\\s+\""),
+                                     QString::SkipEmptyParts );
+    if( !isModal() )
+    {
+        for( size_t i = 0 ; i< tempMRL.size(); i++ )
+        {
+             QString mrli = tempMRL[i].remove( QRegExp( "^\"" ) ).
+                                       remove( QRegExp( "\"\\s+$" ) );
+             const char * psz_utf8 = qtu( tempMRL[i] );
+             /* Play the first one, parse and enqueue the other ones */
+             playlist_Add( THEPL, psz_utf8, NULL,
+                           PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
+                           ( i ? PLAYLIST_PREPARSE : 0 ),
+                           PLAYLIST_END, VLC_TRUE, VLC_FALSE );
+        }
+
+    }
+    else
+        accept();
+}
+
+void OpenDialog::toggleAdvancedPanel()
+{
+    if (ui.advancedFrame->isVisible()) {
+        ui.advancedFrame->hide();
+        setMinimumHeight(1);
+        resize( width(), mainHeight );
+
+    } else {
+        if( mainHeight == 0 )
+            mainHeight = height();
+
+        ui.advancedFrame->show();
+        if( advHeight == 0 ) {
+            advHeight = height() - mainHeight;
+        }
+        resize( width(), mainHeight + advHeight );
+    }
+}
+
+void OpenDialog::updateMRL() {
+    mrl = mainMRL;
+    if( ui.slaveCheckbox->isChecked() ) {
+        mrl += " :input-slave=" + ui.slaveText->text();
+    }
+    int i_cache = config_GetInt( p_intf, qta(storedMethod) );
+    if( i_cache != ui.cacheSpinBox->value() ) {
+        mrl += QString(" :%1=%2").arg(storedMethod).
+                                  arg(ui.cacheSpinBox->value());
+    }
+    ui.advancedLineInput->setText(mrl);
+}
+
+void OpenDialog::updateMRL(QString tempMRL)
+{
+    mainMRL = tempMRL;
+    updateMRL();
+}
+
+void OpenDialog::newMethod(QString method)
+{
+    if( method != storedMethod ) {
+        storedMethod = method;
+        int i_value = config_GetInt( p_intf, qta(storedMethod) );
+        ui.cacheSpinBox->setValue(i_value);
+    }
 }