Commit a8b8b032 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

improve++

parent 20e75607
......@@ -8,6 +8,7 @@ set(libgrammar_SRCS
backgroundgrammarchecker.cpp
grammarsettings.cpp
grammarplugin.cpp
grammarloader.cpp
widgets/grammarcomboboxlanguage.cpp
widgets/grammarconfigurewidget.cpp
)
......
......@@ -25,3 +25,4 @@ GrammarClient::GrammarClient(QObject *parent)
}
}
#include "grammarclient_p.moc"
......@@ -26,6 +26,7 @@
namespace Grammar {
class GrammarPlugin;
class GRAMMAR_EXPORT GrammarClient : public QObject
{
Q_OBJECT
......@@ -35,6 +36,8 @@ public:
virtual QStringList languages() const = 0;
virtual QString name() const = 0;
virtual Grammar::GrammarPlugin *createGrammarChecker(const QString &language) = 0;
};
}
......
/*
Copyright (c) 2013 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "grammarloader.h"
#include "grammarclient_p.h"
#include <kservicetypetrader.h>
namespace Grammar {
class GrammarLoaderPrivate
{
public:
GrammarLoaderPrivate()
{
loadPlugins();
}
void loadPlugins()
{
plugins = KServiceTypeTrader::self()->query(QString::fromLatin1("Grammar/GrammarClient"));
KService::List::const_iterator end(plugins.constEnd());
for (KService::List::const_iterator itr = plugins.constBegin(); itr != end; ++itr ) {
loadPlugin((*itr));
}
}
void loadPlugin(const KSharedPtr<KService> &service)
{
QString error;
Grammar::GrammarClient *client = service->createInstance<Grammar::GrammarClient>(this, QVariantList(), &error);
if (client) {
const QStringList languages = client->languages();
clients.append(client->name());
#if 0
for (QStringList::const_iterator itr = languages.begin();
itr != languages.end(); ++itr) {
if (!d->languageClients[*itr].isEmpty() &&
client->reliability() <
d->languageClients[*itr].first()->reliability())
d->languageClients[*itr].append(client);
else
d->languageClients[*itr].prepend(client);
}
#endif
//kDebug() << "Successfully loaded plugin:" << service->entryPath();
} else {
kDebug() << error;
}
}
KService::List plugins;
};
GrammarLoader::GrammarLoader()
: d(new GrammarLoaderPrivate)
{
}
GrammarLoader::~GrammarLoader()
{
delete d;
}
QStringList GrammarLoader::clients() const
{
return d->clients;
}
}
#include "grammarloader.moc"
/*
Copyright (c) 2013 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef GRAMMARLOADER_H
#define GRAMMARLOADER_H
#include <QObject>
#include "grammar_export.h"
namespace Grammar {
class GrammarLoaderPrivate;
class GRAMMAR_EXPORT GrammarLoader : public QObject
{
Q_OBJECT
public:
GrammarLoader();
~GrammarLoader();
QStringList clients() const;
private:
friend class GrammarLoaderPrivate;
GrammarLoaderPrivate * const d;
};
}
#endif // GRAMMARLOADER_H
......@@ -17,8 +17,7 @@
#include "grammarlinkclient.h"
#include <link-grammar/link-includes.h>
#include "grammarlinkplugin.h"
#include <kpluginfactory.h>
#include <kpluginloader.h>
......@@ -37,6 +36,12 @@ GrammarLinkClient::~GrammarLinkClient()
}
Grammar::GrammarPlugin *GrammarLinkClient::createGrammarChecker(const QString &language)
{
GrammarLinkPlugin *plugin = new GrammarLinkPlugin(language);
return plugin;
}
QStringList GrammarLinkClient::languages() const
{
//TODO
......
......@@ -20,6 +20,7 @@
#define GRAMMARLINKCLIENT_H
#include "grammar/grammarclient_p.h"
#include "grammar/grammarplugin_p.h"
#include <QtCore/QVariantList>
class GrammarLinkClient : public Grammar::GrammarClient
......@@ -29,6 +30,8 @@ public:
GrammarLinkClient(QObject *parent, const QVariantList &);
~GrammarLinkClient();
Grammar::GrammarPlugin *createGrammarChecker(const QString &language);
QStringList languages() const;
QString name() const;
......
......@@ -17,11 +17,24 @@
#include "grammarlinkplugin.h"
#include <locale.h>
#include <QDebug>
GrammarLinkPlugin::GrammarLinkPlugin(const QString &language)
: Grammar::GrammarPlugin(language)
{
setlocale(LC_ALL, "");
mOpts = parse_options_create();
mDict = dictionary_create_lang(language.toLatin1());
if (!mDict) {
qDebug()<<" dictionary for language "<<language<<" not found";
}
}
GrammarLinkPlugin::~GrammarLinkPlugin()
{
if (mDict)
dictionary_delete(mDict);
if (mOpts)
parse_options_delete(mOpts);
}
......@@ -16,7 +16,9 @@
*/
#include "grammar/grammarplugin_p.h"
extern "C" {
#include <link-grammar/link-includes.h>
}
#ifndef GRAMMARLINKPLUGIN_H
#define GRAMMARLINKPLUGIN_H
......@@ -25,6 +27,9 @@ class GrammarLinkPlugin : public Grammar::GrammarPlugin
public:
GrammarLinkPlugin(const QString &language);
~GrammarLinkPlugin();
private:
Dictionary mDict;
Parse_Options mOpts;
};
#endif // GRAMMARLINKPLUGIN_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment