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