Code

switch back to cairo pdf importer temporarily
[inkscape.git] / src / extension / init.cpp
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 extern gboolean inkscape_app_use_gui( Inkscape::Application const *app );
67 namespace Inkscape {
68 namespace Extension {
70 /** This is the extention that all files are that are pulled from
71     the extension directory and parsed */
72 #define SP_MODULE_EXTENSION  "inx"
74 static void build_module_from_dir(gchar const *dirname);
75 static void check_extensions();
77 /**
78  * \return    none
79  * \brief     Examines the given string preference and checks to see
80  *            that at least one of the registered extensions matches
81  *            it.  If not, a default is assigned.
82  * \param     pref_path        Preference path to load
83  * \param     pref_attr        Attribute to load from the preference
84  * \param     pref_default     Default string to set
85  * \param     extension_family List of extensions to search
86  */
87 static void
88 update_pref(gchar const *pref_path, gchar const *pref_attr,
89             gchar const *pref_default) // , GSList *extension_family)
90 {
91     gchar const *pref = prefs_get_string_attribute(pref_path,pref_attr);
92     /*
93     gboolean missing=TRUE;
94     for (GSList *list = extension_family; list; list = g_slist_next(list)) {
95         g_assert( list->data );
97         Inkscape::Extension *extension;
98         extension = reinterpret_cast<Inkscape::Extension *>(list->data);
100         if (!strcmp(extension->get_id(),pref)) missing=FALSE;
101     }
102     */
103     if (!Inkscape::Extension::db.get( pref ) /*missing*/) {
104         prefs_set_string_attribute(pref_path, pref_attr, pref_default);
105     }
108 /**
109  * Invokes the init routines for internal modules.
110  *
111  * This should be a list of all the internal modules that need to initialized.  This is just a
112  * convinent place to put them.  Also, this function calls build_module_from_dir to parse the
113  * Inkscape extensions directory.
114  */
115 void
116 init()
118     /* TODO: Change to Internal */
119     Internal::Svg::init();
120     Internal::Svgz::init();
121     Internal::PsOutput::init();
122     Internal::EpsOutput::init();
123     Internal::PrintPS::init();
124 #ifdef HAVE_CAIRO_PDF
125     Internal::CairoPdfOutput::init();
126     Internal::PrintCairoPDF::init();
127     if (0) {
128     Internal::CairoRendererPdfOutput::init();
129     Internal::CairoRendererOutput::init();
130     }
131     Internal::CairoPsOutput::init();
132 #endif
133 #ifdef HAVE_POPPLER
134     //Internal::PdfInput::init();
135 #endif
136 #ifdef HAVE_POPPLER_GLIB
137     if (1) {
138     Internal::PdfInputCairo::init();
139     }
140 #endif
141 #ifdef WITH_GNOME_PRINT
142     Internal::PrintGNOME::init();
143 #endif
144 #ifdef WIN32
145     Internal::PrintWin32::init();
146     Internal::PrintEmfWin32::init();
147     Internal::EmfWin32::init();
148 #endif
149     Internal::PovOutput::init();
150     Internal::OdfOutput::init();
151     Internal::PrintLatex::init();
152     Internal::LatexOutput::init();
153     Internal::WpgInput::init();
155     /* Effects */
156     Internal::BlurEdge::init();
157     Internal::GimpGrad::init();
158     Internal::Grid::init();
160     /* Load search path for extensions */
161     if (Inkscape::Extension::Extension::search_path.size() == 0)
162     {
163         Inkscape::Extension::Extension::search_path.push_back(profile_path("extensions"));
164         Inkscape::Extension::Extension::search_path.push_back(g_strdup(INKSCAPE_EXTENSIONDIR));
165     }
167     for (unsigned int i=0; i<Inkscape::Extension::Extension::search_path.size(); i++) {
168         build_module_from_dir(Inkscape::Extension::Extension::search_path[i]);
169     }
171     /* this is at the very end because it has several catch-alls
172      * that are possibly over-ridden by other extensions (such as
173      * svgz)
174      */
175     Internal::GdkpixbufInput::init();
177     /* now we need to check and make sure everyone is happy */
178     check_extensions();
180     /* This is a hack to deal with updating saved outdated module
181      * names in the prefs...
182      */
183     update_pref("dialogs.save_as", "default",
184                 SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE
185                 // Inkscape::Extension::db.get_output_list()
186         );
189 /**
190  * \return    none
191  * \brief     This function parses a directory for files of SP_MODULE_EXTENSION
192  *            type and loads them.
193  * \param     dirname  The directory that should be searched for modules
194  *
195  * Here is just a basic function that moves through a directory.  It looks at every entry, and
196  * compares its filename with SP_MODULE_EXTENSION.  Of those that pass, build_from_file is called
197  * with their filenames.
198  */
199 static void
200 build_module_from_dir(gchar const *dirname)
202     if (!dirname) {
203         g_warning(_("Null external module directory name.  Modules will not be loaded."));
204         return;
205     }
207     if (!Glib::file_test(std::string(dirname), Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_DIR)) {
208         return;
209     }
211     //# Hopefully doing this the Glib way is portable
213     GError *err;
214     GDir *directory = g_dir_open(dirname, 0, &err);
215     if (!directory) {
216         gchar *safeDir = Inkscape::IO::sanitizeString(dirname);
217         g_warning(_("Modules directory (%s) is unavailable.  External modules in that directory will not be loaded."), safeDir);
218         g_free(safeDir);
219         return;
220     }
222     gchar *filename;
223     while ((filename = (gchar *)g_dir_read_name(directory)) != NULL) {
225         if (strlen(filename) < strlen(SP_MODULE_EXTENSION)) {
226             continue;
227         }
229         if (strcmp(SP_MODULE_EXTENSION, filename + (strlen(filename) - strlen(SP_MODULE_EXTENSION)))) {
230             continue;
231         }
233         gchar *pathname = g_strdup_printf("%s/%s", dirname, filename);
234         build_from_file(pathname);
235         g_free(pathname);
236     }
238     g_dir_close(directory);
242 static void
243 check_extensions_internal(Extension *in_plug, gpointer in_data)
245     int *count = (int *)in_data;
247     if (in_plug == NULL) return;
248     if (!in_plug->deactivated() && !in_plug->check()) {
249          in_plug->deactivate();
250         (*count)++;
251     }
254 static void
255 check_extensions()
257     int count = 1;
258     bool anyfail = false;
259     // int pass = 0;
261     Inkscape::Extension::Extension::error_file_open();
262     while (count != 0) {
263         // printf("Check extensions pass %d\n", pass++);
264         count = 0;
265         db.foreach(check_extensions_internal, (gpointer)&count);
266         if (count != 0) anyfail = true;
267     }
268     Inkscape::Extension::Extension::error_file_close();
271 } } /* namespace Inkscape::Extension */
274 /*
275   Local Variables:
276   mode:c++
277   c-file-style:"stroustrup"
278   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
279   indent-tabs-mode:nil
280   fill-column:99
281   End:
282 */
283 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :