adapt patch from Mitz Pettel <mitz@webkit.org>
[kdelibs.git] / sonnet / README
blobbffd26f0f019a94415e58bd7c9ac5cb13dd12935
1 This is KSpell 2 beta implementation. KSpell 2 is completely in
2 process and is plugin based.  
4 The main class in the KSpell 2 is the KSpell::Loader. Loader is
5 responsible for loading all the plugins and creating the actual
6 dictionaries.
8 Dictionaries are abstracted in the KSpell::Dictionary object which
9 encapsulates all spell-checking functionality.
11 You'll notice that the Loader is being created via the 
12 Loader::Ptr Loader::openLoader( KSharedConfig *config =0 );
13 call. The Loader is a shared object and the reason for this construct
14 is very simple:
15 - most application would need to have a few Loader objects (one for
16 the dialog dictionaries, one for the background spell checking, one
17 for the suggestion dictionaries) and because Loader loads plugins on
18 creation it would be ineffective to have a few redundant Loader
19 objects in one application,
20 - each Loader maps to a configuration file. If one Loader would change
21 in the application, all others would have to reparse and repopulate
22 the options, which would be really inefficient.
24 Due to the above you deal with the loader via the Loader::Ptr
25 interface. 
27 Once you have the Loader object in your application, you can ask it
28 for a Dictionary of some language. If such a dictionary is available
29 you get it back as a Dictionary class and you use that class to do the
30 actual spell checking.
32 Loader on construction checks for available KSpell::Client's which are
33 loaded as dynamic plugins. It's the actual KSpell::Client that gives
34 the loader the KSpell::Dictionary. 
35 One can specify a default client and the default language for a Loader
36 theough the settings() method and the KSpell::Settings class which it
37 returns. 
39 Also note that you can have dictionaries for multiple languages in
40 your application.
41 And most importantly the interface to KSpell::Dictionary is
42 synchronous so once you pass a word to check you don't have to wait
43 for any signals - you get corrections right back.
44 Sample usage of KSpell 2 looks like follows:
46 #include <kspell_loader.h>
47 #include <kspell_dictionary.h>
48 using namespace KSpell;
51 Loader::Ptr loader = Loader::openLoader( someKSettingsObject );
52 Dictionary *enDict = loader->dictionary( "en_US" );
53 Dictionary *deDict = loader->dictionary( "de_DE" );
55 void someFunc( const QString& word )
57     if ( enDict->check( word ) ) {
58         kDebug()<<"Word \""<<word<<"\" is misspelled." <<endl;
59         QStringList suggestion = enDict->suggest( word );       
60         kDebug()<<"Suggestions: "<< suggestions <<endl;
61     }
63     QStringList suggestions;
64     if ( deDict->checkAndSuggest( word, suggestions ) ) {
65        kDebug()<<"Wort \""<<word<<"\" ist fehlbuchstabiert." <<endl;
66        kDebug()<<"Vorschlage: "<< suggestions <<endl;
67     }
70 delete enDict;
71 delete deDict;