[glom/gtkmm4v3: 3/21] Update GdaBinary/GdaBlob code for libgdamm-6.0.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/gtkmm4v3: 3/21] Update GdaBinary/GdaBlob code for libgdamm-6.0.
- Date: Tue, 14 Mar 2017 09:43:49 +0000 (UTC)
commit 78ec64c43847ba60d3673c3b4b6f2c45c1e857fc
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Dec 16 16:44:36 2016 +0100
Update GdaBinary/GdaBlob code for libgdamm-6.0.
glom/libglom/data_structure/field.cc | 24 +++++++++----
.../libglom/python_embed/pygdavalue_conversions.cc | 22 +++++++++---
glom/utility_widgets/dialog_image_load_progress.cc | 35 +++++++++++--------
glom/utility_widgets/dialog_image_load_progress.h | 5 ++-
glom/utility_widgets/dialog_image_save_progress.cc | 26 +++++++++------
glom/utility_widgets/dialog_image_save_progress.h | 2 +-
glom/utility_widgets/imageglom.cc | 32 +++++++++++-------
glom/utils_ui.cc | 11 ++++--
8 files changed, 99 insertions(+), 58 deletions(-)
---
diff --git a/glom/libglom/data_structure/field.cc b/glom/libglom/data_structure/field.cc
index 2ca038a..9f5a455 100644
--- a/glom/libglom/data_structure/field.cc
+++ b/glom/libglom/data_structure/field.cc
@@ -255,7 +255,9 @@ Glib::ustring Field::to_file_format(const Gnome::Gda::Value& value, glom_field_t
return Glib::ustring();
else
{
- auto base64 = g_base64_encode(gdabinary->data, gdabinary->binary_length);
+ const auto data = gda_binary_get_data(gdabinary);
+ const auto data_len = gda_binary_get_size(gdabinary);
+ auto base64 = g_base64_encode(static_cast<const guchar*>(data), data_len);
if(!base64)
return Glib::ustring();
else
@@ -268,18 +270,24 @@ Glib::ustring Field::to_file_format(const Gnome::Gda::Value& value, glom_field_t
{
const auto gdablob = gda_value_get_blob(value.gobj());
- if(!gdablob || !gdablob->op)
+ if(!gdablob)
return Glib::ustring();
else
{
- if(!gda_blob_op_read_all(gdablob->op, const_cast<GdaBlob*>(gdablob)))
+ const auto op = gda_blob_get_op(const_cast<GdaBlob*>(gdablob));
+ if (!op)
+ return Glib::ustring();
+
+ if(!gda_blob_op_read_all(op, const_cast<GdaBlob*>(gdablob)))
{
return Glib::ustring();
}
else
{
- const auto gdabinary = &(gdablob->data);
- auto base64 = g_base64_encode(gdabinary->data, gdabinary->binary_length);
+ const auto gdabinary = gda_blob_get_binary(const_cast<GdaBlob*>(gdablob));
+ const auto data = gda_binary_get_data(gdabinary);
+ const auto data_len = gda_binary_get_size(gdabinary);
+ auto base64 = g_base64_encode(static_cast<const guchar*>(data), data_len);
if(!base64)
return Glib::ustring();
else
@@ -367,10 +375,10 @@ Gnome::Gda::Value Field::from_file_format(const Glib::ustring& str, glom_field_t
} else {
//What we use now in new files:
- auto gdabinary = g_new(GdaBinary, 1);
+ auto gdabinary = gda_binary_new();
gsize len = 0;
- gdabinary->data = g_base64_decode(string_unescaped.c_str(), &len);
- gdabinary->binary_length = len;
+ const auto data = g_base64_decode(string_unescaped.c_str(), &len);
+ gda_binary_set_data(gdabinary, data, len);
Gnome::Gda::Value value;
value_reinit(value.gobj(), GDA_TYPE_BINARY);
diff --git a/glom/libglom/python_embed/pygdavalue_conversions.cc
b/glom/libglom/python_embed/pygdavalue_conversions.cc
index f39766b..2e98d96 100644
--- a/glom/libglom/python_embed/pygdavalue_conversions.cc
+++ b/glom/libglom/python_embed/pygdavalue_conversions.cc
@@ -201,15 +201,25 @@ boost::python::object glom_pygda_value_as_boost_pyobject(const Glib::ValueBase&
ret = boost::python::object(g_value_get_uint64(boxed));
} else if(value_type == GDA_TYPE_BINARY) {
const auto gdabinary = gda_value_get_binary(boxed);
- if(gdabinary)
- ret = boost::python::object((const char*)gdabinary->data); /* TODO: Use the size. TODO: Check for
null GdaBinary. */
+ if(gdabinary) {
+ const auto data = gda_binary_get_data(gdabinary);
+ ret = boost::python::object((const char*)data); /* TODO: Use the size. TODO: Check for null
GdaBinary. */
+ }
} else if(value_type == GDA_TYPE_BLOB) {
const auto gdablob = gda_value_get_blob (boxed);
- if(gdablob && gdablob->op)
- {
- if(gda_blob_op_read_all(gdablob->op, const_cast<GdaBlob*>(gdablob)))
+ if(gdablob) {
+ const auto op = gda_blob_get_op(const_cast<GdaBlob*>(gdablob));
+ if (op)
{
- ret = boost::python::object((const char*)gdablob->data.data); /* TODO: Use the size. TODO: Check
for null GdaBinary. */
+ if(gda_blob_op_read_all(op, const_cast<GdaBlob*>(gdablob)))
+ {
+ const auto gdabinary = gda_blob_get_binary(const_cast<GdaBlob*>(gdablob));
+ if (gdabinary)
+ {
+ const auto data = gda_binary_get_data(gdabinary);
+ ret = boost::python::object((const char*)data); /* TODO: Use the size. TODO: Check for null
GdaBinary. */
+ }
+ }
}
}
} else if(value_type == G_TYPE_BOOLEAN) {
diff --git a/glom/utility_widgets/dialog_image_load_progress.cc
b/glom/utility_widgets/dialog_image_load_progress.cc
index ea7747f..160cdea 100644
--- a/glom/utility_widgets/dialog_image_load_progress.cc
+++ b/glom/utility_widgets/dialog_image_load_progress.cc
@@ -40,7 +40,8 @@ const char* DialogImageLoadProgress::glade_id("dialog_image_load_progress");
const bool DialogImageLoadProgress::glade_developer(false);
DialogImageLoadProgress::DialogImageLoadProgress(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>&
builder)
-: Gtk::Dialog(cobject)
+: Gtk::Dialog(cobject),
+ m_data(nullptr, &gda_binary_free)
{
builder->get_widget("progress_bar", m_progress_bar);
@@ -53,7 +54,7 @@ DialogImageLoadProgress::DialogImageLoadProgress(BaseObjectType* cobject, const
DialogImageLoadProgress::~DialogImageLoadProgress()
{
if(m_data)
- g_free(m_data->data);
+ gda_binary_free(m_data.get());
// TODO: Cancel outstanding async operations in destructor?
}
@@ -63,9 +64,7 @@ void DialogImageLoadProgress::load(const Glib::ustring& uri)
// Can only load one file with data
g_assert(!m_data.get());
- m_data = std::make_unique<GdaBinary>();
- m_data->data = nullptr;
- m_data->binary_length = 0;
+ m_data = UniquePtr(gda_binary_new(), &gda_binary_free);
m_file = Gio::File::create_for_uri(uri);
m_progress_bar->set_text(Glib::ustring::compose("Loading %1...", m_file->get_parse_name()));
@@ -100,15 +99,17 @@ void DialogImageLoadProgress::on_query_info(const Glib::RefPtr<Gio::AsyncResult>
try
{
auto info = m_stream->query_info_finish(result);
- m_data->binary_length = info->get_size();
// We need to use the glib allocator here:
- m_data->data = static_cast<guchar*>(g_try_malloc(m_data->binary_length));
- if(!m_data->data)
+ const auto data_len = info->get_size();
+ const auto data = static_cast<guchar*>(g_try_malloc(data_len));
+ gda_binary_set_data(m_data.get(), data, data_len);
+ if(!data)
error(_("Not enough memory available to load the image"));
// Read the first chunk from the file
- m_stream->read_async(m_data->data, std::min<gsize>(CHUNK_SIZE, m_data->binary_length),
sigc::bind(sigc::mem_fun(*this, &DialogImageLoadProgress::on_stream_read), 0));
+ m_stream->read_async(data, std::min<gsize>(CHUNK_SIZE, data_len),
+ sigc::bind(sigc::mem_fun(*this, &DialogImageLoadProgress::on_stream_read), 0));
}
catch(const Glib::Error& ex)
{
@@ -124,13 +125,14 @@ void DialogImageLoadProgress::on_stream_read(const Glib::RefPtr<Gio::AsyncResult
g_assert(size >= 0); // Would have thrown an exception otherwise
// Cannot read more data than there is available in the file:
- g_assert( static_cast<gssize>(offset + size) <= static_cast<gssize>(m_data->binary_length));
+ const auto data_len = gda_binary_get_size(m_data.get());
+ g_assert( static_cast<gssize>(offset + size) <= static_cast<gssize>(data_len));
// Set progress
- m_progress_bar->set_fraction(static_cast<double>(offset + size) / m_data->binary_length);
+ m_progress_bar->set_fraction(static_cast<double>(offset + size) / data_len);
// Read next chunk, if any
- if( static_cast<gssize>(offset + size) < static_cast<gssize>(m_data->binary_length) )
+ if( static_cast<gssize>(offset + size) < static_cast<gssize>(data_len) )
{
// Even if choose a priority lower than GDK_PRIORITY_REDRAW + 10 for the
// read_async we don't see the progressbar progressing while the image
@@ -150,9 +152,12 @@ void DialogImageLoadProgress::on_stream_read(const Glib::RefPtr<Gio::AsyncResult
void DialogImageLoadProgress::on_read_next(unsigned int at)
{
- g_assert(at < static_cast<gsize>(m_data->binary_length));
+ const auto data_len = gda_binary_get_size(m_data.get());
+ g_assert(at < static_cast<gsize>(data_len));
- m_stream->read_async(m_data->data + at, std::min<gsize>(CHUNK_SIZE, m_data->binary_length - at),
sigc::bind(sigc::mem_fun(*this, &DialogImageLoadProgress::on_stream_read), at));
+ const auto data = gda_binary_get_data(m_data.get());
+ m_stream->read_async(static_cast<guchar*>(data) + at, std::min<gsize>(CHUNK_SIZE, data_len - at),
+ sigc::bind(sigc::mem_fun(*this, &DialogImageLoadProgress::on_stream_read), at));
}
void DialogImageLoadProgress::error(const Glib::ustring& error_message)
@@ -165,7 +170,7 @@ void DialogImageLoadProgress::error(const Glib::ustring& error_message)
response(Gtk::RESPONSE_REJECT);
}
-std::unique_ptr<GdaBinary> DialogImageLoadProgress::get_image_data()
+DialogImageLoadProgress::UniquePtr DialogImageLoadProgress::get_image_data()
{
//This will not be as if it was reset.
//Not every std::move() does that, but std::move() with std::unique_ptr<> does.
diff --git a/glom/utility_widgets/dialog_image_load_progress.h
b/glom/utility_widgets/dialog_image_load_progress.h
index 989a6d8..6083a5d 100644
--- a/glom/utility_widgets/dialog_image_load_progress.h
+++ b/glom/utility_widgets/dialog_image_load_progress.h
@@ -43,7 +43,8 @@ public:
void load(const Glib::ustring& uri);
- std::unique_ptr<GdaBinary> get_image_data();
+ using UniquePtr = std::unique_ptr<GdaBinary, void(*)(GdaBinary*)>;
+ UniquePtr get_image_data();
private:
void error(const Glib::ustring& error_message);
@@ -53,7 +54,7 @@ private:
void on_stream_read(const Glib::RefPtr<Gio::AsyncResult>& result, unsigned int offset);
void on_read_next(unsigned int at);
- std::unique_ptr<GdaBinary> m_data;
+ UniquePtr m_data;
Gtk::ProgressBar* m_progress_bar;
Glib::RefPtr<Gio::File> m_file;
diff --git a/glom/utility_widgets/dialog_image_save_progress.cc
b/glom/utility_widgets/dialog_image_save_progress.cc
index b4a5a70..9a8847a 100644
--- a/glom/utility_widgets/dialog_image_save_progress.cc
+++ b/glom/utility_widgets/dialog_image_save_progress.cc
@@ -55,10 +55,12 @@ void DialogImageSaveProgress::save(const Glib::ustring& uri)
{
g_assert(m_data);
- if(m_data->data == nullptr)
+ const auto data = gda_binary_get_data(const_cast<GdaBinary*>(m_data));
+ if(!data)
return;
- if(m_data->binary_length == 0)
+ const auto data_len = gda_binary_get_size(const_cast<GdaBinary*>(m_data));
+ if(data_len == 0)
return;
m_file = Gio::File::create_for_uri(uri);
@@ -89,8 +91,8 @@ void DialogImageSaveProgress::save(const Glib::ustring& uri)
//Write the data to the output uri
try
{
- m_stream->write_async(m_data->data,
- std::min<gsize>(CHUNK_SIZE, m_data->binary_length),
+ m_stream->write_async(data,
+ std::min<gsize>(CHUNK_SIZE, data_len),
sigc::bind(sigc::mem_fun(*this, &DialogImageSaveProgress::on_stream_write), 0));
}
catch(const Gio::Error& ex)
@@ -109,10 +111,11 @@ void DialogImageSaveProgress::on_stream_write(const Glib::RefPtr<Gio::AsyncResul
g_assert(size >= 0); // Would have thrown an exception otherwise
// Set progress
- m_progress_bar->set_fraction(static_cast<double>(offset + size) / m_data->binary_length);
+ const auto data_len = gda_binary_get_size(const_cast<GdaBinary*>(m_data));
+ m_progress_bar->set_fraction(static_cast<double>(offset + size) / data_len);
// Write next chunk, if any
- if( static_cast<gssize>(offset + size) < static_cast<gssize>(m_data->binary_length))
+ if( static_cast<gssize>(offset + size) < static_cast<gssize>(data_len))
// Even if choose a priority lower than GDK_PRIORITY_REDRAW + 10 for the
// write_async we don't see the progressbar progressing while the image
// is loading. Therefore we put an idle inbetween.
@@ -140,14 +143,17 @@ void DialogImageSaveProgress::error(const Glib::ustring& error_message)
void DialogImageSaveProgress::on_write_next(unsigned int at)
{
- g_assert(at < static_cast<gsize>(m_data->binary_length));
+ const auto data_len = gda_binary_get_size(const_cast<GdaBinary*>(m_data));
+ g_assert(at < static_cast<gsize>(data_len));
- m_stream->write_async(m_data->data + at, std::min<gsize>(CHUNK_SIZE, m_data->binary_length - at),
sigc::bind(sigc::mem_fun(*this, &DialogImageSaveProgress::on_stream_write), at));
+ const auto data = gda_binary_get_data(const_cast<GdaBinary*>(m_data));
+ m_stream->write_async(static_cast<const guchar*>(data) + at, std::min<gsize>(CHUNK_SIZE, data_len - at),
+ sigc::bind(sigc::mem_fun(*this, &DialogImageSaveProgress::on_stream_write), at));
}
-void DialogImageSaveProgress::set_image_data(const GdaBinary& data)
+void DialogImageSaveProgress::set_image_data(const GdaBinary* data)
{
- m_data = &data;
+ m_data = data;
}
} // namespace Glom
diff --git a/glom/utility_widgets/dialog_image_save_progress.h
b/glom/utility_widgets/dialog_image_save_progress.h
index f3d5d24..1d552f4 100644
--- a/glom/utility_widgets/dialog_image_save_progress.h
+++ b/glom/utility_widgets/dialog_image_save_progress.h
@@ -41,7 +41,7 @@ public:
void save(const Glib::ustring& uri);
- void set_image_data(const GdaBinary& data);
+ void set_image_data(const GdaBinary* data);
private:
void on_stream_write(const Glib::RefPtr<Gio::AsyncResult>& result, unsigned int offset);
diff --git a/glom/utility_widgets/imageglom.cc b/glom/utility_widgets/imageglom.cc
index fc994f1..d1074de 100644
--- a/glom/utility_widgets/imageglom.cc
+++ b/glom/utility_widgets/imageglom.cc
@@ -283,8 +283,10 @@ const GdaBinary* ImageGlom::get_binary() const
else if(m_original_data.get_value_type() == GDA_TYPE_BLOB)
{
const auto gda_blob = gda_value_get_blob(m_original_data.gobj());
- if(gda_blob && gda_blob_op_read_all(gda_blob->op, const_cast<GdaBlob*>(gda_blob)))
- gda_binary = &(gda_blob->data);
+ const auto op = gda_blob ? gda_blob_get_op(const_cast<GdaBlob*>(gda_blob)) : nullptr;
+ if(gda_blob && op && gda_blob_op_read_all(op, const_cast<GdaBlob*>(gda_blob))) {
+ gda_binary = gda_blob_get_binary(const_cast<GdaBlob*>(gda_blob));
+ }
}
return gda_binary;
@@ -297,12 +299,14 @@ Glib::ustring ImageGlom::get_mime_type() const
if(!gda_binary)
return Glib::ustring();
- if(!gda_binary->data)
+ const auto data = gda_binary_get_data(const_cast<GdaBinary*>(gda_binary));
+ if(!data)
return Glib::ustring();
bool uncertain = false;
+ const auto datalen = gda_binary_get_size(const_cast<GdaBinary*>(gda_binary));
const auto result = Gio::content_type_guess(std::string(),
- gda_binary->data, gda_binary->binary_length,
+ static_cast<const guchar*>(data), datalen,
uncertain);
//std::cout << G_STRFUNC << ": mime_type=" << result << ", uncertain=" << uncertain << std::endl;
@@ -720,7 +724,8 @@ bool ImageGlom::save_file_sync(const Glib::ustring& uri)
return false;
}
- if(!gda_binary->data)
+ const auto data = gda_binary_get_data(const_cast<GdaBinary*>(gda_binary));
+ if(!data)
{
std::cerr << G_STRFUNC << ": GdaBinary::data is null\n";
return false;
@@ -729,7 +734,8 @@ bool ImageGlom::save_file_sync(const Glib::ustring& uri)
try
{
const auto filepath = Glib::filename_from_uri(uri);
- Glib::file_set_contents(filepath, (const char*)gda_binary->data, gda_binary->binary_length);
+ const auto datalen = gda_binary_get_size(const_cast<GdaBinary*>(gda_binary));
+ Glib::file_set_contents(filepath, static_cast<const char*>(data), datalen);
}
catch(const Glib::Error& ex)
{
@@ -758,7 +764,7 @@ bool ImageGlom::save_file(const Glib::ustring& uri)
if(!gda_binary)
return false;
- dialog_save->set_image_data(*gda_binary);
+ dialog_save->set_image_data(gda_binary);
dialog_save->save(uri);
dialog_save->run();
@@ -803,16 +809,14 @@ void ImageGlom::on_menupopup_activate_select_file()
if(dialog_progress->run() == Gtk::RESPONSE_ACCEPT)
{
- GdaBinary* bin = g_new(GdaBinary, 1);
+ // This takes ownership of the GdaBinary from the dialog:
auto image_data = dialog_progress->get_image_data();
- bin->data = image_data->data;
- bin->binary_length = image_data->binary_length;
clear_original_data();
g_value_unset(m_original_data.gobj());
g_value_init(m_original_data.gobj(), GDA_TYPE_BINARY);
- gda_value_take_binary(m_original_data.gobj(), bin);
+ gda_value_take_binary(m_original_data.gobj(), image_data.get());
show_image_data();
signal_edited().emit();
@@ -846,10 +850,12 @@ void ImageGlom::on_clipboard_get(Gtk::SelectionData& selection_data, guint /* in
if(!gda_binary)
return;
- if(!gda_binary->data)
+ const auto data = gda_binary_get_data(const_cast<GdaBinary*>(gda_binary));
+ if(!data)
return;
- selection_data.set(mime_type, 8, gda_binary->data, gda_binary->binary_length);
+ const auto datalen = gda_binary_get_size(const_cast<GdaBinary*>(gda_binary));
+ selection_data.set(mime_type, 8, static_cast<guchar*>(data), datalen);
// This set() override uses an 8-bit text format for the data.
//selection_data.set_pixbuf(m_pixbuf_clipboard);
diff --git a/glom/utils_ui.cc b/glom/utils_ui.cc
index de179d8..e0ce9d8 100644
--- a/glom/utils_ui.cc
+++ b/glom/utils_ui.cc
@@ -234,10 +234,15 @@ Glib::RefPtr<Gdk::Pixbuf> UiUtils::get_pixbuf_for_gda_value(const Gnome::Gda::Va
if(value.get_value_type() == GDA_TYPE_BLOB)
{
const auto blob = value.get_blob();
- if(gda_blob_op_read_all(blob->op, const_cast<GdaBlob*>(blob)))
+ const auto op = blob ? gda_blob_get_op(const_cast<GdaBlob*>(blob)) : nullptr;
+ if(op && gda_blob_op_read_all(op, const_cast<GdaBlob*>(blob)))
{
- buffer_binary_length = blob->data.binary_length;
- buffer_binary = blob->data.data;
+ const auto binary = gda_blob_get_binary(const_cast<GdaBlob*>(blob));
+ if (binary)
+ {
+ buffer_binary_length = gda_binary_get_size(binary);
+ buffer_binary = gda_binary_get_data(binary);
+ }
}
else
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]