File indexing completed on 2025-01-05 04:01:16
0001 /* 0002 * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <memory> 0010 0011 #include <QString> 0012 #include <QStringList> 0013 #include <QByteArray> 0014 #include <QMimeData> 0015 0016 #include "app/log/log_line.hpp" 0017 0018 namespace glaxnimate::model { 0019 class Document; 0020 class Composition; 0021 class DocumentNode; 0022 } // namespace glaxnimate::model 0023 0024 namespace glaxnimate::io::mime { 0025 0026 struct DeserializedData 0027 { 0028 DeserializedData(); 0029 DeserializedData(const DeserializedData&) = delete; 0030 DeserializedData(DeserializedData&&); 0031 DeserializedData& operator=(const DeserializedData&) = delete; 0032 DeserializedData& operator=(DeserializedData&&); 0033 ~DeserializedData(); 0034 0035 std::unique_ptr<model::Document> document; 0036 model::Composition* main = nullptr; 0037 0038 bool empty() const; 0039 void initialize_data(); 0040 }; 0041 0042 class MimeSerializer 0043 { 0044 public: 0045 virtual ~MimeSerializer() = default; 0046 0047 virtual QString slug() const = 0; 0048 virtual QString name() const = 0; 0049 virtual QStringList mime_types() const = 0; 0050 0051 virtual QByteArray serialize(const std::vector<model::DocumentNode*>& objects) const = 0; 0052 0053 virtual io::mime::DeserializedData deserialize(const QByteArray& data) const; 0054 0055 virtual bool can_deserialize() const = 0; 0056 0057 virtual void to_mime_data(QMimeData& out, const std::vector<model::DocumentNode*>& objects) const 0058 { 0059 QByteArray data = serialize(objects); 0060 for ( const QString& mime : mime_types() ) 0061 out.setData(mime, data); 0062 } 0063 0064 io::mime::DeserializedData from_mime_data(const QMimeData& data) const; 0065 0066 protected: 0067 void message(const QString& message, app::log::Severity severity = app::log::Warning) const; 0068 0069 }; 0070 0071 } // namespace glaxnimate::io::mime