Logo Search packages:      
Sourcecode: kmess version File versions

ThumbnailProvider::ThumbnailProvider ( const QString &  fileName,
int  size = 96 
) [explicit]

The constructor.

Starts a KIO::PreviewJob to get the preview. When the job completed or failed, gotResult() is fired.

Parameters:
fileName Name of the file to request.
size Size of the thumbnails. Windows Live Messenger also uses 96x96 thumbnails for all files. Depending on it's "file preview size" setting, it scales the received images down afterwards.

Definition at line 44 of file thumbnailprovider.cpp.

References enabledPlugins_, fileList_, slotFailed(), and slotGotPreview().

: QObject( 0 )
, fileName_( fileName )
, resultError_( false )
, size_( size )
{
#ifdef KMESSDEBUG_THUMBNAILPROVIDER
  kDebug() << "requesting thumbnail for" << fileName;
#endif

  // The quick method (also displays a transfer dialog):
  // KIO::NetAccess::download( "thumbnail://" + fileName, tempFile, 0 )
  // thumbnailImage_ = QImage( tempFile );
  // KIO::NetAccess::removeTempFile( tempFile );


  // The complex (but async) method:
  // Wrap file in a file list, use KIO::PreviewJob
  KUrl url( fileName );
  fileList_ = KUrl::List( url );

  // Remove preview for text files
  // TODO: preview should work, but doesn't
  enabledPlugins_ = KIO::PreviewJob::availablePlugins();
  enabledPlugins_.removeAll( "textthumbnail" );

#ifdef KMESSDEBUG_THUMBNAILPROVIDER
  kDebug() << "enabled preview plugins: " << enabledPlugins_;
#endif

  // Get file type
  KMimeType::Ptr type = KMimeType::findByUrl( url );

#ifdef KMESSDEBUG_THUMBNAILPROVIDER
  kDebug() << "file mime type '" << type->name() << "'";
#endif

  // For some file types, don't generate a preview
  // TODO: improve, files like .h and .cpp have a different mime type.
  if( type->name() == "text/plain" )
  {
#ifdef KMESSDEBUG_THUMBNAILPROVIDER
    kDebug() << "not creating previews for this file type.";
#endif
    // Make slot call delayed, so clients can still connect to signals first.
    QTimer::singleShot( 0, this, SLOT(slotFailed()) );
    return;
  }

  // Create the preview job
  KIO::PreviewJob *previewJob = KIO::filePreview( fileList_, size, size,
                                                  100,   // 100% alpha
                                                  true,  // scale (default value)
                                                  true,  // save (default value)
                                                  &enabledPlugins_ );

  // Connect signals.
  connect( previewJob, SIGNAL(      gotPreview(const KFileItem&, const QPixmap&) ),
           this,         SLOT(  slotGotPreview(const KFileItem&, const QPixmap&) ));
  connect( previewJob, SIGNAL(          failed(const KFileItem&) ),
           this,         SLOT(      slotFailed(const KFileItem&) ));

  // The KIO::PreviewJob auto deletes itself.
}


Generated by  Doxygen 1.6.0   Back to index