system.cpp revision 32840c249b2de74d2bbc4511df7638cb6a260fd4
/*
* This is file is kind of the junk file. Basically everything that
* didn't fit in one of the other well defined areas, well, it's now
* here. Which is good in someways, but this file really needs some
* definition. Hopefully that will come ASAP.
*
* Authors:
* Ted Gould <ted@gould.cx>
* Johan Engelen <johan@shouraizou.nl>
*
* Copyright (C) 2006-2007 Johan Engelen
* Copyright (C) 2002-2004 Ted Gould
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <interface.h>
#include "extension.h"
#include "db.h"
#include "input.h"
#include "output.h"
#include "effect.h"
#include "patheffect.h"
#include "print.h"
#include "implementation/script.h"
#include "implementation/xslt.h"
#include "xml/rebase-hrefs.h"
/* #include "implementation/plugin.h" */
namespace Inkscape {
namespace Extension {
static Extension *build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation *in_imp);
/**
* \return A new document created from the filename passed in
* \brief This is a generic function to use the open function of
* a module (including Autodetect)
* \param key Identifier of which module to use
* \param filename The file that should be opened
*
* First things first, are we looking at an autodetection? Well if that's the case then the module
* needs to be found, and that is done with a database lookup through the module DB. The foreach
* function is called, with the parameter being a gpointer array. It contains both the filename
* (to find its extension) and where to write the module when it is found.
*
* If there is no autodetection, then the module database is queried with the key given.
*
* If everything is cool at this point, the module is loaded, and there is possibility for
* preferences. If there is a function, then it is executed to get the dialog to be displayed.
* After it is finished the function continues.
*
* Lastly, the open function is called in the module itself.
*/
{
} else {
}
bool last_chance_svg = false;
last_chance_svg = true;
}
throw Input::no_extension_found();
}
throw Input::open_failed();
}
return NULL;
if (!doc) {
throw Input::open_failed();
}
if (last_chance_svg) {
/* We can't call sp_ui_error_dialog because we may be
running from the console, in which case calling sp_ui
routines will cause a segfault. See bug 1000350 - bryce */
// sp_ui_error_dialog(_("Format autodetect failed. The file is being opened as SVG."));
g_warning(_("Format autodetect failed. The file is being opened as SVG."));
}
/* This kinda overkill as most of these are already set, but I want
to make sure for this release -- TJG */
doc->setModifiedSinceSave(false);
return doc;
}
/**
* \return none
* \brief This is the function that searches each module to see
* if it matches the filename for autodetection.
* \param in_plug The module to be tested
* \param in_data An array of pointers containing the filename, and
* the place to put a successfully found module.
*
* Basically this function only looks at input modules as it is part of the open function. If the
* module is an input module, it then starts to take it apart, and the data that is passed in.
* Because the data being passed in is in such a weird format, there are a few casts to make it
* easier to use. While it looks like a lot of local variables, they'll all get removed by the
* compiler.
*
* First thing that is checked is if the filename is shorter than the extension itself. There is
* no way for a match in that case. If it's long enough then there is a string compare of the end
* of the filename (for the length of the extension), and the extension itself. If this passes
* then the pointer passed in is set to the current module.
*/
static void
{
// skip all the rest if we already found a function to open it
// since they're ordered by preference now.
if (!*pimod) {
}
}
}
return;
}
/**
* \return None
* \brief This is a generic function to use the save function of
* a module (including Autodetect)
* \param key Identifier of which module to use
* \param doc The document to be saved
* \param filename The file that the document should be saved to
* \param official (optional) whether to set :output_module and :modified in the
* document; is true for normal save, false for temporary saves
*
* First things first, are we looking at an autodetection? Well if that's the case then the module
* needs to be found, and that is done with a database lookup through the module DB. The foreach
* function is called, with the parameter being a gpointer array. It contains both the filename
* (to find its extension) and where to write the module when it is found.
*
* If there is no autodetection the module database is queried with the key given.
*
* If everything is cool at this point, the module is loaded, and there is possibility for
* preferences. If there is a function, then it is executed to get the dialog to be displayed.
* After it is finished the function continues.
*
* Lastly, the save function is called in the module itself.
*/
void
save(Extension *key, SPDocument *doc, gchar const *filename, bool setextension, bool check_overwrite, bool official)
{
/* This is a nasty hack, but it is required to ensure that
autodetect will always save with the Inkscape extensions
if they are available. */
}
/* If autodetect fails, save as Inkscape SVG */
}
} else {
}
throw Output::no_extension_found();
return;
}
throw Output::save_failed();
}
throw Output::save_cancelled();
}
if (setextension) {
}
}
}
throw Output::no_overwrite();
}
bool saved_modified = false;
if (official) {
}
// Update attributes:
{
sp_document_set_undo_sensitive(doc, false);
{
// also save the extension for next use
// set the "dataloss" attribute if the chosen extension is lossy
if (omod->causes_dataloss()) {
}
}
doc->setModifiedSinceSave(false);
}
try {
}
catch(...) {
// revert attributes in case of official and overwrite
if(check_overwrite && official) {
sp_document_set_undo_sensitive(doc, false);
{
}
}
// free used ressources
}
// If it is an unofficial save, set the modified attributes back to what they were.
if ( !official) {
sp_document_set_undo_sensitive(doc, false);
{
}
}
return;
}
/**
* \return none
* \brief This is the function that searches each module to see
* if it matches the filename for autodetection.
* \param in_plug The module to be tested
* \param in_data An array of pointers containing the filename, and
* the place to put a successfully found module.
*
* Basically this function only looks at output modules as it is part of the open function. If the
* module is an output module, it then starts to take it apart, and the data that is passed in.
* Because the data being passed in is in such a weird format, there are a few casts to make it
* easier to use. While it looks like a lot of local variables, they'll all get removed by the
* compiler.
*
* First thing that is checked is if the filename is shorter than the extension itself. There is
* no way for a match in that case. If it's long enough then there is a string compare of the end
* of the filename (for the length of the extension), and the extension itself. If this passes
* then the pointer passed in is set to the current module.
*/
static void
{
// skip all the rest if we already found someone to save it
// since they're ordered by preference now.
if (!*pomod) {
}
}
}
return;
}
Print *
{
}
/**
* \return The built module
* \brief Creates a module from a Inkscape::XML::Document describing the module
* \param doc The XML description of the module
*
* This function basically has two segments. The first is that it goes through the Repr tree
* provided, and determines what kind of of module this is, and what kind of implementation to use.
* All of these are then stored in two enums that are defined in this function. This makes it
* easier to add additional types (which will happen in the future, I'm sure).
*
* Second, there is case statements for these enums. The first one is the type of module. This is
* the one where the module is actually created. After that, then the implementation is applied to
* get the load and unload functions. If there is no implementation then these are not set. This
*/
static Extension *
{
enum {
/* MODULE_PLUGIN, */
enum {
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());
return NULL;
}
while (child_repr != NULL) {
/* printf("Child: %s\n", child_repr->name()); */
#if 0
#endif
}
//Inkscape::XML::Node *old_repr = child_repr;
//Inkscape::GC::release(old_repr);
}
switch (module_implementation_type) {
case MODULE_EXTENSION: {
break;
}
case MODULE_XSLT: {
break;
}
#if 0
case MODULE_PLUGIN: {
break;
}
#endif
default: {
break;
}
}
} else {
}
switch (module_functional_type) {
case MODULE_INPUT: {
break;
}
case MODULE_OUTPUT: {
break;
}
case MODULE_FILTER: {
break;
}
case MODULE_PRINT: {
break;
}
case MODULE_PATH_EFFECT: {
break;
}
default: {
break;
}
}
return module;
}
/**
* \return The module created
* \brief This function creates a module from a filename of an
* XML description.
* \param filename The file holding the XML description of the module.
*
* This function calls build_from_reprdoc with using sp_repr_read_file to create the reprdoc.
*/
{
else
return ext;
}
/**
* \return The module created
* \brief This function creates a module from a buffer holding an
* XML description.
* \param buffer The buffer holding the XML description of the module.
*
* This function calls build_from_reprdoc with using sp_repr_read_mem to create the reprdoc. It
* finds the length of the buffer using strlen.
*/
{
return ext;
}
} } /* namespace Inkscape::Extension */
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :