Initial commit.
[abby.git] / src / prefsdlg.cpp
blob3a72d38924f6dca3d862e1dfc3475a75aaaa3b8f
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 (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());
59 s.setValue("pos",pos());
61 s.setValue("savedirEdit",savedirEdit->text());
62 s.setValue("commandEdit",commandEdit->text());
63 s.setValue("ccliveEdit",ccliveEdit->text());
64 s.setValue("additionalEdit",additionalEdit->text());
66 s.setValue("proxyCombo",proxyCombo->currentIndex());
67 s.setValue("proxyEdit",proxyEdit->text());
68 s.setValue("limitBox",limitBox->checkState());
69 s.setValue("limitSpin",limitSpin->value());
71 s.setValue("youtubeGroup",youtubeGroup->isChecked());
72 s.setValue("ytuserEdit",ytuserEdit->text());
73 s.setValue("ytpassEdit",ytpassEdit->text());
75 s.setValue("qmFile",qmFile);
77 s.endGroup();
80 void
81 PreferencesDialog::readSettings() {
82 QSettings s;
84 s.beginGroup("PreferencesDialog");
86 resize(s.value("size",QSize(400,400)).toSize());
87 move(s.value("pos",QPoint(200,200)).toPoint());
89 savedirEdit->setText(s.value("savedirEdit").toString());
90 commandEdit->setText(s.value("commandEdit").toString());
91 ccliveEdit->setText(s.value("ccliveEdit").toString());
92 additionalEdit->setText(s.value("additionalEdit").toString());
94 proxyCombo->setCurrentIndex(s.value("proxyCombo").toInt());
95 proxyEdit->setText(s.value("proxyEdit").toString());
96 limitBox->setCheckState(
97 s.value("limitBox").toBool()
98 ? Qt::Checked
99 : Qt::Unchecked);
100 limitSpin->setValue(s.value("limitSpin").toInt());
102 youtubeGroup->setChecked(s.value("youtubeGroup").toBool());
103 ytuserEdit->setText(s.value("ytuserEdit").toString());
104 ytpassEdit->setText(s.value("ytpassEdit").toString());
106 qmFile = s.value("qmFile").toString();
108 s.endGroup();
111 QStringList
112 PreferencesDialog::findQmFiles() {
113 QDir dir(":/i18n");
115 QStringList fnames =
116 dir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name);
118 QMutableStringListIterator iter(fnames);
119 while (iter.hasNext()) {
120 iter.next();
121 iter.setValue(dir.filePath(iter.value()));
123 return fnames;
126 QString
127 PreferencesDialog::langName(const QString &qmFile) {
128 QTranslator transl;
129 transl.load(qmFile);
130 return transl.translate("MainWindow","English");
134 // Slots
136 void
137 PreferencesDialog::onProxyChanged(int index) {
138 proxyEdit->setEnabled(index == 1);
141 void
142 PreferencesDialog::onLimitStateChanged(int state) {
143 limitSpin->setEnabled(state != 0);
146 void
147 PreferencesDialog::onBrowseSaveDir() {
148 QFileDialog dlg(this);
150 dlg.setFileMode(QFileDialog::Directory);
151 dlg.setViewMode(QFileDialog::Detail);
152 dlg.setDirectory(savedirEdit->text());
154 if (dlg.exec())
155 savedirEdit->setText(dlg.selectedFiles()[0]);
158 void
159 PreferencesDialog::onBrowseCommand() {
160 QString fname = QFileDialog::getOpenFileName(this,tr("Choose command"));
161 if (!fname.isEmpty())
162 commandEdit->setText(fname);
165 void
166 PreferencesDialog::onBrowseCclive() {
167 QString fname = QFileDialog::getOpenFileName(this,tr("Choose cclive"));
168 if (!fname.isEmpty())
169 ccliveEdit->setText(fname);
172 void
173 PreferencesDialog::onLangChanged(int index) {
174 qmFile = "";
175 if (index > 0)
176 qmFile = qmFiles[index-1];
178 QMessageBox::information(this, QCoreApplication::applicationName(),
179 tr("You need to restart the application for the language change "
180 "to take effect."));