[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kdecore
From: Matthias Kretz <kretz () kde ! org>
Date: 2007-08-27 22:14:57
Message-ID: 1188252897.752867.17563.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 705416 by mkretz:
add KService::pluginKeyword() that returns the value of the X-KDE-PluginKeyword entry
mark KService::createInstance methods using QStringList as deprecated
add createInstance overloads that take a QVariantList and that use KPluginLoader \
instead of KLibLoader
M +10 -0 services/kservice.cpp
M +53 -4 services/kservice.h
M +24 -13 services/kservicetypetrader.h
M +2 -2 sonnet/loader.cpp
--- trunk/KDE/kdelibs/kdecore/services/kservice.cpp #705415:705416
@@ -684,6 +684,16 @@
return it->toString();
}
+QString KService::pluginKeyword() const
+{
+ QMap<QString,QVariant>::ConstIterator it = \
d->m_mapProps.find("X-KDE-PluginKeyword"); + if ((it == d->m_mapProps.end()) || \
(!it->isValid())) { + return QString();
+ }
+
+ return it->toString();
+}
+
bool KService::allowMultipleFiles() const {
// Can we pass multiple files on the command line or do we have to start the \
application for every single file ?
return (d->m_strExec.contains( "%F" ) || d->m_strExec.contains( "%U" ) ||
--- trunk/KDE/kdelibs/kdecore/services/kservice.h #705415:705416
@@ -339,6 +339,13 @@
QString parentApp() const;
/**
+ * The keyword to be used when constructing the plugin using KPluginFactory. The \
keyword is + * defined with X-KDE-PluginKeyword in the .desktop file and with \
K_REGISTER_PLUGIN_WITH_KEYWORD + * when implementing the plugin.
+ */
+ QString pluginKeyword() const;
+
+ /**
* Returns the requested property. Some often used properties
* have convenience access functions like exec(),
* serviceTypes etc.
@@ -510,9 +517,29 @@
* factory was unable to create an object of the given type.
*/
template <class T>
+ static T *createInstance(const KService::Ptr &service, QObject *parent = 0,
+ const QVariantList &args = QVariantList(), QString *error = 0)
+ {
+ KPluginLoader pluginLoader(service->library());
+ KPluginFactory *factory = pluginLoader.factory();
+ if (factory) {
+ const QString keyword = service->pluginKeyword();
+ T *o = factory->create<T>(keyword, parent, args);
+ if (o) {
+ return o;
+ }
+ }
+ if (error) {
+ *error = pluginLoader.errorString();
+ }
+ return 0;
+ }
+
+ template <class T>
+ KDE_DEPRECATED
static T *createInstance( const KService::Ptr &service,
- QObject *parent = 0,
- const QStringList &args = QStringList(),
+ QObject *parent,
+ const QStringList &args,
int *error = 0 )
{
const QString library = service->library();
@@ -539,9 +566,31 @@
* factory was unable to create an object of the given type.
*/
template <class T, class ServiceIterator>
+ static T *createInstance(ServiceIterator begin, ServiceIterator end, QObject \
*parent = 0, + const QVariantList &args = QVariantList(), QString *error = \
0) + {
+ for (; begin != end; ++begin) {
+ KService::Ptr service = *begin;
+ if (error) {
+ *error = QString();
+ }
+
+ T *component = createInstance<T>(service, parent, args, error);
+ if (component) {
+ return component;
+ }
+ }
+ if (error) {
+ *error = KLibLoader::errorString(KLibLoader::ErrNoServiceFound);
+ }
+ return 0;
+ }
+
+ template <class T, class ServiceIterator>
+ KDE_DEPRECATED
static T *createInstance( ServiceIterator begin, ServiceIterator end,
- QObject *parent = 0,
- const QStringList &args = QStringList(),
+ QObject *parent,
+ const QStringList &args,
int *error = 0 )
{
for (; begin != end; ++begin ) {
--- trunk/KDE/kdelibs/kdecore/services/kservicetypetrader.h #705415:705416
@@ -152,27 +152,38 @@
* factory was unable to create an object of the given type.
*/
template <class T>
- static T *createInstanceFromQuery( const QString &serviceType,
- const QString &constraint = QString(),
- QObject *parent = 0,
- const QStringList &args = QStringList(),
- int *error = 0 )
+ static T *createInstanceFromQuery(const QString &serviceType,
+ const QString &constraint = QString(), QObject *parent = 0,
+ const QVariantList &args = QVariantList(), QString *error = 0)
{
- const KService::List offers = KServiceTypeTrader::self()->query( \
serviceType, constraint );
- if ( offers.isEmpty() )
- {
- if ( error )
+ const KService::List offers = KServiceTypeTrader::self()->query(serviceType, \
constraint); + if (offers.isEmpty()) {
+ if (error) {
+ *error = KLibLoader::errorString(KLibLoader::ErrNoServiceFound);
+ }
+ return 0;
+ }
+
+ return KService::createInstance<T>(offers.begin(), offers.end(), parent, \
args, error); + }
+
+ template <class T>
+ KDE_DEPRECATED
+ static T *createInstanceFromQuery(const QString &serviceType, const QString \
&constraint, + QObject *parent, const QStringList &args, int *error = 0)
+ {
+ const KService::List offers = KServiceTypeTrader::self()->query(serviceType, \
constraint); + if (offers.isEmpty()) {
+ if (error) {
*error = KLibLoader::ErrNoServiceFound;
+ }
return 0;
}
- return KService::createInstance<T>( offers.begin(),
- offers.end(),
- parent, args, error );
+ return KService::createInstance<T>(offers.begin(), offers.end(), parent, \
args, error); }
-
/**
* @internal (public for KMimeTypeTrader)
*/
--- trunk/KDE/kdelibs/kdecore/sonnet/loader.cpp #705415:705416
@@ -270,7 +270,7 @@
void Loader::loadPlugin(const KSharedPtr<KService> &service)
{
- int error = 0;
+ QString error;
Client *client = KService::createInstance<Client>(service,
this,
@@ -297,7 +297,7 @@
kDebug() << "Loading plugin '"
<< service->desktopEntryPath()
<< "' failed, KLibLoader reported error: '" << endl
- << KLibLoader::errorString(error) << "'" << endl;
+ << error << "'" << endl;
}
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic