예제 #1
0
QObject* Manager::module(const QString& modulename)
{
    if( d->modules.contains(modulename) ) {
        QObject* obj = d->modules[modulename];
        if( obj )
            return obj;
    }

    if( modulename.isEmpty() || modulename.contains( QRegExp("[^a-zA-Z0-9]") ) ) {
        qrosswarning( QString("Invalid module name '%1'").arg(modulename) );
        return 0;
    }

    QByteArray libraryname = QString("qrossmodule%1").arg(modulename).toLower().toLatin1();

#if 0
    KLibLoader* loader = KLibLoader::self();
    KLibrary* lib = loader->library( libraryname, QLibrary::ExportExternalSymbolsHint );
    if( ! lib ) { //FIXME this fallback-code should be in KLibLoader imho.
        lib = loader->library( QString("lib%1").arg(libraryname), QLibrary::ExportExternalSymbolsHint );
        if( ! lib ) {
            qrosswarning( QString("Failed to load module '%1': %2").arg(modulename).arg(loader->lastErrorMessage()) );
            return 0;
        }
    }

    def_module_func func;
    func = (def_module_func) lib->resolveFunction("qrossmodule");
    if( ! func ) {
        qrosswarning( QString("Failed to determinate init function in module '%1'").arg(modulename) );
        return 0;
    }

    QObject* module = (QObject*) (func)(); // call the function
    lib->unload(); // unload the library

    if( ! module ) {
        qrosswarning( QString("Failed to load module object '%1'").arg(modulename) );
        return 0;
    }
#else
    if( void* funcPtr = loadLibrary(libraryname, "qrossmodule") ) {
        def_module_func func = (def_module_func) funcPtr;
        Q_ASSERT( func );
        QObject* module = (QObject*) (func)(); // call the function
        Q_ASSERT( module );
        //qrossdebug( QString("Manager::module Module successfully loaded: modulename=%1 module.objectName=%2 module.className=%3").arg(modulename).arg(module->objectName()).arg(module->metaObject()->className()) );
        d->modules.insert(modulename, module);
        return module;
    }
    else {
        qrosswarning( QString("Failed to load module '%1'").arg(modulename) );
    }
#endif
    return 0;
}
예제 #2
0
bool Greeter::loadGreetPlugin()
{
    if (m_pluginHandle.library) {
        //we were locked once before, so all the plugin loading's done already
        //FIXME should I be unloading the plugin on unlock instead?
        return true;
    }
    for (QStringList::ConstIterator it = m_plugins.constBegin(); it != m_plugins.constEnd(); ++it) {
        GreeterPluginHandle plugin;
        KLibrary *lib = new KLibrary( (*it)[0] == QLatin1Char( '/' ) ? *it : QLatin1String( "kgreet_" ) + *it );
        if (lib->fileName().isEmpty()) {
            kWarning(1212) << "GreeterPlugin " << *it << " does not exist" ;
            delete lib;
            continue;
        }
        if (!lib->load()) {
            kWarning(1212) << "Cannot load GreeterPlugin " << *it << " (" << lib->fileName() << ")" ;
            delete lib;
            continue;
        }
        plugin.library = lib;
        plugin.info = (KGreeterPluginInfo *)lib->resolveFunction( "kgreeterplugin_info" );
        if (!plugin.info ) {
            kWarning(1212) << "GreeterPlugin " << *it << " (" << lib->fileName() << ") is no valid greet widget plugin" ;
            lib->unload();
            delete lib;
            continue;
        }
        if (plugin.info->method && !m_method.isEmpty() && m_method != QLatin1String(  plugin.info->method )) {
            kDebug(1212) << "GreeterPlugin " << *it << " (" << lib->fileName() << ") serves " << plugin.info->method << ", not " << m_method;
            lib->unload();
            delete lib;
            continue;
        }
        if (!plugin.info->init( m_method, getConf, this )) {
            kDebug(1212) << "GreeterPlugin " << *it << " (" << lib->fileName() << ") refuses to serve " << m_method;
            lib->unload();
            delete lib;
            continue;
        }
        kDebug(1212) << "GreeterPlugin " << *it << " (" << plugin.info->method << ", " << plugin.info->name << ") loaded";
        m_pluginHandle = plugin;
        return true;
    }
    return false;
}
// tests whether the plugin can be loaded
bool KDecorationPlugins::canLoad(QString nameStr, KLibrary **loadedLib)
{
    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;
    }

    KConfigGroup group(config, QString("Style"));
    if (group.readEntry<bool>("NoPlugin", false)) {
        error(i18n("Loading of window decoration plugin library disabled in configuration."));
        return false;
    }

    KLibrary libToFind(nameStr);
    QString path = libToFind.fileName();
    kDebug(1212) << "kwin : path " << path << " for " << nameStr;

    if (path.isEmpty()) {
        return false;
    }

    // Try loading the requested plugin
    KLibrary *lib = new KLibrary(path);

    if (!lib)
        return false;

    // 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;
    }
#endif
    // so we check whether this lib was loaded before and don't unload it in case
    bool wasLoaded = lib->isLoaded();

    KDecorationFactory*(*cptr)() = NULL;
    int (*vptr)()  = NULL;
    int deco_version = 0;
    KLibrary::void_function_ptr version_func = lib->resolveFunction("decoration_version");
    if (version_func) {
        vptr = (int(*)())version_func;
        deco_version = vptr();
    } else {
        // block some decos known to link the unstable API but (for now) let through other legacy stuff
        const bool isLegacyStableABI = !(nameStr.contains("qtcurve", Qt::CaseInsensitive) ||
                                         nameStr.contains("crystal", Qt::CaseInsensitive) ||
                                         nameStr.contains("oxygen", Qt::CaseInsensitive));
        if (isLegacyStableABI) {
            // it's an old build of a legacy decoration that very likely uses the stable API
            // so we just set the API version to the current one
            // TODO: remove for 4.9.x or 4.10 - this is just to cover recompiles
            deco_version = KWIN_DECORATION_API_VERSION;
        }
        kWarning(1212) << QString("****** The library %1 has no API version ******").arg(path);
        kWarning(1212) << "****** Please use the KWIN_DECORATION macro in extern \"C\" to get this decoration loaded in future versions of kwin";
    }
    if (deco_version != KWIN_DECORATION_API_VERSION) {
        if (version_func)
            kWarning(1212) << i18n("The library %1 has wrong API version %2", path, deco_version);
        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) {
        kDebug(1212) << i18n("The library %1 is not a KWin plugin.", path);
        lib->unload();
        delete lib;
        return false;
    }

    if (loadedLib) {
        *loadedLib = lib;
    } else {
        if (!wasLoaded)
            lib->unload();
        delete lib;
    }
    return true;
}