• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

akregator

  • sources
  • kde-4.12
  • kdepim
  • akregator
  • src
pluginmanager.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 begin : 2004/03/12
3 copyright : (C) Mark Kretschmann
4 email : markey@web.de
5 ***************************************************************************/
6 
7 /***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "pluginmanager.h"
17 #include "plugin.h"
18 
19 #include <vector>
20 #include <QFile>
21 #include <QString>
22 
23 #include <klibloader.h>
24 #include <kdebug.h>
25 #include <klocale.h>
26 #include <kmessagebox.h>
27 
28 using std::vector;
29 using Akregator::Plugin;
30 
31 namespace Akregator {
32 
33 vector<PluginManager::StoreItem>
34 PluginManager::m_store;
35 
36 
38 // PUBLIC INTERFACE
40 
41 KService::List
42 PluginManager::query( const QString& constraint )
43 {
44  // Add versioning constraint
45  QString
46  str = "[X-KDE-akregator-framework-version] == ";
47  str += QString::number( AKREGATOR_PLUGIN_INTERFACE_VERSION );
48  str += " and ";
49  if (!constraint.trimmed().isEmpty())
50  str += constraint + " and ";
51  str += "[X-KDE-akregator-rank] > 0";
52 
53  kDebug() <<"Plugin trader constraint:" << str;
54 
55  return KServiceTypeTrader::self()->query( "Akregator/Plugin", str );
56 }
57 
58 
59 Plugin*
60 PluginManager::createFromQuery( const QString &constraint )
61 {
62  KService::List offers = query( constraint );
63 
64  if ( offers.isEmpty() ) {
65  kWarning() <<"No matching plugin found.";
66  return 0;
67  }
68 
69  // Select plugin with highest rank
70  int rank = 0;
71  uint current = 0;
72  for ( int i = 0; i < offers.count(); ++i ) {
73  if ( offers[i]->property( "X-KDE-akregator-rank" ).toInt() > rank )
74  current = i;
75  }
76 
77  return createFromService( offers[current] );
78 }
79 
80 
81 Plugin*
82 PluginManager::createFromService( const KService::Ptr service, QObject *parent )
83 {
84  kDebug() <<"Trying to load:" << service->library();
85 
86  KPluginLoader loader( *service );
87  KPluginFactory* factory = loader.factory();
88  if ( !factory ) {
89  kWarning() << QString( " Could not create plugin factory for: %1\n"
90  " Error message: %2" ).arg( service->library(), loader.errorString() );
91  return 0;
92  }
93  Plugin* const plugin = factory->create<Plugin>( parent );
94 
95  //put plugin into store
96  StoreItem item;
97  item.plugin = plugin;
98  item.service = service;
99  m_store.push_back( item );
100 
101  dump( service );
102  return plugin;
103 }
104 
105 
106 void
107 PluginManager::unload( Plugin* plugin )
108 {
109 #ifdef TEMPORARILY_REMOVED
110  vector<StoreItem>::iterator iter = lookupPlugin( plugin );
111 
112  if ( iter != m_store.end() ) {
113  delete (*iter).plugin;
114  kDebug() <<"Unloading library:"<< (*iter).service->library();
115  //PENDING(kdab,frank) Review
116  (*iter).library->unload();
117 
118 
119  m_store.erase( iter );
120  }
121  else
122  kWarning() <<"Could not unload plugin (not found in store).";
123 #else //TEMPORARILY_REMOVED
124  Q_UNUSED( plugin )
125  kWarning() <<"PluginManager::unload temporarily disabled";
126 #endif //TEMPORARILY_REMOVED
127 
128 }
129 
130 
131 KService::Ptr
132 PluginManager::getService( const Plugin* plugin )
133 {
134  if ( !plugin ) {
135  kWarning() <<"pointer == NULL";
136  return KService::Ptr( 0 );
137  }
138 
139  //search plugin in store
140  vector<StoreItem>::const_iterator iter = lookupPlugin( plugin );
141 
142  if ( iter == m_store.end() ) {
143  kWarning() <<"Plugin not found in store.";
144  return KService::Ptr( 0 );
145  }
146 
147  return (*iter).service;
148 }
149 
150 
151 void
152 PluginManager::showAbout( const QString &constraint )
153 {
154  KService::List offers = query( constraint );
155 
156  if ( offers.isEmpty() )
157  return;
158 
159  KService::Ptr s = offers.front();
160 
161  const QString body = "<tr><td>%1</td><td>%2</td></tr>";
162 
163  QString str = "<html><body><table width=\"100%\" border=\"1\">";
164 
165  str += body.arg( i18nc( "Name of the plugin", "Name" ), s->name() );
166  str += body.arg( i18nc( "Library name", "Library" ), s->library() );
167  str += body.arg( i18nc( "Plugin authors", "Authors" ), s->property( "X-KDE-akregator-authors" ).toStringList().join( "\n" ) );
168  str += body.arg( i18nc( "Plugin authors' emaila addresses", "Email" ), s->property( "X-KDE-akregator-email" ).toStringList().join( "\n" ) );
169  str += body.arg( i18nc( "Plugin version", "Version" ), s->property( "X-KDE-akregator-version" ).toString() );
170  str += body.arg( i18nc( "Framework version plugin requires", "Framework Version" ), s->property( "X-KDE-akregator-framework-version" ).toString() );
171 
172  str += "</table></body></html>";
173 
174  KMessageBox::information( 0, str, i18n( "Plugin Information" ) );
175 }
176 
177 
178 void
179 PluginManager::dump( const KService::Ptr service )
180 {
181  kDebug()
182  << "PluginManager Service Info:" << endl
183  << "---------------------------" << endl
184  << "name : " << service->name() << endl
185  << "library : " << service->library() << endl
186  << "desktopEntryPath : " << service->entryPath() << endl
187  << "X-KDE-akregator-plugintype : " << service->property( "X-KDE-akregator-plugintype" ).toString() << endl
188  << "X-KDE-akregator-name : " << service->property( "X-KDE-akregator-name" ).toString() << endl
189  << "X-KDE-akregator-authors : " << service->property( "X-KDE-akregator-authors" ).toStringList() << endl
190  << "X-KDE-akregator-rank : " << service->property( "X-KDE-akregator-rank" ).toString() << endl
191  << "X-KDE-akregator-version : " << service->property( "X-KDE-akregator-version" ).toString() << endl
192  << "X-KDE-akregator-framework-version: " << service->property( "X-KDE-akregator-framework-version" ).toString()
193  << endl;
194 
195 }
196 
197 
199 // PRIVATE INTERFACE
201 
202 vector<PluginManager::StoreItem>::iterator
203 PluginManager::lookupPlugin( const Plugin* plugin )
204 {
205  vector<StoreItem>::iterator iter;
206 
207  //search plugin pointer in store
208  vector<StoreItem>::const_iterator end;
209  for ( iter = m_store.begin(); iter != end; ++iter ) {
210  if ( (*iter).plugin == plugin )
211  break;
212  }
213 
214  return iter;
215 }
216 
217 } // namespace Akregator
pluginmanager.h
AKREGATOR_PLUGIN_INTERFACE_VERSION
#define AKREGATOR_PLUGIN_INTERFACE_VERSION
Definition: plugin.h:37
Akregator::PluginManager::showAbout
static void showAbout(const QString &constraint)
Show modal info dialog about plugin.
Definition: pluginmanager.cpp:152
uint
unsigned int uint
Definition: article.h:39
plugin.h
QObject
Akregator::Plugin
Definition: plugin.h:41
Akregator::PluginManager::query
static KService::List query(const QString &constraint=QString())
It will return a list of services that match your specifications.
Definition: pluginmanager.cpp:42
Akregator::PluginManager::createFromQuery
static Akregator::Plugin * createFromQuery(const QString &constraint=QString())
Load and instantiate plugin from query.
Definition: pluginmanager.cpp:60
Akregator::PluginManager::createFromService
static Akregator::Plugin * createFromService(const KService::Ptr service, QObject *parent=0)
Load and instantiate plugin from service.
Definition: pluginmanager.cpp:82
Akregator::PluginManager::unload
static void unload(Akregator::Plugin *plugin)
Remove library and delete plugin.
Definition: pluginmanager.cpp:107
Akregator::PluginManager::dump
static void dump(const KService::Ptr service)
Dump properties from a service to stdout for debugging.
Definition: pluginmanager.cpp:179
Akregator::PluginManager::getService
static KService::Ptr getService(const Akregator::Plugin *plugin)
Look up service for loaded plugin from store.
Definition: pluginmanager.cpp:132
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:14 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akregator

Skip menu "akregator"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal