]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/open.cpp
qt4 - Playlist: move the column selection to a submenu.
[vlc] / modules / gui / qt4 / dialogs / open.cpp
index 248ebfb6fbe853fc3a8daa51725f3083d1089505..f57f1c3809cc51ff4ab704177e85b3c0d2b98607 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * open.cpp : Advanced open dialog
  *****************************************************************************
- * Copyright (C) 2006 the VideoLAN team
+ * Copyright (C) 2006-2007 the VideoLAN team
  * $Id: streaminfo.cpp 16816 2006-09-23 20:56:52Z jb $
  *
  * Authors: Jean-Baptiste Kempf <jb@videolan.org>
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
+#include "qt4.hpp"
+#include "util/qvlcframe.hpp"
+#include "input_manager.hpp"
+
+#include "dialogs/open.hpp"
+#include "components/open.hpp"
+
 #include <QTabWidget>
 #include <QGridLayout>
 #include <QFileDialog>
 #include <QRegExp>
 #include <QMenu>
-#include "dialogs/open.hpp"
-#include "components/open.hpp"
-
-#include "qt4.hpp"
-#include "util/qvlcframe.hpp"
-
-#include "input_manager.hpp"
-#include "dialogs_provider.hpp"
 
 OpenDialog *OpenDialog::instance = NULL;
 
-OpenDialog::OpenDialog( QWidget *parent, intf_thread_t *_p_intf, bool modal ) :
-                                                QVLCDialog( parent, _p_intf )
+OpenDialog::OpenDialog( QWidget *parent, intf_thread_t *_p_intf, bool modal,
+                        int _action_flag )  :  QVLCDialog( parent, _p_intf )
 {
     setModal( modal );
+    i_action_flag = _action_flag;
+
+    /* Basic Creation of the Window */
     ui.setupUi( this );
     setWindowTitle( qtr("Open" ) );
-    resize( 500, 300);
+    resize( 410, 300);
 
-    fileOpenPanel = new FileOpenPanel( ui.Tab , p_intf );
-    diskOpenPanel = new DiskOpenPanel( ui.Tab , p_intf );
-    netOpenPanel = new NetOpenPanel( ui.Tab , p_intf );
+    /* Tab definition and creation */
+    fileOpenPanel = new FileOpenPanel( ui.Tab, p_intf );
+    discOpenPanel = new DiscOpenPanel( ui.Tab, p_intf );
+    netOpenPanel = new NetOpenPanel( ui.Tab, p_intf );
     captureOpenPanel = new CaptureOpenPanel( ui.Tab, 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 &Device" ) );
+    /* Insert the tabs */
+    ui.Tab->insertTab( OPEN_FILE_TAB, fileOpenPanel, qtr( "&File" ) );
+    ui.Tab->insertTab( OPEN_DISC_TAB, discOpenPanel, qtr( "&Disc" ) );
+    ui.Tab->insertTab( OPEN_NETWORK_TAB, netOpenPanel, qtr( "&Network" ) );
+    ui.Tab->insertTab( OPEN_CAPTURE_TAB, captureOpenPanel,
+                                qtr( "Capture &Device" ) );
 
-    ui.advancedFrame->hide();
+    /* Hide the advancedPanel */
+    if(! config_GetInt( p_intf, "qt-adv-options") )
+    {
+        ui.advancedFrame->hide();
+    }
+    else
+    {
+        ui.advancedCheckBox->setCheckState( Qt::Checked );
+    }
+
+    ui.slaveLabel->hide();
+    ui.slaveText->hide();
+    ui.slaveBrowseButton->hide();
+
+    /* Buttons Creation */
+    QSizePolicy buttonSizePolicy( static_cast<QSizePolicy::Policy>(7),
+                                  static_cast<QSizePolicy::Policy>(1) );
+    buttonSizePolicy.setHorizontalStretch(0);
+    buttonSizePolicy.setVerticalStretch(0);
+
+    playButton = new QToolButton( this );
+    playButton->setText( qtr( "&Play" ) );
+    playButton->setSizePolicy( buttonSizePolicy );
+    playButton->setMinimumSize( QSize(90, 0) );
+    playButton->setPopupMode( QToolButton::MenuButtonPopup );
+    playButton->setToolButtonStyle( Qt::ToolButtonTextOnly );
+
+    cancelButton = new QPushButton();
+    cancelButton->setText( qtr( "&Cancel" ) );
+    cancelButton->setSizePolicy( buttonSizePolicy );
 
     QMenu * openButtonMenu = new QMenu( "Open" );
     openButtonMenu->addAction( qtr("&Enqueue"), this, SLOT( enqueue() ),
-                                QKeySequence( "Alt+E") );
+                                    QKeySequence( "Alt+E") );
+    openButtonMenu->addAction( qtr("&Play"), this, SLOT( play() ),
+                                    QKeySequence( "Alt+P" ) );
     openButtonMenu->addAction( qtr("&Stream"), this, SLOT( stream() ) ,
-                                QKeySequence( "Alt+T" ) );
+                                    QKeySequence( "Alt+S" ) );
+    openButtonMenu->addAction( qtr("&Convert"), this, SLOT( transcode( ) ) ,
+                                    QKeySequence( "Alt+C" ) );
+
+    playButton->setMenu( openButtonMenu );
+
+    ui.buttonsBox->addButton( playButton, QDialogButtonBox::AcceptRole );
+    ui.buttonsBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
 
-    ui.playButton->setMenu( openButtonMenu );
     /* 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( discOpenPanel, mrlUpdated( QString ), this, updateMRL(QString) );
     CONNECT( captureOpenPanel, mrlUpdated( QString ), this,
-            updateMRL(QString) );
-
+                                                         updateMRL(QString) );
 
     CONNECT( fileOpenPanel, methodChanged( QString ),
-             this, newMethod(QString) );
+                                                 this, newMethod(QString) );
     CONNECT( netOpenPanel, methodChanged( QString ),
-             this, newMethod(QString) );
-    CONNECT( diskOpenPanel, methodChanged( QString ),
-             this, newMethod(QString) );
+                                                 this, newMethod(QString) );
+    CONNECT( discOpenPanel, methodChanged( QString ),
+                                                 this, newMethod(QString) );
+    CONNECT( captureOpenPanel, methodChanged( QString ),
+                                                 this, newMethod(QString) );
 
+    /* Advanced frame Connects */
     CONNECT( ui.slaveText, textChanged(QString), this, updateMRL());
     CONNECT( ui.cacheSpinBox, valueChanged(int), this, updateMRL());
-
-    BUTTONACT( ui.playButton, play());
-    BUTTONACT( ui.cancelButton, cancel());
+    CONNECT( ui.startTimeSpinBox, valueChanged(int), this, updateMRL());
     BUTTONACT( ui.advancedCheckBox , toggleAdvancedPanel() );
 
+    /* Buttons action */
+    BUTTONACT( playButton, play());
+    BUTTONACT( cancelButton, cancel());
+
+    /* At creation time, modify the default buttons */
+    if ( i_action_flag ) setMenuAction();
+
+
     /* Initialize caching */
     storedMethod = "";
     newMethod("file-caching");
@@ -99,6 +149,30 @@ OpenDialog::~OpenDialog()
 {
 }
 
+/* Finish the dialog and decide if you open another one after */
+void OpenDialog::setMenuAction()
+{
+    switch ( i_action_flag )
+    {
+        case OPEN_AND_STREAM:
+            playButton->setText( qtr("&Stream") );
+            BUTTONACT( playButton, stream() );
+            break;
+        case OPEN_AND_SAVE:
+            playButton->setText( qtr("&Convert / Save") );
+            BUTTONACT( playButton, stream( true ) );
+            break;
+        case ENQUEUE:
+            playButton->setText( qtr("&Enqueue") );
+            BUTTONACT( playButton, enqueue() );
+            break;
+        case OPEN_AND_PLAY:
+        default:
+            playButton->setText( qtr("&Play") );
+            BUTTONACT( playButton, play() );
+   }
+}
+
 void OpenDialog::showTab(int i_tab=0)
 {
     this->show();
@@ -111,6 +185,11 @@ void OpenDialog::signalCurrent() {
     }
 }
 
+/***********
+ * Actions *
+ ***********/
+
+/* If Cancel is pressed or escaped */
 void OpenDialog::cancel()
 {
     fileOpenPanel->clear();
@@ -119,21 +198,44 @@ void OpenDialog::cancel()
         reject();
 }
 
-void OpenDialog::close() 
+/* If EnterKey is pressed */
+void OpenDialog::close()
 {
-    play();
+    /* FIXME */
+    if ( !i_action_flag )
+    {
+        play();
+    }
+    else
+    {
+        stream();
+    }
 }
+
+/* Play button */
 void OpenDialog::play()
 {
-    playOrEnqueue( false );
+    finish( false );
 }
 
 void OpenDialog::enqueue()
 {
-    playOrEnqueue( true );
+    finish( true );
 }
 
-void OpenDialog::playOrEnqueue( bool b_enqueue = false )
+void OpenDialog::transcode()
+{
+    stream( true );
+}
+
+void OpenDialog::stream( bool b_transcode_only )
+{
+    /* not finished FIXME */
+    /* Should go through the finish function */
+    THEDP->streamingDialog( mrl, b_transcode_only );
+}
+
+void OpenDialog::finish( bool b_enqueue = false )
 {
     this->toggleVisible();
     mrl = ui.advancedLineInput->text();
@@ -175,28 +277,28 @@ void OpenDialog::playOrEnqueue( bool b_enqueue = false )
         accept();
 }
 
-void OpenDialog::stream()
-{
-//TODO. Policy not yet defined
-}
-
 void OpenDialog::toggleAdvancedPanel()
 {
     //FIXME does not work under Windows
     if (ui.advancedFrame->isVisible()) {
         ui.advancedFrame->hide();
+#ifndef WIN32
         setMinimumHeight(1);
         resize( width(), mainHeight );
-
+#endif
     } else {
+#ifndef WIN32
         if( mainHeight == 0 )
             mainHeight = height();
+#endif
 
         ui.advancedFrame->show();
+#ifndef WIN32
         if( advHeight == 0 ) {
             advHeight = height() - mainHeight;
         }
         resize( width(), mainHeight + advHeight );
+#endif
     }
 }
 
@@ -210,6 +312,10 @@ void OpenDialog::updateMRL() {
         mrl += QString(" :%1=%2").arg(storedMethod).
                                   arg(ui.cacheSpinBox->value());
     }
+    if( ui.startTimeSpinBox->value()) {
+        mrl += " :start-time=" + QString("%1").
+            arg(ui.startTimeSpinBox->value());
+    }
     ui.advancedLineInput->setText(mrl);
 }