Bugs fixed
[qstardict] / plugins / stardict / settingsdialog.cpp
1 /*****************************************************************************
2  * settingsdialog.cpp - QStarDict, a StarDict clone written with using Qt    *
3  * Copyright (C) 2008 Alexander Rodin                                        *
4  *                                                                           *
5  * This program 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 2 of the License, or         *
8  * (at your option) any later version.                                       *
9  *                                                                           *
10  * This program 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.                              *
14  *                                                                           *
15  * You should have received a copy of the GNU General Public License along   *
16  * with this program; if not, write to the Free Software Foundation, Inc.,   *
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.               *
18  *****************************************************************************/
19
20 #include "settingsdialog.h"
21
22 #include <QFileDialog>
23 #include "stardict.h"
24
25 SettingsDialog::SettingsDialog(StarDict *plugin, QWidget *parent)
26     : QDialog(parent),
27       m_plugin(plugin)
28 {
29     setupUi(this);
30
31     //reformatListsBox->setChecked(m_plugin->m_reformatLists);
32     expandAbbreviationsBox->setChecked(m_plugin->m_expandAbbreviations);
33     dictDirsList->addItems(m_plugin->m_dictDirs);
34     dictDirsList->setProperty("FingerScrollable", true);
35
36     connect(this, SIGNAL(accepted()), SLOT(apply()));
37 }
38
39 void SettingsDialog::on_addDictDirButton_clicked()
40 {
41     QString dirName = QFileDialog::getExistingDirectory(this, tr("Select dictionaries directory"));
42     if (! dirName.isEmpty())
43     {
44         dictDirsList->addItem(dirName);
45     }
46 }
47
48 void SettingsDialog::on_removeDictDirButton_clicked()
49 {
50     delete dictDirsList->takeItem(dictDirsList->currentRow());
51 }
52
53 void SettingsDialog::on_moveUpDictDirButton_clicked()
54 {
55     if (dictDirsList->currentRow() > 0)
56     {
57         dictDirsList->insertItem(dictDirsList->currentRow(),
58                                  dictDirsList->takeItem(dictDirsList->currentRow()));
59         dictDirsList->setCurrentRow(dictDirsList->currentRow() - 1);
60     }
61 }
62
63 void SettingsDialog::on_moveDownDictDirButton_clicked()
64 {
65     if (dictDirsList->currentRow() < dictDirsList->count() - 1)
66     dictDirsList->insertItem(dictDirsList->currentRow(),
67                              dictDirsList->takeItem(dictDirsList->currentRow() + 1));
68 }
69
70 void SettingsDialog::apply()
71 {
72     m_plugin->m_reformatLists = reformatListsBox->isChecked();
73     m_plugin->m_expandAbbreviations = expandAbbreviationsBox->isChecked();
74     m_plugin->m_dictDirs.clear();
75     for (int i = 0; i < dictDirsList->count(); ++i)
76         m_plugin->m_dictDirs << dictDirsList->item(i)->text();
77 }
78
79 void SettingsDialog::closeEvent(QCloseEvent *event)
80 {
81     SettingsDialog::apply();
82 }
83
84 // vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent textwidth=120 formatoptions=tc
85