]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/open.cpp
Qt4 - Make Open dialog KDE/GNOME/WIN32 compliant for buttons...
[vlc] / modules / gui / qt4 / dialogs / open.cpp
index e9a532a14254194a6f9e8d48ff6146bb1bfb454d..b1881cc8c71c4a3089b7b9c7c509fb06d0d0a4d7 100644 (file)
@@ -1,6 +1,6 @@
 /*****************************************************************************
  * open.cpp : Advanced open dialog
- ****************************************************************************
+ *****************************************************************************
  * Copyright (C) 2006 the VideoLAN team
  * $Id: streaminfo.cpp 16816 2006-09-23 20:56:52Z jb $
  *
  *
  * 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. *****************************************************************************/
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
 
 #include <QTabWidget>
 #include <QGridLayout>
 #include <QFileDialog>
-
+#include <QRegExp>
+#include <QMenu>
 #include "dialogs/open.hpp"
 #include "components/open.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,
+                        bool _stream_after ) :  QVLCDialog( parent, _p_intf )
 {
-    setWindowTitle( qtr("Open" ) );
     setModal( modal );
+    b_stream_after = _stream_after;
+
     ui.setupUi( this );
-    fileOpenPanel = new FileOpenPanel(this , p_intf );
-    diskOpenPanel = new DiskOpenPanel(this , p_intf );
-    netOpenPanel = new NetOpenPanel(this , p_intf );
-    ui.Tab->addTab(fileOpenPanel, qtr("File"));
-    ui.Tab->addTab(diskOpenPanel, qtr("Disk"));
-    ui.Tab->addTab(netOpenPanel, qtr("Network"));
+    setWindowTitle( qtr("Open" ) );
+    resize( 500, 300);
 
+    /* Tab definition and creation */
+    fileOpenPanel = new FileOpenPanel( ui.Tab , p_intf );
+    diskOpenPanel = new DiskOpenPanel( 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" ) );
+
+    /* Hide the advancedPanel */
     ui.advancedFrame->hide();
 
+    /* Buttons Creation */
+    QSizePolicy buttonSizePolicy(static_cast<QSizePolicy::Policy>(7), static_cast<QSizePolicy::Policy>(1));
+    buttonSizePolicy.setHorizontalStretch(0);
+    buttonSizePolicy.setVerticalStretch(0);
+
+    playButton = new QToolButton();
+    playButton->setText( qtr( "&Play" ) );
+    playButton->setSizePolicy( buttonSizePolicy );
+    playButton->setMinimumSize(QSize(90, 0));
+    playButton->setPopupMode(QToolButton::MenuButtonPopup);
+    playButton->setToolButtonStyle(Qt::ToolButtonTextOnly);
+
+    cancelButton = new QToolButton();
+    cancelButton->setText( qtr( "&Cancel" ) );
+    cancelButton->setSizePolicy( buttonSizePolicy );
+
+    QMenu * openButtonMenu = new QMenu( "Open" );
+    openButtonMenu->addAction( qtr("&Enqueue"), this, SLOT( enqueue() ),
+                                    QKeySequence( "Alt+E") );
+    openButtonMenu->addAction( qtr("&Play"), this, SLOT( play() ),
+                                    QKeySequence( "Alt+P" ) );
+    openButtonMenu->addAction( qtr("&Stream"), this, SLOT( stream() ) ,
+                                    QKeySequence( "Alt+S" ) );
+
+    playButton->setMenu( openButtonMenu );
+
+    ui.buttonsBox->addButton( playButton, QDialogButtonBox::AcceptRole );
+    ui.buttonsBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
+
+
     /* 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) );
@@ -67,8 +110,12 @@ OpenDialog::OpenDialog( QWidget *parent, intf_thread_t *_p_intf, bool modal ) :
     CONNECT( ui.slaveText, textChanged(QString), this, updateMRL());
     CONNECT( ui.cacheSpinBox, valueChanged(int), this, updateMRL());
 
-    BUTTONACT( ui.closeButton, ok());
-    BUTTONACT( ui.cancelButton, cancel());
+    /* Buttons action */
+    BUTTONACT( playButton, play());
+    BUTTONACT( cancelButton, cancel());
+
+    if ( b_stream_after ) setAfter();
+
     BUTTONACT( ui.advancedCheckBox , toggleAdvancedPanel() );
 
     /* Initialize caching */
@@ -82,6 +129,20 @@ OpenDialog::~OpenDialog()
 {
 }
 
+void OpenDialog::setAfter()
+{
+    if (!b_stream_after )
+    {
+        playButton->setText( qtr("&Play") );
+        BUTTONACT( playButton, play() );
+    }
+    else
+    {
+        playButton->setText( qtr("&Stream") );
+        BUTTONACT( playButton, stream() );
+    }
+}
+
 void OpenDialog::showTab(int i_tab=0)
 {
     this->show();
@@ -94,6 +155,11 @@ void OpenDialog::signalCurrent() {
     }
 }
 
+/*********** 
+ * Actions *
+ ***********/
+
+/* If Cancel is pressed or escaped */
 void OpenDialog::cancel()
 {
     fileOpenPanel->clear();
@@ -102,23 +168,74 @@ void OpenDialog::cancel()
         reject();
 }
 
-void OpenDialog::ok()
+/* If EnterKey is pressed */
+void OpenDialog::close()
+{
+    if ( !b_stream_after )
+    {
+        play();
+    }
+    else
+    {
+        stream();
+    }
+}
+
+/* Play button */
+void OpenDialog::play()
+{
+    playOrEnqueue( false );
+}
+
+void OpenDialog::enqueue()
+{
+    playOrEnqueue( true );
+}
+
+void OpenDialog::stream()
+{
+    /* not finished FIXME */
+    THEDP->streamingDialog( mrl );
+}
+
+
+void OpenDialog::playOrEnqueue( bool b_enqueue = false )
 {
     this->toggleVisible();
     mrl = ui.advancedLineInput->text();
-    QStringList tempMRL = mrl.split(" ");
+
     if( !isModal() )
     {
-        for( size_t i = 0 ; i< tempMRL.size(); i++ )
+        QStringList tempMRL = SeparateEntries( mrl );
+        for( size_t i = 0; i < tempMRL.size(); i++ )
         {
-             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 );
-         }
+            bool b_start = !i && !b_enqueue;
+            input_item_t *p_input;
+            const char *psz_utf8 = qtu( tempMRL[i] );
+
+            p_input = input_ItemNew( p_intf, psz_utf8, NULL );
 
+            /* Insert options */
+            while( i + 1 < tempMRL.size() && tempMRL[i + 1].startsWith( ":" ) )
+            {
+                i++;
+                psz_utf8 = qtu( tempMRL[i] );
+                input_ItemAddOption( p_input, psz_utf8 );
+            }
+
+            if( b_start )
+            {
+                playlist_AddInput( THEPL, p_input,
+                                   PLAYLIST_APPEND | PLAYLIST_GO,
+                                   PLAYLIST_END, VLC_TRUE, VLC_FALSE );
+            }
+            else
+            {
+                playlist_AddInput( THEPL, p_input,
+                                   PLAYLIST_APPEND|PLAYLIST_PREPARSE,
+                                   PLAYLIST_END, VLC_TRUE, VLC_FALSE );
+            }
+        }
     }
     else
         accept();
@@ -126,6 +243,7 @@ void OpenDialog::ok()
 
 void OpenDialog::toggleAdvancedPanel()
 {
+    //FIXME does not work under Windows
     if (ui.advancedFrame->isVisible()) {
         ui.advancedFrame->hide();
         setMinimumHeight(1);
@@ -170,3 +288,51 @@ void OpenDialog::newMethod(QString method)
         ui.cacheSpinBox->setValue(i_value);
     }
 }
+
+QStringList OpenDialog::SeparateEntries( QString entries )
+{
+    bool b_quotes_mode = false;
+
+    QStringList entries_array;
+    QString entry;
+
+    int index = 0;
+    while( index < entries.size() )
+    {
+        int delim_pos = entries.indexOf( QRegExp( "\\s+|\"" ), index );
+        if( delim_pos < 0 ) delim_pos = entries.size() - 1;
+        entry += entries.mid( index, delim_pos - index + 1 );
+        index = delim_pos + 1;
+
+        if( entry.isEmpty() ) continue;
+
+        if( !b_quotes_mode && entry.endsWith( "\"" ) )
+        {
+            /* Enters quotes mode */
+            entry.truncate( entry.size() - 1 );
+            b_quotes_mode = true;
+        }
+        else if( b_quotes_mode && entry.endsWith( "\"" ) )
+        {
+            /* Finished the quotes mode */
+            entry.truncate( entry.size() - 1 );
+            b_quotes_mode = false;
+        }
+        else if( !b_quotes_mode && !entry.endsWith( "\"" ) )
+        {
+            /* we found a non-quoted standalone string */
+            if( index < entries.size() ||
+                entry.endsWith( " " ) || entry.endsWith( "\t" ) ||
+                entry.endsWith( "\r" ) || entry.endsWith( "\n" ) )
+                entry.truncate( entry.size() - 1 );
+            if( !entry.isEmpty() ) entries_array.append( entry );
+            entry.clear();
+        }
+        else
+        {;}
+    }
+
+    if( !entry.isEmpty() ) entries_array.append( entry );
+
+    return entries_array;
+}