[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: Thumbnail Standard, XCF reader
From:       Malte Starostik <malte () kde ! org>
Date:       2002-02-11 15:33:42
[Download RAW message or body]

Am Montag, 11. Februar 2002 16:25:16 schrieb Dirk Mueller:
> On Mon, 11 Feb 2002, Malte Starostik wrote:
> > As it adds to the interoperability with "foreign" applications, I'd
> > really like to commit this for 3.0, but not without an okay.
>
> Did you forget to append the patch ?
If you insist :-)
-- 
Malte Starostik
PGP: 1024D/D2F3C787 [C138 2121 FAF3 410A 1C2A  27CD 5431 7745 D2F3 C787]

["kio.diff" (text/x-diff)]

Index: kio/previewjob.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/previewjob.cpp,v
retrieving revision 1.27
diff -u -3 -d -p -r1.27 previewjob.cpp
--- kio/previewjob.cpp	2002/01/25 08:41:17	1.27
+++ kio/previewjob.cpp	2002/02/11 15:31:04
@@ -72,13 +72,19 @@ struct KIO::PreviewJobPrivate
     PreviewItem currentItem;
     // The modification time of that URL
     time_t tOrig;
-    // Path to thumbnail cache for this directory
+    // Path to thumbnail cache for the current size
     QString thumbPath;
+    // Original URL of current item in TMS format
+    // (file:///path/to/file instead of file:/path/to/file)
+    QString origName;
+    // Thumbnail file name for current item
+    QString thumbName;
     // Size of thumbnail
     int width;
     int height;
-    // named thumbnail size for caching
-    QString sizeName;
+    // Unscaled size of thumbnail (128 or 256 if cache is enabled)
+    int cacheWidth;
+    int cacheHeight;
     // Whether the thumbnail should be scaled
     bool bScale;
     // Whether we should save the thumbnail
@@ -114,6 +120,8 @@ PreviewJob::PreviewJob( const KFileItemL
     d->enabledPlugins = enabledPlugins;
     d->width = width;
     d->height = height ? height : width;
+    d->cacheWidth = d->width;
+    d->cacheHeight = d->height;
     d->iconSize = iconSize;
     d->iconAlpha = iconAlpha;
     d->deleteItems = deleteItems;
@@ -183,22 +191,11 @@ void PreviewJob::startPreview()
 
     if (bNeedCache)
     {
-        KGlobal::dirs()->addResourceType( "thumbnails", "share/thumbnails/" );
-        if (d->width == d->height)
-        {
-            if (d->width == 48)
-                d->sizeName = "small";
-            else if (d->width == 64)
-                d->sizeName = "med";
-            else if (d->width == 90)
-                d->sizeName = "large";
-            else if (d->width == 112)
-                d->sizeName = "xxl";
-            else
-                d->sizeName.setNum(d->width);
-        }
-        else
-            d->sizeName = QString::fromLatin1("%1x%2").arg(d->width).arg(d->height);
+        if (d->width <= 128 && d->height <= 128) d->cacheWidth = d->cacheHeight = \
128; +        else d->cacheWidth = d->cacheHeight = 256;
+        d->thumbPath = QDir::homeDirPath() + "/.thumbnails/"
+            + (d->cacheWidth == 128 ? "normal/" : "large/");
+        KStandardDirs::makeDir(d->thumbPath, 0700);
     }
     else
         d->bSave = false;
@@ -233,7 +230,6 @@ void PreviewJob::removeItem( const KFile
 
 void PreviewJob::determineNextFile()
 {
-    KURL oldURL;
     if (d->currentItem.item)
     {
         if (!d->succeeded)
@@ -254,23 +250,6 @@ void PreviewJob::determineNextFile()
         d->currentItem = d->items.first();
         d->succeeded = false;
         d->items.remove(d->items.begin());
-        if (d->bSave)
-        {
-            oldURL.setPath(QDir::cleanDirPath(oldURL.directory()));
-            KURL newURL = d->currentItem.item->url();
-            newURL.setPath(QDir::cleanDirPath(newURL.directory()));
-            // different path, determine cache dir
-            if (oldURL != newURL)
-            {
-                KMD5 md5(QFile::encodeName(newURL.url()));
-                QCString hash = md5.hexDigest();
-                d->thumbPath = locateLocal("thumbnails",
-                    QString::fromLatin1( hash.data(), 4 ) + "/" +
-                    QString::fromLatin1( hash.data()+4, 4 ) + "/" +
-                    QString::fromLatin1( hash.data()+8 ) + "/" +
-                    d->sizeName + "/");
-            }
-        }
         KIO::Job *job = KIO::stat( d->currentItem.item->url(), false );
         addSubjob(job);
     }
@@ -355,18 +334,25 @@ bool PreviewJob::statResultThumbnail()
     if ( d->thumbPath.isEmpty() )
         return false;
 
-    QString thumbPath = d->thumbPath + d->currentItem.item->url().fileName();
-    struct stat st;
-    if ( ::stat( QFile::encodeName( thumbPath ), &st ) != 0 ||
-         st.st_mtime < d->tOrig )
-        return false;
+    KURL url = d->currentItem.item->url();
+    // Don't include the password if any
+    url.setPass(QString::null);
+    // The TMS defines local files as file:///path/to/file instead of KDE's
+    // (file:/path/to/file)
+    if (url.protocol() == "file") d->origName = "file://" + url.path();
+    else d->origName = url.url();
 
-    QPixmap pix;
-    if ( !pix.load( thumbPath ) )
-        return false;
+    KMD5 md5( QFile::encodeName( d->origName ) );
+    d->thumbName = QFile::encodeName( md5.hexDigest() ) + ".png";
 
+    QImage thumb;
+    if ( !thumb.load( d->thumbPath + d->thumbName ) ) return false;
+
+    if ( thumb.text( "Thumb::URI", 0 ) != d->origName ) return false;
+    if ( thumb.text( "Thumb::MTime", 0 ).toInt() != d->tOrig ) return false;
+
     // Found it, use it
-    emitPreview(pix);
+    emitPreview( thumb );
     d->succeeded = true;
     determineNextFile();
     return true;
@@ -400,10 +386,11 @@ void PreviewJob::createThumbnail( QStrin
     KIO::TransferJob *job = KIO::get(thumbURL, false, false);
     addSubjob(job);
     connect(job, SIGNAL(data(KIO::Job *, const QByteArray &)), \
SLOT(slotThumbData(KIO::Job *, const QByteArray &))); +    bool save = d->bSave && \
d->currentItem.plugin->property("CacheThumbnail").toBool();  \
                job->addMetaData("mimeType", d->currentItem.item->mimetype());
-    job->addMetaData("width", QString().setNum(d->width));
-    job->addMetaData("height", QString().setNum(d->height));
-    job->addMetaData("iconSize", QString().setNum(d->iconSize));
+    job->addMetaData("width", QString().setNum(save ? d->cacheWidth : d->width));
+    job->addMetaData("height", QString().setNum(save ? d->cacheHeight : d->height));
+    job->addMetaData("iconSize", QString().setNum(save ? 64 : d->iconSize));
     job->addMetaData("iconAlpha", QString().setNum(d->iconAlpha));
     job->addMetaData("plugin", d->currentItem.plugin->library());
     if (d->shmid == -1)
@@ -412,7 +399,7 @@ void PreviewJob::createThumbnail( QStrin
             shmdt((char*)d->shmaddr);
             shmctl(d->shmid, IPC_RMID, 0);
         }
-        d->shmid = shmget(IPC_PRIVATE, d->width * d->height * 4, IPC_CREAT|0600);
+        d->shmid = shmget(IPC_PRIVATE, d->cacheWidth * d->cacheHeight * 4, \
IPC_CREAT|0600);  if (d->shmid != -1)
         {
             d->shmaddr = static_cast<uchar *>(shmat(d->shmid, 0, SHM_RDONLY));
@@ -433,36 +420,44 @@ void PreviewJob::createThumbnail( QStrin
 void PreviewJob::slotThumbData(KIO::Job *, const QByteArray &data)
 {
     bool save = d->bSave && \
                d->currentItem.plugin->property("CacheThumbnail").toBool();
-    QPixmap pix;
+    QImage thumb;
     if (d->shmaddr)
     {
         QDataStream str(data, IO_ReadOnly);
         int width, height, depth;
         bool alpha;
         str >> width >> height >> depth >> alpha;
-        QImage img(d->shmaddr, width, height, depth, 0, 0, QImage::IgnoreEndian);
-        img.setAlphaBuffer(alpha);
-        pix.convertFromImage(img);
-        if (save)
-        {
-            QByteArray saveData;
-            QDataStream saveStr(saveData, IO_WriteOnly);
-            saveStr << img;
-            saveThumbnail(saveData);
-        }
+        thumb = QImage(d->shmaddr, width, height, depth, 0, 0, \
QImage::IgnoreEndian); +        thumb.setAlphaBuffer(alpha);
     }
-    else
+    else thumb.loadFromData(data);
+    if (save)
     {
-        pix.loadFromData(data);
-        if (save)
-            saveThumbnail(data);
+        thumb.setText("Thumb::URI", 0, d->origName);
+        thumb.setText("Thumb::MTime", 0, QString::number(d->tOrig));
+        thumb.setText("Thumb::Mimetype", 0, d->currentItem.item->mimetype());
+        thumb.setText("Software", 0, "KDE Preview Generator");
+        KTempFile temp(d->thumbPath + "kde-tmp-", ".png");
+        thumb.save(temp.name(), "PNG");
+        rename(QFile::encodeName(temp.name()), QFile::encodeName(d->thumbPath + \
d->thumbName));  }
-    emitPreview(pix);
+    emitPreview( thumb );
     d->succeeded = true;
 }
 
-void PreviewJob::emitPreview(const QPixmap &pix)
+void PreviewJob::emitPreview(const QImage &thumb)
 {
+    QPixmap pix;
+    if (thumb.width() > d->width || thumb.height() > d->height)
+    {
+        double imgRatio = (double)thumb.height() / (double)thumb.width();
+        if (imgRatio > (double)d->height / (double)d->width)
+            pix.convertFromImage(
+                thumb.smoothScale((int)QMAX((double)d->height / imgRatio, 1), \
d->height)); +        else pix.convertFromImage(
+            thumb.smoothScale(d->width, (int)QMAX((double)d->width * imgRatio, 1)));
+    }
+    else pix.convertFromImage(thumb);
     emit gotPreview(d->currentItem.item, pix);
 }
 
@@ -471,16 +466,6 @@ void PreviewJob::emitFailed(const KFileI
     if (!item)
         item = d->currentItem.item;
     emit failed(item);
-}
-
-void PreviewJob::saveThumbnail(const QByteArray &imgData)
-{
-    QFile file( d->thumbPath + d->currentItem.item->url().fileName() );
-    if ( file.open(IO_WriteOnly) )
-    {
-        file.writeBlock( imgData.data(), imgData.size() );
-        file.close();
-    }
 }
 
 QStringList PreviewJob::availablePlugins()
Index: kio/previewjob.h
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/previewjob.h,v
retrieving revision 1.9
diff -u -3 -d -p -r1.9 previewjob.h
--- kio/previewjob.h	2001/12/14 12:18:35	1.9
+++ kio/previewjob.h	2002/02/11 15:31:04
@@ -87,9 +87,8 @@ namespace KIO {
 
     private:
         void determineNextFile();
-        void emitPreview(const QPixmap &pix);
+        void emitPreview(const QImage &thumb);
         void emitFailed(const KFileItem *item = 0);
-        void saveThumbnail(const QByteArray &imgData);
 
     private:
         struct PreviewJobPrivate *d;


["libkonq.diff" (text/x-diff)]

Index: konq_iconviewwidget.cc
===================================================================
RCS file: /home/kde/kdebase/libkonq/konq_iconviewwidget.cc,v
retrieving revision 1.183
diff -u -3 -d -p -r1.183 konq_iconviewwidget.cc
--- konq_iconviewwidget.cc	2002/01/28 20:58:01	1.183
+++ konq_iconviewwidget.cc	2002/02/11 15:31:19
@@ -639,9 +639,11 @@ void KonqIconViewWidget::startImagePrevi
     if (iconSize < 28)
         size = 48;
     else if (iconSize < 40)
-        size = 60;
+        size = 64;
+    else if (iconSize < 60)
+        size = 96;
     else
-        size = 90;
+	size = 128;
 
     d->pPreviewJob = KIO::filePreview( items, size, size, iconSize,
         m_pSettings->textPreviewIconTransparency(), true /* scale */,

["qt-copy-src-kernel.diff" (text/x-diff)]

Index: qpngio.cpp
===================================================================
RCS file: /home/kde/qt-copy/src/kernel/qpngio.cpp,v
retrieving revision 1.38
diff -u -3 -d -p -r1.38 qpngio.cpp
--- qpngio.cpp	2002/01/26 20:45:16	1.38
+++ qpngio.cpp	2002/02/11 15:31:43
@@ -311,6 +311,16 @@ png_get_valid(png_ptr, info_ptr, PNG_INF
     image.setDotsPerMeterX(png_get_x_pixels_per_meter(png_ptr,info_ptr));
     image.setDotsPerMeterY(png_get_y_pixels_per_meter(png_ptr,info_ptr));
 
+#ifndef QT_NO_IMAGE_TEXT
+    png_textp text_ptr;
+    int num_text=0;
+    png_get_text(png_ptr,info_ptr,&text_ptr,&num_text);
+    while (num_text--) {
+	image.setText(text_ptr->key,0,text_ptr->text);
+	text_ptr++;
+    }
+#endif
+
     delete [] row_pointers;
 
     iio->setImage(image);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic