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