1 /** @file
2 * @brief Alternate stub implementations for some functions.
3 *
4 * This file exists only for the benefit of the linker when building tests,
5 * to avoid circular dependencies. If some test causes link errors because of a function
6 * it doesn't need, feel free to add a stub here.
7 */
8 /* Authors: Krzysztof KosiĆski <twwenk.pl@gmail.com>
9 * This file is in the public domain.
10 */
12 #include "preferences.h"
13 #include <glib.h>
14 #include <glib/gstdio.h>
15 #include <cstring>
16 #include <cstdlib>
18 int sp_main_gui(int /*argc*/, char const **/*argv*/) { return 0; }
19 int sp_main_console(int /*argc*/, char const **/*argv*/) { return 0; }
21 // stubbed out preferences implementation using a simple map
22 namespace Inkscape {
24 std::map<Glib::ustring, Preferences::Entry> _prefs;
26 Preferences::Preferences() :
27 _prefs_basename(""),
28 _prefs_dir(""),
29 _prefs_filename(""),
30 _prefs_doc(NULL),
31 _use_gui(true),
32 _quiet(false),
33 _loaded(false),
34 _writable(false)
35 {
36 }
38 Preferences::~Preferences()
39 {
40 }
42 void Preferences::load(bool /*use_gui*/, bool /*quiet*/) {}
43 void Preferences::save() {}
45 // getter methods
47 Preferences::Entry const Preferences::getEntry(Glib::ustring const &pref_path)
48 {
49 return _prefs[pref_path];
50 }
51 void Preferences::setBool(Glib::ustring const &pref_path, bool value)
52 {
53 _prefs[pref_path] = _create_pref_value(pref_path, (void const*) (value ? "1" : "0"));
54 }
55 void Preferences::setInt(Glib::ustring const &pref_path, int value)
56 {
57 gchar *intstr = (gchar*) g_malloc(32);
58 g_snprintf(intstr, 32, "%d", value);
59 _prefs[pref_path] = _create_pref_value(pref_path, (void const*) intstr);
60 }
61 void Preferences::setDouble(Glib::ustring const &pref_path, double value)
62 {
63 gchar *buf = (gchar*) g_malloc(G_ASCII_DTOSTR_BUF_SIZE);
64 g_ascii_dtostr(buf, G_ASCII_DTOSTR_BUF_SIZE, value);
65 _prefs[pref_path] = _create_pref_value(pref_path, (void const*) buf);
66 }
67 void Preferences::setString(Glib::ustring const &pref_path, Glib::ustring const &value)
68 {
69 _prefs[pref_path] = _create_pref_value(pref_path, (void const*) g_strdup(value.data()));
70 }
72 bool Preferences::_extractBool(Entry const &v)
73 {
74 gchar const *s = static_cast<gchar const *>(v._value);
75 if ( !s[0] || !strcmp(s, "0") || !strcmp(s, "false") ) return false;
76 return true;
77 }
78 int Preferences::_extractInt(Entry const &v)
79 {
80 gchar const *s = static_cast<gchar const *>(v._value);
81 if ( !strcmp(s, "true") ) return true;
82 if ( !strcmp(s, "false") ) return false;
83 return atoi(s);
84 }
85 double Preferences::_extractDouble(Entry const &v)
86 {
87 gchar const *s = static_cast<gchar const *>(v._value);
88 return g_ascii_strtod(s, NULL);
89 }
91 Glib::ustring Preferences::_extractString(Entry const &v)
92 {
93 return Glib::ustring(static_cast<gchar const *>(v._value));
94 }
95 Preferences::Entry const Preferences::_create_pref_value(Glib::ustring const &path, void const *ptr)
96 {
97 return Entry(path, ptr);
98 }
100 Preferences *Preferences::_instance = NULL;
103 } // namespace Inkscape
106 /*
107 Local Variables:
108 mode:c++
109 c-file-style:"stroustrup"
110 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
111 indent-tabs-mode:nil
112 fill-column:99
113 End:
114 */
115 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :