51
43
void FunctionModuleRegistry::Private::registerFunctionModule(FunctionModule* module)
53
module->registerFunctions();
45
const QList<QSharedPointer<Function> > functions = module->functions();
46
for (int i = 0; i < functions.count(); ++i) {
47
FunctionRepository::self()->add(functions[i]);
54
49
Q_ASSERT(!module->descriptionFileName().isEmpty());
55
const KStandardDirs* dirs = Factory::global().dirs();
50
const KStandardDirs* dirs = KGlobal::activeComponent().dirs();
56
51
const QString fileName = dirs->findResource("functions", module->descriptionFileName());
57
52
if (fileName.isEmpty()) {
58
53
kDebug(36002) << module->descriptionFileName() << "not found.";
60
56
FunctionRepository::self()->loadFunctionDescriptions(fileName);
59
void FunctionModuleRegistry::Private::removeFunctionModule(FunctionModule* module)
61
const QList<QSharedPointer<Function> > functions = module->functions();
62
for (int i = 0; i < functions.count(); ++i) {
63
FunctionRepository::self()->remove(functions[i]);
64
68
FunctionModuleRegistry::FunctionModuleRegistry()
67
71
d->repositoryInitialized = false;
71
74
FunctionModuleRegistry::~FunctionModuleRegistry()
76
79
FunctionModuleRegistry* FunctionModuleRegistry::instance()
78
return &s_singleton->instance;
81
K_GLOBAL_STATIC(FunctionModuleRegistry, s_instance)
81
void FunctionModuleRegistry::loadFunctions()
85
void FunctionModuleRegistry::loadFunctionModules()
83
const QString serviceType = QString::fromLatin1("KSpread/Plugin");
84
const QString query = QString::fromLatin1("([X-KSpread-Version] >= 2) and "
85
"([X-KDE-PluginInfo-Category] == 'FunctionModule')");
87
const quint32 minKSpreadVersion = KOFFICE_MAKE_VERSION(2, 1, 0);
88
const QString serviceType = QLatin1String("KSpread/Plugin");
89
const QString query = QLatin1String("([X-KSpread-InterfaceVersion] == 0) and "
90
"([X-KDE-PluginInfo-Category] == 'FunctionModule')");
86
91
const KService::List offers = KServiceTypeTrader::self()->query(serviceType, query);
87
92
const KConfigGroup moduleGroup = KGlobal::config()->group("Plugins");
88
93
const KPluginInfo::List pluginInfos = KPluginInfo::fromServices(offers, moduleGroup);
94
kDebug(36002) << pluginInfos.count() << "function modules found.";
89
95
foreach(KPluginInfo pluginInfo, pluginInfos) {
90
KPluginFactory *factory = KPluginLoader(*pluginInfo.service()).factory();
92
kDebug(36002) << "Unable to create plugin factory for" << pluginInfo.name();
95
FunctionModule* module = factory->create<FunctionModule>(this);
97
kDebug(36002) << "Unable to create function module for" << pluginInfo.name();
100
96
pluginInfo.load(); // load activation state
101
if (pluginInfo.isPluginEnabled()) {
102
// Module already registered?
103
if (contains(module->id())) {
107
// Is the function repository already initialized?
97
KPluginLoader loader(*pluginInfo.service());
98
// Let's be paranoid: do not believe the service type.
99
if (loader.pluginVersion() < minKSpreadVersion) {
100
kDebug(36002) << pluginInfo.name()
101
<< "was built against KSpread" << loader.pluginVersion()
102
<< "; required version >=" << minKSpreadVersion;
105
if (pluginInfo.isPluginEnabled() && !contains(pluginInfo.pluginName())) {
106
// Plugin enabled, but not registered. Add it.
107
KPluginFactory* const factory = loader.factory();
109
kDebug(36002) << "Unable to create plugin factory for" << pluginInfo.name();
112
FunctionModule* const module = factory->create<FunctionModule>(this);
114
kDebug(36002) << "Unable to create function module for" << pluginInfo.name();
117
add(pluginInfo.pluginName(), module);
119
// Delays the function registration until the user needs one.
108
120
if (d->repositoryInitialized) {
109
121
d->registerFunctionModule(module);
112
// Module not registered?
113
if (!contains(module->id())) {
116
module->removeFunctions();
117
remove(module->id());
123
} else if (!pluginInfo.isPluginEnabled() && contains(pluginInfo.pluginName())) {
124
// Plugin disabled, but registered. Remove it.
125
FunctionModule* const module = get(pluginInfo.pluginName());
126
// Delay the function registration until the user needs one.
127
if (d->repositoryInitialized) {
128
d->removeFunctionModule(module);
130
remove(pluginInfo.pluginName());
131
if (module->isRemovable()) {
133
delete loader.factory();
137
add(pluginInfo.pluginName(), module);
138
// Delay the function registration until the user needs one.
139
if (d->repositoryInitialized) {
140
d->registerFunctionModule(module);