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 #include "io.hpp"
0008 #include "plugin.hpp"
0009 #include "model/assets/composition.hpp"
0010 
0011 using namespace glaxnimate;
0012 
0013 void plugin::IoService::enable()
0014 {
0015     if ( registered )
0016         disable();
0017     registered = io::IoRegistry::instance().register_object(std::make_unique<IoFormat>(this));
0018 }
0019 
0020 void plugin::IoService::disable()
0021 {
0022     if ( registered )
0023         io::IoRegistry::instance().unregister(registered);
0024     registered = nullptr;
0025 }
0026 
0027 bool plugin::IoFormat::on_open(QIODevice& file, const QString& name, model::Document* document, const QVariantMap& settings)
0028 {
0029     return service->plugin()->run_script(service->open, {
0030         PluginRegistry::instance().global_parameter("window"),
0031         QVariant::fromValue(document),
0032         QVariant::fromValue(&file),
0033         name,
0034         QVariant::fromValue(this),
0035         settings
0036     });
0037 }
0038 
0039 bool plugin::IoFormat::on_save(QIODevice& file, const QString& name, model::Composition* comp, const QVariantMap& settings)
0040 {
0041     return service->plugin()->run_script(service->save, {
0042         PluginRegistry::instance().global_parameter("window"),
0043         QVariant::fromValue(comp->document()),
0044         QVariant::fromValue(comp),
0045         QVariant::fromValue(&file),
0046         name,
0047         QVariant::fromValue(this),
0048         settings
0049     });
0050 }
0051 
0052 
0053 
0054 std::unique_ptr<app::settings::SettingsGroup> glaxnimate::plugin::IoFormat::open_settings() const
0055 {
0056     return std::make_unique<app::settings::SettingsGroup>(service->open.settings);
0057 }
0058 
0059 std::unique_ptr<app::settings::SettingsGroup> glaxnimate::plugin::IoFormat::save_settings(model::Composition*) const
0060 {
0061     return std::make_unique<app::settings::SettingsGroup>(service->save.settings);
0062 }
0063