Code

Filters. Custom predefined filters update and new ABC filters.
[inkscape.git] / src / preferences.cpp
index 39a9e4d69aafe98f292926346439a49d51a3bcc1..3815d44c563eaf32d19a1af7a03e835a79ae079b 100644 (file)
@@ -11,6 +11,7 @@
  */
 
 #include <cstring>
+#include <sstream>
 #include <glibmm/fileutils.h>
 #include <glibmm/i18n.h>
 #include <glib.h>
@@ -446,6 +447,13 @@ void Preferences::setDouble(Glib::ustring const &pref_path, double value)
     _setRawValue(pref_path, buf);
 }
 
+void Preferences::setColor(Glib::ustring const &pref_path, guint32 value)
+{
+    gchar buf[16];
+    g_snprintf(buf, 16, "#%08x", value);
+    _setRawValue(pref_path, buf);
+}
+
 /**
  * @brief Set a string attribute of a preference
  * @param pref_path Path of the preference to modify
@@ -732,6 +740,20 @@ Glib::ustring Preferences::_extractString(Entry const &v)
     return Glib::ustring(static_cast<gchar const *>(v._value));
 }
 
+guint32 Preferences::_extractColor(Entry const &v)
+{
+    gchar const *s = static_cast<gchar const *>(v._value);
+    std::istringstream hr(s);
+    guint32 color;
+    if (s[0] == '#') {
+        hr.ignore(1);
+        hr >> std::hex >> color;
+    } else {
+        hr >> color;
+    }
+    return color;
+}
+
 SPCSSAttr *Preferences::_extractStyle(Entry const &v)
 {
     SPCSSAttr *style = sp_repr_css_attr_new();
@@ -806,4 +828,4 @@ Preferences *Preferences::_instance = NULL;
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :