diff options
Diffstat (limited to 'src/gvcore/thumbnailloadjob.cpp')
-rw-r--r-- | src/gvcore/thumbnailloadjob.cpp | 166 |
1 files changed, 83 insertions, 83 deletions
diff --git a/src/gvcore/thumbnailloadjob.cpp b/src/gvcore/thumbnailloadjob.cpp index 09cec44..f4335df 100644 --- a/src/gvcore/thumbnailloadjob.cpp +++ b/src/gvcore/thumbnailloadjob.cpp @@ -1,6 +1,6 @@ // vim: set tabstop=4 shiftwidth=4 noexpandtab: /* Gwenview - A simple image viewer for KDE - Copyright 2000-2004 Aurélien Gâteau + Copyright 2000-2004 Aur�lien G�teau This class is based on the ImagePreviewJob class from Konqueror. Original copyright follows. */ @@ -29,12 +29,12 @@ #include <unistd.h> #include <assert.h> -// Qt -#include <qdir.h> -#include <qfile.h> -#include <qimage.h> -#include <qpixmap.h> -#include <qtimer.h> +// TQt +#include <tqdir.h> +#include <tqfile.h> +#include <tqimage.h> +#include <tqpixmap.h> +#include <tqtimer.h> // KDE #include <kapplication.h> @@ -74,17 +74,17 @@ namespace Gwenview { #endif -static QString generateOriginalURI(KURL url) { +static TQString generateOriginalURI(KURL url) { // Don't include the password if any - url.setPass(QString::null); + url.setPass(TQString()); return url.url(); } -static QString generateThumbnailPath(const QString& uri, int size) { - KMD5 md5( QFile::encodeName(uri) ); - QString baseDir=ThumbnailLoadJob::thumbnailBaseDir(size); - return baseDir + QString(QFile::encodeName( md5.hexDigest())) + ".png"; +static TQString generateThumbnailPath(const TQString& uri, int size) { + KMD5 md5( TQFile::encodeName(uri).data() ); + TQString baseDir=ThumbnailLoadJob::thumbnailBaseDir(size); + return baseDir + TQString(TQFile::encodeName( md5.hexDigest())) + ".png"; } //------------------------------------------------------------------------ @@ -93,12 +93,12 @@ static QString generateThumbnailPath(const QString& uri, int size) { // //------------------------------------------------------------------------ void ThumbnailThread::load( - const QString& originalURI, time_t originalTime, int originalSize, const QString& originalMimeType, - const QString& pixPath, - const QString& thumbnailPath, + const TQString& originalURI, time_t originalTime, int originalSize, const TQString& originalMimeType, + const TQString& pixPath, + const TQString& thumbnailPath, int size, bool storeThumbnail) { - QMutexLocker lock( &mMutex ); + TQMutexLocker lock( &mMutex ); assert( mPixPath.isNull()); mOriginalURI = TSDeepCopy(originalURI); @@ -114,7 +114,7 @@ void ThumbnailThread::load( } void ThumbnailThread::run() { - QMutexLocker lock( &mMutex ); + TQMutexLocker lock( &mMutex ); while( !testCancel()) { // empty mPixPath means nothing to do while( mPixPath.isNull()) { @@ -122,14 +122,14 @@ void ThumbnailThread::run() { if( testCancel()) return; } loadThumbnail(); - mPixPath = QString(); // done, ready for next - QSize size(mOriginalWidth, mOriginalHeight); - emitCancellableSignal( this, SIGNAL( done( const QImage&, const QSize&)), mImage, size); + mPixPath = TQString(); // done, ready for next + TQSize size(mOriginalWidth, mOriginalHeight); + emitCancellableSignal( this, TQT_SIGNAL( done( const TQImage&, const TQSize&)), mImage, size); } } void ThumbnailThread::loadThumbnail() { - mImage = QImage(); + mImage = TQImage(); bool loaded=false; bool needCaching=true; @@ -156,9 +156,9 @@ void ThumbnailThread::loadThumbnail() { mImage=ImageUtils::transform(mImage,orientation); } } - // File is not a JPEG, or JPEG optimized load failed, load file using Qt + // File is not a JPEG, or JPEG optimized load failed, load file using TQt if (!loaded) { - QImage originalImage; + TQImage originalImage; if (originalImage.load(mPixPath)) { mOriginalWidth=originalImage.width(); mOriginalHeight=originalImage.height(); @@ -166,11 +166,11 @@ void ThumbnailThread::loadThumbnail() { if( testCancel()) return; - if (QMAX(mOriginalWidth, mOriginalHeight)<=thumbSize ) { + if (TQMAX(mOriginalWidth, mOriginalHeight)<=thumbSize ) { mImage=originalImage; needCaching = false; } else { - mImage=ImageUtils::scale(originalImage,thumbSize,thumbSize,ImageUtils::SMOOTH_FAST,QImage::ScaleMin); + mImage=ImageUtils::scale(originalImage,thumbSize,thumbSize,ImageUtils::SMOOTH_FAST,TQ_ScaleMin); } loaded = true; } @@ -180,20 +180,20 @@ void ThumbnailThread::loadThumbnail() { if( mStoreThumbnailsInCache && needCaching ) { mImage.setText("Thumb::URI", 0, mOriginalURI); - mImage.setText("Thumb::MTime", 0, QString::number(mOriginalTime)); - mImage.setText("Thumb::Size", 0, QString::number(mOriginalSize)); + mImage.setText("Thumb::MTime", 0, TQString::number(mOriginalTime)); + mImage.setText("Thumb::Size", 0, TQString::number(mOriginalSize)); mImage.setText("Thumb::Mimetype", 0, mOriginalMimeType); - mImage.setText("Thumb::Image::Width", 0, QString::number(mOriginalWidth)); - mImage.setText("Thumb::Image::Height", 0, QString::number(mOriginalHeight)); + mImage.setText("Thumb::Image::Width", 0, TQString::number(mOriginalWidth)); + mImage.setText("Thumb::Image::Height", 0, TQString::number(mOriginalHeight)); mImage.setText("Software", 0, "Gwenview"); - QString thumbnailDir = ThumbnailLoadJob::thumbnailBaseDir(mThumbnailSize); + TQString thumbnailDir = ThumbnailLoadJob::thumbnailBaseDir(mThumbnailSize); KStandardDirs::makeDir(thumbnailDir, 0700); KTempFile tmp(thumbnailDir + "/gwenview", ".png"); tmp.setAutoDelete(true); if (tmp.status()!=0) { - QString reason( strerror(tmp.status()) ); + TQString reason( strerror(tmp.status()) ); kdWarning() << "Could not create a temporary file.\nReason: " << reason << endl; return; } @@ -203,13 +203,13 @@ void ThumbnailThread::loadThumbnail() { return; } - rename(QFile::encodeName(tmp.name()), QFile::encodeName(mThumbnailPath)); + rename(TQFile::encodeName(tmp.name()), TQFile::encodeName(mThumbnailPath)); } } bool ThumbnailThread::isJPEG() { - QString format=QImageIO::imageFormat(mPixPath); + TQString format=TQImageIO::imageFormat(mPixPath); return format=="JPEG"; } @@ -229,7 +229,7 @@ bool ThumbnailThread::loadJPEG() { struct jpeg_decompress_struct cinfo; // Open file - FILE* inputFile=fopen(QFile::encodeName( mPixPath ).data(), "rb"); + FILE* inputFile=fopen(TQFile::encodeName( mPixPath ).data(), "rb"); if(!inputFile) return false; // Error handling @@ -249,7 +249,7 @@ bool ThumbnailThread::loadJPEG() { // Get image size and check if we need a thumbnail int size= mThumbnailSize <= ThumbnailSize::NORMAL ? ThumbnailSize::NORMAL : ThumbnailSize::LARGE; - int imgSize = QMAX(cinfo.image_width, cinfo.image_height); + int imgSize = TQMAX(cinfo.image_width, cinfo.image_height); if (imgSize<=size) { fclose(inputFile); @@ -266,7 +266,7 @@ bool ThumbnailThread::loadJPEG() { cinfo.scale_num=1; cinfo.scale_denom=scale; - // Create QImage + // Create TQImage jpeg_start_decompress(&cinfo); switch(cinfo.output_components) { @@ -277,7 +277,7 @@ bool ThumbnailThread::loadJPEG() { case 1: // B&W image mImage.create( cinfo.output_width, cinfo.output_height, 8, 256 ); for (int i=0; i<256; i++) - mImage.setColor(i, qRgb(i,i,i)); + mImage.setColor(i, tqRgb(i,i,i)); break; default: jpeg_destroy_decompress(&cinfo); @@ -295,16 +295,16 @@ bool ThumbnailThread::loadJPEG() { if ( cinfo.output_components == 3 ) { for (uint j=0; j<cinfo.output_height; j++) { uchar *in = mImage.scanLine(j) + cinfo.output_width*3; - QRgb *out = (QRgb*)( mImage.scanLine(j) ); + TQRgb *out = (TQRgb*)( mImage.scanLine(j) ); for (uint i=cinfo.output_width; i--; ) { in-=3; - out[i] = qRgb(in[0], in[1], in[2]); + out[i] = tqRgb(in[0], in[1], in[2]); } } } - int newMax = QMAX(cinfo.output_width, cinfo.output_height); + int newMax = TQMAX(cinfo.output_width, cinfo.output_height); int newx = size*cinfo.output_width / newMax; int newy = size*cinfo.output_height / newMax; @@ -322,16 +322,16 @@ bool ThumbnailThread::loadJPEG() { // ThumbnailLoadJob static methods // //------------------------------------------------------------------------ -QString ThumbnailLoadJob::thumbnailBaseDir() { - static QString dir; +TQString ThumbnailLoadJob::thumbnailBaseDir() { + static TQString dir; if (!dir.isEmpty()) return dir; - dir=QDir::homeDirPath() + "/.thumbnails/"; + dir=TQDir::homeDirPath() + "/.thumbnails/"; return dir; } -QString ThumbnailLoadJob::thumbnailBaseDir(int size) { - QString dir = thumbnailBaseDir(); +TQString ThumbnailLoadJob::thumbnailBaseDir(int size) { + TQString dir = thumbnailBaseDir(); if (size<=ThumbnailSize::NORMAL) { dir+="normal/"; } else { @@ -342,9 +342,9 @@ QString ThumbnailLoadJob::thumbnailBaseDir(int size) { void ThumbnailLoadJob::deleteImageThumbnail(const KURL& url) { - QString uri=generateOriginalURI(url); - QFile::remove(generateThumbnailPath(uri, ThumbnailSize::NORMAL)); - QFile::remove(generateThumbnailPath(uri, ThumbnailSize::LARGE)); + TQString uri=generateOriginalURI(url); + TQFile::remove(generateThumbnailPath(uri, ThumbnailSize::NORMAL)); + TQFile::remove(generateThumbnailPath(uri, ThumbnailSize::LARGE)); } @@ -371,7 +371,7 @@ void ThumbnailLoadJob::deleteImageThumbnail(const KURL& url) { updateItemsOrder() builds mItems from mAllItems */ -ThumbnailLoadJob::ThumbnailLoadJob(const QValueVector<const KFileItem*>* items, int size) +ThumbnailLoadJob::ThumbnailLoadJob(const TQValueVector<const KFileItem*>* items, int size) : KIO::Job(false), mState( STATE_NEXTTHUMB ), mCurrentVisibleIndex( -1 ), mFirstVisibleIndex( -1 ), mLastVisibleIndex( -1 ), mThumbnailSize(size), mSuspended( false ) @@ -385,11 +385,11 @@ ThumbnailLoadJob::ThumbnailLoadJob(const QValueVector<const KFileItem*>* items, Q_ASSERT(!items->empty()); mAllItems=*items; mProcessedState.resize( mAllItems.count()); - qFill( mProcessedState.begin(), mProcessedState.end(), false ); + tqFill( mProcessedState.begin(), mProcessedState.end(), false ); mCurrentItem = NULL; - connect(&mThumbnailThread, SIGNAL(done(const QImage&, const QSize&)), - SLOT(thumbnailReady(const QImage&, const QSize&)) ); + connect(&mThumbnailThread, TQT_SIGNAL(done(const TQImage&, const TQSize&)), + TQT_SLOT(thumbnailReady(const TQImage&, const TQSize&)) ); Cache::instance()->updateAge(); // see addThumbnail in Cache } @@ -547,9 +547,9 @@ void ThumbnailLoadJob::determineNextIcon() { if( mCurrentURL.isLocalFile() && !KIO::probably_slow_mounted( mCurrentURL.path())) { KDE_struct_stat buff; - if ( KDE_stat( QFile::encodeName(mCurrentURL.path()), &buff ) == 0 ) { + if ( KDE_stat( TQFile::encodeName(mCurrentURL.path()), &buff ) == 0 ) { mOriginalTime = buff.st_mtime; - QTimer::singleShot( 0, this, SLOT( checkThumbnail())); + TQTimer::singleShot( 0, this, TQT_SLOT( checkThumbnail())); } } if( mOriginalTime == 0 ) { // KIO must be used @@ -598,8 +598,8 @@ void ThumbnailLoadJob::slotResult(KIO::Job * job) { if (job->error()) { emitThumbnailLoadingFailed(); LOG("Delete temp file " << mTempPath); - QFile::remove(mTempPath); - mTempPath = QString::null; + TQFile::remove(mTempPath); + mTempPath = TQString(); determineNextIcon(); } else { startCreatingThumbnail(mTempPath); @@ -613,9 +613,9 @@ void ThumbnailLoadJob::slotResult(KIO::Job * job) { } -void ThumbnailLoadJob::thumbnailReady( const QImage& im, const QSize& _size) { - QImage img = TSDeepCopy( im ); - QSize size = _size; +void ThumbnailLoadJob::thumbnailReady( const TQImage& im, const TQSize& _size) { + TQImage img = TSDeepCopy( im ); + TQSize size = _size; if ( !img.isNull()) { emitThumbnailLoaded(img, size); } else { @@ -623,8 +623,8 @@ void ThumbnailLoadJob::thumbnailReady( const QImage& im, const QSize& _size) { } if( !mTempPath.isEmpty()) { LOG("Delete temp file " << mTempPath); - QFile::remove(mTempPath); - mTempPath = QString::null; + TQFile::remove(mTempPath); + mTempPath = TQString(); } determineNextIcon(); } @@ -634,14 +634,14 @@ void ThumbnailLoadJob::checkThumbnail() { if (mCurrentURL.isLocalFile() && mCurrentURL.directory(false).startsWith(thumbnailBaseDir()) ) { - QImage image(mCurrentURL.path()); + TQImage image(mCurrentURL.path()); emitThumbnailLoaded(image, image.size()); determineNextIcon(); return; } - QSize imagesize; + TQSize imagesize; if( mOriginalTime == time_t( Cache::instance()->timestamp( mCurrentURL ).toTime_t())) { - QPixmap cached = Cache::instance()->thumbnail( mCurrentURL, imagesize ); + TQPixmap cached = Cache::instance()->thumbnail( mCurrentURL, imagesize ); if( !cached.isNull()) { emit thumbnailLoaded(mCurrentItem, cached, imagesize); determineNextIcon(); @@ -654,19 +654,19 @@ void ThumbnailLoadJob::checkThumbnail() { LOG("Stat thumb " << mThumbnailPath); - QImage thumb; + TQImage thumb; if ( thumb.load(mThumbnailPath) ) { if (thumb.text("Thumb::URI", 0) == mOriginalURI && thumb.text("Thumb::MTime", 0).toInt() == mOriginalTime ) { int width=0, height=0; - QSize size; + TQSize size; bool ok; width=thumb.text("Thumb::Image::Width", 0).toInt(&ok); if (ok) height=thumb.text("Thumb::Image::Height", 0).toInt(&ok); if (ok) { - size=QSize(width, height); + size=TQSize(width, height); } else { LOG("Thumbnail for " << mOriginalURI << " does not contain correct image size information"); KFileMetaInfo fmi(mCurrentURL); @@ -688,7 +688,7 @@ void ThumbnailLoadJob::checkThumbnail() { } // Thumbnail not found or not valid - if ( MimeTypeUtils::rasterImageMimeTypes().contains(mCurrentItem->mimetype()) ) { + if ( MimeTypeUtils::rasterImageMimeTypes().tqcontains(mCurrentItem->mimetype()) ) { // This is a raster image if (mCurrentURL.isLocalFile()) { // Original is a local file, create the thumbnail @@ -712,16 +712,16 @@ void ThumbnailLoadJob::checkThumbnail() { list.append(mCurrentItem); KIO::Job* job=KIO::filePreview(list, mThumbnailSize); job->setWindow(KApplication::kApplication()->mainWidget()); - connect(job, SIGNAL(gotPreview(const KFileItem*, const QPixmap&)), - this, SLOT(slotGotPreview(const KFileItem*, const QPixmap&)) ); - connect(job, SIGNAL(failed(const KFileItem*)), - this, SLOT(emitThumbnailLoadingFailed()) ); + connect(job, TQT_SIGNAL(gotPreview(const KFileItem*, const TQPixmap&)), + this, TQT_SLOT(slotGotPreview(const KFileItem*, const TQPixmap&)) ); + connect(job, TQT_SIGNAL(failed(const KFileItem*)), + this, TQT_SLOT(emitThumbnailLoadingFailed()) ); addSubjob(job); return; } } -void ThumbnailLoadJob::startCreatingThumbnail(const QString& pixPath) { +void ThumbnailLoadJob::startCreatingThumbnail(const TQString& pixPath) { LOG("Creating thumbnail from " << pixPath); mThumbnailThread.load( mOriginalURI, mOriginalTime, mCurrentItem->size(), mCurrentItem->mimetype(), pixPath, mThumbnailPath, mThumbnailSize, @@ -729,33 +729,33 @@ void ThumbnailLoadJob::startCreatingThumbnail(const QString& pixPath) { } -void ThumbnailLoadJob::slotGotPreview(const KFileItem* item, const QPixmap& pixmap) { +void ThumbnailLoadJob::slotGotPreview(const KFileItem* item, const TQPixmap& pixmap) { LOG(""); - QSize size; + TQSize size; emit thumbnailLoaded(item, pixmap, size); } -void ThumbnailLoadJob::emitThumbnailLoaded(const QImage& img, QSize size) { - int biggestDimension=QMAX(img.width(), img.height()); +void ThumbnailLoadJob::emitThumbnailLoaded(const TQImage& img, TQSize size) { + int biggestDimension=TQMAX(img.width(), img.height()); - QImage thumbImg; + TQImage thumbImg; if (biggestDimension>mThumbnailSize) { // Scale down thumbnail if necessary - thumbImg=ImageUtils::scale(img,mThumbnailSize, mThumbnailSize, ImageUtils::SMOOTH_FAST,QImage::ScaleMin); + thumbImg=ImageUtils::scale(img,mThumbnailSize, mThumbnailSize, ImageUtils::SMOOTH_FAST,TQ_ScaleMin); } else { thumbImg=img; } - QDateTime tm; + TQDateTime tm; tm.setTime_t( mOriginalTime ); - QPixmap thumb( thumbImg ); // store as QPixmap in cache (faster to retrieve, no conversion needed) + TQPixmap thumb( thumbImg ); // store as TQPixmap in cache (faster to retrieve, no conversion needed) Cache::instance()->addThumbnail( mCurrentURL, thumb, size, tm ); emit thumbnailLoaded(mCurrentItem, thumb, size); } void ThumbnailLoadJob::emitThumbnailLoadingFailed() { - QSize size; + TQSize size; emit thumbnailLoaded(mCurrentItem, mBrokenPixmap, size); } |