[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kio-extras] thumbnail: Add Open Document thumbnailer
From:       Kai Uwe Broulik <null () kde ! org>
Date:       2018-09-19 11:22:47
Message-ID: E1g2aZD-0000md-AH () code ! kde ! org
[Download RAW message or body]

Git commit 6828ff113ac36d0cba7a0c7e2e4d0264c7156c2e by Kai Uwe Broulik.
Committed on 19/09/2018 at 11:22.
Pushed by broulik into branch 'master'.

Add Open Document thumbnailer

Provides thumbnails for ODT, ODS, ODP, ODG, ODF files as well as their template counterparts

FEATURE: 375176
FIXED-IN: 18.12.0

Differential Revision: https://phabricator.kde.org/D15591

M  +14   -0    thumbnail/CMakeLists.txt
A  +57   -0    thumbnail/opendocumentcreator.cpp     [License: LGPL]
A  +33   -0    thumbnail/opendocumentcreator.h     [License: LGPL]
A  +9    -0    thumbnail/opendocumentthumbnail.desktop

https://commits.kde.org/kio-extras/6828ff113ac36d0cba7a0c7e2e4d0264c7156c2e

diff --git a/thumbnail/CMakeLists.txt b/thumbnail/CMakeLists.txt
index 48ae3c2e..889ee612 100644
--- a/thumbnail/CMakeLists.txt
+++ b/thumbnail/CMakeLists.txt
@@ -216,6 +216,19 @@ endif(TAGLIB_FOUND)
 
 # ########### 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 @@ install(FILES
 #    desktopthumbnail.desktop
     comicbookthumbnail.desktop
     kraorathumbnail.desktop
+    opendocumentthumbnail.desktop
     ${audiothumbnail_desktop}
     DESTINATION ${SERVICES_INSTALL_DIR})
 
diff --git a/thumbnail/opendocumentcreator.cpp b/thumbnail/opendocumentcreator.cpp
new file mode 100644
index 00000000..770f59c8
--- /dev/null
+++ b/thumbnail/opendocumentcreator.cpp
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2018 Kai Uwe Broulik <kde@broulik.de>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "opendocumentcreator.h"
+
+#include <QImage>
+
+#include <KZip>
+
+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<const KZipFileEntry *>(entry);
+    return image.loadFromData(zipFileEntry->data(), "PNG");
+}
diff --git a/thumbnail/opendocumentcreator.h b/thumbnail/opendocumentcreator.h
new file mode 100644
index 00000000..a58afe98
--- /dev/null
+++ b/thumbnail/opendocumentcreator.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2018 Kai Uwe Broulik <kde@broulik.de>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <kio/thumbcreator.h>
+
+class OpenDocumentCreator : public ThumbCreator
+{
+public:
+    OpenDocumentCreator();
+    ~OpenDocumentCreator() override;
+
+    bool create(const QString &path, int width, int height, QImage &image) override;
+
+};
diff --git a/thumbnail/opendocumentthumbnail.desktop b/thumbnail/opendocumentthumbnail.desktop
new file mode 100644
index 00000000..abab3fb3
--- /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;applica \
tion/vnd.oasis.opendocument.text-master;application/vnd.oasis.opendocument.text-master-template;applicatio \
n/vnd.oasis.opendocument.spreadsheet;application/vnd.oasis.opendocument.spreadsheet-template;application/v \
nd.oasis.opendocument.graphics;application/vnd.oasis.opendocument.graphics-template;application/vnd.oasis. \
opendocument.presentation;application/vnd.oasis.opendocument.presentation-template;application/vnd.oasis.o \
pendocument.formula;application/vnd.oasis.opendocument.formula-template;application/vnd.oasis.opendocument.chart;application/vnd.oasis.opendocument.chart-template;
 +
+X-KDE-Library=opendocumentthumbnail
+CacheThumbnail=true


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic