Update for doxygen 1.5.5, graph generation, and match current code.
[tagua/yd.git] / src / variants.cpp
blob12a84ae99b0a098b008ea008755f14c0fc9bd494
1 /*
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.
9 */
11 #include "variants.h"
12 #include <memory>
13 #include <KDebug>
14 #include "foreach.h"
15 #include "variant.h"
17 void load_plugins();
19 typedef Repository* PluginFactory(IVariantLoader*);
21 Repository* Variants::load(const KService::Ptr& plugin) {
22 // load plugin
23 QString symbol = plugin->library() + "_initrepo";
24 KLibrary pluginLib(plugin->library());
26 // resolve initrepo function
27 void* initrepo_ = pluginLib.resolveSymbol(qPrintable(symbol));
28 if (!initrepo_) {
29 kWarning() << "Error loading plugin" << plugin->library();
30 kWarning() << pluginLib.errorString();
31 return false;
33 PluginFactory* initrepo = reinterpret_cast<PluginFactory*>(initrepo_);
35 return (*initrepo)(this);
38 Variants::Variants() { }
40 Variants& Variants::self() {
41 static Variants inst;
42 return inst;
45 Variant* Variants::create(const KService::Ptr& plugin) {
46 Repository* repo = load(plugin);
47 if (repo)
48 return new Variant(plugin->name(), repo,
49 plugin->property("X-Tagua-Proxy").toString());
51 return 0;
54 Variant* Variants::create(const QString& name) {
55 KService::Ptr service = get(name);
56 return service ? create(service) : 0;
59 KService::Ptr Variants::get(const QString& name) {
60 KService::List services =
61 KServiceTypeTrader::self()->query("Tagua/Variant",
62 "Name =~ '" + name + "'");
63 if (services.empty())
64 return KService::Ptr();
65 else
66 return services[0];
69 KService::List Variants::all() const {
70 return KServiceTypeTrader::self()->query(
71 "Tagua/Variant", "[X-Tagua-Hidden] == false");
74 Repository* Variants::getRepository(const QString& variant) {
75 KService::Ptr service = get(variant);
76 if (!service) return 0;
78 return load(service);