Esempio n. 1
0
void PreviewJob::startPreview()
{
    // Load the list of plugins to determine which mimetypes are supported
    TDETrader::OfferList plugins = TDETrader::self()->query("ThumbCreator");
    TQMap<TQString, KService::Ptr> mimeMap;

    for (TDETrader::OfferList::ConstIterator it = plugins.begin(); it != plugins.end(); ++it)
        if (!d->enabledPlugins || d->enabledPlugins->contains((*it)->desktopEntryName()))
    {
        TQStringList mimeTypes = (*it)->property("MimeTypes").toStringList();
        for (TQStringList::ConstIterator mt = mimeTypes.begin(); mt != mimeTypes.end(); ++mt)
            mimeMap.insert(*mt, *it);
    }

    // Look for images and store the items in our todo list :)
    bool bNeedCache = false;
    for (KFileItemListIterator it(d->initialItems); it.current(); ++it )
    {
        PreviewItem item;
        item.item = it.current();
        TQMap<TQString, KService::Ptr>::ConstIterator plugin = mimeMap.find(it.current()->mimetype());
        if (plugin == mimeMap.end()
            && (it.current()->mimetype() != "application/x-desktop")
            && (it.current()->mimetype() != "media/builtin-mydocuments")
            && (it.current()->mimetype() != "media/builtin-mycomputer")
            && (it.current()->mimetype() != "media/builtin-mynetworkplaces")
            && (it.current()->mimetype() != "media/builtin-printers")
            && (it.current()->mimetype() != "media/builtin-trash")
            && (it.current()->mimetype() != "media/builtin-webbrowser"))
        {
            TQString mimeType = it.current()->mimetype();
            plugin = mimeMap.find(mimeType.replace(TQRegExp("/.*"), "/*"));

            if (plugin == mimeMap.end())
            {
                // check mime type inheritance
                KMimeType::Ptr mimeInfo = KMimeType::mimeType(it.current()->mimetype());
                TQString parentMimeType = mimeInfo->parentMimeType();
                while (!parentMimeType.isEmpty())
                {
                    plugin = mimeMap.find(parentMimeType);
                    if (plugin != mimeMap.end()) break;

                    KMimeType::Ptr parentMimeInfo = KMimeType::mimeType(parentMimeType);
                    if (!parentMimeInfo) break;

                    parentMimeType = parentMimeInfo->parentMimeType();
                }
            }

            if (plugin == mimeMap.end())
            {
                // check X-TDE-Text property
                KMimeType::Ptr mimeInfo = KMimeType::mimeType(it.current()->mimetype());
                TQVariant textProperty = mimeInfo->property("X-TDE-text");
                if (textProperty.isValid() && textProperty.type() == TQVariant::Bool)
                {
                    if (textProperty.toBool())
                    {
                        plugin = mimeMap.find("text/plain");
                        if (plugin == mimeMap.end())
                        {
                            plugin = mimeMap.find( "text/*" );
                        }
                    }
                }
            }
        }

        if (plugin != mimeMap.end())
        {
            item.plugin = *plugin;
            d->items.append(item);
            if (!bNeedCache && d->bSave &&
                (it.current()->url().protocol() != "file" ||
                 !it.current()->url().directory( false ).startsWith(d->thumbRoot)) &&
                (*plugin)->property("CacheThumbnail").toBool())
                bNeedCache = true;
        }
        else
        {
            emitFailed(it.current());
            if (d->deleteItems)
                delete it.current();
        }
    }

  // Read configuration value for the maximum allowed size
    TDEConfig * config = TDEGlobal::config();
    TDEConfigGroupSaver cgs( config, "PreviewSettings" );
    d->maximumSize = config->readNumEntry( "MaximumSize", 1024*1024 /* 1MB */ );

    if (bNeedCache)
    {
        if (d->width <= 128 && d->height <= 128) d->cacheWidth = d->cacheHeight = 128;
        else d->cacheWidth = d->cacheHeight = 256;
        d->thumbPath = d->thumbRoot + (d->cacheWidth == 128 ? "normal/" : "large/");
        TDEStandardDirs::makeDir(d->thumbPath, 0700);
    }
    else
        d->bSave = false;
    determineNextFile();
}
Esempio n. 2
0
KPreviewWidgetBase * KFileMetaPreview::previewProviderFor( const TQString& mimeType )
{
//     tqDebug("### looking for: %s", mimeType.latin1());
    // often the first highlighted item, where we can be sure, there is no plugin
    // (this "folders reflect icons" is a konq-specific thing, right?)
    if ( mimeType == "inode/directory" ) 
        return 0L;

    KPreviewWidgetBase *provider = m_previewProviders.find( mimeType );
    if ( provider )
        return provider;

//tqDebug("#### didn't find anything for: %s", mimeType.latin1());

    if ( s_tryAudioPreview && 
         !mimeType.startsWith("text/") && !mimeType.startsWith("image/") )
    {
        if ( !haveAudioPreview )
        {
            KPreviewWidgetBase *audioPreview = createAudioPreview( m_stack );
            if ( audioPreview )
            {
                haveAudioPreview = true;
                (void) m_stack->addWidget( audioPreview );
                TQStringList mimeTypes = audioPreview->supportedMimeTypes();
                TQStringList::ConstIterator it = mimeTypes.begin();
                for ( ; it != mimeTypes.end(); ++it )
                    m_previewProviders.insert( *it, audioPreview );
            }
        }
    }

    // with the new mimetypes from the audio-preview, try again
    provider = m_previewProviders.find( mimeType );
    if ( provider )
        return provider;

    // ### mimetype may be image/* for example, try that
    int index = mimeType.find( '/' );
    if ( index > 0 )
    {
        provider = m_previewProviders.find( mimeType.left( index + 1 ) + "*" );
        if ( provider )
            return provider;
    }

    KMimeType::Ptr mimeInfo = KMimeType::mimeType( mimeType );
    if ( mimeInfo )
    {
        // check mime type inheritance
        TQString parentMimeType = mimeInfo->parentMimeType();
        while ( !parentMimeType.isEmpty() )
        {
            provider = m_previewProviders.find( parentMimeType );
            if ( provider )
                return provider;

            KMimeType::Ptr parentMimeInfo = KMimeType::mimeType( parentMimeType );
            if ( !parentMimeInfo ) break;

            parentMimeType = parentMimeInfo->parentMimeType();
        }

        // check X-TDE-Text property
        TQVariant textProperty = mimeInfo->property( "X-TDE-text" );
        if ( textProperty.isValid() && textProperty.type() == TQVariant::Bool )
        {
            if ( textProperty.toBool() )
            {
                provider = m_previewProviders.find( "text/plain" );
                if ( provider )
                    return provider;

                provider = m_previewProviders.find( "text/*" );
                if ( provider )
                    return provider;
            }
        }
    }

    return 0L;
}
Esempio n. 3
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;
}