Speed up for plain text files: don't stat .xvpics and .pics, there's

no way you'll find something for you.

BTW, this means that when the thing is pluginified, we'll need a flag
for the plugin, that tells if it saves or not (easy), but also a way
to know which plugin is going to be used, from this code (not only from
the ioslave). Hmmm.

svn path=/trunk/kdebase/libkonq/; revision=74132
This commit is contained in:
David Faure 2000-12-09 12:35:20 +00:00
parent 432faa7f4f
commit 955917b232
2 changed files with 75 additions and 54 deletions

View file

@ -174,6 +174,17 @@ void KonqImagePreviewJob::slotResult( KIO::Job *job )
determineThumbnailURL();
QString mimeType = m_currentItem->item()->mimetype();
if ( mimeType.startsWith( "text/") &&
! (mimeType == "text/html" && m_renderHTML))
{
// This is a text preview, no need to look for a saved thumbnail
// Just create it, and be done
getOrCreateThumbnail();
return;
}
m_state = STATE_STATTHUMB;
KIO::Job * job = KIO::stat( m_thumbURL, false );
kdDebug(1203) << "KonqImagePreviewJob: KIO::stat thumb " << m_thumbURL.url() << endl;
@ -283,19 +294,8 @@ void KonqImagePreviewJob::slotResult( KIO::Job *job )
m_bDirsCreated = true;
}
// We still need to load the orig file ! (This is getting tedious) :)
if ( m_currentURL.isLocalFile() )
createThumbnail( m_currentURL.path() );
else
{
m_state = STATE_GETORIG;
QString localFile = tmpnam(0); // Generate a temp file name
KURL localURL;
localURL.setPath( localFile );
KIO::Job * job = KIO::file_copy( m_currentURL, localURL, -1, false, false, false /* No GUI */ );
kdDebug(1203) << "KonqImagePreviewJob: KIO::file_copy orig " << m_currentURL.url() << " to " << localFile << endl;
addSubjob(job);
}
// This is the next stage
getOrCreateThumbnail();
return;
case STATE_GETORIG:
{
@ -362,47 +362,67 @@ void KonqImagePreviewJob::determineThumbnailURL()
bool KonqImagePreviewJob::statResultThumbnail( KIO::StatJob * job )
{
bool bThumbnail = false;
if (!job->error()) // found a thumbnail
{
KIO::UDSEntry entry = job->statResult();
KIO::UDSEntry::ConstIterator it = entry.begin();
time_t tThumb = 0;
for( ; it != entry.end(); it++ ) {
if ( (*it).m_uds == KIO::UDS_MODIFICATION_TIME ) {
tThumb = (time_t)((*it).m_long);
}
}
// Only ok if newer than the file
bThumbnail = (tThumb >= m_tOrig);
}
if ( !bThumbnail )
return false;
if ( m_thumbURL.isLocalFile() )
{
QPixmap pix;
if ( pix.load( m_thumbURL.path() ) )
bool bThumbnail = false;
if (!job->error()) // found a thumbnail
{
// Found it, use it
m_iconView->setThumbnailPixmap( m_currentItem, pix );
determineNextIcon();
return true;
KIO::UDSEntry entry = job->statResult();
KIO::UDSEntry::ConstIterator it = entry.begin();
time_t tThumb = 0;
for( ; it != entry.end(); it++ ) {
if ( (*it).m_uds == KIO::UDS_MODIFICATION_TIME ) {
tThumb = (time_t)((*it).m_long);
}
}
// Only ok if newer than the file
bThumbnail = (tThumb >= m_tOrig);
}
if ( !bThumbnail )
return false;
if ( m_thumbURL.isLocalFile() )
{
QPixmap pix;
if ( pix.load( m_thumbURL.path() ) )
{
// Found it, use it
m_iconView->setThumbnailPixmap( m_currentItem, pix );
determineNextIcon();
return true;
}
}
else
{
m_state = STATE_GETTHUMB;
QString localFile = tmpnam(0); // Generate a temp file name
KURL localURL;
localURL.setPath( localFile );
KIO::Job * job = KIO::file_copy( m_thumbURL, localURL, -1, false, false, false /* No GUI */ );
kdDebug(1203) << "KonqImagePreviewJob: KIO::file_copy thumb " << m_thumbURL.url() << " to " << localFile << endl;
addSubjob(job);
return true;
}
return false;
}
void KonqImagePreviewJob::getOrCreateThumbnail()
{
// We still need to load the orig file ! (This is getting tedious) :)
if ( m_currentURL.isLocalFile() )
createThumbnail( m_currentURL.path() );
else
{
m_state = STATE_GETORIG;
QString localFile = tmpnam(0); // Generate a temp file name
KURL localURL;
localURL.setPath( localFile );
KIO::Job * job = KIO::file_copy( m_currentURL, localURL, -1, false,
false, false /* No GUI */ );
kdDebug(1203) << "KonqImagePreviewJob: KIO::file_copy orig "
<< m_currentURL.url() << " to " << localFile << endl;
addSubjob(job);
}
}
else
{
m_state = STATE_GETTHUMB;
QString localFile = tmpnam(0); // Generate a temp file name
KURL localURL;
localURL.setPath( localFile );
KIO::Job * job = KIO::file_copy( m_thumbURL, localURL, -1, false, false, false /* No GUI */ );
kdDebug(1203) << "KonqImagePreviewJob: KIO::file_copy thumb " << m_thumbURL.url() << " to " << localFile << endl;
addSubjob(job);
return true;
}
return false;
}
void KonqImagePreviewJob::createThumbnail( QString pixPath )

View file

@ -56,6 +56,7 @@ public:
protected:
void determineNextIcon();
void determineThumbnailURL();
void getOrCreateThumbnail();
bool statResultThumbnail( KIO::StatJob * );
void createThumbnail( QString );
@ -67,11 +68,11 @@ private slots:
private:
void saveThumbnail(const QImage &img);
private:
enum { STATE_STATORIG, STATE_STATTHUMB, STATE_STATXV, STATE_GETTHUMB, // if the thumbnail exists
STATE_CREATEDIR1, STATE_CREATEDIR2, STATE_GETORIG, STATE_PUTTHUMB, // if we create it
STATE_CREATETHUMB // thumbnail:/ slave
STATE_CREATETHUMB // thumbnail:/ slave
} m_state;
// Our todo list :)