Fix Bug: Saved settings should be locale independent - ID: 3111032
[synfig.git] / synfig-studio / src / synfigapp / inputdevice.cpp
index d9df69d..aea4e62 100644 (file)
@@ -60,56 +60,64 @@ public:
 
        virtual bool get_value(const synfig::String& key, synfig::String& value)const
        {
-               if(key=="state")
+               try
                {
-                       value=input_device->get_state();
-                       return true;
-               }
-               if(key=="bline_width")
-               {
-                       value=strprintf("%s",input_device->get_bline_width().get_string().c_str());
-                       return true;
-               }
-               if(key=="opacity")
-               {
-                       value=strprintf("%f",(float)input_device->get_opacity());
-                       return true;
-               }
-               if(key=="blend_method")
-               {
-                       value=strprintf("%i",(int)input_device->get_blend_method());
-                       return true;
-               }
-               if(key=="outline_color")
-               {
-                       Color c(input_device->get_outline_color());
-                       value=strprintf("%f %f %f %f",(float)c.get_r(),(float)c.get_g(),(float)c.get_b(),(float)c.get_a());
+                       SETTINGS_LOCALE_SAFE_AND_BACKUP
+                       if(key=="state")
+                       {
+                               value=input_device->get_state();
+                               return true;
+                       }
+                       if(key=="bline_width")
+                       {
+                               value=strprintf("%s",input_device->get_bline_width().get_string().c_str());
+                               return true;
+                       }
+                       if(key=="opacity")
+                       {
+                               value=strprintf("%f",(float)input_device->get_opacity());
+                               return true;
+                       }
+                       if(key=="blend_method")
+                       {
+                               value=strprintf("%i",(int)input_device->get_blend_method());
+                               return true;
+                       }
+                       if(key=="outline_color")
+                       {
+                               Color c(input_device->get_outline_color());
+                               value=strprintf("%f %f %f %f",(float)c.get_r(),(float)c.get_g(),(float)c.get_b(),(float)c.get_a());
 
-                       return true;
-               }
-               if(key=="fill_color")
-               {
-                       Color c(input_device->get_fill_color());
-                       value=strprintf("%f %f %f %f",(float)c.get_r(),(float)c.get_g(),(float)c.get_b(),(float)c.get_a());
+                               return true;
+                       }
+                       if(key=="fill_color")
+                       {
+                               Color c(input_device->get_fill_color());
+                               value=strprintf("%f %f %f %f",(float)c.get_r(),(float)c.get_g(),(float)c.get_b(),(float)c.get_a());
 
-                       return true;
-               }
-               if(key=="mode")
-               {
-                       get_mode_value(value);
-                       return true;
-               }
-               if(key=="axes")
-               {
-                       get_axes_value(value);
-                       return true;
+                               return true;
+                       }
+                       if(key=="mode")
+                       {
+                               get_mode_value(value);
+                               return true;
+                       }
+                       if(key=="axes")
+                       {
+                               get_axes_value(value);
+                               return true;
+                       }
+                       if(key=="keys")
+                       {
+                               get_keys_value(value);
+                               return true;
+                       }
+                       SETTINGS_LOCALE_RESTORE
                }
-               if(key=="keys")
+               catch(...)
                {
-                       get_keys_value(value);
-                       return true;
+                       synfig::warning("DeviceSettings: Caught exception when attempting to get value.");
                }
-
                return Settings::get_value(key, value);
        }
 
@@ -143,58 +151,66 @@ public:
 
        virtual bool set_value(const synfig::String& key,const synfig::String& value)
        {
-               if(key=="state")
+               try
                {
-                       input_device->set_state(value);
-                       return true;
-               }
-               if(key=="bline_width")
-               {
-                       input_device->set_bline_width(synfig::Distance(value));
-                       return true;
-               }
-               if(key=="opacity")
-               {
-                       input_device->set_opacity(atof(value.c_str()));
-                       return true;
-               }
-               if(key=="blend_method")
-               {
-                       input_device->set_blend_method(Color::BlendMethod(atoi(value.c_str())));
-                       return true;
-               }
-               if(key=="outline_color")
-               {
-                       float r=0,g=0,b=0,a=1;
-                       if(!strscanf(value,"%f %f %f %f",&r,&g,&b,&a))
-                               return false;
-                       input_device->set_outline_color(synfig::Color(r,g,b,a));
-                       return true;
-               }
-               if(key=="fill_color")
-               {
-                       float r=0,g=0,b=0,a=1;
-                       if(!strscanf(value,"%f %f %f %f",&r,&g,&b,&a))
-                               return false;
-                       input_device->set_fill_color(synfig::Color(r,g,b,a));
-                       return true;
-               }
-               if(key=="mode")
-               {
-                       set_mode_value(value);
-                       return true;
-               }
-               if(key=="axes")
-               {
-                       set_axes_value(value);
-                       return true;
+                       SETTINGS_LOCALE_SAFE_AND_BACKUP
+                       if(key=="state")
+                       {
+                               input_device->set_state(value);
+                               return true;
+                       }
+                       if(key=="bline_width")
+                       {
+                               input_device->set_bline_width(synfig::Distance(value));
+                               return true;
+                       }
+                       if(key=="opacity")
+                       {
+                               input_device->set_opacity(atof(value.c_str()));
+                               return true;
+                       }
+                       if(key=="blend_method")
+                       {
+                               input_device->set_blend_method(Color::BlendMethod(atoi(value.c_str())));
+                               return true;
+                       }
+                       if(key=="outline_color")
+                       {
+                               float r=0,g=0,b=0,a=1;
+                               if(!strscanf(value,"%f %f %f %f",&r,&g,&b,&a))
+                                       return false;
+                               input_device->set_outline_color(synfig::Color(r,g,b,a));
+                               return true;
+                       }
+                       if(key=="fill_color")
+                       {
+                               float r=0,g=0,b=0,a=1;
+                               if(!strscanf(value,"%f %f %f %f",&r,&g,&b,&a))
+                                       return false;
+                               input_device->set_fill_color(synfig::Color(r,g,b,a));
+                               return true;
+                       }
+                       if(key=="mode")
+                       {
+                               set_mode_value(value);
+                               return true;
+                       }
+                       if(key=="axes")
+                       {
+                               set_axes_value(value);
+                               return true;
+                       }
+                       if(key=="keys")
+                       {
+                               set_keys_value(value);
+                               return true;
+                       }
+                       SETTINGS_LOCALE_RESTORE
                }
-               if(key=="keys")
+               catch(...)
                {
-                       set_keys_value(value);
-                       return true;
+                       synfig::warning("DeviceSettings: Caught exception when attempting to set value.");
                }
-
                return Settings::set_value(key, value);
        }