示例#1
0
Package PluginLoader::loadPackage(const QString &packageFormat, const QString &specialization)
{
    if (!d->isDefaultLoader) {
        Package p = internalLoadPackage(packageFormat, specialization);
        if (p.hasValidStructure()) {
            return p;
        }
    }

    if (packageFormat.isEmpty()) {
        return Package();
    }

    const QString hashkey = packageFormat + '%' + specialization;
    PackageStructure *structure = d->structures.value(hashkey).data();

    if (structure) {
        return Package(structure);
    }

    KPackage::PackageStructure *internalStructure = KPackage::PackageLoader::self()->loadPackageStructure(packageFormat);

    if (internalStructure) {
        structure = new PackageStructure();
        structure->d->internalStructure = internalStructure;
    //fallback to old structures
    } else {
        const QString constraint = QStringLiteral("[X-KDE-PluginInfo-Name] == '%1'").arg(packageFormat);
        structure = KPluginTrader::createInstanceFromQuery<Plasma::PackageStructure>(PluginLoaderPrivate::s_packageStructurePluginDir, QStringLiteral("Plasma/PackageStructure"), constraint, 0);
        if (structure) {
            structure->d->internalStructure = new PackageStructureWrapper(structure);
        }
    }


    if (structure) {
        d->structures.insert(hashkey, structure);
        return Package(structure);
    }

#ifndef NDEBUG
        // qCDebug(LOG_PLASMA) << "Couldn't load Package for" << packageFormat << "! reason given: " << error;
#endif

    return Package();
}
Package PluginLoader::loadPackage(const QString &packageFormat, const QString &specialization)
{
    if (!d->isDefaultLoader) {
        Package p = internalLoadPackage(packageFormat, specialization);
        if (p.hasValidStructure()) {
            return p;
        }
    }

    if (packageFormat.isEmpty()) {
        return Package();
    }

    const QString hashkey = packageFormat + '%' + specialization;
    PackageStructure *structure = d->structures.value(hashkey).data();

    KPackage::PackageStructure *internalStructure = 0;
    if (structure) {
        return Package(structure);
    }

    if (packageFormat.startsWith(QLatin1String("Plasma"))) {
        if (packageFormat.endsWith(QLatin1String("/Applet"))) {
            internalStructure = new PlasmoidPackage();
        } else if (packageFormat.endsWith(QLatin1String("/DataEngine"))) {
            internalStructure = new DataEnginePackage();
        } else if (packageFormat.endsWith(QLatin1String("/Theme"))) {
            internalStructure = new ThemePackage();
        } else if (packageFormat.endsWith(QLatin1String("/ContainmentActions"))) {
            internalStructure = new ContainmentActionsPackage();
        } else if (packageFormat.endsWith(QLatin1String("/Generic"))) {
            internalStructure = new GenericPackage();
        }

        if (internalStructure) {
            structure = new PackageStructure();
            structure->d->internalStructure = internalStructure;
            d->structures.insert(hashkey, structure);
            return Package(structure);
        }
    }

    internalStructure = KPackage::PackageLoader::self()->loadPackageStructure(packageFormat);

    if (internalStructure) {
        structure = new PackageStructure();
        structure->d->internalStructure = internalStructure;
    //fallback to old structures
    } else {
        const QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(packageFormat);
        structure = KPluginTrader::createInstanceFromQuery<Plasma::PackageStructure>(PluginLoaderPrivate::s_packageStructurePluginDir, "Plasma/PackageStructure", constraint, 0);
        if (structure) {
            structure->d->internalStructure = new PackageStructureWrapper(structure);
        }
    }


    if (structure) {
        d->structures.insert(hashkey, structure);
        return Package(structure);
    }

#ifndef NDEBUG
        // qCDebug(LOG_PLASMA) << "Couldn't load Package for" << packageFormat << "! reason given: " << error;
#endif

    return Package();
}