summaryrefslogtreecommitdiffstats
path: root/src/preferences.cpp
blob: 5d3981b5804b8354f5bf6dc6ae6591dc563712d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/** \file
 * \brief  Prefs handling implementation
 *
 * Authors:
 *   Ralf Stephan <ralf@ark.in-berlin.de>
 *
 * Copyright (C) 2005 Authors
 *
 * Released under GNU GPL.  Read the file 'COPYING' for more information.
 */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <glibmm/i18n.h>

#include "preferences-skeleton.h"
#include "xml/repr.h"
#include "dialogs/input.h"
#include "inkscape.h"
#include "preferences.h"

#define PREFERENCES_FILE "preferences.xml"

static Inkscape::XML::Document *_preferences;
static bool _save_preferences;

namespace Inkscape {

void
Preferences::loadSkeleton()
{
    _preferences = sp_repr_read_mem (preferences_skeleton, PREFERENCES_SKELETON_SIZE, 0);
}

Inkscape::XML::Document*
Preferences::get()
{
    return _preferences;
}

/**
 *  Attempts to load the preferences file indicated by the global PREFERENCES_FILE
 *  parameter.  If it cannot load it, the default preferences_skeleton will be used
 *  instead.
 */
void
Preferences::load()
{
    /// \todo this still uses old Gtk+ code which should be somewhere else
    if (inkscape_load_config (PREFERENCES_FILE, 
                              _preferences,
                              preferences_skeleton, 
                              PREFERENCES_SKELETON_SIZE,
                              _("%s is not a regular file.\n%s"),
                              _("%s not a valid XML file, or\n"
                                "you don't have read permissions on it.\n%s"),
                              _("%s is not a valid preferences file.\n%s"),
                              _("Inkscape will run with default settings.\n"
                                "New settings will not be saved.")))
    {
        sp_input_load_from_preferences();
        _save_preferences = true;
    } else
        _save_preferences = false;
}

void
Preferences::save()
{
    if (!_preferences || ! _save_preferences)
        return;
    
    gchar *fn = profile_path (PREFERENCES_FILE);
    (void) sp_repr_save_file (_preferences, fn);
    g_free (fn);
}


} // namespace Inkscape

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0))
  indent-tabs-mode:nil
  fill-column:75
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :