Fix: rss/scan: check for url scheme; insert if missing.
[abby.git] / src / prefsdlg.cpp
blob00ec10d6e61ed89beca6cc7f1b48d4cc254ed8d8
1 /*
2 * abby Copyright (C) 2009 Toni Gundogdu.
3 * This file is part of abby.
5 * abby 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 3 of the License, or
8 * (at your option) any later version.
10 * abby 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, see <http://www.gnu.org/licenses/>.
18 #include <QDialog>
19 #include <QSettings>
20 #include <QFileDialog>
21 #include <QTranslator>
22 #include <QMessageBox>
24 #include "prefsdlg.h"
26 PreferencesDialog::PreferencesDialog(QWidget *parent)
27 : QDialog(parent)
29 setupUi(this);
30 readSettings();
32 langCombo->addItem("English");
34 int sel = 0;
35 qmFiles = findQmFiles();
36 for (register int i=0; i<qmFiles.size(); ++i) {
37 langCombo->addItem(langName(qmFiles[i]));
38 if (qmFile == qmFiles[i])
39 sel = i+1;
41 langCombo->setCurrentIndex(sel);
43 connect(langCombo, SIGNAL(currentIndexChanged(int)),
44 this, SLOT(onLangChanged(int)));
47 void
48 PreferencesDialog::onFinished(int) {
49 writeSettings();
52 void
53 PreferencesDialog::writeSettings() {
54 QSettings s;
56 s.beginGroup("PreferencesDialog");
58 s.setValue("size", size());
60 s.setValue("savedirEdit", savedirEdit->text());
61 s.setValue("streamEdit", streamEdit->text());
62 s.setValue("commandEdit", commandEdit->text());
63 s.setValue("ccliveEdit", ccliveEdit->text());
65 s.setValue("proxyCombo", proxyCombo->currentIndex());
66 s.setValue("proxyEdit", proxyEdit->text());
67 s.setValue("limitBox", limitBox->checkState());
68 s.setValue("limitSpin", limitSpin->value());
69 s.setValue("timeoutBox", timeoutBox->checkState());
70 s.setValue("timeoutSpin", timeoutSpin->value());
71 s.setValue("socksBox", socksBox->checkState());
73 s.setValue("qmFile", qmFile);
75 s.endGroup();
78 void
79 PreferencesDialog::readSettings() {
80 QSettings s;
82 s.beginGroup("PreferencesDialog");
84 resize( s.value("size", QSize(525,205)).toSize() );
86 savedirEdit->setText( s.value("savedirEdit").toString() );
87 streamEdit->setText( s.value("streamEdit").toString() );
88 commandEdit->setText( s.value("commandEdit").toString() );
89 ccliveEdit->setText( s.value("ccliveEdit").toString() );
91 proxyCombo->setCurrentIndex( s.value("proxyCombo").toInt() );
92 proxyEdit->setText( s.value("proxyEdit").toString() );
93 limitBox->setCheckState(
94 s.value("limitBox").toBool()
95 ? Qt::Checked
96 : Qt::Unchecked);
97 limitSpin->setValue( s.value("limitSpin").toInt() );
98 timeoutBox->setCheckState(
99 s.value("timeoutBox").toBool()
100 ? Qt::Checked
101 : Qt::Unchecked);
102 timeoutSpin->setValue( s.value("timeoutSpin").toInt() );
103 socksBox->setCheckState(
104 s.value("socksBox").toBool()
105 ? Qt::Checked
106 : Qt::Unchecked);
108 qmFile = s.value("qmFile").toString();
110 s.endGroup();
113 QStringList
114 PreferencesDialog::findQmFiles() {
115 QDir dir(":/i18n");
117 QStringList fnames =
118 dir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name);
120 QMutableStringListIterator iter(fnames);
121 while (iter.hasNext()) {
122 iter.next();
123 iter.setValue(dir.filePath(iter.value()));
125 return fnames;
128 QString
129 PreferencesDialog::langName(const QString& qmFile) {
130 QTranslator transl;
131 transl.load(qmFile);
132 return transl.translate("MainWindow","English");
136 // Slots
138 void
139 PreferencesDialog::onProxyChanged(int index) {
140 proxyEdit->setEnabled(index == 1);
143 void
144 PreferencesDialog::onLimitStateChanged(int state) {
145 limitSpin->setEnabled(state != 0);
148 void
149 PreferencesDialog::onBrowseSaveDir() {
150 QFileDialog dlg(this);
152 dlg.setFileMode(QFileDialog::Directory);
153 dlg.setViewMode(QFileDialog::Detail);
154 dlg.setDirectory(savedirEdit->text());
156 if (dlg.exec())
157 savedirEdit->setText(dlg.selectedFiles()[0]);
160 void
161 PreferencesDialog::onBrowseStreamCommand() {
162 QString fname = QFileDialog::getOpenFileName(this,tr("Choose command"));
163 if (!fname.isEmpty())
164 streamEdit->setText(fname);
167 void
168 PreferencesDialog::onBrowseCommand() {
169 QString fname = QFileDialog::getOpenFileName(this,tr("Choose command"));
170 if (!fname.isEmpty())
171 commandEdit->setText(fname);
174 void
175 PreferencesDialog::onBrowseCclive() {
176 QString fname = QFileDialog::getOpenFileName(this,tr("Choose cclive"));
177 if (!fname.isEmpty())
178 ccliveEdit->setText(fname);
181 void
182 PreferencesDialog::onLangChanged(int index) {
183 qmFile = "";
184 if (index > 0)
185 qmFile = qmFiles[index-1];
187 QMessageBox::information(this, QCoreApplication::applicationName(),
188 tr("You need to restart the application for the language change "
189 "to take effect."));
192 void
193 PreferencesDialog::onTimeoutStateChanged(int state) {
194 timeoutSpin->setEnabled(state != 0);
195 socksBox->setEnabled(state != 0);