Commit b9245218 authored by Murray Cumming's avatar Murray Cumming Committed by Murray Cumming
Browse files

Comment out the debug query output on stdout, because it slows us down

2005-07-15  Murray Cumming  <murrayc@murrayc.com>

        * glom/base_db.cc: Comment out the debug query output on
        stdout, because it slows us down when we use lots of image data.
        * glom/data_structure/glomconversions.cc: Tried to use
        PQescapeBytea() instead of my custom (slow) encoding code, without
        success, so left that code commented-out.
        * glom/utility_widgets/imageglom.cc:
        * glom/utility_widgets/imageglom.h: Implemented copy/paste.
parent 363e769f
2005-07-15 Murray Cumming <murrayc@murrayc.com>
* glom/base_db.cc: Comment out the debug query output on
stdout, because it slows us down when we use lots of image data.
* glom/data_structure/glomconversions.cc: Tried to use
PQescapeBytea() instead of my custom (slow) encoding code, without
success, so left that code commented-out.
* glom/utility_widgets/imageglom.cc:
* glom/utility_widgets/imageglom.h: Implemented copy/paste.
2005-07-14 Murray Cumming <murrayc@murrayc.com>
* glom/mode_data/box_data_details.cc:on_flowtable_field_edited():
......
......@@ -136,7 +136,17 @@ Glib::RefPtr<Gnome::Gda::DataModel> Base_DB::Query_execute(const Glib::ustring&
{
Glib::RefPtr<Gnome::Gda::Connection> gda_connection = sharedconnection->get_gda_connection();
std::cout << "Query_execute(): " << strQuery << std::endl;
/*
try
{
std::cout << "Debug: Query_execute(): " << strQuery << std::endl;
}
catch(const Glib::Exception& ex)
{
std::cout << "Debug: query string could not be converted to std::cout: " << ex.what() << std::endl;
}
*/
result = gda_connection->execute_single_command(strQuery);
if(!result)
{
......
......@@ -607,58 +607,73 @@ Gnome::Gda::Value GlomConversions::get_example_value(Field::glom_field_type fiel
}
Glib::ustring GlomConversions::get_escaped_binary_data(guint8* buffer, size_t buffer_size)
unsigned char *
Glom_PQescapeBytea(const unsigned char *bintext, size_t binlen, size_t *bytealen)
{
//g_warning("GlomConversions::get_escaped_binary_data: debug: buffer ");
//for(int i = 0; i < 10; ++i)
// g_warning("%02X (%c), ", (guint8)buffer[i], buffer[i]);
//TODO: Performance: Preallocate a string of the appropriate size.
//Use an output parameter instead of copying it during return.
Glib::ustring result;
if(buffer && buffer_size)
const unsigned char *vp;
unsigned char *rp;
unsigned char *result;
size_t i;
size_t len;
/*
* empty string has 1 char ('\0')
*/
len = 1;
vp = bintext;
for (i = binlen; i > 0; i--, vp++)
{
guint8* buffer_end = buffer + buffer_size;
char byte_as_octal[4]; //3 digits, and a null terminator
for(guint8* pos = buffer; pos < buffer_end; ++pos)
{
sprintf(byte_as_octal, "%03o", *pos); //Format as octal with 3 digits.
byte_as_octal[3] = 0;
// g_warning("byte=%d, as_hex=%s", *pos, byte_as_octal);
if (*vp < 0x20 || *vp > 0x7e)
len += 5; /* '5' is for '\\ooo' */
else if (*vp == '\'')
len += 2;
else if (*vp == '\\')
len += 4;
else
len++;
}
result += Glib::ustring("\\\\") + byte_as_octal;
rp = result = (unsigned char *) malloc(len);
if (rp == NULL)
return NULL;
vp = bintext;
*bytealen = len;
for (i = binlen; i > 0; i--, vp++)
{
if (*vp < 0x20 || *vp > 0x7e)
{
(void) sprintf((char*)rp, "\\\\%03o", *vp);
rp += 5;
}
else if (*vp == '\'')
{
rp[0] = '\\';
rp[1] = '\'';
rp += 2;
}
else if (*vp == '\\')
{
rp[0] = '\\';
rp[1] = '\\';
rp[2] = '\\';
rp[3] = '\\';
rp += 4;
}
else
*rp++ = *vp;
}
*rp = '\0';
return result;
}
#define ISFIRSTOCTDIGIT(CH) ((CH) >= '0' && (CH) <= '3')
#define ISOCTDIGIT(CH) ((CH) >= '0' && (CH) <= '7')
#define OCTVAL(CH) ((CH) - '0')
Gnome::Gda::Value GlomConversions::parse_escaped_binary_data(const Glib::ustring& escaped_data)
{
//Hopefully we don't need to use this because Gda does it for us when we read a part of a "SELECT" result into a Gnome::Value.
//TODO: Performance
Gnome::Gda::Value result;
size_t buffer_binary_length = 0;
guchar* buffer_binary = Glom_PQunescapeBytea((guchar*)escaped_data.c_str(), &buffer_binary_length);
if(buffer_binary)
{
result.set(buffer_binary, buffer_binary_length);
free(buffer_binary);
}
return result;
}
unsigned char *
Glom_PQunescapeBytea(const unsigned char *strtext, size_t *retbuflen)
{
......@@ -737,5 +752,65 @@ Glom_PQunescapeBytea(const unsigned char *strtext, size_t *retbuflen)
return tmpbuf;
}
Glib::ustring GlomConversions::get_escaped_binary_data(guint8* buffer, size_t buffer_size)
{
//g_warning("GlomConversions::get_escaped_binary_data: debug: buffer ");
//for(int i = 0; i < 10; ++i)
// g_warning("%02X (%c), ", (guint8)buffer[i], buffer[i]);
//TODO: Performance: Preallocate a string of the appropriate size.
//Use an output parameter instead of copying it during return.
Glib::ustring result;
/* This should be much faster, and more correct, but it gives an error - "unterminated quoted string at or near: "
size_t escaped_length = 0;
guchar* escaped = Glom_PQescapeBytea(buffer, buffer_size, &escaped_length);
if(escaped && escaped_length)
{
result = std::string((char*)escaped, escaped_length);
free(escaped);
}
*/
if(buffer && buffer_size)
{
guint8* buffer_end = buffer + buffer_size;
char byte_as_octal[4]; //3 digits, and a null terminator
for(guint8* pos = buffer; pos < buffer_end; ++pos)
{
sprintf(byte_as_octal, "%03o", *pos); //Format as octal with 3 digits.
byte_as_octal[3] = 0;
// g_warning("byte=%d, as_hex=%s", *pos, byte_as_octal);
result += Glib::ustring("\\\\") + byte_as_octal;
}
}
return result;
}
Gnome::Gda::Value GlomConversions::parse_escaped_binary_data(const Glib::ustring& escaped_data)
{
//Hopefully we don't need to use this because Gda does it for us when we read a part of a "SELECT" result into a Gnome::Value.
//TODO: Performance
Gnome::Gda::Value result;
size_t buffer_binary_length = 0;
guchar* buffer_binary = Glom_PQunescapeBytea((guchar*)escaped_data.c_str(), &buffer_binary_length);
if(buffer_binary)
{
result.set(buffer_binary, buffer_binary_length);
free(buffer_binary);
}
return result;
}
......@@ -26,6 +26,9 @@
#include <iostream> // for cout, endl
#define GLOM_IMAGE_FORMAT "png"
#define GLOM_IMAGE_FORMAT_MIME_TYPE "image/png"
ImageGlom::ImageGlom()
: m_image(Gtk::Stock::MISSING_IMAGE, Gtk::ICON_SIZE_DIALOG), //The widget is invisible if we don't specify an image.
m_pMenuPopup_UserMode(0)
......@@ -141,14 +144,14 @@ void ImageGlom::set_value(const Gnome::Gda::Value& value)
// PixbufLoader::create() is broken in gtkmm before 2.6.something,
// so let's do this in C so it works with all 2.6 versions:
GError* error = 0;
GdkPixbufLoader* loader = gdk_pixbuf_loader_new_with_type("png", &error);
GdkPixbufLoader* loader = gdk_pixbuf_loader_new_with_type(GLOM_IMAGE_FORMAT, &error);
if(!error)
refPixbufLoader = Glib::wrap(loader);
/*
try
{
refPixbufLoader = Gdk::PixbufLoader::create("png");
refPixbufLoader = Gdk::PixbufLoader::create(GLOM_IMAGE_FORMAT);
g_warning("debug a1");
}
catch(const Gdk::PixbufError& ex)
......@@ -211,7 +214,7 @@ Gnome::Gda::Value ImageGlom::get_value() const
gchar* buffer = 0;
gsize buffer_size = 0;
std::list<Glib::ustring> list_empty;
m_pixbuf_original->save_to_buffer(buffer, buffer_size, "png", list_empty, list_empty); //Always store images as PNG in the database.
m_pixbuf_original->save_to_buffer(buffer, buffer_size, GLOM_IMAGE_FORMAT, list_empty, list_empty); //Always store images as PNG in the database.
//g_warning("ImageGlom::get_value(): debug: to db: ");
//for(int i = 0; i < 10; ++i)
......@@ -351,14 +354,64 @@ void ImageGlom::on_menupopup_activate_select_file()
}
}
void ImageGlom::on_clipboard_get(Gtk::SelectionData& selection_data, guint /* info */)
{
//info is meant to indicate the target, but it seems to be always 0,
//so we use the selection_data's target instead.
const std::string target = selection_data.get_target();
if(target == GLOM_IMAGE_FORMAT_MIME_TYPE)
{
// This set() override uses an 8-bit text format for the data.
selection_data.set_pixbuf(m_pixbuf_clipboard);
}
else
{
g_warning("ExampleWindow::on_clipboard_get(): Unexpected clipboard target format.");
}
}
void ImageGlom::on_clipboard_clear()
{
m_pixbuf_clipboard.clear();
}
void ImageGlom::on_menupopup_activate_copy()
{
//When copy is used, store it here until it is pasted.
m_pixbuf_clipboard = m_pixbuf_original->copy(); //TODO: Get it from the DB, when we stop storing the original here instead of just the preview.
Glib::RefPtr<Gtk::Clipboard> refClipboard = Gtk::Clipboard::get();
//Targets:
std::list<Gtk::TargetEntry> listTargets;
listTargets.push_back( Gtk::TargetEntry(GLOM_IMAGE_FORMAT_MIME_TYPE) );
refClipboard->set( listTargets, sigc::mem_fun(*this, &ImageGlom::on_clipboard_get), sigc::mem_fun(*this, &ImageGlom::on_clipboard_clear) );
}
void ImageGlom::on_clipboard_received_image(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf)
{
if(pixbuf)
{
m_pixbuf_original = pixbuf;
m_image.set(m_pixbuf_original); //Load the image.
scale();
signal_edited().emit();
}
}
void ImageGlom::on_menupopup_activate_paste()
{
//Tell the clipboard to call our method when it is ready:
Glib::RefPtr<Gtk::Clipboard> refClipboard = Gtk::Clipboard::get();
refClipboard->request_image( sigc::mem_fun(*this, &ImageGlom::on_clipboard_received_image) );
}
void ImageGlom::setup_menu_usermode()
......
......@@ -46,6 +46,10 @@ protected:
void on_menupopup_activate_select_file();
void on_menupopup_activate_copy();
void on_menupopup_activate_paste();
void on_clipboard_get(Gtk::SelectionData& selection_data, guint /* info */);
void on_clipboard_clear();
void on_clipboard_received_image(const Glib::RefPtr<Gdk::Pixbuf>& pixbuf);
virtual App_Glom* get_application();
......@@ -57,6 +61,7 @@ protected:
Gtk::Image m_image;
Gtk::Frame m_frame;
Glib::RefPtr<Gdk::Pixbuf> m_pixbuf_original; //Only stored temporarily, because it could be big.
Glib::RefPtr<Gdk::Pixbuf> m_pixbuf_clipboard; //When copy is used, store it here until it is pasted.
Gtk::Menu* m_pMenuPopup_UserMode;
Glib::RefPtr<Gtk::ActionGroup> m_refActionGroup_UserModePopup;
......
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