1 /*****************************************************************************
2 * prefs_dialog.cpp : Preferences
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/
23 #include "dialogs/prefs_dialog.hpp"
24 #include "dialogs_provider.hpp"
25 #include "util/qvlcframe.hpp"
27 #include "components/preferences.hpp"
28 #include "components/simple_preferences.hpp"
31 #include <QHBoxLayout>
33 #include <QRadioButton>
34 #include <QVBoxLayout>
35 #include <QPushButton>
38 PrefsDialog *PrefsDialog::instance = NULL;
40 PrefsDialog::PrefsDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
42 QGridLayout *main_layout = new QGridLayout(this);
43 setWindowTitle( qtr( "Preferences" ) );
46 tree_panel = new QWidget(0);
47 tree_panel_l = new QHBoxLayout;
48 tree_panel->setLayout( tree_panel_l );
49 main_panel = new QWidget(0);
50 main_panel_l = new QHBoxLayout;
51 main_panel->setLayout( main_panel_l );
54 types = new QGroupBox( "Show settings" );
55 QHBoxLayout *tl = new QHBoxLayout(0);
56 tl->setSpacing( 3 ); tl->setMargin( 3 );
57 small = new QRadioButton( "Basic", types ); tl->addWidget( small );
58 all = new QRadioButton( "All", types ); tl->addWidget( all );
60 small->setChecked( true );
65 advanced_panel = NULL;
67 main_layout->addWidget( types, 0,0,1,1 );
68 main_layout->addWidget( tree_panel, 1,0,1,1 );
69 main_layout->addWidget( main_panel, 0, 1, 2, 1 );
71 main_layout->setColumnMinimumWidth( 0, 200 );
72 main_layout->setColumnStretch( 0, 1 );
73 main_layout->setColumnStretch( 1,3 );
77 QPushButton *save, *cancel;
78 QHBoxLayout *buttonsLayout = QVLCFrame::doButtons( this, NULL,
82 main_layout->addLayout( buttonsLayout, 2,0, 1 ,3 );
83 setLayout( main_layout );
85 BUTTONACT( save, save() );
86 BUTTONACT( cancel, cancel() );
87 BUTTONACT( small, setSmall() );
88 BUTTONACT( all, setAll() );
90 for( int i = 0; i < SPrefsMax ; i++ ) simple_panels[i] = NULL;
93 void PrefsDialog::setAll()
97 tree_panel_l->removeWidget( simple_tree );
103 advanced_tree = new PrefsTree( p_intf, tree_panel );
104 CONNECT( advanced_tree,
105 currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem *),
106 this, changePanel( QTreeWidgetItem * ) );
108 tree_panel_l->addWidget( advanced_tree );
109 advanced_tree->show();
113 main_panel_l->removeWidget( simple_panel );
114 simple_panel->hide();
116 if( !advanced_panel )
117 advanced_panel = new PrefsPanel( main_panel );
118 main_panel_l->addWidget( advanced_panel );
119 advanced_panel->show();
122 void PrefsDialog::setSmall()
126 tree_panel_l->removeWidget( advanced_tree );
127 advanced_tree->hide();
131 simple_tree = new SPrefsCatList( p_intf, tree_panel );
132 CONNECT( simple_tree,
133 currentItemChanged( QListWidgetItem *, QListWidgetItem *),
134 this, changeSimplePanel( QListWidgetItem * ) );
136 tree_panel_l->addWidget( simple_tree );
141 main_panel_l->removeWidget( advanced_panel );
142 advanced_panel->hide();
145 simple_panel = new SPrefsPanel( p_intf, main_panel, SPrefsDefaultCat );
146 main_panel_l->addWidget( simple_panel );
147 simple_panel->show();
150 void PrefsDialog::changeSimplePanel( QListWidgetItem *item )
152 int number = item->data( Qt::UserRole ).toInt();
155 main_panel_l->removeWidget( simple_panel );
156 simple_panel->hide();
158 if( !simple_panels[number] )
159 simple_panel = new SPrefsPanel( p_intf, main_panel, number );
160 simple_panels[number] = simple_panel;
161 main_panel_l->addWidget( simple_panel );
162 simple_panel->show();
165 void PrefsDialog::changePanel( QTreeWidgetItem *item )
167 PrefsItemData *data = item->data( 0, Qt::UserRole ).value<PrefsItemData*>();
171 main_panel_l->removeWidget( advanced_panel );
172 advanced_panel->hide();
175 data->panel = new PrefsPanel( p_intf, main_panel , data );
177 advanced_panel = data->panel;
178 main_panel_l->addWidget( advanced_panel );
179 advanced_panel->show();
182 void PrefsDialog::save()
184 if( small->isChecked() && simple_tree )
186 for( int i = 0 ; i< SPrefsMax; i++ )
187 if( simple_panels[i] ) simple_panels[i]->apply();
189 else if( all->isChecked() && advanced_tree )
190 advanced_tree->applyAll();
191 config_SaveConfigFile( p_intf, NULL );
195 void PrefsDialog::cancel()
197 if( small->isChecked() && simple_tree )
199 for( int i = 0 ; i< SPrefsMax; i++ )
200 if( simple_panels[i] ) simple_panels[i]->clean();
202 else if( all->isChecked() && advanced_tree )
204 advanced_tree->cleanAll();
205 advanced_panel = NULL;