mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
Remove qtwebkit-plugins
This commit is contained in:
parent
ebaf53f4f4
commit
d6f478be7e
|
@ -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
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#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());
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#ifndef NOTIFICATIONPRESENTER_H
|
||||
#define NOTIFICATIONPRESENTER_H
|
||||
|
||||
#include "qwebkitplatformplugin.h"
|
||||
|
||||
class NotificationPresenter : public QWebNotificationPresenter
|
||||
{
|
||||
public:
|
||||
explicit NotificationPresenter();
|
||||
|
||||
void showNotification(const QWebNotificationData* data);
|
||||
};
|
||||
|
||||
#endif // NOTIFICATIONPRESENTER_H
|
|
@ -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
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "qtwebkitplugin.h"
|
||||
#include "notifications/notificationpresenter.h"
|
||||
|
||||
#ifdef USE_HUNSPELL
|
||||
#include "spellcheck/spellcheck.h"
|
||||
#endif
|
||||
|
||||
#include <QtPlugin>
|
||||
|
||||
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
|
|
@ -1,39 +0,0 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#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
|
|
@ -1,152 +0,0 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
|
||||
// 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<GrammarDetail> &,
|
||||
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
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#ifndef SPELLCHECKER_H
|
||||
#define SPELLCHECKER_H
|
||||
|
||||
#include <QTextBoundaryFinder>
|
||||
#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<GrammarDetail> &,
|
||||
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
|
|
@ -1,137 +0,0 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "spellcheckdialog.h"
|
||||
#include "ui_spellcheckdialog.h"
|
||||
#include "datapaths.h"
|
||||
#include "settings.h"
|
||||
#include "speller.h"
|
||||
#include "qztools.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QFileDialog>
|
||||
#include <QInputDialog>
|
||||
|
||||
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;
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#ifndef SPELLCHECKDIALOG_H
|
||||
#define SPELLCHECKDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#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
|
|
@ -1,168 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SpellCheckDialog</class>
|
||||
<widget class="QDialog" name="SpellCheckDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>441</width>
|
||||
<height>305</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>SpellCheck</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string><b>Dictionary path</b></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="dictPath">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="MacToolButton" name="changeDictPath">
|
||||
<property name="text">
|
||||
<string>Change...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string><b>User dictionary</b></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QListWidget" name="userDictList"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="add">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="remove">
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="textLabel">
|
||||
<property name="text">
|
||||
<string>Using Hunspell library</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>MacToolButton</class>
|
||||
<extends>QToolButton</extends>
|
||||
<header>mactoolbutton.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>SpellCheckDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>SpellCheckDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
|
@ -1,424 +0,0 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "speller.h"
|
||||
#include "spellcheckdialog.h"
|
||||
#include "settings.h"
|
||||
#include "datapaths.h"
|
||||
#include "mainapplication.h"
|
||||
#include "qztools.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QTextCodec>
|
||||
#include <QTextStream>
|
||||
#include <QFile>
|
||||
#include <QLocale>
|
||||
#include <QDirIterator>
|
||||
#include <QWebHitTestResult>
|
||||
#include <QTextBoundaryFinder>
|
||||
#include <QTextStream>
|
||||
#include <QMenu>
|
||||
|
||||
#include <hunspell/hunspell.hxx>
|
||||
|
||||
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::Language> 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<QAction*>(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<QAction*>(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<QAction*>(sender());
|
||||
|
||||
if (!act) {
|
||||
return;
|
||||
}
|
||||
|
||||
Language lang = act->data().value<Language>();
|
||||
|
||||
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<QMenu*>(sender());
|
||||
|
||||
if (!menu || !menu->isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QVector<Language> 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;
|
||||
}
|
|
@ -1,110 +0,0 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#ifndef SPELLER_H
|
||||
#define SPELLER_H
|
||||
|
||||
#include <QWebElement>
|
||||
#include <QStringList>
|
||||
#include <QVector>
|
||||
#include <QFile>
|
||||
|
||||
#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<Language> 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<Language> 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
|
Loading…
Reference in New Issue
Block a user