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>
37 #include <QScrollArea>
39 PrefsDialog *PrefsDialog::instance = NULL;
41 PrefsDialog::PrefsDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
43 QGridLayout *main_layout = new QGridLayout(this);
44 setWindowTitle( qtr( "Preferences" ) );
46 setMaximumHeight (600);
48 tree_panel = new QWidget(0);
49 tree_panel_l = new QHBoxLayout;
50 tree_panel->setLayout( tree_panel_l );
51 main_panel = new QWidget(0);
52 main_panel_l = new QHBoxLayout;
53 main_panel->setLayout( main_panel_l );
56 types = new QGroupBox( "Show settings" );
57 QHBoxLayout *types_l = new QHBoxLayout(0);
58 types_l->setSpacing( 3 ); types_l->setMargin( 3 );
59 small = new QRadioButton( "Basic", types ); types_l->addWidget( small );
60 all = new QRadioButton( "All", types ); types_l->addWidget( all );
61 types->setLayout(types_l);
62 small->setChecked( true );
67 advanced_panel = NULL;
69 main_layout->addWidget( tree_panel, 0, 0, 3, 1 );
70 main_layout->addWidget( types, 3, 0, 1, 1 );
72 main_layout->addWidget( main_panel, 0, 1, 4, 1 );
74 main_layout->setColumnMinimumWidth( 0, 200 );
75 main_layout->setColumnStretch( 0, 1 );
76 main_layout->setColumnStretch( 1,3 );
78 main_layout->setRowStretch( 2, 4);
82 QPushButton *save, *cancel;
83 QHBoxLayout *buttonsLayout = QVLCFrame::doButtons( this, NULL,
87 main_layout->addLayout( buttonsLayout, 4, 0, 1 ,3 );
88 setLayout( main_layout );
91 BUTTONACT( save, save() );
92 BUTTONACT( cancel, cancel() );
93 BUTTONACT( small, setSmall() );
94 BUTTONACT( all, setAll() );
96 for( int i = 0; i < SPrefsMax ; i++ ) simple_panels[i] = NULL;
99 void PrefsDialog::setAll()
103 tree_panel_l->removeWidget( simple_tree );
109 advanced_tree = new PrefsTree( p_intf, tree_panel );
110 CONNECT( advanced_tree,
111 currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem *),
112 this, changePanel( QTreeWidgetItem * ) );
114 tree_panel_l->addWidget( advanced_tree );
115 advanced_tree->show();
119 main_panel_l->removeWidget( simple_panel );
120 simple_panel->hide();
122 if( !advanced_panel )
123 advanced_panel = new PrefsPanel( main_panel );
124 main_panel_l->addWidget( advanced_panel );
125 advanced_panel->show();
128 void PrefsDialog::setSmall()
132 tree_panel_l->removeWidget( advanced_tree );
133 advanced_tree->hide();
137 simple_tree = new SPrefsCatList( p_intf, tree_panel );
138 CONNECT( simple_tree,
139 currentItemChanged( QListWidgetItem *, QListWidgetItem *),
140 this, changeSimplePanel( QListWidgetItem * ) );
142 tree_panel_l->addWidget( simple_tree );
147 main_panel_l->removeWidget( advanced_panel );
148 advanced_panel->hide();
151 simple_panel = new SPrefsPanel( p_intf, main_panel, SPrefsDefaultCat );
152 main_panel_l->addWidget( simple_panel );
153 simple_panel->show();
156 void PrefsDialog::changeSimplePanel( QListWidgetItem *item )
158 int number = item->data( Qt::UserRole ).toInt();
161 main_panel_l->removeWidget( simple_panel );
162 simple_panel->hide();
164 simple_panel = simple_panels[number];
167 simple_panel = new SPrefsPanel( p_intf, main_panel, number );
168 simple_panels[number] = simple_panel;
170 main_panel_l->addWidget( simple_panel );
171 simple_panel->show();
172 // panel_label->setText(qtr("Test"));
175 void PrefsDialog::changePanel( QTreeWidgetItem *item )
177 PrefsItemData *data = item->data( 0, Qt::UserRole ).value<PrefsItemData*>();
181 main_panel_l->removeWidget( advanced_panel );
182 advanced_panel->hide();
185 data->panel = new PrefsPanel( p_intf, main_panel , data );
187 advanced_panel = data->panel;
188 main_panel_l->addWidget( advanced_panel );
189 advanced_panel->show();
192 void PrefsDialog::showModulePrefs( char *psz_module )
195 all->setChecked( true );
196 for( int i_cat_index = 0 ; i_cat_index < advanced_tree->topLevelItemCount();
199 QTreeWidgetItem *cat_item = advanced_tree->topLevelItem( i_cat_index );
200 PrefsItemData *data = cat_item->data( 0, Qt::UserRole ).
201 value<PrefsItemData *>();
202 for( int i_sc_index = 0; i_sc_index < cat_item->childCount();
205 QTreeWidgetItem *subcat_item = cat_item->child( i_sc_index );
206 PrefsItemData *sc_data = subcat_item->data(0, Qt::UserRole).
207 value<PrefsItemData *>();
208 for( int i_module = 0; i_module < subcat_item->childCount();
211 QTreeWidgetItem *module_item = subcat_item->child( i_module );
212 PrefsItemData *mod_data = module_item->data(0, Qt::UserRole).
213 value<PrefsItemData *>();
214 if( !strcmp( mod_data->psz_name, psz_module ) ) {
215 advanced_tree->setCurrentItem( module_item );
223 void PrefsDialog::save()
225 if( small->isChecked() && simple_tree )
227 for( int i = 0 ; i< SPrefsMax; i++ )
228 if( simple_panels[i] ) simple_panels[i]->apply();
230 else if( all->isChecked() && advanced_tree )
231 advanced_tree->applyAll();
232 config_SaveConfigFile( p_intf, NULL );
236 void PrefsDialog::cancel()
238 if( small->isChecked() && simple_tree )
240 for( int i = 0 ; i< SPrefsMax; i++ )
241 if( simple_panels[i] ) simple_panels[i]->clean();
243 else if( all->isChecked() && advanced_tree )
245 advanced_tree->cleanAll();
246 advanced_panel = NULL;