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

akregator

  • sources
  • kde-4.14
  • 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 <QString>
21 
22 #include <klibloader.h>
23 #include <kdebug.h>
24 #include <klocale.h>
25 #include <kmessagebox.h>
26 
27 using std::vector;
28 using Akregator::Plugin;
29 
30 namespace Akregator {
31 
32 vector<PluginManager::StoreItem>
33 PluginManager::m_store;
34 
35 
37 // PUBLIC INTERFACE
39 
40 KService::List
41 PluginManager::query( const QString& constraint )
42 {
43  // Add versioning constraint
44  QString
45  str = "[X-KDE-akregator-framework-version] == ";
46  str += QString::number( AKREGATOR_PLUGIN_INTERFACE_VERSION );
47  str += " and ";
48  if (!constraint.trimmed().isEmpty())
49  str += constraint + " and ";
50  str += "[X-KDE-akregator-rank] > 0";
51 
52  kDebug() <<"Plugin trader constraint:" << str;
53 
54  return KServiceTypeTrader::self()->query( "Akregator/Plugin", str );
55 }
56 
57 
58 Plugin*
59 PluginManager::createFromQuery( const QString &constraint )
60 {
61  KService::List offers = query( constraint );
62 
63  if ( offers.isEmpty() ) {
64  kWarning() <<"No matching plugin found.";
65  return 0;
66  }
67 
68  // Select plugin with highest rank
69  int rank = 0;
70  uint current = 0;
71  for ( int i = 0; i < offers.count(); ++i ) {
72  if ( offers[i]->property( "X-KDE-akregator-rank" ).toInt() > rank )
73  current = i;
74  }
75 
76  return createFromService( offers[current] );
77 }
78 
79 
80 Plugin*
81 PluginManager::createFromService( const KService::Ptr service, QObject *parent )
82 {
83  kDebug() <<"Trying to load:" << service->library();
84 
85  KPluginLoader loader( *service );
86  KPluginFactory* factory = loader.factory();
87  if ( !factory ) {
88  kWarning() << QString( " Could not create plugin factory for: %1\n"
89  " Error message: %2" ).arg( service->library(), loader.errorString() );
90  return 0;
91  }
92  Plugin* const plugin = factory->create<Plugin>( parent );
93 
94  //put plugin into store
95  StoreItem item;
96  item.plugin = plugin;
97  item.service = service;
98  m_store.push_back( item );
99 
100  dump( service );
101  return plugin;
102 }
103 
104 
105 void
106 PluginManager::unload( Plugin* plugin )
107 {
108 #ifdef TEMPORARILY_REMOVED
109  vector<StoreItem>::iterator iter = lookupPlugin( plugin );
110 
111  if ( iter != m_store.end() ) {
112  delete (*iter).plugin;
113  kDebug() <<"Unloading library:"<< (*iter).service->library();
114  //PENDING(kdab,frank) Review
115  (*iter).library->unload();
116 
117 
118  m_store.erase( iter );
119  }
120  else
121  kWarning() <<"Could not unload plugin (not found in store).";
122 #else //TEMPORARILY_REMOVED
123  Q_UNUSED( plugin )
124  kWarning() <<"PluginManager::unload temporarily disabled";
125 #endif //TEMPORARILY_REMOVED
126 
127 }
128 
129 
130 KService::Ptr
131 PluginManager::getService( const Plugin* plugin )
132 {
133  if ( !plugin ) {
134  kWarning() <<"pointer == NULL";
135  return KService::Ptr( 0 );
136  }
137 
138  //search plugin in store
139  vector<StoreItem>::const_iterator iter = lookupPlugin( plugin );
140 
141  if ( iter == m_store.end() ) {
142  kWarning() <<"Plugin not found in store.";
143  return KService::Ptr( 0 );
144  }
145 
146  return (*iter).service;
147 }
148 
149 
150 void
151 PluginManager::showAbout( const QString &constraint )
152 {
153  KService::List offers = query( constraint );
154 
155  if ( offers.isEmpty() )
156  return;
157 
158  KService::Ptr s = offers.front();
159 
160  const QString body = "<tr><td>%1</td><td>%2</td></tr>";
161 
162  QString str = "<html><body><table width=\"100%\" border=\"1\">";
163 
164  str += body.arg( i18nc( "Name of the plugin", "Name" ), s->name() );
165  str += body.arg( i18nc( "Library name", "Library" ), s->library() );
166  str += body.arg( i18nc( "Plugin authors", "Authors" ), s->property( "X-KDE-akregator-authors" ).toStringList().join( "\n" ) );
167  str += body.arg( i18nc( "Plugin authors' emaila addresses", "Email" ), s->property( "X-KDE-akregator-email" ).toStringList().join( "\n" ) );
168  str += body.arg( i18nc( "Plugin version", "Version" ), s->property( "X-KDE-akregator-version" ).toString() );
169  str += body.arg( i18nc( "Framework version plugin requires", "Framework Version" ), s->property( "X-KDE-akregator-framework-version" ).toString() );
170 
171  str += "</table></body></html>";
172 
173  KMessageBox::information( 0, str, i18n( "Plugin Information" ) );
174 }
175 
176 
177 void
178 PluginManager::dump( const KService::Ptr service )
179 {
180  kDebug()
181  << "PluginManager Service Info:" << endl
182  << "---------------------------" << endl
183  << "name : " << service->name() << endl
184  << "library : " << service->library() << endl
185  << "desktopEntryPath : " << service->entryPath() << endl
186  << "X-KDE-akregator-plugintype : " << service->property( "X-KDE-akregator-plugintype" ).toString() << endl
187  << "X-KDE-akregator-name : " << service->property( "X-KDE-akregator-name" ).toString() << endl
188  << "X-KDE-akregator-authors : " << service->property( "X-KDE-akregator-authors" ).toStringList() << endl
189  << "X-KDE-akregator-rank : " << service->property( "X-KDE-akregator-rank" ).toString() << endl
190  << "X-KDE-akregator-version : " << service->property( "X-KDE-akregator-version" ).toString() << endl
191  << "X-KDE-akregator-framework-version: " << service->property( "X-KDE-akregator-framework-version" ).toString()
192  << endl;
193 
194 }
195 
196 
198 // PRIVATE INTERFACE
200 
201 vector<PluginManager::StoreItem>::iterator
202 PluginManager::lookupPlugin( const Plugin* plugin )
203 {
204  vector<StoreItem>::iterator iter;
205 
206  //search plugin pointer in store
207  vector<StoreItem>::const_iterator end;
208  for ( iter = m_store.begin(); iter != end; ++iter ) {
209  if ( (*iter).plugin == plugin )
210  break;
211  }
212 
213  return iter;
214 }
215 
216 } // 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:151
uint
unsigned int uint
Definition: article.h:41
plugin.h
Akregator::Plugin
Definition: plugin.h:41
QString::number
QString number(int n, int base)
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:41
QObject
QString::isEmpty
bool isEmpty() const
QString::trimmed
QString trimmed() const
QString
Akregator::PluginManager::createFromQuery
static Akregator::Plugin * createFromQuery(const QString &constraint=QString())
Load and instantiate plugin from query.
Definition: pluginmanager.cpp:59
Akregator::PluginManager::createFromService
static Akregator::Plugin * createFromService(const KService::Ptr service, QObject *parent=0)
Load and instantiate plugin from service.
Definition: pluginmanager.cpp:81
Akregator::PluginManager::unload
static void unload(Akregator::Plugin *plugin)
Remove library and delete plugin.
Definition: pluginmanager.cpp:106
Akregator::PluginManager::dump
static void dump(const KService::Ptr service)
Dump properties from a service to stdout for debugging.
Definition: pluginmanager.cpp:178
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
Akregator::PluginManager::getService
static KService::Ptr getService(const Akregator::Plugin *plugin)
Look up service for loaded plugin from store.
Definition: pluginmanager.cpp:131
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:00 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
  • pimprint

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