22#include <glibmm/miscutils.h>
66std::unique_ptr<SPDocument>
open(
Extension *
key,
char const *filename,
bool is_importing)
70 bool last_chance_svg =
false;
72 last_chance_svg =
true;
73 imod =
dynamic_cast<Input *
>(
db.
get(SP_MODULE_KEY_INPUT_SVG));
84 if (std::strlen(imod->
get_id()) > 21) {
86 bool ask = prefs->
getBool(
"/dialogs/import/ask");
87 bool ask_svg = prefs->
getBool(
"/dialogs/import/ask_svg");
88 Glib::ustring
id = Glib::ustring(imod->
get_id(), 22);
89 if (
id.compare(
"org.inkscape.input.svg") == 0) {
90 if (ask_svg && is_importing) {
97 }
else if(strlen(imod->
get_id()) > 27) {
98 id = Glib::ustring(imod->
get_id(), 28);
99 if (!ask &&
id.compare(
"org.inkscape.input.gdkpixbuf") == 0) {
111 if (!imod->
prefs()) {
115 auto doc = imod->
open(filename, is_importing);
118 if (last_chance_svg) {
119 if ( INKSCAPE.use_gui() ) {
120 sp_ui_error_dialog(_(
"Could not detect file format. Tried to open it as an SVG anyway but this also failed."));
122 g_warning(
"%s", _(
"Could not detect file format. Tried to open it as an SVG anyway but this also failed."));
130 doc->setDocumentFilename(filename);
166 if (
key ==
nullptr) {
169 if (mod->can_save_filename(filename)) {
178 if (omod !=
nullptr && !strcmp(omod->
get_id(), SP_MODULE_KEY_OUTPUT_SVG)) {
179 omod =
dynamic_cast<Output *
>(
db.
get(SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE));
182 if (omod ==
nullptr) {
189 if (!
dynamic_cast<Output *
>(omod)) {
190 g_warning(
"Unable to find output module to handle file: %s\n", filename);
199 if (!omod->
prefs()) {
218 gchar *saved_output_extension =
nullptr;
219 gchar *saved_dataloss =
nullptr;
222 saved_dataloss = g_strdup(repr->
attribute(
"inkscape:dataloss"));
244 omod->
save(doc, filename);
248 if(check_overwrite && official) {
252 repr->
setAttribute(
"inkscape:dataloss", saved_dataloss);
258 g_free(saved_output_extension);
259 g_free(saved_dataloss);
260 g_free(saved_filename);
270 repr->
setAttribute(
"inkscape:dataloss", saved_dataloss);
274 g_free(saved_output_extension);
275 g_free(saved_dataloss);
310 g_return_val_if_fail(doc !=
nullptr,
false);
314 if (strcmp(repr->
name(), INKSCAPE_EXTENSION_NS
"inkscape-extension")) {
315 g_warning(
"Extension definition started with <%s> instead of <" INKSCAPE_EXTENSION_NS
"inkscape-extension>. Extension will not be created. See http://wiki.inkscape.org/wiki/index.php/Extensions for reference.\n", repr->
name());
320 while (child_repr !=
nullptr) {
321 char const *element_name = child_repr->
name();
323 if (!strcmp(element_name, INKSCAPE_EXTENSION_NS
"input")) {
325 }
else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS
"template")) {
327 }
else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS
"output")) {
329 }
else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS
"effect")) {
331 }
else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS
"print")) {
333 }
else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS
"path-effect")) {
335 }
else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS
"script")) {
337 }
else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS
"xslt")) {
339 }
else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS
"plugin")) {
344 child_repr = child_repr->
next();
349 ImplementationHolder imp;
351 imp = std::move(in_imp);
353 switch (module_implementation_type) {
355 imp = ImplementationHolder::make_owning<Implementation::Script>();
359 imp = ImplementationHolder::make_owning<Implementation::XSLT>();
365 loader.set_base_directory(*baseDir);
367 imp = ImplementationHolder::make_nonowning(loader.load_implementation(doc));
373 std::unique_ptr<Extension>
module;
375 switch (module_functional_type) {
377 module = std::make_unique<Input>(repr, std::move(imp), baseDir);
381 module = std::make_unique<Template>(repr, std::move(imp), baseDir);
385 module = std::make_unique<Output>(repr, std::move(imp), baseDir);
389 module = std::make_unique<Effect>(repr, std::move(imp), baseDir, file_name);
393 module = std::make_unique<Print>(repr, std::move(imp), baseDir);
397 module = std::make_unique<PathEffect>(repr, std::move(imp), baseDir);
401 g_warning(
"Extension of unknown type!");
402 module = std::make_unique<Extension>(repr, std::move(imp), baseDir);
407 g_warning(
"Building extension failed. Extension does not have a valid ID");
410 g_warning(
"Building extension failed. Extension does not have a valid name");
415 g_warning(
"Building extension failed: no implementation was found");
434 std::string dir = Glib::path_get_dirname(filename);
435 auto file_name = Glib::path_get_basename(filename);
439 g_critical(
"Inkscape::Extension::build_from_file() - XML description loaded from '%s' not valid.", filename);
444 g_warning(
"Inkscape::Extension::build_from_file() - Could not parse extension from '%s'.", filename);
459build_from_mem(gchar
const *buffer, std::unique_ptr<Implementation::Implementation> in_imp)
463 g_critical(
"Inkscape::Extension::build_from_mem() - XML description loaded from memory buffer not valid.");
468 g_critical(
"Inkscape::Extension::build_from_mem() - Could not parse extension from memory buffer.");
481 Glib::ustring extension;
485 extension = prefs->
getString(
"/dialogs/save_as/default");
488 extension = prefs->
getString(
"/dialogs/save_copy/default");
491 extension = SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE;
498 if(extension.empty()) {
499 extension = SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE;
509 bool use_current_dir =
true;
513 use_current_dir = prefs->
getBool(
"/dialogs/save_as/use_current_dir",
true);
517 path = prefs->
getString(
"/dialogs/save_as/path");
522 path = prefs->
getString(
"/dialogs/save_as/path");
525 use_current_dir = prefs->
getBool(
"/dialogs/save_copy/use_current_dir", prefs->
getBool(
"/dialogs/save_as/use_current_dir",
true));
529 path = prefs->
getString(
"/dialogs/save_copy/path");
538 path = prefs->
getString(
"/dialogs/save_as/path");
548 path = g_get_home_dir();
563 prefs->
setString(
"/dialogs/save_as/default", extension);
566 prefs->
setString(
"/dialogs/save_copy/default", extension);
581 prefs->
setString(
"/dialogs/save_as/path", path);
584 prefs->
setString(
"/dialogs/save_copy/path", path);
RAII-style mechanism for creating a temporary undo-insensitive context.
std::list< Output * > OutputList
void take_ownership(std::unique_ptr< Extension > module)
Take the ownership of an extension to ensure that it is freed on program exit.
OutputList & get_output_list(OutputList &ou_list)
Creates a list of all the Output extensions.
Extension * get(const gchar *key) const
This function looks up a Inkscape::Extension::Extension by using its unique id. It then returns a ref...
no valid ID found while parsing XML representation
no valid name found while parsing XML representation
extension is not compatible with the current system and should not be loaded
No implementation could be loaded for the extension.
An error class for when a filename already exists, but the user doesn't want to overwrite it.
The object that is the basis for the Extension system.
@ STATE_LOADED
The extension has been loaded successfully.
char const * get_id() const
Get the ID of this extension - not a copy don't delete!
void set_state(state_t in_state)
A function to set whether the extension should be loaded or unloaded.
bool loaded()
A quick function to test the state of the extension.
virtual bool prefs()
Create a dialog for preference for this extension.
This class contains the mechanism to load c++ plugins dynamically.
The existing file can not be opened for writing.
Failed because we couldn't find an extension to match the filename.
Generic failure for an undescribed reason.
bool causes_dataloss() const
void save(SPDocument *doc, gchar const *filename, bool detachbase=false)
Save a document as a file.
Preference storage class.
bool getBool(Glib::ustring const &pref_path, bool def=false)
Retrieve a Boolean value.
Glib::ustring getString(Glib::ustring const &pref_path, Glib::ustring const &def="")
Retrieve an UTF-8 string.
static Preferences * get()
Access the singleton Preferences object.
void setString(Glib::ustring const &pref_path, Glib::ustring const &value)
Set an UTF-8 string value.
A helper class holding an owning or non-owning pointer depending on the memory management requirement...
Interface for refcounted XML nodes.
virtual Node * next()=0
Get the next sibling of this node.
virtual char const * name() const =0
Get the name of the element node.
void setAttribute(Util::const_char_ptr key, Util::const_char_ptr value)
Change an attribute of this node.
virtual Node * firstChild()=0
Get the first child of this node.
virtual char const * attribute(char const *key) const =0
Get the string representation of a node's attribute.
void removeAttribute(Inkscape::Util::const_char_ptr key)
Remove an attribute of this node.
virtual Node * root()=0
Get the root node of this node's document.
Typed SVG document implementation.
char const * getDocumentFilename() const
bool isModifiedSinceSave() const
void setModifiedSinceSave(bool const modified=true)
Indicate to the user if the document has been modified since the last save by displaying a "*" in fro...
Inkscape::XML::Node * getReprRoot()
void changeFilenameAndHrefs(char const *filename)
Changes the base, name and filename members of document, and updates any relative hrefs in the docume...
TODO: insert short description here.
Inkscape::Extension::Extension: Frontend to certain, possibly pluggable, actions.
void sp_ui_error_dialog(char const *message)
bool sp_ui_overwrite_file(std::string const &filename)
If necessary, ask the user if a file may be overwritten.
Loader for external plug-ins.
DB db
This is the actual database object.
Glib::ustring get_file_save_extension(Inkscape::Extension::FileSaveMethod method)
Determine the desired default file extension depending on the given file save method.
std::unique_ptr< SPDocument > open(Extension *key, char const *filename, bool is_importing)
This is a generic function to use the open function of a module (including Autodetect)
void store_file_extension_in_prefs(Glib::ustring extension, FileSaveMethod method)
Write the given file extension back to prefs so that it can be used later on.
void save(Extension *key, SPDocument *doc, gchar const *filename, bool check_overwrite, bool official, Inkscape::Extension::FileSaveMethod save_method)
This is a generic function to use the save function of a module (including Autodetect)
void store_save_path_in_prefs(Glib::ustring path, FileSaveMethod method)
Write the given path back to prefs so that it can be used later on.
Print * get_print(gchar const *key)
bool build_from_reprdoc(Inkscape::XML::Document *doc, std::unique_ptr< Implementation::Implementation > in_imp, std::string *baseDir, std::string *file_name)
Creates a module from a Inkscape::XML::Document describing the module.
void build_from_mem(gchar const *buffer, std::unique_ptr< Implementation::Implementation > in_imp)
Create a module from a buffer holding an XML description.
FileSaveMethod
Used to distinguish between the various invocations of the save dialogs (and thus to determine the fi...
@ FILE_SAVE_METHOD_SAVE_COPY
@ FILE_SAVE_METHOD_INKSCAPE_SVG
@ FILE_SAVE_METHOD_EXPORT
@ FILE_SAVE_METHOD_TEMPORARY
@ FILE_SAVE_METHOD_SAVE_AS
void build_from_file(gchar const *filename)
This function creates a module from a filename of an XML description.
Glib::ustring get_file_save_path(SPDocument *doc, FileSaveMethod method)
Determine the desired default save path depending on the given FileSaveMethod.
static R & release(R &r)
Decrements the reference count of a anchored object.
bool file_test(char const *utf8name, GFileTest test)
bool file_is_writable(char const *utf8name)
static cairo_user_data_key_t key
Singleton class to access the preferences file in a convenient way.
TODO: insert short description here.
Document * sp_repr_read_file(const gchar *filename, const gchar *default_ns, bool xinclude)
Reads XML from a file, and returns the Document.
Document * sp_repr_read_mem(const gchar *buffer, gint length, const gchar *default_ns)
Reads and parses XML from a buffer, returning it as an Document.
Interface for XML documents.