kioslave: drop windowsimagecreator thumbnailer

it uses the ICO image format handler which can read only
image/vnd.microsoft.icon

also optimized the windowsexecreator while at it to not created
temporary file (which later wrestool would overwrite anyway) but
rather just generate output file path via KTemporaryFile::filePath()
and delete it manually when done

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-12-16 14:39:50 +02:00
parent 1ab5455149
commit 17cd523fb2
8 changed files with 69 additions and 316 deletions

View file

@ -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}
)

View file

@ -1,128 +0,0 @@
/*
icoutils_common.cpp - Extract Microsoft Window icons and images using icoutils package
Copyright (c) 2009-2010 by Pali Rohár <pali.rohar@gmail.com>
*************************************************************************
* *
* 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 <QList>
#include <QString>
#include <QTemporaryFile>
#include <QImage>
#include <QImageReader>
#include <QPair>
#include <QProcess>
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 <IconInExe> 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 <QImage> 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;
}

View file

@ -1,32 +0,0 @@
/*
icoutils.h - Extract Microsoft Window icons and images using icoutils package
Copyright (c) 2009-2010 by Pali Rohár <pali.rohar@gmail.com>
Copyright (c) 2013 by Andrius da Costa Ribas <andriusmao@gmail.com>
*************************************************************************
* *
* 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 <QString>
#include <QImage>
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

View file

@ -14,24 +14,86 @@
*/
#include "windowsexecreator.h"
#include "icoutils.h"
#include <QString>
#include <QImage>
#include <QPair>
#include <QProcess>
#include <ktemporaryfile.h>
#include <kdebug.h>
#include <kdemacros.h>
typedef QPair<QString,int> 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<IconInExe> 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;
}

View file

@ -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

View file

@ -1,37 +0,0 @@
/*
windowsimagecreator.cpp - Thumbnail Creator for Microsoft Windows Images
Copyright (c) 2009 by Pali Rohár <pali.rohar@gmail.com>
*************************************************************************
* *
* 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 <QString>
#include <QImage>
#include <kdemacros.h>
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);
}

View file

@ -1,28 +0,0 @@
/*
windowsimagecreator.h - Thumbnail Creator for Microsoft Windows Images
Copyright (c) 2009-2010 by Pali Rohár <pali.rohar@gmail.com>
*************************************************************************
* *
* 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 <kio/thumbcreator.h>
class WindowsImageCreator : public ThumbCreator
{
public:
WindowsImageCreator() {}
bool create(const QString &path, int width, int height, QImage &img);
};
#endif // WINDOWS_IMAGE_CREATOR_H

View file

@ -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