1 /*
2 * This is what gets executed to initialize all of the modules. For
3 * the internal modules this invovles executing their initialization
4 * functions, for external ones it involves reading their .spmodule
5 * files and bringing them into Sodipodi.
6 *
7 * Authors:
8 * Ted Gould <ted@gould.cx>
9 *
10 * Copyright (C) 2002-2004 Authors
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information
13 */
15 #ifdef HAVE_CONFIG_H
16 # include "config.h"
17 #endif
18 #include "path-prefix.h"
21 #include "inkscape.h"
22 #include <glibmm/i18n.h>
24 #include "system.h"
25 #include "db.h"
26 #include "internal/svgz.h"
27 #include "internal/ps.h"
28 #ifdef HAVE_CAIRO_PDF
29 # include "internal/pdf-cairo.h"
30 #endif
31 #ifdef WITH_GNOME_PRINT
32 # include "internal/gnome.h"
33 #endif
34 #ifdef WIN32
35 # include "internal/win32.h"
36 #endif
37 #include "internal/ps-out.h"
38 #ifdef HAVE_CAIRO_PDF
39 # include "internal/cairo-pdf-out.h"
40 # include "internal/cairo-renderer-pdf-out.h"
41 # include "internal/cairo-png-out.h"
42 #endif
43 #include "internal/pov-out.h"
44 #include "internal/odf.h"
45 #include "internal/latex-pstricks-out.h"
46 #include "internal/latex-pstricks.h"
47 #include "internal/eps-out.h"
48 #include "internal/gdkpixbuf-input.h"
49 #include "internal/bluredge.h"
50 #include "internal/gimpgrad.h"
51 #include "internal/grid.h"
52 #include "internal/wpg-input.h"
53 #include "prefs-utils.h"
54 #include "io/sys.h"
56 extern gboolean inkscape_app_use_gui( Inkscape::Application const *app );
58 namespace Inkscape {
59 namespace Extension {
61 /** This is the extention that all files are that are pulled from
62 the extension directory and parsed */
63 #define SP_MODULE_EXTENSION "inx"
65 static void build_module_from_dir(gchar const *dirname);
66 static void check_extensions();
68 /**
69 * \return none
70 * \brief Examines the given string preference and checks to see
71 * that at least one of the registered extensions matches
72 * it. If not, a default is assigned.
73 * \param pref_path Preference path to load
74 * \param pref_attr Attribute to load from the preference
75 * \param pref_default Default string to set
76 * \param extension_family List of extensions to search
77 */
78 static void
79 update_pref(gchar const *pref_path, gchar const *pref_attr,
80 gchar const *pref_default) // , GSList *extension_family)
81 {
82 gchar const *pref = prefs_get_string_attribute(pref_path,pref_attr);
83 /*
84 gboolean missing=TRUE;
85 for (GSList *list = extension_family; list; list = g_slist_next(list)) {
86 g_assert( list->data );
88 Inkscape::Extension *extension;
89 extension = reinterpret_cast<Inkscape::Extension *>(list->data);
91 if (!strcmp(extension->get_id(),pref)) missing=FALSE;
92 }
93 */
94 if (!Inkscape::Extension::db.get( pref ) /*missing*/) {
95 prefs_set_string_attribute(pref_path, pref_attr, pref_default);
96 }
97 }
99 /**
100 * Invokes the init routines for internal modules.
101 *
102 * This should be a list of all the internal modules that need to initialized. This is just a
103 * convinent place to put them. Also, this function calls build_module_from_dir to parse the
104 * Inkscape extensions directory.
105 */
106 void
107 init()
108 {
109 /* TODO: Change to Internal */
110 Internal::Svg::init();
111 Internal::Svgz::init();
112 Internal::PsOutput::init();
113 Internal::EpsOutput::init();
114 Internal::PrintPS::init();
115 #ifdef HAVE_CAIRO_PDF
116 Internal::CairoPdfOutput::init();
117 Internal::PrintCairoPDF::init();
118 Internal::CairoRendererPdfOutput::init();
119 Internal::CairoRendererOutput::init();
120 #endif
121 #ifdef WITH_GNOME_PRINT
122 Internal::PrintGNOME::init();
123 #endif
124 #ifdef WIN32
125 Internal::PrintWin32::init();
126 #endif
127 Internal::PovOutput::init();
128 Internal::OdfOutput::init();
129 Internal::PrintLatex::init();
130 Internal::LatexOutput::init();
131 Internal::WpgInput::init();
133 /* Effects */
134 Internal::BlurEdge::init();
135 Internal::GimpGrad::init();
136 Internal::Grid::init();
138 /* Load search path for extensions */
139 if (Inkscape::Extension::Extension::search_path.size() == 0)
140 {
141 Inkscape::Extension::Extension::search_path.push_back(profile_path("extensions"));
142 Inkscape::Extension::Extension::search_path.push_back(g_strdup(INKSCAPE_EXTENSIONDIR));
143 }
145 for (unsigned int i=0; i<Inkscape::Extension::Extension::search_path.size(); i++) {
146 build_module_from_dir(Inkscape::Extension::Extension::search_path[i]);
147 }
149 /* this is at the very end because it has several catch-alls
150 * that are possibly over-ridden by other extensions (such as
151 * svgz)
152 */
153 Internal::GdkpixbufInput::init();
155 /* now we need to check and make sure everyone is happy */
156 check_extensions();
158 /* This is a hack to deal with updating saved outdated module
159 * names in the prefs...
160 */
161 update_pref("dialogs.save_as", "default",
162 SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE
163 // Inkscape::Extension::db.get_output_list()
164 );
165 }
167 /**
168 * \return none
169 * \brief This function parses a directory for files of SP_MODULE_EXTENSION
170 * type and loads them.
171 * \param dirname The directory that should be searched for modules
172 *
173 * Here is just a basic function that moves through a directory. It looks at every entry, and
174 * compares its filename with SP_MODULE_EXTENSION. Of those that pass, build_from_file is called
175 * with their filenames.
176 */
177 static void
178 build_module_from_dir(gchar const *dirname)
179 {
180 if (!dirname) {
181 g_warning(_("Null external module directory name. Modules will not be loaded."));
182 return;
183 }
185 if (!Glib::file_test(std::string(dirname), Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_DIR)) {
186 return;
187 }
189 //# Hopefully doing this the Glib way is portable
191 GError *err;
192 GDir *directory = g_dir_open(dirname, 0, &err);
193 if (!directory) {
194 gchar *safeDir = Inkscape::IO::sanitizeString(dirname);
195 g_warning(_("Modules directory (%s) is unavailable. External modules in that directory will not be loaded."), safeDir);
196 g_free(safeDir);
197 return;
198 }
200 gchar *filename;
201 while ((filename = (gchar *)g_dir_read_name(directory)) != NULL) {
203 if (strlen(filename) < strlen(SP_MODULE_EXTENSION)) {
204 continue;
205 }
207 if (strcmp(SP_MODULE_EXTENSION, filename + (strlen(filename) - strlen(SP_MODULE_EXTENSION)))) {
208 continue;
209 }
211 gchar *pathname = g_strdup_printf("%s/%s", dirname, filename);
212 build_from_file(pathname);
213 g_free(pathname);
214 }
216 g_dir_close(directory);
217 }
220 static void
221 check_extensions_internal(Extension *in_plug, gpointer in_data)
222 {
223 int *count = (int *)in_data;
225 if (in_plug == NULL) return;
226 if (!in_plug->deactivated() && !in_plug->check()) {
227 in_plug->deactivate();
228 (*count)++;
229 }
230 }
232 static void
233 check_extensions()
234 {
235 int count = 1;
236 bool anyfail = false;
237 // int pass = 0;
239 Inkscape::Extension::Extension::error_file_open();
240 while (count != 0) {
241 // printf("Check extensions pass %d\n", pass++);
242 count = 0;
243 db.foreach(check_extensions_internal, (gpointer)&count);
244 if (count != 0) anyfail = true;
245 }
246 Inkscape::Extension::Extension::error_file_close();
247 }
249 } } /* namespace Inkscape::Extension */
252 /*
253 Local Variables:
254 mode:c++
255 c-file-style:"stroustrup"
256 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
257 indent-tabs-mode:nil
258 fill-column:99
259 End:
260 */
261 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :