]> git.sesse.net Git - vlc/commitdiff
Preferences
authorClément Stenac <zorglub@videolan.org>
Sat, 2 Sep 2006 08:39:28 +0000 (08:39 +0000)
committerClément Stenac <zorglub@videolan.org>
Sat, 2 Sep 2006 08:39:28 +0000 (08:39 +0000)
* Enable Save/Cancel. Please test heavily with already implemented stuff. There is a layout bug with simple prefs because they don't implement save yet. Also, we still have some parenting issues to fix
* Remove "advanced" stuff

modules/gui/qt4/components/preferences.cpp
modules/gui/qt4/components/preferences.hpp
modules/gui/qt4/components/preferences_widgets.hpp
modules/gui/qt4/components/simple_preferences.cpp
modules/gui/qt4/components/simple_preferences.hpp
modules/gui/qt4/dialogs/prefs_dialog.cpp
modules/gui/qt4/dialogs/prefs_dialog.hpp
modules/gui/qt4/util/qvlcframe.hpp

index b20cdc9a39c98067db9a22b08f9855bdaa1b75bf..db2331d545f51624395bb0a4154453b471a224af 100644 (file)
@@ -274,43 +274,62 @@ PrefsTree::PrefsTree( intf_thread_t *_p_intf, QWidget *_parent ) :
 
 PrefsTree::~PrefsTree() {}
 
-void PrefsTree::ApplyAll()
+void PrefsTree::applyAll()
 {
-    DoAll( false );
+    doAll( false );
 }
 
-void PrefsTree::CleanAll()
+void PrefsTree::cleanAll()
 {
-    DoAll( true );
+    doAll( true );
 }
 
 /// \todo When cleaning, we should remove the panel ?
