summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/QtSpellCheckerWindow.cpp')
-rw-r--r--Swift/QtUI/QtSpellCheckerWindow.cpp129
1 files changed, 56 insertions, 73 deletions
diff --git a/Swift/QtUI/QtSpellCheckerWindow.cpp b/Swift/QtUI/QtSpellCheckerWindow.cpp
index db2b1e7..a8178c4 100644
--- a/Swift/QtUI/QtSpellCheckerWindow.cpp
+++ b/Swift/QtUI/QtSpellCheckerWindow.cpp
@@ -4,112 +4,95 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
-#include "Swift/QtUI/QtSpellCheckerWindow.h"
+/*
+ * Copyright (c) 2016 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
-#include <Swift/Controllers/Settings/SettingsProvider.h>
-#include <Swift/Controllers/SettingConstants.h>
-#include <Swift/QtUI/QtUISettingConstants.h>
-#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/QtSpellCheckerWindow.h>
#include <QCoreApplication>
-#include <QFileDialog>
#include <QDir>
+#include <QFileDialog>
#include <QStringList>
#include <QTimer>
+#include <Swiften/Base/Log.h>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/QtUISettingConstants.h>
+
namespace Swift {
QtSpellCheckerWindow::QtSpellCheckerWindow(SettingsProvider* settings, QWidget* parent) : QDialog(parent) {
- settings_ = settings;
- ui_.setupUi(this);
+ settings_ = settings;
+ ui_.setupUi(this);
#ifdef HAVE_HUNSPELL
- ui_.hunspellOptions->show();
+ ui_.hunspellOptions->show();
#else
- ui_.hunspellOptions->hide();
- QTimer::singleShot(0, this, SLOT(shrinkWindow()));
+ ui_.hunspellOptions->hide();
+ QTimer::singleShot(0, this, SLOT(shrinkWindow()));
#endif
- connect(ui_.spellChecker, SIGNAL(toggled(bool)), this, SLOT(handleChecker(bool)));
- connect(ui_.cancel, SIGNAL(clicked()), this, SLOT(handleCancel()));
- connect(ui_.apply, SIGNAL(clicked()), this, SLOT(handleApply()));
- connect(ui_.pathButton, SIGNAL(clicked()), this, SLOT(handlePathButton()));
- setFromSettings();
+ connect(ui_.spellChecker, SIGNAL(toggled(bool)), this, SLOT(handleChecker(bool)));
+ connect(ui_.cancel, SIGNAL(clicked()), this, SLOT(handleCancel()));
+ connect(ui_.apply, SIGNAL(clicked()), this, SLOT(handleApply()));
+ setFromSettings();
}
void QtSpellCheckerWindow::shrinkWindow() {
- resize(0,0);
+ resize(0,0);
}
void QtSpellCheckerWindow::setFromSettings() {
- ui_.spellChecker->setChecked(settings_->getSetting(SettingConstants::SPELL_CHECKER));
- ui_.pathContent->setText(P2QSTRING(settings_->getSetting(SettingConstants::DICT_PATH)));
- ui_.currentLanguageValue->setText(P2QSTRING(settings_->getSetting(SettingConstants::DICT_FILE)));
- std::string currentPath = settings_->getSetting(SettingConstants::DICT_PATH);
- QString filename = "*.dic";
- QDir dictDirectory = QDir(P2QSTRING(currentPath));
- QStringList files = dictDirectory.entryList(QStringList(filename), QDir::Files);
- showFiles(files);
- setEnabled(settings_->getSetting(SettingConstants::SPELL_CHECKER));
+ ui_.spellChecker->setChecked(settings_->getSetting(QtUISettingConstants::SPELL_CHECKER));
+ setEnabled(settings_->getSetting(QtUISettingConstants::SPELL_CHECKER));
}
-void QtSpellCheckerWindow::handleChecker(bool state) {
- setEnabled(state);
+void QtSpellCheckerWindow::setSupportedLanguages(const std::vector<std::string>& languages) {
+ languageItems_.clear();
+ ui_.languageView->clear();
+ for (const auto& shortLang : languages) {
+ auto locale = QLocale(P2QSTRING(shortLang));
+ auto label = QString("%1 ( %2 )").arg(locale.nativeLanguageName(), locale.nativeCountryName());
+
+ QListWidgetItem* item = new QListWidgetItem(label);
+ item->setData(Qt::UserRole, P2QSTRING(shortLang));
+ languageItems_[shortLang] = item;
+ ui_.languageView->addItem(item);
+ }
}
-void QtSpellCheckerWindow::setEnabled(bool state) {
- ui_.pathContent->setEnabled(state);
- ui_.languageView->setEnabled(state);
- ui_.pathButton->setEnabled(state);
- ui_.pathLabel->setEnabled(state);
- ui_.currentLanguage->setEnabled(state);
- ui_.currentLanguageValue->setEnabled(state);
- ui_.language->setEnabled(state);
+void QtSpellCheckerWindow::setActiveLanguage(const std::string& language) {
+ SWIFT_LOG_ASSERT(languageItems_.find(language) != languageItems_.end(), warning) << "Language '" << language << "' is not available." << std::endl;
+ if (languageItems_.find(language) != languageItems_.end()) {
+ languageItems_[language]->setSelected(true);
+ }
}
-void QtSpellCheckerWindow::handleApply() {
- settings_->storeSetting(SettingConstants::SPELL_CHECKER, ui_.spellChecker->isChecked());
- QList<QListWidgetItem* > selectedLanguage = ui_.languageView->selectedItems();
- if (!selectedLanguage.empty()) {
- settings_->storeSetting(SettingConstants::DICT_FILE, Q2PSTRING((selectedLanguage.first())->text()));
- }
- this->done(0);
+void QtSpellCheckerWindow::setAutomaticallyIdentifiesLanguage(bool isAutomaticallyIdentifying) {
+ ui_.languageView->setHidden(isAutomaticallyIdentifying);
}
-void QtSpellCheckerWindow::handleCancel() {
- this->done(0);
+void QtSpellCheckerWindow::handleChecker(bool state) {
+ setEnabled(state);
}
-void QtSpellCheckerWindow::handlePathButton() {
- std::string currentPath = settings_->getSetting(SettingConstants::DICT_PATH);
- QString dirpath = QFileDialog::getExistingDirectory(this, tr("Dictionary Path"), P2QSTRING(currentPath));
- if (dirpath != P2QSTRING(currentPath)) {
- ui_.languageView->clear();
- settings_->storeSetting(SettingConstants::DICT_FILE, "");
- ui_.currentLanguageValue->setText(" ");
- }
- if (!dirpath.isEmpty()) {
- if (!dirpath.endsWith("/")) {
- dirpath.append("/");
- }
- settings_->storeSetting(SettingConstants::DICT_PATH, Q2PSTRING(dirpath));
- QDir dictDirectory = QDir(dirpath);
- ui_.pathContent->setText(dirpath);
- QString filename = "*.dic";
- QStringList files = dictDirectory.entryList(QStringList(filename), QDir::Files);
- showFiles(files);
- }
+void QtSpellCheckerWindow::setEnabled(bool state) {
+ ui_.language->setEnabled(state);
}
-void QtSpellCheckerWindow::handlePersonalPathButton() {
- std::string currentPath = settings_->getSetting(SettingConstants::PERSONAL_DICT_PATH);
- QString filename = QFileDialog::getOpenFileName(this, tr("Select Personal Dictionary"), P2QSTRING(currentPath), tr("(*.dic"));
- settings_->storeSetting(SettingConstants::PERSONAL_DICT_PATH, Q2PSTRING(filename));
+void QtSpellCheckerWindow::handleApply() {
+ settings_->storeSetting(QtUISettingConstants::SPELL_CHECKER, ui_.spellChecker->isChecked());
+ QList<QListWidgetItem* > selectedLanguage = ui_.languageView->selectedItems();
+ if (!selectedLanguage.empty()) {
+ settings_->storeSetting(QtUISettingConstants::SPELL_CHECKER_LANGUAGE, Q2PSTRING(selectedLanguage.first()->data(Qt::UserRole).toString()));
+ }
+ this->done(0);
}
-void QtSpellCheckerWindow::showFiles(const QStringList& files) {
- ui_.languageView->clear();
- for (int i = 0; i < files.size(); ++i) {
- ui_.languageView->insertItem(i, files[i]);
- }
+void QtSpellCheckerWindow::handleCancel() {
+ this->done(0);
}
}