1 /***************************************************************************
2 * Copyright (C) 2005-2012 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 <QMessageBox>
22 #include <QPushButton>
24 #include "settingspagedlg.h"
26 #include "iconloader.h"
28 SettingsPageDlg::SettingsPageDlg(SettingsPage *page, QWidget *parent)
33 page->setParent(this);
35 // make it look more native under Mac OS X:
36 setWindowFlags(Qt::Sheet);
38 ui.pageTitle->setText(page->title());
39 setWindowTitle(tr("Configure %1").arg(page->title()));
40 setWindowIcon(SmallIcon("configure"));
42 // make the scrollarea behave sanely
43 ui.settingsFrame->setWidgetResizable(true);
44 ui.settingsFrame->setWidget(page);
48 connect(page, SIGNAL(changed(bool)), this, SLOT(setButtonStates()));
49 connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *)));
54 SettingsPage *SettingsPageDlg::currentPage() const {
58 void SettingsPageDlg::setButtonStates() {
59 SettingsPage *sp = currentPage();
60 ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(sp && sp->hasChanged());
61 ui.buttonBox->button(QDialogButtonBox::Reset)->setEnabled(sp && sp->hasChanged());
62 ui.buttonBox->button(QDialogButtonBox::RestoreDefaults)->setEnabled(sp && sp->hasDefaults());
65 void SettingsPageDlg::buttonClicked(QAbstractButton *button) {
66 switch(ui.buttonBox->standardButton(button)) {
67 case QDialogButtonBox::Ok:
68 if(currentPage() && currentPage()->hasChanged()) {
69 if(applyChanges()) accept();
72 case QDialogButtonBox::Apply:
75 case QDialogButtonBox::Cancel:
79 case QDialogButtonBox::Reset:
82 case QDialogButtonBox::RestoreDefaults:
90 bool SettingsPageDlg::applyChanges() {
91 if(!currentPage()) return false;
92 if(currentPage()->aboutToSave()) {
93 currentPage()->save();
99 void SettingsPageDlg::undoChanges() {
101 currentPage()->load();
105 void SettingsPageDlg::reload() {
106 if(!currentPage()) return;
107 int ret = QMessageBox::question(this, tr("Reload Settings"), tr("Do you like to reload the settings, undoing your changes on this page?"),
108 QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
109 if(ret == QMessageBox::Yes) {
110 currentPage()->load();
114 void SettingsPageDlg::loadDefaults() {
115 if(!currentPage()) return;
116 int ret = QMessageBox::question(this, tr("Restore Defaults"), tr("Do you like to restore the default values for this page?"),
117 QMessageBox::RestoreDefaults|QMessageBox::Cancel, QMessageBox::Cancel);
118 if(ret == QMessageBox::RestoreDefaults) {
119 currentPage()->defaults();