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 (register 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());
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
);
79 PreferencesDialog::readSettings() {
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()
97 limitSpin
->setValue( s
.value("limitSpin").toInt() );
98 timeoutBox
->setCheckState(
99 s
.value("timeoutBox").toBool()
102 timeoutSpin
->setValue( s
.value("timeoutSpin").toInt() );
103 socksBox
->setCheckState(
104 s
.value("socksBox").toBool()
108 qmFile
= s
.value("qmFile").toString();
114 PreferencesDialog::findQmFiles() {
118 dir
.entryList(QStringList("*.qm"), QDir::Files
, QDir::Name
);
120 QMutableStringListIterator
iter(fnames
);
121 while (iter
.hasNext()) {
123 iter
.setValue(dir
.filePath(iter
.value()));
129 PreferencesDialog::langName(const QString
& qmFile
) {
132 return transl
.translate("MainWindow","English");
139 PreferencesDialog::onProxyChanged(int index
) {
140 proxyEdit
->setEnabled(index
== 1);
144 PreferencesDialog::onLimitStateChanged(int state
) {
145 limitSpin
->setEnabled(state
!= 0);
149 PreferencesDialog::onBrowseSaveDir() {
150 QFileDialog
dlg(this);
152 dlg
.setFileMode(QFileDialog::Directory
);
153 dlg
.setViewMode(QFileDialog::Detail
);
154 dlg
.setDirectory(savedirEdit
->text());
157 savedirEdit
->setText(dlg
.selectedFiles()[0]);
161 PreferencesDialog::onBrowseStreamCommand() {
162 QString fname
= QFileDialog::getOpenFileName(this,tr("Choose command"));
163 if (!fname
.isEmpty())
164 streamEdit
->setText(fname
);
168 PreferencesDialog::onBrowseCommand() {
169 QString fname
= QFileDialog::getOpenFileName(this,tr("Choose command"));
170 if (!fname
.isEmpty())
171 commandEdit
->setText(fname
);
175 PreferencesDialog::onBrowseCclive() {
176 QString fname
= QFileDialog::getOpenFileName(this,tr("Choose cclive"));
177 if (!fname
.isEmpty())
178 ccliveEdit
->setText(fname
);
182 PreferencesDialog::onLangChanged(int index
) {
185 qmFile
= qmFiles
[index
-1];
187 QMessageBox::information(this, QCoreApplication::applicationName(),
188 tr("You need to restart the application for the language change "
193 PreferencesDialog::onTimeoutStateChanged(int state
) {
194 timeoutSpin
->setEnabled(state
!= 0);
195 socksBox
->setEnabled(state
!= 0);