2022-10-06 15:54:20 +03:00
|
|
|
/* This file is part of the KDE project
|
|
|
|
Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
|
2014-11-15 04:16:00 +02:00
|
|
|
|
2022-10-06 15:54:20 +03:00
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License version 2, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2014-11-15 04:16:00 +02:00
|
|
|
|
|
|
|
#include "comiccreator.h"
|
|
|
|
|
2022-10-06 15:54:20 +03:00
|
|
|
#include <QFile>
|
2014-11-15 04:16:00 +02:00
|
|
|
#include <kdemacros.h>
|
2022-10-06 15:54:20 +03:00
|
|
|
#include <karchive.h>
|
2014-11-15 04:16:00 +02:00
|
|
|
#include <kdebug.h>
|
|
|
|
|
2022-10-06 15:54:20 +03:00
|
|
|
#include <sys/stat.h>
|
2014-11-15 04:16:00 +02:00
|
|
|
|
|
|
|
// For KIO-Thumbnail debug outputs
|
|
|
|
#define KIO_THUMB 11371
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
KDE_EXPORT ThumbCreator *new_creator()
|
|
|
|
{
|
2022-10-04 03:38:56 +03:00
|
|
|
return new ComicCreator();
|
2014-11-15 04:16:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-04 03:38:56 +03:00
|
|
|
ComicCreator::ComicCreator()
|
|
|
|
{
|
|
|
|
}
|
2014-11-15 04:16:00 +02:00
|
|
|
|
2022-10-06 15:54:20 +03:00
|
|
|
bool ComicCreator::create(const QString &path, int width, int height, QImage &img)
|
2014-11-15 04:16:00 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(width);
|
|
|
|
Q_UNUSED(height);
|
|
|
|
|
|
|
|
// Can our archive be opened?
|
2022-10-06 15:54:20 +03:00
|
|
|
KArchive karchive(path);
|
|
|
|
if (!karchive.isReadable()) {
|
|
|
|
kDebug(KIO_THUMB) << "KArchive cannot open the comic book" << karchive.errorString();
|
|
|
|
return false;
|
2014-11-15 04:16:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get and filter the entries from the archive.
|
2022-10-06 15:54:20 +03:00
|
|
|
QStringList imageslist;
|
|
|
|
foreach (const KArchiveEntry &karchiveentry, karchive.list()) {
|
|
|
|
if (!S_ISREG(karchiveentry.mode)) {
|
|
|
|
continue;
|
2014-11-15 04:16:00 +02:00
|
|
|
}
|
2022-10-06 15:54:20 +03:00
|
|
|
const QByteArray lowerpathname = karchiveentry.pathname.toLower();
|
|
|
|
if (!lowerpathname.endsWith(".gif") && !lowerpathname.endsWith(".jpg")
|
|
|
|
&& !lowerpathname.endsWith(".jpeg") && !lowerpathname.endsWith(".png")) {
|
|
|
|
continue;
|
2014-11-15 04:16:00 +02:00
|
|
|
}
|
2022-10-06 15:54:20 +03:00
|
|
|
imageslist.append(QFile::decodeName(karchiveentry.pathname));
|
2014-11-15 04:16:00 +02:00
|
|
|
}
|
|
|
|
|
2022-10-06 15:54:20 +03:00
|
|
|
if (imageslist.isEmpty()) {
|
|
|
|
kDebug(KIO_THUMB) << "No image found in the comic book";
|
|
|
|
return false;
|
2014-11-15 04:16:00 +02:00
|
|
|
}
|
|
|
|
|
2022-10-06 15:54:20 +03:00
|
|
|
// Extract the cover file.
|
|
|
|
img = QImage::fromData(karchive.data(imageslist.at(0)));
|
|
|
|
if (img.isNull()) {
|
|
|
|
kWarning(KIO_THUMB) << "Could not get the comic book image" << karchive.errorString();
|
|
|
|
return false;
|
2014-11-15 04:16:00 +02:00
|
|
|
}
|
|
|
|
|
2022-10-06 15:54:20 +03:00
|
|
|
return true;
|
2014-11-15 04:16:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ThumbCreator::Flags ComicCreator::flags() const
|
|
|
|
{
|
2022-10-06 15:54:20 +03:00
|
|
|
return ThumbCreator::DrawFrame;
|
2014-11-15 04:16:00 +02:00
|
|
|
}
|