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 (450);
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 );
57 types = new QGroupBox( "Show settings" );
58 QHBoxLayout *types_l = new QHBoxLayout(0);
59 types_l->setSpacing( 3 ); types_l->setMargin( 3 );
60 small = new QRadioButton( "Basic", types ); types_l->addWidget( small );
61 all = new QRadioButton( "All", types ); types_l->addWidget( all );
62 types->setLayout(types_l);
63 small->setChecked( true );
66 QLabel *panel_label = new QLabel;
67 QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
68 labelFont.setPointSize( labelFont.pointSize() + 4 );
69 labelFont.setBold( true );
70 panel_label->setFont( labelFont );
73 QFrame *title_line = new QFrame;
74 title_line->setFrameShape(QFrame::HLine);
75 title_line->setFrameShadow(QFrame::Sunken);
77 QScrollArea *scrollArea = new QScrollArea;
82 advanced_panel = NULL;
84 main_layout->addWidget( tree_panel, 0, 0, 3, 1 );
85 main_layout->addWidget( types, 3, 0, 1, 1 );
87 main_layout->addWidget( panel_label, 0, 1, 1, 1 );
88 main_layout->addWidget( title_line, 1, 1, 1, 1 );
89 main_layout->addWidget( main_panel, 2, 1, 2, 1 );
91 main_layout->setColumnMinimumWidth( 0, 200 );
92 main_layout->setColumnStretch( 0, 1 );
93 main_layout->setColumnStretch( 1,3 );
95 main_layout->setRowStretch( 2, 4);
99 QPushButton *save, *cancel;
100 QHBoxLayout *buttonsLayout = QVLCFrame::doButtons( this, NULL,
102 &cancel, _("Cancel"),
104 main_layout->addLayout( buttonsLayout, 4, 0, 1 ,3 );
105 setLayout( main_layout );
108 BUTTONACT( save, save() );
109 BUTTONACT( cancel, cancel() );
110 BUTTONACT( small, setSmall() );
111 BUTTONACT( all, setAll() );
113 for( int i = 0; i < SPrefsMax ; i++ ) simple_panels[i] = NULL;
116 void PrefsDialog::setAll()
120 tree_panel_l->removeWidget( simple_tree );
126 advanced_tree = new PrefsTree( p_intf, tree_panel );
127 CONNECT( advanced_tree,
128 currentItemChanged( QTreeWidgetItem *, QTreeWidgetItem *),
129 this, changePanel( QTreeWidgetItem * ) );
131 tree_panel_l->addWidget( advanced_tree );
132 advanced_tree->show();
136 main_panel_l->removeWidget( simple_panel );
137 simple_panel->hide();
139 if( !advanced_panel )
140 advanced_panel = new PrefsPanel( main_panel );
141 main_panel_l->addWidget( advanced_panel );
142 advanced_panel->show();
145 void PrefsDialog::setSmall()
149 tree_panel_l->removeWidget( advanced_tree );
150 advanced_tree->hide();
154 simple_tree = new SPrefsCatList( p_intf, tree_panel );
155 CONNECT( simple_tree,
156 currentItemChanged( QListWidgetItem *, QListWidgetItem *),
157 this, changeSimplePanel( QListWidgetItem * ) );
159 tree_panel_l->addWidget( simple_tree );
164 main_panel_l->removeWidget( advanced_panel );
165 advanced_panel->hide();
168 simple_panel = new SPrefsPanel( p_intf, main_panel, SPrefsDefaultCat );
169 main_panel_l->addWidget( simple_panel );
170 simple_panel->show();
173 void PrefsDialog::changeSimplePanel( QListWidgetItem *item )
175 int number = item->data( Qt::UserRole ).toInt();
178 main_panel_l->removeWidget( simple_panel );
179 simple_panel->hide();
181 simple_panel = simple_panels[number];
184 simple_panel = new SPrefsPanel( p_intf, main_panel, number );
185 simple_panels[number] = simple_panel;
187 main_panel_l->addWidget( simple_panel );
188 simple_panel->show();
191 void PrefsDialog::changePanel( QTreeWidgetItem *item )
193 PrefsItemData *data = item->data( 0, Qt::UserRole ).value<PrefsItemData*>();
197 main_panel_l->removeWidget( advanced_panel );
198 advanced_panel->hide();
201 data->panel = new PrefsPanel( p_intf, main_panel , data );
203 advanced_panel = data->panel;
204 main_panel_l->addWidget( advanced_panel );
205 advanced_panel->show();
208 void PrefsDialog::showModulePrefs( char *psz_module )
211 all->setChecked( true );
212 for( int i_cat_index = 0 ; i_cat_index < advanced_tree->topLevelItemCount();
215 QTreeWidgetItem *cat_item = advanced_tree->topLevelItem( i_cat_index );
216 PrefsItemData *data = cat_item->data( 0, Qt::UserRole ).
217 value<PrefsItemData *>();
218 for( int i_sc_index = 0; i_sc_index < cat_item->childCount();
221 QTreeWidgetItem *subcat_item = cat_item->child( i_sc_index );
222 PrefsItemData *sc_data = subcat_item->data(0, Qt::UserRole).
223 value<PrefsItemData *>();
224 for( int i_module = 0; i_module < subcat_item->childCount();
227 QTreeWidgetItem *module_item = subcat_item->child( i_module );
228 PrefsItemData *mod_data = module_item->data(0, Qt::UserRole).
229 value<PrefsItemData *>();
230 if( !strcmp( mod_data->psz_name, psz_module ) ) {
231 advanced_tree->setCurrentItem( module_item );
239 void PrefsDialog::save()
241 if( small->isChecked() && simple_tree )
243 for( int i = 0 ; i< SPrefsMax; i++ )
244 if( simple_panels[i] ) simple_panels[i]->apply();
246 else if( all->isChecked() && advanced_tree )
247 advanced_tree->applyAll();
248 config_SaveConfigFile( p_intf, NULL );
252 void PrefsDialog::cancel()
254 if( small->isChecked() && simple_tree )
256 for( int i = 0 ; i< SPrefsMax; i++ )
257 if( simple_panels[i] ) simple_panels[i]->clean();
259 else if( all->isChecked() && advanced_tree )
261 advanced_tree->cleanAll();
262 advanced_panel = NULL;