From 408cb49b5559a81ea803df64bf58457a5dd4bf16 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 12 Nov 2018 21:22:44 +0100 Subject: Rewrite of main.cpp using InkscapeApplication (Gtk::Application) Use Gio::File for accessing files. Use Gio options to handle command line arguments. Use Gio::Actions for some command line arguments. Move file export code to src/io/file-export-cmd.h/.cpp. Make into class. --- src/io/file.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/io/file.cpp (limited to 'src/io/file.cpp') diff --git a/src/io/file.cpp b/src/io/file.cpp new file mode 100644 index 000000000..3505f018d --- /dev/null +++ b/src/io/file.cpp @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * File operations (independent of GUI) + * + * Copyright (C) 2018 Tavmjong Bah + * + * The contents of this file may be used under the GNU General Public License Version 2 or later. + * + */ + +#include +#include + +#include "file.h" + +#include "document.h" + +#include "extension/system.h" // Extension::open() +#include "extension/extension.h" +#include "extension/db.h" +#include "extension/output.h" +#include "extension/input.h" + +// SPDocument* +// ink_file_new(const std::string &Template) +// { +// SPDocument *doc = SPDocument::createNewDoc( Template, true, true ); +// return doc; +// } + + +SPDocument* +ink_file_open(const Glib::RefPtr& file) +{ + + SPDocument *doc = nullptr; + + std::string path = file->get_path(); + + try { + doc = Inkscape::Extension::open(nullptr, path.c_str()); + } catch (Inkscape::Extension::Input::no_extension_found &e) { + doc = nullptr; + } catch (Inkscape::Extension::Input::open_failed &e) { + doc = nullptr; + } + + // Try to open explicitly as SVG. + if (doc == nullptr) { + try { + doc = Inkscape::Extension::open(Inkscape::Extension::db.get(SP_MODULE_KEY_INPUT_SVG), path.c_str()); + } catch (Inkscape::Extension::Input::no_extension_found &e) { + doc = nullptr; + } catch (Inkscape::Extension::Input::open_failed &e) { + doc = nullptr; + } + } + if (doc == nullptr) { + std::cerr << "ink_file_open: '" << path << "' cannot be opened!" << std::endl; + } + + return doc; +} + -- cgit v1.2.3