generic: port to the new spelling classes

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-06-09 20:30:46 +03:00
parent 2dff528754
commit 15319dc6bc
18 changed files with 82 additions and 157 deletions

View file

@ -59,7 +59,6 @@
#include <kio/job.h>
#include <kio/jobclasses.h>
#include <kio/netaccess.h>
#include <kapplication.h>
#include <kcharsets.h>
#include <kcolorbutton.h>
@ -88,6 +87,7 @@
#include <kactioncollection.h>
#include <kplugininfo.h>
#include <ktabwidget.h>
#include <kspeller.h>
#include <QtCore/QFile>
#include <QtCore/QMap>
@ -342,9 +342,9 @@ KateSpellCheckConfigTab::KateSpellCheckConfigTab(QWidget *parent)
//
// after initial reload, connect the stuff for the changed () signal
m_sonnetConfigWidget = new Sonnet::ConfigWidget(KGlobal::config().data(), this);
connect(m_sonnetConfigWidget, SIGNAL(configChanged()), this, SLOT(slotChanged()));
layout->addWidget(m_sonnetConfigWidget);
m_spellConfigWidget = new KSpellConfigWidget(KGlobal::config().data(), this);
connect(m_spellConfigWidget, SIGNAL(configChanged()), this, SLOT(slotChanged()));
layout->addWidget(m_spellConfigWidget);
layout->addWidget(newWidget);
setLayout(layout);
@ -369,7 +369,7 @@ void KateSpellCheckConfigTab::apply()
m_changed = false;
KateDocumentConfig::global()->configStart();
m_sonnetConfigWidget->save();
m_spellConfigWidget->save();
KateDocumentConfig::global()->configEnd();
foreach (KateDocument *doc, KateGlobal::self()->kateDocuments()) {
doc->refreshOnTheFlyCheck();
@ -1062,7 +1062,7 @@ KateDictionaryBar::KateDictionaryBar(KateView* view, QWidget *parent)
QHBoxLayout *topLayout = new QHBoxLayout(centralWidget());
topLayout->setMargin(0);
//topLayout->setSpacing(spacingHint());
m_dictionaryComboBox = new Sonnet::DictionaryComboBox(centralWidget());
m_dictionaryComboBox = new KSpellDictionaryComboBox(centralWidget());
connect(m_dictionaryComboBox, SIGNAL(dictionaryChanged(QString)),
this, SLOT(dictionaryChanged(QString)));
connect(view->doc(), SIGNAL(defaultDictionaryChanged(KateDocument*)),
@ -1085,7 +1085,7 @@ void KateDictionaryBar::updateData()
KateDocument *document = m_view->doc();
QString dictionary = document->defaultDictionary();
if(dictionary.isEmpty()) {
dictionary = Sonnet::Speller().defaultLanguage();
dictionary = KSpeller::defaultLanguage();
}
m_dictionaryComboBox->setCurrentByDictionary(dictionary);
}

View file

@ -38,9 +38,8 @@
#include <kdialog.h>
#include <kfiledialog.h>
#include <kmimetype.h>
#include <sonnet/configwidget.h>
#include <sonnet/dictionarycombobox.h>
#include <kspellconfigwidget.h>
#include <kspelldictionarycombobox.h>
#include <QtCore/QProcess>
#include <QtCore/QStringList>
@ -148,7 +147,7 @@ class KateDictionaryBar : public KateViewBarWidget
private:
KateView* m_view;
Sonnet::DictionaryComboBox *m_dictionaryComboBox;
KSpellDictionaryComboBox *m_dictionaryComboBox;
};
class KateIndentConfigTab : public KateConfigPage
@ -240,7 +239,7 @@ class KateSpellCheckConfigTab : public KateConfigPage
protected:
Ui::SpellCheckConfigWidget *ui;
Sonnet::ConfigWidget *m_sonnetConfigWidget;
KSpellConfigWidget *m_spellConfigWidget;
public Q_SLOTS:
void apply ();

View file

@ -61,7 +61,7 @@ KateOnTheFlyChecker::KateOnTheFlyChecker(KateDocument *document)
connect(&document->buffer(), SIGNAL(respellCheckBlock(int,int)),
this, SLOT(handleRespellCheckBlock(int,int)));
// load the settings for the speller
// creates speller and loads the settings for it
updateConfig();
foreach(KTextEditor::View* view, document->views()) {
@ -394,24 +394,14 @@ void KateOnTheFlyChecker::performSpellCheck()
m_currentDecToEncOffsetList,
encToDecOffsetList);
ON_THE_FLY_DEBUG << "next spell checking" << text;
if(text.isEmpty()) { // passing an empty string to Sonnet can lead to a bad allocation exception
if(text.isEmpty()) { // passing an empty string to speller can lead to a bad allocation exception
spellCheckDone(); // (bug 225867)
return;
}
if(m_speller.language() != language) {
m_speller.setLanguage(language);
}
if(!m_backgroundChecker) {
m_backgroundChecker = new Sonnet::BackgroundChecker(m_speller, this);
connect(m_backgroundChecker,
SIGNAL(misspelling(QString,int)),
this,
SLOT(misspelling(QString,int)));
connect(m_backgroundChecker, SIGNAL(done()), this, SLOT(spellCheckDone()));
m_backgroundChecker->restore(KGlobal::config().data());
updateConfig();
}
m_backgroundChecker->setSpeller(m_speller);
m_backgroundChecker->changeLanguage(language);
m_backgroundChecker->setText(text); // don't call 'start()' after this!
}
@ -628,10 +618,6 @@ void KateOnTheFlyChecker::misspelling(const QString &word, int start)
movingRange->setAttribute(KTextEditor::Attribute::Ptr(attribute));
m_misspelledList.push_back(MisspelledItem(movingRange, m_currentlyCheckedItem.second));
if(m_backgroundChecker) {
m_backgroundChecker->continueChecking();
}
}
void KateOnTheFlyChecker::spellCheckDone()
@ -667,11 +653,17 @@ QList<KTextEditor::MovingRange*> KateOnTheFlyChecker::installedMovingRanges(cons
void KateOnTheFlyChecker::updateConfig()
{
ON_THE_FLY_DEBUG;
m_speller.restore(KGlobal::config().data());
if(m_backgroundChecker) {
m_backgroundChecker->restore(KGlobal::config().data());
delete m_backgroundChecker;
m_backgroundChecker = nullptr;
}
m_backgroundChecker = new KSpellBackgroundChecker(KGlobal::config().data(), this);
connect(m_backgroundChecker,
SIGNAL(misspelling(QString,int)),
this,
SLOT(misspelling(QString,int)));
connect(m_backgroundChecker, SIGNAL(done()), this, SLOT(spellCheckDone()));
}
void KateOnTheFlyChecker::refreshSpellCheck(const KTextEditor::Range &range)

View file

@ -30,14 +30,10 @@
#include <QSet>
#include <QTimer>
#include <sonnet/speller.h>
#include <kspellbackgroundchecker.h>
#include "katedocument.h"
namespace Sonnet {
class BackgroundChecker;
}
class KateOnTheFlyChecker : public QObject, private KTextEditor::MovingRangeFeedback {
Q_OBJECT
@ -73,9 +69,8 @@ class KateOnTheFlyChecker : public QObject, private KTextEditor::MovingRangeFeed
protected:
KateDocument *const m_document;
Sonnet::Speller m_speller;
QList<SpellCheckItem> m_spellCheckQueue;
Sonnet::BackgroundChecker *m_backgroundChecker;
KSpellBackgroundChecker *m_backgroundChecker;
SpellCheckItem m_currentlyCheckedItem;
static const SpellCheckItem invalidSpellCheckQueueItem;
MisspelledList m_misspelledList;

View file

@ -30,7 +30,7 @@
#include <kactioncollection.h>
#include <ktexteditor/view.h>
#include <sonnet/speller.h>
#include <kspeller.h>
#include "katedocument.h"
#include "katehighlight.h"
@ -46,22 +46,22 @@ KateSpellCheckManager::~KateSpellCheckManager()
QStringList KateSpellCheckManager::suggestions(const QString& word, const QString& dictionary)
{
Sonnet::Speller speller;
speller.setLanguage(dictionary);
KSpeller speller(KGlobal::config().data());
speller.setDictionary(dictionary);
return speller.suggest(word);
}
void KateSpellCheckManager::ignoreWord(const QString& word, const QString& dictionary)
{
Sonnet::Speller speller;
speller.setLanguage(dictionary);
KSpeller speller(KGlobal::config().data());
speller.setDictionary(dictionary);
speller.addToSession(word);
}
void KateSpellCheckManager::addToDictionary(const QString& word, const QString& dictionary)
{
Sonnet::Speller speller;
speller.setLanguage(dictionary);
KSpeller speller(KGlobal::config().data());
speller.setDictionary(dictionary);
speller.addToPersonal(word);
}

View file

@ -27,8 +27,6 @@
#include <QString>
#include <ktexteditor/document.h>
#include <sonnet/backgroundchecker.h>
#include <sonnet/speller.h>
class KateDocument;
class KateView;

View file

@ -36,16 +36,12 @@
#include <kactioncollection.h>
#include <kicon.h>
#include <kstandardaction.h>
#include <sonnet/dialog.h>
#include <sonnet/backgroundchecker.h>
#include <sonnet/speller.h>
#include <kspelldialog.h>
KateSpellCheckDialog::KateSpellCheckDialog( KateView* view )
: QObject( view )
, m_view (view)
, m_speller (NULL)
, m_backgroundChecker(NULL)
, m_sonnetDialog(NULL)
, m_spellDialog(NULL)
, m_globalSpellCheckRange(NULL)
, m_spellCheckCancelledByUser(false)
{
@ -54,9 +50,7 @@ KateSpellCheckDialog::KateSpellCheckDialog( KateView* view )
KateSpellCheckDialog::~KateSpellCheckDialog()
{
delete m_globalSpellCheckRange;
delete m_sonnetDialog;
delete m_backgroundChecker;
delete m_speller;
delete m_spellDialog;
}
void KateSpellCheckDialog::createActions( KActionCollection* ac )
@ -106,41 +100,27 @@ void KateSpellCheckDialog::spellcheck( const KTextEditor::Cursor &from, const KT
end = m_view->doc()->documentEnd();
}
if ( !m_speller )
if ( !m_spellDialog )
{
m_speller = new Sonnet::Speller();
}
m_speller->restore(KGlobal::config().data());
m_spellDialog = new KSpellDialog(KGlobal::config().data(), m_view);
m_spellDialog->showSpellCheckCompletionMessage();
m_spellDialog->setSpellCheckContinuedAfterReplacement(false);
if ( !m_backgroundChecker )
{
m_backgroundChecker = new Sonnet::BackgroundChecker(*m_speller);
}
connect(m_spellDialog,SIGNAL(accepted()),this,SLOT(installNextSpellCheckRange()));
m_backgroundChecker->restore(KGlobal::config().data());
if ( !m_sonnetDialog )
{
m_sonnetDialog = new Sonnet::Dialog(m_backgroundChecker, m_view);
m_sonnetDialog->showProgressDialog(200);
m_sonnetDialog->showSpellCheckCompletionMessage();
m_sonnetDialog->setSpellCheckContinuedAfterReplacement(false);
connect(m_sonnetDialog,SIGNAL(done(QString)),this,SLOT(installNextSpellCheckRange()));
connect(m_sonnetDialog,SIGNAL(replace(QString,int,QString)),
connect(m_spellDialog,SIGNAL(replace(QString,int,QString)),
this,SLOT(corrected(QString,int,QString)));
connect(m_sonnetDialog,SIGNAL(misspelling(QString,int)),
connect(m_spellDialog,SIGNAL(misspelling(QString,int)),
this,SLOT(misspelling(QString,int)));
connect(m_sonnetDialog,SIGNAL(cancel()),
connect(m_spellDialog,SIGNAL(rejected()),
this,SLOT(cancelClicked()));
connect(m_sonnetDialog,SIGNAL(destroyed(QObject*)),
connect(m_spellDialog,SIGNAL(destroyed(QObject*)),
this,SLOT(objectDestroyed(QObject*)));
connect(m_sonnetDialog,SIGNAL(languageChanged(QString)),
connect(m_spellDialog,SIGNAL(languageChanged(QString)),
this,SLOT(languageChanged(QString)));
}
@ -206,7 +186,7 @@ void KateSpellCheckDialog::corrected( const QString& word, int pos, const QStrin
m_currentSpellCheckRange.setRange( KTextEditor::Range( replacementStartCursor, m_currentSpellCheckRange.end() ) );
// we have to be careful here: due to static word wrapping the text might change in addition to simply
// the misspelled word being replaced, i.e. new line breaks might be inserted as well. As such, the text
// in the 'Sonnet::Dialog' might be eventually out of sync with the visible text. Therefore, we 'restart'
// in the 'KSpellDialog' might be eventually out of sync with the visible text. Therefore, we 'restart'
// spell checking from the current position.
performSpellCheck( KTextEditor::Range( replacementStartCursor, m_globalSpellCheckRange->end().toCursor() ) );
}
@ -222,7 +202,7 @@ void KateSpellCheckDialog::performSpellCheck(const KTextEditor::Range& range)
installNextSpellCheckRange();
// first check if there is really something to spell check
if(m_currentSpellCheckRange.isValid()) {
m_sonnetDialog->show();
m_spellDialog->show();
}
}
@ -283,19 +263,15 @@ void KateSpellCheckDialog::installNextSpellCheckRange()
QString text = m_view->doc()->decodeCharacters(m_currentSpellCheckRange,
m_currentDecToEncOffsetList,
encToDecOffsetList);
// ensure that no empty string is passed on to Sonnet as this can lead to a crash
// ensure that no empty string is passed on to speller as this can lead to a crash
// (bug 228789)
if(text.isEmpty()) {
nextRangeBegin = m_currentSpellCheckRange.end();
continue;
}
if(m_speller->language() != dictionary) {
m_speller->setLanguage(dictionary);
m_backgroundChecker->setSpeller(*m_speller);
}
m_sonnetDialog->setBuffer(text);
m_spellDialog->changeLanguage(dictionary);
m_spellDialog->setBuffer(text);
break;
}
}
@ -321,7 +297,7 @@ void KateSpellCheckDialog::spellCheckDone()
void KateSpellCheckDialog::objectDestroyed(QObject *object)
{
Q_UNUSED(object);
m_sonnetDialog = NULL;
m_spellDialog = NULL;
}
void KateSpellCheckDialog::languageChanged(const QString &language)

View file

@ -34,11 +34,7 @@ class KateView;
class KAction;
class KActionCollection;
class KProgressDialog;
namespace Sonnet {
class Dialog;
class BackgroundChecker;
class Speller;
}
class KSpellDialog;
#include "ktexteditor/range.h"
@ -93,9 +89,7 @@ class KateSpellCheckDialog : public QObject
KateView *m_view;
KAction *m_spellcheckSelection;
Sonnet::Speller *m_speller;
Sonnet::BackgroundChecker *m_backgroundChecker;
Sonnet::Dialog *m_sonnetDialog;
KSpellDialog *m_spellDialog;
// define the part of the text that is to be checked
KTextEditor::Range m_currentSpellCheckRange;

View file

@ -35,7 +35,7 @@
#include <kiconloader.h>
#include <klocale.h>
#include <kcolorcombo.h>
#include <sonnet/dictionarycombobox.h>
#include <kspelldictionarycombobox.h>
//BEGIN VariableEditor
VariableEditor::VariableEditor(VariableItem* item, QWidget* parent)
@ -316,7 +316,7 @@ VariableSpellCheckEditor::VariableSpellCheckEditor(VariableSpellCheckItem *item,
{
QGridLayout *l = (QGridLayout*) layout();
m_dictionaryCombo = new Sonnet::DictionaryComboBox(this);
m_dictionaryCombo = new KSpellDictionaryComboBox(this);
m_dictionaryCombo->setCurrentByDictionary(item->value());
l->addWidget(m_dictionaryCombo, 0, 2, Qt::AlignLeft);

View file

@ -21,7 +21,12 @@
#ifndef VARIABLE_EDITOR_H
#define VARIABLE_EDITOR_H
#include <QtGui/QWidget>
#include <QWidget>
#include <QCheckBox>
#include <QComboBox>
#include <QLabel>
#include <QLineEdit>
#include <QSpinBox>
class KateHelpButton;
@ -37,15 +42,7 @@ class VariableRemoveSpacesItem;
class KColorCombo;
class KFontComboBox;
#include <QCheckBox>
#include <QComboBox>
#include <QLabel>
#include <QLineEdit>
#include <QSpinBox>
namespace Sonnet {
class DictionaryComboBox;
}
class KSpellDictionaryComboBox;
class VariableEditor : public QWidget
{
@ -169,7 +166,7 @@ protected Q_SLOTS:
void setItemValue(const QString& newValue);
private:
Sonnet::DictionaryComboBox *m_dictionaryCombo;
KSpellDictionaryComboBox *m_dictionaryCombo;
};

View file

@ -42,7 +42,7 @@
#include <kdialog.h>
#include <klocale.h>
#include <sonnet/speller.h>
#include <kspeller.h>
VariableLineEdit::VariableLineEdit(QWidget* parent)
: QWidget(parent)
@ -179,8 +179,7 @@ void VariableLineEdit::addKateItems(VariableListView* listview)
listview->addItem(item);
// Add 'default-dictionary' to list
Sonnet::Speller speller;
item = new VariableSpellCheckItem("default-dictionary", speller.defaultLanguage());
item = new VariableSpellCheckItem("default-dictionary", KSpeller::defaultLanguage());
item->setHelpText(i18nc("short translation please", "Set the default dictionary used for spell checking."));
listview->addItem(item);

View file

@ -23,7 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "spellchecking.h"
#include <kpluginfactory.h>
#include <sonnet/configwidget.h>
#include <kspellconfigwidget.h>
#include <QBoxLayout>
@ -33,17 +33,17 @@ K_EXPORT_PLUGIN(SpellFactory( "kcmspellchecking" ))
SonnetSpellCheckingModule::SonnetSpellCheckingModule(QWidget* parent, const QVariantList&):
KCModule(SpellFactory::componentData(), parent)
{
QBoxLayout *layout = new QVBoxLayout( this );
layout->setMargin(0);
m_config = new KConfig("sonnetrc");
m_configWidget = new Sonnet::ConfigWidget( m_config, this );
layout->addWidget(m_configWidget);
connect(m_configWidget, SIGNAL(configChanged()), this, SLOT(changed()));
QBoxLayout *layout = new QVBoxLayout( this );
layout->setMargin(0);
m_config = new KConfig("kdeglobals");
m_configWidget = new KSpellConfigWidget( m_config, this );
layout->addWidget(m_configWidget);
connect(m_configWidget, SIGNAL(configChanged()), this, SLOT(changed()));
}
SonnetSpellCheckingModule::~SonnetSpellCheckingModule()
{
delete m_config;
delete m_config;
}
void SonnetSpellCheckingModule::save()

View file

@ -26,11 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "kcmodule.h"
class KConfig;
namespace Sonnet
{
class ConfigWidget;
}
class KSpellConfigWidget;
class SonnetSpellCheckingModule : public KCModule
{
@ -44,7 +40,7 @@ class SonnetSpellCheckingModule : public KCModule
void defaults();
private:
Sonnet::ConfigWidget *m_configWidget;
KSpellConfigWidget *m_configWidget;
KConfig *m_config;
};

View file

@ -24,8 +24,7 @@
#include <KStandardAction>
#include <KActionCollection>
#include <KAction>
#include <sonnet/dialog.h>
#include <sonnet/backgroundchecker.h>
#include <KSpellDialog>
KLineSpellChecking::KLineSpellChecking(QWidget* parent)
: KLineEdit(parent)
@ -43,12 +42,9 @@ void KLineSpellChecking::slotCheckSpelling()
if ( text().isEmpty() ) {
return;
}
Sonnet::Dialog *spellDialog = new Sonnet::Dialog(new Sonnet::BackgroundChecker(this), 0);
KSpellDialog *spellDialog = new KSpellDialog(KGlobal::config().data(), 0);
connect(spellDialog, SIGNAL(replace(QString,int,QString)), this, SLOT(spellCheckerCorrected(QString,int,QString)));
connect(spellDialog, SIGNAL(misspelling(QString,int)), this, SLOT(spellCheckerMisspelling(QString,int)));
connect(spellDialog, SIGNAL(done(QString)), this, SLOT(slotSpellCheckDone(QString)));
connect(spellDialog, SIGNAL(cancel()), this, SLOT(spellCheckerFinished()));
connect(spellDialog, SIGNAL(stop()), this, SLOT(spellCheckerFinished()));
spellDialog->setBuffer(text());
spellDialog->show();
}
@ -73,16 +69,6 @@ void KLineSpellChecking::spellCheckerCorrected( const QString &old, int pos, con
}
}
void KLineSpellChecking::spellCheckerFinished()
{
}
void KLineSpellChecking::slotSpellCheckDone( const QString &s )
{
if( s != text() )
setText( s );
}
void KLineSpellChecking::contextMenuEvent(QContextMenuEvent *e)
{
QMenu* popup = createStandardContextMenu();

View file

@ -37,10 +37,8 @@ protected:
private slots:
void slotCheckSpelling();
void slotSpellCheckDone( const QString &s );
void spellCheckerMisspelling( const QString &text, int pos);
void spellCheckerCorrected( const QString &, int, const QString &);
void spellCheckerFinished();
private:
KAction *m_spellAction;

View file

@ -34,7 +34,6 @@
#include <KStandardAction>
#include <KStandardShortcut>
#include <KXMLGUIFactory>
#include <sonnet/configdialog.h>
#include "treeview.h"
#include "basictab.h"

View file

@ -24,7 +24,6 @@
#include <KLocale>
#include <KConfigGroup>
#include <sonnet/configwidget.h>
PreferencesDialog::PreferencesDialog( QWidget *parent )
: KPageDialog( parent )
@ -57,7 +56,7 @@ SpellCheckingPage::SpellCheckingPage( QWidget *parent )
: QWidget( parent )
{
QHBoxLayout *lay = new QHBoxLayout( this );
m_confPage = new Sonnet::ConfigWidget(&( *KGlobal::config() ), this );
m_confPage = new KSpellConfigWidget(KGlobal::config().data(), this );
lay->addWidget( m_confPage );
setLayout( lay );
}

View file

@ -20,15 +20,12 @@
#ifndef PREFERENCESDLG_H
#define PREFERENCESDLG_H
#include <QCheckBox>
#include <KPageDialog>
#include <KSpellConfigWidget>
class SpellCheckingPage;
class MiscPage;
#include <QCheckBox>
namespace Sonnet {
class ConfigWidget;
}
class PreferencesDialog : public KPageDialog
{
@ -51,7 +48,7 @@ public:
SpellCheckingPage( QWidget * );
void saveOptions();
private:
Sonnet::ConfigWidget *m_confPage;
KSpellConfigWidget *m_confPage;
};
class MiscPage : public QWidget