1 /*****************************************************************************
2 * prefs_dialog.cpp : Preferences
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/
24 #include "dialogs/prefs_dialog.hpp"
25 #include "dialogs_provider.hpp"
26 #include "util/qvlcframe.hpp"
28 #include "components/preferences.hpp"
29 #include "components/simple_preferences.hpp"
32 #include <QHBoxLayout>
34 #include <QRadioButton>
35 #include <QVBoxLayout>
36 #include <QPushButton>
38 #include <QScrollArea>
40 PrefsDialog *PrefsDialog::instance = NULL;
42 PrefsDialog::PrefsDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
44 QGridLayout *main_layout = new QGridLayout( this );
45 setWindowTitle( qtr( "Preferences" ) );
47 setMaximumHeight( 650 );
48 setMaximumWidth( 800 );
50 tree_panel = new QWidget( 0 );
51 tree_panel_l = new QHBoxLayout;
52 tree_panel->setLayout( tree_panel_l );
53 main_panel = new QWidget( 0 );
54 main_panel_l = new QHBoxLayout;
55 main_panel->setLayout( main_panel_l );
58 types = new QGroupBox( "Show settings" );
59 types->setAlignment( Qt::AlignHCenter );
60 QHBoxLayout *types_l = new QHBoxLayout(0);
61 types_l->setSpacing( 3 ); types_l->setMargin( 3 );
62 small = new QRadioButton( "Basic", types ); types_l->addWidget( small );
63 all = new QRadioButton( "All", types ); types_l->addWidget( all );
64 types->setLayout( types_l );
65 small->setChecked( true );
70 advanced_panel = NULL;
72 main_layout->addWidget( tree_panel, 0, 0, 3, 1 );
73 main_layout->addWidget( types, 3, 0, 1, 1 );
75 main_layout->addWidget( main_panel, 0, 1, 4, 1 );
77 main_layout->setColumnMinimumWidth( 0, 150 );
78 main_layout->setColumnStretch( 0, 1 );
79 main_layout->setColumnStretch( 1,3 );
81 main_layout->setRowStretch( 2, 4);
85 QPushButton *save, *cancel;
86 QHBoxLayout *buttonsLayout = QVLCFrame::doButtons( this, NULL,
90 main_layout->addLayout( buttonsLayout, 4, 0, 1 ,3 );
91 setLayout( main_layout );
94 BUTTONACT( save, save() );
95 BUTTONACT( cancel, cancel() );
96 BUTTONACT( small, setSmall() );
97 BUTTONACT( all, setAll() );
99 for( int i = 0; i < SPrefsMax ; i++ ) simple_panels[i] = NULL;
102 void PrefsDialog::setAll()
106 tree_panel_l->removeWidget( simple_tree );
112 advanced_tree = new PrefsTree( p_intf, tree_panel );
113 CONNECT( advanced_tree,
114 currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem *),
115 this, changePanel( QTreeWidgetItem * ) );
117 tree_panel_l->addWidget( advanced_tree );
118 advanced_tree->show();
122 main_panel_l->removeWidget( simple_panel );
123 simple_panel->hide();
125 if( !advanced_panel )
126 advanced_panel = new PrefsPanel( main_panel );
127 main_panel_l->addWidget( advanced_panel );
128 advanced_panel->show();
131 void PrefsDialog::setSmall()
135 tree_panel_l->removeWidget( advanced_tree );
136 advanced_tree->hide();
140 simple_tree = new SPrefsCatList( p_intf, tree_panel );
141 CONNECT( simple_tree,
142 currentItemChanged( QListWidgetItem *, QListWidgetItem *),
143 this, changeSimplePanel( QListWidgetItem * ) );
145 tree_panel_l->addWidget( simple_tree );
150 main_panel_l->removeWidget( advanced_panel );
151 advanced_panel->hide();
154 simple_panel = new SPrefsPanel( p_intf, main_panel, SPrefsDefaultCat );
155 main_panel_l->addWidget( simple_panel );
156 simple_panel->show();
159 void PrefsDialog::changeSimplePanel( QListWidgetItem *item )
161 int number = item->data( Qt::UserRole ).toInt();
164 main_panel_l->removeWidget( simple_panel );
165 simple_panel->hide();
167 simple_panel = simple_panels[number];
170 simple_panel = new SPrefsPanel( p_intf, main_panel, number );
171 simple_panels[number] = simple_panel;
173 main_panel_l->addWidget( simple_panel );
174 simple_panel->show();
175 // panel_label->setText(qtr("Test")); //FIXME
178 void PrefsDialog::changePanel( QTreeWidgetItem *item )
180 PrefsItemData *data = item->data( 0, Qt::UserRole ).value<PrefsItemData*>();
184 main_panel_l->removeWidget( advanced_panel );
185 advanced_panel->hide();
188 data->panel = new PrefsPanel( p_intf, main_panel , data );
190 advanced_panel = data->panel;
191 main_panel_l->addWidget( advanced_panel );
192 advanced_panel->show();
195 void PrefsDialog::showModulePrefs( char *psz_module )
198 all->setChecked( true );
199 for( int i_cat_index = 0 ; i_cat_index < advanced_tree->topLevelItemCount();
202 QTreeWidgetItem *cat_item = advanced_tree->topLevelItem( i_cat_index );
203 PrefsItemData *data = cat_item->data( 0, Qt::UserRole ).
204 value<PrefsItemData *>();
205 for( int i_sc_index = 0; i_sc_index < cat_item->childCount();
208 QTreeWidgetItem *subcat_item = cat_item->child( i_sc_index );
209 PrefsItemData *sc_data = subcat_item->data(0, Qt::UserRole).
210 value<PrefsItemData *>();
211 for( int i_module = 0; i_module < subcat_item->childCount();
214 QTreeWidgetItem *module_item = subcat_item->child( i_module );
215 PrefsItemData *mod_data = module_item->data( 0, Qt::UserRole ).
216 value<PrefsItemData *>();
217 if( !strcmp( mod_data->psz_name, psz_module ) ) {
218 advanced_tree->setCurrentItem( module_item );
226 void PrefsDialog::save()
228 if( small->isChecked() && simple_tree )
230 for( int i = 0 ; i< SPrefsMax; i++ )
231 if( simple_panels[i] ) simple_panels[i]->apply();
233 else if( all->isChecked() && advanced_tree )
234 advanced_tree->applyAll();
235 config_SaveConfigFile( p_intf, NULL );
239 void PrefsDialog::cancel()
241 if( small->isChecked() && simple_tree )
243 for( int i = 0 ; i< SPrefsMax; i++ )
244 if( simple_panels[i] ) simple_panels[i]->clean();
246 else if( all->isChecked() && advanced_tree )
248 advanced_tree->cleanAll();
249 advanced_panel = NULL;