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(); // disabled, to be deleted, replaced by CairoPsOutput
161 //Internal::EpsOutput::init(); // disabled, to be deleted, replaced by CairoEpsOutput
162 Internal::PrintPS::init();
163 #ifdef HAVE_CAIRO_PDF
164 if (prefs_get_int_attribute("options.useoldpdfexporter", "value", 1) == 1) {
165 //g_print ("Using CairoPdfOutput: old pdf exporter\n");
166 Internal::CairoPdfOutput::init();
167 Internal::PrintCairoPDF::init();
168 } else {
169 //g_print ("Using CairoRendererPdfOutput: new pdf exporter\n");
170 Internal::CairoRendererPdfOutput::init();
171 Internal::CairoRendererOutput::init();
172 }
173 Internal::CairoPsOutput::init();
174 Internal::CairoEpsOutput::init();
175 #endif
176 #ifdef HAVE_POPPLER
177 Internal::PdfInput::init();
178 #endif
179 #ifdef HAVE_POPPLER_GLIB
180 if (0) {
181 Internal::PdfInputCairo::init();
182 }
183 #endif
184 #ifdef WIN32
185 Internal::PrintWin32::init();
186 Internal::PrintEmfWin32::init();
187 Internal::EmfWin32::init();
188 #endif
189 Internal::PovOutput::init();
190 Internal::JavaFXOutput::init();
191 Internal::OdfOutput::init();
192 Internal::PrintLatex::init();
193 Internal::LatexOutput::init();
194 #ifdef WITH_LIBWPG
195 Internal::WpgInput::init();
196 #endif
198 /* Effects */
199 Internal::BlurEdge::init();
200 Internal::GimpGrad::init();
201 Internal::Grid::init();
203 /* Raster Effects */
204 #ifdef WITH_IMAGE_MAGICK
205 Internal::Bitmap::AdaptiveThreshold::init();
206 Internal::Bitmap::AddNoise::init();
207 Internal::Bitmap::Blur::init();
208 Internal::Bitmap::Channel::init();
209 Internal::Bitmap::Charcoal::init();
210 Internal::Bitmap::Colorize::init();
211 Internal::Bitmap::Contrast::init();
212 Internal::Bitmap::CycleColormap::init();
213 Internal::Bitmap::Edge::init();
214 Internal::Bitmap::Despeckle::init();
215 Internal::Bitmap::Emboss::init();
216 Internal::Bitmap::Enhance::init();
217 Internal::Bitmap::Equalize::init();
218 Internal::Bitmap::GaussianBlur::init();
219 Internal::Bitmap::Implode::init();
220 Internal::Bitmap::Level::init();
221 Internal::Bitmap::LevelChannel::init();
222 Internal::Bitmap::MedianFilter::init();
223 Internal::Bitmap::Modulate::init();
224 Internal::Bitmap::Negate::init();
225 Internal::Bitmap::Normalize::init();
226 Internal::Bitmap::OilPaint::init();
227 Internal::Bitmap::Opacity::init();
228 Internal::Bitmap::Raise::init();
229 Internal::Bitmap::ReduceNoise::init();
230 Internal::Bitmap::Sample::init();
231 Internal::Bitmap::Shade::init();
232 Internal::Bitmap::Sharpen::init();
233 Internal::Bitmap::Solarize::init();
234 Internal::Bitmap::Spread::init();
235 Internal::Bitmap::Swirl::init();
236 //Internal::Bitmap::Threshold::init();
237 Internal::Bitmap::Unsharpmask::init();
238 Internal::Bitmap::Wave::init();
239 #endif /* WITH_IMAGE_MAGICK */
241 Internal::Filter::Filter::filters_all();
243 /* Load search path for extensions */
244 if (Inkscape::Extension::Extension::search_path.size() == 0)
245 {
246 Inkscape::Extension::Extension::search_path.push_back(profile_path("extensions"));
248 Inkscape::Extension::Extension::search_path.push_back(g_strdup(INKSCAPE_EXTENSIONDIR));
250 }
252 for (unsigned int i=0; i<Inkscape::Extension::Extension::search_path.size(); i++) {
253 build_module_from_dir(Inkscape::Extension::Extension::search_path[i]);
254 }
256 /* this is at the very end because it has several catch-alls
257 * that are possibly over-ridden by other extensions (such as
258 * svgz)
259 */
260 Internal::GdkpixbufInput::init();
262 /* now we need to check and make sure everyone is happy */
263 check_extensions();
265 /* This is a hack to deal with updating saved outdated module
266 * names in the prefs...
267 */
268 update_pref("dialogs.save_as", "default",
269 SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE
270 // Inkscape::Extension::db.get_output_list()
271 );
272 }
274 /**
275 * \return none
276 * \brief This function parses a directory for files of SP_MODULE_EXTENSION
277 * type and loads them.
278 * \param dirname The directory that should be searched for modules
279 *
280 * Here is just a basic function that moves through a directory. It looks at every entry, and
281 * compares its filename with SP_MODULE_EXTENSION. Of those that pass, build_from_file is called
282 * with their filenames.
283 */
284 static void
285 build_module_from_dir(gchar const *dirname)
286 {
287 if (!dirname) {
288 g_warning(_("Null external module directory name. Modules will not be loaded."));
289 return;
290 }
292 if (!Glib::file_test(std::string(dirname), Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_DIR)) {
293 return;
294 }
296 //# Hopefully doing this the Glib way is portable
298 GError *err;
299 GDir *directory = g_dir_open(dirname, 0, &err);
300 if (!directory) {
301 gchar *safeDir = Inkscape::IO::sanitizeString(dirname);
302 g_warning(_("Modules directory (%s) is unavailable. External modules in that directory will not be loaded."), safeDir);
303 g_free(safeDir);
304 return;
305 }
307 gchar *filename;
308 while ((filename = (gchar *)g_dir_read_name(directory)) != NULL) {
309 if (strlen(filename) < strlen(SP_MODULE_EXTENSION)) {
310 continue;
311 }
313 if (strcmp(SP_MODULE_EXTENSION, filename + (strlen(filename) - strlen(SP_MODULE_EXTENSION)))) {
314 continue;
315 }
317 gchar *pathname = g_build_filename(dirname, filename, NULL);
318 build_from_file(pathname);
319 g_free(pathname);
320 }
322 g_dir_close(directory);
324 return;
325 }
328 static void
329 check_extensions_internal(Extension *in_plug, gpointer in_data)
330 {
331 int *count = (int *)in_data;
333 if (in_plug == NULL) return;
334 if (!in_plug->deactivated() && !in_plug->check()) {
335 in_plug->deactivate();
336 (*count)++;
337 }
338 }
340 static void
341 check_extensions()
342 {
343 int count = 1;
344 bool anyfail = false;
345 // int pass = 0;
347 Inkscape::Extension::Extension::error_file_open();
348 while (count != 0) {
349 count = 0;
350 db.foreach(check_extensions_internal, (gpointer)&count);
351 if (count != 0) anyfail = true;
352 }
353 Inkscape::Extension::Extension::error_file_close();
354 }
356 } } /* namespace Inkscape::Extension */
359 /*
360 Local Variables:
361 mode:c++
362 c-file-style:"stroustrup"
363 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
364 indent-tabs-mode:nil
365 fill-column:99
366 End:
367 */
368 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :