diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -100,6 +100,8 @@ settings/languagepropertiespage.cpp settings/kgametheme/kgametheme.cpp settings/kgametheme/kgamethemeselector.cpp + settings/webdictoptions.cpp + settings/dictionaryeditor.cpp statistics/conjugationoptions.cpp statistics/lessonstatisticsview.cpp statistics/statisticsmodel.cpp @@ -140,6 +142,8 @@ settings/generaloptionsbase.ui settings/languagepropertiespage.ui settings/documentproperties.ui + settings/webdictoptions.ui + settings/dictionaryeditor.ui settings/kgametheme/kgamethemeselector.ui statistics/statisticsmainwindow.ui dashboard/dashboard.ui diff --git a/src/editor/browserwidget.h b/src/editor/browserwidget.h --- a/src/editor/browserwidget.h +++ b/src/editor/browserwidget.h @@ -47,16 +47,18 @@ */ void setTranslation(KEduVocExpression* entry, int translation); + /** + * Load a list of providers of online dictionaries + */ + void setupProviders(); private slots: void showCurrentTranslation(); void openUrl(const QUrl& targetUrl); void providerChanged(int); + private: - /** - * Load a list of providers of online dictionaries - */ - void setupProviders(); + /// Column in the document - corresponds to the language (-KV_COL_TRANS) int m_currentTranslation; diff --git a/src/editor/browserwidget.cpp b/src/editor/browserwidget.cpp --- a/src/editor/browserwidget.cpp +++ b/src/editor/browserwidget.cpp @@ -17,7 +17,7 @@ #include #include - +#include "../settings/webdictoptions.h" #include using namespace Editor; @@ -35,7 +35,6 @@ layout->addWidget(m_htmlPart); connect(showCurrentButton, &QPushButton::clicked, this, &BrowserWidget::showCurrentTranslation); - setupProviders(); connect(providerComboBox, static_cast(&KComboBox::currentIndexChanged), this, &BrowserWidget::providerChanged); @@ -43,63 +42,20 @@ void BrowserWidget::setupProviders() { - providerComboBox->clear(); - DictionaryProvider provider; - provider.name = "De-Es Beolingus"; - provider.url = "http://beolingus.org/dings.cgi?service=dees&query=\\{@}"; - provider.languages << "de" << "es"; - m_providers.append(provider); - providerComboBox->addItem(provider.name); - - provider.name = "De-En Beolingus"; - provider.url = "http://beolingus.org/dings.cgi?query=\\{@}"; - provider.languages << "de" << "en"; - m_providers.append(provider); - providerComboBox->addItem(provider.name); - - provider.name = "De-En Leo"; - provider.url = "http://dict.leo.org/?search=\\{@}"; - provider.languages << "de" << "en"; - m_providers.append(provider); - providerComboBox->addItem(provider.name); - - provider.name = "De-Es Leo"; - provider.url = "http://dict.leo.org/?lp=esde&search=\\{@}"; - provider.languages << "de" << "es"; - m_providers.append(provider); - providerComboBox->addItem(provider.name); - - provider.name = "De-Fr Leo"; - provider.url = "http://dict.leo.org/?lp=frde&search=\\{@}"; - provider.languages << "de" << "fr"; - m_providers.append(provider); - providerComboBox->addItem(provider.name); - - provider.name = "Ru-En Multitran"; - provider.url = "http://multitran.ru/c/m.exe?SHL=1&CL=1&l1=1&s=\\{@}"; - provider.languages << "ru" << "en"; - m_providers.append(provider); - providerComboBox->addItem(provider.name); - - provider.name = "Ru-De Multitran"; - provider.url = "http://multitran.ru/c/m.exe?SHL=1&CL=1&l1=3&s=\\{@}"; - provider.languages << "ru" << "de"; - m_providers.append(provider); - providerComboBox->addItem(provider.name); - - provider.name = "Ru-Fr Multitran"; - provider.url = "http://multitran.ru/c/m.exe?SHL=1&CL=1&l1=4&s=\\{@}"; - provider.languages << "ru" << "fr"; - m_providers.append(provider); - providerComboBox->addItem(provider.name); - - provider.name = "Heinzelnisse"; - provider.url = "http://heinzelnisse.info/dict?setOptions=true&searchItem=\\{@}&dictDeNoSearch=on&dictNoDeSearch=on&dictExactSearch=on&dictPhoneticSearch=on&wikiSearch=on&dictNynorskSearch=on&dictBokmaalSearch=checked&forumKeywordSearch=on&suggestion=on"; - provider.languages << "no" << "de"; - m_providers.append(provider); - providerComboBox->addItem(provider.name); + WebDictOptions dictionaryOptions; + const QList cfgDics = dictionaryOptions.dictionariesObjList(); + QList::const_iterator itr; + providerComboBox->clear(); + m_providers.clear(); + for (itr = cfgDics.constBegin(); itr != cfgDics.constEnd(); ++itr) { + provider.name = (*itr)["name"].toString(); + provider.url = (*itr)["url"].toString(); + provider.languages << (*itr)["source"].toString() << (*itr)["target"].toString(); + m_providers.append(provider); + providerComboBox->addItem(provider.name); + } } void BrowserWidget::setTranslation(KEduVocExpression* entry, int translation) diff --git a/src/editor/editor.h b/src/editor/editor.h --- a/src/editor/editor.h +++ b/src/editor/editor.h @@ -119,6 +119,11 @@ signals: void signalSetData(const QList& entries, int currentTranslation); + /** + * To trigger update of dictionary list when preferences change + */ + void updateBrowserDock(); + private: ParleyMainWindow *m_mainWindow; diff --git a/src/editor/editor.cpp b/src/editor/editor.cpp --- a/src/editor/editor.cpp +++ b/src/editor/editor.cpp @@ -364,6 +364,7 @@ browserDock->setVisible(false); connect(m_vocabularyView, &VocabularyView::translationChanged, htmlPart, &BrowserWidget::setTranslation); + connect(this, &EditorWindow::updateBrowserDock, htmlPart, &BrowserWidget::setupProviders); tabifyDockWidget(summaryDock,browserDock); // LaTeX @@ -496,6 +497,7 @@ void EditorWindow::applyPrefs() { m_vocabularyView->reset(); + emit updateBrowserDock(); } void EditorWindow::removeGrades() diff --git a/src/settings/dictionaryeditor.h b/src/settings/dictionaryeditor.h new file mode 100644 --- /dev/null +++ b/src/settings/dictionaryeditor.h @@ -0,0 +1,91 @@ +/*************************************************************************** + + web dictionary options for Parley + + ----------------------------------------------------------------------- + + begin : Mon Nov 13 2017 + + copyright :(C) 2017 Dimitris Kardarakos + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef DICTIONARY_EDITOR_H +#define DICTIONARY_EDITOR_H + +#include "ui_dictionaryeditor.h" +#include + +class WebDictOptions; +/** + * The DictionaryEditor class represents the dialog opened to edit/add an online dictionary + */ +class DictionaryEditor : public QDialog, public Ui::WebDictEntry +{ + Q_OBJECT +public: + /** + * Different modes of operation of dictionary entry dialog + */ + enum EntryMode { + AddOnly, + EditOnly + }; + + DictionaryEditor(const QString & dictName, const EntryMode & dictEntryMode, const QList & dictionariesJsonObjList, QWidget *parent = 0); + +signals: + /** + * Inform parent that dictionary under edit has been updated + */ + void updateDictionaryList(const QList & objList); + +private slots: + /** + * Set of actions to take place when user accepts addition/editing by pressing OK + */ + void userAccepted(); + /** + * A set of checks is executed and button OK is enabled/disabled accordingly + */ + void canSave(); + +private: + /** Search configuration and get the dictionary entry satisfying the search spec provided + * Return the dictionary json object or an empty object if dictionary does not exist + */ + QJsonObject dictionaryJsonObj(const QString & keyName, const QString & keyValue); + /** + * Defines the mode the editor has been opened + */ + EntryMode entryMode; + /** + * Returns the next id available as json primary key + */ + const QString nextId(); + /** + * Id of dictionary entry, to serve as primary key + */ + QString entryId; + /** + * Web dictionary options under edit (parent) + */ + WebDictOptions * webDictOptions; + /** + * List of dictionaries that are currently under edit + */ + QList dictionariesJsonObjList; +}; + +#endif diff --git a/src/settings/dictionaryeditor.cpp b/src/settings/dictionaryeditor.cpp new file mode 100644 --- /dev/null +++ b/src/settings/dictionaryeditor.cpp @@ -0,0 +1,141 @@ +/*************************************************************************** + + web dictionary options for Parley + + ----------------------------------------------------------------------- + + begin : Mon Nov 13 2017 + + copyright :(C) 2017 Dimitris Kardarakos + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include +#include "dictionaryeditor.h" +#include "prefs.h" +#include "webdictoptions.h" + +DictionaryEditor::DictionaryEditor(const QString & dictName, const EntryMode & dictEntryMode, const QList & currentDictionaries, QWidget *parent) : QDialog(parent), + entryMode(dictEntryMode), dictionariesJsonObjList(currentDictionaries) +{ + setupUi(this); + + if (entryMode == EntryMode::EditOnly) { + QJsonObject cfgictionary = dictionaryJsonObj("name", dictName); + + entryId = cfgictionary["id"].toString(); + name->setText(cfgictionary["name"].toString()); + url->setText(cfgictionary["url"].toString()); + source->setText(cfgictionary["source"].toString()); + target->setText(cfgictionary["target"].toString()); + } + else if (entryMode == EntryMode::AddOnly) { + entryId = nextId(); + name->setText(dictName); + } + + canSave(); //Enable/disable buttons + + //Initialize label that explains why save cannot be performed + QPalette p = QApplication::palette(); + KColorScheme scheme(QPalette::Active); + p.setColor(QPalette::WindowText, scheme.foreground(KColorScheme::NegativeText).color()); + displayError->setPalette(p); + + connect(buttonBox, &QDialogButtonBox::accepted, this, &DictionaryEditor::userAccepted); + + connect(name, &QLineEdit::textChanged, this, &DictionaryEditor::canSave); + connect(url, &QLineEdit::textChanged, this, &DictionaryEditor::canSave); + connect(source, &QLineEdit::textChanged, this, &DictionaryEditor::canSave); + connect(target, &QLineEdit::textChanged, this, &DictionaryEditor::canSave); + + connect(this, &DictionaryEditor::updateDictionaryList, (WebDictOptions *) parent, &WebDictOptions::updateDictionaryList); +} + +void DictionaryEditor::userAccepted() +{ + QList::iterator itr; + QJsonObject jsonEntry; + + jsonEntry["name"] = name->text(); + jsonEntry["url"] = url->text(); + jsonEntry["source"] = source->text(); + jsonEntry["target"] = target->text(); + jsonEntry["id"] = entryId; + + if (entryMode == EntryMode::AddOnly) { + dictionariesJsonObjList.append(jsonEntry); + emit updateDictionaryList(dictionariesJsonObjList); + } + else if (entryMode == EntryMode::EditOnly) { + for (itr = dictionariesJsonObjList.begin(); itr != dictionariesJsonObjList.end(); ++itr ) { + if ( (*itr)["id"] == entryId) { + (*itr) = jsonEntry; + } + } + emit updateDictionaryList(dictionariesJsonObjList); + } + else { + qDebug() << "No valid action provided"; + } +} + +QJsonObject DictionaryEditor::dictionaryJsonObj(const QString & keyName, const QString & keyValue) { + QList::const_iterator itr; + for (itr = dictionariesJsonObjList.constBegin(); itr != dictionariesJsonObjList.constEnd(); ++itr ) { + if ( (*itr)[keyName] == keyValue ) { + return *itr; + } + } + + return QJsonObject(); +} + + +void DictionaryEditor::canSave() { + QJsonObject cfgDictionary = QJsonObject(); + cfgDictionary = dictionaryJsonObj("name", name->text()); //Dictionary with the same name + + if(!(cfgDictionary.empty()) && (entryMode == EntryMode::AddOnly || (entryMode == EntryMode::EditOnly && cfgDictionary["id"].toString() != entryId ))) { + buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + displayError->setText(i18n("Dictionary with the same name already exists.")); + } + else if ((name->text()).isEmpty() || (url->text()).isEmpty()) { + buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + displayError->setText(i18n("Name and URL cannot be empty.")); + } + else if (name->text().contains("<<") || url->text().contains("<<") || source->text().contains("<<") || target->text().contains("<<")) { + buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + displayError->setText(i18n("Please do not use string '<<'.")); + } + else { + buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); + displayError->setText(QString()); + } +} + +const QString DictionaryEditor::nextId() { + const QList listOfJsonObj = dictionariesJsonObjList; + + int maxId = 0; + + QList::const_iterator itr; + for (itr = listOfJsonObj.constBegin(); itr != listOfJsonObj.constEnd(); ++itr ) { + if ( ((*itr)["id"]).toString().toInt() > maxId ) { + maxId = (*itr)["id"].toString().toInt(); + } + } + + return QString::number(++maxId); +} diff --git a/src/settings/dictionaryeditor.ui b/src/settings/dictionaryeditor.ui new file mode 100644 --- /dev/null +++ b/src/settings/dictionaryeditor.ui @@ -0,0 +1,164 @@ + + + WebDictEntry + + + + 0 + 0 + 400 + 324 + + + + Dialog + + + + + + Web Dictionary + + + Qt::AlignCenter + + + + + + 8 + + + 8 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Name: + + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + URL: + + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Source: + + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Target: + + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + + + + + Qt::AlignCenter + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + WebDictEntry + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + WebDictEntry + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/settings/parley.kcfg b/src/settings/parley.kcfg --- a/src/settings/parley.kcfg +++ b/src/settings/parley.kcfg @@ -396,4 +396,9 @@ $HOME/Vocabularies/ + + + {"id":"1","name":"De-Es Beolingus","source":"de","target":"es","url":"http://beolingus.org/dings.cgi?service=dees&query=\\{@}"}<<{"id":"2","name":"De-En Beolingus","source":"de","target":"en","url":"http://beolingus.org/dings.cgi?query=\\{@}"}<<{"id":"3","name":"De-En Leo","source":"de","target":"en","url":"http://dict.leo.org/?search=\\{@}"}<<{"id":"4","name":"De-Es Leo","source":"de","target":"es","url":"http://dict.leo.org/?lp=esde&search=\\{@}"}<<{"id":"5","name":"De-Fr Leo","source":"de","target":"fr","url":"http://dict.leo.org/?lp=frde&search=\\{@}"}<<{"id":"6","name":"Ru-En Multitran","url":"http://multitran.ru/c/m.exe?SHL=1&CL=1&l1=1&s=\\{@}","source":"ru","target":"en"}<<{"id":"7","name":"Ru-De Multitran","url":"http://multitran.ru/c/m.exe?SHL=1&CL=1&l1=3&s=\\{@}","source":"ru","target":"de"}<<{"id":"8","name":"Ru-Fr Multitran","url":"http://multitran.ru/c/m.exe?SHL=1&CL=1&l1=4&s=\\{@}","source":"ru","target":"fr"}<<{"id":"9","name":"Heinzelnisse","url":"http://heinzelnisse.info/dict?setOptions=true&searchItem=\\{@}&dictDeNoSearch=on&dictNoDeSearch=on&dictExactSearch=on&dictPhoneticSearch=on&wikiSearch=on&dictNynorskSearch=on&dictBokmaalSearch=checked&forumKeywordSearch=on&suggestion=on"","source":"no","target":"de"}<<{"id":"10","name":"Glosbe (en-es)","source":"en","target":"es","url":"https://glosbe.com/en/es/ \\{@}"}<<{"id":"11","name":"Glosbe (es-en)","source":"es","target":"en","url":"https://glosbe.com/es/en/ \\{@}"} + + diff --git a/src/settings/parleyprefs.h b/src/settings/parleyprefs.h --- a/src/settings/parleyprefs.h +++ b/src/settings/parleyprefs.h @@ -28,6 +28,7 @@ class ViewOptions; class PasteOptions; class PluginOptions; +class WebDictOptions; class KEduVocDocument; class KComboBox; @@ -74,6 +75,7 @@ ViewOptions * m_viewOptions; PasteOptions * m_pasteOptions; PluginOptions * m_pluginOptions; + WebDictOptions * m_webdictOptions; KConfigSkeleton *m_config; KEduVocDocument *m_doc; diff --git a/src/settings/parleyprefs.cpp b/src/settings/parleyprefs.cpp --- a/src/settings/parleyprefs.cpp +++ b/src/settings/parleyprefs.cpp @@ -23,6 +23,7 @@ #include "kgametheme/kgamethemeselector.h" #include "generaloptions.h" #include "viewoptions.h" +#include "webdictoptions.h" #include #include @@ -43,11 +44,15 @@ m_viewOptions = new ViewOptions(0); addPage(m_viewOptions, i18n("View"), QStringLiteral("view-choose"), i18n("View Settings"), true); setHelp(QString(), QStringLiteral("parley")); + + m_webdictOptions = new WebDictOptions(0); + addPage(m_webdictOptions, i18n("Dictionaries"), QStringLiteral("preferences-desktop-locale"), i18n("Web Dictionary Options"), true); + connect(m_webdictOptions, &WebDictOptions::dictionariesChanged, this, &ParleyPrefs::updateButtons); } bool ParleyPrefs::hasChanged() { - return m_generalOptions->hasChanged(); + return m_generalOptions->hasChanged() || m_webdictOptions->hasChanged(); } bool ParleyPrefs::isDefault() @@ -58,6 +63,7 @@ void ParleyPrefs::updateSettings() { m_generalOptions->updateSettings(); + m_webdictOptions->updateConfiguration(); emit settingsChanged(QLatin1String("")); } diff --git a/src/settings/webdictionary.ui b/src/settings/webdictionary.ui new file mode 100644 --- /dev/null +++ b/src/settings/webdictionary.ui @@ -0,0 +1,21 @@ + + + + + Form + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + diff --git a/src/settings/webdictoptions.h b/src/settings/webdictoptions.h new file mode 100644 --- /dev/null +++ b/src/settings/webdictoptions.h @@ -0,0 +1,106 @@ +/*************************************************************************** + + web dictionary options for Parley + + ----------------------------------------------------------------------- + + begin : Mon Nov 13 2017 + + copyright :(C) 2017 Dimitris Kardarakos + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef WEBDICTOPTIONS_H +#define WEBDICTOPTIONS_H + +#include "ui_webdictoptions.h" +#include "dictionaryeditor.h" + +/** + * The WebDictOptions class handles the part of configuration responsible for online dictionaries + */ +class WebDictOptions : public QWidget, public Ui::WebDictOptions +{ + Q_OBJECT +public: + WebDictOptions(QWidget* parent = 0); + + /** + * Read string list of dictionaries from configuration + * Return list of json objects of dictionary list under edit + */ + const QList dictionariesObjList(); + + /** + * Saves list of dictionaries under edit to configuration + */ + void updateConfiguration(); + + /** + * Return true if list of dictionaries has changed + */ + bool hasChanged(); +signals: + /** + * To let containers know that dictionary options have changed + */ + void dictionariesChanged(); + +public slots: + /** + * Update dictionary list member + */ + void updateDictionaryList(const QList & listOfObj); + +private slots: + /** + * Handles add dictionary button + */ + void addDictionary(); + /** + * Handles edit dictionary button + */ + void editDictionary(); + /** + * Handles remove dictionary button + */ + void removeDictionary(); + /** + * Opens dictionary editor dialog widget + * Current (selected) dictionary is passed as argument + */ + void openEditor(const QString & entryName, const DictionaryEditor::EntryMode & entryMode); + /** + * Populate user interface with list of dictionaries read from configuration + */ + void populateWidgetList(); + /** + * Set which action is allowed at each button + */ + void configureButtons(); +private: + /** + * Parse a json object list and return a string list + */ + static QStringList jsonObjListToStringList (const QList & listOfObj); + /** + * Find object provided and delete it from list under edit + */ + void deleteFromDictionaryList(const QString & propertyKey, const QString & propertyVal); + /** + * List of dictionaries under edit + */ + QStringList mDictionaryList; +}; +#endif diff --git a/src/settings/webdictoptions.cpp b/src/settings/webdictoptions.cpp new file mode 100644 --- /dev/null +++ b/src/settings/webdictoptions.cpp @@ -0,0 +1,145 @@ +/*************************************************************************** + + web dictionary options for Parley + + ----------------------------------------------------------------------- + + begin : Mon Nov 13 2017 + + copyright :(C) 2017 Dimitris Kardarakos + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "webdictoptions.h" +#include "prefs.h" +#include +#include +WebDictOptions::WebDictOptions(QWidget *parent) : QWidget(parent) +{ + mDictionaryList = (!(Prefs::dictionaries().isEmpty())) ? Prefs::dictionaries().split("<<") : QStringList(); + + setupUi(this); + populateWidgetList(); + + webDictionariesListWidget->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection); + + editButton->setEnabled(false); + removeButton->setEnabled(false); + + connect(addButton, &QPushButton::clicked, this, &WebDictOptions::addDictionary); + connect(editButton, &QPushButton::clicked, this, &WebDictOptions::editDictionary); + connect(removeButton, &QPushButton::clicked, this, &WebDictOptions::removeDictionary); + + connect(webDictionariesListWidget, &QListWidget::itemSelectionChanged, this, &WebDictOptions::configureButtons); +} + +void WebDictOptions::populateWidgetList() { + const QList cfgDics = dictionariesObjList(); + + webDictionariesListWidget->clear(); + + QList::const_iterator itr; + for (itr = cfgDics.begin(); itr != cfgDics.end() ; ++itr ) { + webDictionariesListWidget->addItem( (*itr)["name"].toString()); + } +} + +void WebDictOptions::addDictionary() { + openEditor(QString(), DictionaryEditor::EntryMode::AddOnly); + populateWidgetList(); +} + +void WebDictOptions::editDictionary() { + openEditor(webDictionariesListWidget->currentItem()->text(), DictionaryEditor::EntryMode::EditOnly); + populateWidgetList(); +} + +void WebDictOptions::removeDictionary() { + deleteFromDictionaryList("name", webDictionariesListWidget->currentItem()->text()); + populateWidgetList(); +} + +void WebDictOptions::openEditor(const QString & entryName, const DictionaryEditor::EntryMode & entryMode) +{ + DictionaryEditor* webDictEntry = new DictionaryEditor(entryName, entryMode, dictionariesObjList(), this); + webDictEntry->setModal(true); + webDictEntry->exec(); +} + +void WebDictOptions::configureButtons() { + if (webDictionariesListWidget->selectedItems().isEmpty()) { + editButton->setEnabled(false); + removeButton->setEnabled(false); + } + else { + editButton->setEnabled(true); + removeButton->setEnabled(true); + } +} + +void WebDictOptions::updateConfiguration() { + Prefs::setDictionaries(mDictionaryList.join("<<")); +} + +void WebDictOptions::updateDictionaryList(const QList & listOfObj) { + mDictionaryList = WebDictOptions::jsonObjListToStringList(listOfObj); + emit dictionariesChanged(); +} + +void WebDictOptions::deleteFromDictionaryList(const QString & propertyKey, const QString & propertyVal) { + QStringList::iterator itr = mDictionaryList.begin(); + while(itr != mDictionaryList.end()) { + QJsonDocument jsonDoc = QJsonDocument::fromJson(itr->toUtf8()); + if(!jsonDoc.isNull() && jsonDoc.isObject() && jsonDoc.object()[propertyKey] == propertyVal) { + itr = mDictionaryList.erase(itr); + } + else { + ++itr; + } + } +} + +const QList WebDictOptions::dictionariesObjList() { + QList listOfJsonObj = QList(); + QJsonDocument jsonDoc; + + QStringList::const_iterator itr ; + for (itr = mDictionaryList.constBegin(); itr != mDictionaryList.constEnd(); ++itr) { + jsonDoc = QJsonDocument::fromJson(itr->toUtf8()); + if(!jsonDoc.isNull() && jsonDoc.isObject()) { + listOfJsonObj.append(jsonDoc.object()); + } + } + + return listOfJsonObj; +} + +QStringList WebDictOptions::jsonObjListToStringList(const QList & listOfObj) { + QStringList strList = QStringList(); + QJsonDocument jsonDoc; + + QList::const_iterator itr; + for(itr = listOfObj.constBegin(); itr != listOfObj.constEnd(); ++itr) { + jsonDoc = QJsonDocument(*itr); + if (jsonDoc.isObject()) { + strList.append(QString(QJsonDocument(*itr).toJson(QJsonDocument::Compact)).toUtf8()); + } + } + + return strList; +} + +bool WebDictOptions::hasChanged() { + return (Prefs::dictionaries() != mDictionaryList.join("<<")); +} diff --git a/src/settings/webdictoptions.ui b/src/settings/webdictoptions.ui new file mode 100644 --- /dev/null +++ b/src/settings/webdictoptions.ui @@ -0,0 +1,93 @@ + + + Licensed under GNU LGPL + WebDictOptions + + + + 0 + 0 + 577 + 508 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + + + + &Add + + + + .. + + + + + + + Edit + + + + + + + &Remove + + + + .. + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + + + +