Logo Search packages:      
Sourcecode: inkscape version File versions

extension.h

Go to the documentation of this file.
#ifndef __INK_EXTENSION_H__
#define __INK_EXTENSION_H__

/** \file
 * Frontend to certain, possibly pluggable, actions.
 */

/*
 * Authors:
 *   Ted Gould <ted@gould.cx>
 *
 * Copyright (C) 2002-2005 Authors
 *
 * Released under GNU GPL, read the file 'COPYING' for more information
 */

#include <ostream>
#include <fstream>
#include <vector>
#include <glibmm/ustring.h>
#include "xml/repr.h"
#include <extension/extension-forward.h>

/** The key that is used to identify that the I/O should be autodetected */
00025 #define SP_MODULE_KEY_AUTODETECT "autodetect"
/** This is the key for the SVG input module */
00027 #define SP_MODULE_KEY_INPUT_SVG "org.inkscape.input.svg"
#define SP_MODULE_KEY_INPUT_SVGZ "org.inkscape.input.svgz"
/** Specifies the input module that should be used if none are selected */
00030 #define SP_MODULE_KEY_INPUT_DEFAULT SP_MODULE_KEY_AUTODETECT
/** The key for outputing standard W3C SVG */
00032 #define SP_MODULE_KEY_OUTPUT_SVG "org.inkscape.output.svg.plain"
/** This is an output file that has SVG data with the Sodipodi namespace extensions */
00034 #define SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE "org.inkscape.output.svg.inkscape"
/** Which output module should be used? */
00036 #define SP_MODULE_KEY_OUTPUT_DEFAULT SP_MODULE_KEY_AUTODETECT

/** Defines the key for Postscript printing */
00039 #define SP_MODULE_KEY_PRINT_PS    "org.inkscape.print.ps"
/** Defines the key for printing with GNOME Print */
00041 #define SP_MODULE_KEY_PRINT_GNOME "org.inkscape.print.gnome"
/** Defines the key for printing under Win32 */
00043 #define SP_MODULE_KEY_PRINT_WIN32 "org.inkscape.print.win32"
#ifdef WIN32
/** Defines the default printing to use */
#define SP_MODULE_KEY_PRINT_DEFAULT  SP_MODULE_KEY_PRINT_WIN32
#else
#ifdef WITH_GNOME_PRINT
/** Defines the default printing to use */
#define SP_MODULE_KEY_PRINT_DEFAULT  SP_MODULE_KEY_PRINT_GNOME
#else
/** Defines the default printing to use */
00053 #define SP_MODULE_KEY_PRINT_DEFAULT  SP_MODULE_KEY_PRINT_PS
#endif
#endif

/** Mime type for SVG */
00058 #define MIME_SVG "image/svg+xml"

/** Name of the extension error file */
00061 #define EXTENSION_ERROR_LOG_FILENAME  "extension-errors.log"

