Inkscape
Vector Graphics Editor
|
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... | |
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.
All of the possible locations to look for the dependency.
Definition at line 39 of file dependency.h.
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.
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.
in_repr | XML definition of the dependency |
extension | Reference to the extension requesting this dependency |
default_type | Default 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.
|
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().
bool Inkscape::Extension::Dependency::check | ( | ) |
Check if 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.
const gchar * Inkscape::Extension::Dependency::get_name | ( | ) |
Accessor to the name attribute.
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().
std::string Inkscape::Extension::Dependency::get_path | ( | ) |
Path of this dependency.
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.
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().
|
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().
|
private |
The description of the dependency for the users.
Definition at line 57 of file dependency.h.
Referenced by Dependency(), and info_string().
|
private |
Reference to the extension requesting this dependency.
Definition at line 74 of file dependency.h.
Referenced by check().
|
private |
The location to look for this particular dependency.
Definition at line 64 of file dependency.h.
Referenced by check(), Dependency(), and info_string().
|
staticprivate |
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().
|
private |
The XML representation of the dependency.
Definition at line 53 of file dependency.h.
Referenced by Dependency(), and ~Dependency().
|
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().
Storing the type of this particular dependency.
Definition at line 62 of file dependency.h.
Referenced by check(), Dependency(), get_path(), and info_string().
|
staticprivate |
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().
|
staticconstexprprivate |
Definition at line 50 of file dependency.h.
Referenced by get_path().