-void PrefsTree::DoAll( bool doclean )
+void PrefsTree::doAll( bool doclean )
 {
     for( int i_cat_index = 0 ; i_cat_index < topLevelItemCount();
              i_cat_index++ )
     {
         QTreeWidgetItem *cat_item = topLevelItem( i_cat_index );
-        for( int i_sc_index = 0; i_sc_index <= cat_item->childCount();
+        for( int i_sc_index = 0; i_sc_index < cat_item->childCount();
                  i_sc_index++ )
         {
             QTreeWidgetItem *sc_item = cat_item->child( i_sc_index );
-            for( int i_module = 0 ; i_module <= sc_item->childCount();
+            for( int i_module = 0 ; i_module < sc_item->childCount();
                      i_module++ )
             {
-                PrefsItemData *data = sc_item->child( i_sc_index )->
-                                                 data( 0, Qt::UserRole ).
-                                                 value<PrefsItemData *>();
+                PrefsItemData *data = sc_item->child( i_module )->
+                               data( 0, Qt::UserRole).value<PrefsItemData *>();
                 if( data->panel && doclean )
-                    data->panel->Clean();
+                {
+                    delete data->panel;
+                    data->panel = NULL;
+                }
                 else if( data->panel )
-                    data->panel->Apply();
+                    data->panel->apply();
             }
+            PrefsItemData *data = sc_item->data( 0, Qt::UserRole).
+                                            value<PrefsItemData *>();
+            if( data->panel && doclean )
+            {
+                delete data->panel;
+                data->panel = NULL;
+            }
+            else if( data->panel )
+                data->panel->apply();
+        }
+        PrefsItemData *data = cat_item->data( 0, Qt::UserRole).
+                                            value<PrefsItemData *>();
+        if( data->panel && doclean )
+        {
+            delete data->panel;
+            data->panel = NULL;
         }
+        else if( data->panel )
+            data->panel->apply();
     }
 }
 
-
 /*********************************************************************
  * The Panel
  *********************************************************************/
@@ -478,45 +497,53 @@ PrefsPanel::PrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
     scroller->setWidget( scrolled_area );
     scroller->setWidgetResizable( true );
     global_layout->addWidget( scroller );
-
+    setLayout( global_layout );
+#if 0
     some_hidden_text = new QLabel( qfu( I_HIDDEN_ADV ) );
     some_hidden_text->setWordWrap( true );
-
-    setLayout( global_layout );
     setAdvanced( currently_advanced, true );
+#endif
 }
 
-void PrefsPanel::Apply()
+void PrefsPanel::apply()
 {
     /* todo */
     QList<ConfigControl *>::Iterator i;
     for( i = controls.begin() ; i != controls.end() ; i++ )
     {
-        VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(*i);
-        if( !vicc )
+        ConfigControl *c = qobject_cast<ConfigControl *>(*i);
+        fprintf( stderr, "Get a control %s\n", c->getName() );
+        switch( c->getType() )
         {
+        case 1:
+            {
+            VIntConfigControl *vicc = qobject_cast<VIntConfigControl *>(*i);
+                fprintf( stderr, "Put %s = %i\n",  vicc->getName(),vicc->getValue() );
+            config_PutInt( p_intf, vicc->getName(), vicc->getValue() );
+            break;
+            }
+        case 2:
+            {
             VFloatConfigControl *vfcc = qobject_cast<VFloatConfigControl *>(*i);
-            if( !vfcc)
+                fprintf( stderr, "Put %s = %f\n",  vfcc->getName(),vfcc->getValue() );
+            config_PutFloat( p_intf, vfcc->getName(), vfcc->getValue() );
+            break;
+            }
+        case 3:
             {
-                VStringConfigControl *vscc =
-                               qobject_cast<VStringConfigControl *>(*i);
-                assert( vscc );
-                config_PutPsz( p_intf, vscc->getName().toAscii().data(),
+            VStringConfigControl *vscc =
+                            qobject_cast<VStringConfigControl *>(*i);
+                fprintf( stderr, "Put %s = %s\n",  vscc->getName(),vscc->getValue().toAscii().data() );
+            config_PutPsz( p_intf, vscc->getName(),
                                        vscc->getValue().toAscii().data() );
-                continue;
             }
-            config_PutFloat( p_intf, vfcc->getName().toAscii().data(),
-                                     vfcc->getValue() );
-            continue;
         }
-        config_PutInt( p_intf, vicc->getName().toAscii().data(),
-                               vicc->getValue() );
     }
 }
 
-void PrefsPanel::Clean()
+void PrefsPanel::clean()
 {}
-
+#if 0
 void PrefsPanel::setAdvanced( bool adv, bool force )
 {
     bool some_hidden = false;
@@ -548,3 +575,4 @@ void PrefsPanel::setAdvanced( bool adv, bool force )
         some_hidden_text->show();
     }
 }
+#endif
index a1ac874821dbacd5595bbb101b76fce6e06542c0..85687b0aaf742899a419a2c529850eb516e32f3a 100644 (file)
@@ -64,11 +64,11 @@ public:
     PrefsTree( intf_thread_t *, QWidget * );
     virtual ~PrefsTree();
 
-    void ApplyAll();
-    void CleanAll();
+    void applyAll();
+    void cleanAll();
 
 private:
-    void DoAll( bool );
+    void doAll( bool );
     intf_thread_t *p_intf;
 };
 
@@ -81,17 +81,21 @@ public:
     PrefsPanel( intf_thread_t *, QWidget *, PrefsItemData *, bool );
     PrefsPanel( QWidget *);
     virtual ~PrefsPanel() {};
-    void Apply();
-    void Clean();
+    void apply();
+    void clean();
 private:
     intf_thread_t *p_intf;
     QList<ConfigControl *> controls;
-    QLabel *some_hidden_text;
     QVBoxLayout *global_layout;
+#if 0
+    QLabel *some_hidden_text;
     bool advanced;
+#endif
 public slots:
+#if 0
     void setAdvanced( bool, bool );
     void setAdvanced( bool a ) { return setAdvanced( a, false ); }
+#endif
 };
 
 #endif
index 46cdab5a54872b35fb655ec0ee1ea80a5516858d..f21f79d6be9fca81b4102f06e7912f8e6a8b8885 100644 (file)
@@ -50,7 +50,8 @@ public:
         widget = NULL;
     }
     virtual ~ConfigControl() {};
-    QString getName() { return qfu( p_item->psz_name ); }
+    virtual int getType() = 0;
+    char * getName() { return  p_item->psz_name; }
     QWidget *getWidget() { assert( widget ); return widget; }
     bool isAdvanced() { return p_item->b_advanced; }
     virtual void hide() { getWidget()->hide(); };
@@ -83,6 +84,7 @@ public:
                 ConfigControl(a,b) {};
     virtual ~VIntConfigControl() {};
     virtual int getValue() = 0;
+    virtual int getType() { return 1; }
 };
 
 class IntegerConfigControl : public VIntConfigControl
@@ -161,6 +163,7 @@ public:
                 ConfigControl(a,b) {};
     virtual ~VFloatConfigControl() {};
     virtual float getValue() = 0;
+    virtual int getType() { return 2; }
 };
 
 class FloatConfigControl : public VFloatConfigControl
@@ -218,6 +221,7 @@ public:
                 ConfigControl(a,b) {};
     virtual ~VStringConfigControl() {};
     virtual QString getValue() = 0;
+    virtual int getType() { return 3; }
 };
 
 class StringConfigControl : public VStringConfigControl
index eaa5446aab6960e3a3b1ce912c0a07fea09b5aa4..13a270d6a0db51d34eeb608bad614e9c5a1cd0b4 100644 (file)
@@ -86,18 +86,18 @@ SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
     setCurrentRow( SPrefsInterface );
 }
 
-void SPrefsCatList::ApplyAll()
+void SPrefsCatList::applyAll()
 {
-    DoAll( false );
+    doAll( false );
 }
 
-void SPrefsCatList::CleanAll()
+void SPrefsCatList::cleanAll()
 {
-    DoAll( true );
+    doAll( true );
 }
 
 /// \todo When cleaning, we should remove the panel ?
-void SPrefsCatList::DoAll( bool doclean )
+void SPrefsCatList::doAll( bool doclean )
 {
     /* Todo */
 }
@@ -202,15 +202,15 @@ void SPrefsPanel::Apply()
                 VStringConfigControl *vscc =
                                qobject_cast<VStringConfigControl *>(*i);
                 assert( vscc );
-                config_PutPsz( p_intf, vscc->getName().toAscii().data(),
+                config_PutPsz( p_intf, vscc->getName(),
                                        vscc->getValue().toAscii().data() );
                 continue;
             }
-            config_PutFloat( p_intf, vfcc->getName().toAscii().data(),
+            config_PutFloat( p_intf, vfcc->getName(),
                                      vfcc->getValue() );
             continue;
         }
-        config_PutInt( p_intf, vicc->getName().toAscii().data(),
+        config_PutInt( p_intf, vicc->getName(),
                                vicc->getValue() );
     }
 }
index 7403cbdbf7783e4560b2cac88dd938a61e09c37c..0c43f13b4c31b998c1b50ae7d90119e729ea7a97 100644 (file)
@@ -48,11 +48,11 @@ public:
     SPrefsCatList( intf_thread_t *, QWidget *);
     virtual ~SPrefsCatList() {};
 
-    void ApplyAll();
-    void CleanAll();
+    void applyAll();
+    void cleanAll();
 
 private:
-    void DoAll( bool );
+    void doAll( bool );
     intf_thread_t *p_intf;
 };
 
index 59af6e2dbcdfc1aabd95c7cbb576aa39b7ac12b6..bb49805e12780703fa96418eadb477c71b88d2da 100644 (file)
@@ -57,9 +57,9 @@ PrefsDialog::PrefsDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
      all = new QRadioButton( "All", types ); tl->addWidget( all );
      types->setLayout(tl);
      small->setChecked( true );
-
+#if 0
      adv_chk = new QCheckBox("Advanced options");
-
+#endif
      advanced_tree = NULL;
      simple_tree = NULL;
      simple_panel = NULL;
@@ -67,29 +67,42 @@ 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 );
+#if 0
      main_layout->addWidget( adv_chk , 2,0,1,1 );
-     main_layout->addWidget( main_panel, 0, 1, 3, 1 );
+#endif
+     main_layout->addWidget( main_panel, 0, 1, 2, 1 );
 
      main_layout->setColumnMinimumWidth( 0, 200 );
      main_layout->setColumnStretch( 0, 1 );
      main_layout->setColumnStretch( 1,3 );
 
      setSmall();
-
+#if 0
      connect( adv_chk, SIGNAL( toggled(bool) ),
               this, SLOT( setAdvanced( bool ) ) );
+#endif
+
+     QPushButton *save, *cancel;
+     QHBoxLayout *buttonsLayout =
+         QVLCFrame::doButtons( this, NULL, &save, _("Save"),
+                                           &cancel, _("Cancel"),
+                                                NULL, NULL );
+     connect( save, SIGNAL( clicked() ), this, SLOT( save() ) );
+     connect( cancel, SIGNAL( clicked() ), this, SLOT( cancel() ) );
+     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()) );
 }
