2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
11 #include "kdepluginvariants.h"
19 typedef Repository
* PluginFactory(IVariantLoader
*);
21 Repository
* KDEPluginVariants::load(const KService::Ptr
& plugin
) {
23 QString symbol
= plugin
->library() + "_initrepo";
24 KLibrary
pluginLib(plugin
->library());
26 // resolve initrepo function
27 void* initrepo_
= pluginLib
.resolveSymbol(qPrintable(symbol
));
29 kWarning() << "Error loading plugin" << plugin
->library();
30 kWarning() << pluginLib
.errorString();
33 PluginFactory
* initrepo
= reinterpret_cast<PluginFactory
*>(initrepo_
);
35 return (*initrepo
)(this);
38 KDEPluginVariants::KDEPluginVariants() { }
40 KDEPluginVariants
& KDEPluginVariants::self() {
41 static KDEPluginVariants inst
;
45 Variant
* KDEPluginVariants::create(const KService::Ptr
& plugin
) {
46 Repository
* repo
= load(plugin
);
48 return new Variant(plugin
->name(), repo
,
49 plugin
->property("X-Tagua-Proxy").toString());
54 Variant
* KDEPluginVariants::create(const QString
& name
) {
55 KService::Ptr service
= get(name
);
56 return service
? create(service
) : 0;
59 KService::Ptr
KDEPluginVariants::get(const QString
& name
) {
60 KService::List services
=
61 KServiceTypeTrader::self()->query("Tagua/Variant",
62 "Name =~ '" + name
+ "'");
64 return KService::Ptr();
69 QStringList
KDEPluginVariants::all() const {
70 KService::List klist
= KServiceTypeTrader::self()->query(
71 "Tagua/Variant", "[X-Tagua-Hidden] == false");
73 foreach (KService::Ptr service
, klist
) {
74 result
<< service
->name();
79 Repository
* KDEPluginVariants::getRepository(const QString
& variant
) {
80 KService::Ptr service
= get(variant
);
81 if (!service
) return 0;