Commit 4717c1ac authored by Clément Stenac's avatar Clément Stenac

Preferences

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