Update Finnish translation
[nomnom.git] / src / settings / nsettingsdialog_options_appearance.cpp
blobb58e4da870f05e507c24cca5fb12c2fef162bd49
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 <QImageReader>
22 #include <QVBoxLayout>
23 #include <QHBoxLayout>
24 #include <QGridLayout>
25 #include <QFileDialog>
26 #include <QPushButton>
27 #include <QGroupBox>
28 #include <QComboBox>
29 #include <QLabel>
31 #include <NSettingsMutator>
32 #include <NSettingsDialog>
33 #include <NTripwireEdit>
34 #include <NLang>
36 extern nn::NSettingsMutator settings; // main.cpp
38 namespace nn
41 NSettingsAppearance::NSettingsAppearance(QWidget *parent/*=NULL*/)
42 : NSettingsTabWidget(parent)
45 #ifdef _1
46 // Icons
48 QGridLayout *iconsBox = new QGridLayout;
49 addGridRow(iconsBox, tr("Application:"), &appEdit, SLOT(browseApp()));
50 addGridRow(iconsBox, tr("Busy:"), &busyEdit, SLOT(browseBusy()));
51 addGridRow(iconsBox, tr("Error:"), &errorEdit, SLOT(browseError()));
53 QGroupBox *gIcons = new QGroupBox(tr("Icons"));
54 gIcons->setLayout(iconsBox);
55 #endif // _1
57 // Language
59 langCombo = new QComboBox;
60 langCombo->addItem("English");
62 foreach (const lang::NResultPair p, lang::qm_files())
64 langCombo->addItem(p.first);
67 QHBoxLayout *langBox = new QHBoxLayout;
68 langBox->addWidget(langCombo);
69 langBox->addStretch(0);
71 QGroupBox *gLang = new QGroupBox(tr("Language"));
72 gLang->setLayout(langBox);
74 // Layout
76 QVBoxLayout *box = new QVBoxLayout;
77 #ifdef _1
78 box->addWidget(gIcons);
79 #endif
80 box->addWidget(gLang);
81 box->addStretch(0);
82 setLayout(box);
85 void NSettingsAppearance::addGridRow(QGridLayout *g,
86 const QString& text,
87 NTripwireEdit **e,
88 const char *slot)
90 QLabel *l = new QLabel(text);
91 *e = new NTripwireEdit;
92 l->setBuddy(*e);
94 (*e)->setReadOnly(true);
95 (*e)->setToolTip(tr("Leave empty for application default"));
97 connect(*e, SIGNAL(entered()), this, slot);
99 QPushButton *b = new QPushButton;
100 b->setIcon(QIcon(":/images/edit-clear.png"));
101 b->setToolTip(tr("Clear"));
103 connect(b, SIGNAL(clicked()), *e, SLOT(clear()));
105 const int row = g->rowCount() + 1;
107 g->addWidget(l, row, 0);
108 g->addWidget(*e, row, 1);
109 g->addWidget(b, row, 2);
112 void NSettingsAppearance::init()
116 void NSettingsAppearance::read()
118 #ifdef _1
119 appEdit->setText(settings.value(CustomApplicationIcon).toString());
120 busyEdit->setText(settings.value(CustomBusyIcon).toString());
121 errorEdit->setText(settings.value(CustomErrorIcon).toString());
122 #endif
123 const int n = langCombo->findText(settings.value(Language).toString());
124 if (n != -1)
125 langCombo->setCurrentIndex(n);
128 void NSettingsAppearance::write()
130 #ifdef _1
131 settings.setValue(CustomApplicationIcon, appEdit->text());
132 settings.setValue(CustomBusyIcon, busyEdit->text());
133 settings.setValue(CustomErrorIcon, errorEdit->text());
134 #endif
135 settings.setValue(Language, langCombo->currentText());
138 bool NSettingsAppearance::verify(QString&)
140 return true;
143 static QString construct_filter()
145 QString filter =
146 qApp->translate("nn::NSettingsAppearance","Images") + " (";
148 foreach(QByteArray b, QImageReader::supportedImageFormats())
150 filter += "*." +b+ " ";
153 filter = filter.simplified();
154 filter += ")";
156 return filter;
159 static bool browse(QWidget *parent, QString& fname)
161 fname = QFileDialog::getOpenFileName(
162 parent,
163 qApp->translate("nn::NSettingsAppearance", "Open image"),
164 QDir::homePath(),
165 construct_filter());
166 return ! fname.isEmpty();
169 #ifdef _1
170 void NSettingsAppearance::browseApp()
172 QString fname;
173 if (browse(this, fname))
174 appEdit->setText(fname);
177 void NSettingsAppearance::browseBusy()
179 QString fname;
180 if (browse(this, fname))
181 busyEdit->setText(fname);
184 void NSettingsAppearance::browseError()
186 QString fname;
187 if (browse(this, fname))
188 errorEdit->setText(fname);
190 #endif // _1
192 } // namespace nn
194 /* vim: set ts=2 sw=2 tw=72 expandtab: */