/*
* 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>
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
*
* 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 "ui/interface.h"
#include <unistd.h>
#include <glibmm/miscutils.h>
#include "system.h"
#include "preferences.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 "inkscape.h"
#include "document-undo.h"
#include "loader.h"
namespace Inkscape {
namespace Extension {
static Extension *build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation *in_imp, std::string* baseDir);
/**
* \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();
}
// Hide pixbuf extensions depending on user preferences.
//g_warning("Extension: %s", imod->get_id());
bool show = true;
show = false;
}
}
throw Input::open_failed();
}
return NULL;
}
if (!doc) {
throw Input::open_failed();
}
if (last_chance_svg) {
sp_ui_error_dialog(_("Format autodetect failed. The file is being opened as SVG."));
} else {
}
}
if (!show) {
}
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 */
// omod = dynamic_cast<Output *>(db.get(SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE)); use exception and let user choose
}
} else {
}
throw Output::no_extension_found();
}
throw Output::save_failed();
}
throw Output::save_cancelled();
}
if (setextension) {
}
}
}
throw Output::no_overwrite();
}
// test if the file exists and is writable
// the test only checks the file attributes and might pass where ACL does not allow to write
if (Inkscape::IO::file_test(filename, G_FILE_TEST_EXISTS) && !Inkscape::IO::file_is_writable(filename)) {
throw Output::file_read_only();
}
if (official) {
}
// Update attributes:
{
{
// 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) {
{
}
}
// free used ressources
}
// If it is an unofficial save, set the modified attributes back to what they were.
if ( !official) {
{
}
}
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 *
build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation *in_imp, std::string* baseDir)
{
enum {
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()); */
}
//Inkscape::XML::Node *old_repr = child_repr;
//Inkscape::GC::release(old_repr);
}
switch (module_implementation_type) {
case MODULE_EXTENSION: {
break;
}
case MODULE_XSLT: {
break;
}
case MODULE_PLUGIN: {
}
break;
}
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, or NULL if buffer is invalid
* \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;
}
/*
* TODO: Is it guaranteed that the returned extension is valid? If so, we can remove the check for
* filename_extension in sp_file_save_dialog().
*/
switch (method) {
case FILE_SAVE_METHOD_SAVE_AS:
break;
break;
break;
case FILE_SAVE_METHOD_EXPORT:
/// \todo no default extension set for Export? defaults to SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE is ok?
break;
}
}
return extension;
}
bool use_current_dir = true;
switch (method) {
case FILE_SAVE_METHOD_SAVE_AS:
{
} else {
}
break;
}
break;
use_current_dir = prefs->getBool("/dialogs/save_copy/use_current_dir", prefs->getBool("/dialogs/save_as/use_current_dir", true));
} else {
}
break;
} else {
// FIXME: should we use the save_as path here or something else? Maybe we should
// leave this as a choice to the user.
}
break;
case FILE_SAVE_METHOD_EXPORT:
/// \todo no default path set for Export?
// defaults to g_get_home_dir()
break;
}
// g_get_current_dir because this leads to problems on OS X where
// Inkscape opens the dialog inside application bundle when it is
// invoked for the first teim.
}
return path;
}
void
switch (method) {
case FILE_SAVE_METHOD_SAVE_AS:
break;
break;
case FILE_SAVE_METHOD_EXPORT:
// do nothing
break;
}
}
void
switch (method) {
case FILE_SAVE_METHOD_SAVE_AS:
break;
break;
case FILE_SAVE_METHOD_EXPORT:
// do nothing
break;
}
}
} } /* 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 :