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 _writable(false)
32 {
33 }
35 Preferences::~Preferences()
36 {
37 }
39 void Preferences::save() {}
41 // getter methods
43 Preferences::Entry const Preferences::getEntry(Glib::ustring const &pref_path)
44 {
45 return _prefs[pref_path];
46 }
47 void Preferences::setBool(Glib::ustring const &pref_path, bool value)
48 {
49 _prefs[pref_path] = _create_pref_value(pref_path, (void const*) (value ? "1" : "0"));
50 }
51 void Preferences::setInt(Glib::ustring const &pref_path, int value)
52 {
53 gchar *intstr = (gchar*) g_malloc(32);
54 g_snprintf(intstr, 32, "%d", value);
55 _prefs[pref_path] = _create_pref_value(pref_path, (void const*) intstr);
56 }
57 void Preferences::setDouble(Glib::ustring const &pref_path, double value)
58 {
59 gchar *buf = (gchar*) g_malloc(G_ASCII_DTOSTR_BUF_SIZE);
60 g_ascii_dtostr(buf, G_ASCII_DTOSTR_BUF_SIZE, value);
61 _prefs[pref_path] = _create_pref_value(pref_path, (void const*) buf);
62 }
63 void Preferences::setString(Glib::ustring const &pref_path, Glib::ustring const &value)
64 {
65 _prefs[pref_path] = _create_pref_value(pref_path, (void const*) g_strdup(value.data()));
66 }
68 bool Preferences::_extractBool(Entry const &v)
69 {
70 gchar const *s = static_cast<gchar const *>(v._value);
71 if ( !s[0] || !strcmp(s, "0") || !strcmp(s, "false") ) return false;
72 return true;
73 }
74 int Preferences::_extractInt(Entry const &v)
75 {
76 gchar const *s = static_cast<gchar const *>(v._value);
77 if ( !strcmp(s, "true") ) return true;
78 if ( !strcmp(s, "false") ) return false;
79 return atoi(s);
80 }
81 double Preferences::_extractDouble(Entry const &v)
82 {
83 gchar const *s = static_cast<gchar const *>(v._value);
84 return g_ascii_strtod(s, NULL);
85 }
87 Glib::ustring Preferences::_extractString(Entry const &v)
88 {
89 return Glib::ustring(static_cast<gchar const *>(v._value));
90 }
91 Preferences::Entry const Preferences::_create_pref_value(Glib::ustring const &path, void const *ptr)
92 {
93 return Entry(path, ptr);
94 }
96 Preferences *Preferences::_instance = NULL;
99 } // namespace Inkscape
102 /*
103 Local Variables:
104 mode:c++
105 c-file-style:"stroustrup"
106 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
107 indent-tabs-mode:nil
108 fill-column:99
109 End:
110 */
111 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :