diff --git a/kioslave/thumbnail/CMakeLists.txt b/kioslave/thumbnail/CMakeLists.txt index e7863bca..ad17a5a4 100644 --- a/kioslave/thumbnail/CMakeLists.txt +++ b/kioslave/thumbnail/CMakeLists.txt @@ -65,17 +65,12 @@ endif() ########### next target ############### -set(windowsexethumbnail_SRCS windowsexecreator.cpp icoutils.cpp) -set(windowsimagethumbnail_SRCS windowsimagecreator.cpp icoutils.cpp) +set(windowsexethumbnail_SRCS windowsexecreator.cpp) kde4_add_plugin(windowsexethumbnail ${windowsexethumbnail_SRCS}) target_link_libraries( windowsexethumbnail ${KDE4_KIO_LIBS} ) install(TARGETS windowsexethumbnail DESTINATION ${KDE4_PLUGIN_INSTALL_DIR} ) -kde4_add_plugin(windowsimagethumbnail ${windowsimagethumbnail_SRCS}) -target_link_libraries(windowsimagethumbnail ${KDE4_KIO_LIBS}) -install(TARGETS windowsimagethumbnail DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}) - ########### next target ############### set(comicbookthumbnail_SRCS comiccreator.cpp) @@ -111,7 +106,6 @@ install( textthumbnail.desktop desktopthumbnail.desktop comicbookthumbnail.desktop - windowsimagethumbnail.desktop windowsexethumbnail.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR} ) diff --git a/kioslave/thumbnail/icoutils.cpp b/kioslave/thumbnail/icoutils.cpp deleted file mode 100644 index badb4a48..00000000 --- a/kioslave/thumbnail/icoutils.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - icoutils_common.cpp - Extract Microsoft Window icons and images using icoutils package - - Copyright (c) 2009-2010 by Pali Rohár - - ************************************************************************* - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - ************************************************************************* -*/ - -#include "icoutils.h" - -#include -#include -#include -#include -#include -#include -#include - -typedef QPair < QString, int > IconInExe; - -bool IcoUtils::loadIcoImageFromExe(const QString &inputFileName, QImage &image, int needWidth, int needHeight) -{ - QProcess wrestool; - wrestool.start("wrestool", QStringList() << "-l" << inputFileName); - wrestool.waitForFinished(); - - if ( wrestool.exitCode() != 0 ) - return false; - - const QStringList output = QString(wrestool.readAll()).split('\n'); - - QRegExp regExp("--type=(.*) --name=(.*) --language=(.*) \\[(.*)\\]"); - - QList icons; - - // First try use group icons (type 14, default first for windows executables), then icons (type 3), then group cursors (type 12) and finaly cursors (type 1) - // Note: Last icon (type 3) could be in higher resolution - - // Group Icons - foreach ( const QString &line, output ) - if ( regExp.indexIn(line) != -1 && regExp.cap(1).toInt() == 14 ) - icons << qMakePair(regExp.cap(2), 14); - - // Icons - foreach ( const QString &line, output ) - if ( regExp.indexIn(line) != -1 && regExp.cap(1).toInt() == 3 ) - icons << qMakePair(regExp.cap(2), 3); - - if ( icons.isEmpty() ) - return false; - - foreach ( const IconInExe &icon, icons ) - { - - QString name = icon.first; - int type = icon.second; - - if ( name.at(0) == '\'' ) - name = name.mid(1, name.size()-2); - - - QTemporaryFile outputFile; - - if ( ! outputFile.open() ) - return false; - - QFile(outputFile.fileName()).resize(0); - - wrestool.start("wrestool", QStringList() << "-x" << "-t" << QString::number(type) << "-n" << name << inputFileName << "-o" << outputFile.fileName()); - wrestool.waitForFinished(); - - if ( wrestool.exitCode() == 0 && QFile(outputFile.fileName()).size() != 0 ) - return IcoUtils::loadIcoImage(outputFile.fileName(), image, needWidth, needHeight); - - } - - return false; -} - -bool IcoUtils::loadIcoImage(const QString &inputFileName, QImage &image, int needWidth, int needHeight) -{ - QImageReader reader(inputFileName, "ico"); - if ( ! reader.canRead() ) - return false; - - QList icons; - do icons << reader.read(); - while ( reader.jumpToNextImage() ); - - if ( icons.empty() ) - return false; - - int min_w = 1024; - int min_h = 1024; - int index = icons.size() - 1; - - - // we loop in reverse order because QtIcoHandler converts all images to 32-bit depth, and resources are ordered from lower depth to higher depth - for ( int i_index = icons.size() - 1; i_index >= 0 ; --i_index ) - { - - const QImage &icon = icons.at(i_index); - int i_width = icon.width(); - int i_height = icon.height(); - int i_w = qAbs(i_width - needWidth); - int i_h = qAbs(i_height - needHeight); - - if ( i_w < min_w || ( i_w == min_w && i_h < min_h ) ) - { - - min_w = i_w; - min_h = i_h; - index = i_index; - - } - - } - - image = icons.at(index); - return true; -} diff --git a/kioslave/thumbnail/icoutils.h b/kioslave/thumbnail/icoutils.h deleted file mode 100644 index 04f75565..00000000 --- a/kioslave/thumbnail/icoutils.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - icoutils.h - Extract Microsoft Window icons and images using icoutils package - - Copyright (c) 2009-2010 by Pali Rohár - Copyright (c) 2013 by Andrius da Costa Ribas - - ************************************************************************* - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - ************************************************************************* -*/ - -#ifndef ICO_UTILS_H -#define ICO_UTILS_H - -#include -#include - -namespace IcoUtils -{ - - bool loadIcoImageFromExe(const QString &inputPath, QImage &image, int needWidth, int needHeigh); - - bool loadIcoImage(const QString &inputFileName, QImage &image, int needWidth, int needHeight); - -} - -#endif //ICO_UTILS_H diff --git a/kioslave/thumbnail/windowsexecreator.cpp b/kioslave/thumbnail/windowsexecreator.cpp index 4d8684ed..83cafc8c 100644 --- a/kioslave/thumbnail/windowsexecreator.cpp +++ b/kioslave/thumbnail/windowsexecreator.cpp @@ -14,24 +14,86 @@ */ #include "windowsexecreator.h" -#include "icoutils.h" #include #include +#include +#include +#include +#include #include +typedef QPair IconInExe; + extern "C" { KDE_EXPORT ThumbCreator *new_creator() { - return new WindowsExeCreator; + return new WindowsExeCreator(); } } +WindowsExeCreator::WindowsExeCreator() +{ +} + bool WindowsExeCreator::create(const QString &path, int width, int height, QImage &img) { + QProcess wrestool; + wrestool.start("wrestool", QStringList() << "-l" << path); + wrestool.waitForFinished(); - return IcoUtils::loadIcoImageFromExe(path, img, width, height); + if (wrestool.exitCode() != 0) { + return false; + } + const QStringList output = QString(wrestool.readAll()).split('\n'); + + QRegExp regExp("--type=(.*) --name=(.*) --language=(.*) \\[(.*)\\]"); + + QList icons; + + // First try use group icons (type 14, default first for windows executables) + foreach (const QString &line, output) { + if (regExp.indexIn(line) != -1 && regExp.cap(1).toInt() == 14) { + icons << qMakePair(regExp.cap(2), 14); + } + } + + // Then icons (type 3, could be in higher resolution) + foreach (const QString &line, output) { + if (regExp.indexIn(line) != -1 && regExp.cap(1).toInt() == 3) { + icons << qMakePair(regExp.cap(2), 3); + } + } + + foreach (const IconInExe &icon, icons) { + QString name = icon.first; + const int type = icon.second; + + if (name.at(0) == '\'') { + name = name.mid(1, name.size() - 2); + } + + QString outputFile = KTemporaryFile::filePath("XXXXXXXXXX.ico"); + + const QStringList wrestoolargs = QStringList() + << "-x" + << "-t" << QString::number(type) + << "-n" << name + << "-o" << outputFile + << path; + wrestool.start("wrestool", wrestoolargs); + wrestool.waitForFinished(); + + if (wrestool.exitCode() == 0 && QFile::exists(outputFile)) { + const QImage tmp(outputFile, "ICO"); + img = tmp.scaled(QSize(width, height), Qt::KeepAspectRatio); + QFile::remove(outputFile); + return true; + } + } + + return false; } diff --git a/kioslave/thumbnail/windowsexecreator.h b/kioslave/thumbnail/windowsexecreator.h index 24d52713..7c0985e4 100644 --- a/kioslave/thumbnail/windowsexecreator.h +++ b/kioslave/thumbnail/windowsexecreator.h @@ -22,8 +22,9 @@ class WindowsExeCreator : public ThumbCreator { public: - WindowsExeCreator() {} - bool create(const QString &path, int width, int height, QImage &img); + WindowsExeCreator(); + + bool create(const QString &path, int width, int height, QImage &img) final; }; #endif // WINDOWS_EXE_CREATOR_H diff --git a/kioslave/thumbnail/windowsimagecreator.cpp b/kioslave/thumbnail/windowsimagecreator.cpp deleted file mode 100644 index d8f02c40..00000000 --- a/kioslave/thumbnail/windowsimagecreator.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - windowsimagecreator.cpp - Thumbnail Creator for Microsoft Windows Images - - Copyright (c) 2009 by Pali Rohár - - ************************************************************************* - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - ************************************************************************* -*/ - -#include "windowsimagecreator.h" -#include "icoutils.h" - -#include -#include - -#include - -extern "C" -{ - KDE_EXPORT ThumbCreator *new_creator() - { - return new WindowsImageCreator; - } -} - -bool WindowsImageCreator::create(const QString &path, int width, int height, QImage &img) -{ - - return IcoUtils::loadIcoImage(path, img, width, height); - -} diff --git a/kioslave/thumbnail/windowsimagecreator.h b/kioslave/thumbnail/windowsimagecreator.h deleted file mode 100644 index f221fd38..00000000 --- a/kioslave/thumbnail/windowsimagecreator.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - windowsimagecreator.h - Thumbnail Creator for Microsoft Windows Images - - Copyright (c) 2009-2010 by Pali Rohár - - ************************************************************************* - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - ************************************************************************* -*/ - -#ifndef WINDOWS_IMAGE_CREATOR_H -#define WINDOWS_IMAGE_CREATOR_H - -#include - -class WindowsImageCreator : public ThumbCreator -{ -public: - WindowsImageCreator() {} - bool create(const QString &path, int width, int height, QImage &img); -}; - -#endif // WINDOWS_IMAGE_CREATOR_H diff --git a/kioslave/thumbnail/windowsimagethumbnail.desktop b/kioslave/thumbnail/windowsimagethumbnail.desktop deleted file mode 100644 index 65483d2e..00000000 --- a/kioslave/thumbnail/windowsimagethumbnail.desktop +++ /dev/null @@ -1,79 +0,0 @@ -[Desktop Entry] -Encoding=UTF-8 -Type=Service -Name=Microsoft Windows Images -Name[ar]=صور مايكروسوفت ويندوز -Name[ast]=Imáxenes de Microsoft Windows -Name[bg]=Изображения за Microsoft Windows -Name[bn]=মাইক্রোসফ্ট উইন্ডোজ ইমেজ -Name[bs]=Slike s Vindouza -Name[ca]=Imatges de Microsoft Windows -Name[ca@valencia]=Imatges de Microsoft Windows -Name[cs]=Obrázky Microsoft Windows -Name[csb]=Òbrôzczi Microsoft Windows -Name[da]=Microsoft Windows-billeder -Name[de]=Microsoft-Windows-Bilder -Name[el]=Εικόνες Microsoft Windows -Name[en_GB]=Microsoft Windows Images -Name[eo]=Bildoj de Mikrosofto Vindozo -Name[es]=Imágenes de Microsoft Windows -Name[et]=Microsoft Windowsi pildid -Name[eu]=Microsoft Windows irudiak -Name[fa]=تصویر مایکروسافت ویندوز -Name[fi]=Microsoft Windows -vedokset -Name[fr]=Images Microsoft Windows -Name[fy]=Microsoft Windows ôfbyldings -Name[ga]=Íomhánna MS Windows -Name[gl]=Imaxes de Microsoft Windows -Name[gu]=માઈક્રોસોફ્ટ વિન્ડોઝ છબીઓ -Name[he]=תמונות של Microsoft Windows -Name[hi]=माइक्रोसॉफ़्ट विंडो छवियाँ -Name[hr]=Microsoft Windows Slike -Name[hu]=Windows-os képek -Name[ia]=Imagines de Microsoft Windows -Name[id]=Gambar Microsoft Windows -Name[is]=Microsoft Windows myndir -Name[it]=Immagini di Microsoft Windows -Name[ja]=Microsoft Windows 画像 -Name[kk]=Microsoft Windows-тың кескіндері -Name[km]=រូបភាព​របស់ Microsoft Windows -Name[kn]=ಮೈಕ್ರೋಸಾಫ್ಟ್ ವಿಂಡೋಸ್ ಚಿತ್ರಗಳು -Name[ko]=마이크로소프트 Windows 그림 -Name[lt]=Microsoft Windows paveikslėliai -Name[lv]=Microsoft Windows attēli -Name[mk]=Microsoft Windows-слики -Name[ml]=മൈക്രോസോഫ്റ്റ് വിന്‍ഡോസ് ചിത്രങ്ങള്‍ -Name[mr]=माइक्रोसॉफ्ट विंडोज प्रतिमा -Name[nb]=Microsoft Windows-bilder -Name[nds]=Microsoft-Windows-Biller -Name[nl]=Afbeeldingen van Microsoft Windows -Name[nn]=Microsoft Windows-bilete -Name[pa]=ਮਾਈਕਰੋਸਾਫਟ ਵਿੰਡੋਜ਼ ਚਿੱਤਰ -Name[pl]=Obrazy Microsoft Windows -Name[pt]=Imagens do Microsoft Windows -Name[pt_BR]=Imagens do Microsoft Windows -Name[ro]=Imagini Microsoft Windows -Name[ru]=Изображения Microsoft Windows -Name[si]=Microsoft Windows පිළිබිඹු -Name[sk]=Obrázky Microsoft Windows -Name[sl]=Slike Microsoft Windows -Name[sr]=Слике с Виндоуза -Name[sr@ijekavian]=Слике с Виндоуза -Name[sr@ijekavianlatin]=Slike s Windowsa -Name[sr@latin]=Slike s Windowsa -Name[sv]=Microsoft Windows avbilder -Name[tg]=Тасвирҳои Microsoft Windows -Name[th]=แฟ้มภาพต่าง ๆ ของระบบวินโดวส์ -Name[tr]=Microsoft Windows Resimleri -Name[ug]=Microsoft Windows سۈرەتلەر -Name[uk]=Зображення Microsoft Windows -Name[vi]=Ảnh Microsoft Windows -Name[wa]=Imådjes Microsoft Windows -Name[x-test]=xxMicrosoft Windows Imagesxx -Name[zh_CN]=Microsoft Windows 图像 -Name[zh_TW]=Microsoft Windows 影像 -ServiceTypes=ThumbCreator -MimeType=image/vnd.microsoft.icon;image/x-win-bitmap;application/x-navi-animation; -CacheThumbnail=false -X-KDE-Library=windowsimagethumbnail -InitialPreference=2