diff options
author | Michal Klocek <michal.klocek@qt.io> | 2016-10-18 19:01:16 +0200 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2016-10-29 12:27:42 +0000 |
commit | 2fe08ddf9388598003cb3a30f30a2d18ab044969 (patch) | |
tree | 287851c5a4e699fe7fd4fd6277c585a50de190b1 /src | |
parent | 05df6e5f4af76f10a6dc5884c1aa1599a2d7a486 (diff) |
Update spellcheck api to support multiple languages
Task-number: QTBUG-56074
Change-Id: I2a66e91dd4ed1026e5ab2539cfd3f9094263b48c
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/browser_context_adapter.cpp | 10 | ||||
-rw-r--r-- | src/core/browser_context_adapter.h | 5 | ||||
-rw-r--r-- | src/core/browser_context_qt.cpp | 25 | ||||
-rw-r--r-- | src/core/browser_context_qt.h | 4 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineprofile.cpp | 32 | ||||
-rw-r--r-- | src/webengine/api/qquickwebengineprofile.h | 8 | ||||
-rw-r--r-- | src/webengine/plugin/plugins.qmltypes | 4 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebengineprofile.cpp | 20 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebengineprofile.h | 4 |
9 files changed, 60 insertions, 52 deletions
diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp index 86808e177..3396f73ef 100644 --- a/src/core/browser_context_adapter.cpp +++ b/src/core/browser_context_adapter.cpp @@ -491,19 +491,19 @@ void BrowserContextAdapter::clearHttpCache() m_browserContext->url_request_getter_->clearHttpCache(); } -void BrowserContextAdapter::setSpellCheckLanguage(const QString &language) +void BrowserContextAdapter::setSpellCheckLanguages(const QStringList &languages) { #if defined(ENABLE_SPELLCHECK) - m_browserContext->setSpellCheckLanguage(language); + m_browserContext->setSpellCheckLanguages(languages); #endif } -QString BrowserContextAdapter::spellCheckLanguage() const +QStringList BrowserContextAdapter::spellCheckLanguages() const { #if defined(ENABLE_SPELLCHECK) - return m_browserContext->spellCheckLanguage(); + return m_browserContext->spellCheckLanguages(); #else - return QString(); + return QStringList(); #endif } diff --git a/src/core/browser_context_adapter.h b/src/core/browser_context_adapter.h index a6e5a2a3e..39b9db61c 100644 --- a/src/core/browser_context_adapter.h +++ b/src/core/browser_context_adapter.h @@ -108,9 +108,8 @@ public: QString httpUserAgent() const; void setHttpUserAgent(const QString &userAgent); - QStringList spellCheckLanguages(const QStringList &acceptLanguages); - void setSpellCheckLanguage(const QString &language); - QString spellCheckLanguage() const; + void setSpellCheckLanguages(const QStringList &language); + QStringList spellCheckLanguages() const; void setSpellCheckEnabled(bool enabled); bool isSpellCheckEnabled() const; diff --git a/src/core/browser_context_qt.cpp b/src/core/browser_context_qt.cpp index 5f544ab86..a6801e1d7 100644 --- a/src/core/browser_context_qt.cpp +++ b/src/core/browser_context_qt.cpp @@ -213,18 +213,27 @@ void BrowserContextQt::failedToLoadDictionary(const std::string &language) << "Make sure that correct bdic file is in:" << toQt(WebEngineLibraryInfo::getPath(base::DIR_APP_DICTIONARIES).value()); } -void BrowserContextQt::setSpellCheckLanguage(const QString &language) +void BrowserContextQt::setSpellCheckLanguages(const QStringList &languages) { - base::ListValue dictionaries; - dictionaries.AppendString(language.toStdString()); - m_prefService->Set(prefs::kSpellCheckDictionaries, dictionaries); + StringListPrefMember dictionaries_pref; + dictionaries_pref.Init(prefs::kSpellCheckDictionaries, m_prefService.get()); + std::vector<std::string> dictionaries; + dictionaries.reserve(languages.size()); + for (const auto &language : languages) + dictionaries.push_back(language.toStdString()); + dictionaries_pref.SetValue(dictionaries); } -QString BrowserContextQt::spellCheckLanguage() const +QStringList BrowserContextQt::spellCheckLanguages() const { - std::string dictionary; - m_prefService->GetList(prefs::kSpellCheckDictionaries)->GetString(0, &dictionary); - return QString::fromStdString(dictionary); + QStringList spellcheck_dictionaries; + for (const auto &value : *m_prefService->GetList(prefs::kSpellCheckDictionaries)) { + std::string dictionary; + if (value->GetAsString(&dictionary)) + spellcheck_dictionaries.append(QString::fromStdString(dictionary)); + } + + return spellcheck_dictionaries; } void BrowserContextQt::setSpellCheckEnabled(bool enabled) diff --git a/src/core/browser_context_qt.h b/src/core/browser_context_qt.h index c3528871f..ca65552be 100644 --- a/src/core/browser_context_qt.h +++ b/src/core/browser_context_qt.h @@ -102,8 +102,8 @@ public: #if defined(ENABLE_SPELLCHECK) void failedToLoadDictionary(const std::string& language) override; - void setSpellCheckLanguage(const QString &language); - QString spellCheckLanguage() const; + void setSpellCheckLanguages(const QStringList &languages); + QStringList spellCheckLanguages() const; void setSpellCheckEnabled(bool enabled); bool isSpellCheckEnabled() const; #endif diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp index 6a4846ddf..871428f33 100644 --- a/src/webengine/api/qquickwebengineprofile.cpp +++ b/src/webengine/api/qquickwebengineprofile.cpp @@ -87,8 +87,8 @@ ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::MimeHtmlSaveFormat, QtWebEngineC register custom URL schemes (QQuickWebEngineProfile::installUrlSchemeHandler). Spellchecking HTML form fields can be enabled per profile by setting the \l spellCheckEnabled - property and the current language used for spellchecking can be set by using the - \l spellCheckLanguage property. + property and the current languages used for spellchecking can be set by using the + \l spellCheckLanguages property. */ /*! @@ -618,18 +618,18 @@ QQuickWebEngineProfile *QQuickWebEngineProfile::defaultProfile() } /*! - \property QQuickWebEngineProfile::spellCheckLanguage - \brief the language used by the spell checker. + \property QQuickWebEngineProfile::spellCheckLanguages + \brief The languages used by the spell checker. \since QtWebEngine 1.4 */ /*! - \qmlproperty QString WebEngineProfile::spellCheckLanguage + \qmlproperty list<string> WebEngineProfile::spellCheckLanguages - This property holds the language used by the spell checker. - The language should match the name of the \c .bdic dictionary. - For example, the \a language \c en-US will load the \c en-US.bdic + This property holds the list of languages used by the spell checker. + Each language should match the name of the \c .bdic dictionary. + For example, the language \c en-US will load the \c en-US.bdic dictionary file. Qt WebEngine checks for the \c qtwebengine_dictionaries subdirectory @@ -666,24 +666,24 @@ QQuickWebEngineProfile *QQuickWebEngineProfile::defaultProfile() \since QtWebEngine 1.4 */ -void QQuickWebEngineProfile::setSpellCheckLanguage(const QString &language) +void QQuickWebEngineProfile::setSpellCheckLanguages(const QStringList &languages) { Q_D(QQuickWebEngineProfile); - if (language != d->browserContext()->spellCheckLanguage()) { - d->browserContext()->setSpellCheckLanguage(language); - emit spellCheckLanguageChanged(); + if (languages != d->browserContext()->spellCheckLanguages()) { + d->browserContext()->setSpellCheckLanguages(languages); + emit spellCheckLanguagesChanged(); } } /*! \since 5.8 - Returns the language used by the spell checker. + Returns the list of languages used by the spell checker. */ -QString QQuickWebEngineProfile::spellCheckLanguage() const +QStringList QQuickWebEngineProfile::spellCheckLanguages() const { const Q_D(QQuickWebEngineProfile); - return d->browserContext()->spellCheckLanguage(); + return d->browserContext()->spellCheckLanguages(); } /*! @@ -694,7 +694,7 @@ QString QQuickWebEngineProfile::spellCheckLanguage() const */ /*! - \qmlproperty QString WebEngineProfile::spellCheckEnabled + \qmlproperty bool WebEngineProfile::spellCheckEnabled This property holds whether the web engine spell checker is enabled. diff --git a/src/webengine/api/qquickwebengineprofile.h b/src/webengine/api/qquickwebengineprofile.h index 577cc7f6a..d0d925930 100644 --- a/src/webengine/api/qquickwebengineprofile.h +++ b/src/webengine/api/qquickwebengineprofile.h @@ -71,7 +71,7 @@ class Q_WEBENGINE_EXPORT QQuickWebEngineProfile : public QObject { Q_PROPERTY(QString httpAcceptLanguage READ httpAcceptLanguage WRITE setHttpAcceptLanguage NOTIFY httpAcceptLanguageChanged FINAL REVISION 1) Q_PROPERTY(PersistentCookiesPolicy persistentCookiesPolicy READ persistentCookiesPolicy WRITE setPersistentCookiesPolicy NOTIFY persistentCookiesPolicyChanged FINAL) Q_PROPERTY(int httpCacheMaximumSize READ httpCacheMaximumSize WRITE setHttpCacheMaximumSize NOTIFY httpCacheMaximumSizeChanged FINAL) - Q_PROPERTY(QString spellCheckLanguage READ spellCheckLanguage WRITE setSpellCheckLanguage NOTIFY spellCheckLanguageChanged FINAL REVISION 3) + Q_PROPERTY(QStringList spellCheckLanguages READ spellCheckLanguages WRITE setSpellCheckLanguages NOTIFY spellCheckLanguagesChanged FINAL REVISION 3) Q_PROPERTY(bool spellCheckEnabled READ isSpellCheckEnabled WRITE setSpellCheckEnabled NOTIFY spellCheckEnabledChanged FINAL REVISION 3) public: @@ -131,8 +131,8 @@ public: Q_REVISION(2) Q_INVOKABLE void clearHttpCache(); - void setSpellCheckLanguage(const QString &language); - QString spellCheckLanguage() const; + void setSpellCheckLanguages(const QStringList &languages); + QStringList spellCheckLanguages() const; void setSpellCheckEnabled(bool enabled); bool isSpellCheckEnabled() const; @@ -148,7 +148,7 @@ Q_SIGNALS: void persistentCookiesPolicyChanged(); void httpCacheMaximumSizeChanged(); Q_REVISION(1) void httpAcceptLanguageChanged(); - Q_REVISION(3) void spellCheckLanguageChanged(); + Q_REVISION(3) void spellCheckLanguagesChanged(); Q_REVISION(3) void spellCheckEnabledChanged(); void downloadRequested(QQuickWebEngineDownloadItem *download); diff --git a/src/webengine/plugin/plugins.qmltypes b/src/webengine/plugin/plugins.qmltypes index c8aaaf420..304bfd6b7 100644 --- a/src/webengine/plugin/plugins.qmltypes +++ b/src/webengine/plugin/plugins.qmltypes @@ -359,10 +359,10 @@ Module { Property { name: "httpAcceptLanguage"; revision: 1; type: "string" } Property { name: "persistentCookiesPolicy"; type: "PersistentCookiesPolicy" } Property { name: "httpCacheMaximumSize"; type: "int" } - Property { name: "spellCheckLanguage"; revision: 3; type: "string" } + Property { name: "spellCheckLanguages"; revision: 3; type: "QStringList" } Property { name: "spellCheckEnabled"; revision: 3; type: "bool" } Signal { name: "httpAcceptLanguageChanged"; revision: 1 } - Signal { name: "spellCheckLanguageChanged"; revision: 3 } + Signal { name: "spellCheckLanguagesChanged"; revision: 3 } Signal { name: "spellCheckEnabledChanged"; revision: 3 } Signal { name: "downloadRequested" diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp index bd41a5126..886a7207e 100644 --- a/src/webenginewidgets/api/qwebengineprofile.cpp +++ b/src/webenginewidgets/api/qwebengineprofile.cpp @@ -98,8 +98,8 @@ using QtWebEngineCore::BrowserContextAdapter; QWebEngineUrlSchemeHandler::requestStarted() as QWebEngineUrlRequestJob objects. Spellchecking HTML form fields can be enabled per profile by using the setSpellCheckEnabled() - method and the current language used for spellchecking can be set by using the - setSpellCheckLanguage() method. + method and the current languages used for spellchecking can be set by using the + setSpellCheckLanguages() method. */ @@ -565,9 +565,9 @@ QWebEngineProfile *QWebEngineProfile::defaultProfile() /*! \since 5.8 - Sets the current \a language for the spell checker. - The language should match the name of the \c .bdic dictionary. - For example, the \a language \c en-US will load the \c en-US.bdic + Sets the current list of \a languages for the spell checker. + Each language should match the name of the \c .bdic dictionary. + For example, the language \c en-US will load the \c en-US.bdic dictionary file. Qt WebEngine checks for the \c qtwebengine_dictionaries subdirectory @@ -603,21 +603,21 @@ QWebEngineProfile *QWebEngineProfile::defaultProfile() \l{WebEngine Widgets Spellchecker Example}{Spellchecker Example}. */ -void QWebEngineProfile::setSpellCheckLanguage(const QString &language) +void QWebEngineProfile::setSpellCheckLanguages(const QStringList &languages) { Q_D(QWebEngineProfile); - d->browserContext()->setSpellCheckLanguage(language); + d->browserContext()->setSpellCheckLanguages(languages); } /*! \since 5.8 - Returns the language used by the spell checker. + Returns the list of languages used by the spell checker. */ -QString QWebEngineProfile::spellCheckLanguage() const +QStringList QWebEngineProfile::spellCheckLanguages() const { const Q_D(QWebEngineProfile); - return d->browserContext()->spellCheckLanguage(); + return d->browserContext()->spellCheckLanguages(); } /*! diff --git a/src/webenginewidgets/api/qwebengineprofile.h b/src/webenginewidgets/api/qwebengineprofile.h index 704414bcf..1ce4bfe17 100644 --- a/src/webenginewidgets/api/qwebengineprofile.h +++ b/src/webenginewidgets/api/qwebengineprofile.h @@ -121,8 +121,8 @@ public: void clearHttpCache(); - void setSpellCheckLanguage(const QString &language); - QString spellCheckLanguage() const; + void setSpellCheckLanguages(const QStringList &languages); + QStringList spellCheckLanguages() const; void setSpellCheckEnabled(bool enabled); bool isSpellCheckEnabled() const; |