Update Finnish translation
[nomnom.git] / src / settings / nsettingsdialog.cpp
blob966f683d53e7fceebbe431b4bfb7d9a3a7e491a3
1 /* NomNom
2 * Copyright (C) 2011 Toni Gundogdu <legatvs@gmail.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "config.h"
20 #include <QCoreApplication>
21 #include <QDialogButtonBox>
22 #include <QMessageBox>
23 #include <QVBoxLayout>
24 #include <QToolBox>
26 #include <NSettingsMutator>
27 #include <NSettingsDialog>
28 #include <NUtil>
30 extern nn::NSettingsMutator settings; // main.cpp
32 namespace nn
35 NSettingsDialog::NSettingsDialog(QWidget *parent/*=NULL*/)
36 : QDialog(parent)
39 // Toolbox
41 toolbox = new QToolBox;
42 toolbox->addItem(new NSettingsOptions, tr("Op&tions"));
43 toolbox->addItem(new NSettingsCommands, tr("Co&mmands"));
44 toolbox->addItem(new NSettingsDownload, tr("&Download"));
45 #ifdef _1
46 toolbox->addItem(new NSettingsProxy, tr("&Proxy"));
47 #endif
49 // Button box
51 QDialogButtonBox *btnBox = new QDialogButtonBox(
52 QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
54 connect(btnBox, SIGNAL(accepted()), this, SLOT(accept()));
55 connect(btnBox, SIGNAL(rejected()), this, SLOT(reject()));
57 // Layout
59 QVBoxLayout *box = new QVBoxLayout;
60 box->addWidget(toolbox);
61 box->addWidget(btnBox);
62 setLayout(box);
64 // Window
66 setWindowTitle(tr("Settings"));
67 setMinimumSize(QSize(540,450));
68 setSizeGripEnabled(true);
69 fromConfig();
72 void NSettingsDialog::done(int n)
74 if (n == QDialog::Accepted)
76 if (!toConfig())
77 return;
79 QDialog::done(n);
80 close();
83 bool NSettingsDialog::foreachWidget(Mode mode)
85 const int c = toolbox->count();
86 for (int i=0; i<c; ++i)
88 QWidget *w = toolbox->widget(i);
90 NSettingsWidget *s = dynamic_cast<NSettingsWidget*>(w);
92 QString msg;
93 if (mode == To && !s->verify(msg))
95 toolbox->setCurrentWidget(s);
96 info(this, msg);
97 return false;
100 if (mode == From)
102 s->read();
103 s->init();
105 else
107 s->write();
110 return true;
113 void NSettingsDialog::fromConfig()
115 foreachWidget(From);
118 bool NSettingsDialog::toConfig()
120 const bool r = foreachWidget(To);
121 if (r)
122 settings.write();
123 return r;
126 NSettingsWidget::NSettingsWidget(QWidget *parent/*=NULL*/)
127 : QWidget(parent)
131 NSettingsTabWidget::NSettingsTabWidget(QWidget *parent/*=NULL*/)
132 : QWidget(parent)
136 } // namespace nn
138 /* vim: set ts=2 sw=2 tw=72 expandtab: */