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/>.
20 #include <QFileDialog>
21 #include <QTranslator>
22 #include <QMessageBox>
26 PreferencesDialog::PreferencesDialog(QWidget
*parent
)
32 langCombo
->addItem("English");
35 qmFiles
= findQmFiles();
36 for (int i
=0; i
<qmFiles
.size(); ++i
) {
37 langCombo
->addItem(langName(qmFiles
[i
]));
38 if (qmFile
== qmFiles
[i
])
41 langCombo
->setCurrentIndex(sel
);
43 connect(langCombo
, SIGNAL(currentIndexChanged(int)),
44 this, SLOT(onLangChanged(int)));
48 PreferencesDialog::onFinished(int) {
53 PreferencesDialog::writeSettings() {
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
);
81 PreferencesDialog::readSettings() {
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()
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();
112 PreferencesDialog::findQmFiles() {
116 dir
.entryList(QStringList("*.qm"), QDir::Files
, QDir::Name
);
118 QMutableStringListIterator
iter(fnames
);
119 while (iter
.hasNext()) {
121 iter
.setValue(dir
.filePath(iter
.value()));
127 PreferencesDialog::langName(const QString
&qmFile
) {
130 return transl
.translate("MainWindow","English");
137 PreferencesDialog::onProxyChanged(int index
) {
138 proxyEdit
->setEnabled(index
== 1);
142 PreferencesDialog::onLimitStateChanged(int state
) {
143 limitSpin
->setEnabled(state
!= 0);
147 PreferencesDialog::onBrowseSaveDir() {
148 QFileDialog
dlg(this);
150 dlg
.setFileMode(QFileDialog::Directory
);
151 dlg
.setViewMode(QFileDialog::Detail
);
152 dlg
.setDirectory(savedirEdit
->text());
155 savedirEdit
->setText(dlg
.selectedFiles()[0]);
159 PreferencesDialog::onBrowseCommand() {
160 QString fname
= QFileDialog::getOpenFileName(this,tr("Choose command"));
161 if (!fname
.isEmpty())
162 commandEdit
->setText(fname
);
166 PreferencesDialog::onBrowseCclive() {
167 QString fname
= QFileDialog::getOpenFileName(this,tr("Choose cclive"));
168 if (!fname
.isEmpty())
169 ccliveEdit
->setText(fname
);
173 PreferencesDialog::onLangChanged(int index
) {
176 qmFile
= qmFiles
[index
-1];
178 QMessageBox::information(this, QCoreApplication::applicationName(),
179 tr("You need to restart the application for the language change "