1 /***************************************************************************
2 * Copyright (C) 2005-09 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "settingspagedlg.h"
23 #include "iconloader.h"
25 SettingsPageDlg::SettingsPageDlg(SettingsPage *page, QWidget *parent)
30 page->setParent(this);
32 // make it look more native under Mac OS X:
33 setWindowFlags(Qt::Sheet);
35 ui.pageTitle->setText(page->title());
36 setWindowTitle(tr("Configure %1").arg(page->title()));
37 setWindowIcon(SmallIcon("configure"));
39 // make the scrollarea behave sanely
40 ui.settingsFrame->setWidgetResizable(true);
41 ui.settingsFrame->setWidget(page);
45 connect(page, SIGNAL(changed(bool)), this, SLOT(setButtonStates()));
46 connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *)));
51 SettingsPage *SettingsPageDlg::currentPage() const {
55 void SettingsPageDlg::setButtonStates() {
56 SettingsPage *sp = currentPage();
57 ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(sp && sp->hasChanged());
58 ui.buttonBox->button(QDialogButtonBox::Reset)->setEnabled(sp && sp->hasChanged());
59 ui.buttonBox->button(QDialogButtonBox::RestoreDefaults)->setEnabled(sp && sp->hasDefaults());
62 void SettingsPageDlg::buttonClicked(QAbstractButton *button) {
63 switch(ui.buttonBox->standardButton(button)) {
64 case QDialogButtonBox::Ok:
65 if(currentPage() && currentPage()->hasChanged()) {
66 if(applyChanges()) accept();
69 case QDialogButtonBox::Apply:
72 case QDialogButtonBox::Cancel:
76 case QDialogButtonBox::Reset:
79 case QDialogButtonBox::RestoreDefaults:
87 bool SettingsPageDlg::applyChanges() {
88 if(!currentPage()) return false;
89 if(currentPage()->aboutToSave()) {
90 currentPage()->save();
96 void SettingsPageDlg::undoChanges() {
98 currentPage()->load();
102 void SettingsPageDlg::reload() {
103 if(!currentPage()) return;
104 int ret = QMessageBox::question(this, tr("Reload Settings"), tr("Do you like to reload the settings, undoing your changes on this page?"),
105 QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
106 if(ret == QMessageBox::Yes) {
107 currentPage()->load();
111 void SettingsPageDlg::loadDefaults() {
112 if(!currentPage()) return;
113 int ret = QMessageBox::question(this, tr("Restore Defaults"), tr("Do you like to restore the default values for this page?"),
114 QMessageBox::RestoreDefaults|QMessageBox::Cancel, QMessageBox::Cancel);
115 if(ret == QMessageBox::Yes) {
116 currentPage()->defaults();