]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/dialogs/prefs_dialog.cpp
Add video filters panel
[vlc] / modules / gui / qt4 / dialogs / prefs_dialog.cpp
index 59af6e2dbcdfc1aabd95c7cbb576aa39b7ac12b6..24a481001eaf3a4e62957ae9d9c5c9a8f4388eca 100644 (file)
 #include <QVBoxLayout>
 #include <QPushButton>
 #include <QCheckBox>
+
 PrefsDialog *PrefsDialog::instance = NULL;
 
 PrefsDialog::PrefsDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
 {
      QGridLayout *main_layout = new QGridLayout(this);
-     setWindowTitle( qtr("Preferences" ) );
+     setWindowTitle( qtr( "Preferences" ) );
      resize( 800, 450 );
 
      tree_panel = new QWidget(0);
@@ -58,8 +59,6 @@ PrefsDialog::PrefsDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
      types->setLayout(tl);
      small->setChecked( true );
 
-     adv_chk = new QCheckBox("Advanced options");
-
      advanced_tree = NULL;
      simple_tree = NULL;
      simple_panel = NULL;
@@ -67,8 +66,7 @@ PrefsDialog::PrefsDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
 
      main_layout->addWidget( types, 0,0,1,1 );
      main_layout->addWidget( tree_panel, 1,0,1,1 );
-     main_layout->addWidget( adv_chk , 2,0,1,1 );
-     main_layout->addWidget( main_panel, 0, 1, 3, 1 );
+     main_layout->addWidget( main_panel, 0, 1, 2, 1 );
 
      main_layout->setColumnMinimumWidth( 0, 200 );
      main_layout->setColumnStretch( 0, 1 );
@@ -76,18 +74,20 @@ PrefsDialog::PrefsDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
 
      setSmall();
 
-     connect( adv_chk, SIGNAL( toggled(bool) ),
-              this, SLOT( setAdvanced( bool ) ) );
+     QPushButton *save, *cancel;
+     QHBoxLayout *buttonsLayout = QVLCFrame::doButtons( this, NULL,
+                                                        &save, _("Save"),
+                                                        &cancel, _("Cancel"),
+                                                        NULL, NULL );
+     main_layout->addLayout( buttonsLayout, 2,0, 1 ,3 );
      setLayout( main_layout );
 
-     connect( small, SIGNAL( clicked() ), this, SLOT( setSmall()) );
-     connect( all, SIGNAL( clicked() ), this, SLOT( setAll()) );
-}
+     BUTTONACT( save, save() );
+     BUTTONACT( cancel, cancel() );
+     BUTTONACT( small, setSmall() );
+     BUTTONACT( all, setAll() );
 
-void PrefsDialog::setAdvanced( bool advanced )
-{
-    if( advanced_panel )
-        advanced_panel->setAdvanced( advanced );
+     for( int i = 0; i < SPrefsMax ; i++ ) simple_panels[i] = NULL;
 }
 
 void PrefsDialog::setAll()
@@ -101,9 +101,9 @@ void PrefsDialog::setAll()
     if( !advanced_tree )
     {
          advanced_tree = new PrefsTree( p_intf, tree_panel );
-         connect( advanced_tree,
-          SIGNAL( currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem *) ),
-          this, SLOT( changePanel( QTreeWidgetItem * ) ) );
+         CONNECT( advanced_tree,
+                  currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem *),
+                  this, changePanel( QTreeWidgetItem * ) );
     }
     tree_panel_l->addWidget( advanced_tree );
     advanced_tree->show();
@@ -117,7 +117,6 @@ void PrefsDialog::setAll()
          advanced_panel = new PrefsPanel( main_panel );
     main_panel_l->addWidget( advanced_panel );
     advanced_panel->show();
-    adv_chk->show();
 }
 
 void PrefsDialog::setSmall()
@@ -130,9 +129,9 @@ void PrefsDialog::setSmall()
     if( !simple_tree )
     {
          simple_tree = new SPrefsCatList( p_intf, tree_panel );
-         connect( simple_tree,
-          SIGNAL( currentItemChanged( QListWidgetItem *, QListWidgetItem *) ),
-          this, SLOT( changeSimplePanel( QListWidgetItem * ) ) );
+         CONNECT( simple_tree,
+                  currentItemChanged( QListWidgetItem *, QListWidgetItem *),
+                  this,  changeSimplePanel( QListWidgetItem * ) );
     }
     tree_panel_l->addWidget( simple_tree );
     simple_tree->show();