-
+#if 0
 void PrefsDialog::setAdvanced( bool advanced )
 {
     if( advanced_panel )
         advanced_panel->setAdvanced( advanced );
 }
-
+#endif
 void PrefsDialog::setAll()
 {
     if( simple_tree )
@@ -117,7 +130,9 @@ void PrefsDialog::setAll()
          advanced_panel = new PrefsPanel( main_panel );
     main_panel_l->addWidget( advanced_panel );
     advanced_panel->show();
+#if 0
     adv_chk->show();
+#endif
 }
 
 void PrefsDialog::setSmall()
@@ -146,7 +161,9 @@ void PrefsDialog::setSmall()
         simple_panel = new SPrefsPanel( p_intf, main_panel, SPrefsDefaultCat );
     main_panel_l->addWidget( simple_panel );
     simple_panel->show();
+#if 0
     adv_chk->hide();
+#endif
 }
 
 PrefsDialog::~PrefsDialog()
@@ -179,11 +196,40 @@ void PrefsDialog::changePanel( QTreeWidgetItem *item )
     }
     if( !data->panel )
     {
-        data->panel = new PrefsPanel( p_intf, main_panel , data,
-                                      adv_chk->isChecked() );
+        data->panel = new PrefsPanel( p_intf, main_panel , data, true );
+#if 0
+        adv_chk->isChecked() );
+#endif
     }
     advanced_panel = data->panel;
     main_panel_l->addWidget( advanced_panel );
     advanced_panel->show();
+#if 0
     setAdvanced( adv_chk->isChecked() );
+#endif
+}
+
+void PrefsDialog::save()
+{
+    if( small->isChecked() && simple_tree )
+        simple_tree->applyAll();
+    else if( all->isChecked() && advanced_tree )
+        advanced_tree->applyAll();
+    config_SaveConfigFile( p_intf, NULL );
+    hide();
+}
+
+void PrefsDialog::cancel()
+{
+    if( small->isChecked() && simple_tree )
+    {
+        simple_tree->cleanAll();
+        simple_panel = NULL;
+    }
+    else if( all->isChecked() && advanced_tree )
+    {
+        advanced_tree->cleanAll();
+        advanced_panel = NULL;
+    }
+    hide();
 }
index f8dd8b506a72800ab2d0da6a2641ed4d430256a6..8a11c362de7d4575707ae6a605ae0f3b3357f361 100644 (file)
@@ -67,7 +67,9 @@ private:
 
     QGroupBox *types;
     QRadioButton *small,*all;
+#if 0
     QCheckBox *adv_chk;
+#endif
 
     QGridLayout *main_layout;
 
@@ -77,7 +79,11 @@ private slots:
      void changeSimplePanel( QListWidgetItem *);
      void setAll();
      void setSmall();
+     void save();
+     void cancel();
+#if 0
      void setAdvanced( bool );
+#endif
 };
 
 #endif
index e721fd5ecf543517114dd40a61893dbed0e9838c..36a368fb0185ac2b77fb73704b95a06844a2a9df 100644 (file)
@@ -59,10 +59,10 @@ public:
         }
 #endif
     }
-    static void doButtons( QWidget *w, QBoxLayout *l,
-                           QPushButton **defaul, char *psz_default,
-                           QPushButton **alt, char *psz_alt,
-                           QPushButton **other, char *psz_other )
+    static QHBoxLayout* doButtons( QWidget *w, QBoxLayout *l,
+                               QPushButton **defaul, char *psz_default,
+                               QPushButton **alt, char *psz_alt,
+                               QPushButton **other, char *psz_other )
     {
 #ifdef QT42
 #else
@@ -73,6 +73,7 @@ public:
 
         if( psz_default )
         {
+            fprintf( stderr, "Creating default button %s\n", psz_default );
             *defaul = new QPushButton(0);
             buttons_layout->addWidget( *defaul );
             (*defaul)->setText( qfu( psz_default ) );
@@ -89,8 +90,10 @@ public:
             buttons_layout->addWidget( *other );
             (*other)->setText( qfu( psz_other ) );
         }
-        l->addLayout( buttons_layout );
+        if( l )
+            l->addLayout( buttons_layout );
 #endif
+        return buttons_layout;
     };
 
     QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL ), p_intf( _p_intf )