kdelibs/sonnet
2014-12-04 20:34:48 +00:00
..
plugins removed aspell support 2014-11-13 03:43:42 +02:00
unicode initial import 2014-11-13 01:04:59 +02:00
CMakeLists.txt initial import 2014-11-13 01:04:59 +02:00
README initial import 2014-11-13 01:04:59 +02:00

This is KSpell 2 beta implementation. KSpell 2 is completely in
process and is plugin based.  

The main class in the KSpell 2 is the KSpell::Loader. Loader is
responsible for loading all the plugins and creating the actual
dictionaries.

Dictionaries are abstracted in the KSpell::Dictionary object which
encapsulates all spell-checking functionality.

You'll notice that the Loader is being created via the 
Loader::Ptr Loader::openLoader( KSharedConfig *config =0 );
call. The Loader is a shared object and the reason for this construct
is very simple:
- most application would need to have a few Loader objects (one for
the dialog dictionaries, one for the background spell checking, one
for the suggestion dictionaries) and because Loader loads plugins on
creation it would be ineffective to have a few redundant Loader
objects in one application,
- each Loader maps to a configuration file. If one Loader would change
in the application, all others would have to reparse and repopulate
the options, which would be really inefficient.

Due to the above you deal with the loader via the Loader::Ptr
interface. 

Once you have the Loader object in your application, you can ask it
for a Dictionary of some language. If such a dictionary is available
you get it back as a Dictionary class and you use that class to do the
actual spell checking.

Loader on construction checks for available KSpell::Client's which are
loaded as dynamic plugins. It's the actual KSpell::Client that gives
the loader the KSpell::Dictionary. 
One can specify a default client and the default language for a Loader
theough the settings() method and the KSpell::Settings class which it
returns. 

Also note that you can have dictionaries for multiple languages in
your application.
And most importantly the interface to KSpell::Dictionary is
synchronous so once you pass a word to check you don't have to wait
for any signals - you get corrections right back.
Sample usage of KSpell 2 looks like follows:

#include <kspell_loader.h>
#include <kspell_dictionary.h>
using namespace KSpell;


Loader::Ptr loader = Loader::openLoader( someKSettingsObject );
Dictionary *enDict = loader->dictionary( "en_US" );
Dictionary *deDict = loader->dictionary( "de_DE" );

void someFunc( const QString& word )
{
    if ( enDict->check( word ) ) {
        kDebug()<<"Word \""<<word<<"\" is misspelled." <<endl;
        QStringList suggestion = enDict->suggest( word );	
        kDebug()<<"Suggestions: "<< suggestions <<endl;
    }

    QStringList suggestions;
    if ( deDict->checkAndSuggest( word, suggestions ) ) {
       kDebug()<<"Wort \""<<word<<"\" ist fehlbuchstabiert." <<endl;
       kDebug()<<"Vorschlage: "<< suggestions <<endl;
    }
}

delete enDict;
delete deDict;