File indexing completed on 2024-12-15 04:01:20
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 "io/io_registry.hpp" 0010 0011 #include "service.hpp" 0012 0013 namespace glaxnimate::plugin { 0014 0015 class IoService : public PluginService 0016 { 0017 public: 0018 ServiceType type() const override { return ServiceType::IoFormat; } 0019 QString name() const override { return label; } 0020 void enable() override; 0021 void disable() override; 0022 0023 QIcon service_icon() const override { return QIcon::fromTheme("document-save"); } 0024 0025 QString slug; 0026 QString label; 0027 QStringList extensions; 0028 PluginScript open; 0029 PluginScript save; 0030 bool auto_open; 0031 0032 io::ImportExport* registered = nullptr; 0033 }; 0034 0035 0036 class IoFormat : public io::ImportExport 0037 { 0038 Q_OBJECT 0039 public: 0040 IoFormat(IoService* service) : service(service) {} 0041 0042 QString slug() const override { return service->slug; } 0043 QString name() const override { return service->label; } 0044 QStringList extensions() const override { return service->extensions; } 0045 bool can_save() const override { return service->save.valid(); } 0046 bool can_open() const override { return service->open.valid(); } 0047 0048 std::unique_ptr<app::settings::SettingsGroup> open_settings() const override; 0049 std::unique_ptr<app::settings::SettingsGroup> save_settings(model::Composition*) const override; 0050 0051 protected: 0052 bool auto_open() const override { return service->auto_open; } 0053 bool on_save(QIODevice& file, const QString&, model::Composition* comp, const QVariantMap&) override; 0054 bool on_open(QIODevice& file, const QString&, model::Document* document, const QVariantMap&) override; 0055 0056 private: 0057 IoService* service; 0058 }; 0059 0060 0061 0062 } // namespace glaxnimate::plugin