Ejemplo n.º 1
0
static void filterMimeTypeOffers(KService::List& list, const QString& genericServiceType)
{
    KServiceType::Ptr genericServiceTypePtr = KServiceType::serviceType(genericServiceType);
    CHECK_SERVICETYPE(genericServiceTypePtr);

    QMutableListIterator<KService::Ptr> it(list);
    while(it.hasNext()) {
        const KService::Ptr servPtr = it.next();
        // Expand servPtr->hasServiceType( genericServiceTypePtr ) to avoid lookup each time:
        if (!KServiceFactory::self()->hasOffer(genericServiceTypePtr->offset(),
                                               genericServiceTypePtr->serviceOffersOffset(),
                                               servPtr->offset())
            || !servPtr->showInKDE()) {
            it.remove();
        }
    }
}
Ejemplo n.º 2
0
KService::List KServiceType::offers(const QString &_servicetype)
{
    QDict< KService > dict(53);
    KService::List lst;

    // Services associated directly with this servicetype (the normal case)
    KServiceType::Ptr serv = KServiceTypeFactory::self()->findServiceTypeByName(_servicetype);
    if(serv)
        addUnique(lst, dict, KServiceFactory::self()->offers(serv->offset()), false);
    else
        kdWarning(7009) << "KServiceType::offers : servicetype " << _servicetype << " not found" << endl;

    // Find services associated with any mimetype parents. e.g. text/x-java -> text/plain
    KMimeType::Ptr mime = dynamic_cast< KMimeType * >(static_cast< KServiceType * >(serv));
    bool isAMimeType = (mime != 0);
    if(mime)
    {
        while(true)
        {
            QString parent = mime->parentMimeType();
            if(parent.isEmpty())
                break;
            mime = dynamic_cast< KMimeType * >(KServiceTypeFactory::self()->findServiceTypeByName(parent));
            if(!mime)
                break;

            addUnique(lst, dict, KServiceFactory::self()->offers(mime->offset()), false);
        }
    }
    serv = mime = 0;

    // QValueListIterator<KService::Ptr> it = lst.begin();
    // for( ; it != lst.end(); ++it )
    //    kdDebug() << (*it).data() << " " << (*it)->name() << endl;

    // Support for all/* is deactivated by KServiceTypeProfile::configurationMode()
    // (and makes no sense when querying for an "all" servicetype itself
    // nor for non-mimetypes service types)
    if(!KServiceTypeProfile::configurationMode() && isAMimeType && _servicetype.left(4) != "all/")
    {
        // Support for services associated with "all"
        KServiceType *servAll = KServiceTypeFactory::self()->findServiceTypeByName("all/all");
        if(servAll)
        {
            addUnique(lst, dict, KServiceFactory::self()->offers(servAll->offset()), true);
        }
        else
            kdWarning(7009) << "KServiceType::offers : servicetype all/all not found" << endl;
        delete servAll;

        // Support for services associated with "allfiles"
        if(_servicetype != "inode/directory" && _servicetype != "inode/directory-locked")
        {
            KServiceType *servAllFiles = KServiceTypeFactory::self()->findServiceTypeByName("all/allfiles");
            if(servAllFiles)
            {
                addUnique(lst, dict, KServiceFactory::self()->offers(servAllFiles->offset()), true);
            }
            else
                kdWarning(7009) << "KServiceType::offers : servicetype all/allfiles not found" << endl;
            delete servAllFiles;
        }
    }

    return lst;
}