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 WIN32
32 # include "internal/win32.h"
33 # include "internal/emf-win32-inout.h"
34 # include "internal/emf-win32-print.h"
35 #endif
36 #include "internal/ps-out.h"
37 #ifdef HAVE_CAIRO_PDF
38 # include "internal/cairo-pdf-out.h"
39 # include "internal/cairo-renderer-pdf-out.h"
40 # include "internal/cairo-png-out.h"
41 # include "internal/cairo-ps-out.h"
42 #endif
43 #ifdef HAVE_POPPLER
44 # include "internal/pdfinput/pdf-input.h"
45 #endif
46 #ifdef HAVE_POPPLER_GLIB
47 # include "internal/pdf-input-cairo.h"
48 #endif
49 #include "internal/pov-out.h"
50 #include "internal/javafx-out.h"
51 #include "internal/odf.h"
52 #include "internal/latex-pstricks-out.h"
53 #include "internal/latex-pstricks.h"
54 #include "internal/eps-out.h"
55 #include "internal/gdkpixbuf-input.h"
56 #include "internal/bluredge.h"
57 #include "internal/gimpgrad.h"
58 #include "internal/grid.h"
59 #ifdef WITH_LIBWPG
60 #include "internal/wpg-input.h"
61 #endif
62 #include "prefs-utils.h"
63 #include "io/sys.h"
65 #ifdef WITH_IMAGE_MAGICK
66 #include "internal/bitmap/adaptiveThreshold.h"
67 #include "internal/bitmap/addNoise.h"
68 #include "internal/bitmap/blur.h"
69 #include "internal/bitmap/channel.h"
70 #include "internal/bitmap/charcoal.h"
71 #include "internal/bitmap/colorize.h"
72 #include "internal/bitmap/contrast.h"
73 #include "internal/bitmap/cycleColormap.h"
74 #include "internal/bitmap/despeckle.h"
75 #include "internal/bitmap/edge.h"
76 #include "internal/bitmap/emboss.h"
77 #include "internal/bitmap/enhance.h"
78 #include "internal/bitmap/equalize.h"
79 #include "internal/bitmap/gaussianBlur.h"
80 #include "internal/bitmap/implode.h"
81 #include "internal/bitmap/level.h"
82 #include "internal/bitmap/levelChannel.h"
83 #include "internal/bitmap/medianFilter.h"
84 #include "internal/bitmap/modulate.h"
85 #include "internal/bitmap/negate.h"
86 #include "internal/bitmap/normalize.h"
87 #include "internal/bitmap/oilPaint.h"
88 #include "internal/bitmap/opacity.h"
89 #include "internal/bitmap/raise.h"
90 #include "internal/bitmap/reduceNoise.h"
91 #include "internal/bitmap/sample.h"
92 #include "internal/bitmap/shade.h"
93 #include "internal/bitmap/sharpen.h"
94 #include "internal/bitmap/solarize.h"
95 #include "internal/bitmap/spread.h"
96 #include "internal/bitmap/swirl.h"
97 //#include "internal/bitmap/threshold.h"
98 #include "internal/bitmap/unsharpmask.h"
99 #include "internal/bitmap/wave.h"
100 #endif /* WITH_IMAGE_MAGICK */
102 #include "internal/filter/filter.h"
104 extern gboolean inkscape_app_use_gui( Inkscape::Application const *app );
106 namespace Inkscape {
107 namespace Extension {
109 /** This is the extention that all files are that are pulled from
110 the extension directory and parsed */
111 #define SP_MODULE_EXTENSION "inx"
113 static void build_module_from_dir(gchar const *dirname);
114 static void check_extensions();
116 /**
117 * \return none
118 * \brief Examines the given string preference and checks to see
119 * that at least one of the registered extensions matches
120 * it. If not, a default is assigned.
121 * \param pref_path Preference path to load
122 * \param pref_attr Attribute to load from the preference
123 * \param pref_default Default string to set
124 * \param extension_family List of extensions to search
125 */
126 static void
127 update_pref(gchar const *pref_path, gchar const *pref_attr,
128 gchar const *pref_default) // , GSList *extension_family)
129 {
130 gchar const *pref = prefs_get_string_attribute(pref_path,pref_attr);
131 /*
132 gboolean missing=TRUE;
133 for (GSList *list = extension_family; list; list = g_slist_next(list)) {
134 g_assert( list->data );
136 Inkscape::Extension *extension;
137 extension = reinterpret_cast<Inkscape::Extension *>(list->data);
139 if (!strcmp(extension->get_id(),pref)) missing=FALSE;
140 }
141 */
142 if (!Inkscape::Extension::db.get( pref ) /*missing*/) {
143 prefs_set_string_attribute(pref_path, pref_attr, pref_default);
144 }
145 }
147 /**
148 * Invokes the init routines for internal modules.
149 *
150 * This should be a list of all the internal modules that need to initialized. This is just a
151 * convinent place to put them. Also, this function calls build_module_from_dir to parse the
152 * Inkscape extensions directory.
153 */
154 void
155 init()
156 {
157 /* TODO: Change to Internal */
158 Internal::Svg::init();
159 Internal::Svgz::init();
160 Internal::PsOutput::init();
161 Internal::EpsOutput::init();
162 Internal::PrintPS::init();
163 #ifdef HAVE_CAIRO_PDF
164 Internal::CairoPdfOutput::init();
165 Internal::PrintCairoPDF::init();
166 if (0) {
167 Internal::CairoRendererPdfOutput::init();
168 Internal::CairoRendererOutput::init();
169 }
170 Internal::CairoPsOutput::init();
171 #endif
172 #ifdef HAVE_POPPLER
173 Internal::PdfInput::init();
174 #endif
175 #ifdef HAVE_POPPLER_GLIB
176 if (0) {
177 Internal::PdfInputCairo::init();
178 }
179 #endif
180 #ifdef WIN32
181 Internal::PrintWin32::init();
182 Internal::PrintEmfWin32::init();
183 Internal::EmfWin32::init();
184 #endif
185 Internal::PovOutput::init();
186 Internal::JavaFXOutput::init();
187 Internal::OdfOutput::init();
188 Internal::PrintLatex::init();
189 Internal::LatexOutput::init();
190 #ifdef WITH_LIBWPG
191 Internal::WpgInput::init();
192 #endif
194 /* Effects */
195 Internal::BlurEdge::init();
196 Internal::GimpGrad::init();
197 Internal::Grid::init();
199 /* Raster Effects */
200 #ifdef WITH_IMAGE_MAGICK
201 Internal::Bitmap::AdaptiveThreshold::init();
202 Internal::Bitmap::AddNoise::init();
203 Internal::Bitmap::Blur::init();
204 Internal::Bitmap::Channel::init();
205 Internal::Bitmap::Charcoal::init();
206 Internal::Bitmap::Colorize::init();
207 Internal::Bitmap::Contrast::init();
208 Internal::Bitmap::CycleColormap::init();
209 Internal::Bitmap::Edge::init();
210 Internal::Bitmap::Despeckle::init();
211 Internal::Bitmap::Emboss::init();
212 Internal::Bitmap::Enhance::init();
213 Internal::Bitmap::Equalize::init();
214 Internal::Bitmap::GaussianBlur::init();
215 Internal::Bitmap::Implode::init();
216 Internal::Bitmap::Level::init();
217 Internal::Bitmap::LevelChannel::init();
218 Internal::Bitmap::MedianFilter::init();
219 Internal::Bitmap::Modulate::init();
220 Internal::Bitmap::Negate::init();
221 Internal::Bitmap::Normalize::init();
222 Internal::Bitmap::OilPaint::init();
223 Internal::Bitmap::Opacity::init();
224 Internal::Bitmap::Raise::init();
225 Internal::Bitmap::ReduceNoise::init();
226 Internal::Bitmap::Sample::init();
227 Internal::Bitmap::Shade::init();
228 Internal::Bitmap::Sharpen::init();
229 Internal::Bitmap::Solarize::init();
230 Internal::Bitmap::Spread::init();
231 Internal::Bitmap::Swirl::init();
232 //Internal::Bitmap::Threshold::init();
233 Internal::Bitmap::Unsharpmask::init();
234 Internal::Bitmap::Wave::init();
235 #endif /* WITH_IMAGE_MAGICK */
237 Internal::Filter::Filter::filters_all();
239 /* Load search path for extensions */
240 if (Inkscape::Extension::Extension::search_path.size() == 0)
241 {
242 Inkscape::Extension::Extension::search_path.push_back(profile_path("extensions"));
244 Inkscape::Extension::Extension::search_path.push_back(g_strdup(INKSCAPE_EXTENSIONDIR));
246 }
248 for (unsigned int i=0; i<Inkscape::Extension::Extension::search_path.size(); i++) {
249 build_module_from_dir(Inkscape::Extension::Extension::search_path[i]);
250 }
252 /* this is at the very end because it has several catch-alls
253 * that are possibly over-ridden by other extensions (such as
254 * svgz)
255 */
256 Internal::GdkpixbufInput::init();
258 /* now we need to check and make sure everyone is happy */
259 check_extensions();
261 /* This is a hack to deal with updating saved outdated module
262 * names in the prefs...
263 */
264 update_pref("dialogs.save_as", "default",
265 SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE
266 // Inkscape::Extension::db.get_output_list()
267 );
268 }
270 /**
271 * \return none
272 * \brief This function parses a directory for files of SP_MODULE_EXTENSION
273 * type and loads them.
274 * \param dirname The directory that should be searched for modules
275 *
276 * Here is just a basic function that moves through a directory. It looks at every entry, and
277 * compares its filename with SP_MODULE_EXTENSION. Of those that pass, build_from_file is called
278 * with their filenames.
279 */
280 static void
281 build_module_from_dir(gchar const *dirname)
282 {
283 if (!dirname) {
284 g_warning(_("Null external module directory name. Modules will not be loaded."));
285 return;
286 }
288 if (!Glib::file_test(std::string(dirname), Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_DIR)) {
289 return;
290 }
292 //# Hopefully doing this the Glib way is portable
294 GError *err;
295 GDir *directory = g_dir_open(dirname, 0, &err);
296 if (!directory) {
297 gchar *safeDir = Inkscape::IO::sanitizeString(dirname);
298 g_warning(_("Modules directory (%s) is unavailable. External modules in that directory will not be loaded."), safeDir);
299 g_free(safeDir);
300 return;
301 }
303 gchar *filename;
304 while ((filename = (gchar *)g_dir_read_name(directory)) != NULL) {
305 if (strlen(filename) < strlen(SP_MODULE_EXTENSION)) {
306 continue;
307 }
309 if (strcmp(SP_MODULE_EXTENSION, filename + (strlen(filename) - strlen(SP_MODULE_EXTENSION)))) {
310 continue;
311 }
313 gchar *pathname = g_build_filename(dirname, filename, NULL);
314 build_from_file(pathname);
315 g_free(pathname);
316 }
318 g_dir_close(directory);
320 return;
321 }
324 static void
325 check_extensions_internal(Extension *in_plug, gpointer in_data)
326 {
327 int *count = (int *)in_data;
329 if (in_plug == NULL) return;
330 if (!in_plug->deactivated() && !in_plug->check()) {
331 in_plug->deactivate();
332 (*count)++;
333 }
334 }
336 static void
337 check_extensions()
338 {
339 int count = 1;
340 bool anyfail = false;
341 // int pass = 0;
343 Inkscape::Extension::Extension::error_file_open();
344 while (count != 0) {
345 count = 0;
346 db.foreach(check_extensions_internal, (gpointer)&count);
347 if (count != 0) anyfail = true;
348 }
349 Inkscape::Extension::Extension::error_file_close();
350 }
352 } } /* namespace Inkscape::Extension */
355 /*
356 Local Variables:
357 mode:c++
358 c-file-style:"stroustrup"
359 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
360 indent-tabs-mode:nil
361 fill-column:99
362 End:
363 */
364 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :