]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/preferences.cpp
Destroy preferences dialog on close and on reset.
[vlc] / modules / gui / qt4 / dialogs / preferences.cpp
index 9f92b8dfcab54d3697092bb5cc19d52d32915768..a841f700433f33fff47544e34d9a6cfa06b682f7 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "dialogs/preferences.hpp"
 #include "dialogs_provider.hpp"
 #include "util/qvlcframe.hpp"
 #include <QVBoxLayout>
 #include <QPushButton>
 #include <QCheckBox>
-#include <QScrollArea>
 #include <QMessageBox>
 #include <QDialogButtonBox>
 
 PrefsDialog *PrefsDialog::instance = NULL;
 
-PrefsDialog::PrefsDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
+PrefsDialog::PrefsDialog( QWidget *parent, intf_thread_t *_p_intf )
+            : QVLCDialog( parent, _p_intf )
 {
     QGridLayout *main_layout = new QGridLayout( this );
     setWindowTitle( qtr( "Preferences" ) );
-    resize( 750, 550 );
+
+    /* Whether we want it or not, we need to destroy on close to get
+       consistency when reset */
+    setAttribute( Qt::WA_DeleteOnClose );
 
     /* Create Panels */
     tree_panel = new QWidget;
@@ -60,7 +67,7 @@ PrefsDialog::PrefsDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
     types->setAlignment( Qt::AlignHCenter );
     QHBoxLayout *types_l = new QHBoxLayout;
     types_l->setSpacing( 3 ); types_l->setMargin( 3 );
-    small = new QRadioButton( qtr("Basic"), types );
+    small = new QRadioButton( qtr( "Simple" ), types );
     types_l->addWidget( small );
     all = new QRadioButton( qtr("All"), types ); types_l->addWidget( all );
     types->setLayout( types_l );
@@ -80,29 +87,32 @@ PrefsDialog::PrefsDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
 
     buttonsBox->addButton( save, QDialogButtonBox::AcceptRole );
     buttonsBox->addButton( cancel, QDialogButtonBox::RejectRole );
-    buttonsBox->addButton( reset, QDialogButtonBox::ActionRole );
+    buttonsBox->addButton( reset, QDialogButtonBox::ResetRole );
 
     /* Layout  */
     main_layout->addWidget( tree_panel, 0, 0, 3, 1 );
     main_layout->addWidget( types, 3, 0, 2, 1 );
-    main_layout->addWidget( main_panel, 0, 1, 4, 1 );
-    main_layout->addWidget( buttonsBox, 4, 1, 1 ,2 );
+    main_layout->addWidget( main_panel, 0, 1, 4, 2 );
+    main_layout->addWidget( buttonsBox, 4, 2, 1 ,1 );
 
     main_layout->setColumnMinimumWidth( 0, 150 );
+    main_layout->setColumnMinimumWidth( 1, 10 );
     main_layout->setColumnStretch( 0, 1 );
-    main_layout->setColumnStretch( 1, 3 );
+    main_layout->setColumnStretch( 1, 0 );
+    main_layout->setColumnStretch( 2, 3 );
 
-    main_layout->setRowStretch( 2, 4);
+    main_layout->setRowStretch( 2, 4 );
 
+    main_layout->setMargin( 9 );
     setLayout( main_layout );
 
     /* Margins */
     tree_panel_l->setMargin( 1 );
-    main_panel_l->setMargin( 3 );
+    main_panel_l->setLayoutMargins( 6, 0, 0, 3, 3 );
 
     for( int i = 0; i < SPrefsMax ; i++ ) simple_panels[i] = NULL;
 
-    if( config_GetInt( p_intf, "qt-advanced-pref") == 1 )
+    if( config_GetInt( p_intf, "qt-advanced-pref" ) == 1 )
         setAdvanced();
     else
         setSmall();
@@ -113,6 +123,8 @@ PrefsDialog::PrefsDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
 
     BUTTONACT( small, setSmall() );
     BUTTONACT( all, setAdvanced() );
+
+    resize( 750, sizeHint().height() );
 }
 
 void PrefsDialog::setAdvanced()
@@ -128,7 +140,7 @@ void PrefsDialog::setAdvanced()
          advanced_tree = new PrefsTree( p_intf, tree_panel );
         /* and connections */
          CONNECT( advanced_tree,
-                  currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem *),
+                  currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem * ),
                   this, changeAdvPanel( QTreeWidgetItem * ) );
         tree_panel_l->addWidget( advanced_tree );
     }
@@ -137,7 +149,7 @@ void PrefsDialog::setAdvanced()
     advanced_tree->show();
 
     /* Remove the simple current panel from the main panels*/
-    if( current_simple_panel  )
+    if( current_simple_panel )
         if( current_simple_panel->isVisible() ) current_simple_panel->hide();
 
     /* If no advanced Panel exist, create one, attach it and show it*/
