Example #1
0
/**
 * \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.
 */
Extension *
build_from_mem(gchar const *buffer, Implementation::Implementation *in_imp)
{
    Inkscape::XML::Document *doc = sp_repr_read_mem(buffer, strlen(buffer), INKSCAPE_EXTENSION_URI);
    Extension *ext = build_from_reprdoc(doc, in_imp);
    Inkscape::GC::release(doc);
    return ext;
}
SPDocument *
sp_document_new_from_mem(gchar const *buffer, gint length, unsigned int keepalive)
{
    SPDocument *doc;
    Inkscape::XML::Document *rdoc;
    Inkscape::XML::Node *rroot;
    gchar *name;

    rdoc = sp_repr_read_mem(buffer, length, SP_SVG_NS_URI);

    /* If it cannot be loaded, return NULL without warning */
    if (rdoc == NULL) return NULL;

    rroot = rdoc->root();
    /* If xml file is not svg, return NULL without warning */
    /* fixme: destroy document */
    if (strcmp(rroot->name(), "svg:svg") != 0) return NULL;

    name = g_strdup_printf(_("Memory document %d"), ++doc_count);

    doc = sp_document_create(rdoc, NULL, NULL, name, keepalive);

    return doc;
}
Example #3
0
/** \brief  Creates a new preference dialog for extension preferences
    \param  name  Name of the Extension whose dialog this is
    \param  help  The help string for the extension (NULL if none)
    \param  controls  The extension specific widgets in the dialog

    This function initializes the dialog with the name of the extension
    in the title.  It adds a few buttons and sets up handlers for
    them.  It also places the passed-in widgets into the dialog.
*/
PrefDialog::PrefDialog (Glib::ustring name, gchar const * help, Gtk::Widget * controls, Effect * effect) :
#if WITH_GTKMM_3_0
    Gtk::Dialog::Dialog(_(name.c_str()), true),
#else
    Gtk::Dialog::Dialog(_(name.c_str()), true, true),
#endif
    _help(help),
    _name(name),
    _button_ok(NULL),
    _button_cancel(NULL),
    _button_preview(NULL),
    _param_preview(NULL),
    _effect(effect),
    _exEnv(NULL)
{
    Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox());
    if (controls == NULL) {
        if (_effect == NULL) {
            std::cout << "AH!!!  No controls and no effect!!!" << std::endl;
            return;
        }
        controls = _effect->get_imp()->prefs_effect(_effect, SP_ACTIVE_DESKTOP, &_signal_param_change, NULL);
        _signal_param_change.connect(sigc::mem_fun(this, &PrefDialog::param_change));
    }

    hbox->pack_start(*controls, true, true, 6);
    hbox->show();
    this->get_vbox()->pack_start(*hbox, true, true, 6);

    /*
    Gtk::Button * help_button = add_button(Gtk::Stock::HELP, Gtk::RESPONSE_HELP);
    if (_help == NULL)
        help_button->set_sensitive(false);
    */
    _button_cancel = add_button(_effect == NULL ? Gtk::Stock::CANCEL : Gtk::Stock::CLOSE, Gtk::RESPONSE_CANCEL);
    _button_cancel->set_use_stock(true);

    _button_ok = add_button(_effect == NULL ? Gtk::Stock::OK : Gtk::Stock::APPLY, Gtk::RESPONSE_OK);
    _button_ok->set_use_stock(true);
    set_default_response(Gtk::RESPONSE_OK);
    _button_ok->grab_focus();

    if (_effect != NULL && !_effect->no_live_preview) {
        if (_param_preview == NULL) {
            XML::Document * doc = sp_repr_read_mem(live_param_xml, strlen(live_param_xml), NULL);
            _param_preview = Parameter::make(doc->root(), _effect);
        }

        Gtk::HSeparator * sep = Gtk::manage(new Gtk::HSeparator());
        sep->show();
        this->get_vbox()->pack_start(*sep, true, true, 4);

        hbox = Gtk::manage(new Gtk::HBox());
        _button_preview = _param_preview->get_widget(NULL, NULL, &_signal_preview);
        _button_preview->show();
        hbox->pack_start(*_button_preview, true, true,6);
        hbox->show();
        this->get_vbox()->pack_start(*hbox, true, true, 6);

        Gtk::Box * hbox = dynamic_cast<Gtk::Box *>(_button_preview);
        if (hbox != NULL) {
#if WITH_GTKMM_3_0
            _checkbox_preview = dynamic_cast<Gtk::CheckButton *>(hbox->get_children().front());
#else
            _checkbox_preview = dynamic_cast<Gtk::CheckButton *>(hbox->children().back().get_widget());
#endif
        }

        preview_toggle();
        _signal_preview.connect(sigc::mem_fun(this, &PrefDialog::preview_toggle));
    }

    // Set window modality for effects that don't use live preview
    if (_effect != NULL && _effect->no_live_preview) {
        set_modal(false);
    }

    GtkWidget *dlg = GTK_WIDGET(gobj());
    sp_transientize(dlg);

    return;
}
Example #4
0
/**
 * @brief Load internal defaults
 *
 * In the future this will try to load the system-wide file before falling
 * back to the internal defaults.
 */
void Preferences::_loadDefaults()
{
    _prefs_doc = sp_repr_read_mem(preferences_skeleton, PREFERENCES_SKELETON_SIZE, NULL);
}
Example #5
0
/**
 * @brief Load the user's customized preferences
 *
 * Tries to load the user's preferences.xml file. If there is none, creates it.
 * Displays dialog boxes on any errors.
 */
void Preferences::load(bool use_gui, bool quiet)
{   
    Glib::ustring const not_saved = _("Inkscape will run with default settings, "
                                "and new settings will not be saved. ");
    _use_gui = use_gui;
    _quiet = quiet;
    _loaded = true;
    
    // NOTE: After we upgrade to Glib 2.16, use Glib::ustring::compose
    
    // 1. Does the file exist?
    if (!g_file_test(_prefs_filename.data(), G_FILE_TEST_EXISTS)) {
        // No - we need to create one.
        // Does the profile directory exist?
        if (!g_file_test(_prefs_dir.data(), G_FILE_TEST_EXISTS)) {
            // No - create the profile directory
            if (g_mkdir(_prefs_dir.data(), 0755)) {
                // the creation failed
                //_errorDialog(Glib::ustring::compose(_("Cannot create profile directory %1."),
                //    Glib::filename_to_utf8(_prefs_dir)), not_saved);
                gchar *msg = g_strdup_printf(_("Cannot create profile directory %s."),
                    Glib::filename_to_utf8(_prefs_dir).data());
                _errorDialog(msg, not_saved);
                g_free(msg);
                return;
            }
            // create some subdirectories for user stuff
            char const *user_dirs[] = {"keys", "templates", "icons", "extensions", "palettes", NULL};
            for(int i=0; user_dirs[i]; ++i) {
                char *dir = profile_path(user_dirs[i]);
                g_mkdir(dir, 0755);
                g_free(dir);
            }
            
        } else if (!g_file_test(_prefs_dir.data(), G_FILE_TEST_IS_DIR)) {
            // The profile dir is not actually a directory
            //_errorDialog(Glib::ustring::compose(_("%1 is not a valid directory."),
            //    Glib::filename_to_utf8(_prefs_dir)), not_saved);
            gchar *msg = g_strdup_printf(_("%s is not a valid directory."),
                Glib::filename_to_utf8(_prefs_dir).data());
            _errorDialog(msg, not_saved);
            g_free(msg);
            return;
        }
        // The profile dir exists and is valid.
        if (!g_file_set_contents(_prefs_filename.data(), preferences_skeleton, PREFERENCES_SKELETON_SIZE, NULL)) {
            // The write failed.
            //_errorDialog(Glib::ustring::compose(_("Failed to create the preferences file %1."),
            //    Glib::filename_to_utf8(_prefs_filename)), not_saved);
            gchar *msg = g_strdup_printf(_("Failed to create the preferences file %s."),
                Glib::filename_to_utf8(_prefs_filename).data());
            _errorDialog(msg, not_saved);
            g_free(msg);
            return;
        }
        
        // The prefs file was just created.
        // We can return now and skip the rest of the load process.
        _writable = true;
        return;
    }
    
    // Yes, the pref file exists.
    // 2. Is it a regular file?
    if (!g_file_test(_prefs_filename.data(), G_FILE_TEST_IS_REGULAR)) {
        //_errorDialog(Glib::ustring::compose(_("The preferences file %1 is not a regular file."),
        //    Glib::filename_to_utf8(_prefs_filename)), not_saved);
        gchar *msg = g_strdup_printf(_("The preferences file %s is not a regular file."),
            Glib::filename_to_utf8(_prefs_filename).data());
        _errorDialog(msg, not_saved);
        g_free(msg);
        return;
    }
    
    // 3. Is the file readable?
    gchar *prefs_xml = NULL; gsize len = 0;
    if (!g_file_get_contents(_prefs_filename.data(), &prefs_xml, &len, NULL)) {
        //_errorDialog(Glib::ustring::compose(_("The preferences file %1 could not be read."),
        //    Glib::filename_to_utf8(_prefs_filename)), not_saved);
        gchar *msg = g_strdup_printf(_("The preferences file %s could not be read."),
            Glib::filename_to_utf8(_prefs_filename).data());
        _errorDialog(msg, not_saved);
        g_free(msg);
        return;
    }
    // 4. Is it valid XML?
    Inkscape::XML::Document *prefs_read = sp_repr_read_mem(prefs_xml, len, NULL);
    g_free(prefs_xml);
    if (!prefs_read) {
        //_errorDialog(Glib::ustring::compose(_("The preferences file %1 is not a valid XML document."),
        //    Glib::filename_to_utf8(_prefs_filename)), not_saved);
        gchar *msg = g_strdup_printf(_("The preferences file %s is not a valid XML document."),
            Glib::filename_to_utf8(_prefs_filename).data());
        _errorDialog(msg, not_saved);
        g_free(msg);
        return;
    }
    // 5. Basic sanity check: does the root element have a correct name?
    if (strcmp(prefs_read->root()->name(), "inkscape")) {
        //_errorDialog(Glib::ustring::compose(_("The file %1 is not a valid Inkscape preferences file."),
        //    Glib::filename_to_utf8(_prefs_filename)), not_saved);
        gchar *msg = g_strdup_printf(_("The file %s is not a valid Inkscape preferences file."),
            Glib::filename_to_utf8(_prefs_filename).data());
        _errorDialog(msg, not_saved);
        g_free(msg);
        Inkscape::GC::release(prefs_read);
        return;
    }
    
    // Merge the loaded prefs with defaults.
    _prefs_doc->root()->mergeFrom(prefs_read->root(), "id");
    Inkscape::GC::release(prefs_read);
    _writable = true;
}