summaryrefslogtreecommitdiffstats
path: root/kioslave/thumbnail
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit4aed2c8219774f5d797760606b8489a92ddc5163 (patch)
tree3f8c130f7d269626bf6a9447407ef6c35954426a /kioslave/thumbnail
downloadtdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz
tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kioslave/thumbnail')
-rw-r--r--kioslave/thumbnail/Makefile.am69
-rw-r--r--kioslave/thumbnail/configure.in.in14
-rw-r--r--kioslave/thumbnail/cursorcreator.cpp69
-rw-r--r--kioslave/thumbnail/cursorcreator.h33
-rw-r--r--kioslave/thumbnail/cursorthumbnail.desktop80
-rw-r--r--kioslave/thumbnail/djvucreator.cpp139
-rw-r--r--kioslave/thumbnail/djvucreator.h35
-rw-r--r--kioslave/thumbnail/djvuthumbnail.desktop81
-rw-r--r--kioslave/thumbnail/exrcreator.cpp85
-rw-r--r--kioslave/thumbnail/exrcreator.h33
-rw-r--r--kioslave/thumbnail/exrthumbnail.desktop79
-rw-r--r--kioslave/thumbnail/htmlcreator.cpp118
-rw-r--r--kioslave/thumbnail/htmlcreator.h47
-rw-r--r--kioslave/thumbnail/htmlthumbnail.desktop86
-rw-r--r--kioslave/thumbnail/imagecreator.cpp51
-rw-r--r--kioslave/thumbnail/imagecreator.h33
-rw-r--r--kioslave/thumbnail/imagethumbnail.desktop85
-rw-r--r--kioslave/thumbnail/textcreator.cpp195
-rw-r--r--kioslave/thumbnail/textcreator.h43
-rw-r--r--kioslave/thumbnail/textthumbnail.desktop87
-rw-r--r--kioslave/thumbnail/thumbcreator.desktop86
-rw-r--r--kioslave/thumbnail/thumbnail.cpp440
-rw-r--r--kioslave/thumbnail/thumbnail.h54
-rw-r--r--kioslave/thumbnail/thumbnail.protocol9
24 files changed, 2051 insertions, 0 deletions
diff --git a/kioslave/thumbnail/Makefile.am b/kioslave/thumbnail/Makefile.am
new file mode 100644
index 000000000..2b76cc4e0
--- /dev/null
+++ b/kioslave/thumbnail/Makefile.am
@@ -0,0 +1,69 @@
+## Makefile.am of kdebase/kioslave/thumbnail
+
+INCLUDES = $(all_includes) $(EXR_FLAGS)
+AM_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+METASOURCES = AUTO
+
+if have_xcursor
+CURSOR_MODULE = cursorthumbnail.la
+CURSOR_DATAFILE = cursorthumbnail.desktop
+endif
+
+if include_EXR_MODULES
+EXR_MODULE = exrthumbnail.la
+EXR_DATAFILE = exrthumbnail.desktop
+endif
+
+kde_module_LTLIBRARIES = kio_thumbnail.la imagethumbnail.la \
+ textthumbnail.la htmlthumbnail.la \
+ djvuthumbnail.la $(CURSOR_MODULE) \
+ $(EXR_MODULE)
+
+kio_thumbnail_la_SOURCES = thumbnail.cpp
+kio_thumbnail_la_LIBADD = $(LIB_KIO)
+kio_thumbnail_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+
+imagethumbnail_la_SOURCES = imagecreator.cpp
+imagethumbnail_la_LIBADD = $(LIB_KIO) # for kimageio
+imagethumbnail_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+
+textthumbnail_la_SOURCES = textcreator.cpp
+textthumbnail_la_LIBADD = $(LIB_KIO) # for kmimetype
+textthumbnail_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+
+htmlthumbnail_la_SOURCES = htmlcreator.cpp
+htmlthumbnail_la_LIBADD = $(LIB_KHTML)
+htmlthumbnail_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+
+djvuthumbnail_la_SOURCES = djvucreator.cpp
+djvuthumbnail_la_LIBADD = $(LIB_KDECORE)
+djvuthumbnail_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+
+cursorthumbnail_la_SOURCES = cursorcreator.cpp
+cursorthumbnail_la_LIBADD = $(LIB_KDECORE) $(LIB_XCURSOR)
+cursorthumbnail_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+
+exrthumbnail_la_SOURCES = exrcreator.cpp
+exrthumbnail_la_LIBADD = $(LIB_KDECORE) $(LIB_EXR)
+exrthumbnail_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+
+noinst_HEADERS = thumbnail.h imagecreator.h textcreator.h htmlcreator.h \
+ djvucreator.h cursorcreator.h \
+ exrcreator.h
+
+kdelnk_DATA = thumbnail.protocol
+kdelnkdir = $(kde_servicesdir)
+
+servicetypes_DATA = thumbcreator.desktop
+servicetypesdir = $(kde_servicetypesdir)
+
+services_DATA = imagethumbnail.desktop textthumbnail.desktop \
+ htmlthumbnail.desktop \
+ djvuthumbnail.desktop \
+ $(CURSOR_DATAFILE) $(EXR_DATAFILE)
+
+servicesdir = $(kde_servicesdir)
+
+messages:
+ $(XGETTEXT) *.cpp -o $(podir)/kio_thumbnail.pot
+
diff --git a/kioslave/thumbnail/configure.in.in b/kioslave/thumbnail/configure.in.in
new file mode 100644
index 000000000..829727b69
--- /dev/null
+++ b/kioslave/thumbnail/configure.in.in
@@ -0,0 +1,14 @@
+AC_ARG_WITH(openexr,
+ [AC_HELP_STRING(--with-openexr,
+ [enable support for OpenEXR @<:@default=check@:>@])],
+ [], with_openexr=check)
+
+if test "x$with_openexr" != xno; then
+ KDE_FIND_LIBEXR
+
+ if test "x$with_openexr" != xcheck && test -z "$LIB_EXR"; then
+ AC_MSG_ERROR([--with-openexr was given, but test for OpenEXR failed])
+ fi
+fi
+
+AM_CONDITIONAL(include_EXR_MODULES, test -n "$LIB_EXR")
diff --git a/kioslave/thumbnail/cursorcreator.cpp b/kioslave/thumbnail/cursorcreator.cpp
new file mode 100644
index 000000000..0b1470bd6
--- /dev/null
+++ b/kioslave/thumbnail/cursorcreator.cpp
@@ -0,0 +1,69 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2003 Fredrik Hglund <fredrik@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <qimage.h>
+#include <qfile.h>
+
+#include <kdemacros.h>
+
+#include "cursorcreator.h"
+
+#include <X11/Xlib.h>
+#include <X11/Xcursor/Xcursor.h>
+
+extern "C"
+{
+ KDE_EXPORT ThumbCreator *new_creator()
+ {
+ return new CursorCreator;
+ }
+}
+
+bool CursorCreator::create( const QString &path, int width, int height, QImage &img )
+{
+ XcursorImage *cursor = XcursorFilenameLoadImage(
+ QFile::encodeName( path ).data(),
+ width > height ? height : width );
+
+ if ( cursor ) {
+ img = QImage( reinterpret_cast<uchar *>( cursor->pixels ),
+ cursor->width, cursor->height, 32,
+ NULL, 0, QImage::BigEndian );
+ img.setAlphaBuffer( true );
+
+ // Convert the image to non-premultiplied alpha
+ Q_UINT32 *pixels = reinterpret_cast<Q_UINT32 *>( img.bits() );
+ for ( int i = 0; i < (img.width() * img.height()); i++ ) {
+ float alpha = qAlpha( pixels[i] ) / 255.0;
+ if ( alpha > 0.0 && alpha < 1.0 )
+ pixels[i] = qRgba( int( qRed(pixels[i]) / alpha ),
+ int( qGreen(pixels[i]) / alpha ),
+ int( qBlue(pixels[i]) / alpha ),
+ qAlpha(pixels[i]) );
+ }
+
+ // Create a deep copy of the image so the image data is preserved
+ img = img.copy();
+ XcursorImageDestroy( cursor );
+ return true;
+ }
+
+ return false;
+}
+
diff --git a/kioslave/thumbnail/cursorcreator.h b/kioslave/thumbnail/cursorcreator.h
new file mode 100644
index 000000000..7ef8ac2fd
--- /dev/null
+++ b/kioslave/thumbnail/cursorcreator.h
@@ -0,0 +1,33 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2003 Fredrik Hglund <fredrik@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef _CURSORCREATOR_H_
+#define _CURSORCREATOR_H_
+
+#include <kio/thumbcreator.h>
+
+class CursorCreator : public ThumbCreator
+{
+ public:
+ CursorCreator() {}
+ bool create( const QString &path, int, int, QImage &img );
+};
+
+#endif
+
diff --git a/kioslave/thumbnail/cursorthumbnail.desktop b/kioslave/thumbnail/cursorthumbnail.desktop
new file mode 100644
index 000000000..cd37ea5c4
--- /dev/null
+++ b/kioslave/thumbnail/cursorthumbnail.desktop
@@ -0,0 +1,80 @@
+[Desktop Entry]
+Type=Service
+Name=Cursor Files
+Name[af]=Muis wyser Lêers
+Name[ar]=ملفات المؤشر
+Name[az]=Kursor Faylları
+Name[be]=Файлы курсораў
+Name[bg]=Файлове с показалци на мишката
+Name[bn]=কার্সর ফাইল
+Name[br]=Restroù reti
+Name[bs]=Datoteke sa kursorima
+Name[ca]=Fitxers de cursor
+Name[cs]=Soubory s kurzory
+Name[csb]=Lopczi kùrsorów
+Name[cy]=Ffeiliau Cyrchydd
+Name[da]=Markørfiler
+Name[de]=Cursor-Dateien
+Name[el]=Αρχεία δρομέα
+Name[eo]=Tipardosierojn
+Name[es]=Archivos de cursores
+Name[et]=Kursorifailid
+Name[eu]=Kurtsore fitxategiak
+Name[fa]=پرونده‌های مکان‌نما
+Name[fi]=Osoitintiedostot
+Name[fr]=Fichiers de curseurs
+Name[fy]=Rinnerke-triemmen
+Name[ga]=Comhaid Chursóra
+Name[gl]=Ficheiros de Ponteiro
+Name[he]=קבצי סמנים
+Name[hi]=संकेतक फ़ाइल
+Name[hr]=Datoteke pokazivača
+Name[hu]=Kurzorfájlok
+Name[is]=Bendilsskrár
+Name[it]=File dei cursori
+Name[ja]=カーソルファイル
+Name[ka]=კურსორთა ფაილები
+Name[kk]=Меңзер файлдары
+Name[km]=ឯកសារ​ទស្សន៍​ទ្រនិច
+Name[ko]=커서 파일
+Name[lt]=Kursorių bylos
+Name[lv]=Kursoru faili
+Name[mk]=Датотеки со покажувачи
+Name[mn]=Түүчээ файл
+Name[ms]=Fail Kursor
+Name[mt]=Fajls ta' kursur
+Name[nb]=Pekerfiler
+Name[nds]=Blinker-Dateien
+Name[ne]=कर्सर फाइल
+Name[nl]=Cursorbestanden
+Name[nn]=Peikarfiler
+Name[pa]=ਕਰਸਰ ਫਾਇਲਾਂ
+Name[pl]=Pliki kursorów
+Name[pt]=Ficheiros de Cursores
+Name[pt_BR]=Arquivos de Cursor
+Name[ro]=Fișiere cursor
+Name[ru]=Файлы курсоров
+Name[rw]=Amadosiye y'Inyoboranyandiko
+Name[se]=Sievánfiillat
+Name[sk]=Súbory s kurzormi
+Name[sl]=Datoteke s kazalci
+Name[sr]=Фајлови показивача
+Name[sr@Latn]=Fajlovi pokazivača
+Name[sv]=Muspekarfiler
+Name[ta]=நிலைகாட்டி கோப்புகள்
+Name[te]=ములుకు దస్త్రాలు
+Name[tg]=Файлҳои курсор
+Name[th]=แฟ้มเคอร์เซอร์
+Name[tr]=İmleç Dosyaları
+Name[tt]=Kürsär Biremnäre
+Name[uk]=Файли курсорів
+Name[uz]=Kursor fayllari
+Name[uz@cyrillic]=Курсор файллари
+Name[vi]=Tập tin Con trỏ
+Name[wa]=Fitchîs cursoe
+Name[zh_CN]=光标文件
+Name[zh_TW]=游標檔案
+ServiceTypes=ThumbCreator
+MimeTypes=image/x-xcursor
+X-KDE-Library=cursorthumbnail
+CacheThumbnail=false
diff --git a/kioslave/thumbnail/djvucreator.cpp b/kioslave/thumbnail/djvucreator.cpp
new file mode 100644
index 000000000..653fc4163
--- /dev/null
+++ b/kioslave/thumbnail/djvucreator.cpp
@@ -0,0 +1,139 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2001 Malte Starostik <malte@kde.org>
+ Copyright (C) 2001 Leon Bottou <leon@bottou.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include <assert.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+#include <sys/time.h>
+#include <sys/wait.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <qfile.h>
+#include <qimage.h>
+
+#include <kdemacros.h>
+
+#include "djvucreator.h"
+
+
+
+extern "C"
+{
+ KDE_EXPORT ThumbCreator *new_creator()
+ {
+ return new DjVuCreator;
+ }
+}
+
+bool DjVuCreator::create(const QString &path, int width, int height, QImage &img)
+{
+ int output[2];
+ QByteArray data(1024);
+ bool ok = false;
+
+ if (pipe(output) == -1)
+ return false;
+
+ const char* argv[8];
+ QCString sizearg, fnamearg;
+ sizearg.sprintf("%dx%d", width, height);
+ fnamearg = QFile::encodeName( path );
+ argv[0] = "ddjvu";
+ argv[1] = "-page";
+ argv[2] = "1";
+ argv[3] = "-size";
+ argv[4] = sizearg.data();
+ argv[5] = fnamearg.data();
+ argv[6] = 0;
+
+ pid_t pid = fork();
+ if (pid == 0)
+ {
+ close(output[0]);
+ dup2(output[1], STDOUT_FILENO);
+ execvp(argv[0], const_cast<char *const *>(argv));
+ exit(1);
+ }
+ else if (pid >= 0)
+ {
+ close(output[1]);
+ int offset = 0;
+ while (!ok) {
+ fd_set fds;
+ FD_ZERO(&fds);
+ FD_SET(output[0], &fds);
+ struct timeval tv;
+ tv.tv_sec = 20;
+ tv.tv_usec = 0;
+ if (select(output[0] + 1, &fds, 0, 0, &tv) <= 0) {
+ if (errno == EINTR || errno == EAGAIN)
+ continue;
+ break; // error or timeout
+ }
+ if (FD_ISSET(output[0], &fds)) {
+ int count = read(output[0], data.data() + offset, 1024);
+ if (count == -1)
+ break;
+ if (count) // prepare for next block
+ {
+ offset += count;
+ data.resize(offset + 1024);
+ }
+ else // got all data
+ {
+ data.resize(offset);
+ ok = true;
+ }
+ }
+ }
+ if (!ok)
+ kill(pid, SIGTERM);
+ int status = 0;
+ if (waitpid(pid, &status, 0) != pid || (status != 0 && status != 256) )
+ ok = false;
+ }
+ else
+ {
+ close(output[1]);
+ }
+
+ close(output[0]);
+ int l = img.loadFromData( data );
+ return ok && l;
+}
+
+
+ThumbCreator::Flags DjVuCreator::flags() const
+{
+ return static_cast<Flags>(DrawFrame);
+}
+
+
diff --git a/kioslave/thumbnail/djvucreator.h b/kioslave/thumbnail/djvucreator.h
new file mode 100644
index 000000000..f6724c163
--- /dev/null
+++ b/kioslave/thumbnail/djvucreator.h
@@ -0,0 +1,35 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2000 Malte Starostik <malte@kde.org>
+ Copyright (C) 2003 Leon Bottou <leon@bottou.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef _DJVUCREATOR_H_
+#define _DJVUCREATOR_H_
+
+#include <kio/thumbcreator.h>
+
+class DjVuCreator : public ThumbCreator
+{
+public:
+ DjVuCreator() {}
+ virtual bool create(const QString &path, int, int, QImage &img);
+ virtual Flags flags() const;
+
+};
+
+#endif
diff --git a/kioslave/thumbnail/djvuthumbnail.desktop b/kioslave/thumbnail/djvuthumbnail.desktop
new file mode 100644
index 000000000..41ef0678f
--- /dev/null
+++ b/kioslave/thumbnail/djvuthumbnail.desktop
@@ -0,0 +1,81 @@
+[Desktop Entry]
+Type=Service
+Name=DjVu Files
+Name[af]=DjVu Lêers
+Name[ar]=ملفات DjVu
+Name[az]=DjVu Faylları
+Name[be]=DjVu файлы
+Name[bg]=DjVu файлове
+Name[bn]=DjVu ফাইল
+Name[br]=Restr DjVu
+Name[bs]=DjVu datoteke
+Name[ca]=Fitxers DjVu
+Name[cs]=DjVu soubory
+Name[csb]=Lopczi DjVu
+Name[cy]=Ffeiliau DjVu
+Name[da]=DjVu-filer
+Name[de]=DjVu-Dateien
+Name[el]=Αρχεία DjVu
+Name[eo]=DjVu-dosieroj
+Name[es]=Archivos DjVu
+Name[et]=DjVu failid
+Name[eu]=DjVu fitxategiak
+Name[fa]=پرونده‌های DjVu
+Name[fi]=DjVu-tiedostot
+Name[fr]=Fichiers DjVu
+Name[fy]=DjVu-triemmen
+Name[ga]=Comhaid DjVu
+Name[gl]=Ficheiros DjVu
+Name[he]=קבצי DjVu
+Name[hi]=DjVu फ़ाइलें
+Name[hr]=DjVu datoteke
+Name[hu]=DjVu-fájlok
+Name[is]=DjVu skrár
+Name[it]=File DjVu
+Name[ja]=DjVuファイル
+Name[ka]=DjVu ფაილები
+Name[kk]=DjVu файлдары
+Name[km]=ឯកសារ DjVu
+Name[ko]=DjVu 파일
+Name[lt]=DjVu bylos
+Name[lv]=DjVu faili
+Name[mk]=DjVu-датотеки
+Name[mn]=DjVu файлууд
+Name[ms]=Fail DjVu
+Name[mt]=Fajls DjVu
+Name[nb]=DjVu-filer
+Name[nds]=DjVu-Dateien
+Name[ne]=DjVu फाइल
+Name[nl]=DjVu-bestanden
+Name[nn]=DjVu-filer
+Name[pa]=DjVu ਫਾਇਲਾਂ
+Name[pl]=Pliki DjVu
+Name[pt]=Ficheiros DjVu
+Name[pt_BR]=Arquivos DjVu
+Name[ro]=Fișiere DjVu
+Name[ru]=Файлы DjVu
+Name[rw]=Amadosiye DjVu
+Name[se]=DjVu-fiilat
+Name[sk]=Súbory DjVu
+Name[sl]=Datoteke DjVu
+Name[sr]=DjVu фајлови
+Name[sr@Latn]=DjVu fajlovi
+Name[sv]=DjVu-filer
+Name[ta]=DjVu கோப்புகள்
+Name[te]=డెజావు దస్త్రాలు
+Name[tg]=Файлҳои DjVu
+Name[th]=แฟ้ม DjVu
+Name[tr]=DjVu Dosyaları
+Name[tt]=DjVu Bireme
+Name[uk]=Файли DjVu
+Name[uz]=DjVu-fayllari
+Name[uz@cyrillic]=DjVu-файллари
+Name[vi]=Tập tin DjVu
+Name[wa]=Fitchîs DjVu
+Name[zh_CN]=DjVu 文件
+Name[zh_TW]=DjVu 檔案
+ServiceTypes=ThumbCreator
+MimeTypes=image/x-djvu,image/x.djvu,image/vnd.djvu
+X-KDE-Library=djvuthumbnail
+CacheThumbnail=true
+IgnoreMaximumSize=true
diff --git a/kioslave/thumbnail/exrcreator.cpp b/kioslave/thumbnail/exrcreator.cpp
new file mode 100644
index 000000000..ac2bc3a71
--- /dev/null
+++ b/kioslave/thumbnail/exrcreator.cpp
@@ -0,0 +1,85 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2004 Brad Hards <bradh@frogmouth.net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <qimage.h>
+
+#include <kimageio.h>
+#include <kdebug.h>
+#include <kconfig.h>
+#include <kglobal.h>
+#include <qfile.h>
+
+#include <ImfInputFile.h>
+#include <ImfPreviewImage.h>
+
+#include "exrcreator.h"
+
+extern "C"
+{
+ KDE_EXPORT ThumbCreator *new_creator()
+ {
+ return new EXRCreator;
+ }
+}
+
+bool EXRCreator::create(const QString &path, int, int, QImage &img)
+{
+ Imf::InputFile in ( path.ascii() );
+ const Imf::Header &h = in.header();
+
+ if ( h.hasPreviewImage() ) {
+ kdDebug() << "EXRcreator - using preview" << endl;
+ const Imf::PreviewImage &preview = in.header().previewImage();
+ QImage qpreview(preview.width(), preview.height(), 32, 0, QImage::BigEndian);
+ for ( unsigned int y=0; y < preview.height(); y++ ) {
+ for ( unsigned int x=0; x < preview.width(); x++ ) {
+ const Imf::PreviewRgba &q = preview.pixels()[x+(y*preview.width())];
+ qpreview.setPixel( x, y, qRgba(q.r, q.g, q.b, q.a) );
+ }
+ }
+ img = qpreview;
+ return true;
+ } else {
+ // do it the hard way
+ // We ignore maximum size when just extracting the thumnail
+ // from the header, but it is very expensive to render large
+ // EXR images just to turn it into an icon, so we go back
+ // to honouring it in here.
+ kdDebug() << "EXRcreator - using original image" << endl;
+ KConfig * config = KGlobal::config();
+ KConfigGroupSaver cgs( config, "PreviewSettings" );
+ unsigned long long maxSize = config->readNumEntry( "MaximumSize", 1024*1024 /* 1MB */ );
+ unsigned long long fileSize = QFile( path ).size();
+ if ( (fileSize > 0) && (fileSize < maxSize) ) {
+ if (!img.load( path )) {
+ return false;
+ }
+ if (img.depth() != 32)
+ img = img.convertDepth( 32 );
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
+
+ThumbCreator::Flags EXRCreator::flags() const
+{
+ return None;
+}
diff --git a/kioslave/thumbnail/exrcreator.h b/kioslave/thumbnail/exrcreator.h
new file mode 100644
index 000000000..498bcfb1b
--- /dev/null
+++ b/kioslave/thumbnail/exrcreator.h
@@ -0,0 +1,33 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2004 Brad Hards <bradh@frogmouth.net>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef _EXRCREATOR_H_
+#define _EXRCREATOR_H_
+
+#include <kio/thumbcreator.h>
+
+class EXRCreator : public ThumbCreator
+{
+public:
+ EXRCreator() {};
+ virtual bool create(const QString &path, int, int, QImage &img);
+ virtual Flags flags() const;
+};
+
+#endif
diff --git a/kioslave/thumbnail/exrthumbnail.desktop b/kioslave/thumbnail/exrthumbnail.desktop
new file mode 100644
index 000000000..b532e31ed
--- /dev/null
+++ b/kioslave/thumbnail/exrthumbnail.desktop
@@ -0,0 +1,79 @@
+[Desktop Entry]
+Type=Service
+Name=EXR Images
+Name[af]=EXR Beelde
+Name[ar]=صور EXR
+Name[az]=EXR Rəsmləri
+Name[be]=Відарысы EXR
+Name[bg]=EXR образи
+Name[bn]=ই-এক্স-আর ছবি
+Name[br]=Skeudennoù EXR
+Name[bs]=EXR slike
+Name[ca]=Imatges EXR
+Name[cs]=EXR obrázky
+Name[csb]=Òbrôzczi EXR
+Name[da]=EXR-billeder
+Name[de]=EXR-Bilder
+Name[el]=Εικόνες EXR
+Name[eo]=EXR-Bildoj
+Name[es]=Imágenes EXR
+Name[et]=EXR pildifailid
+Name[eu]=EXR irudiak
+Name[fa]=تصاویر EXR
+Name[fi]=EXR-kuvat
+Name[fr]=Images EXR
+Name[fy]=EXR-ôfbyldings
+Name[ga]=Íomhánna EXR
+Name[gl]=Imaxes EXR
+Name[he]=תמונות EXR
+Name[hi]=ईएक्सआर छवियाँ
+Name[hr]=EXR slike
+Name[hu]=EXR-képek
+Name[is]=EXR myndir
+Name[it]=Immagini EXR
+Name[ja]=EXR イメージ
+Name[ka]=EXR გამოსახულებები
+Name[kk]=EXR кескіндері
+Name[km]=រូបភាព EXR
+Name[ko]=EXR 그림
+Name[lt]=EXR paveiksliukai
+Name[lv]=EXR attēli
+Name[mk]=EXR-слики
+Name[ms]=Imej EXR
+Name[mt]=Stampi EXR
+Name[nb]=EXR-bilder
+Name[nds]=EXR-Biller
+Name[ne]=EXR छवि
+Name[nl]=EXR-afbeeldingen
+Name[nn]=EXR-bilete
+Name[pa]=EXR ਚਿੱਤਰ
+Name[pl]=Obrazki EXR
+Name[pt]=Imagens EXR
+Name[pt_BR]=Imagens EXR
+Name[ro]=Imagini EXR
+Name[ru]=Рисунки EXR
+Name[rw]=Amashusho EXR
+Name[se]=EXR-govat
+Name[sk]=EXR Obrázky
+Name[sl]=Slike EXR
+Name[sr]=EXR слике
+Name[sr@Latn]=EXR slike
+Name[sv]=EXR-bilder
+Name[ta]=இ எக்ஸ் ஆர் பிம்பங்கள்
+Name[te]=ఈఎక్స్ ఆర్ చిత్రాలు
+Name[tg]=Тасвирҳои EXR
+Name[th]=แฟ้มภาพ EXR
+Name[tr]=EXR Görüntüsü
+Name[tt]=EXR Bireme
+Name[uk]=Зображення EXR
+Name[uz]=EXR-rasmlar
+Name[uz@cyrillic]=EXR-расмлар
+Name[vi]=Ảnh EXR
+Name[wa]=Imådjes EXR
+Name[zh_CN]=EXR Emacs
+Name[zh_TW]=EXR 影像
+ServiceTypes=ThumbCreator
+MimeTypes=image/x-exr
+X-KDE-Library=exrthumbnail
+CacheThumbnail=true
+IgnoreMaximumSize=true
diff --git a/kioslave/thumbnail/htmlcreator.cpp b/kioslave/thumbnail/htmlcreator.cpp
new file mode 100644
index 000000000..0431bcf6e
--- /dev/null
+++ b/kioslave/thumbnail/htmlcreator.cpp
@@ -0,0 +1,118 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2000 Malte Starostik <malte@kde.org>
+ Copyright (C) 2006 Roberto Cappuccio <roberto.cappuccio@gmail.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <time.h>
+#include <qpixmap.h>
+#include <qimage.h>
+#include <qpainter.h>
+#include <kapplication.h>
+#include <khtml_part.h>
+
+#include "htmlcreator.h"
+
+extern "C"
+{
+ KDE_EXPORT ThumbCreator *new_creator()
+ {
+ return new HTMLCreator;
+ }
+}
+
+HTMLCreator::HTMLCreator()
+ : m_html(0)
+{
+}
+
+HTMLCreator::~HTMLCreator()
+{
+ delete m_html;
+}
+
+bool HTMLCreator::create(const QString &path, int width, int height, QImage &img)
+{
+ if (!m_html)
+ {
+ m_html = new KHTMLPart;
+ connect(m_html, SIGNAL(completed()), SLOT(slotCompleted()));
+ m_html->setJScriptEnabled(false);
+ m_html->setJavaEnabled(false);
+ m_html->setPluginsEnabled(false);
+ m_html->setMetaRefreshEnabled(false);
+ m_html->setOnlyLocalReferences(true);
+ }
+ KURL url;
+ url.setPath(path);
+ m_html->openURL(url);
+
+ int t = startTimer(5000);
+
+ qApp->enter_loop();
+
+ killTimer(t);
+
+ // render the HTML page on a bigger pixmap and use smoothScale,
+ // looks better than directly scaling with the QPainter (malte)
+ QPixmap pix;
+ if (width > 400 || height > 600)
+ {
+ if (height * 3 > width * 4)
+ pix.resize(width, width * 4 / 3);
+ else
+ pix.resize(height * 3 / 4, height);
+ }
+ else
+ pix.resize(400, 600);
+
+ // light-grey background, in case loadind the page failed
+ pix.fill( QColor( 245, 245, 245 ) );
+
+ int borderX = pix.width() / width, borderY = pix.height() / height;
+ QRect rc(borderX, borderY, pix.width() - borderX * 2,
+ pix.height() - borderY * 2);
+
+ QPainter p;
+ p.begin(&pix);
+ m_html->paint(&p, rc);
+ p.end();
+
+ img = pix.convertToImage();
+
+ m_html->closeURL();
+
+ return true;
+}
+
+void HTMLCreator::timerEvent(QTimerEvent *)
+{
+ qApp->exit_loop();
+}
+
+void HTMLCreator::slotCompleted()
+{
+ qApp->exit_loop();
+}
+
+ThumbCreator::Flags HTMLCreator::flags() const
+{
+ return DrawFrame;
+}
+
+#include "htmlcreator.moc"
+
diff --git a/kioslave/thumbnail/htmlcreator.h b/kioslave/thumbnail/htmlcreator.h
new file mode 100644
index 000000000..6cb58b18f
--- /dev/null
+++ b/kioslave/thumbnail/htmlcreator.h
@@ -0,0 +1,47 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2000 Malte Starostik <malte@kde.org>
+ Copyright (C) 2006 Roberto Cappuccio <roberto.cappuccio@gmail.com>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef _HTMLCREATOR_H_
+#define _HTMLCREATOR_H_
+
+#include <kio/thumbcreator.h>
+
+class KHTMLPart;
+
+class HTMLCreator : public QObject, public ThumbCreator
+{
+ Q_OBJECT
+public:
+ HTMLCreator();
+ virtual ~HTMLCreator();
+ virtual bool create(const QString &path, int width, int height, QImage &img);
+ virtual Flags flags() const;
+
+protected:
+ virtual void timerEvent(QTimerEvent *);
+
+private slots:
+ void slotCompleted();
+
+private:
+ KHTMLPart *m_html;
+};
+
+#endif
diff --git a/kioslave/thumbnail/htmlthumbnail.desktop b/kioslave/thumbnail/htmlthumbnail.desktop
new file mode 100644
index 000000000..30a057051
--- /dev/null
+++ b/kioslave/thumbnail/htmlthumbnail.desktop
@@ -0,0 +1,86 @@
+[Desktop Entry]
+Type=Service
+Name=HTML Files
+Name[af]=HTML Lêers
+Name[ar]=ملفات HTML
+Name[az]=HTML Faylları
+Name[be]=Файлы HTML
+Name[bg]=HTML файлове
+Name[bn]=HTML ফাইল
+Name[br]=Restroù HTML
+Name[bs]=HTML datoteke
+Name[ca]=Fitxers HTML
+Name[cs]=HTML soubory
+Name[csb]=Lopczi HTML
+Name[cy]=Ffeiliau HTML
+Name[da]=HTML-filer
+Name[de]=HTML-Dateien
+Name[el]=Αρχεία HTML
+Name[eo]=HTML-dosieroj
+Name[es]=Archivos HTML
+Name[et]=HTML failid
+Name[eu]=HTML fitxategiak
+Name[fa]=پرونده‌های زنگام
+Name[fi]=HTML-tiedostot
+Name[fr]=Fichiers HTML
+Name[fy]=HTML-triemmen
+Name[ga]=Comhaid HTML
+Name[gl]=Ficheiros HTML
+Name[he]=קבצי HTML
+Name[hi]=एचटीएमएल फ़ाइलें
+Name[hr]=HTML datoteke
+Name[hu]=HTML-fájlok
+Name[id]=Berkas HTML
+Name[is]=HTML skrár
+Name[it]=File HTML
+Name[ja]=HTML ファイル
+Name[ka]=HTML ფაილები
+Name[kk]=HTML файлдары
+Name[km]=ឯកសារ HTML
+Name[ko]=HTML 파일
+Name[lo]=ແຟ້ມ HTML
+Name[lt]=HTML bylos
+Name[lv]=HTML Faili
+Name[mk]=HTML-датотеки
+Name[mn]=HTML-Файлууд
+Name[ms]=Fail HTML
+Name[mt]=Fajls HTML
+Name[nb]=HTML-filer
+Name[nds]=HTML-Dateien
+Name[ne]=HTML फाइल
+Name[nl]=HTML-bestanden
+Name[nn]=HTML-filer
+Name[nso]=Difaele tsa HTML
+Name[pa]=HTML ਫਾਇਲ਼ਾਂ
+Name[pl]=Strony HTML
+Name[pt]=Ficheiros HTML
+Name[pt_BR]=Arquivos HTML
+Name[ro]=Fișiere HTML
+Name[ru]=Файлы HTML
+Name[rw]=Amadosiye HTML
+Name[se]=HTML-fiillat
+Name[sk]=HTML súbory
+Name[sl]=Datoteke HTML
+Name[sr]=HTML фајлови
+Name[sr@Latn]=HTML fajlovi
+Name[sv]=HTML-filer
+Name[ta]=HTML கோப்புகள்
+Name[te]=హెచ్ టి ఎం ఎల్ దస్త్రాలు
+Name[tg]=Файлҳои HTML
+Name[th]=แฟ้ม HTML
+Name[tr]=HTML Dosyaları
+Name[tt]=HTML Bireme
+Name[uk]=Файли HTML
+Name[uz]=HTML-fayllari
+Name[uz@cyrillic]=HTML-файллари
+Name[ven]=Dzifaela dza HTML
+Name[vi]=Tập tin HTML
+Name[wa]=Fitchîs HTML
+Name[xh]=Iifayile ze HTML
+Name[zh_CN]=HTML 文件
+Name[zh_TW]=HTML 檔案
+Name[zu]=Amafayela e-HTML
+ServiceTypes=ThumbCreator
+MimeTypes=text/html
+X-KDE-Library=htmlthumbnail
+CacheThumbnail=true
diff --git a/kioslave/thumbnail/imagecreator.cpp b/kioslave/thumbnail/imagecreator.cpp
new file mode 100644
index 000000000..24a75a51a
--- /dev/null
+++ b/kioslave/thumbnail/imagecreator.cpp
@@ -0,0 +1,51 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2000 Carsten Pfeiffer <pfeiffer@kde.org>
+ 2000 Malte Starostik <malte@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <assert.h>
+
+#include <qimage.h>
+
+#include <kimageio.h>
+
+#include "imagecreator.h"
+
+extern "C"
+{
+ KDE_EXPORT ThumbCreator *new_creator()
+ {
+ KImageIO::registerFormats();
+ return new ImageCreator;
+ }
+}
+
+bool ImageCreator::create(const QString &path, int, int, QImage &img)
+{
+ // create image preview
+ if (!img.load( path ))
+ return false;
+ if (img.depth() != 32)
+ img = img.convertDepth( 32 );
+ return true;
+}
+
+ThumbCreator::Flags ImageCreator::flags() const
+{
+ return None;
+}
diff --git a/kioslave/thumbnail/imagecreator.h b/kioslave/thumbnail/imagecreator.h
new file mode 100644
index 000000000..d06c9fa7d
--- /dev/null
+++ b/kioslave/thumbnail/imagecreator.h
@@ -0,0 +1,33 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2000 Malte Starostik <malte@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef _IMAGECREATOR_H_
+#define _IMAGECREATOR_H_
+
+#include <kio/thumbcreator.h>
+
+class ImageCreator : public ThumbCreator
+{
+public:
+ ImageCreator() {}
+ virtual bool create(const QString &path, int, int, QImage &img);
+ virtual Flags flags() const;
+};
+
+#endif
diff --git a/kioslave/thumbnail/imagethumbnail.desktop b/kioslave/thumbnail/imagethumbnail.desktop
new file mode 100644
index 000000000..6b53f5392
--- /dev/null
+++ b/kioslave/thumbnail/imagethumbnail.desktop
@@ -0,0 +1,85 @@
+[Desktop Entry]
+Type=Service
+Name=Images
+Name[af]=Beelde
+Name[ar]=الصور
+Name[az]=Rəsmlər
+Name[be]=Відарысы
+Name[bg]=Графични файлове
+Name[bn]=ছবি
+Name[br]=Skeudennoù
+Name[bs]=Slike
+Name[ca]=Imatges
+Name[cs]=Obrázky
+Name[csb]=Òbrôzczi
+Name[cy]=Delweddau
+Name[da]=Billeder
+Name[de]=Bilder
+Name[el]=Εικόνες
+Name[eo]=Bildoj
+Name[es]=Imágenes
+Name[et]=Pildid
+Name[eu]=Irudiak
+Name[fa]=تصاویر
+Name[fi]=Kuvat
+Name[fy]=Ofbyldings
+Name[ga]=Íomhánna
+Name[gl]=Imaxes
+Name[he]=תמונות
+Name[hi]=छवि
+Name[hr]=Slike
+Name[hu]=Képek
+Name[id]=Gambar
+Name[is]=Myndir
+Name[it]=Immagini
+Name[ja]=イメージ
+Name[ka]=გამოსახულებები
+Name[kk]=Кескіндер
+Name[km]=រូបភាព
+Name[ko]=그림
+Name[lo]=ແຟ້ມພາບ
+Name[lt]=Paveiksliukai
+Name[lv]=Attēli
+Name[mk]=Слики
+Name[mn]=Зургууд
+Name[ms]=Imej
+Name[mt]=Stampi
+Name[nb]=Bilder
+Name[nds]=Biller
+Name[ne]=छवि
+Name[nl]=Afbeeldingen
+Name[nn]=Bilete
+Name[nso]=Diponagalo
+Name[pa]=ਚਿੱਤਰ
+Name[pl]=Obrazki
+Name[pt]=Imagens
+Name[pt_BR]=Imagens
+Name[ro]=Imagini
+Name[ru]=Рисунки
+Name[rw]=Amashusho
+Name[se]=Govat
+Name[sk]=Obrázky
+Name[sl]=Slike
+Name[sr]=Слике
+Name[sr@Latn]=Slike
+Name[sv]=Grafik
+Name[ta]=பிம்பங்கள்
+Name[te]=చిత్రాలు
+Name[tg]=Тасвир
+Name[th]=แฟ้มภาพ
+Name[tr]=Resimler
+Name[tt]=Sürätlär
+Name[uk]=Зображення
+Name[uz]=Rasmlar
+Name[uz@cyrillic]=Расмлар
+Name[ven]=Zwifanyiso
+Name[vi]=Ảnh
+Name[wa]=Imådjes
+Name[xh]=Imifanekiso
+Name[zh_CN]=图像
+Name[zh_TW]=影像
+Name[zu]=Izithombe
+ServiceTypes=ThumbCreator
+MimeTypes=image/cgm,image/fax-g3,image/gif,image/jp2,image/jpeg,image/pjpeg,image/png,image/tiff,image/x-bmp,image/x-dds,image/x-ico,image/x-jng,image/x-pcx,image/x-photo-cd,image/x-portable-bitmap,image/x-portable-greymap,image/x-portable-pixmap,image/x-rgb,image/x-targa,image/x-wmf,image/x-xbm,image/x-xcf-gimp,image/x-xfig,image/x-xpm
+X-KDE-Library=imagethumbnail
+CacheThumbnail=true
diff --git a/kioslave/thumbnail/textcreator.cpp b/kioslave/thumbnail/textcreator.cpp
new file mode 100644
index 000000000..b0424e228
--- /dev/null
+++ b/kioslave/thumbnail/textcreator.cpp
@@ -0,0 +1,195 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2000,2002 Carsten Pfeiffer <pfeiffer@kde.org>
+ 2000 Malte Starostik <malte@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <qfile.h>
+#include <qpixmap.h>
+#include <qimage.h>
+
+#include <kstandarddirs.h>
+#include <kpixmapsplitter.h>
+#include <kmimetype.h>
+
+#include "textcreator.h"
+
+extern "C"
+{
+ KDE_EXPORT ThumbCreator *new_creator()
+ {
+ return new TextCreator;
+ }
+}
+
+TextCreator::TextCreator()
+ : m_splitter(0),
+ m_data(0),
+ m_dataSize(0)
+{
+}
+
+TextCreator::~TextCreator()
+{
+ delete m_splitter;
+ delete [] m_data;
+}
+
+bool TextCreator::create(const QString &path, int width, int height, QImage &img)
+{
+ // Filter out unwanted mimetypes
+ KMimeType::Ptr mimeType = KMimeType::findByPath( path );
+ if ( mimeType->is( "text/rtf" ) )
+ return false;
+
+ if ( !m_splitter )
+ {
+ m_splitter = new KPixmapSplitter;
+ QString pixmap = locate( "data", "konqueror/pics/thumbnailfont_7x4.png" );
+ if ( !pixmap.isEmpty() )
+ {
+ // FIXME: make font/glyphsize configurable...
+ m_splitter->setPixmap( QPixmap( pixmap ));
+ m_splitter->setItemSize( QSize( 4, 7 ));
+ }
+ }
+
+ bool ok = false;
+
+ // determine some sizes...
+ // example: width: 60, height: 64
+ QSize pixmapSize( width, height );
+ if (height * 3 > width * 4)
+ pixmapSize.setHeight( width * 4 / 3 );
+ else
+ pixmapSize.setWidth( height * 3 / 4 );
+
+ if ( pixmapSize != m_pixmap.size() )
+ m_pixmap.resize( pixmapSize );
+
+ // one pixel for the rectangle, the rest. whitespace
+ int xborder = 1 + pixmapSize.width()/16; // minimum x-border
+ int yborder = 1 + pixmapSize.height()/16; // minimum y-border
+
+ QSize chSize = m_splitter->itemSize(); // the size of one char
+ int xOffset = chSize.width();
+ int yOffset = chSize.height();
+
+ // calculate a better border so that the text is centered
+ int canvasWidth = pixmapSize.width() - 2*xborder;
+ int canvasHeight = pixmapSize.height() - 2*yborder;
+ int numCharsPerLine = (int) (canvasWidth / chSize.width());
+ int numLines = (int) (canvasHeight / chSize.height());
+
+ // assumes an average line length of <= 120 chars
+ const int bytesToRead = 120 * numLines;
+
+ // create text-preview
+ QFile file( path );
+ if ( file.open( IO_ReadOnly ))
+ {
+ if ( !m_data || m_dataSize < bytesToRead + 1 )
+ {
+ delete [] m_data;
+ m_data = new char[bytesToRead+1];
+ m_dataSize = bytesToRead + 1;
+ }
+
+ int read = file.readBlock( m_data, bytesToRead );
+ if ( read > 0 )
+ {
+ ok = true;
+ m_data[read] = '\0';
+ QString text = QString::fromLocal8Bit( m_data );
+ // FIXME: maybe strip whitespace and read more?
+
+ m_pixmap.fill( QColor( 245, 245, 245 ) ); // light-grey background
+
+ QRect rect;
+
+ int rest = m_pixmap.width() - (numCharsPerLine * chSize.width());
+ xborder = QMAX( xborder, rest/2); // center horizontally
+ rest = m_pixmap.height() - (numLines * chSize.height());
+ yborder = QMAX( yborder, rest/2); // center vertically
+ // end centering
+
+ int x = xborder, y = yborder; // where to paint the characters
+ int posNewLine = m_pixmap.width() - (chSize.width() + xborder);
+ int posLastLine = m_pixmap.height() - (chSize.height() + yborder);
+ bool newLine = false;
+ Q_ASSERT( posNewLine > 0 );
+ const QPixmap *fontPixmap = &(m_splitter->pixmap());
+
+ for ( uint i = 0; i < text.length(); i++ )
+ {
+ if ( x > posNewLine || newLine ) // start a new line?
+ {
+ x = xborder;
+ y += yOffset;
+
+ if ( y > posLastLine ) // more text than space
+ break;
+
+ // after starting a new line, we also jump to the next
+ // physical newline in the file if we don't come from one
+ if ( !newLine )
+ {
+ int pos = text.find( '\n', i );
+ if ( pos == -1 )
+ break;
+ i = pos + 1;
+ }
+
+ newLine = false;
+ }
+
+ // check for newlines in the text (unix,dos)
+ QChar ch = text.at( i );
+ if ( ch == '\n' )
+ {
+ newLine = true;
+ continue;
+ }
+ else if ( ch == '\r' && text.at(i+1) == '\n' )
+ {
+ newLine = true;
+ i++; // skip the next character (\n) as well
+ continue;
+ }
+
+ rect = m_splitter->coordinates( ch );
+ if ( !rect.isEmpty() )
+ {
+ bitBlt( &m_pixmap, QPoint(x,y), fontPixmap, rect, Qt::CopyROP );
+ }
+
+ x += xOffset; // next character
+ }
+ if (ok)
+ img = m_pixmap.convertToImage();
+ }
+
+ file.close();
+ }
+ return ok;
+}
+
+ThumbCreator::Flags TextCreator::flags() const
+{
+ return (Flags)(DrawFrame | BlendIcon);
+}
+
diff --git a/kioslave/thumbnail/textcreator.h b/kioslave/thumbnail/textcreator.h
new file mode 100644
index 000000000..92461d0cd
--- /dev/null
+++ b/kioslave/thumbnail/textcreator.h
@@ -0,0 +1,43 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2000 Malte Starostik <malte@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef _TEXTCREATOR_H_
+#define _TEXTCREATOR_H_
+
+#include <qpixmap.h>
+#include <kio/thumbcreator.h>
+
+class KPixmapSplitter;
+
+class TextCreator : public ThumbCreator
+{
+public:
+ TextCreator();
+ virtual ~TextCreator();
+ virtual bool create(const QString &path, int width, int height, QImage &img);
+ virtual Flags flags() const;
+
+private:
+ KPixmapSplitter *m_splitter;
+ char *m_data;
+ int m_dataSize;
+ QPixmap m_pixmap;
+};
+
+#endif
diff --git a/kioslave/thumbnail/textthumbnail.desktop b/kioslave/thumbnail/textthumbnail.desktop
new file mode 100644
index 000000000..bb13dbf38
--- /dev/null
+++ b/kioslave/thumbnail/textthumbnail.desktop
@@ -0,0 +1,87 @@
+[Desktop Entry]
+Type=Service
+Name=Text Files
+Name[af]=Teks Lêers
+Name[ar]=الملفات النصية
+Name[az]=Mətn Faylları
+Name[be]=Тэкставыя файлы
+Name[bg]=Текстови файлове
+Name[bn]=টেক্সট ফাইল
+Name[br]=Restroù testenn
+Name[bs]=Tekst datoteke
+Name[ca]=Fitxers de text
+Name[cs]=Textové soubory
+Name[csb]=Tekstowé lopczi
+Name[cy]=Ffeiliau Testun
+Name[da]=Tekstfiler
+Name[de]=Textdateien
+Name[el]=Αρχεία κειμένου
+Name[eo]=Tekstdosieroj
+Name[es]=Archivos de texto
+Name[et]=Tekstifailid
+Name[eu]=Testu fitxategiak
+Name[fa]=پرونده‌های متنی
+Name[fi]=Tekstitiedostot
+Name[fr]=Fichiers de texte
+Name[fy]=Teksttriemmen
+Name[ga]=Comhaid Téacs
+Name[gl]=Ficheiros de Texto
+Name[he]=קבצי טקסט
+Name[hi]=पाठ फ़ाइलें
+Name[hr]=Tekstualne datoteke
+Name[hsb]=Tekstowe dataje
+Name[hu]=Szöveges fájlok
+Name[id]=Berkas Teks
+Name[is]=Textaskrár
+Name[it]=File di testo
+Name[ja]=テキストファイル
+Name[ka]=ტექსტური ფაილები
+Name[kk]=Мәтін файлдары
+Name[km]=ឯកសារ​អត្ថបទ
+Name[ko]=텍스트 파일
+Name[lo]=ແຟ້ມຂໍ້ຄວາມ
+Name[lt]=tekstinės bylos
+Name[lv]=Teksta Faili
+Name[mk]=Текстуални датотеки
+Name[mn]=Текст файлууд
+Name[ms]=Fail Teks
+Name[mt]=Fajls ta' Test
+Name[nb]=Tekstfiler
+Name[nds]=Textdateien
+Name[ne]=पाठ फाइल
+Name[nl]=Tekstbestanden
+Name[nn]=Tekstfiler
+Name[nso]=Difaele tsa Sengwalwana
+Name[pa]=ਪਾਠ ਫਾਇਲ਼ਾਂ
+Name[pl]=Pliki tekstowe
+Name[pt]=Ficheiros de Texto
+Name[pt_BR]=Arquivos Texto
+Name[ro]=Fișiere text
+Name[ru]=Текстовые файлы
+Name[rw]=Amadosiye Mwandiko
+Name[se]=Teakstafiilat
+Name[sk]=Textové súbory
+Name[sl]=Besedilne datoteke
+Name[sr]=Текстуални фајлови
+Name[sr@Latn]=Tekstualni fajlovi
+Name[sv]=Textfiler
+Name[ta]=உரை கோப்புகள்
+Name[te]=వచన దస్త్రాలు
+Name[tg]=Файлҳои матн
+Name[th]=แฟ้มข้อความ
+Name[tr]=Metin Dosyaları
+Name[tt]=Mäten Bireme
+Name[uk]=Текстові файли
+Name[uz]=Matn fayllari
+Name[uz@cyrillic]=Матн файллари
+Name[ven]=Dzifaela dza manwalwa
+Name[vi]=Tập tin Văn bản
+Name[wa]=Fitchîs tecse
+Name[xh]=Iifayile Zombhalo
+Name[zh_CN]=文本文件
+Name[zh_TW]=文字檔案
+Name[zu]=Amafayela Ombhalo
+ServiceTypes=ThumbCreator
+MimeTypes=text/plain
+X-KDE-Library=textthumbnail
+CacheThumbnail=false
diff --git a/kioslave/thumbnail/thumbcreator.desktop b/kioslave/thumbnail/thumbcreator.desktop
new file mode 100644
index 000000000..e7c5951f8
--- /dev/null
+++ b/kioslave/thumbnail/thumbcreator.desktop
@@ -0,0 +1,86 @@
+[Desktop Entry]
+Type=ServiceType
+X-KDE-ServiceType=ThumbCreator
+Comment=Thumbnail Handler
+Comment[af]=Duimnael Handteerder
+Comment[ar]=معامل الأظافر
+Comment[az]=Kiçik Rəsm Faylları Nümayişçisi
+Comment[be]=Апрацоўшчык мініяцюраў
+Comment[bg]=Манипулатор на мини изображения
+Comment[bn]=থাম্বনেইল হ্যাণ্ডলার
+Comment[bs]=Upravljanje thumbnail-ima
+Comment[ca]=Gestor de miniatures
+Comment[cs]=Ovladač miniatur
+Comment[csb]=Programa òbsłùżënkù miniaturków
+Comment[cy]=Trinydd Lluniau Cryno
+Comment[da]=Miniaturehåndtering
+Comment[de]=Minibild-Verwaltung
+Comment[el]=Χειριστής εικόνας επισκόπησης
+Comment[eo]=Miniatura traktilo
+Comment[es]=Manejador de miniaturas
+Comment[et]=Pisipiltide käsitlemine
+Comment[eu]=Koadro txikien maneiatzailea
+Comment[fa]=گردانندۀ ریزنقش
+Comment[fi]=Esikatselukuvien hallinta
+Comment[fr]=Gestionnaire d'aperçu des images
+Comment[fy]=Miniatueren ôfhanneler
+Comment[ga]=Láimhseálaí na Mionsamhlacha
+Comment[gl]=Manexador de Miniaturas
+Comment[he]=מנהל הדוגמיות
+Comment[hi]=थम्बनेल हैंडलर
+Comment[hr]=Rukovatelj sličicama
+Comment[hu]=A gyorsnézeti ikonok kezelője
+Comment[is]=Þumalmyndaforrit
+Comment[it]=Gestore delle miniature
+Comment[ja]=サムネイルハンドラ
+Comment[ka]=მინი-გამოსახულების დამმუშავებელი
+Comment[kk]=Нобай өңдеуші
+Comment[km]=ឧបករណ៍​ដោះស្រាយ​រូបភាព​តូចៗ
+Comment[ko]=미리 보기 처리기
+Comment[lt]=Miniatiūrų tvarkiklis
+Comment[lv]=Sīktēlu apkalpotājs
+Comment[mk]=Ракувач со сликички
+Comment[mn]=Бяцхан зураг-Удирдлага
+Comment[ms]=Pengendali Thumbnail
+Comment[mt]=Handler għall-bolol
+Comment[nb]=Håndtering av forhåndsvisning
+Comment[nds]=Minibildmaker
+Comment[ne]=थम्बनेल ह्यान्डलर
+Comment[nl]=Miniafbeeldingenmaker
+Comment[nn]=Handtering av førehandsvising
+Comment[nso]=Moswari wa Thumbnail
+Comment[pa]=ਥੰਮਨੇਲ ਹੈਂਡਲਰ
+Comment[pl]=Program obsługujący miniaturki
+Comment[pt]=Tratamento de Miniaturas
+Comment[pt_BR]=Manipulador de Miniaturas
+Comment[ro]=Generator previzualizări
+Comment[ru]=Обработчик мини-изображений
+Comment[rw]=Mugenga Igaragazaryihuse
+Comment[se]=Gieđahala ovdačájehemiid
+Comment[sk]=Podpora náhľadu obrázkov
+Comment[sl]=Obdelovalnik sličic
+Comment[sr]=Управљач сличицама
+Comment[sr@Latn]=Upravljač sličicama
+Comment[sv]=Hanterar miniatyrbilder
+Comment[ta]=சிறிய பிம்ப கையாளுதல்
+Comment[tg]=Идоракунандаи тасвироти хурдтарины
+Comment[th]=ตัวรับมือภาพตัวอย่างแบบย่อ
+Comment[tr]=Küçük Resim Dosyaları Görüntüleyici
+Comment[tt]=Keçesürät Eşkärtkeç
+Comment[uk]=Маніпулятор мініатюр
+Comment[ven]=Tshaufara nga gunwe
+Comment[vi]=Thao tác Hình nhỏ
+Comment[wa]=Manaedjeu d' prévoeyaedje
+Comment[xh]=Umqheba Wozipho lobhontsi
+Comment[zh_CN]=缩略图处理器
+Comment[zh_TW]=縮圖處理器
+Comment[zu]=Umphathi we-Thumbnail
+
+[PropertyDef::MimeTypes]
+Type=QStringList
+
+[PropertyDef::CacheThumbnail]
+Type=bool
+
+[PropertyDef::IgnoreMaximumSize]
+Type=bool
diff --git a/kioslave/thumbnail/thumbnail.cpp b/kioslave/thumbnail/thumbnail.cpp
new file mode 100644
index 000000000..99cb3a89d
--- /dev/null
+++ b/kioslave/thumbnail/thumbnail.cpp
@@ -0,0 +1,440 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2000 Malte Starostik <malte@kde.org>
+ 2000 Carsten Pfeiffer <pfeiffer@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <stdlib.h>
+#include <unistd.h>
+#ifdef __FreeBSD__
+ #include <machine/param.h>
+#endif
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+#include <qfile.h>
+#include <qbitmap.h>
+#include <qpixmap.h>
+#include <qpainter.h>
+#include <qimage.h>
+#include <qbuffer.h>
+
+#include <kdatastream.h> // Do not remove, needed for correct bool serialization
+#include <kurl.h>
+#include <kapplication.h>
+#include <kglobal.h>
+#include <kiconloader.h>
+#include <kimageeffect.h>
+#include <kmimetype.h>
+#include <klibloader.h>
+#include <kdebug.h>
+#include <kservice.h>
+#include <kservicetype.h>
+#include <kuserprofile.h>
+#include <kfilemetainfo.h>
+#include <klocale.h>
+
+#include <config.h> // For HAVE_NICE
+#include "thumbnail.h"
+#include <kio/thumbcreator.h>
+
+// Use correctly KInstance instead of KApplication (but then no QPixmap)
+#undef USE_KINSTANCE
+// Fix thumbnail: protocol
+#define THUMBNAIL_HACK (1)
+
+#ifdef THUMBNAIL_HACK
+# include <qfileinfo.h>
+# include <ktrader.h>
+#endif
+
+// Recognized metadata entries:
+// mimeType - the mime type of the file, used for the overlay icon if any
+// width - maximum width for the thumbnail
+// height - maximum height for the thumbnail
+// iconSize - the size of the overlay icon to use if any
+// iconAlpha - the transparency value used for icon overlays
+// plugin - the name of the plugin library to be used for thumbnail creation.
+// Provided by the application to save an addition KTrader
+// query here.
+// shmid - the shared memory segment id to write the image's data to.
+// The segment is assumed to provide enough space for a 32-bit
+// image sized width x height pixels.
+// If this is given, the data returned by the slave will be:
+// int width
+// int height
+// int depth
+// Otherwise, the data returned is the image in PNG format.
+
+using namespace KIO;
+
+extern "C"
+{
+ KDE_EXPORT int kdemain(int argc, char **argv);
+}
+
+
+int kdemain(int argc, char **argv)
+{
+#ifdef HAVE_NICE
+ nice( 5 );
+#endif
+
+#ifdef USE_KINSTANCE
+ KInstance instance("kio_thumbnail");
+#else
+ // creating KApplication in a slave in not a very good idea,
+ // as dispatchLoop() doesn't allow it to process its messages,
+ // so it for example wouldn't reply to ksmserver - on the other
+ // hand, this slave uses QPixmaps for some reason, and they
+ // need QApplication
+ // and HTML previews need even KApplication :(
+ putenv(strdup("SESSION_MANAGER="));
+ KApplication::disableAutoDcopRegistration();
+
+ KApplication app(argc, argv, "kio_thumbnail", false, true);
+#endif
+
+ if (argc != 4)
+ {
+ kdError(7115) << "Usage: kio_thumbnail protocol domain-socket1 domain-socket2" << endl;
+ exit(-1);
+ }
+
+ ThumbnailProtocol slave(argv[2], argv[3]);
+ slave.dispatchLoop();
+
+ return 0;
+}
+
+ThumbnailProtocol::ThumbnailProtocol(const QCString &pool, const QCString &app)
+ : SlaveBase("thumbnail", pool, app)
+{
+ m_creators.setAutoDelete(true);
+ m_iconDict.setAutoDelete(true);
+ m_iconSize = 0;
+}
+
+ThumbnailProtocol::~ThumbnailProtocol()
+{
+}
+
+void ThumbnailProtocol::get(const KURL &url)
+{
+ m_mimeType = metaData("mimeType");
+ kdDebug(7115) << "Wanting MIME Type:" << m_mimeType << endl;
+#ifdef THUMBNAIL_HACK
+ // ### HACK
+ bool direct=false;
+ if (m_mimeType.isEmpty())
+ {
+ kdDebug(7115) << "PATH: " << url.path() << endl;
+ QFileInfo info(url.path());
+ if (info.isDir())
+ {
+ // We cannot process a directory
+ error(KIO::ERR_IS_DIRECTORY,url.path());
+ return;
+ }
+ else if (!info.exists())
+ {
+ // The file does not exist
+ error(KIO::ERR_DOES_NOT_EXIST,url.path());
+ return;
+ }
+ else if (!info.isReadable())
+ {
+ // The file is not readable!
+ error(KIO::ERR_COULD_NOT_READ,url.path());
+ return;
+ }
+ m_mimeType = KMimeType::findByURL(url)->name();
+ kdDebug(7115) << "Guessing MIME Type:" << m_mimeType << endl;
+ direct=true; // thumbnail: was probably called from Konqueror
+ }
+#endif
+
+ if (m_mimeType.isEmpty())
+ {
+ error(KIO::ERR_INTERNAL, i18n("No MIME Type specified."));
+ return;
+ }
+
+ m_width = metaData("width").toInt();
+ m_height = metaData("height").toInt();
+ int iconSize = metaData("iconSize").toInt();
+
+ if (m_width < 0 || m_height < 0)
+ {
+ error(KIO::ERR_INTERNAL, i18n("No or invalid size specified."));
+ return;
+ }
+#ifdef THUMBNAIL_HACK
+ else if (!m_width || !m_height)
+ {
+ kdDebug(7115) << "Guessing height, width, icon sizre!" << endl;
+ m_width=128;
+ m_height=128;
+ iconSize=128;
+ }
+#endif
+
+ if (!iconSize)
+ iconSize = KGlobal::iconLoader()->currentSize(KIcon::Desktop);
+ if (iconSize != m_iconSize)
+ m_iconDict.clear();
+ m_iconSize = iconSize;
+
+ m_iconAlpha = metaData("iconAlpha").toInt();
+ if (m_iconAlpha)
+ m_iconAlpha = (m_iconAlpha << 24) | 0xffffff;
+
+ QImage img;
+
+ KConfigGroup group( KGlobal::config(), "PreviewSettings" );
+
+
+ // ### KFMI
+ bool kfmiThumb = false;
+ if (group.readBoolEntry( "UseFileThumbnails", true )) {
+ KService::Ptr service =
+ KServiceTypeProfile::preferredService( m_mimeType, "KFilePlugin");
+
+ if ( service && service->isValid() && /*url.isLocalFile() && */
+ service->property("SupportsThumbnail").toBool())
+ {
+ KFileMetaInfo info(url.path(), m_mimeType, KFileMetaInfo::Thumbnail);
+ if (info.isValid())
+ {
+ KFileMetaInfoItem item = info.item(KFileMimeTypeInfo::Thumbnail);
+ if (item.isValid() && item.value().type() == QVariant::Image)
+ {
+ img = item.value().toImage();
+ kdDebug(7115) << "using KFMI for the thumbnail\n";
+ kfmiThumb = true;
+ }
+ }
+ }
+ }
+ ThumbCreator::Flags flags = ThumbCreator::None;
+
+ if (!kfmiThumb)
+ {
+ kdDebug(7115) << "using thumb creator for the thumbnail\n";
+ QString plugin = metaData("plugin");
+#ifdef THUMBNAIL_HACK
+ if (plugin.isEmpty())
+ {
+ KTrader::OfferList plugins = KTrader::self()->query("ThumbCreator");
+ QMap<QString, KService::Ptr> mimeMap;
+
+ for (KTrader::OfferList::ConstIterator it = plugins.begin(); it != plugins.end(); ++it)
+ {
+ QStringList mimeTypes = (*it)->property("MimeTypes").toStringList();
+ for (QStringList::ConstIterator mt = mimeTypes.begin(); mt != mimeTypes.end(); ++mt)
+ {
+ if ((*mt)==m_mimeType)
+ {
+ plugin=(*it)->library();
+ break;
+ }
+ }
+ if (!plugin.isEmpty())
+ break;
+ }
+ }
+ kdDebug(7115) << "Guess plugin: " << plugin << endl;
+#endif
+ if (plugin.isEmpty())
+ {
+ error(KIO::ERR_INTERNAL, i18n("No plugin specified."));
+ return;
+ }
+
+ ThumbCreator *creator = m_creators[plugin];
+ if (!creator)
+ {
+ // Don't use KLibFactory here, this is not a QObject and
+ // neither is ThumbCreator
+ KLibrary *library = KLibLoader::self()->library(QFile::encodeName(plugin));
+ if (library)
+ {
+ newCreator create = (newCreator)library->symbol("new_creator");
+ if (create)
+ creator = create();
+ }
+ if (!creator)
+ {
+ error(KIO::ERR_INTERNAL, i18n("Cannot load ThumbCreator %1").arg(plugin));
+ return;
+ }
+ m_creators.insert(plugin, creator);
+ }
+
+ if (!creator->create(url.path(), m_width, m_height, img))
+ {
+ error(KIO::ERR_INTERNAL, i18n("Cannot create thumbnail for %1").arg(url.path()));
+ return;
+ }
+ flags = creator->flags();
+ }
+
+ if (img.width() > m_width || img.height() > m_height)
+ {
+ double imgRatio = (double)img.height() / (double)img.width();
+ if (imgRatio > (double)m_height / (double)m_width)
+ img = img.smoothScale( int(QMAX((double)m_height / imgRatio, 1)), m_height);
+ else
+ img = img.smoothScale(m_width, int(QMAX((double)m_width * imgRatio, 1)));
+ }
+
+// ### FIXME
+#ifndef USE_KINSTANCE
+ if (flags & ThumbCreator::DrawFrame)
+ {
+ QPixmap pix;
+ pix.convertFromImage(img);
+ int x2 = pix.width() - 1;
+ int y2 = pix.height() - 1;
+ // paint a black rectangle around the "page"
+ QPainter p;
+ p.begin( &pix );
+ p.setPen( QColor( 48, 48, 48 ));
+ p.drawLine( x2, 0, x2, y2 );
+ p.drawLine( 0, y2, x2, y2 );
+ p.setPen( QColor( 215, 215, 215 ));
+ p.drawLine( 0, 0, x2, 0 );
+ p.drawLine( 0, 0, 0, y2 );
+ p.end();
+
+ const QBitmap *mask = pix.mask();
+ if ( mask ) // need to update it so we can see the frame
+ {
+ QBitmap bitmap( *mask );
+ QPainter painter;
+ painter.begin( &bitmap );
+ painter.drawLine( x2, 0, x2, y2 );
+ painter.drawLine( 0, y2, x2, y2 );
+ painter.drawLine( 0, 0, x2, 0 );
+ painter.drawLine( 0, 0, 0, y2 );
+ painter.end();
+
+ pix.setMask( bitmap );
+ }
+
+ img = pix.convertToImage();
+ }
+#endif
+
+ if ((flags & ThumbCreator::BlendIcon) && KGlobal::iconLoader()->alphaBlending(KIcon::Desktop))
+ {
+ // blending the mimetype icon in
+ QImage icon = getIcon();
+
+ int x = img.width() - icon.width() - 4;
+ x = QMAX( x, 0 );
+ int y = img.height() - icon.height() - 6;
+ y = QMAX( y, 0 );
+ KImageEffect::blendOnLower( x, y, icon, img );
+ }
+
+ if (img.isNull())
+ {
+ error(KIO::ERR_INTERNAL, i18n("Failed to create a thumbnail."));
+ return;
+ }
+
+ const QString shmid = metaData("shmid");
+ if (shmid.isEmpty())
+ {
+#ifdef THUMBNAIL_HACK
+ if (direct)
+ {
+ // If thumbnail was called directly from Konqueror, then the image needs to be raw
+ //kdDebug(7115) << "RAW IMAGE TO STREAM" << endl;
+ QBuffer buf;
+ if (!buf.open(IO_WriteOnly))
+ {
+ error(KIO::ERR_INTERNAL, i18n("Could not write image."));
+ return;
+ }
+ img.save(&buf,"PNG");
+ buf.close();
+ data(buf.buffer());
+ }
+ else
+#endif
+ {
+ QByteArray imgData;
+ QDataStream stream( imgData, IO_WriteOnly );
+ //kdDebug(7115) << "IMAGE TO STREAM" << endl;
+ stream << img;
+ data(imgData);
+ }
+ }
+ else
+ {
+ QByteArray imgData;
+ QDataStream stream( imgData, IO_WriteOnly );
+ //kdDebug(7115) << "IMAGE TO SHMID" << endl;
+ void *shmaddr = shmat(shmid.toInt(), 0, 0);
+ if (shmaddr == (void *)-1)
+ {
+ error(KIO::ERR_INTERNAL, i18n("Failed to attach to shared memory segment %1").arg(shmid));
+ return;
+ }
+ if (img.width() * img.height() > m_width * m_height)
+ {
+ error(KIO::ERR_INTERNAL, i18n("Image is too big for the shared memory segment"));
+ shmdt((char*)shmaddr);
+ return;
+ }
+ if( img.depth() != 32 ) // KIO::PreviewJob and this code below completely
+ img = img.convertDepth( 32 ); // ignores colortable :-/, so make sure there is none
+ stream << img.width() << img.height() << img.depth()
+ << img.hasAlphaBuffer();
+ memcpy(shmaddr, img.bits(), img.numBytes());
+ shmdt((char*)shmaddr);
+ data(imgData);
+ }
+ finished();
+}
+
+const QImage& ThumbnailProtocol::getIcon()
+{
+ QImage* icon = m_iconDict.find(m_mimeType);
+ if ( !icon ) // generate it!
+ {
+ icon = new QImage( KMimeType::mimeType(m_mimeType)->pixmap( KIcon::Desktop, m_iconSize ).convertToImage() );
+ icon->setAlphaBuffer( true );
+
+ int w = icon->width();
+ int h = icon->height();
+ for ( int y = 0; y < h; y++ )
+ {
+ QRgb *line = (QRgb *) icon->scanLine( y );
+ for ( int x = 0; x < w; x++ )
+ line[x] &= m_iconAlpha; // transparency
+ }
+
+ m_iconDict.insert( m_mimeType, icon );
+ }
+
+ return *icon;
+}
+
diff --git a/kioslave/thumbnail/thumbnail.h b/kioslave/thumbnail/thumbnail.h
new file mode 100644
index 000000000..23118e21c
--- /dev/null
+++ b/kioslave/thumbnail/thumbnail.h
@@ -0,0 +1,54 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2000 Malte Starostik <malte@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef _THUMBNAIL_H_
+#define _THUMBNAIL_H_
+
+#include <qdict.h>
+
+#include <kio/slavebase.h>
+
+class ThumbCreator;
+class QImage;
+
+class ThumbnailProtocol : public KIO::SlaveBase
+{
+public:
+ ThumbnailProtocol(const QCString &pool, const QCString &app);
+ virtual ~ThumbnailProtocol();
+
+ virtual void get(const KURL &url);
+
+protected:
+ const QImage& getIcon();
+
+private:
+ QString m_mimeType;
+ int m_width;
+ int m_height;
+ bool m_keepAspectRatio;
+ int m_iconSize;
+ int m_iconAlpha;
+ // Thumbnail creators
+ QDict<ThumbCreator> m_creators;
+ // transparent icon cache
+ QDict<QImage> m_iconDict;
+};
+
+#endif
diff --git a/kioslave/thumbnail/thumbnail.protocol b/kioslave/thumbnail/thumbnail.protocol
new file mode 100644
index 000000000..774db3225
--- /dev/null
+++ b/kioslave/thumbnail/thumbnail.protocol
@@ -0,0 +1,9 @@
+[Protocol]
+exec=kio_thumbnail
+protocol=thumbnail
+input=stream
+output=stream
+reading=true
+source=false
+DocPath=kioslave/thumbnail.html
+Icon=thumbnail