File indexing completed on 2024-04-28 16:44:44

0001 /*
0002  *   SPDX-FileCopyrightText: 2007 Ryan Bitanga <ephebiphobic@gmail.com>
0003  *
0004  *   SPDX-License-Identifier: LGPL-2.0-only
0005  */
0006 
0007 #ifndef SPELLCHECK_H
0008 #define SPELLCHECK_H
0009 
0010 #include <sonnet/speller.h>
0011 
0012 #include <KRunner/AbstractRunner>
0013 #include <QMutex>
0014 #include <QSharedPointer>
0015 
0016 using namespace Plasma;
0017 
0018 /**
0019  * This checks the spelling of query
0020  */
0021 class SpellCheckRunner : public AbstractRunner
0022 {
0023     Q_OBJECT
0024 
0025 public:
0026     SpellCheckRunner(QObject *parent, const KPluginMetaData &metaData, const QVariantList &args);
0027     ~SpellCheckRunner() override;
0028 
0029     void match(RunnerContext &context) override;
0030     void run(const RunnerContext &context, const QueryMatch &action) override;
0031 
0032     void reloadConfiguration() override;
0033 
0034 protected Q_SLOTS:
0035     void init() override;
0036     QMimeData *mimeDataForMatch(const QueryMatch &match) override;
0037 
0038     void loadData();
0039     void destroydata();
0040 
0041 private:
0042     QString findLang(const QStringList &terms);
0043 
0044     QString m_triggerWord;
0045     QStringList m_availableLangCodes; // en_US, ru_RU, ...
0046     QMap<QString, QString> m_languages; // key=language name, value=language code
0047     bool m_requireTriggerWord;
0048     QMap<QString, QSharedPointer<Sonnet::Speller>> m_spellers; // spellers
0049     QMutex m_spellLock; // Lock held when constructing a new speller
0050 
0051     friend class SpellCheckRunnerTest;
0052 };
0053 
0054 #endif