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