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 Glib::ustring pref = Inkscape::Preferences::get()->getString(pref_path);
124 /*
125 gboolean missing=TRUE;
126 for (GSList *list = extension_family; list; list = g_slist_next(list)) {
127 g_assert( list->data );
129 Inkscape::Extension *extension;
130 extension = reinterpret_cast<Inkscape::Extension *>(list->data);
132 if (!strcmp(extension->get_id(),pref)) missing=FALSE;
133 }
134 */
135 if (!Inkscape::Extension::db.get( pref.data() ) /*missing*/) {
136 Inkscape::Preferences::get()->setString(pref_path, pref_default);
137 }
138 }
140 /**
141 * Invokes the init routines for internal modules.
142 *
143 * This should be a list of all the internal modules that need to initialized. This is just a
144 * convinent place to put them. Also, this function calls build_module_from_dir to parse the
145 * Inkscape extensions directory.
146 */
147 void
148 init()
149 {
150 /* TODO: Change to Internal */
151 Internal::Svg::init();
152 Internal::Svgz::init();
154 #ifdef HAVE_CAIRO_PDF
155 //g_print ("Using CairoRendererPdfOutput: new pdf exporter\n");
156 Internal::CairoRendererPdfOutput::init();
157 Internal::CairoRendererOutput::init();
159 Internal::CairoPsOutput::init();
160 Internal::CairoEpsOutput::init();
161 #endif
162 #ifdef HAVE_POPPLER
163 Internal::PdfInput::init();
164 #endif
165 #ifdef HAVE_POPPLER_GLIB
166 if (0) {
167 Internal::PdfInputCairo::init();
168 }
169 #endif
170 #ifdef WIN32
171 Internal::PrintWin32::init();
172 Internal::PrintEmfWin32::init();
173 Internal::EmfWin32::init();
174 #endif
175 Internal::PovOutput::init();
176 Internal::JavaFXOutput::init();
177 Internal::OdfOutput::init();
178 Internal::PrintLatex::init();
179 Internal::LatexOutput::init();
180 #ifdef WITH_LIBWPG
181 Internal::WpgInput::init();
182 #endif
184 /* Effects */
185 Internal::BlurEdge::init();
186 Internal::GimpGrad::init();
187 Internal::Grid::init();
189 /* Raster Effects */
190 #ifdef WITH_IMAGE_MAGICK
191 Internal::Bitmap::AdaptiveThreshold::init();
192 Internal::Bitmap::AddNoise::init();
193 Internal::Bitmap::Blur::init();
194 Internal::Bitmap::Channel::init();
195 Internal::Bitmap::Charcoal::init();
196 Internal::Bitmap::Colorize::init();
197 Internal::Bitmap::Contrast::init();
198 Internal::Bitmap::CycleColormap::init();
199 Internal::Bitmap::Edge::init();
200 Internal::Bitmap::Despeckle::init();
201 Internal::Bitmap::Emboss::init();
202 Internal::Bitmap::Enhance::init();
203 Internal::Bitmap::Equalize::init();
204 Internal::Bitmap::GaussianBlur::init();
205 Internal::Bitmap::Implode::init();
206 Internal::Bitmap::Level::init();
207 Internal::Bitmap::LevelChannel::init();
208 Internal::Bitmap::MedianFilter::init();
209 Internal::Bitmap::Modulate::init();
210 Internal::Bitmap::Negate::init();
211 Internal::Bitmap::Normalize::init();
212 Internal::Bitmap::OilPaint::init();
213 Internal::Bitmap::Opacity::init();
214 Internal::Bitmap::Raise::init();
215 Internal::Bitmap::ReduceNoise::init();
216 Internal::Bitmap::Sample::init();
217 Internal::Bitmap::Shade::init();
218 Internal::Bitmap::Sharpen::init();
219 Internal::Bitmap::Solarize::init();
220 Internal::Bitmap::Spread::init();
221 Internal::Bitmap::Swirl::init();
222 //Internal::Bitmap::Threshold::init();
223 Internal::Bitmap::Unsharpmask::init();
224 Internal::Bitmap::Wave::init();
225 #endif /* WITH_IMAGE_MAGICK */
227 Internal::Filter::Filter::filters_all();
229 /* Load search path for extensions */
230 if (Inkscape::Extension::Extension::search_path.size() == 0)
231 {
232 Inkscape::Extension::Extension::search_path.push_back(profile_path("extensions"));
234 Inkscape::Extension::Extension::search_path.push_back(g_strdup(INKSCAPE_EXTENSIONDIR));
236 }
238 for (unsigned int i=0; i<Inkscape::Extension::Extension::search_path.size(); i++) {
239 build_module_from_dir(Inkscape::Extension::Extension::search_path[i]);
240 }
242 /* this is at the very end because it has several catch-alls
243 * that are possibly over-ridden by other extensions (such as
244 * svgz)
245 */
246 Internal::GdkpixbufInput::init();
248 /* now we need to check and make sure everyone is happy */
249 check_extensions();
251 /* This is a hack to deal with updating saved outdated module
252 * names in the prefs...
253 */
254 update_pref("/dialogs/save_as/default",
255 SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE
256 // Inkscape::Extension::db.get_output_list()
257 );
258 }
260 /**
261 * \return none
262 * \brief This function parses a directory for files of SP_MODULE_EXTENSION
263 * type and loads them.
264 * \param dirname The directory that should be searched for modules
265 *
266 * Here is just a basic function that moves through a directory. It looks at every entry, and
267 * compares its filename with SP_MODULE_EXTENSION. Of those that pass, build_from_file is called
268 * with their filenames.
269 */
270 static void
271 build_module_from_dir(gchar const *dirname)
272 {
273 if (!dirname) {
274 g_warning(_("Null external module directory name. Modules will not be loaded."));
275 return;
276 }
278 if (!Glib::file_test(std::string(dirname), Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_DIR)) {
279 return;
280 }
282 //# Hopefully doing this the Glib way is portable
284 GError *err;
285 GDir *directory = g_dir_open(dirname, 0, &err);
286 if (!directory) {
287 gchar *safeDir = Inkscape::IO::sanitizeString(dirname);
288 g_warning(_("Modules directory (%s) is unavailable. External modules in that directory will not be loaded."), safeDir);
289 g_free(safeDir);
290 return;
291 }
293 gchar *filename;
294 while ((filename = (gchar *)g_dir_read_name(directory)) != NULL) {
295 if (strlen(filename) < strlen(SP_MODULE_EXTENSION)) {
296 continue;
297 }
299 if (strcmp(SP_MODULE_EXTENSION, filename + (strlen(filename) - strlen(SP_MODULE_EXTENSION)))) {
300 continue;
301 }
303 gchar *pathname = g_build_filename(dirname, filename, NULL);
304 build_from_file(pathname);
305 g_free(pathname);
306 }
308 g_dir_close(directory);
310 return;
311 }
314 static void
315 check_extensions_internal(Extension *in_plug, gpointer in_data)
316 {
317 int *count = (int *)in_data;
319 if (in_plug == NULL) return;
320 if (!in_plug->deactivated() && !in_plug->check()) {
321 in_plug->deactivate();
322 (*count)++;
323 }
324 }
326 static void
327 check_extensions()
328 {
329 int count = 1;
330 bool anyfail = false;
331 // int pass = 0;
333 Inkscape::Extension::Extension::error_file_open();
334 while (count != 0) {
335 count = 0;
336 db.foreach(check_extensions_internal, (gpointer)&count);
337 if (count != 0) anyfail = true;
338 }
339 Inkscape::Extension::Extension::error_file_close();
340 }
342 } } /* namespace Inkscape::Extension */
345 /*
346 Local Variables:
347 mode:c++
348 c-file-style:"stroustrup"
349 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
350 indent-tabs-mode:nil
351 fill-column:99
352 End:
353 */
354 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :