[niepce] Make sure the ConfigDataBinder is initialised properly
- From: Hubert Figuière <hub src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [niepce] Make sure the ConfigDataBinder is initialised properly
- Date: Sun, 23 Jun 2013 21:14:49 +0000 (UTC)
commit 1f6808c1b1d9a4f98537e703f9e1362aa415287a
Author: Hubert Figuière <hub figuiere net>
Date: Sat Jun 22 12:09:22 2013 -0400
Make sure the ConfigDataBinder is initialised properly
Better catch exception when using config data. Exception raise
caused but improperly initialised data.
src/fwk/toolkit/configdatabinder.hpp | 105 +++++++++++++++++++---------------
src/niepce/ui/imageliststore.cpp | 12 ++++-
2 files changed, 69 insertions(+), 48 deletions(-)
---
diff --git a/src/fwk/toolkit/configdatabinder.hpp b/src/fwk/toolkit/configdatabinder.hpp
index 44d2547..021bb47 100644
--- a/src/fwk/toolkit/configdatabinder.hpp
+++ b/src/fwk/toolkit/configdatabinder.hpp
@@ -41,8 +41,8 @@ public:
typedef Glib::PropertyProxy_Base property_t;
ConfigDataBinderBase(const property_t & property,
- Configuration & config, const std::string & key);
-
+ Configuration & config, const std::string & key);
+
virtual void on_changed(void) = 0;
protected:
property_t m_property;
@@ -53,54 +53,56 @@ protected:
template <class T>
class ConfigDataBinder
- : public ConfigDataBinderBase
+ : public ConfigDataBinderBase
{
public:
- typedef Glib::PropertyProxy<T> property_t;
-
- ConfigDataBinder(const property_t & property,
- Configuration & config, const std::string & key)
- : ConfigDataBinderBase(property, config, key)
- {
- Glib::ustring value;
- value = m_config.getValue(m_config_key, "");
- if(!value.empty()) {
- try {
- static_cast<property_t&>(m_property).set_value(
- boost::lexical_cast<T>(value));
- }
- catch(const boost::bad_lexical_cast &)
- {
- ERR_OUT("exception converting %s", value.c_str());
- }
- }
- }
-
- virtual ~ConfigDataBinder()
- {
- try {
- m_config.setValue(m_config_key,
- boost::lexical_cast<std::string>(m_value));
- }
- catch(const boost::bad_lexical_cast &)
- {
- ERR_OUT("exception");
- }
- }
-
-
- virtual void on_changed(void)
- {
- try {
- m_value = static_cast<property_t&>(m_property).get_value();
- }
- catch(const std::exception &)
- {
- ERR_OUT("exception");
- }
- }
+ typedef Glib::PropertyProxy<T> property_t;
+
+ ConfigDataBinder(const property_t & property,
+ Configuration & config, const std::string & key)
+ : ConfigDataBinderBase(property, config, key)
+ {
+ Glib::ustring value;
+ value = m_config.getValue(m_config_key, "");
+ if(!value.empty()) {
+ try {
+ T real_value;
+ real_value = boost::lexical_cast<T>(value);
+ static_cast<property_t&>(m_property).set_value(real_value);
+ }
+ catch(const boost::bad_lexical_cast &)
+ {
+ ERR_OUT("exception converting %s", value.c_str());
+ }
+ }
+ m_value = static_cast<property_t&>(m_property).get_value();
+ }
+
+ virtual ~ConfigDataBinder()
+ {
+ try {
+ m_config.setValue(m_config_key,
+ boost::lexical_cast<std::string>(m_value));
+ }
+ catch(const boost::bad_lexical_cast &)
+ {
+ ERR_OUT("exception");
+ }
+ }
+
+
+ virtual void on_changed(void)
+ {
+ try {
+ m_value = static_cast<property_t&>(m_property).get_value();
+ }
+ catch(const std::exception &)
+ {
+ ERR_OUT("exception");
+ }
+ }
private:
- T m_value;
+ T m_value;
};
@@ -108,3 +110,12 @@ private:
#endif
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0))
+ indent-tabs-mode:nil
+ fill-column:80
+ End:
+*/
diff --git a/src/niepce/ui/imageliststore.cpp b/src/niepce/ui/imageliststore.cpp
index 3f7b415..a4641af 100644
--- a/src/niepce/ui/imageliststore.cpp
+++ b/src/niepce/ui/imageliststore.cpp
@@ -122,7 +122,17 @@ void ImageListStore::on_lib_notification(const eng::LibNotification &ln)
case eng::Library::NOTIFY_XMP_NEEDS_UPDATE:
{
fwk::Configuration & cfg = fwk::Application::app()->config();
- int write_xmp = boost::lexical_cast<int>(cfg.getValue("write_xmp_automatically", "0"));
+ int write_xmp = false;
+ Glib::ustring xmp_pref;
+ try {
+ xmp_pref = cfg.getValue("write_xmp_automatically", "0");
+ write_xmp = boost::lexical_cast<int>(xmp_pref);
+ }
+ catch(const std::exception & e)
+ {
+ ERR_OUT("couldn't cast %s: %s", xmp_pref.c_str(),
+ e.what());
+ }
getLibraryClient()->processXmpUpdateQueue(write_xmp);
break;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]