namespace Inkscape {
namespace Extension {

/** The object that is the basis for the Extension system.  This object
    contains all of the information that all Extension have.  The
    individual items are detailed within. This is the interface that
    those who want to _use_ the extensions system should use.  This
    is most likely to be those who are inside the Inkscape program. */
00071 class Extension {
public:
    /** An enumeration to identify if the Extension has been loaded or not. */
00074     typedef enum {
00075         STATE_LOADED,      /**< The extension has been loaded successfully */
00076         STATE_UNLOADED,    /**< The extension has not been loaded */
00077         STATE_DEACTIVATED, /**< The extension is missing something which makes it unusable */
    } state_t;

private:
00081     gchar     *id;                        /**< The unique identifier for the Extension */
00082     gchar     *name;                      /**< A user friendly name for the Extension */
00083     state_t    _state;                    /**< Which state the Extension is currently in */
00084     std::vector<Dependency *>  _deps;     /**< Dependencies for this extension */
00085     static std::ofstream error_file;      /**< This is the place where errors get reported */

protected:
00088     SPRepr *repr;                         /**< The XML description of the Extension */
00089     Implementation::Implementation * imp; /**< An object that holds all the functions for making this work */
00090     ExpirationTimer * timer;              /**< Timeout to unload after a given time */

public:
                  Extension    (SPRepr * in_repr,
                                Implementation::Implementation * in_imp);
    virtual      ~Extension    (void);

    void          set_state    (state_t in_state);
    state_t       get_state    (void);
    bool          loaded       (void);
    virtual bool  check        (void);
    SPRepr *      get_repr     (void);
    gchar *       get_id       (void);
    gchar *       get_name     (void);
    void          deactivate   (void);
    bool          deactivated  (void);
    void          printFailure (Glib::ustring reason);


/* Parameter Stuff */
    /* This is what allows modules to save values that are persistent
       through a reset and while running.  These values should be created
       when the extension is initialized, but will pull from previously
       set values if they are available.
     */
private:
00116     GSList * parameters; /**< A table to store the parameters for this extension.
                              This only gets created if there are parameters in this
                              extension */
    /** This is an enum to define the parameter type */
00120     enum param_type_t {
00121         PARAM_BOOL,   /**< Boolean parameter */
00122         PARAM_INT,    /**< Integer parameter */
00123         PARAM_FLOAT,  /**< Float parameter */
00124         PARAM_STRING, /**< String parameter */
00125         PARAM_CNT     /**< How many types are there? */
    };
    /** A union to select between the types of parameters.  They will
        probbably all fit within a pointer of various systems, but making
        them a union ensures this */
00130     union param_switch_t {
00131         bool t_bool;      /**< To get a boolean use this */
00132         int  t_int;       /**< If you want an integer this is your variable */
00133         float t_float;    /**< This guy stores the floating point numbers */
00134         gchar * t_string; /**< Strings are here */
    };
    /** The class that actually stores the value and type of the
        variable.  It should really take up a very small space.  It's
        important to note that the name is stored as the key to the
        hash table. */
00140     class param_t {
    public:
00142         gchar * name;        /**< The name of this parameter */
00143         param_type_t type;   /**< What type of variable */
00144         param_switch_t val;  /**< Here is the actual value */
    };
public:
    class param_wrong_type {}; /**< An error class for when a parameter is
                                    called on a type it is not */
    class param_not_exist {};  /**< An error class for when a parameter is
                                    looked for that just simply doesn't exist */
    class no_overwrite {};     /**< An error class for when a filename
                                    already exists, but the user doesn't
                                    want to overwrite it */
private:
    void             make_param       (SPRepr * paramrepr);
    inline param_t * param_shared     (const gchar * name,
                                       GSList * list);
public:
    bool             get_param_bool   (const gchar * name,
                                       const SPReprDoc *   doc = NULL);
    int              get_param_int    (const gchar * name,
                                       const SPReprDoc *   doc = NULL);
    float            get_param_float  (const gchar * name,
                                       const SPReprDoc *   doc = NULL);
    const gchar *    get_param_string (const gchar * name,
                                       const SPReprDoc *   doc = NULL);
    bool             set_param_bool   (const gchar * name,
                                       bool          value,
                                       SPReprDoc *   doc = NULL);
    int              set_param_int    (const gchar * name,
                                       int           value,
                                       SPReprDoc *   doc = NULL);
    float            set_param_float  (const gchar * name,
                                       float         value,
                                       SPReprDoc *   doc = NULL);
    const gchar *    set_param_string (const gchar * name,
                                       const gchar * value,
                                       SPReprDoc *   doc = NULL);

    /* Error file handling */
public:
    static void      error_file_open  (void);
    static void      error_file_close (void);
};



/*

This is a prototype for how collections should work.  Whoever gets
around to implementing this gets to decide what a 'folder' and an
'item' really is.  That is the joy of implementing it, eh?

class Collection : public Extension {

public:
    folder  get_root (void);
    int     get_count (folder);
    thumbnail get_thumbnail(item);
    item[]  get_items(folder);
    folder[]  get_folders(folder);
    metadata get_metadata(item);
    image   get_image(item);

};
*/

}  /* namespace Extension */
}  /* namespace Inkscape */

#endif /* __INK_EXTENSION_H__ */

/*
  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 :

Generated by  Doxygen 1.6.0   Back to index