Logo Search packages:      
Sourcecode: inkscape version File versions

SPDocument * Inkscape::Extension::open ( Extension *  key,
gchar const *  filename 
)

This is a generic function to use the open function of a module (including Autodetect).

Returns:
A new document created from the filename passed in
Parameters:
key Identifier of which module to use
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.

Definition at line 63 of file system.cpp.

References db, open_internal(), SPDocument::setModifiedSinceSave(), sp_document_set_uri(), and SP_MODULE_KEY_INPUT_SVG.

Referenced by Inkscape::Extension::Implementation::Script::effect(), file_import(), Inkscape::Extension::Implementation::Script::open(), sp_file_open(), and sp_process_file_list().

{
    Input *imod = NULL;
    if (key == NULL) {
        gpointer parray[2];
        parray[0] = (gpointer)filename;
        parray[1] = (gpointer)&imod;
        db.foreach(open_internal, (gpointer)&parray);
    } else {
        imod = dynamic_cast<Input *>(key);
    }

    bool last_chance_svg = false;
    if (key == NULL && imod == NULL) {
        last_chance_svg = true;
        imod = dynamic_cast<Input *>(db.get(SP_MODULE_KEY_INPUT_SVG));
    }

    if (imod == NULL) {
        throw Input::no_extension_found();
    }

    imod->set_state(Extension::STATE_LOADED);

    if (!imod->loaded()) {
        throw Input::open_failed();
    }

    if (!imod->prefs(filename))
        return NULL;

    SPDocument *doc = imod->open(filename);
    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);

    sp_document_set_uri(doc, filename);

    return doc;
}


Generated by  Doxygen 1.6.0   Back to index