Inkscape
Vector Graphics Editor
Inkscape::Extension::Dependency Class Reference

A class to represent a dependency for an extension. More...

#include <dependency.h>

Public Types

enum  type_t { TYPE_EXECUTABLE , TYPE_FILE , TYPE_EXTENSION , TYPE_CNT }
 All the possible types of dependencies. More...
 
enum  location_t {
  LOCATION_PATH , LOCATION_EXTENSIONS , LOCATION_INX , LOCATION_ABSOLUTE ,
  LOCATION_CNT
}
 All of the possible locations to look for the dependency. More...
 

Public Member Functions

 Dependency (Inkscape::XML::Node *in_repr, const Extension *extension, type_t type=TYPE_FILE)
 Create a dependency using an XML definition. More...
 
virtual ~Dependency ()
 This dependency is not longer needed. More...
 
bool check ()
 Check if the dependency passes. More...
 
const gchar * get_name ()
 Accessor to the name attribute. More...
 
std::string get_path ()
 Path of this dependency. More...
 
Glib::ustring info_string ()
 Print out a dependency to a string. More...
 

Private Attributes

Inkscape::XML::Node_repr
 The XML representation of the dependency. More...
 
const gchar * _string = nullptr
 The string that is in the XML tags pulled out. More...
 
const gchar * _description = nullptr
 The description of the dependency for the users. More...
 
std::string _absolute_location = UNCHECKED
 The absolute path to the dependency file determined while checking this dependency. More...
 
type_t _type = TYPE_FILE
 Storing the type of this particular dependency. More...
 
location_t _location = LOCATION_PATH
 The location to look for this particular dependency. More...
 
const Extension_extension
 Reference to the extension requesting this dependency. More...
 

Static Private Attributes

static constexpr const char * UNCHECKED = "---unchecked---"
 
static gchar const * _type_str [TYPE_CNT]
 Strings to represent the different enum values in type_t in the XML. More...
 
static gchar const * _location_str [LOCATION_CNT]
 Strings to represent the different enum values in location_t in the XML. More...
 

Detailed Description

A class to represent a dependency for an extension.

There are different things that can be done in a dependency, and this class takes care of all of them.

Definition at line 27 of file dependency.h.

Member Enumeration Documentation

◆ location_t

All of the possible locations to look for the dependency.

Enumerator
LOCATION_PATH 

