From d6f478be7ef74fc967c7e59ff156875fe0ee1524 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Fri, 16 Oct 2015 23:18:39 +0200 Subject: [PATCH] Remove qtwebkit-plugins --- src/lib/lib.pro | 3 - .../notifications/notificationpresenter.cpp | 37 -- .../notifications/notificationpresenter.h | 31 -- src/lib/plugins/qtwebkit/qtwebkit-plugins.pri | 69 --- src/lib/plugins/qtwebkit/qtwebkitplugin.cpp | 63 --- src/lib/plugins/qtwebkit/qtwebkitplugin.h | 39 -- .../qtwebkit/spellcheck/spellcheck.cpp | 152 ------- .../plugins/qtwebkit/spellcheck/spellcheck.h | 56 --- .../qtwebkit/spellcheck/spellcheckdialog.cpp | 137 ------ .../qtwebkit/spellcheck/spellcheckdialog.h | 51 --- .../qtwebkit/spellcheck/spellcheckdialog.ui | 168 ------- .../plugins/qtwebkit/spellcheck/speller.cpp | 424 ------------------ src/lib/plugins/qtwebkit/spellcheck/speller.h | 110 ----- 13 files changed, 1340 deletions(-) delete mode 100644 src/lib/plugins/qtwebkit/notifications/notificationpresenter.cpp delete mode 100644 src/lib/plugins/qtwebkit/notifications/notificationpresenter.h delete mode 100644 src/lib/plugins/qtwebkit/qtwebkit-plugins.pri delete mode 100644 src/lib/plugins/qtwebkit/qtwebkitplugin.cpp delete mode 100644 src/lib/plugins/qtwebkit/qtwebkitplugin.h delete mode 100644 src/lib/plugins/qtwebkit/spellcheck/spellcheck.cpp delete mode 100644 src/lib/plugins/qtwebkit/spellcheck/spellcheck.h delete mode 100644 src/lib/plugins/qtwebkit/spellcheck/spellcheckdialog.cpp delete mode 100644 src/lib/plugins/qtwebkit/spellcheck/spellcheckdialog.h delete mode 100644 src/lib/plugins/qtwebkit/spellcheck/spellcheckdialog.ui delete mode 100644 src/lib/plugins/qtwebkit/spellcheck/speller.cpp delete mode 100644 src/lib/plugins/qtwebkit/spellcheck/speller.h diff --git a/src/lib/lib.pro b/src/lib/lib.pro index afde95604..8a6d87853 100644 --- a/src/lib/lib.pro +++ b/src/lib/lib.pro @@ -11,9 +11,6 @@ include(../defines.pri) include(../../translations/translations.pri) include(3rdparty/qtsingleapplication/qtsingleapplication.pri) -# QTWEBENGINE DISABLED -#include(plugins/qtwebkit/qtwebkit-plugins.pri) - CONFIG(debug, debug|release): include(../../tests/modeltest/modeltest.pri) unix:!contains(DEFINES, "DISABLE_DBUS") QT += dbus diff --git a/src/lib/plugins/qtwebkit/notifications/notificationpresenter.cpp b/src/lib/plugins/qtwebkit/notifications/notificationpresenter.cpp deleted file mode 100644 index 5463e3baf..000000000 --- a/src/lib/plugins/qtwebkit/notifications/notificationpresenter.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2013-2014 David Rosca -* -* 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 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* ============================================================ */ -#include "notificationpresenter.h" -#include "desktopnotificationsfactory.h" -#include "mainapplication.h" - -NotificationPresenter::NotificationPresenter() - : QWebNotificationPresenter() -{ -} - -void NotificationPresenter::showNotification(const QWebNotificationData* data) -{ - if (data->message().isEmpty()) { - qDebug() << "NotificationPresenter: HTML notifications are not supported."; - return; - } - - mApp->desktopNotifications()->showNotification(QPixmap(":qupzilla.png"), - data->title(), - data->message()); -} diff --git a/src/lib/plugins/qtwebkit/notifications/notificationpresenter.h b/src/lib/plugins/qtwebkit/notifications/notificationpresenter.h deleted file mode 100644 index 8b15bba68..000000000 --- a/src/lib/plugins/qtwebkit/notifications/notificationpresenter.h +++ /dev/null @@ -1,31 +0,0 @@ -/* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2013-2014 David Rosca -* -* 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 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* ============================================================ */ -#ifndef NOTIFICATIONPRESENTER_H -#define NOTIFICATIONPRESENTER_H - -#include "qwebkitplatformplugin.h" - -class NotificationPresenter : public QWebNotificationPresenter -{ -public: - explicit NotificationPresenter(); - - void showNotification(const QWebNotificationData* data); -}; - -#endif // NOTIFICATIONPRESENTER_H diff --git a/src/lib/plugins/qtwebkit/qtwebkit-plugins.pri b/src/lib/plugins/qtwebkit/qtwebkit-plugins.pri deleted file mode 100644 index 15914332a..000000000 --- a/src/lib/plugins/qtwebkit/qtwebkit-plugins.pri +++ /dev/null @@ -1,69 +0,0 @@ -# Unix -!mac:unix { - contains(DEFINES, USE_QTWEBKIT_2_2) { - buildNotifications = true - - contains(DEFINES, USE_QTWEBKIT_2_3):system(pkg-config --exists hunspell) { - buildSpellcheck = true - LIBS += $$system(pkg-config --libs hunspell) - } - } - else { - buildPlugin = false - } -} - -# Mac OS X -mac { - buildPlugin = false -} - -# OS/2 -os2 { - buildPlugin = false -} - -# Windows -win32 { - win32-msvc* { - # QtWebKit 2.3 and Hunspell is now needed to build on Windows - buildNotifications = true - buildSpellcheck = true - LIBS += -llibhunspell - } - else { # mingw - buildPlugin = false - } -} - -!equals(buildPlugin, false) { - HEADERS += $$PWD/qtwebkitplugin.h \ - $$[QT_INSTALL_HEADERS]/QtWebKit/qwebkitplatformplugin.h - - SOURCES += $$PWD/qtwebkitplugin.cpp - - DEFINES *= QT_STATICPLUGIN -} -else { - buildNotifications = false - buildSpellcheck = false -} - -equals(buildNotifications, true) { - HEADERS += $$PWD/notifications/notificationpresenter.h - SOURCES += $$PWD/notifications/notificationpresenter.cpp -} - -equals(buildSpellcheck, true) { - HEADERS += $$PWD/spellcheck/spellcheck.h \ - $$PWD/spellcheck/speller.h \ - $$PWD/spellcheck/spellcheckdialog.h \ - - SOURCES += $$PWD/spellcheck/spellcheck.cpp \ - $$PWD/spellcheck/speller.cpp \ - $$PWD/spellcheck/spellcheckdialog.cpp \ - - FORMS += $$PWD/spellcheck/spellcheckdialog.ui - - DEFINES *= USE_HUNSPELL -} diff --git a/src/lib/plugins/qtwebkit/qtwebkitplugin.cpp b/src/lib/plugins/qtwebkit/qtwebkitplugin.cpp deleted file mode 100644 index 1d1d966ec..000000000 --- a/src/lib/plugins/qtwebkit/qtwebkitplugin.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2013-2014 David Rosca -* -* 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 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* ============================================================ */ -#include "qtwebkitplugin.h" -#include "notifications/notificationpresenter.h" - -#ifdef USE_HUNSPELL -#include "spellcheck/spellcheck.h" -#endif - -#include - -QtWebKitPlugin::QtWebKitPlugin() -{ -} - -bool QtWebKitPlugin::supportsExtension(Extension ext) const -{ - return (ext == Notifications -#ifdef USE_HUNSPELL - || ext == SpellChecker -#endif - ); -} - -QObject* QtWebKitPlugin::createExtension(Extension ext) const -{ - switch (ext) { -#ifdef USE_HUNSPELL - case SpellChecker: - return new SpellCheck(); -#endif - case Notifications: - return new NotificationPresenter(); - - default: - return 0; - } -} - -#if QT_VERSION < 0x050000 -Q_EXPORT_PLUGIN2(qtwebkitplugins, QtWebKitPlugin) -#endif - -#if (QT_VERSION < 0x050000) -Q_IMPORT_PLUGIN(qtwebkitplugins) -#else -Q_IMPORT_PLUGIN(QtWebKitPlugin) -#endif diff --git a/src/lib/plugins/qtwebkit/qtwebkitplugin.h b/src/lib/plugins/qtwebkit/qtwebkitplugin.h deleted file mode 100644 index c27e14cb6..000000000 --- a/src/lib/plugins/qtwebkit/qtwebkitplugin.h +++ /dev/null @@ -1,39 +0,0 @@ -/* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2013-2014 David Rosca -* -* 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 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* ============================================================ */ -#ifndef QTWEBKITPLUGIN_H -#define QTWEBKITPLUGIN_H - -#include "qwebkitplatformplugin.h" - -class QtWebKitPlugin : public QObject, public QWebKitPlatformPlugin -{ - Q_OBJECT - Q_INTERFACES(QWebKitPlatformPlugin) - -#if QT_VERSION >= 0x050000 - Q_PLUGIN_METADATA(IID "org.qtwebkit.QtWebKit.QtWebKitPlugins") -#endif - -public: - explicit QtWebKitPlugin(); - - bool supportsExtension(Extension ext) const; - QObject* createExtension(Extension ext) const; -}; - -#endif // QTWEBKITPLUGIN_H diff --git a/src/lib/plugins/qtwebkit/spellcheck/spellcheck.cpp b/src/lib/plugins/qtwebkit/spellcheck/spellcheck.cpp deleted file mode 100644 index 892b3d370..000000000 --- a/src/lib/plugins/qtwebkit/spellcheck/spellcheck.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2013-2014 David Rosca -* -* 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 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* ============================================================ */ - -// Based on https://gitorious.org/kdewebkit-spellcheck - -#include "spellcheck.h" -#include "speller.h" - -SpellCheck::SpellCheck() - : QWebSpellChecker() -{ -} - -bool SpellCheck::isContinousSpellCheckingEnabled() const -{ - return Speller::instance()->isEnabled(); -} - -void SpellCheck::toggleContinousSpellChecking() -{ -} - -void SpellCheck::learnWord(const QString &word) -{ - Q_UNUSED(word); -} - -void SpellCheck::ignoreWordInSpellDocument(const QString &word) -{ - Q_UNUSED(word); -} - -void SpellCheck::checkSpellingOfString(const QString &word, - int* misspellingLocation, int* misspellingLength) -{ - if (misspellingLocation == NULL || misspellingLength == NULL) { - return; - } - - *misspellingLocation = -1; - *misspellingLength = 0; - - QTextBoundaryFinder finder = QTextBoundaryFinder(QTextBoundaryFinder::Word, word); - - QTextBoundaryFinder::BoundaryReasons boundary = finder.boundaryReasons(); - int start = finder.position(), end = finder.position(); - bool inWord = startOfWord(boundary, finder.type()); - - while (finder.toNextBoundary() > 0) { - boundary = finder.boundaryReasons(); - - if (endOfWord(boundary, finder.type()) && inWord) { - end = finder.position(); - QString str = finder.string().mid(start, end - start); - if (Speller::isValidWord(str)) { - if (Speller::instance()->isMisspelled(str)) { - *misspellingLocation = start; - *misspellingLength = end - start; - } - return; - } - inWord = false; - } - - if (startOfWord(boundary, finder.type())) { - start = finder.position(); - inWord = true; - } - } -} - -QString SpellCheck::autoCorrectSuggestionForMisspelledWord(const QString &word) -{ - /* Auto correcting mispelled words is really not a great idea */ - Q_UNUSED(word) - return QString(); -#if 0 - QStringList words = Speller::instance()->suggest(word); - if (words.size() > 0) { - return words[0]; - } - else { - return QString(); - } - - return QString(); -#endif -} - -void SpellCheck::guessesForWord(const QString &word, - const QString &context, QStringList &guesses) -{ - Q_UNUSED(context); - - QStringList words = Speller::instance()->suggest(word); - guesses = words; -} - -bool SpellCheck::isGrammarCheckingEnabled() -{ - return false; -} - -void SpellCheck::toggleGrammarChecking() -{ -} - -void SpellCheck::checkGrammarOfString(const QString &, QList &, - int* badGrammarLocation, int* badGrammarLength) -{ - Q_UNUSED(badGrammarLocation); - Q_UNUSED(badGrammarLength); -} - -bool SpellCheck::endOfWord(const QTextBoundaryFinder::BoundaryReasons &reasons, - const QTextBoundaryFinder::BoundaryType &type) -{ -#if QT_VERSION < 0x050000 - Q_UNUSED(type) - return reasons & QTextBoundaryFinder::EndWord; -#else - return (reasons & QTextBoundaryFinder::EndOfItem) && - (type & QTextBoundaryFinder::Word); -#endif -} - -bool SpellCheck::startOfWord(const QTextBoundaryFinder::BoundaryReasons &reasons, - const QTextBoundaryFinder::BoundaryType &type) -{ -#if QT_VERSION < 0x050000 - Q_UNUSED(type) - return reasons & QTextBoundaryFinder::StartWord; -#else - return (reasons & QTextBoundaryFinder::StartOfItem) && - (type & QTextBoundaryFinder::Word); -#endif -} diff --git a/src/lib/plugins/qtwebkit/spellcheck/spellcheck.h b/src/lib/plugins/qtwebkit/spellcheck/spellcheck.h deleted file mode 100644 index 18b854279..000000000 --- a/src/lib/plugins/qtwebkit/spellcheck/spellcheck.h +++ /dev/null @@ -1,56 +0,0 @@ -/* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2013-2014 David Rosca -* -* 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 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* ============================================================ */ -#ifndef SPELLCHECKER_H -#define SPELLCHECKER_H - -#include -#include "qwebkitplatformplugin.h" - -class Speller; - -class SpellCheck : public QWebSpellChecker -{ - Q_OBJECT - -public: - explicit SpellCheck(); - - bool isContinousSpellCheckingEnabled() const; - void toggleContinousSpellChecking(); - - void learnWord(const QString &word); - void ignoreWordInSpellDocument(const QString &word); - void checkSpellingOfString(const QString &word, - int* misspellingLocation, int* misspellingLength); - QString autoCorrectSuggestionForMisspelledWord(const QString &word); - void guessesForWord(const QString &word, - const QString &context, QStringList &guesses); - - bool isGrammarCheckingEnabled(); - void toggleGrammarChecking(); - void checkGrammarOfString(const QString &, QList &, - int* badGrammarLocation, int* badGrammarLength); - -private: - bool endOfWord(const QTextBoundaryFinder::BoundaryReasons &reasons, - const QTextBoundaryFinder::BoundaryType &type); - bool startOfWord(const QTextBoundaryFinder::BoundaryReasons &reasons, - const QTextBoundaryFinder::BoundaryType &type); -}; - -#endif // SPELLCHECKER_H diff --git a/src/lib/plugins/qtwebkit/spellcheck/spellcheckdialog.cpp b/src/lib/plugins/qtwebkit/spellcheck/spellcheckdialog.cpp deleted file mode 100644 index be2fbd590..000000000 --- a/src/lib/plugins/qtwebkit/spellcheck/spellcheckdialog.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2013-2014 David Rosca -* -* 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 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* ============================================================ */ -#include "spellcheckdialog.h" -#include "ui_spellcheckdialog.h" -#include "datapaths.h" -#include "settings.h" -#include "speller.h" -#include "qztools.h" - -#include -#include -#include -#include - -SpellCheckDialog::SpellCheckDialog(QWidget* parent) - : QDialog(parent) - , ui(new Ui::SpellCheckDialog) - , m_listChanged(false) -{ - ui->setupUi(this); - - ui->dictPath->setText(Speller::instance()->dictionaryPath()); - - QFile file(DataPaths::currentProfilePath() + "/userdictionary.txt"); - if (!file.open(QFile::ReadOnly)) { - qWarning() << "SpellCheckDialog: Cannot open file" << file.fileName() << "for reading!"; - } - else { - QString word; - QTextStream stream(&file); - stream.setCodec("UTF-8"); - - while (!stream.atEnd()) { - stream >> word; - word = word.trimmed(); - - if (!word.isEmpty()) { - ui->userDictList->insertItem(0, word); - } - } - - file.close(); - } - - connect(ui->changeDictPath, SIGNAL(clicked()), this, SLOT(changeDictionaryPath())); - connect(ui->add, SIGNAL(clicked()), this, SLOT(addUserWord())); - connect(ui->remove, SIGNAL(clicked()), this, SLOT(removeUserWord())); - connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(saveSettings())); - - ui->userDictList->setFocus(); -} - -void SpellCheckDialog::changeDictionaryPath() -{ - const QString path = QzTools::getExistingDirectory("SpellCheckDialog-Directory", this, tr("Choose dictionary path..."), ui->dictPath->text()); - - if (!path.isEmpty()) { - ui->dictPath->setText(path); - } -} - -void SpellCheckDialog::addUserWord() -{ - const QString word = QInputDialog::getText(0, tr("Add new word..."), tr("Add new word:")); - - if (!word.isEmpty()) { - ui->userDictList->addItem(word); - ui->userDictList->setCurrentRow(ui->userDictList->count() - 1); - - m_listChanged = true; - } -} - -void SpellCheckDialog::removeUserWord() -{ - QListWidgetItem* item = ui->userDictList->currentItem(); - - if (!item) { - return; - } - - m_listChanged = true; - delete item; -} - -void SpellCheckDialog::saveSettings() -{ - // Save only when changed - - if (ui->dictPath->text() != Speller::instance()->dictionaryPath()) { - Settings settings; - settings.beginGroup("SpellCheck"); - settings.setValue("dictionaryPath", ui->dictPath->text()); - settings.endGroup(); - } - - if (!m_listChanged) { - return; - } - - QFile file(DataPaths::currentProfilePath() + "/userdictionary.txt"); - if (!file.open(QFile::WriteOnly | QFile::Truncate)) { - qWarning() << "SpellCheckDialog: Cannot open file" << file.fileName() << "for reading!"; - return; - } - - QTextStream stream(&file); - stream.setCodec("UTF-8"); - int count = ui->userDictList->count(); - - for (int i = 0; i < count; ++i) { - const QString word = ui->userDictList->item(i)->text(); - stream << word << endl; - } - - file.close(); -} - -SpellCheckDialog::~SpellCheckDialog() -{ - delete ui; -} diff --git a/src/lib/plugins/qtwebkit/spellcheck/spellcheckdialog.h b/src/lib/plugins/qtwebkit/spellcheck/spellcheckdialog.h deleted file mode 100644 index a18d97359..000000000 --- a/src/lib/plugins/qtwebkit/spellcheck/spellcheckdialog.h +++ /dev/null @@ -1,51 +0,0 @@ -/* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2013-2014 David Rosca -* -* 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 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* ============================================================ */ -#ifndef SPELLCHECKDIALOG_H -#define SPELLCHECKDIALOG_H - -#include - -#include "qzcommon.h" - -namespace Ui -{ -class SpellCheckDialog; -} - -class QUPZILLA_EXPORT SpellCheckDialog : public QDialog -{ - Q_OBJECT - -public: - explicit SpellCheckDialog(QWidget* parent = 0); - ~SpellCheckDialog(); - -private slots: - void changeDictionaryPath(); - void addUserWord(); - void removeUserWord(); - - void saveSettings(); - -private: - Ui::SpellCheckDialog* ui; - - bool m_listChanged; -}; - -#endif // SPELLCHECKDIALOG_H diff --git a/src/lib/plugins/qtwebkit/spellcheck/spellcheckdialog.ui b/src/lib/plugins/qtwebkit/spellcheck/spellcheckdialog.ui deleted file mode 100644 index 71d7f790b..000000000 --- a/src/lib/plugins/qtwebkit/spellcheck/spellcheckdialog.ui +++ /dev/null @@ -1,168 +0,0 @@ - - - SpellCheckDialog - - - - 0 - 0 - 441 - 305 - - - - SpellCheck - - - - - - <b>Dictionary path</b> - - - - - - - - - false - - - - - - - Change... - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 40 - 20 - - - - - - - - - - <b>User dictionary</b> - - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Add - - - - - - - Remove - - - - - - - - - - - - - Using Hunspell library - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - - MacToolButton - QToolButton -
mactoolbutton.h
-
-
- - - - buttonBox - accepted() - SpellCheckDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - SpellCheckDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - -
diff --git a/src/lib/plugins/qtwebkit/spellcheck/speller.cpp b/src/lib/plugins/qtwebkit/spellcheck/speller.cpp deleted file mode 100644 index d39ee5407..000000000 --- a/src/lib/plugins/qtwebkit/spellcheck/speller.cpp +++ /dev/null @@ -1,424 +0,0 @@ -/* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2013-2014 David Rosca -* -* 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 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* ============================================================ */ -#include "speller.h" -#include "spellcheckdialog.h" -#include "settings.h" -#include "datapaths.h" -#include "mainapplication.h" -#include "qztools.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -Q_GLOBAL_STATIC(Speller, qz_speller) - -Speller::Speller() - : QObject() - , m_textCodec(0) - , m_hunspell(0) - , m_enabled(false) - , m_startPos(0) - , m_endPos(0) -{ - loadSettings(); -} - -bool Speller::isEnabled() const -{ - return m_enabled; -} - -void Speller::loadSettings() -{ - - Settings settings; - settings.beginGroup("SpellCheck"); - m_enabled = settings.value("enabled", true).toBool(); - m_dictionaryPath = settings.value("dictionaryPath", getDictionaryPath()).toString(); - m_language.code = settings.value("language", mApp->currentLanguage()).toString(); - m_language.name = nameForLanguage(m_language.code); - settings.endGroup(); - - m_userDictionary.setFileName(DataPaths::currentProfilePath() + "/userdictionary.txt"); - - if (m_enabled) { - initialize(); - } -} - -void Speller::initialize() -{ - delete m_hunspell; - m_hunspell = 0; - - if (m_dictionaryPath.isEmpty()) { - qWarning() << "SpellCheck: Cannot locate dictionary path!"; - return; - } - - QString dictionary = m_dictionaryPath + QLatin1Char('/') + m_language.code; - - if (!dictionaryExists(dictionary)) { - qWarning() << "SpellCheck: Dictionaries for" << dictionary << "doesn't exists!"; - return; - } - - const QString dicPath = dictionary + ".dic"; - const QString affPath = dictionary + ".aff"; - - m_hunspell = new Hunspell(affPath.toLocal8Bit().constData(), - dicPath.toLocal8Bit().constData()); - - m_textCodec = QTextCodec::codecForName(m_hunspell->get_dic_encoding()); - - if (m_userDictionary.exists()) { - if (!m_userDictionary.open(QFile::ReadOnly)) { - qWarning() << "SpellCheck: Cannot open" << m_userDictionary.fileName() << "for reading!"; - } - else { - QString word; - QTextStream stream(&m_userDictionary); - stream.setCodec("UTF-8"); - while (!stream.atEnd()) { - stream >> word; - putWord(word); - } - } - m_userDictionary.close(); - } - - qDebug() << "SpellCheck: Language =" << language().code - << (m_textCodec ? m_textCodec->name() : "invalid text codec"); -} - -Speller::Language Speller::language() const -{ - return m_language; -} - -QVector Speller::availableLanguages() -{ - if (!m_availableLanguages.isEmpty()) { - return m_availableLanguages; - } - - QDirIterator it(m_dictionaryPath, QStringList("*.dic"), QDir::Files); - - while (it.hasNext()) { - const QString affFilePath = it.next().replace(QLatin1String(".dic"), QLatin1String(".aff")); - - if (!QFile(affFilePath).exists()) { - continue; - } - - Language lang; - lang.code = it.fileInfo().baseName(); - lang.name = nameForLanguage(lang.code); - - if (!m_availableLanguages.contains(lang)) { - m_availableLanguages.append(lang); - } - } - - return m_availableLanguages; -} - -QString Speller::dictionaryPath() const -{ - return m_dictionaryPath; -} - -void Speller::createContextMenu(QMenu* menu) -{ - menu->addSeparator(); - - QAction* act = menu->addAction(tr("Check &Spelling"), this, SLOT(toggleEnableSpellChecking())); - act->setCheckable(true); - act->setChecked(m_enabled); - - if (m_enabled) { - QMenu* men = menu->addMenu(tr("Languages")); - connect(men, SIGNAL(aboutToShow()), this, SLOT(populateLanguagesMenu())); - } - - menu->addSeparator(); -} - -void Speller::populateContextMenu(QMenu* menu, const QWebHitTestResult &hitTest) -{ - m_element = hitTest.element(); - - if (!m_enabled || - m_element.isNull() || - m_element.attribute(QLatin1String("type")) == QLatin1String("password") - ) { - return; - } - - const QString text = m_element.evaluateJavaScript("this.value").toString(); - const int pos = m_element.evaluateJavaScript("this.selectionStart").toInt() + 1; - - QTextBoundaryFinder finder = QTextBoundaryFinder(QTextBoundaryFinder::Word, text); - finder.setPosition(pos); - m_startPos = finder.toPreviousBoundary(); - m_endPos = finder.toNextBoundary(); - - const QString word = text.mid(m_startPos, m_endPos - m_startPos).trimmed(); - - if (!isValidWord(word) || !isMisspelled(word)) { - return; - } - - const int limit = 6; - QStringList suggests = suggest(word); - int count = suggests.count() > limit ? limit : suggests.count(); - - QFont boldFont = menu->font(); - boldFont.setBold(true); - - for (int i = 0; i < count; ++i) { - QAction* act = menu->addAction(suggests.at(i), this, SLOT(replaceWord())); - act->setData(suggests.at(i)); - act->setFont(boldFont); - } - - if (count == 0) { - menu->addAction(tr("No suggestions"))->setEnabled(false); - } - - menu->addAction(tr("Add to dictionary"), this, SLOT(addToDictionary()))->setData(word); - menu->addSeparator(); -} - -void Speller::addToDictionary() -{ - if (QAction* act = qobject_cast(sender())) { - const QString word = act->data().toString(); - putWord(word); - - if (!m_userDictionary.open(QFile::WriteOnly | QFile::Append)) { - qWarning() << "SpellCheck: Cannot open file" << m_userDictionary.fileName() << "for writing!"; - return; - } - - QTextStream stream(&m_userDictionary); - stream.setCodec("UTF-8"); - stream << word << endl; - m_userDictionary.close(); - } -} - -void Speller::replaceWord() -{ - if (m_element.isNull()) { - return; - } - - if (QAction* act = qobject_cast(sender())) { - QString word = act->data().toString(); - QString text = m_element.evaluateJavaScript("this.value").toString(); - const int cursorPos = m_element.evaluateJavaScript("this.selectionStart").toInt(); - - text.replace(m_startPos, m_endPos - m_startPos, word); - text.replace(QLatin1Char('\\'), QLatin1String("\\\\")); - text.replace(QLatin1Char('\n'), QLatin1String("\\n")); - text.replace(QLatin1Char('\''), QLatin1String("\\'")); - - m_element.evaluateJavaScript(QString("this.value='%1'").arg(text)); - m_element.evaluateJavaScript(QString("this.selectionStart=this.selectionEnd=%1").arg(cursorPos)); - } -} - -void Speller::showSettings() -{ - SpellCheckDialog dialog; - - if (dialog.exec() == QDialog::Accepted) { - loadSettings(); - } -} - -void Speller::changeLanguage() -{ - QAction* act = qobject_cast(sender()); - - if (!act) { - return; - } - - Language lang = act->data().value(); - - Settings settings; - settings.beginGroup("SpellCheck"); - settings.setValue("language", lang.code); - settings.endGroup(); - - loadSettings(); -} - -void Speller::putWord(const QString &word) -{ - if (!m_hunspell || !m_textCodec || word.isEmpty()) { - return; - } - - const QByteArray data = m_textCodec->fromUnicode(word); - - if (m_hunspell->add(data.constData()) != 0) { - qWarning() << "SpellCheck: Error while adding" << word << "word!"; - } -} - -bool Speller::isMisspelled(const QString &string) -{ - if (!m_hunspell || !m_textCodec) { - return false; - } - - const QByteArray data = m_textCodec->fromUnicode(string); - - return m_hunspell->spell(data.constData()) == 0; -} - -QStringList Speller::suggest(const QString &word) -{ - if (!m_hunspell || !m_textCodec) { - return QStringList(); - } - - char** suggestions; - const QByteArray data = m_textCodec->fromUnicode(word); - int count = m_hunspell->suggest(&suggestions, data.constData()); - - QStringList suggests; - for (int i = 0; i < count; ++i) { - suggests.append(m_textCodec->toUnicode(suggestions[i])); - } - m_hunspell->free_list(&suggestions, count); - - return suggests; -} - -bool Speller::isValidWord(const QString &str) -{ - if (str.isEmpty() || (str.length() == 1 && !str[0].isLetter())) { - return false; - } - - const int length = str.length(); - - for (int i = 0; i < length; ++i) { - if (!str[i].isNumber()) { - return true; - } - } - - return false; -} - -Speller* Speller::instance() -{ - return qz_speller(); -} - -void Speller::populateLanguagesMenu() -{ - QMenu* menu = qobject_cast(sender()); - - if (!menu || !menu->isEmpty()) { - return; - } - - const QVector langs = availableLanguages(); - foreach (const Language &lang, langs) { - QAction* act = menu->addAction(lang.name, this, SLOT(changeLanguage())); - act->setCheckable(true); - act->setChecked(m_language == lang); - act->setData(QVariant::fromValue(lang)); - } - - if (menu->isEmpty()) { - QAction* act = menu->addAction(tr("No suggestions")); - act->setEnabled(false); - } - - menu->addSeparator(); - menu->addAction(tr("Settings"), this, SLOT(showSettings())); -} - -void Speller::toggleEnableSpellChecking() -{ - m_enabled = !m_enabled; - - Settings settings; - settings.beginGroup("SpellCheck"); - settings.setValue("enabled", m_enabled); - settings.endGroup(); - - loadSettings(); -} - -bool Speller::dictionaryExists(const QString &path) const -{ - return QFile(path + ".dic").exists() && - QFile(path + ".aff").exists(); -} - -QString Speller::getDictionaryPath() const -{ -#ifdef Q_OS_UNIX - const QString defaultDicPath = "/usr/share/hunspell"; -#else - const QString defaultDicPath = DataPaths::path(DataPaths::AppData) + "/hunspell"; -#endif - - const QString dicPath = QString::fromLocal8Bit(qgetenv("DICPATH")).trimmed(); - return dicPath.isEmpty() ? defaultDicPath : dicPath; -} - -QString Speller::nameForLanguage(const QString &code) const -{ - QLocale locale = QLocale(code); - - QString name = QLocale::languageToString(locale.language()); - const QString scriptName = QLocale::scriptToString(locale.script()); - - if (locale.country() != QLocale::AnyCountry) { - if (code.contains(QLatin1Char('-'))) { - name.append(QL1S(" (") + scriptName + QL1S(")")); - } - name.append(QL1S(" / ") + QLocale::countryToString(locale.country())); - } - - return name; -} - -Speller::~Speller() -{ - delete m_hunspell; -} diff --git a/src/lib/plugins/qtwebkit/spellcheck/speller.h b/src/lib/plugins/qtwebkit/spellcheck/speller.h deleted file mode 100644 index e3c1657c0..000000000 --- a/src/lib/plugins/qtwebkit/spellcheck/speller.h +++ /dev/null @@ -1,110 +0,0 @@ -/* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2013-2014 David Rosca -* -* 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 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -* ============================================================ */ -#ifndef SPELLER_H -#define SPELLER_H - -#include -#include -#include -#include - -#include "qzcommon.h" - -class QTextCodec; -class Hunspell; - -class QMenu; -class QWebHitTestResult; - -class QUPZILLA_EXPORT Speller : public QObject -{ - Q_OBJECT - -public: - struct Language { - QString code; - QString name; - - bool operator==(const Language &other) { - return this->name == other.name && - this->name.left(2) == other.name.left(2); - // Compare only first two chars of name. - // So "cs_CZ - CzechRepublic" == "cs - CzechRepublic" - } - }; - - explicit Speller(); - ~Speller(); - - bool isEnabled() const; - void loadSettings(); - - Language language() const; - QVector availableLanguages(); - - QString dictionaryPath() const; - - void createContextMenu(QMenu* menu); - void populateContextMenu(QMenu* menu, const QWebHitTestResult &hitTest); - - bool isMisspelled(const QString &string); - QStringList suggest(const QString &word); - - static bool isValidWord(const QString &str); - static Speller* instance(); - -public slots: - void populateLanguagesMenu(); - void toggleEnableSpellChecking(); - -private slots: - void addToDictionary(); - void replaceWord(); - - void showSettings(); - void changeLanguage(); - -private: - void initialize(); - void putWord(const QString &word); - - bool dictionaryExists(const QString &path) const; - QString getDictionaryPath() const; - QString nameForLanguage(const QString &code) const; - - QString m_dictionaryPath; - QTextCodec* m_textCodec; - Hunspell* m_hunspell; - - QFile m_userDictionary; - Language m_language; - QVector m_availableLanguages; - bool m_enabled; - - // Replacing word - QWebElement m_element; - int m_startPos; - int m_endPos; -}; - -// Hint to QVector to use std::realloc on item moving -Q_DECLARE_TYPEINFO(Speller::Language, Q_MOVABLE_TYPE); - -Q_DECLARE_METATYPE(Speller::Language) - -#endif // SPELLER_H