]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/open.cpp
Qt4 - Rename dialog/prefs_dialog to dialog/preferences: files in dialog/ are already...
[vlc] / modules / gui / qt4 / components / open.cpp
index 1329ff8d3eb256b4e9ff60fe207fcd792911d86d..a3fd97fea8f5a6c7ba8aab515844c11b5444618a 100644 (file)
 
 #include "qt4.hpp"
 #include "components/open.hpp"
+#include "dialogs/open.hpp"
+#include "dialogs_provider.hpp"
+#include "util/customwidgets.hpp"
 
 #include <QFileDialog>
+#include <QDialogButtonBox>
+#include <QLineEdit>
 
 /**************************************************************************
  * File open
 FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
                                 OpenPanel( _parent, _p_intf )
 {
+    /* Classic UI Setup */
     ui.setupUi( this );
 
+    /* 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. */
+
+    /* 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(" *"));
+
+    // Make this QFileDialog a child of tempWidget from the ui.
+    dialogBox = new FileOpenBox( ui.tempWidget, NULL,
+            qfu( p_intf->p_libvlc->psz_homedir ), fileTypes );
+    dialogBox->setFileMode( QFileDialog::ExistingFiles );
+    dialogBox->setAcceptMode( QFileDialog::AcceptOpen );
+
+    /* 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" ));
+
+    // Add it to the layout
+    ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
+
+    // But hide the two OK/Cancel buttons. Enable them for debug.
+#ifndef WIN32
+    findChild<QDialogButtonBox*>()->hide();
+#endif
+
+    /* 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:" ) );
+
+    // Hide the subtitles control by default.
+    ui.subFrame->hide();
+
+    /* 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 );
+            }
+        }
+    }
+
+    /* 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 );
+            }
+        }
+    }
 
-    BUTTONACT( ui.fileBrowseButton, browseFile() );
     BUTTONACT( ui.subBrowseButton, browseFileSub() );
+    BUTTONACT( ui.subCheckBox, toggleSubtitleFrame());
 
-    BUTTONACT( ui.subGroupBox, 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()
@@ -52,31 +137,27 @@ FileOpenPanel::~FileOpenPanel()
 
 QStringList FileOpenPanel::browse(QString help)
 {
-    return QFileDialog::getOpenFileNames( this, help, "", "" );
+    return THEDP->showSimpleOpen( help );
 }
 
 void FileOpenPanel::browseFile()
 {
     QString fileString = "";
-    QStringList files = browse( qtr("Open File") );
-    foreach( QString file, files) {
-        if( file.contains(" ") ) {
-            fileString += "\"" + file + "\"";
-        } else {
-            fileString += file;
-        }
+    foreach( QString file, dialogBox->selectedFiles() ) {
+         fileString += "\"" + file + "\" ";
     }
-
     ui.fileInput->setEditText( fileString );
-    ui.fileInput->addItem( fileString );
-    if ( ui.fileInput->count() > 8 ) ui.fileInput->removeItem(0);
-
     updateMRL();
 }
 
 void FileOpenPanel::browseFileSub()
 {
-    ui.subInput->setEditText( browse( qtr("Open subtitles file") ).join(" ") );
+    // FIXME Handle selection of more than one subtitles file
+    QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"),
+                            EXT_FILTER_SUBTITLE,
+                            dialogBox->directory().absolutePath() );
+    if( files.isEmpty() ) return;
+    ui.subInput->setEditText( files.join(" ") );
     updateMRL();
 }
 
@@ -84,21 +165,53 @@ void FileOpenPanel::updateMRL()
 {
     QString mrl = ui.fileInput->currentText();
 
-    if( ui.subGroupBox->isChecked() ) {
+    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() );
+        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();
+        mrl.append( " :freetype-rel-fontsize=" + QString().setNum( size ) );
     }
-    emit mrlUpdated(mrl);
+    emit mrlUpdated( mrl );
     emit methodChanged( "file-caching" );
 }
 
+
+/* 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);
+}
+
+void FileOpenBox::accept()
+{
+    OpenDialog::getInstance( NULL, NULL )->play();
+}
+
+/* Function called by Open Dialog when clicked on cancel */
 void FileOpenPanel::clear()
 {
-    ui.fileInput->setEditText( "");
-    ui.subInput->setEditText( "");
+    ui.fileInput->setEditText( "" );
+    ui.subInput->setEditText( "" );
 }
 
+void FileOpenPanel::toggleSubtitleFrame()
+{
+    if (ui.subFrame->isVisible())
+    {
+        ui.subFrame->hide();
+//        setMinimumHeight(1);
+        resize( sizeHint());
+    }
+    else
+    {
+        ui.subFrame->show();
+    }
+
+    /* Update the MRL */
+    updateMRL();
+}
 
 /**************************************************************************
  * Disk open
@@ -260,3 +373,24 @@ void NetOpenPanel::updateMRL() {
     }
     emit mrlUpdated(mrl);
 }
+
+/**************************************************************************
+ * Capture open
+ **************************************************************************/
+CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
+                                OpenPanel( _parent, _p_intf )
+{
+    ui.setupUi( this );
+}
+
+CaptureOpenPanel::~CaptureOpenPanel()
+{}
+
+void CaptureOpenPanel::clear()
+{}
+
+void CaptureOpenPanel::updateMRL()
+{
+    QString mrl = "";
+    emit mrlUpdated(mrl);
+}