Look in the PATH for this dependency - historically this is the default (it's a bit odd for interpreted script files but makes sense for other executables)

LOCATION_EXTENSIONS 

Look in the extensions directory (note: this can be in both, user and system locations!)

LOCATION_INX 

Look relative to the inx file's location.

LOCATION_ABSOLUTE 

This dependency is already defined in absolute terms.

LOCATION_CNT 

Number of locations to look.

Definition at line 39 of file dependency.h.

◆ type_t

All the possible types of dependencies.

Enumerator
TYPE_EXECUTABLE 

Look for an executable.

TYPE_FILE 

Look to make sure a file exists.

TYPE_EXTENSION 

Make sure a specific extension is loaded and functional.

TYPE_CNT 

Number of types.

Definition at line 31 of file dependency.h.

Constructor & Destructor Documentation

◆ Dependency()

Inkscape::Extension::Dependency::Dependency ( Inkscape::XML::Node in_repr,
const Extension extension,
type_t  default_type = TYPE_FILE 
)

Create a dependency using an XML definition.

Parameters
in_reprXML definition of the dependency
extensionReference to the extension requesting this dependency
default_typeDefault file type of the dependency (unless overridden by XML definition's "type" attribute)

This function mostly looks for the 'location' and 'type' attributes and turns them into the enums of the same name. This makes things a little bit easier to use later. Also, a pointer to the core content is pulled out – also to make things easier.

Definition at line 54 of file dependency.cpp.

References _description, _location, _location_str, _repr, _string, _type, _type_str, Inkscape::GC::anchor(), Inkscape::XML::Node::attribute(), Inkscape::XML::Node::content(), Inkscape::XML::Node::firstChild(), LOCATION_CNT, and TYPE_CNT.

◆ ~Dependency()

Inkscape::Extension::Dependency::~Dependency ( )
virtual

This dependency is not longer needed.

Unreference the XML structure.

Definition at line 99 of file dependency.cpp.

References _repr, and Inkscape::GC::release().

Member Function Documentation

◆ check()

bool Inkscape::Extension::Dependency::check ( )

Check if the dependency passes.

Returns
Whether or not the dependency passes.

This function depends largely on all of the enums. The first level that is evaluated is the _type.

If the type is TYPE_EXTENSION then the id for the extension is looked up in the database. If the extension is found, and it is not deactivated, the dependency passes.

If the type is TYPE_EXECUTABLE or TYPE_FILE things are getting even more interesting because now the _location variable is also taken into account. First, the difference between the two is that the file test for TYPE_EXECUTABLE also tests to make sure the file is executable, besides checking that it exists.

If the _location is LOCATION_EXTENSIONS then the INKSCAPE_EXTENSIONDIR is put on the front of the string with build_filename. Then the appropriate filetest is run.

If the _location is LOCATION_ABSOLUTE then the file test is run directly on the string.

If the _location is LOCATION_PATH or not specified then the path is used to find the file. Each entry in the path is stepped through, attached to the string, and then tested. If the file is found then a TRUE is returned. If we get all the way through the path then a FALSE is returned, the command could not be found.

Definition at line 134 of file dependency.cpp.

References _absolute_location, _extension, _location, _string, _type, Inkscape::Extension::db, Inkscape::IO::Resource::EXTENSIONS, Inkscape::IO::file_test(), Inkscape::Extension::DB::get(), Inkscape::Extension::Extension::get_base_directory(), Inkscape::IO::Resource::get_filename(), Inkscape::Extension::Extension::get_id(), LOCATION_ABSOLUTE, LOCATION_EXTENSIONS, LOCATION_INX, LOCATION_PATH, TYPE_EXECUTABLE, TYPE_EXTENSION, and TYPE_FILE.

◆ get_name()

const gchar * Inkscape::Extension::Dependency::get_name ( )

Accessor to the name attribute.

Returns
A string containing the name of the dependency.

Returns the name of the dependency as found in the configuration file.

Definition at line 309 of file dependency.cpp.

References _string.

Referenced by Inkscape::Extension::Loader::load_dependency(), and Inkscape::Extension::Loader::load_implementation().

◆ get_path()

std::string Inkscape::Extension::Dependency::get_path ( )

Path of this dependency.

Returns
Absolute path to the dependency file (or an empty string if dependency was not found or is of TYPE_EXTENSION)

Returns the verified absolute path of the dependency file. This value is only available after checking the Dependency by calling Dependency::check().

Definition at line 322 of file dependency.cpp.

References _absolute_location, _string, _type, TYPE_EXTENSION, and UNCHECKED.

◆ info_string()

Glib::ustring Inkscape::Extension::Dependency::info_string ( )

Print out a dependency to a string.

Definition at line 339 of file dependency.cpp.

References _description, _location, _location_str, _string, _type, _type_str, and Geom::compose().

Member Data Documentation

◆ _absolute_location

std::string Inkscape::Extension::Dependency::_absolute_location = UNCHECKED
private

The absolute path to the dependency file determined while checking this dependency.

Definition at line 59 of file dependency.h.

Referenced by check(), and get_path().

◆ _description

const gchar* Inkscape::Extension::Dependency::_description = nullptr
private

The description of the dependency for the users.

Definition at line 57 of file dependency.h.

Referenced by Dependency(), and info_string().

◆ _extension

const Extension* Inkscape::Extension::Dependency::_extension
private

Reference to the extension requesting this dependency.

Definition at line 74 of file dependency.h.

Referenced by check().

◆ _location

location_t Inkscape::Extension::Dependency::_location = LOCATION_PATH
private

The location to look for this particular dependency.

Definition at line 64 of file dependency.h.

Referenced by check(), Dependency(), and info_string().

◆ _location_str

gchar const * Inkscape::Extension::Dependency::_location_str
staticprivate
Initial value:
= {
"path",
"extensions",
"inx",
"absolute",
}

Strings to represent the different enum values in location_t in the XML.

Definition at line 71 of file dependency.h.

Referenced by Dependency(), and info_string().

◆ _repr

Inkscape::XML::Node* Inkscape::Extension::Dependency::_repr
private

The XML representation of the dependency.

Definition at line 53 of file dependency.h.

Referenced by Dependency(), and ~Dependency().

◆ _string

const gchar* Inkscape::Extension::Dependency::_string = nullptr
private

The string that is in the XML tags pulled out.

Definition at line 55 of file dependency.h.

Referenced by check(), Dependency(), get_name(), get_path(), and info_string().

◆ _type

type_t Inkscape::Extension::Dependency::_type = TYPE_FILE
private

Storing the type of this particular dependency.

Definition at line 62 of file dependency.h.

Referenced by check(), Dependency(), get_path(), and info_string().

◆ _type_str

gchar const * Inkscape::Extension::Dependency::_type_str
staticprivate
Initial value:
= {
"executable",
"file",
"extension",
}

Strings to represent the different enum values in type_t in the XML.

Definition at line 68 of file dependency.h.

Referenced by Dependency(), and info_string().

◆ UNCHECKED

constexpr const char* Inkscape::Extension::Dependency::UNCHECKED = "---unchecked---"
staticconstexprprivate

Definition at line 50 of file dependency.h.

Referenced by get_path().


The documentation for this class was generated from the following files: