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"
58 #ifdef WITH_DBUS
59 #include "dbus/dbus-init.h"
60 #endif
62 #ifdef WITH_IMAGE_MAGICK
63 #include "internal/bitmap/adaptiveThreshold.h"
64 #include "internal/bitmap/addNoise.h"
65 #include "internal/bitmap/blur.h"
66 #include "internal/bitmap/channel.h"
67 #include "internal/bitmap/charcoal.h"
68 #include "internal/bitmap/colorize.h"
69 #include "internal/bitmap/contrast.h"
70 #include "internal/bitmap/cycleColormap.h"
71 #include "internal/bitmap/despeckle.h"
72 #include "internal/bitmap/edge.h"
73 #include "internal/bitmap/emboss.h"
74 #include "internal/bitmap/enhance.h"
75 #include "internal/bitmap/equalize.h"
76 #include "internal/bitmap/gaussianBlur.h"
77 #include "internal/bitmap/implode.h"
78 #include "internal/bitmap/level.h"
79 #include "internal/bitmap/levelChannel.h"
80 #include "internal/bitmap/medianFilter.h"
81 #include "internal/bitmap/modulate.h"
82 #include "internal/bitmap/negate.h"
83 #include "internal/bitmap/normalize.h"
84 #include "internal/bitmap/oilPaint.h"
85 #include "internal/bitmap/opacity.h"
86 #include "internal/bitmap/raise.h"
87 #include "internal/bitmap/reduceNoise.h"
88 #include "internal/bitmap/sample.h"
89 #include "internal/bitmap/shade.h"
90 #include "internal/bitmap/sharpen.h"
91 #include "internal/bitmap/solarize.h"
92 #include "internal/bitmap/spread.h"
93 #include "internal/bitmap/swirl.h"
94 //#include "internal/bitmap/threshold.h"
95 #include "internal/bitmap/unsharpmask.h"
96 #include "internal/bitmap/wave.h"
97 #endif /* WITH_IMAGE_MAGICK */
99 #include "internal/filter/filter.h"
101 extern gboolean inkscape_app_use_gui( Inkscape::Application const *app );
103 namespace Inkscape {
104 namespace Extension {
106 /** This is the extention that all files are that are pulled from
107 the extension directory and parsed */
108 #define SP_MODULE_EXTENSION "inx"
110 static void build_module_from_dir(gchar const *dirname);
111 static void check_extensions();
113 /**
114 * \return none
115 * \brief Examines the given string preference and checks to see
116 * that at least one of the registered extensions matches
117 * it. If not, a default is assigned.
118 * \param pref_path Preference path to update
119 * \param pref_default Default string to set
120 * \param extension_family List of extensions to search
121 */
122 static void
123 update_pref(Glib::ustring const &pref_path,
124 gchar const *pref_default) // , GSList *extension_family)
125 {
126 Glib::ustring pref = Inkscape::Preferences::get()->getString(pref_path);
127 /*
128 gboolean missing=TRUE;
129 for (GSList *list = extension_family; list; list = g_slist_next(list)) {
130 g_assert( list->data );
132 Inkscape::Extension *extension;
133 extension = reinterpret_cast<Inkscape::Extension *>(list->data);
135 if (!strcmp(extension->get_id(),pref)) missing=FALSE;
136 }
137 */
138 if (!Inkscape::Extension::db.get( pref.data() ) /*missing*/) {
139 Inkscape::Preferences::get()->setString(pref_path, pref_default);
140 }
141 }
143 /**
144 * Invokes the init routines for internal modules.
145 *
146 * This should be a list of all the internal modules that need to initialized. This is just a
147 * convinent place to put them. Also, this function calls build_module_from_dir to parse the
148 * Inkscape extensions directory.
149 */
150 void
151 init()
152 {
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 #ifdef WITH_DBUS
193 Dbus::init();
194 #endif
196 /* Raster Effects */
197 #ifdef WITH_IMAGE_MAGICK
198 Internal::Bitmap::AdaptiveThreshold::init();
199 Internal::Bitmap::AddNoise::init();
200 Internal::Bitmap::Blur::init();
201 Internal::Bitmap::Channel::init();
202 Internal::Bitmap::Charcoal::init();
203 Internal::Bitmap::Colorize::init();
204 Internal::Bitmap::Contrast::init();
205 Internal::Bitmap::CycleColormap::init();
206 Internal::Bitmap::Edge::init();
207 Internal::Bitmap::Despeckle::init();
208 Internal::Bitmap::Emboss::init();
209 Internal::Bitmap::Enhance::init();
210 Internal::Bitmap::Equalize::init();
211 Internal::Bitmap::GaussianBlur::init();
212 Internal::Bitmap::Implode::init();
213 Internal::Bitmap::Level::init();
214 Internal::Bitmap::LevelChannel::init();
215 Internal::Bitmap::MedianFilter::init();
216 Internal::Bitmap::Modulate::init();
217 Internal::Bitmap::Negate::init();
218 Internal::Bitmap::Normalize::init();
219 Internal::Bitmap::OilPaint::init();
220 Internal::Bitmap::Opacity::init();
221 Internal::Bitmap::Raise::init();
222 Internal::Bitmap::ReduceNoise::init();
223 Internal::Bitmap::Sample::init();
224 Internal::Bitmap::Shade::init();
225 Internal::Bitmap::Sharpen::init();
226 Internal::Bitmap::Solarize::init();
227 Internal::Bitmap::Spread::init();
228 Internal::Bitmap::Swirl::init();
229 //Internal::Bitmap::Threshold::init();
230 Internal::Bitmap::Unsharpmask::init();
231 Internal::Bitmap::Wave::init();
232 #endif /* WITH_IMAGE_MAGICK */
234 Internal::Filter::Filter::filters_all();
236 /* Load search path for extensions */
237 if (Inkscape::Extension::Extension::search_path.size() == 0)
238 {
239 Inkscape::Extension::Extension::search_path.push_back(profile_path("extensions"));
241 Inkscape::Extension::Extension::search_path.push_back(g_strdup(INKSCAPE_EXTENSIONDIR));
243 }
245 for (unsigned int i=0; i<Inkscape::Extension::Extension::search_path.size(); i++) {
246 build_module_from_dir(Inkscape::Extension::Extension::search_path[i]);
247 }
249 /* this is at the very end because it has several catch-alls
250 * that are possibly over-ridden by other extensions (such as
251 * svgz)
252 */
253 Internal::GdkpixbufInput::init();
255 /* now we need to check and make sure everyone is happy */
256 check_extensions();
258 /* This is a hack to deal with updating saved outdated module
259 * names in the prefs...
260 */
261 update_pref("/dialogs/save_as/default",
262 SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE
263 // Inkscape::Extension::db.get_output_list()
264 );
265 }
267 /**
268 * \return none
269 * \brief This function parses a directory for files of SP_MODULE_EXTENSION
270 * type and loads them.
271 * \param dirname The directory that should be searched for modules
272 *
273 * Here is just a basic function that moves through a directory. It looks at every entry, and
274 * compares its filename with SP_MODULE_EXTENSION. Of those that pass, build_from_file is called
275 * with their filenames.
276 */
277 static void
278 build_module_from_dir(gchar const *dirname)
279 {
280 if (!dirname) {
281 g_warning(_("Null external module directory name. Modules will not be loaded."));
282 return;
283 }
285 if (!Glib::file_test(std::string(dirname), Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_DIR)) {
286 return;
287 }
289 //# Hopefully doing this the Glib way is portable
291 GError *err;
292 GDir *directory = g_dir_open(dirname, 0, &err);
293 if (!directory) {
294 gchar *safeDir = Inkscape::IO::sanitizeString(dirname);
295 g_warning(_("Modules directory (%s) is unavailable. External modules in that directory will not be loaded."), safeDir);
296 g_free(safeDir);
297 return;
298 }
300 gchar *filename;
301 while ((filename = (gchar *)g_dir_read_name(directory)) != NULL) {
302 if (strlen(filename) < strlen(SP_MODULE_EXTENSION)) {
303 continue;
304 }
306 if (strcmp(SP_MODULE_EXTENSION, filename + (strlen(filename) - strlen(SP_MODULE_EXTENSION)))) {
307 continue;
308 }
310 gchar *pathname = g_build_filename(dirname, filename, NULL);
311 build_from_file(pathname);
312 g_free(pathname);
313 }
315 g_dir_close(directory);
317 return;
318 }
321 static void
322 check_extensions_internal(Extension *in_plug, gpointer in_data)
323 {
324 int *count = (int *)in_data;
326 if (in_plug == NULL) return;
327 if (!in_plug->deactivated() && !in_plug->check()) {
328 in_plug->deactivate();
329 (*count)++;
330 }
331 }
333 static void
334 check_extensions()
335 {
336 int count = 1;
337 bool anyfail = false;
338 // int pass = 0;
340 Inkscape::Extension::Extension::error_file_open();
341 while (count != 0) {
342 count = 0;
343 db.foreach(check_extensions_internal, (gpointer)&count);
344 if (count != 0) anyfail = true;
345 }
346 Inkscape::Extension::Extension::error_file_close();
347 }
349 } } /* namespace Inkscape::Extension */
352 /*
353 Local Variables:
354 mode:c++
355 c-file-style:"stroustrup"
356 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
357 indent-tabs-mode:nil
358 fill-column:99
359 End:
360 */
361 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :