]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/preferences_widgets.cpp
* open file widget: do nothing if the user clicked on cancel
[vlc] / modules / gui / qt4 / components / preferences_widgets.cpp
index 80e9c33cb2f8056bf76780b045c941b9d60f9255..7531c77fe5864a9675ea22fd6d1e5005c4d0b7ca 100644 (file)
@@ -1,11 +1,12 @@
 /*****************************************************************************
  * preferences_widgets.cpp : Widgets for preferences displays
  ****************************************************************************
- * Copyright (C) 2006 the VideoLAN team
+ * Copyright (C) 2006-2007 the VideoLAN team
  * $Id$
  *
  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
  *          Antoine Cellerier <dionoea@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
@@ -44,6 +45,7 @@
 #include <QGridLayout>
 #include <QPushButton>
 #include <QSlider>
+#include <QFileDialog>
 
 #include <vlc_keys.h>
 
@@ -101,10 +103,12 @@ ConfigControl *ConfigControl::createControl( vlc_object_t *p_this,
                                                   l, line );
         break;
     case CONFIG_ITEM_FILE:
-        fprintf( stderr, "Todo (CONFIG_ITEM_FILE)\n" );
+        p_control = new FileConfigControl( p_this, p_item, parent, l,
+                                                line, false );
         break;
     case CONFIG_ITEM_DIRECTORY:
-        fprintf( stderr, "Todo (CONFIG_ITEM_DIRECTORY)\n" );
+        p_control = new DirectoryConfigControl( p_this, p_item, parent, l,
+                                                line, false );
         break;
     case CONFIG_ITEM_KEY:
         p_control = new KeySelectorControl( p_this, p_item, parent, l, line );
@@ -207,6 +211,89 @@ void StringConfigControl::finish()
         label->setToolTip( qfu(p_item->psz_longtext) );
 }
 
+/*********** File **************/
+FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
+                                          module_config_t *_p_item,
+                                          QWidget *_parent, QGridLayout *l,
+                                          int &line, bool pwd ) :
+                           VStringConfigControl( _p_this, _p_item, _parent )
+{
+    label = new QLabel( qfu(p_item->psz_text) );
+    text = new QLineEdit( qfu(p_item->value.psz) );
+    browse = new QPushButton( qtr( "Browse" ) );
+
+    BUTTONACT( browse, updateField() );
+
+    finish();
+
+    if( !l )
+    {
+        QHBoxLayout *layout = new QHBoxLayout();
+        layout->addWidget( label, 0 ); layout->addWidget( text, 1 );
+        layout->addWidget( browse, 2 );
+        widget->setLayout( layout );
+    }
+    else
+    {
+        l->addWidget( label, line, 0 ); l->addWidget( text, line, 1 );
+        l->addWidget( browse, line, 2 );
+    }
+}
+
+
+FileConfigControl::FileConfigControl( vlc_object_t *_p_this,
+                                   module_config_t *_p_item,
+                                   QLabel *_label, QLineEdit *_text,
+                                   QPushButton *_button, bool pwd ):
+                           VStringConfigControl( _p_this, _p_item )
+{
+    browse = _button;
+    text = _text;
+    label = _label;
+
+    BUTTONACT( browse, updateField() );
+
+    finish( );
+}
+
+void FileConfigControl::updateField()
+{
+    QString file = QFileDialog::getOpenFileName( NULL,
+                  qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ) );
+    if( file.isNull() ) return;
+    text->setText( file );
+}
+
+void FileConfigControl::finish()
+{
+    text->setText( qfu(p_item->value.psz) );
+    text->setToolTip( qfu(p_item->psz_longtext) );
+    if( label )
+        label->setToolTip( qfu(p_item->psz_longtext) );
+}
+
+/********* String / Directory **********/
+
+DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
+                        module_config_t *_p_item, QWidget *_p_widget,
+                        QGridLayout *_p_layout, int& _int, bool _pwd ) :
+     FileConfigControl( _p_this, _p_item, _p_widget, _p_layout, _int, _pwd)
+{}
+
+DirectoryConfigControl::DirectoryConfigControl( vlc_object_t *_p_this,
+                        module_config_t *_p_item, QLabel *_p_label,
+                        QLineEdit *_p_line, QPushButton *_p_button, bool _pwd ):
+     FileConfigControl( _p_this, _p_item, _p_label, _p_line, _p_button, _pwd)
+{}
+
+
+void DirectoryConfigControl::updateField()
+{
+    text->setText( QFileDialog::getOpenFileName( NULL,
+                qtr( "Select File" ), qfu( p_this->p_libvlc->psz_homedir ),
+                NULL, 0,  QFileDialog::ShowDirsOnly ) );
+}
+
 /********* String / choice list **********/
 StringListConfigControl::StringListConfigControl( vlc_object_t *_p_this,
                module_config_t *_p_item, QWidget *_parent, bool bycat,
@@ -551,8 +638,7 @@ void IntegerRangeConfigControl::finish()
 IntegerRangeSliderConfigControl::IntegerRangeSliderConfigControl(
                                             vlc_object_t *_p_this,
                                             module_config_t *_p_item,
-                                            QLabel *_label, QSlider *_slider,
-                                            bool *_bool          ) :
+                                            QLabel *_label, QSlider *_slider ):
                     VIntConfigControl( _p_this, _p_item )
 {
     slider = _slider;