kio-extras5/0001-Port-comicbook-thumbnailer-to-KF5.patch

182 lines
6.2 KiB
Diff

From 92203bdebc4814ef27388ca0fdd6731f2abeab3d Mon Sep 17 00:00:00 2001
From: Maarten De Meyer <de.meyer.maarten@gmail.com>
Date: Sun, 28 Sep 2014 17:35:40 +0200
Subject: [PATCH 1/5] Port comicbook thumbnailer to KF5
Mostly standard porting stuff.
Still need to change qdebug calls to qCDebug.
CCBUG: 339456
REVIEW: 120382
(cherry picked from commit 72d25f79050f8cf249b0a640a2be8764c59eca91)
---
CMakeLists.txt | 1 +
thumbnail/CMakeLists.txt | 22 +++++++++++++---------
thumbnail/comiccreator.cpp | 41 +++++++++++++++++++----------------------
3 files changed, 33 insertions(+), 31 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 34c5fb9f2fe10bb53ab4f1c7c09815494157c263..3d538d4e3f06620e61cbddc375bc4a9652671bf8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -36,6 +36,7 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
KIO
KHtml
KDE4Support
+ Pty
Solid
)
diff --git a/thumbnail/CMakeLists.txt b/thumbnail/CMakeLists.txt
index cd1263af2444e97b7c7d20f2a25899009db9af01..aec8b8ea9c86f6b8b650caf885c02117dbf014f0 100644
--- a/thumbnail/CMakeLists.txt
+++ b/thumbnail/CMakeLists.txt
@@ -201,14 +201,18 @@ install(TARGETS svgthumbnail DESTINATION ${PLUGIN_INSTALL_DIR})
# install ( FILES windowsimagethumbnail.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
#
# ########### next target ###############
-#
-# set(comicbookthumbnail_SRCS comiccreator.cpp)
-# add_library(comicbookthumbnail MODULE ${comicbookthumbnail_SRCS})
-# target_link_libraries(comicbookthumbnail ${KIO_LIBRARIES})
-# if (UNIX)
-# target_link_libraries(comicbookthumbnail KF5::Pty)
-# endif ()
-# install(TARGETS comicbookthumbnail DESTINATION ${PLUGIN_INSTALL_DIR})
+
+set(comicbookthumbnail_SRCS comiccreator.cpp)
+add_library(comicbookthumbnail MODULE ${comicbookthumbnail_SRCS})
+target_link_libraries(comicbookthumbnail
+ Qt5::Gui
+ KF5::Archive
+ KF5::KIOWidgets
+)
+if (UNIX)
+ target_link_libraries(comicbookthumbnail KF5::Pty)
+endif ()
+install(TARGETS comicbookthumbnail DESTINATION ${PLUGIN_INSTALL_DIR})
########### install files ###############
@@ -222,5 +226,5 @@ install(FILES
# htmlthumbnail.desktop
# djvuthumbnail.desktop
# desktopthumbnail.desktop
-# comicbookthumbnail.desktop
+ comicbookthumbnail.desktop
DESTINATION ${SERVICES_INSTALL_DIR})
diff --git a/thumbnail/comiccreator.cpp b/thumbnail/comiccreator.cpp
index 39df58a4ddc1de3d79cdb0766fc0b11c02c9ec2d..4ec0db8c6953e2d9983e4a9d7f542b27404175e4 100644
--- a/thumbnail/comiccreator.cpp
+++ b/thumbnail/comiccreator.cpp
@@ -29,23 +29,22 @@
#include "comiccreator.h"
-#include <kdemacros.h>
-#include <kmimetype.h>
-#include <kstandarddirs.h>
-
#include <kzip.h>
#include <ktar.h>
#include <QDebug>
-#include <ktempdir.h>
#include <kprocess.h>
#include <memory>
#include <QtCore/QFile>
#include <QtCore/QEventLoop>
+#include <QMimeDatabase>
+#include <QMimeType>
#include <QStandardPaths>
+#include <QTemporaryDir>
// For KIO-Thumbnail debug outputs
+// TODO KF5 qCDebug
#define KIO_THUMB 11371
extern "C"
@@ -66,23 +65,25 @@ bool ComicCreator::create(const QString& path, int width, int height, QImage& im
QImage cover;
// Detect mime type.
- const KMimeType::Ptr mime = KMimeType::findByFileContent(path);
+ QMimeDatabase db;
+ db.mimeTypeForFile(path, QMimeDatabase::MatchContent);
+ const QMimeType mime = db.mimeTypeForFile(path, QMimeDatabase::MatchContent);
- if (mime->is("application/x-cbz") || mime->name() == "application/zip") {
+ if (mime.inherits("application/x-cbz") || mime.inherits("application/zip")) {
// ZIP archive.
cover = extractArchiveImage(path, ZIP);
- } else if (mime->is("application/x-cbt") ||
- mime->name() == "application/x-gzip" ||
- mime->name() == "application/x-tar") {
+ } else if (mime.inherits("application/x-cbt") ||
+ mime.inherits("application/x-gzip") ||
+ mime.inherits("application/x-tar")) {
// TAR archive
cover = extractArchiveImage(path, TAR);
- } else if (mime->is("application/x-cbr") || mime->name() == "application/x-rar") {
+ } else if (mime.inherits("application/x-cbr") || mime.inherits("application/x-rar")) {
// RAR archive.
cover = extractRARImage(path);
}
if (cover.isNull()) {
- kDebug(KIO_THUMB)<<"Error creating the comic book thumbnail.";
+ qDebug()<<"Error creating the comic book thumbnail.";
return false;
}
@@ -178,7 +179,7 @@ QImage ComicCreator::extractRARImage(const QString& path)
// Check if unrar is available. Get its path in 'unrarPath'.
QString unrar = unrarPath();
if (unrar.isEmpty()) {
- kDebug(KIO_THUMB)<<"A suitable version of unrar is not available.";
+ qDebug()<<"A suitable version of unrar is not available.";
return QImage();
}
@@ -195,14 +196,12 @@ QImage ComicCreator::extractRARImage(const QString& path)
// Extract the cover file alone. Use verbose paths.
// unrar x -n<file> path/to/archive /path/to/temp
- KTempDir cUnrarTempDir;
- startProcess(unrar, QStringList() << "x" << "-n" + entries[0] << path << cUnrarTempDir.name());
+ QTemporaryDir cUnrarTempDir;
+ startProcess(unrar, QStringList() << "x" << "-n" + entries[0] << path << cUnrarTempDir.path());
// Load cover file data into image.
QImage cover;
- cover.load(cUnrarTempDir.name() + entries[0]);
-
- cUnrarTempDir.unlink();
+ cover.load(cUnrarTempDir.path() + QDir::separator() + entries[0]);
return cover;
}
@@ -223,10 +222,10 @@ QString ComicCreator::unrarPath() const
/// Check the standard paths to see if a suitable unrar is available.
QString unrar = QStandardPaths::findExecutable("unrar");
if (unrar.isEmpty()) {
- unrar = KStandardDirs::findExe("unrar-nonfree");
+ unrar = QStandardPaths::findExecutable("unrar-nonfree");
}
if (unrar.isEmpty()) {
- unrar = KStandardDirs::findExe("rar");
+ unrar = QStandardPaths::findExecutable("rar");
}
if (!unrar.isEmpty()) {
QProcess proc;
@@ -313,5 +312,3 @@ ThumbCreator::Flags ComicCreator::flags() const
{
return DrawFrame;
}
-
-#include "comiccreator.moc"
--
2.1.2