24 #include "defaultdictionary.h"
25 #include "dictionary.h"
27 #include <tdeparts/plugin.h>
28 #include <tdeparts/componentfactory.h>
30 #include <kplugininfo.h>
32 #include <tdeconfig.h>
36 #include <tqptrdict.h>
39 #define DEFAULT_CONFIG_FILE "tdespellrc"
47 KPluginInfo::List plugins;
51 TQMap<TQString, TQPtrList<Client> > languageClients;
56 TQPtrDict<Broker> *Broker::s_brokers = 0;
60 TDESharedConfig::Ptr preventDeletion;
62 preventDeletion = TDESharedConfig::openConfig( DEFAULT_CONFIG_FILE );
64 preventDeletion = config;
67 Broker *broker = s_brokers->find( preventDeletion );
76 Broker::Broker( TDESharedConfig *config )
78 TDESharedConfig::Ptr preventDeletion( config );
79 Q_UNUSED( preventDeletion );
82 s_brokers =
new TQPtrDict<Broker>;
83 s_brokers->insert( config,
this );
86 d->settings =
new Settings(
this, config );
89 d->defaultDictionary =
new DefaultDictionary( d->settings->defaultLanguage(),
95 kdDebug()<<
"Removing broker : "<<
this << endl;
96 s_brokers->remove( d->settings->sharedConfig() );
97 KPluginInfo::List::iterator it = d->plugins.begin();
98 while ( it != d->plugins.end() ) {
99 KPluginInfo *pluginInfo = *it;
100 it = d->plugins.remove( it );
104 delete d->settings; d->settings = 0;
110 return d->defaultDictionary;
115 TQString pclient = clientName;
116 TQString plang = language;
117 bool ddefault =
false;
119 if ( plang.isEmpty() ) {
120 plang = d->settings->defaultLanguage();
122 if ( clientName == d->settings->defaultClient() &&
123 plang == d->settings->defaultLanguage() ) {
127 TQPtrList<Client> lClients = d->languageClients[ plang ];
129 if ( lClients.isEmpty() ) {
130 kdError()<<
"No language dictionaries for the language : "<< plang <<endl;
134 TQPtrListIterator<Client> itr( lClients );
135 while ( itr.current() ) {
136 if ( !pclient.isEmpty() ) {
137 if ( pclient == itr.current()->name() ) {
138 Dictionary *dict = itr.current()->dictionary( plang );
140 dict->m_default = ddefault;
146 Dictionary *dict = itr.current()->dictionary( plang );
149 dict->m_default = ddefault;
165 return d->languageClients.keys();
173 void Broker::loadPlugins()
175 d->plugins = KPluginInfo::fromServices(
176 TDETrader::self()->query(
"KSpell/Client" ) );
178 for ( KPluginInfo::List::Iterator itr = d->plugins.begin();
179 itr != d->plugins.end(); ++itr ) {
180 loadPlugin( ( *itr )->pluginName() );
184 void Broker::loadPlugin(
const TQString& pluginId )
188 kdDebug()<<
"Loading plugin " << pluginId << endl;
190 Client *client = KParts::ComponentFactory::createInstanceFromQuery<Client>(
191 TQString::fromLatin1(
"KSpell/Client" ),
192 TQString::fromLatin1(
"[X-TDE-PluginInfo-Name]=='%1'" ).arg( pluginId ),
193 this, 0, TQStringList(), &error );
197 TQStringList
languages = client->languages();
198 d->clients.append( client->name() );
200 for ( TQStringList::Iterator itr =
languages.begin();
202 if ( !d->languageClients[ *itr ].isEmpty() &&
203 client->reliability() < d->languageClients[ *itr ].first()->reliability() )
204 d->languageClients[ *itr ].append( client );
206 d->languageClients[ *itr ].prepend( client );
209 kdDebug() << k_funcinfo <<
"Successfully loaded plugin '"
210 << pluginId <<
"'" << endl;
216 case KParts::ComponentFactory::ErrNoServiceFound:
217 kdDebug() << k_funcinfo <<
"No service implementing the given mimetype "
218 <<
"and fullfilling the given constraint expression can be found."
221 case KParts::ComponentFactory::ErrServiceProvidesNoLibrary:
222 kdDebug() <<
"the specified service provides no shared library." << endl;
224 case KParts::ComponentFactory::ErrNoLibrary:
225 kdDebug() <<
"the specified library could not be loaded." << endl;
227 case KParts::ComponentFactory::ErrNoFactory:
228 kdDebug() <<
"the library does not export a factory for creating components."
231 case KParts::ComponentFactory::ErrNoComponent:
232 kdDebug() <<
"the factory does not support creating "
233 <<
"components of the specified type."
238 kdDebug() << k_funcinfo <<
"Loading plugin '" << pluginId
239 <<
"' failed, KLibLoader reported error: '" << endl
240 << KLibLoader::self()->lastErrorMessage() <<
"'" << endl;
244 void Broker::changed()
251 #include "broker.moc"
Class used to deal with dictionaries.
TQStringList clients() const
Returns names of all supported clients (e.g.
DefaultDictionary * defaultDictionary() const
Function returns the so-called DefaultDictionary.
Dictionary * dictionary(const TQString &language=TQString::null, const TQString &client=TQString::null) const
Returns dictionary for the given language and preferred client.
Settings * settings() const
Returns the Settings object used by the broker.
void configurationChanged()
Signal is emitted whenever the Settings object associated with this Broker changes.
static Broker * openBroker(TDESharedConfig *config=0)
Constructs the broker.
TQStringList languages() const
Returns a list of supported languages.
Class is returned by from Broker.