From 35399e6a2fb548315d1341ba2bdb0aae2e05fb1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20T=2E=20Colombini=20G=C3=B3mez?= Date: Thu, 7 Nov 2013 16:35:24 +0100 Subject: [PATCH] =?UTF-8?q?Arreglando=20fugas=20y=20peque=C3=B1os=20errore?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/db-model-holder.c | 5 +++-- module/src/vn-consulter.c | 1 + vn/column/vn-column-combo.c | 29 +++++++++++++++++------- vn/column/vn-column-image.c | 44 ++++++++++++++++++++----------------- vn/column/vn-column-image.h | 1 + vn/vn-column.c | 10 +++++---- vn/vn-gui.c | 38 ++++++++++++++++++++++++-------- 7 files changed, 85 insertions(+), 43 deletions(-) diff --git a/db/db-model-holder.c b/db/db-model-holder.c index bfc759f..6cdaed0 100644 --- a/db/db-model-holder.c +++ b/db/db-model-holder.c @@ -49,9 +49,10 @@ DbModel * db_model_holder_get_model (DbModelHolder * obj) /** * db_model_holder_set_model: * @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) { diff --git a/module/src/vn-consulter.c b/module/src/vn-consulter.c index a631830..6f27476 100644 --- a/module/src/vn-consulter.c +++ b/module/src/vn-consulter.c @@ -250,6 +250,7 @@ static void vn_consulter_init (VnConsulter * obj) static void vn_consulter_finalize (VnConsulter * obj) { g_free (obj->file); + G_OBJECT_CLASS (vn_consulter_parent_class)->finalize (G_OBJECT (obj)); } static void vn_consulter_class_init (VnConsulterClass * k) diff --git a/vn/column/vn-column-combo.c b/vn/column/vn-column-combo.c index 604378d..9a7c00f 100644 --- a/vn/column/vn-column-combo.c +++ b/vn/column/vn-column-combo.c @@ -38,12 +38,13 @@ static void vn_column_combo_on_status_changed (DbModel * model, 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; } -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)); @@ -53,6 +54,9 @@ static void vn_column_combo_set_model (VnColumnCombo * obj, DbModel * model) vn_column_combo_on_status_changed, obj); g_clear_object (&obj->model); g_clear_object (&obj->tree_model); + + if (obj->completion_ready) + gtk_entry_completion_set_model (obj->completion, NULL); } 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)); g_signal_connect (model, "status-changed", 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_CALLBACK (vn_column_combo_restore_focus), obj); - if (!obj->completion) + if (!obj->completion) obj->completion = gtk_entry_completion_new (); } else @@ -194,7 +201,9 @@ static void vn_column_combo_set_editable (VnColumnCombo * obj, gboolean editable if (obj->cell_editable) 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->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); break; 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; default: 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) { - 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)); } @@ -333,6 +346,6 @@ static void vn_column_combo_class_init (VnColumnComboClass * klass) static void vn_column_combo_model_holder_interface_init (DbModelHolderInterface * iface) { - iface->get_model = (DbModelHolderGetModelFunc) vn_column_combo_get_model; - iface->set_model = (DbModelHolderSetModelFunc) vn_column_combo_set_model; + iface->get_model = (DbModelHolderGetModelFunc) vn_column_combo_model_holder_get_model; + iface->set_model = (DbModelHolderSetModelFunc) vn_column_combo_model_holder_set_model; } diff --git a/vn/column/vn-column-image.c b/vn/column/vn-column-image.c index 6c3a388..1ea865b 100644 --- a/vn/column/vn-column-image.c +++ b/vn/column/vn-column-image.c @@ -192,10 +192,11 @@ static GdkPixbuf * vn_column_image_set_image (VnColumnImage * obj, GdkPixbuf * pixbuf = NULL; GError * error = NULL; const guchar * raw_data = g_bytes_get_data (bytes, &size); - GdkPixbufLoader * loader = gdk_pixbuf_loader_new (); if (raw_data) { + GdkPixbufLoader * loader = gdk_pixbuf_loader_new (); + if (gdk_pixbuf_loader_write (loader, raw_data, size, &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); 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; } @@ -261,7 +260,8 @@ static void vn_column_image_set_value (VnColumnImage * obj, GtkTreeModel * model else if (type == G_TYPE_STRING) { 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 (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_free (name); return; } 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 && view_y <= cell_rect.y && cell_rect.y <= view_y + view_rect.height)) - { - g_free (name); return; - } } } else @@ -329,7 +325,12 @@ static void vn_column_image_set_value (VnColumnImage * obj, GtkTreeModel * model ((GHashFunc) g_str_hash, (GEqualFunc) g_str_equal, (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) 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->iter = gtk_tree_iter_copy (iter); 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); } } @@ -399,9 +400,11 @@ static void vn_column_image_set_property (VnColumnImage * obj, guint id, case PROP_TOOLTIP_SIZE: obj->tooltip_size = g_value_get_int (value); break; -/* case PROP_FILE_LOADER: - obj->loader = g_value_get_object (value); - break;*/ + case PROP_FILE_LOADER: + obj->loader = g_value_dup_object (value); + if (obj->loader) + obj->external_loader = TRUE; + break; default: 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: g_value_set_int (value, obj->tooltip_size); break; -/* case PROP_FILE_LOADER: + case PROP_FILE_LOADER: g_value_set_object (value, obj->loader); - break;*/ + break; default: 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->tooltip_path = NULL; obj->loader = NULL; + obj->external_loader = FALSE; obj->loaded = NULL; obj->tooltips = NULL; obj->tree_view = NULL; @@ -521,12 +525,12 @@ static void vn_column_image_class_init (VnColumnImageClass * klass) ,300 ,G_PARAM_CONSTRUCT | G_PARAM_READWRITE )); -/* + g_object_class_install_property (k, PROP_FILE_LOADER, g_param_spec_object ("file-loader" ,_("File loader") ,_("An optional file loader, if it's NULL the column will create one") ,DB_TYPE_FILE_LOADER ,G_PARAM_CONSTRUCT | G_PARAM_READWRITE - ));*/ + )); } diff --git a/vn/column/vn-column-image.h b/vn/column/vn-column-image.h index 0758551..1eb6ff5 100644 --- a/vn/column/vn-column-image.h +++ b/vn/column/vn-column-image.h @@ -42,6 +42,7 @@ struct _VnColumnImage gchar * tooltip_path; gint tooltip_size; DbFileLoader * loader; + gboolean external_loader; GHashTable * loaded; GHashTable * tooltips; GtkTreeView * tree_view; diff --git a/vn/vn-column.c b/vn/vn-column.c index 41852ba..83ecc53 100644 --- a/vn/vn-column.c +++ b/vn/vn-column.c @@ -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 * * 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 * @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 ret = FALSE; DbModel * model; GtkTreePath * tree_path; @@ -307,11 +308,11 @@ gboolean vn_column_get_iter (VnColumn * obj, const gchar * path, DbIter * iter) else { db_model_get_iter (model, iter, gtk_tree_path_get_indices (tree_path)[0]); - return TRUE; + ret = TRUE; } 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) { + g_free (obj->column_name); G_OBJECT_CLASS (vn_column_parent_class)->finalize (G_OBJECT (obj)); } diff --git a/vn/vn-gui.c b/vn/vn-gui.c index 402e041..9aefbcd 100644 --- a/vn/vn-gui.c +++ b/vn/vn-gui.c @@ -155,6 +155,8 @@ static void vn_gui_free_mod_data (ModData * data) if (data->action_data) g_slist_free_full (data->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; GdomeDOMString * mod_title; GdomeDOMString * library; + GdomeDOMString * name_str; // 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); + name_str = S("name"); + 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); + gdome_str_unref (library_str); 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); node = gdome_el_firstChild (el, &e); mod_title = gdome_n_nodeValue (node, &e); mod_title_strip = g_strstrip (g_strdup (mod_title->str)); - nl = gdome_doc_getElementsByTagName (doc, S("form"), &e); - action_nl = gdome_doc_getElementsByTagName (doc, S("action"), &e); + nl = gdome_doc_getElementsByTagName (doc, form_str, &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_doc_unref (doc, &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; ActionData * action_data; 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 @@ -353,11 +368,11 @@ static void vn_gui_load_module (VnGui * obj, const gchar * dir, const gchar * fi // Getting form info el = (GdomeElement *) gdome_nl_item (nl, n, &e); - icon = gdome_el_getAttribute (el, S("icon"), &e); - action_name = gdome_el_getAttribute (el, S("action-name"), &e); - accel = gdome_el_getAttribute (el, S("accel"), &e); + icon = gdome_el_getAttribute (el, icon_str, &e); + action_name = gdome_el_getAttribute (el, action_name_str, &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), "-. ", '_'); 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); } + gdome_str_unref (icon_str); + gdome_str_unref (action_name_str); + gdome_str_unref (accel_str); + len = gdome_nl_length (action_nl, &e); for (n = 0; n < len; n++) { 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); 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_name); + gdome_str_unref (name_str); gdome_str_unref (mod_title); gdome_nl_unref (nl, &e); gdome_nl_unref (action_nl, &e);