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>
39 #include <QMessageBox>
42 PrefsDialog *PrefsDialog::instance = NULL;
44 PrefsDialog::PrefsDialog( intf_thread_t *_p_intf ) : QVLCFrame( _p_intf )
46 QGridLayout *main_layout = new QGridLayout( this );
47 setWindowTitle( qtr( "Preferences" ) );
49 setMaximumHeight( 650 );
50 setMaximumWidth( 700 );
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 );
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 );
72 advanced_panel = NULL;
74 main_layout->addWidget( tree_panel, 0, 0, 3, 1 );
75 main_layout->addWidget( types, 3, 0, 1, 1 );
77 main_layout->addWidget( main_panel, 0, 1, 4, 1 );
79 main_layout->setColumnMinimumWidth( 0, 150 );
80 main_layout->setColumnStretch( 0, 1 );
81 main_layout->setColumnStretch( 1,3 );
83 main_layout->setRowStretch( 2, 4);
87 QPushButton *save, *cancel, *reset;
88 QHBoxLayout *buttonsLayout = QVLCFrame::doButtons( this, NULL,
91 &reset, _( "Reset Preferences" ) );
92 main_layout->addLayout( buttonsLayout, 4, 0, 1 ,3 );
93 setLayout( main_layout );
96 BUTTONACT( save, save() );
97 BUTTONACT( cancel, cancel() );
98 BUTTONACT( reset, reset() );
99 BUTTONACT( small, setSmall() );
100 BUTTONACT( all, setAll() );
102 for( int i = 0; i < SPrefsMax ; i++ ) simple_panels[i] = NULL;
105 void PrefsDialog::setAll()
109 tree_panel_l->removeWidget( simple_tree );
115 advanced_tree = new PrefsTree( p_intf, tree_panel );
116 CONNECT( advanced_tree,
117 currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem *),
118 this, changePanel( QTreeWidgetItem * ) );
120 tree_panel_l->addWidget( advanced_tree );
121 advanced_tree->show();
125 main_panel_l->removeWidget( simple_panel );
126 simple_panel->hide();
128 if( !advanced_panel )
129 advanced_panel = new PrefsPanel( main_panel );
130 main_panel_l->addWidget( advanced_panel );
131 advanced_panel->show();
134 void PrefsDialog::setSmall()
138 tree_panel_l->removeWidget( advanced_tree );
139 advanced_tree->hide();
143 simple_tree = new SPrefsCatList( p_intf, tree_panel );
144 CONNECT( simple_tree,
145 currentItemChanged( QListWidgetItem *, QListWidgetItem *),
146 this, changeSimplePanel( QListWidgetItem * ) );
148 tree_panel_l->addWidget( simple_tree );
153 main_panel_l->removeWidget( advanced_panel );
154 advanced_panel->hide();
157 simple_panel = new SPrefsPanel( p_intf, main_panel, SPrefsDefaultCat );
158 main_panel_l->addWidget( simple_panel );
159 simple_panel->show();
162 void PrefsDialog::changeSimplePanel( QListWidgetItem *item )
164 int number = item->data( Qt::UserRole ).toInt();
167 main_panel_l->removeWidget( simple_panel );
168 simple_panel->hide();
170 simple_panel = simple_panels[number];
173 simple_panel = new SPrefsPanel( p_intf, main_panel, number );
174 simple_panels[number] = simple_panel;
176 main_panel_l->addWidget( simple_panel );
177 simple_panel->show();
178 // panel_label->setText(qtr("Test")); //FIXME
181 void PrefsDialog::changePanel( QTreeWidgetItem *item )
183 PrefsItemData *data = item->data( 0, Qt::UserRole ).value<PrefsItemData*>();
187 main_panel_l->removeWidget( advanced_panel );
188 advanced_panel->hide();
191 data->panel = new PrefsPanel( p_intf, main_panel , data );
193 advanced_panel = data->panel;
194 main_panel_l->addWidget( advanced_panel );
195 advanced_panel->show();
198 void PrefsDialog::showModulePrefs( char *psz_module )
201 all->setChecked( true );
202 for( int i_cat_index = 0 ; i_cat_index < advanced_tree->topLevelItemCount();
205 QTreeWidgetItem *cat_item = advanced_tree->topLevelItem( i_cat_index );
206 PrefsItemData *data = cat_item->data( 0, Qt::UserRole ).
207 value<PrefsItemData *>();
208 for( int i_sc_index = 0; i_sc_index < cat_item->childCount();
211 QTreeWidgetItem *subcat_item = cat_item->child( i_sc_index );
212 PrefsItemData *sc_data = subcat_item->data(0, Qt::UserRole).
213 value<PrefsItemData *>();
214 for( int i_module = 0; i_module < subcat_item->childCount();
217 QTreeWidgetItem *module_item = subcat_item->child( i_module );
218 PrefsItemData *mod_data = module_item->data( 0, Qt::UserRole ).
219 value<PrefsItemData *>();
220 if( !strcmp( mod_data->psz_name, psz_module ) ) {
221 advanced_tree->setCurrentItem( module_item );
229 void PrefsDialog::save()
231 if( small->isChecked() && simple_tree )
233 for( int i = 0 ; i< SPrefsMax; i++ )
234 if( simple_panels[i] ) simple_panels[i]->apply();
236 else if( all->isChecked() && advanced_tree )
237 advanced_tree->applyAll();
238 config_SaveConfigFile( p_intf, NULL );
242 void PrefsDialog::cancel()
244 if( small->isChecked() && simple_tree )
246 for( int i = 0 ; i< SPrefsMax; i++ )
247 if( simple_panels[i] ) simple_panels[i]->clean();
249 else if( all->isChecked() && advanced_tree )
251 advanced_tree->cleanAll();
252 advanced_panel = NULL;
257 void PrefsDialog::reset()
259 int ret = QMessageBox::question(this, qtr("Reset Preferences"),
260 qtr("This will reset your VLC media player preferences.\n"
261 "Are you sure you want to continue?"),
262 QMessageBox::Ok | QMessageBox::Cancel,
264 if ( ret == QMessageBox::Ok )
266 config_ResetAll( p_intf );
267 // TODO reset changes ?
268 config_SaveConfigFile( p_intf, NULL );