2007-04-29 17:35:43 +00:00
|
|
|
/*****************************************************************
|
|
|
|
// vim: sw=4 sts=4 et tw=100
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 1999, 2000 Daniel M. Duley <mosfet@kde.org>
|
|
|
|
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
copy of this software and associated documentation files (the "Software"),
|
|
|
|
to deal in the Software without restriction, including without limitation
|
|
|
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
DEALINGS IN THE SOFTWARE.
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
#include "kdecoration_plugins_p.h"
|
|
|
|
|
|
|
|
#include <kconfig.h>
|
|
|
|
#include <klocale.h>
|
2010-11-10 16:42:52 +00:00
|
|
|
#include <klibrary.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <kconfiggroup.h>
|
2013-03-07 11:55:39 +00:00
|
|
|
#include <KDE/KLocalizedString>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
2013-09-02 09:17:23 +00:00
|
|
|
#include <QDebug>
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFile>
|
|
|
|
|
|
|
|
#include "kdecorationfactory.h"
|
|
|
|
|
|
|
|
KDecorationPlugins::KDecorationPlugins(const KSharedConfigPtr &cfg)
|
2011-01-30 14:34:42 +00:00
|
|
|
: create_ptr(NULL),
|
|
|
|
library(NULL),
|
|
|
|
fact(NULL),
|
|
|
|
old_library(NULL),
|
|
|
|
old_fact(NULL),
|
2013-07-23 05:02:52 +00:00
|
|
|
pluginStr(QStringLiteral("kwin3_undefined ")),
|
2011-01-30 14:34:42 +00:00
|
|
|
config(cfg)
|
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
KDecorationPlugins::~KDecorationPlugins()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (library) {
|
|
|
|
assert(fact != NULL);
|
2007-04-29 17:35:43 +00:00
|
|
|
delete fact;
|
2011-01-30 14:34:42 +00:00
|
|
|
library->unload();
|
|
|
|
}
|
|
|
|
if (old_library) {
|
|
|
|
assert(old_fact != NULL);
|
2007-04-29 17:35:43 +00:00
|
|
|
delete old_fact;
|
2011-01-30 14:34:42 +00:00
|
|
|
old_library->unload();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-07-26 07:51:16 +00:00
|
|
|
QString KDecorationPlugins::currentPlugin()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-07-26 07:51:16 +00:00
|
|
|
return pluginStr;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-07-26 07:51:16 +00:00
|
|
|
|
2013-08-23 10:36:30 +00:00
|
|
|
bool KDecorationPlugins::reset()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
QString oldPlugin = pluginStr;
|
|
|
|
config->reparseConfiguration();
|
2013-08-23 10:36:30 +00:00
|
|
|
loadPlugin(QString()); // "" = read the one in cfg file
|
|
|
|
return oldPlugin != pluginStr;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
KDecorationFactory* KDecorationPlugins::factory()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return fact;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2013-04-08 10:31:16 +00:00
|
|
|
const KDecorationFactory *KDecorationPlugins::factory() const
|
|
|
|
{
|
|
|
|
return fact;
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
// convenience
|
2011-01-30 14:34:42 +00:00
|
|
|
KDecoration* KDecorationPlugins::createDecoration(KDecorationBridge* bridge)
|
|
|
|
{
|
|
|
|
if (fact != NULL)
|
|
|
|
return fact->createDecoration(bridge);
|
2007-04-29 17:35:43 +00:00
|
|
|
return NULL;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2012-07-09 20:42:56 +00:00
|
|
|
// tests whether the plugin can be loaded
|
|
|
|
bool KDecorationPlugins::canLoad(QString nameStr, KLibrary **loadedLib)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-07-09 20:42:56 +00:00
|
|
|
if (nameStr.isEmpty())
|
|
|
|
return false; // we can't load that
|
|
|
|
|
|
|
|
// Check if this library is not already loaded.
|
|
|
|
if (pluginStr == nameStr) {
|
|
|
|
if (loadedLib) {
|
|
|
|
*loadedLib = library;
|
|
|
|
}
|
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2012-07-09 20:42:56 +00:00
|
|
|
|
2013-07-23 05:02:52 +00:00
|
|
|
KConfigGroup group(config, QStringLiteral("Style"));
|
2011-04-28 13:56:50 +00:00
|
|
|
if (group.readEntry<bool>("NoPlugin", false)) {
|
|
|
|
error(i18n("Loading of window decoration plugin library disabled in configuration."));
|
|
|
|
return false;
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-11-10 16:42:52 +00:00
|
|
|
KLibrary libToFind(nameStr);
|
|
|
|
QString path = libToFind.fileName();
|
2013-09-02 09:17:23 +00:00
|
|
|
qDebug() << "kwin : path " << path << " for " << nameStr;
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (path.isEmpty()) {
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
// Try loading the requested plugin
|
2012-07-09 20:42:56 +00:00
|
|
|
KLibrary *lib = new KLibrary(path);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2012-07-09 20:42:56 +00:00
|
|
|
if (!lib)
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2012-07-09 20:42:56 +00:00
|
|
|
|
|
|
|
// TODO this would be a nice shortcut, but for "some" reason QtCurve with wrong ABI slips through
|
|
|
|
// TODO figure where it's loaded w/o being unloaded and check whether that can be fixed.
|
|
|
|
#if 0
|
|
|
|
if (lib->isLoaded()) {
|
|
|
|
if (loadedLib) {
|
|
|
|
*loadedLib = lib;
|
|
|
|
}
|
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2012-07-09 20:42:56 +00:00
|
|
|
#endif
|
|
|
|
// so we check whether this lib was loaded before and don't unload it in case
|
|
|
|
bool wasLoaded = lib->isLoaded();
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2012-07-09 20:42:56 +00:00
|
|
|
KDecorationFactory*(*cptr)() = NULL;
|
|
|
|
int (*vptr)() = NULL;
|
2012-06-28 16:16:09 +00:00
|
|
|
int deco_version = 0;
|
2012-07-09 20:42:56 +00:00
|
|
|
KLibrary::void_function_ptr version_func = lib->resolveFunction("decoration_version");
|
2012-05-17 21:25:22 +00:00
|
|
|
if (version_func) {
|
2012-07-09 20:42:56 +00:00
|
|
|
vptr = (int(*)())version_func;
|
|
|
|
deco_version = vptr();
|
2012-06-28 16:16:09 +00:00
|
|
|
}
|
|
|
|
if (deco_version != KWIN_DECORATION_API_VERSION) {
|
2012-07-09 20:42:56 +00:00
|
|
|
if (version_func)
|
2013-09-02 09:17:23 +00:00
|
|
|
qWarning() << i18n("The library %1 has wrong API version %2", path, deco_version);
|
2012-07-09 20:42:56 +00:00
|
|
|
lib->unload();
|
|
|
|
delete lib;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
KLibrary::void_function_ptr create_func = lib->resolveFunction("create_factory");
|
|
|
|
if (create_func)
|
|
|
|
cptr = (KDecorationFactory * (*)())create_func;
|
|
|
|
|
|
|
|
if (!cptr) {
|
2013-09-02 09:17:23 +00:00
|
|
|
qDebug() << i18n("The library %1 is not a KWin plugin.", path);
|
2012-07-09 20:42:56 +00:00
|
|
|
lib->unload();
|
|
|
|
delete lib;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loadedLib) {
|
|
|
|
*loadedLib = lib;
|
|
|
|
} else {
|
|
|
|
if (!wasLoaded)
|
|
|
|
lib->unload();
|
|
|
|
delete lib;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns true if plugin was loaded successfully
|
|
|
|
bool KDecorationPlugins::loadPlugin(QString nameStr)
|
|
|
|
{
|
2013-07-23 05:02:52 +00:00
|
|
|
KConfigGroup group(config, QStringLiteral("Style"));
|
2012-07-09 20:42:56 +00:00
|
|
|
if (nameStr.isEmpty()) {
|
|
|
|
nameStr = group.readEntry("PluginLib", defaultPlugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if this library is not already loaded.
|
|
|
|
if (pluginStr == nameStr)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
KLibrary *oldLibrary = library;
|
|
|
|
KDecorationFactory* oldFactory = fact;
|
|
|
|
|
|
|
|
if (!canLoad(nameStr, &library)) {
|
|
|
|
// If that fails, fall back to the default plugin
|
|
|
|
nameStr = defaultPlugin;
|
|
|
|
if (!canLoad(nameStr, &library)) {
|
|
|
|
// big time trouble!
|
|
|
|
// -> exit kwin with an error message
|
|
|
|
error(i18n("The default decoration plugin is corrupt and could not be loaded."));
|
|
|
|
return false;
|
2012-05-17 21:25:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-09 20:42:56 +00:00
|
|
|
// guarded by "canLoad"
|
2007-04-29 17:35:43 +00:00
|
|
|
KLibrary::void_function_ptr create_func = library->resolveFunction("create_factory");
|
2011-01-30 14:34:42 +00:00
|
|
|
if (create_func)
|
|
|
|
create_ptr = (KDecorationFactory * (*)())create_func;
|
2012-07-09 20:42:56 +00:00
|
|
|
if (!create_ptr) { // this means someone probably attempted to load "some" kwin plugin/lib as deco
|
|
|
|
// and thus cheated on the "isLoaded" shortcut -> try the default and yell a warning
|
2011-01-30 14:34:42 +00:00
|
|
|
if (nameStr != defaultPlugin) {
|
2013-09-02 09:17:23 +00:00
|
|
|
qWarning() << i18n("The library %1 was attempted to be loaded as a decoration plugin but it is NOT", nameStr);
|
2012-07-09 20:42:56 +00:00
|
|
|
return loadPlugin(defaultPlugin);
|
|
|
|
} else {
|
|
|
|
// big time trouble!
|
|
|
|
// -> exit kwin with an error message
|
|
|
|
error(i18n("The default decoration plugin is corrupt and could not be loaded."));
|
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-09 20:42:56 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
fact = create_ptr();
|
2011-01-30 14:34:42 +00:00
|
|
|
fact->checkRequirements(this); // let it check what is supported
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
pluginStr = nameStr;
|
|
|
|
|
|
|
|
// For clients in kdeartwork
|
2013-07-22 14:18:47 +00:00
|
|
|
#warning insertCatalog needs porting
|
|
|
|
#if KWIN_QT5_PORTING
|
2007-04-29 17:35:43 +00:00
|
|
|
QString catalog = nameStr;
|
2011-01-30 14:34:42 +00:00
|
|
|
catalog.replace("kwin3_", "kwin_");
|
|
|
|
KGlobal::locale()->insertCatalog(catalog);
|
2007-04-29 17:35:43 +00:00
|
|
|
// For KCommonDecoration based clients
|
2011-02-20 15:02:33 +00:00
|
|
|
KGlobal::locale()->insertCatalog("libkdecorations");
|
2007-04-29 17:35:43 +00:00
|
|
|
// For clients in kdebase
|
2011-01-30 14:34:42 +00:00
|
|
|
KGlobal::locale()->insertCatalog("kwin_clients");
|
2007-04-29 17:35:43 +00:00
|
|
|
// For clients in kdeartwork
|
2011-01-30 14:34:42 +00:00
|
|
|
KGlobal::locale()->insertCatalog("kwin_art_clients");
|
2013-07-22 14:18:47 +00:00
|
|
|
#endif
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
old_library = oldLibrary; // save for delayed destroying
|
|
|
|
old_fact = oldFactory;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KDecorationPlugins::destroyPreviousPlugin()
|
|
|
|
{
|
|
|
|
// Destroy the old plugin
|
2011-01-30 14:34:42 +00:00
|
|
|
if (old_library) {
|
2007-04-29 17:35:43 +00:00
|
|
|
delete old_fact;
|
|
|
|
old_fact = NULL;
|
2011-01-30 14:34:42 +00:00
|
|
|
old_library->unload();
|
2012-07-09 20:42:56 +00:00
|
|
|
delete old_library;
|
2007-04-29 17:35:43 +00:00
|
|
|
old_library = NULL;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void KDecorationPlugins::error(const QString&)
|
|
|
|
{
|
|
|
|
}
|