diff --git a/thumbnail/CMakeLists.txt b/thumbnail/CMakeLists.txt --- a/thumbnail/CMakeLists.txt +++ b/thumbnail/CMakeLists.txt @@ -216,6 +216,19 @@ # ########### next target ############### +set(opendocumentthumbnail_SRCS opendocumentcreator.cpp) +add_library(opendocumentthumbnail MODULE ${opendocumentthumbnail_SRCS}) + +target_link_libraries(opendocumentthumbnail + Qt5::Gui + KF5::KIOWidgets + KF5::Archive +) + +install(TARGETS opendocumentthumbnail DESTINATION ${PLUGIN_INSTALL_DIR}) + +# ########### next target ############### + if(libappimage_FOUND) set(appimagethumbnail_SRCS appimagecreator.cpp) @@ -244,6 +257,7 @@ # desktopthumbnail.desktop comicbookthumbnail.desktop kraorathumbnail.desktop + opendocumentthumbnail.desktop ${audiothumbnail_desktop} DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/thumbnail/opendocumentcreator.h b/thumbnail/opendocumentcreator.h new file mode 100644 --- /dev/null +++ b/thumbnail/opendocumentcreator.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018 Kai Uwe Broulik + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#pragma once + +#include + +class OpenDocumentCreator : public ThumbCreator +{ +public: + OpenDocumentCreator(); + ~OpenDocumentCreator() override; + + bool create(const QString &path, int width, int height, QImage &image) override; + +}; diff --git a/thumbnail/opendocumentcreator.cpp b/thumbnail/opendocumentcreator.cpp new file mode 100644 --- /dev/null +++ b/thumbnail/opendocumentcreator.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2018 Kai Uwe Broulik + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "opendocumentcreator.h" + +#include + +#include + +extern "C" +{ + Q_DECL_EXPORT ThumbCreator *new_creator() + { + return new OpenDocumentCreator; + } +} + +OpenDocumentCreator::OpenDocumentCreator() = default; + +OpenDocumentCreator::~OpenDocumentCreator() = default; + +bool OpenDocumentCreator::create(const QString &path, int width, int height, QImage &image) +{ + Q_UNUSED(width); + Q_UNUSED(height); + + KZip zip(path); + if (!zip.open(QIODevice::ReadOnly)) { + return false; + } + + const KArchiveEntry *entry = zip.directory()->entry(QStringLiteral("Thumbnails/thumbnail.png")); + + if (!entry || !entry->isFile()) { + return false; + } + + const KZipFileEntry *zipFileEntry = static_cast(entry); + return image.loadFromData(zipFileEntry->data(), "PNG"); +} diff --git a/thumbnail/opendocumentthumbnail.desktop b/thumbnail/opendocumentthumbnail.desktop new file mode 100644 --- /dev/null +++ b/thumbnail/opendocumentthumbnail.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Type=Service +Name=Office Documents (Open Document Files) + +X-KDE-ServiceTypes=ThumbCreator +MimeType=application/vnd.oasis.opendocument.text;application/vnd.oasis.opendocument.text-template;application/vnd.oasis.opendocument.text-master;application/vnd.oasis.opendocument.text-master-template;application/vnd.oasis.opendocument.spreadsheet;application/vnd.oasis.opendocument.spreadsheet-template;application/vnd.oasis.opendocument.graphics;application/vnd.oasis.opendocument.graphics-template;application/vnd.oasis.opendocument.presentation;application/vnd.oasis.opendocument.presentation-template;application/vnd.oasis.opendocument.formula;application/vnd.oasis.opendocument.formula-template;application/vnd.oasis.opendocument.chart;application/vnd.oasis.opendocument.chart-template; + +X-KDE-Library=opendocumentthumbnail +CacheThumbnail=true