25 #include "defaultdictionary.h"
26 #include "dictionary.h"
28 #include <kparts/plugin.h>
29 #include <kparts/componentfactory.h>
31 #include <kplugininfo.h>
37 #include <tqptrdict.h>
40 #define DEFAULT_CONFIG_FILE "kspellrc"
48 KPluginInfo::List plugins;
52 TQMap<TQString, TQPtrList<Client> > languageClients;
57 TQPtrDict<Broker> *Broker::s_brokers = 0;
61 KSharedConfig::Ptr preventDeletion;
63 preventDeletion = KSharedConfig::openConfig( DEFAULT_CONFIG_FILE );
65 preventDeletion = config;
68 Broker *broker = s_brokers->find( preventDeletion );
77 Broker::Broker( KSharedConfig *config )
79 KSharedConfig::Ptr preventDeletion( config );
80 Q_UNUSED( preventDeletion );
83 s_brokers =
new TQPtrDict<Broker>;
84 s_brokers->insert( config,
this );
87 d->settings =
new Settings(
this, config );
90 d->defaultDictionary =
new DefaultDictionary( d->settings->defaultLanguage(),
96 kdDebug()<<
"Removing broker : "<<
this << endl;
97 s_brokers->remove( d->settings->sharedConfig() );
98 KPluginInfo::List::iterator it = d->plugins.begin();
99 while ( it != d->plugins.end() ) {
100 KPluginInfo *pluginInfo = *it;
101 it = d->plugins.remove( it );
105 delete d->settings; d->settings = 0;
111 return d->defaultDictionary;
116 TQString pclient = clientName;
117 TQString plang = language;
118 bool ddefault =
false;
120 if ( plang.isEmpty() ) {
121 plang = d->settings->defaultLanguage();
123 if ( clientName == d->settings->defaultClient() &&
124 plang == d->settings->defaultLanguage() ) {
128 TQPtrList<Client> lClients = d->languageClients[ plang ];
130 if ( lClients.isEmpty() ) {
131 kdError()<<
"No language dictionaries for the language : "<< plang <<endl;
135 TQPtrListIterator<Client> itr( lClients );
136 while ( itr.current() ) {
137 if ( !pclient.isEmpty() ) {
138 if ( pclient == itr.current()->name() ) {
139 Dictionary *dict = itr.current()->dictionary( plang );
141 dict->m_default = ddefault;
147 Dictionary *dict = itr.current()->dictionary( plang );
150 dict->m_default = ddefault;
166 return d->languageClients.keys();
174 void Broker::loadPlugins()
176 d->plugins = KPluginInfo::fromServices(
177 KTrader::self()->query(
"KSpell/Client" ) );
179 for ( KPluginInfo::List::Iterator itr = d->plugins.begin();
180 itr != d->plugins.end(); ++itr ) {
181 loadPlugin( ( *itr )->pluginName() );
185 void Broker::loadPlugin(
const TQString& pluginId )
189 kdDebug()<<
"Loading plugin " << pluginId << endl;
191 Client *client = KParts::ComponentFactory::createInstanceFromQuery<Client>(
192 TQString::fromLatin1(
"KSpell/Client" ),
193 TQString::fromLatin1(
"[X-KDE-PluginInfo-Name]=='%1'" ).arg( pluginId ),
194 this, 0, TQStringList(), &error );
198 TQStringList
languages = client->languages();
199 d->clients.append( client->name() );
201 for ( TQStringList::Iterator itr = languages.begin();
202 itr != languages.end(); ++itr ) {
203 if ( !d->languageClients[ *itr ].isEmpty() &&
204 client->reliability() < d->languageClients[ *itr ].first()->reliability() )
205 d->languageClients[ *itr ].append( client );
207 d->languageClients[ *itr ].prepend( client );
210 kdDebug() << k_funcinfo <<
"Successfully loaded plugin '"
211 << pluginId <<
"'" << endl;
217 case KParts::ComponentFactory::ErrNoServiceFound:
218 kdDebug() << k_funcinfo <<
"No service implementing the given mimetype "
219 <<
"and fullfilling the given constraint expression can be found."
222 case KParts::ComponentFactory::ErrServiceProvidesNoLibrary:
223 kdDebug() <<
"the specified service provides no shared library." << endl;
225 case KParts::ComponentFactory::ErrNoLibrary:
226 kdDebug() <<
"the specified library could not be loaded." << endl;
228 case KParts::ComponentFactory::ErrNoFactory:
229 kdDebug() <<
"the library does not export a factory for creating components."
232 case KParts::ComponentFactory::ErrNoComponent:
233 kdDebug() <<
"the factory does not support creating "
234 <<
"components of the specified type."
239 kdDebug() << k_funcinfo <<
"Loading plugin '" << pluginId
240 <<
"' failed, KLibLoader reported error: '" << endl
241 << KLibLoader::self()->lastErrorMessage() <<
"'" << endl;
245 void Broker::changed()
252 #include "broker.moc"