1 /*****************************************************************************
2 * preferences.cpp : Preferences
3 *****************************************************************************
4 * Copyright (C) 2006-2007 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.
23 *****************************************************************************/
25 #include "dialogs/preferences.hpp"
26 #include "dialogs_provider.hpp"
27 #include "util/qvlcframe.hpp"
29 #include "components/complete_preferences.hpp"
30 #include "components/simple_preferences.hpp"
33 #include <QHBoxLayout>
35 #include <QRadioButton>
36 #include <QVBoxLayout>
37 #include <QPushButton>
39 #include <QScrollArea>
40 #include <QMessageBox>
41 #include <QDialogButtonBox>
43 PrefsDialog *PrefsDialog::instance = NULL;
45 PrefsDialog::PrefsDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
47 QGridLayout *main_layout = new QGridLayout( this );
48 setWindowTitle( qtr( "Preferences" ) );
52 tree_panel = new QWidget( 0 );
53 tree_panel_l = new QHBoxLayout;
54 tree_panel->setLayout( tree_panel_l );
55 main_panel = new QWidget( 0 );
56 main_panel_l = new QHBoxLayout;
57 main_panel->setLayout( main_panel_l );
59 /* Choice for types */
60 types = new QGroupBox( "Show settings" );
61 types->setAlignment( Qt::AlignHCenter );
62 QHBoxLayout *types_l = new QHBoxLayout(0);
63 types_l->setSpacing( 3 ); types_l->setMargin( 3 );
64 small = new QRadioButton( "Basic", types ); types_l->addWidget( small );
65 all = new QRadioButton( "All", types ); types_l->addWidget( all );
66 types->setLayout( types_l );
67 small->setChecked( true );
69 /* Tree and panel initialisations */
73 advanced_panel = NULL;
76 QDialogButtonBox *buttonsBox = new QDialogButtonBox();
77 QPushButton *save = new QPushButton( qtr( "&Save" ) );
78 QPushButton *cancel = new QPushButton( qtr( "&Cancel" ) );
79 QPushButton *reset = new QPushButton( qtr( "&Reset Preferences" ) );
81 buttonsBox->addButton( save, QDialogButtonBox::AcceptRole );
82 buttonsBox->addButton( cancel, QDialogButtonBox::RejectRole );
83 buttonsBox->addButton( reset, QDialogButtonBox::ActionRole );
86 main_layout->addWidget( tree_panel, 0, 0, 3, 1 );
87 main_layout->addWidget( types, 3, 0, 2, 1 );
88 main_layout->addWidget( main_panel, 0, 1, 4, 1 );
89 main_layout->addWidget( buttonsBox, 4, 1, 1 ,2 );
91 main_layout->setColumnMinimumWidth( 0, 150 );
92 main_layout->setColumnStretch( 0, 1 );
93 main_layout->setColumnStretch( 1, 3 );
95 main_layout->setRowStretch( 2, 4);
97 setLayout( main_layout );
100 tree_panel_l->setMargin( 1 );
101 main_panel_l->setMargin( 3 );
105 BUTTONACT( save, save() );
106 BUTTONACT( cancel, cancel() );
107 BUTTONACT( reset, reset() );
108 BUTTONACT( small, setSmall() );
109 BUTTONACT( all, setAll() );
111 for( int i = 0; i < SPrefsMax ; i++ ) simple_panels[i] = NULL;
114 void PrefsDialog::setAll()
118 tree_panel_l->removeWidget( simple_tree );
124 advanced_tree = new PrefsTree( p_intf, tree_panel );
125 CONNECT( advanced_tree,
126 currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem *),
127 this, changePanel( QTreeWidgetItem * ) );
129 tree_panel_l->addWidget( advanced_tree );
130 advanced_tree->show();
134 main_panel_l->removeWidget( simple_panel );
135 simple_panel->hide();
137 if( !advanced_panel )
138 advanced_panel = new PrefsPanel( main_panel );
139 main_panel_l->addWidget( advanced_panel );
140 advanced_panel->show();
143 void PrefsDialog::setSmall()
147 tree_panel_l->removeWidget( advanced_tree );
148 advanced_tree->hide();
152 simple_tree = new SPrefsCatList( p_intf, tree_panel );
153 CONNECT( simple_tree,
154 currentItemChanged( int ),
155 this, changeSimplePanel( int ) );
157 tree_panel_l->addWidget( simple_tree );
162 main_panel_l->removeWidget( advanced_panel );
163 advanced_panel->hide();
166 simple_panel = new SPrefsPanel( p_intf, main_panel, SPrefsDefaultCat );
167 main_panel_l->addWidget( simple_panel );
168 simple_panel->show();
171 void PrefsDialog::changeSimplePanel( int number )
175 main_panel_l->removeWidget( simple_panel );
176 simple_panel->hide();
178 simple_panel = simple_panels[number];
181 simple_panel = new SPrefsPanel( p_intf, main_panel, number );
182 simple_panels[number] = simple_panel;
184 main_panel_l->addWidget( simple_panel );
185 simple_panel->show();
188 void PrefsDialog::changePanel( QTreeWidgetItem *item )
190 PrefsItemData *data = item->data( 0, Qt::UserRole ).value<PrefsItemData*>();
194 main_panel_l->removeWidget( advanced_panel );
195 advanced_panel->hide();
198 data->panel = new PrefsPanel( p_intf, main_panel , data );
200 advanced_panel = data->panel;
201 main_panel_l->addWidget( advanced_panel );
202 advanced_panel->show();
205 void PrefsDialog::showModulePrefs( char *psz_module )
208 all->setChecked( true );
209 for( int i_cat_index = 0 ; i_cat_index < advanced_tree->topLevelItemCount();
212 QTreeWidgetItem *cat_item = advanced_tree->topLevelItem( i_cat_index );
213 PrefsItemData *data = cat_item->data( 0, Qt::UserRole ).
214 value<PrefsItemData *>();
215 for( int i_sc_index = 0; i_sc_index < cat_item->childCount();
218 QTreeWidgetItem *subcat_item = cat_item->child( i_sc_index );
219 PrefsItemData *sc_data = subcat_item->data(0, Qt::UserRole).
220 value<PrefsItemData *>();
221 for( int i_module = 0; i_module < subcat_item->childCount();
224 QTreeWidgetItem *module_item = subcat_item->child( i_module );
225 PrefsItemData *mod_data = module_item->data( 0, Qt::UserRole ).
226 value<PrefsItemData *>();
227 if( !strcmp( mod_data->psz_name, psz_module ) ) {
228 advanced_tree->setCurrentItem( module_item );
236 void PrefsDialog::save()
238 if( small->isChecked() && simple_tree )
240 for( int i = 0 ; i< SPrefsMax; i++ )
241 if( simple_panels[i] ) simple_panels[i]->apply();
243 else if( all->isChecked() && advanced_tree )
244 advanced_tree->applyAll();
245 config_SaveConfigFile( p_intf, NULL );
249 void PrefsDialog::cancel()
251 if( small->isChecked() && simple_tree )
253 for( int i = 0 ; i< SPrefsMax; i++ )
254 if( simple_panels[i] ) simple_panels[i]->clean();
256 else if( all->isChecked() && advanced_tree )
258 advanced_tree->cleanAll();
259 advanced_panel = NULL;
264 void PrefsDialog::reset()
266 int ret = QMessageBox::question(this, qtr("Reset Preferences"),
267 qtr("This will reset your VLC media player preferences.\n"
268 "Are you sure you want to continue?"),
269 QMessageBox::Ok | QMessageBox::Cancel,
271 if ( ret == QMessageBox::Ok )
273 config_ResetAll( p_intf );
274 config_SaveConfigFile( p_intf, NULL );