Commit 0c430bb9 authored by Murray Cumming's avatar Murray Cumming Committed by Murray Cumming
Browse files

get_text_for_gda_value(): Return escaped text for images, instead of using

2007-12-20  Murray Cumming  <murrayc@murrayc.com>

        * glom/libglom/data_structure/glomconversions.cc: get_text_for_gda_value():
        Return escaped text for images, instead of using to_string(). This fixes the 
        loading of images from the document, so they are not lost when closing the 
        document.

svn path=/trunk/; revision=1374
parent 2e3176a0
2007-12-20 Murray Cumming <murrayc@murrayc.com>
* glom/libglom/data_structure/glomconversions.cc: get_text_for_gda_value():
Return escaped text for images, instead of using to_string(). This fixes the
loading of images from the document, so they are not lost when closing the
document.
2007-12-20 Murray Cumming <murrayc@murrayc.com>
* glom/utility_widgets/canvas/canvas_image_movable.cc:
......
......@@ -208,6 +208,7 @@ Glom_PQescapeString(char *to, const char *from, size_t length)
} //anonymous
/// Escape text, including text that is the result of get_escaped_binary_data().
static std::string glom_escape_text(const std::string& src)
{
if(src.empty())
......
......@@ -275,8 +275,14 @@ Glib::ustring Conversions::get_text_for_gda_value(Field::glom_field_type glom_ty
}
else if (glom_type == Field::TYPE_IMAGE)
{
std::cerr << "Conversions::get_text_for_gda_value(): Unexpected image field type" << std::endl;
return value.to_string();
//Return the binary-as-escaped-text format, suitable for use in the document.
std::string result;
long buffer_length;
const guchar* buffer = value.get_binary(buffer_length);
if(buffer && buffer_length > 0)
result = Conversions::get_escaped_binary_data((guint8*)buffer, buffer_length);
return result;
}
else
{
......@@ -409,12 +415,12 @@ Gnome::Gda::Value Conversions::parse_value(Field::glom_field_type glom_type, con
}
else if(glom_type == Field::TYPE_IMAGE)
{
//We assume that the text is the same (escaped text) format that we use in the document when saving examples.
//We assume that the text is the same (escaped text) format that we use in the document when saving images:
//(The SQL format).
Gnome::Gda::Value result;
size_t buffer_binary_length = 0;
guchar* buffer_binary = Glom_PQunescapeBytea((const guchar*)text.c_str() /* must be null-terminated */, &buffer_binary_length); //freed by us later.
guchar* buffer_binary = Glom_PQunescapeBytea((const guchar*)text.c_str() /* must be null-terminated */, &buffer_binary_length); //freed by us later.
if(buffer_binary)
{
result.set(buffer_binary, buffer_binary_length);
......@@ -1004,7 +1010,7 @@ Glib::RefPtr<Gdk::Pixbuf> Conversions::get_pixbuf_for_gda_value(const Gnome::Gda
{
const Glib::Exception& ex = *error.get();
#endif
g_warning("ImageGlom::set_value(): PixbufLoader::write() failed: %s", ex.what().c_str());
g_warning("Conversions::get_pixbuf_for_gda_value(): PixbufLoader::write() failed: %s", ex.what().c_str());
}
}
......
......@@ -59,6 +59,7 @@ namespace Conversions
Gnome::Gda::Value get_example_value(Field::glom_field_type field_type);
///Get a string representing binary data, for SQL
Glib::ustring get_escaped_binary_data(guint8* buffer, size_t buffer_size);
Gnome::Gda::Value convert_value(const Gnome::Gda::Value& value, Field::glom_field_type target_glom_type);
......
......@@ -251,9 +251,9 @@ Gnome::Gda::Value ImageGlom::get_value() const
buffer = 0;
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
catch(const Glib::Exception& /* ex */)
catch(const Glib::Exception& ex)
{
std::cerr << "ImageGlom::get_value(): " << ex.what() << std::endl;
}
#endif // GLIBMM_EXCEPTIONS_ENABLED
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment