17 #include "pluginmanager.h"
24 #include <klibloader.h>
26 #include <tdelocale.h>
27 #include <tdemessagebox.h>
30 using Akregator::Plugin;
34 vector<PluginManager::StoreItem>
35 PluginManager::m_store;
43 PluginManager::query(
const TQString& constraint )
47 str =
"[X-TDE-akregator-framework-version] == ";
48 str += TQString::number( FrameworkVersion );
50 if (!constraint.stripWhiteSpace().isEmpty())
51 str += constraint +
" and ";
52 str +=
"[X-TDE-akregator-rank] > 0";
54 kdDebug() <<
"Plugin trader constraint: " << str << endl;
56 return TDETrader::self()->query(
"Akregator/Plugin", str );
61 PluginManager::createFromQuery(
const TQString &constraint )
63 TDETrader::OfferList offers = query( constraint );
65 if ( offers.isEmpty() ) {
66 kdWarning() << k_funcinfo <<
"No matching plugin found.\n";
73 for ( uint i = 0; i < offers.count(); i++ ) {
74 if ( offers[i]->property(
"X-TDE-akregator-rank" ).toInt() > rank )
78 return createFromService( offers[current] );
83 PluginManager::createFromService(
const KService::Ptr service )
85 kdDebug() <<
"Trying to load: " << service->library() << endl;
88 KLibLoader *loader = KLibLoader::self();
90 KLibrary *lib = loader->globalLibrary( TQFile::encodeName( service->library() ) );
93 KMessageBox::error( 0, i18n(
"<p>KLibLoader could not load the plugin:<br/><i>%1</i></p>"
94 "<p>Error message:<br/><i>%2</i></p>" )
95 .arg( service->library() )
96 .arg( loader->lastErrorMessage() ) );
100 Plugin* (*create_plugin)() = ( Plugin* (*)() ) lib->symbol( "create_plugin" );
102 if ( !create_plugin ) {
103 kdWarning() << k_funcinfo <<
"create_plugin == NULL\n";
107 Plugin* plugin = create_plugin();
111 item.plugin = plugin;
113 item.service = service;
114 m_store.push_back( item );
122 PluginManager::unload( Plugin* plugin )
124 vector<StoreItem>::iterator iter = lookupPlugin( plugin );
126 if ( iter != m_store.end() ) {
127 delete (*iter).plugin;
128 kdDebug() <<
"Unloading library: "<< (*iter).service->library() << endl;
129 (*iter).library->unload();
131 m_store.erase( iter );
134 kdWarning() << k_funcinfo <<
"Could not unload plugin (not found in store).\n";
139 PluginManager::getService(
const Plugin* plugin )
142 kdWarning() << k_funcinfo <<
"pointer == NULL\n";
147 vector<StoreItem>::const_iterator iter = lookupPlugin( plugin );
149 if ( iter == m_store.end() )
150 kdWarning() << k_funcinfo <<
"Plugin not found in store.\n";
152 return (*iter).service;
157 PluginManager::showAbout(
const TQString &constraint )
159 TDETrader::OfferList offers = query( constraint );
161 if ( offers.isEmpty() )
164 KService::Ptr s = offers.front();
166 const TQString body =
"<tr><td>%1</td><td>%2</td></tr>";
168 TQString str =
"<html><body><table width=\"100%\" border=\"1\">";
170 str += body.arg( i18n(
"Name" ), s->name() );
171 str += body.arg( i18n(
"Library" ), s->library() );
172 str += body.arg( i18n(
"Authors" ), s->property(
"X-TDE-akregator-authors" ).toStringList().join(
"\n" ) );
173 str += body.arg( i18n(
"Email" ), s->property(
"X-TDE-akregator-email" ).toStringList().join(
"\n" ) );
174 str += body.arg( i18n(
"Version" ), s->property(
"X-TDE-akregator-version" ).toString() );
175 str += body.arg( i18n(
"Framework Version" ), s->property(
"X-TDE-akregator-framework-version" ).toString() );
177 str +=
"</table></body></html>";
179 KMessageBox::information( 0, str, i18n(
"Plugin Information" ) );
184 PluginManager::dump(
const KService::Ptr service )
187 <<
"PluginManager Service Info:" << endl
188 <<
"---------------------------" << endl
189 <<
"name : " << service->name() << endl
190 <<
"library : " << service->library() << endl
191 <<
"desktopEntryPath : " << service->desktopEntryPath() << endl
192 <<
"X-TDE-akregator-plugintype : " << service->property(
"X-TDE-akregator-plugintype" ).toString() << endl
193 <<
"X-TDE-akregator-name : " << service->property(
"X-TDE-akregator-name" ).toString() << endl
194 <<
"X-TDE-akregator-authors : " << service->property(
"X-TDE-akregator-authors" ).toStringList() << endl
195 <<
"X-TDE-akregator-rank : " << service->property(
"X-TDE-akregator-rank" ).toString() << endl
196 <<
"X-TDE-akregator-version : " << service->property(
"X-TDE-akregator-version" ).toString() << endl
197 <<
"X-TDE-akregator-framework-version: " << service->property(
"X-TDE-akregator-framework-version" ).toString()
207 vector<PluginManager::StoreItem>::iterator
208 PluginManager::lookupPlugin(
const Plugin* plugin )
210 vector<StoreItem>::iterator iter;
213 vector<StoreItem>::const_iterator end;
214 for ( iter = m_store.begin(); iter != end; ++iter ) {
215 if ( (*iter).plugin == plugin )