@@ -146,11 +145,6 @@ void PrefsDialog::setSmall()
         simple_panel = new SPrefsPanel( p_intf, main_panel, SPrefsDefaultCat );
     main_panel_l->addWidget( simple_panel );
     simple_panel->show();
-    adv_chk->hide();
-}
-
-PrefsDialog::~PrefsDialog()
-{
 }
 
 void PrefsDialog::changeSimplePanel( QListWidgetItem *item )
@@ -160,10 +154,10 @@ void PrefsDialog::changeSimplePanel( QListWidgetItem *item )
     {
         main_panel_l->removeWidget( simple_panel );
         simple_panel->hide();
-        /* Don't do this once it works, you would loose all changes */
-        delete simple_panel;
     }
-    simple_panel = new SPrefsPanel( p_intf, main_panel, number );
+    if( !simple_panels[number] )
+        simple_panel = new SPrefsPanel( p_intf, main_panel, number );
+    simple_panels[number] = simple_panel;
     main_panel_l->addWidget( simple_panel );
     simple_panel->show();
 }
@@ -178,12 +172,68 @@ void PrefsDialog::changePanel( QTreeWidgetItem *item )
         advanced_panel->hide();
     }
     if( !data->panel )
-    {
-        data->panel = new PrefsPanel( p_intf, main_panel , data,
-                                      adv_chk->isChecked() );
-    }
+        data->panel = new PrefsPanel( p_intf, main_panel , data );
+
     advanced_panel = data->panel;
     main_panel_l->addWidget( advanced_panel );
     advanced_panel->show();
-    setAdvanced( adv_chk->isChecked() );
+}
+
+void PrefsDialog::showModulePrefs( char *psz_module )
+{
+    setAll();
+    all->setChecked( true );
+    for( int i_cat_index = 0 ; i_cat_index < advanced_tree->topLevelItemCount();
+         i_cat_index++ )
+    {
+        QTreeWidgetItem *cat_item = advanced_tree->topLevelItem( i_cat_index );
+        PrefsItemData *data = cat_item->data( 0, Qt::UserRole ).
+                                                   value<PrefsItemData *>();
+        for( int i_sc_index = 0; i_sc_index < cat_item->childCount();
+                                  i_sc_index++ )
+        {
+            QTreeWidgetItem *subcat_item = cat_item->child( i_sc_index );
+            PrefsItemData *sc_data = subcat_item->data(0, Qt::UserRole).
+                                                    value<PrefsItemData *>();
+            for( int i_module = 0; i_module < subcat_item->childCount();
+                                   i_module++ )
+            {
+                QTreeWidgetItem *module_item = subcat_item->child( i_module );
+                PrefsItemData *mod_data = module_item->data(0, Qt::UserRole).
+                                                    value<PrefsItemData *>();
+                if( !strcmp( mod_data->psz_name, psz_module ) ) {
+                    advanced_tree->setCurrentItem( module_item );
+                }
+            }
+        }
+    }
+    show();
+}
+
+void PrefsDialog::save()
+{
+    if( small->isChecked() && simple_tree )
+    {
+        for( int i = 0 ; i< SPrefsMax; i++ )
+            if( simple_panels[i] ) simple_panels[i]->apply();
+    }
+    else if( all->isChecked() && advanced_tree )
+        advanced_tree->applyAll();
+    config_SaveConfigFile( p_intf, NULL );
+    hide();
+}
+
+void PrefsDialog::cancel()
+{
+    if( small->isChecked() && simple_tree )
+    {
+        for( int i = 0 ; i< SPrefsMax; i++ )
+            if( simple_panels[i] ) simple_panels[i]->clean();
+    }
+    else if( all->isChecked() && advanced_tree )
+    {
+        advanced_tree->cleanAll();
+        advanced_panel = NULL;
+    }
+    hide();
 }