diff options
Diffstat (limited to 'tdeioslave/thumbnail')
25 files changed, 2186 insertions, 0 deletions
diff --git a/tdeioslave/thumbnail/CMakeLists.txt b/tdeioslave/thumbnail/CMakeLists.txt new file mode 100644 index 000000000..9836c76af --- /dev/null +++ b/tdeioslave/thumbnail/CMakeLists.txt @@ -0,0 +1,135 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +##### check for openexr ######################### + +if( WITH_OPENEXR ) + pkg_search_module( OPENEXR OpenEXR ) + if( NOT OPENEXR_FOUND ) + message(FATAL_ERROR "\nopenexr are requested, but not found on your system" ) + endif( NOT OPENEXR_FOUND ) + set( HAVE_EXR 1 ) +endif( WITH_OPENEXR ) + + +##### compiler/linker flags ##################### + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} + ${XCURSOR_INCLUDE_DIRS} + ${OPENEXR_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +##### other data ################################ + +install( FILES + thumbnail.protocol imagethumbnail.desktop textthumbnail.desktop + htmlthumbnail.desktop djvuthumbnail.desktop + DESTINATION ${SERVICES_INSTALL_DIR} ) + +install( FILES thumbcreator.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR} ) + + +##### kio_thumbnail (module) #################### + +set( target kio_thumbnail ) + +tde_add_kpart( ${target} AUTOMOC + SOURCES thumbnail.cpp + LINK tdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) + + +##### imagethumbnail (module) #################### + +set( target imagethumbnail ) + +tde_add_kpart( ${target} AUTOMOC + SOURCES imagecreator.cpp + LINK tdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) + + +##### textthumbnail (module) #################### + +set( target textthumbnail ) + +tde_add_kpart( ${target} AUTOMOC + SOURCES textcreator.cpp + LINK tdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) + + +##### htmlthumbnail (module) #################### + +set( target htmlthumbnail ) + +tde_add_kpart( ${target} AUTOMOC + SOURCES htmlcreator.cpp + LINK tdehtml-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) + + +##### djvuthumbnail (module) #################### + +set( target djvuthumbnail ) + +tde_add_kpart( ${target} AUTOMOC + SOURCES djvucreator.cpp + LINK tdecore-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) + + +##### cursorthumbnail (module) ################## + +if( WITH_XCURSOR ) + + set( target cursorthumbnail ) + + tde_add_kpart( ${target} AUTOMOC + SOURCES cursorcreator.cpp + LINK tdecore-shared ${XCURSOR_LIBRARIES} + DESTINATION ${PLUGIN_INSTALL_DIR} + ) + + install( FILES cursorthumbnail.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) + +endif( WITH_XCURSOR ) + + +##### exrthumbnail (module) ##################### + +if( WITH_OPENEXR ) + + set( target exrthumbnail ) + + tde_add_kpart( ${target} AUTOMOC + SOURCES exrcreator.cpp + LINK tdecore-shared ${OPENEXR_LIBRARIES} + DESTINATION ${PLUGIN_INSTALL_DIR} + ) + + install( FILES exrthumbnail.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) + +endif( WITH_OPENEXR ) diff --git a/tdeioslave/thumbnail/Makefile.am b/tdeioslave/thumbnail/Makefile.am new file mode 100644 index 000000000..93697f148 --- /dev/null +++ b/tdeioslave/thumbnail/Makefile.am @@ -0,0 +1,69 @@ +## Makefile.am of tdebase/tdeioslave/thumbnail + +INCLUDES = $(all_includes) $(EXR_FLAGS) +AM_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_KIO) -ltdetexteditor +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_TDECORE) +djvuthumbnail_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) + +cursorthumbnail_la_SOURCES = cursorcreator.cpp +cursorthumbnail_la_LIBADD = $(LIB_TDECORE) $(LIB_XCURSOR) +cursorthumbnail_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) + +exrthumbnail_la_SOURCES = exrcreator.cpp +exrthumbnail_la_LIBADD = $(LIB_TDECORE) $(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)/tdeio_thumbnail.pot + diff --git a/tdeioslave/thumbnail/configure.in.in b/tdeioslave/thumbnail/configure.in.in new file mode 100644 index 000000000..829727b69 --- /dev/null +++ b/tdeioslave/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/tdeioslave/thumbnail/cursorcreator.cpp b/tdeioslave/thumbnail/cursorcreator.cpp new file mode 100644 index 000000000..a8f6a2eb9 --- /dev/null +++ b/tdeioslave/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 <tqimage.h> +#include <tqfile.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 TQString &path, int width, int height, TQImage &img ) +{ + XcursorImage *cursor = XcursorFilenameLoadImage( + TQFile::encodeName( path ).data(), + width > height ? height : width ); + + if ( cursor ) { + img = TQImage( reinterpret_cast<uchar *>( cursor->pixels ), + cursor->width, cursor->height, 32, + NULL, 0, TQImage::BigEndian ); + img.setAlphaBuffer( true ); + + // Convert the image to non-premultiplied alpha + TQ_UINT32 *pixels = reinterpret_cast<TQ_UINT32 *>( img.bits() ); + for ( int i = 0; i < (img.width() * img.height()); i++ ) { + float alpha = tqAlpha( pixels[i] ) / 255.0; + if ( alpha > 0.0 && alpha < 1.0 ) + pixels[i] = tqRgba( int( tqRed(pixels[i]) / alpha ), + int( tqGreen(pixels[i]) / alpha ), + int( tqBlue(pixels[i]) / alpha ), + tqAlpha(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/tdeioslave/thumbnail/cursorcreator.h b/tdeioslave/thumbnail/cursorcreator.h new file mode 100644 index 000000000..a9b845fd0 --- /dev/null +++ b/tdeioslave/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 <tdeio/thumbcreator.h> + +class CursorCreator : public ThumbCreator +{ + public: + CursorCreator() {} + bool create( const TQString &path, int, int, TQImage &img ); +}; + +#endif + diff --git a/tdeioslave/thumbnail/cursorthumbnail.desktop b/tdeioslave/thumbnail/cursorthumbnail.desktop new file mode 100644 index 000000000..8aead0601 --- /dev/null +++ b/tdeioslave/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-TDE-Library=cursorthumbnail +CacheThumbnail=false diff --git a/tdeioslave/thumbnail/djvucreator.cpp b/tdeioslave/thumbnail/djvucreator.cpp new file mode 100644 index 000000000..20a32fb26 --- /dev/null +++ b/tdeioslave/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 <tqfile.h> +#include <tqimage.h> + +#include <kdemacros.h> + +#include "djvucreator.h" + + + +extern "C" +{ + KDE_EXPORT ThumbCreator *new_creator() + { + return new DjVuCreator; + } +} + +bool DjVuCreator::create(const TQString &path, int width, int height, TQImage &img) +{ + int output[2]; + TQByteArray data(1024); + bool ok = false; + + if (pipe(output) == -1) + return false; + + const char* argv[8]; + TQCString sizearg, fnamearg; + sizearg.sprintf("%dx%d", width, height); + fnamearg = TQFile::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/tdeioslave/thumbnail/djvucreator.h b/tdeioslave/thumbnail/djvucreator.h new file mode 100644 index 000000000..b1335ac7c --- /dev/null +++ b/tdeioslave/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 <tdeio/thumbcreator.h> + +class DjVuCreator : public ThumbCreator +{ +public: + DjVuCreator() {} + virtual bool create(const TQString &path, int, int, TQImage &img); + virtual Flags flags() const; + +}; + +#endif diff --git a/tdeioslave/thumbnail/djvuthumbnail.desktop b/tdeioslave/thumbnail/djvuthumbnail.desktop new file mode 100644 index 000000000..8608da662 --- /dev/null +++ b/tdeioslave/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-TDE-Library=djvuthumbnail +CacheThumbnail=true +IgnoreMaximumSize=true diff --git a/tdeioslave/thumbnail/exrcreator.cpp b/tdeioslave/thumbnail/exrcreator.cpp new file mode 100644 index 000000000..59c1fba76 --- /dev/null +++ b/tdeioslave/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 <tqimage.h> + +#include <kimageio.h> +#include <kdebug.h> +#include <tdeconfig.h> +#include <kglobal.h> +#include <tqfile.h> + +#include <ImfInputFile.h> +#include <ImfPreviewImage.h> + +#include "exrcreator.h" + +extern "C" +{ + KDE_EXPORT ThumbCreator *new_creator() + { + return new EXRCreator; + } +} + +bool EXRCreator::create(const TQString &path, int, int, TQImage &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(); + TQImage qpreview(preview.width(), preview.height(), 32, 0, TQImage::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, tqRgba(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; + TDEConfig * config = TDEGlobal::config(); + TDEConfigGroupSaver cgs( config, "PreviewSettings" ); + unsigned long long maxSize = config->readNumEntry( "MaximumSize", 1024*1024 /* 1MB */ ); + unsigned long long fileSize = TQFile( 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/tdeioslave/thumbnail/exrcreator.h b/tdeioslave/thumbnail/exrcreator.h new file mode 100644 index 000000000..8fb831bec --- /dev/null +++ b/tdeioslave/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 <tdeio/thumbcreator.h> + +class EXRCreator : public ThumbCreator +{ +public: + EXRCreator() {}; + virtual bool create(const TQString &path, int, int, TQImage &img); + virtual Flags flags() const; +}; + +#endif diff --git a/tdeioslave/thumbnail/exrthumbnail.desktop b/tdeioslave/thumbnail/exrthumbnail.desktop new file mode 100644 index 000000000..a1ec416a1 --- /dev/null +++ b/tdeioslave/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-TDE-Library=exrthumbnail +CacheThumbnail=true +IgnoreMaximumSize=true diff --git a/tdeioslave/thumbnail/htmlcreator.cpp b/tdeioslave/thumbnail/htmlcreator.cpp new file mode 100644 index 000000000..a928e4253 --- /dev/null +++ b/tdeioslave/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 <tqpixmap.h> +#include <tqimage.h> +#include <tqpainter.h> +#include <kapplication.h> +#include <tdehtml_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 TQString &path, int width, int height, TQImage &img) +{ + if (!m_html) + { + m_html = new KHTMLPart; + connect(m_html, TQT_SIGNAL(completed()), TQT_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); + + tqApp->enter_loop(); + + killTimer(t); + + // render the HTML page on a bigger pixmap and use smoothScale, + // looks better than directly scaling with the TQPainter (malte) + TQPixmap 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( TQColor( 245, 245, 245 ) ); + + int borderX = pix.width() / width, borderY = pix.height() / height; + TQRect rc(borderX, borderY, pix.width() - borderX * 2, + pix.height() - borderY * 2); + + TQPainter p; + p.begin(&pix); + m_html->paint(&p, rc); + p.end(); + + img = pix.convertToImage(); + + m_html->closeURL(); + + return true; +} + +void HTMLCreator::timerEvent(TQTimerEvent *) +{ + tqApp->exit_loop(); +} + +void HTMLCreator::slotCompleted() +{ + tqApp->exit_loop(); +} + +ThumbCreator::Flags HTMLCreator::flags() const +{ + return DrawFrame; +} + +#include "htmlcreator.moc" + diff --git a/tdeioslave/thumbnail/htmlcreator.h b/tdeioslave/thumbnail/htmlcreator.h new file mode 100644 index 000000000..31ef0f398 --- /dev/null +++ b/tdeioslave/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 <tdeio/thumbcreator.h> + +class KHTMLPart; + +class HTMLCreator : public TQObject, public ThumbCreator +{ + Q_OBJECT +public: + HTMLCreator(); + virtual ~HTMLCreator(); + virtual bool create(const TQString &path, int width, int height, TQImage &img); + virtual Flags flags() const; + +protected: + virtual void timerEvent(TQTimerEvent *); + +private slots: + void slotCompleted(); + +private: + KHTMLPart *m_html; +}; + +#endif diff --git a/tdeioslave/thumbnail/htmlthumbnail.desktop b/tdeioslave/thumbnail/htmlthumbnail.desktop new file mode 100644 index 000000000..084673f57 --- /dev/null +++ b/tdeioslave/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-TDE-Library=htmlthumbnail +CacheThumbnail=true diff --git a/tdeioslave/thumbnail/imagecreator.cpp b/tdeioslave/thumbnail/imagecreator.cpp new file mode 100644 index 000000000..259a8928f --- /dev/null +++ b/tdeioslave/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 <tqimage.h> + +#include <kimageio.h> + +#include "imagecreator.h" + +extern "C" +{ + KDE_EXPORT ThumbCreator *new_creator() + { + KImageIO::registerFormats(); + return new ImageCreator; + } +} + +bool ImageCreator::create(const TQString &path, int, int, TQImage &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/tdeioslave/thumbnail/imagecreator.h b/tdeioslave/thumbnail/imagecreator.h new file mode 100644 index 000000000..05278611d --- /dev/null +++ b/tdeioslave/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 <tdeio/thumbcreator.h> + +class ImageCreator : public ThumbCreator +{ +public: + ImageCreator() {} + virtual bool create(const TQString &path, int, int, TQImage &img); + virtual Flags flags() const; +}; + +#endif diff --git a/tdeioslave/thumbnail/imagethumbnail.desktop b/tdeioslave/thumbnail/imagethumbnail.desktop new file mode 100644 index 000000000..ca76f4d59 --- /dev/null +++ b/tdeioslave/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-TDE-Library=imagethumbnail +CacheThumbnail=true diff --git a/tdeioslave/thumbnail/textcreator.cpp b/tdeioslave/thumbnail/textcreator.cpp new file mode 100644 index 000000000..322c944a2 --- /dev/null +++ b/tdeioslave/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 <tqfile.h> +#include <tqpixmap.h> +#include <tqimage.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 TQString &path, int width, int height, TQImage &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; + TQString pixmap = locate( "data", "konqueror/pics/thumbnailfont_7x4.png" ); + if ( !pixmap.isEmpty() ) + { + // FIXME: make font/glyphsize configurable... + m_splitter->setPixmap( TQPixmap( pixmap )); + m_splitter->setItemSize( TQSize( 4, 7 )); + } + } + + bool ok = false; + + // determine some sizes... + // example: width: 60, height: 64 + TQSize 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 + + TQSize 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 + TQFile 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'; + TQString text = TQString::fromLocal8Bit( m_data ); + // FIXME: maybe strip whitespace and read more? + + m_pixmap.fill( TQColor( 245, 245, 245 ) ); // light-grey background + + TQRect 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 TQPixmap *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) + TQChar 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, TQPoint(x,y), fontPixmap, rect, TQt::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/tdeioslave/thumbnail/textcreator.h b/tdeioslave/thumbnail/textcreator.h new file mode 100644 index 000000000..e3ab984d1 --- /dev/null +++ b/tdeioslave/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 <tqpixmap.h> +#include <tdeio/thumbcreator.h> + +class KPixmapSplitter; + +class TextCreator : public ThumbCreator +{ +public: + TextCreator(); + virtual ~TextCreator(); + virtual bool create(const TQString &path, int width, int height, TQImage &img); + virtual Flags flags() const; + +private: + KPixmapSplitter *m_splitter; + char *m_data; + int m_dataSize; + TQPixmap m_pixmap; +}; + +#endif diff --git a/tdeioslave/thumbnail/textthumbnail.desktop b/tdeioslave/thumbnail/textthumbnail.desktop new file mode 100644 index 000000000..16fa73a8b --- /dev/null +++ b/tdeioslave/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-TDE-Library=textthumbnail +CacheThumbnail=false diff --git a/tdeioslave/thumbnail/thumbcreator.desktop b/tdeioslave/thumbnail/thumbcreator.desktop new file mode 100644 index 000000000..e3151bf77 --- /dev/null +++ b/tdeioslave/thumbnail/thumbcreator.desktop @@ -0,0 +1,86 @@ +[Desktop Entry] +Type=ServiceType +X-TDE-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=TQStringList + +[PropertyDef::CacheThumbnail] +Type=bool + +[PropertyDef::IgnoreMaximumSize] +Type=bool diff --git a/tdeioslave/thumbnail/thumbnail.cpp b/tdeioslave/thumbnail/thumbnail.cpp new file mode 100644 index 000000000..1d5d4c929 --- /dev/null +++ b/tdeioslave/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 <tqfile.h> +#include <tqbitmap.h> +#include <tqpixmap.h> +#include <tqpainter.h> +#include <tqimage.h> +#include <tqbuffer.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 <tdefilemetainfo.h> +#include <klocale.h> + +#include <config.h> // For HAVE_NICE +#include "thumbnail.h" +#include <tdeio/thumbcreator.h> + +// Use correctly TDEInstance instead of TDEApplication (but then no TQPixmap) +#undef USE_KINSTANCE +// Fix thumbnail: protocol +#define THUMBNAIL_HACK (1) + +#ifdef THUMBNAIL_HACK +# include <tqfileinfo.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 TDEIO; + +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 + TDEInstance instance("kio_thumbnail"); +#else + // creating TDEApplication 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 TDEApplication :( + putenv(strdup("SESSION_MANAGER=")); + TDEApplication::disableAutoDcopRegistration(); + + TDEApplication 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 TQCString &pool, const TQCString &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; + TQFileInfo info(url.path()); + if (info.isDir()) + { + // We cannot process a directory + error(TDEIO::ERR_IS_DIRECTORY,url.path()); + return; + } + else if (!info.exists()) + { + // The file does not exist + error(TDEIO::ERR_DOES_NOT_EXIST,url.path()); + return; + } + else if (!info.isReadable()) + { + // The file is not readable! + error(TDEIO::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(TDEIO::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(TDEIO::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 = TDEGlobal::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; + + TQImage img; + + TDEConfigGroup group( TDEGlobal::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() == TQVariant::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"; + TQString plugin = metaData("plugin"); +#ifdef THUMBNAIL_HACK + if (plugin.isEmpty()) + { + KTrader::OfferList plugins = KTrader::self()->query("ThumbCreator"); + TQMap<TQString, KService::Ptr> mimeMap; + + for (KTrader::OfferList::ConstIterator it = plugins.begin(); it != plugins.end(); ++it) + { + TQStringList mimeTypes = (*it)->property("MimeTypes").toStringList(); + for (TQStringList::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(TDEIO::ERR_INTERNAL, i18n("No plugin specified.")); + return; + } + + ThumbCreator *creator = m_creators[plugin]; + if (!creator) + { + // Don't use KLibFactory here, this is not a TQObject and + // neither is ThumbCreator + KLibrary *library = KLibLoader::self()->library(TQFile::encodeName(plugin)); + if (library) + { + newCreator create = (newCreator)library->symbol("new_creator"); + if (create) + creator = create(); + } + if (!creator) + { + error(TDEIO::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(TDEIO::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(TQMAX((double)m_height / imgRatio, 1)), m_height); + else + img = img.smoothScale(m_width, int(TQMAX((double)m_width * imgRatio, 1))); + } + +// ### FIXME +#ifndef USE_KINSTANCE + if (flags & ThumbCreator::DrawFrame) + { + TQPixmap pix; + pix.convertFromImage(img); + int x2 = pix.width() - 1; + int y2 = pix.height() - 1; + // paint a black rectangle around the "page" + TQPainter p; + p.begin( &pix ); + p.setPen( TQColor( 48, 48, 48 )); + p.drawLine( x2, 0, x2, y2 ); + p.drawLine( 0, y2, x2, y2 ); + p.setPen( TQColor( 215, 215, 215 )); + p.drawLine( 0, 0, x2, 0 ); + p.drawLine( 0, 0, 0, y2 ); + p.end(); + + const TQBitmap *mask = pix.mask(); + if ( mask ) // need to update it so we can see the frame + { + TQBitmap bitmap( *mask ); + TQPainter 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) && TDEGlobal::iconLoader()->alphaBlending(KIcon::Desktop)) + { + // blending the mimetype icon in + TQImage 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(TDEIO::ERR_INTERNAL, i18n("Failed to create a thumbnail.")); + return; + } + + const TQString 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; + TQBuffer buf; + if (!buf.open(IO_WriteOnly)) + { + error(TDEIO::ERR_INTERNAL, i18n("Could not write image.")); + return; + } + img.save(&buf,"PNG"); + buf.close(); + data(buf.buffer()); + } + else +#endif + { + TQByteArray imgData; + TQDataStream stream( imgData, IO_WriteOnly ); + //kdDebug(7115) << "IMAGE TO STREAM" << endl; + stream << img; + data(imgData); + } + } + else + { + TQByteArray imgData; + TQDataStream stream( imgData, IO_WriteOnly ); + //kdDebug(7115) << "IMAGE TO SHMID" << endl; + void *shmaddr = shmat(shmid.toInt(), 0, 0); + if (shmaddr == (void *)-1) + { + error(TDEIO::ERR_INTERNAL, i18n("Failed to attach to shared memory segment %1").arg(shmid)); + return; + } + if (img.width() * img.height() > m_width * m_height) + { + error(TDEIO::ERR_INTERNAL, i18n("Image is too big for the shared memory segment")); + shmdt((char*)shmaddr); + return; + } + if( img.depth() != 32 ) // TDEIO::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 TQImage& ThumbnailProtocol::getIcon() +{ + TQImage* icon = m_iconDict.find(m_mimeType); + if ( !icon ) // generate it! + { + icon = new TQImage( 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/tdeioslave/thumbnail/thumbnail.h b/tdeioslave/thumbnail/thumbnail.h new file mode 100644 index 000000000..760d3b151 --- /dev/null +++ b/tdeioslave/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 <tqdict.h> + +#include <tdeio/slavebase.h> + +class ThumbCreator; +class TQImage; + +class ThumbnailProtocol : public TDEIO::SlaveBase +{ +public: + ThumbnailProtocol(const TQCString &pool, const TQCString &app); + virtual ~ThumbnailProtocol(); + + virtual void get(const KURL &url); + +protected: + const TQImage& getIcon(); + +private: + TQString m_mimeType; + int m_width; + int m_height; + bool m_keepAspectRatio; + int m_iconSize; + int m_iconAlpha; + // Thumbnail creators + TQDict<ThumbCreator> m_creators; + // transparent icon cache + TQDict<TQImage> m_iconDict; +}; + +#endif diff --git a/tdeioslave/thumbnail/thumbnail.protocol b/tdeioslave/thumbnail/thumbnail.protocol new file mode 100644 index 000000000..b1426c893 --- /dev/null +++ b/tdeioslave/thumbnail/thumbnail.protocol @@ -0,0 +1,9 @@ +[Protocol] +exec=kio_thumbnail +protocol=thumbnail +input=stream +output=stream +reading=true +source=false +DocPath=tdeioslave/thumbnail.html +Icon=thumbnail |