Arreglando fugas y pequeños errores

This commit is contained in:
Alejandro T. Colombini Gómez 2013-11-07 16:35:24 +01:00
parent cee7dc52b3
commit 35399e6a2f
7 changed files with 85 additions and 43 deletions

View File

@ -49,9 +49,10 @@ DbModel * db_model_holder_get_model (DbModelHolder * obj)
/** /**
* db_model_holder_set_model: * db_model_holder_set_model:
* @obj: a #DbModelHolder * @obj: a #DbModelHolder
* @model: the #DbModel * @model:(allow-none): the #DbModel
* *
* Sets the model used by holder. * Sets the model used by holder. If @model is NULL, then it will unset the
* model.
**/ **/
void db_model_holder_set_model (DbModelHolder * obj, DbModel * model) void db_model_holder_set_model (DbModelHolder * obj, DbModel * model)
{ {

View File

@ -250,6 +250,7 @@ static void vn_consulter_init (VnConsulter * obj)
static void vn_consulter_finalize (VnConsulter * obj) static void vn_consulter_finalize (VnConsulter * obj)
{ {
g_free (obj->file); g_free (obj->file);
G_OBJECT_CLASS (vn_consulter_parent_class)->finalize (G_OBJECT (obj));
} }
static void vn_consulter_class_init (VnConsulterClass * k) static void vn_consulter_class_init (VnConsulterClass * k)

View File

@ -38,12 +38,13 @@ static void vn_column_combo_on_status_changed (DbModel * model,
g_object_set (VN_COLUMN (obj)->cell, "model", NULL, NULL); g_object_set (VN_COLUMN (obj)->cell, "model", NULL, NULL);
} }
static DbModel * vn_column_combo_get_model (VnColumnCombo * obj) static DbModel * vn_column_combo_model_holder_get_model (VnColumnCombo * obj)
{ {
return obj->model; return obj->model;
} }
static void vn_column_combo_set_model (VnColumnCombo * obj, DbModel * model) static void vn_column_combo_model_holder_set_model (VnColumnCombo * obj,
DbModel * model)
{ {
g_return_if_fail (!model || DB_IS_MODEL (model)); g_return_if_fail (!model || DB_IS_MODEL (model));
@ -53,6 +54,9 @@ static void vn_column_combo_set_model (VnColumnCombo * obj, DbModel * model)
vn_column_combo_on_status_changed, obj); vn_column_combo_on_status_changed, obj);
g_clear_object (&obj->model); g_clear_object (&obj->model);
g_clear_object (&obj->tree_model); g_clear_object (&obj->tree_model);
if (obj->completion_ready)
gtk_entry_completion_set_model (obj->completion, NULL);
} }
if (model) if (model)
@ -61,6 +65,9 @@ static void vn_column_combo_set_model (VnColumnCombo * obj, DbModel * model)
obj->tree_model = GTK_TREE_MODEL (vn_model_new (model)); obj->tree_model = GTK_TREE_MODEL (vn_model_new (model));
g_signal_connect (model, "status-changed", g_signal_connect (model, "status-changed",
G_CALLBACK (vn_column_combo_on_status_changed), obj); G_CALLBACK (vn_column_combo_on_status_changed), obj);
if (obj->completion_ready)
gtk_entry_completion_set_model (obj->completion, obj->tree_model);
} }
} }
@ -184,7 +191,7 @@ static void vn_column_combo_set_editable (VnColumnCombo * obj, gboolean editable
g_signal_connect_swapped (parent->cell, "editing-canceled", g_signal_connect_swapped (parent->cell, "editing-canceled",
G_CALLBACK (vn_column_combo_restore_focus), obj); G_CALLBACK (vn_column_combo_restore_focus), obj);
if (!obj->completion) if (!obj->completion)
obj->completion = gtk_entry_completion_new (); obj->completion = gtk_entry_completion_new ();
} }
else else
@ -194,7 +201,9 @@ static void vn_column_combo_set_editable (VnColumnCombo * obj, gboolean editable
if (obj->cell_editable) if (obj->cell_editable)
g_signal_handlers_disconnect_by_data (obj->cell_editable, obj); g_signal_handlers_disconnect_by_data (obj->cell_editable, obj);
obj->completion = NULL; if (obj->completion)
g_clear_object (&obj->completion);
obj->completion_ready = FALSE; obj->completion_ready = FALSE;
obj->cell_editable = NULL; obj->cell_editable = NULL;
} }
@ -247,7 +256,7 @@ static void vn_column_combo_set_property (VnColumnCombo * obj, guint id,
obj->sort_column = g_value_get_int (value); obj->sort_column = g_value_get_int (value);
break; break;
case PROP_MODEL: case PROP_MODEL:
vn_column_combo_set_model (obj, g_value_get_object (value)); vn_column_combo_model_holder_set_model (obj, g_value_get_object (value));
break; break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
@ -291,7 +300,11 @@ static void vn_column_combo_init (VnColumnCombo * obj)
static void vn_column_combo_finalize (VnColumnCombo * obj) static void vn_column_combo_finalize (VnColumnCombo * obj)
{ {
vn_column_combo_set_model (obj, NULL); vn_column_combo_model_holder_set_model (obj, NULL);
if (obj->completion)
g_object_unref (obj->completion);
G_OBJECT_CLASS (vn_column_combo_parent_class)->finalize (G_OBJECT (obj)); G_OBJECT_CLASS (vn_column_combo_parent_class)->finalize (G_OBJECT (obj));
} }
@ -333,6 +346,6 @@ static void vn_column_combo_class_init (VnColumnComboClass * klass)
static void vn_column_combo_model_holder_interface_init (DbModelHolderInterface * iface) static void vn_column_combo_model_holder_interface_init (DbModelHolderInterface * iface)
{ {
iface->get_model = (DbModelHolderGetModelFunc) vn_column_combo_get_model; iface->get_model = (DbModelHolderGetModelFunc) vn_column_combo_model_holder_get_model;
iface->set_model = (DbModelHolderSetModelFunc) vn_column_combo_set_model; iface->set_model = (DbModelHolderSetModelFunc) vn_column_combo_model_holder_set_model;
} }

View File

@ -192,10 +192,11 @@ static GdkPixbuf * vn_column_image_set_image (VnColumnImage * obj,
GdkPixbuf * pixbuf = NULL; GdkPixbuf * pixbuf = NULL;
GError * error = NULL; GError * error = NULL;
const guchar * raw_data = g_bytes_get_data (bytes, &size); const guchar * raw_data = g_bytes_get_data (bytes, &size);
GdkPixbufLoader * loader = gdk_pixbuf_loader_new ();
if (raw_data) if (raw_data)
{ {
GdkPixbufLoader * loader = gdk_pixbuf_loader_new ();
if (gdk_pixbuf_loader_write (loader, raw_data, size, &error) if (gdk_pixbuf_loader_write (loader, raw_data, size, &error)
&& gdk_pixbuf_loader_close (loader, &error)) && gdk_pixbuf_loader_close (loader, &error))
{ {
@ -208,11 +209,9 @@ static GdkPixbuf * vn_column_image_set_image (VnColumnImage * obj,
vn_column_image_download_error (obj, error); vn_column_image_download_error (obj, error);
g_error_free (error); g_error_free (error);
} }
}
else
gdk_pixbuf_loader_close (loader, NULL);
g_object_unref (loader); g_object_unref (loader);
}
return pix && pixbuf ? g_object_ref (pixbuf) : NULL; return pix && pixbuf ? g_object_ref (pixbuf) : NULL;
} }
@ -261,7 +260,8 @@ static void vn_column_image_set_value (VnColumnImage * obj, GtkTreeModel * model
else if (type == G_TYPE_STRING) else if (type == G_TYPE_STRING)
{ {
DownloadData * data; DownloadData * data;
gchar * name = g_value_dup_string (value); gchar * cell_name;
const gchar * name = g_value_get_string (value);
GtkTreeView * view = GTK_TREE_VIEW GtkTreeView * view = GTK_TREE_VIEW
(gtk_tree_view_column_get_tree_view (GTK_TREE_VIEW_COLUMN (obj))); (gtk_tree_view_column_get_tree_view (GTK_TREE_VIEW_COLUMN (obj)));
@ -300,7 +300,6 @@ static void vn_column_image_set_value (VnColumnImage * obj, GtkTreeModel * model
g_hash_table_insert (obj->tooltips, iter->user_data, data); g_hash_table_insert (obj->tooltips, iter->user_data, data);
} }
g_free (name);
return; return;
} }
else else
@ -318,10 +317,7 @@ static void vn_column_image_set_value (VnColumnImage * obj, GtkTreeModel * model
if (!(view_x <= cell_rect.x && cell_rect.x <= view_x + view_rect.width if (!(view_x <= cell_rect.x && cell_rect.x <= view_x + view_rect.width
&& view_y <= cell_rect.y && cell_rect.y <= view_y + view_rect.height)) && view_y <= cell_rect.y && cell_rect.y <= view_y + view_rect.height))
{
g_free (name);
return; return;
}
} }
} }
else else
@ -329,7 +325,12 @@ static void vn_column_image_set_value (VnColumnImage * obj, GtkTreeModel * model
((GHashFunc) g_str_hash, (GEqualFunc) g_str_equal, ((GHashFunc) g_str_hash, (GEqualFunc) g_str_equal,
(GDestroyNotify) g_free, (GDestroyNotify) free_object); (GDestroyNotify) g_free, (GDestroyNotify) free_object);
g_hash_table_insert (obj->loaded, g_strdup (name), NULL); cell_name =
/*obj->external_loader ?
g_strconcat ("/", obj->path, "/", name, NULL):*/
g_strdup (name);
g_hash_table_insert (obj->loaded, g_strdup (cell_name), NULL);
if (!obj->loader) if (!obj->loader)
obj->loader = db_file_loader_new (obj->host, obj->path); obj->loader = db_file_loader_new (obj->host, obj->path);
@ -344,9 +345,9 @@ static void vn_column_image_set_value (VnColumnImage * obj, GtkTreeModel * model
data->model = g_object_ref (model); data->model = g_object_ref (model);
data->iter = gtk_tree_iter_copy (iter); data->iter = gtk_tree_iter_copy (iter);
data->cell = cell; data->cell = cell;
data->name = name; data->name = cell_name;
db_file_loader_download (obj->loader, name, db_file_loader_download (obj->loader, cell_name,
(DbFileLoaderCallbackFunc) vn_column_image_on_download, data); (DbFileLoaderCallbackFunc) vn_column_image_on_download, data);
} }
} }
@ -399,9 +400,11 @@ static void vn_column_image_set_property (VnColumnImage * obj, guint id,
case PROP_TOOLTIP_SIZE: case PROP_TOOLTIP_SIZE:
obj->tooltip_size = g_value_get_int (value); obj->tooltip_size = g_value_get_int (value);
break; break;
/* case PROP_FILE_LOADER: case PROP_FILE_LOADER:
obj->loader = g_value_get_object (value); obj->loader = g_value_dup_object (value);
break;*/ if (obj->loader)
obj->external_loader = TRUE;
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
} }
@ -424,9 +427,9 @@ static void vn_column_image_get_property (VnColumnImage * obj, guint id,
case PROP_TOOLTIP_SIZE: case PROP_TOOLTIP_SIZE:
g_value_set_int (value, obj->tooltip_size); g_value_set_int (value, obj->tooltip_size);
break; break;
/* case PROP_FILE_LOADER: case PROP_FILE_LOADER:
g_value_set_object (value, obj->loader); g_value_set_object (value, obj->loader);
break;*/ break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
} }
@ -443,6 +446,7 @@ static void vn_column_image_init (VnColumnImage * obj)
obj->path = NULL; obj->path = NULL;
obj->tooltip_path = NULL; obj->tooltip_path = NULL;
obj->loader = NULL; obj->loader = NULL;
obj->external_loader = FALSE;
obj->loaded = NULL; obj->loaded = NULL;
obj->tooltips = NULL; obj->tooltips = NULL;
obj->tree_view = NULL; obj->tree_view = NULL;
@ -521,12 +525,12 @@ static void vn_column_image_class_init (VnColumnImageClass * klass)
,300 ,300
,G_PARAM_CONSTRUCT | G_PARAM_READWRITE ,G_PARAM_CONSTRUCT | G_PARAM_READWRITE
)); ));
/*
g_object_class_install_property (k, PROP_FILE_LOADER, g_object_class_install_property (k, PROP_FILE_LOADER,
g_param_spec_object ("file-loader" g_param_spec_object ("file-loader"
,_("File loader") ,_("File loader")
,_("An optional file loader, if it's NULL the column will create one") ,_("An optional file loader, if it's NULL the column will create one")
,DB_TYPE_FILE_LOADER ,DB_TYPE_FILE_LOADER
,G_PARAM_CONSTRUCT | G_PARAM_READWRITE ,G_PARAM_CONSTRUCT | G_PARAM_READWRITE
));*/ ));
} }

View File

@ -42,6 +42,7 @@ struct _VnColumnImage
gchar * tooltip_path; gchar * tooltip_path;
gint tooltip_size; gint tooltip_size;
DbFileLoader * loader; DbFileLoader * loader;
gboolean external_loader;
GHashTable * loaded; GHashTable * loaded;
GHashTable * tooltips; GHashTable * tooltips;
GtkTreeView * tree_view; GtkTreeView * tree_view;

View File

@ -224,7 +224,7 @@ void vn_column_set_null (VnColumn * obj, gboolean null)
} }
/** /**
* vn_column_get_tab_index * vn_column_get_tab_index:
* @obj: the #VnColumn * @obj: the #VnColumn
* *
* Sets the order in which the column will be selected while pressing Tab across * Sets the order in which the column will be selected while pressing Tab across
@ -240,7 +240,7 @@ int vn_column_get_tab_index (VnColumn * obj)
} }
/** /**
* vn_column_set_tab_index * vn_column_set_tab_index:
* @obj: the #VnColumn * @obj: the #VnColumn
* @tab_index: the index of the column * @tab_index: the index of the column
* *
@ -289,6 +289,7 @@ DbModel * vn_column_get_model (VnColumn * obj)
**/ **/
gboolean vn_column_get_iter (VnColumn * obj, const gchar * path, DbIter * iter) gboolean vn_column_get_iter (VnColumn * obj, const gchar * path, DbIter * iter)
{ {
gboolean ret = FALSE;
DbModel * model; DbModel * model;
GtkTreePath * tree_path; GtkTreePath * tree_path;
@ -307,11 +308,11 @@ gboolean vn_column_get_iter (VnColumn * obj, const gchar * path, DbIter * iter)
else else
{ {
db_model_get_iter (model, iter, gtk_tree_path_get_indices (tree_path)[0]); db_model_get_iter (model, iter, gtk_tree_path_get_indices (tree_path)[0]);
return TRUE; ret = TRUE;
} }
gtk_tree_path_free (tree_path); gtk_tree_path_free (tree_path);
return FALSE; return ret;
} }
/** /**
@ -405,6 +406,7 @@ static void vn_column_init (VnColumn * obj)
static void vn_column_finalize (VnColumn * obj) static void vn_column_finalize (VnColumn * obj)
{ {
g_free (obj->column_name);
G_OBJECT_CLASS (vn_column_parent_class)->finalize (G_OBJECT (obj)); G_OBJECT_CLASS (vn_column_parent_class)->finalize (G_OBJECT (obj));
} }

View File

@ -155,6 +155,8 @@ static void vn_gui_free_mod_data (ModData * data)
if (data->action_data) if (data->action_data)
g_slist_free_full (data->action_data, g_slist_free_full (data->action_data,
(GDestroyNotify) vn_gui_free_action_data); (GDestroyNotify) vn_gui_free_action_data);
g_free (data);
} }
/* /*
@ -213,6 +215,7 @@ static void vn_gui_load_module (VnGui * obj, const gchar * dir, const gchar * fi
GdomeNode * node; GdomeNode * node;
GdomeDOMString * mod_title; GdomeDOMString * mod_title;
GdomeDOMString * library; GdomeDOMString * library;
GdomeDOMString * name_str;
// Validating the module definition against the DTD (using libxml2 directly) // Validating the module definition against the DTD (using libxml2 directly)
@ -257,22 +260,31 @@ static void vn_gui_load_module (VnGui * obj, const gchar * dir, const gchar * fi
gdome_di_unref (di, &e); gdome_di_unref (di, &e);
name_str = S("name");
if (doc) if (doc)
{ {
nl = gdome_doc_getElementsByTagName (doc, S("library"), &e); GdomeDOMString * library_str = S("library"),
* form_str = S("form"),
* action_str = S("action");
nl = gdome_doc_getElementsByTagName (doc, library_str, &e);
el = (GdomeElement *) gdome_nl_item (nl, 0, &e); el = (GdomeElement *) gdome_nl_item (nl, 0, &e);
gdome_str_unref (library_str);
gdome_nl_unref (nl, &e); gdome_nl_unref (nl, &e);
library = gdome_el_getAttribute (el, S("name"), &e); library = gdome_el_getAttribute (el, name_str, &e);
mod_name = g_strdup (library->str); mod_name = g_strdup (library->str);
node = gdome_el_firstChild (el, &e); node = gdome_el_firstChild (el, &e);
mod_title = gdome_n_nodeValue (node, &e); mod_title = gdome_n_nodeValue (node, &e);
mod_title_strip = g_strstrip (g_strdup (mod_title->str)); mod_title_strip = g_strstrip (g_strdup (mod_title->str));
nl = gdome_doc_getElementsByTagName (doc, S("form"), &e); nl = gdome_doc_getElementsByTagName (doc, form_str, &e);
action_nl = gdome_doc_getElementsByTagName (doc, S("action"), &e); action_nl = gdome_doc_getElementsByTagName (doc, action_str, &e);
gdome_str_unref (form_str);
gdome_str_unref (action_str);
gdome_str_unref (library); gdome_str_unref (library);
gdome_doc_unref (doc, &e); gdome_doc_unref (doc, &e);
gdome_n_unref (node, &e); gdome_n_unref (node, &e);
@ -333,6 +345,9 @@ static void vn_gui_load_module (VnGui * obj, const gchar * dir, const gchar * fi
GSList * mod_actions = NULL; GSList * mod_actions = NULL;
ActionData * action_data; ActionData * action_data;
GtkActionGroup * actions = gtk_action_group_new (mod_name); GtkActionGroup * actions = gtk_action_group_new (mod_name);
GdomeDOMString * icon_str = S("icon"),
* action_name_str = S("action-name"),
* accel_str = S("accel");
// Creating folder to put forms inside // Creating folder to put forms inside
@ -353,11 +368,11 @@ static void vn_gui_load_module (VnGui * obj, const gchar * dir, const gchar * fi
// Getting form info // Getting form info
el = (GdomeElement *) gdome_nl_item (nl, n, &e); el = (GdomeElement *) gdome_nl_item (nl, n, &e);
icon = gdome_el_getAttribute (el, S("icon"), &e); icon = gdome_el_getAttribute (el, icon_str, &e);
action_name = gdome_el_getAttribute (el, S("action-name"), &e); action_name = gdome_el_getAttribute (el, action_name_str, &e);
accel = gdome_el_getAttribute (el, S("accel"), &e); accel = gdome_el_getAttribute (el, accel_str, &e);
name = gdome_el_getAttribute (el, S("name"), &e); name = gdome_el_getAttribute (el, name_str, &e);
c_name = g_strdelimit (g_strdup (name->str), "-. ", '_'); c_name = g_strdelimit (g_strdup (name->str), "-. ", '_');
node = gdome_el_firstChild (el, &e); node = gdome_el_firstChild (el, &e);
@ -429,12 +444,16 @@ static void vn_gui_load_module (VnGui * obj, const gchar * dir, const gchar * fi
g_free (symbol_name); g_free (symbol_name);
} }
gdome_str_unref (icon_str);
gdome_str_unref (action_name_str);
gdome_str_unref (accel_str);
len = gdome_nl_length (action_nl, &e); len = gdome_nl_length (action_nl, &e);
for (n = 0; n < len; n++) for (n = 0; n < len; n++)
{ {
el = (GdomeElement *) gdome_nl_item (action_nl, n, &e); el = (GdomeElement *) gdome_nl_item (action_nl, n, &e);
name = gdome_el_getAttribute (el, S("name"), &e); name = gdome_el_getAttribute (el, name_str, &e);
node = gdome_el_firstChild (el, &e); node = gdome_el_firstChild (el, &e);
title = gdome_n_nodeValue (node, &e); title = gdome_n_nodeValue (node, &e);
@ -484,6 +503,7 @@ static void vn_gui_load_module (VnGui * obj, const gchar * dir, const gchar * fi
g_free (mod_title_strip); g_free (mod_title_strip);
g_free (mod_name); g_free (mod_name);
gdome_str_unref (name_str);
gdome_str_unref (mod_title); gdome_str_unref (mod_title);
gdome_nl_unref (nl, &e); gdome_nl_unref (nl, &e);
gdome_nl_unref (action_nl, &e); gdome_nl_unref (action_nl, &e);