@@ -148,6 +160,11 @@ void PrefsDialog::setAdvanced()
     }
     advanced_panel->show();
 
+    /* Select the first Item of the preferences. Maybe you want to select a specified
+       category... */
+    advanced_tree->setCurrentIndex(
+            advanced_tree->model()->index( 0, 0, QModelIndex() ) );
+
     all->setChecked( true );
 }
 
@@ -174,11 +191,12 @@ void PrefsDialog::setSmall()
     if( advanced_panel )
         if( advanced_panel->isVisible() ) advanced_panel->hide();
 
-    if( !current_simple_panel  )
+    if( !current_simple_panel )
     {
-        current_simple_panel  = new SPrefsPanel( p_intf, main_panel, SPrefsDefaultCat );
+        current_simple_panel =
+            new SPrefsPanel( p_intf, main_panel, SPrefsDefaultCat );
         simple_panels[SPrefsDefaultCat] =  current_simple_panel;
-        main_panel_l->addWidget( current_simple_panel  );
+        main_panel_l->addWidget( current_simple_panel );
     }
 
     current_simple_panel->show();
@@ -188,15 +206,15 @@ void PrefsDialog::setSmall()
 /* Switching from on simple panel to another */
 void PrefsDialog::changeSimplePanel( int number )
 {
-    if( current_simple_panel  )
+    if( current_simple_panel )
         if( current_simple_panel->isVisible() ) current_simple_panel->hide();
 
     current_simple_panel = simple_panels[number];
-    if( !current_simple_panel  )
+    if( !current_simple_panel )
     {
         current_simple_panel  = new SPrefsPanel( p_intf, main_panel, number );
         simple_panels[number] = current_simple_panel;
-        main_panel_l->addWidget( current_simple_panel  );
+        main_panel_l->addWidget( current_simple_panel );
     }
 
     current_simple_panel->show();
@@ -211,10 +229,12 @@ void PrefsDialog::changeAdvPanel( QTreeWidgetItem *item )
         if( advanced_panel->isVisible() ) advanced_panel->hide();
 
     if( !data->panel )
+    {
         data->panel = new AdvPrefsPanel( p_intf, main_panel , data );
+        main_panel_l->addWidget( data->panel );
+    }
 
     advanced_panel = data->panel;
-    main_panel_l->addWidget( advanced_panel );
     advanced_panel->show();
 }
 
@@ -271,27 +291,41 @@ void PrefsDialog::save()
     /* Save to file */
     config_SaveConfigFile( p_intf, NULL );
 
+    destroyPanels();
+
+    hide();
+}
+
+void PrefsDialog::destroyPanels()
+{
+    msg_Dbg( p_intf, "Destroying the Panels" );
     /* Delete the other panel in order to force its reload after clicking
        on apply. In fact, if we don't do that, the preferences from the other
        panels won't be accurate, so we would have to recreate the whole dialog,
        and we don't want that.*/
     if( small->isChecked() && advanced_panel )
     {
-        delete advanced_panel;
+        /* Deleting only the active panel from the advanced config doesn't work
+           because the data records of PrefsItemData  contains still a
+           reference to it only cleanAll() is sure to remove all Panels! */
+        advanced_tree->cleanAll();
         advanced_panel = NULL;
     }
-    if( all->isChecked() && current_simple_panel  )
+    if( all->isChecked() && current_simple_panel )
     {
         for( int i = 0 ; i< SPrefsMax; i++ )
         {
-            if( simple_panels[i] ) delete simple_panels[i];
+            if( simple_panels[i] )
+            {
+               delete simple_panels[i];
+               simple_panels[i] = NULL;
+            }
         }
         current_simple_panel  = NULL;
     }
-
-    hide();
 }
 
+
 /* Clean the preferences, dunno if it does something really */
 void PrefsDialog::cancel()
 {
@@ -311,14 +345,20 @@ void PrefsDialog::cancel()
 /* Reset all the preferences, when you click the button */
 void PrefsDialog::reset()
 {
-    int ret = QMessageBox::question(this, qtr("Reset Preferences"),
-                 qtr("This will reset your VLC media player preferences.\n"
-                         "Are you sure you want to continue?"),
-                  QMessageBox::Ok | QMessageBox::Cancel,
-                                                         QMessageBox::Ok);
-    if ( ret == QMessageBox::Ok )
+    int ret = QMessageBox::question(
+                 this,
+                 qtr( "Reset Preferences" ),
+                 qtr( "This will reset your VLC media player preferences.\n"
+                      "Are you sure you want to continue?" ),
+                 QMessageBox::Ok | QMessageBox::Cancel,
+                 QMessageBox::Ok);
+
+    if( ret == QMessageBox::Ok )
     {
         config_ResetAll( p_intf );
         config_SaveConfigFile( p_intf, NULL );
+
+        instance = NULL;
+        close();
     }
 }