1 /** \file
2 * \brief Prefs handling implementation
3 *
4 * Authors:
5 * Ralf Stephan <ralf@ark.in-berlin.de>
6 *
7 * Copyright (C) 2005 Authors
8 *
9 * Released under GNU GPL. Read the file 'COPYING' for more information.
10 */
12 #ifdef HAVE_CONFIG_H
13 # include <config.h>
14 #endif
16 #include <glibmm/i18n.h>
18 #include "preferences-skeleton.h"
19 #include "xml/repr.h"
20 #include "dialogs/input.h"
21 #include "inkscape.h"
22 #include "preferences.h"
24 #define PREFERENCES_FILE "preferences.xml"
26 static Inkscape::XML::Document *_preferences;
27 static bool _save_preferences;
29 namespace Inkscape {
31 void
32 Preferences::loadSkeleton()
33 {
34 _preferences = sp_repr_read_mem (preferences_skeleton, PREFERENCES_SKELETON_SIZE, 0);
35 }
37 Inkscape::XML::Document*
38 Preferences::get()
39 {
40 return _preferences;
41 }
43 /**
44 * Attempts to load the preferences file indicated by the global PREFERENCES_FILE
45 * parameter. If it cannot load it, the default preferences_skeleton will be used
46 * instead.
47 */
48 void
49 Preferences::load()
50 {
51 /// \todo this still uses old Gtk+ code which should be somewhere else
52 if (inkscape_load_config (PREFERENCES_FILE,
53 _preferences,
54 preferences_skeleton,
55 PREFERENCES_SKELETON_SIZE,
56 _("%s is not a regular file.\n%s"),
57 _("%s not a valid XML file, or\n"
58 "you don't have read permissions on it.\n%s"),
59 _("%s is not a valid preferences file.\n%s"),
60 _("Inkscape will run with default settings.\n"
61 "New settings will not be saved.")))
62 {
63 sp_input_load_from_preferences();
64 _save_preferences = true;
65 } else
66 _save_preferences = false;
67 }
69 void
70 Preferences::save()
71 {
72 if (!_preferences || ! _save_preferences)
73 return;
75 gchar *fn = profile_path (PREFERENCES_FILE);
76 (void) sp_repr_save_file (_preferences, fn);
77 g_free (fn);
78 }
81 } // namespace Inkscape
83 /*
84 Local Variables:
85 mode:c++
86 c-file-style:"stroustrup"
87 c-file-offsets:((innamespace . 0)(inline-open . 0))
88 indent-tabs-mode:nil
89 fill-column:75
90 End:
91 */
92 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :