diff --git a/db/db-calc.c b/db/db-calc.c index b402a8f..23e63f3 100644 --- a/db/db-calc.c +++ b/db/db-calc.c @@ -29,7 +29,7 @@ * updates its value according to the changes. * * #DbCalc has as built-in operations the sumatory and average that can be - * selected passing #DB_CALC_SUM OR #DB_CALC_AVG, respectively. + * selected passing #DB_CALC_TYPE_SUM OR #DB_CALC_TYPE_AVG, respectively. * * While creating a #DbCalc it's possible to specify either a single column * number, to calculate using only this column and no additional operations, or @@ -51,7 +51,7 @@ G_DEFINE_TYPE (DbCalc, db_calc, GVN_TYPE_PARAM); * * Return value: a new #DbCalc **/ -DbCalc * db_calc_new (DbModel * model, DbCalcOperationType type, gint col) +DbCalc * db_calc_new (DbModel * model, DbCalcType type, gint col) { g_return_val_if_fail (DB_IS_MODEL (model), NULL); g_return_val_if_fail (0 <= col || col < db_model_get_ncols (model), NULL); @@ -72,7 +72,7 @@ DbCalc * db_calc_new (DbModel * model, DbCalcOperationType type, gint col) * * Return value: a new #DbCalc **/ -DbCalc * db_calc_new_with_func (DbModel * model, DbCalcOperationType type, DbCalcFunc func, gpointer data) +DbCalc * db_calc_new_with_func (DbModel * model, DbCalcType type, DbCalcFunc func, gpointer data) { g_return_val_if_fail (DB_IS_MODEL (model), NULL); g_return_val_if_fail (func, NULL); @@ -119,7 +119,7 @@ static void db_calc_internal_func static void db_calc_before_unset (DbModel * model, DbIter * iter, DbCalc * obj) { - GValue value = {0}; + GValue value = G_VALUE_INIT; obj->func (obj, iter, &value, obj->data); @@ -130,14 +130,14 @@ static void db_calc_before_unset (DbModel * model, DbIter * iter, DbCalc * obj) current = db_calc_value_to_double (gvn_param_get_value (GVN_PARAM (obj))); old = db_calc_value_to_double (&value); - if (obj->type == DB_CALC_AVG) - { + if (obj->type == DB_CALC_TYPE_AVG) + { if (obj->count != 1) current = (current * (gdouble) obj->count - old) / (gdouble) (obj->count - 1); else current = 0; } - else if (obj->type == DB_CALC_SUM) + else if (obj->type == DB_CALC_TYPE_SUM) current -= old; obj->count--; @@ -158,7 +158,7 @@ static void db_calc_before_delete (DbModel * model, gint path, DbCalc * obj) static void db_calc_after_set (DbModel * model, DbIter * iter, DbCalc * obj) { - GValue value = {0}; + GValue value = G_VALUE_INIT; obj->func (obj, iter, &value, obj->data); @@ -169,9 +169,9 @@ static void db_calc_after_set (DbModel * model, DbIter * iter, DbCalc * obj) current = db_calc_value_to_double (gvn_param_get_value (GVN_PARAM (obj))); new = db_calc_value_to_double (&value); - if (obj->type == DB_CALC_AVG) + if (obj->type == DB_CALC_TYPE_AVG) current = (current * (gdouble) obj->count + new) / (gdouble) (obj->count + 1); - else if (obj->type == DB_CALC_SUM) + else if (obj->type == DB_CALC_TYPE_SUM) current += new; obj->count++; @@ -187,7 +187,7 @@ static void db_calc_refresh (DbModel * model, DbModelStatus status, DbCalc * obj { DbIter iter; gdouble current = 0; - GValue val = {0}; + GValue val = G_VALUE_INIT; if (status != DB_MODEL_STATUS_READY) return; if (!db_model_get_iter_first (model, &iter)) return; @@ -207,7 +207,7 @@ static void db_calc_refresh (DbModel * model, DbModelStatus status, DbCalc * obj } while (db_model_iter_next (model, &iter)); - if (obj->type == DB_CALC_AVG) + if (obj->type == DB_CALC_TYPE_AVG) current = (obj->count > 0) ? current / (gdouble) obj->count : 0; g_value_set_double (g_value_init (&val, G_TYPE_DOUBLE), current); @@ -233,13 +233,13 @@ static void db_calc_set_property (DbCalc * obj, guint id, { case PROP_MODEL: obj->model = g_value_dup_object (value); - g_object_connect (obj->model - ,"signal::line-updated", db_calc_before_unset, obj - ,"signal-after::line-updated", db_calc_after_set, obj - ,"signal::line-deleted", db_calc_before_delete, obj - ,"signal::status-changed", db_calc_refresh, obj - , NULL - ); + if (obj->model) + g_object_connect (obj->model + ,"signal::line-updated", db_calc_before_unset, obj + ,"signal-after::line-updated", db_calc_after_set, obj + ,"signal::line-deleted", db_calc_before_delete, obj + ,"signal::status-changed", db_calc_refresh, obj + , NULL); break; case PROP_TYPE: obj->type = g_value_get_int (value); @@ -333,12 +333,11 @@ static void db_calc_class_init (DbCalcClass * k) ); g_object_class_install_property (klass, PROP_TYPE - ,g_param_spec_int ("type" + ,g_param_spec_enum ("type" ,_("Operation type") ,_("The type of the operation applied over the function") - ,0 - ,1 - ,0 + ,DB_TYPE_CALC_TYPE + ,DB_CALC_TYPE_SUM ,G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE) ); @@ -366,3 +365,23 @@ static void db_calc_class_init (DbCalcClass * k) ,G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE) ); } + +GType db_calc_type_get_type () +{ + static GType type = 0; + + if (type == 0) + { + static const GEnumValue values[] = + { + {DB_CALC_TYPE_SUM, "DB_CALC_TYPE_SUM", "sum"} + ,{DB_CALC_TYPE_AVG, "DB_CALC_TYPE_AVG", "avg"} + ,{0, NULL, NULL} + }; + + type = g_enum_register_static + (g_intern_static_string ("DbCalcType"), values); + } + + return type; +} diff --git a/db/db-calc.h b/db/db-calc.h index 60a503b..db694a9 100644 --- a/db/db-calc.h +++ b/db/db-calc.h @@ -33,6 +33,8 @@ #define DB_IS_CALC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DB_TYPE_CLASS)) #define DB_CALC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DB_TYPE_CALC, DbCalcClass)) +#define DB_TYPE_CALC_TYPE (db_calc_type_get_type ()) + typedef struct _DbCalc DbCalc; typedef struct _DbCalcClass DbCalcClass; @@ -50,25 +52,25 @@ typedef struct _DbCalcClass DbCalcClass; typedef void (*DbCalcFunc) (DbCalc * obj, DbIter * iter, GValue * out, gpointer user_data); /** - * DbCalcOperationType: - * @DB_CALC_SUM: sumatory of the values - * @DB_CALC_AVG: average of the values + * DbCalcType: + * @DB_CALC_TYPE_SUM: sumatory of the values + * @DB_CALC_TYPE_AVG: average of the values * * Defines which type of operation will be performed over the column values. **/ typedef enum { - DB_CALC_SUM, - DB_CALC_AVG + DB_CALC_TYPE_SUM, + DB_CALC_TYPE_AVG } -DbCalcOperationType; +DbCalcType; struct _DbCalc { GvnParam parent; DbModel * model; - DbCalcOperationType type; + DbCalcType type; DbCalcFunc func; gpointer data; guint col; @@ -81,12 +83,14 @@ struct _DbCalcClass GvnParamClass klass; }; -GType db_calc_get_type (); +GType db_calc_get_type (); +GType db_calc_type_get_type (); + DbCalc * db_calc_new (DbModel * model - ,DbCalcOperationType type + ,DbCalcType type ,gint col); DbCalc * db_calc_new_with_func (DbModel * model - ,DbCalcOperationType type + ,DbCalcType type ,DbCalcFunc func ,gpointer data); diff --git a/db/db-conn.c b/db/db-conn.c index 6e23f0a..2acb167 100644 --- a/db/db-conn.c +++ b/db/db-conn.c @@ -91,7 +91,7 @@ static gboolean db_conn_idle_error (IdleData * idle_data) GError * error = idle_data->data; g_signal_emit (idle_data->obj, signals[ERROR], 0, error); g_error_free (error); - return FALSE; + return G_SOURCE_REMOVE; } /* @@ -117,7 +117,7 @@ static gboolean db_conn_idle_status (IdleData * idle_data) { DbConnStatus status = GPOINTER_TO_INT (idle_data->data); g_signal_emit (idle_data->obj, signals[STATUS_CHANGED], 0, status); - return FALSE; + return G_SOURCE_REMOVE; } /* diff --git a/db/db-file-loader.c b/db/db-file-loader.c index e09ea17..6f9d204 100644 --- a/db/db-file-loader.c +++ b/db/db-file-loader.c @@ -218,7 +218,7 @@ static gboolean db_file_loader_callback (File * file) g_hash_table_remove (file->obj->priv->downloading, file); - return FALSE; + return G_SOURCE_REMOVE; } static gboolean db_file_loader_resolve_host (DbFileLoader * obj, diff --git a/db/db-model.c b/db/db-model.c index 01a41ee..2b2656c 100644 --- a/db/db-model.c +++ b/db/db-model.c @@ -220,7 +220,7 @@ DbColDef; typedef struct { - gchar * dst; + SqlField * dst; GvnParam * param; } DbParamDef; @@ -1780,6 +1780,7 @@ void db_model_set_default_value_from_param (DbModel * obj, const gchar * dst_field, GvnParam * param) { SqlExpr * value; + SqlField * field; SqlOperation * op; g_return_if_fail (DB_IS_MODEL (obj)); @@ -1787,7 +1788,8 @@ void db_model_set_default_value_from_param (DbModel * obj, g_return_if_fail (dst_field); op = sql_operation_new (SQL_OPERATION_TYPE_EQUAL); - sql_operation_add_expr (op, sql_field_new (dst_field, NULL, NULL)); + field = sql_parser_parse_field (dst_field); + sql_operation_add_expr (op, SQL_EXPR (field)); value = sql_value_new (); sql_value_set_param (SQL_VALUE (value), param); @@ -1796,7 +1798,7 @@ void db_model_set_default_value_from_param (DbModel * obj, sql_string_add_expr (SQL_STRING (obj->priv->stmt), SQL_EXPR (op)); DbParamDef * def = g_new (DbParamDef, 1); - def->dst = g_strdup (dst_field); + def->dst = g_object_ref_sink (field); def->param = g_object_ref_sink (param); obj->priv->param_default = g_slist_prepend (obj->priv->param_default, def); @@ -1930,7 +1932,7 @@ void db_model_set (DbModel * obj, DbIter * iter, ...) { gint column; gpointer content; - GValue val = {0}; + GValue val = G_VALUE_INIT; va_list va; g_return_if_fail (DB_IS_MODEL (obj)); @@ -2026,7 +2028,7 @@ gboolean db_model_set_value (DbModel * obj, DbIter * iter, gint col, const GValu } else { - GValue new_value = {0}; + GValue new_value = G_VALUE_INIT; DbRow * row = iter->data; DbOperation * operation = g_hash_table_lookup (priv->row_ops, row); DbModelRowOp row_op = operation ? operation->type : 0; @@ -2136,8 +2138,8 @@ gboolean db_model_insert (DbModel * obj, DbIter * iter) { DbParamDef * param_def = p->data; - if (!g_strcmp0 (param_def->dst, priv->column[i].name)) - { + if (!g_strcmp0 (param_def->dst->name, priv->column[i].name)) + { def = gvn_param_get_value (param_def->param); g_value_init (&row->value[i], G_VALUE_TYPE (def)); gvn_value_copy (def, &row->value[i]); @@ -2343,7 +2345,7 @@ void db_model_order_by (DbModel * obj, gint col, DbSortType order) gboolean db_model_search (DbModel * obj, gint col, DbIter * iter, gpointer content) { gboolean ret; - GValue value = {0}; + GValue value = G_VALUE_INIT; g_return_val_if_fail (DB_IS_MODEL (obj), FALSE); g_return_val_if_fail (obj->priv->result @@ -2585,7 +2587,7 @@ void db_model_perform_operations (DbModel * obj, gboolean retry) if (priv->column[i].info & DB_COLUMN_PRI_KEY) { gboolean unset = FALSE; - GValue value = {0}; + GValue value = G_VALUE_INIT; SqlExpr * eq_value; equal_op = SQL_OPERATION @@ -2630,7 +2632,7 @@ void db_model_perform_operations (DbModel * obj, gboolean retry) DbParamDef * param_def = sl->data; for (m = insert->field; m; m = m->next) - if (!g_strcmp0 (((SqlField*) m->data)->name, param_def->dst)) + if (!g_strcmp0 (((SqlField*) m->data)->name, param_def->dst->name)) { cont = TRUE; break; @@ -2641,8 +2643,7 @@ void db_model_perform_operations (DbModel * obj, gboolean retry) val = sql_value_new_with_value (gvn_param_get_value (param_def->param)); - sql_insert_add_field (insert, - SQL_FIELD (sql_field_new (param_def->dst, NULL, NULL))); + sql_insert_add_field (insert, param_def->dst); sql_insert_add_expr (insert, val); } @@ -2996,7 +2997,7 @@ gint db_model_get_path (DbModel * obj, DbIter * iter) /** * db_model_get_iter: * @obj: a #DbModel - * @iter: (out): an uninitialized #DbIter + * @iter: (out): an unitialized #DbIter * @path: the number of the row being accessed * * Sets @iter pointing to the row of @obj specified by @path. @@ -3261,8 +3262,6 @@ static void db_model_init (DbModel *obj) static void db_model_finalize (DbModel * obj) { GSList * n; - GObjectClass * parent; - parent = g_type_class_peek_parent (DB_MODEL_GET_CLASS (obj)); db_model_clear (obj); @@ -3292,14 +3291,15 @@ static void db_model_finalize (DbModel * obj) for (n = obj->priv->param_default; n; n = n->next) { - g_object_unref (((DbParamDef *) n->data)->param); - g_free (((DbParamDef *) n->data)->dst); - g_free (n->data); + DbParamDef * pd = n->data; + g_object_unref (pd->param); + g_object_unref (pd->dst); + g_free (pd); } g_slist_free (obj->priv->param_default); - parent->finalize (G_OBJECT (obj)); + G_OBJECT_CLASS (db_model_parent_class)->finalize (G_OBJECT (obj)); } static void db_model_class_init (DbModelClass *k) diff --git a/db/db-param.c b/db/db-param.c index 9e90e47..e5abdba 100644 --- a/db/db-param.c +++ b/db/db-param.c @@ -94,7 +94,7 @@ static void db_param_on_iterator_iter_changed (DbIterator * iterator, DbParam * if (!value) { - GValue tmp_value = {0}; + GValue tmp_value = G_VALUE_INIT; g_value_init (&tmp_value, GVN_TYPE_NULL); klass->put_value (GVN_PARAM (obj), &tmp_value); g_value_unset (&tmp_value); diff --git a/db/db-request.c b/db/db-request.c index 9bf13e6..5145ede 100644 --- a/db/db-request.c +++ b/db/db-request.c @@ -35,7 +35,7 @@ static gboolean db_request_idle (DbRequest * obj) if (obj->callback) obj->callback (obj, obj->user_data); - return FALSE; + return G_SOURCE_REMOVE; } static void db_request_idle_notify (DbRequest * obj) diff --git a/debian/changelog b/debian/changelog index c4b9ca5..52587bf 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -libhedera (1.0-8) stable; urgency=low +libhedera (1.0-9) stable; urgency=low * Initial Release. diff --git a/docs/reference/hedera/hedera-docs.sgml b/docs/reference/hedera/hedera-docs.sgml index 89ba21f..b907dfa 100644 --- a/docs/reference/hedera/hedera-docs.sgml +++ b/docs/reference/hedera/hedera-docs.sgml @@ -110,7 +110,7 @@ - + diff --git a/docs/reference/hedera/running.xml b/docs/reference/hedera/running.xml index 72c3be3..fa1f605 100644 --- a/docs/reference/hedera/running.xml +++ b/docs/reference/hedera/running.xml @@ -24,9 +24,9 @@ pkg-config to know where these directories actually are in your installation: -$ pkg-config --variable=modulelibdir hedera -$ pkg-config --variable=moduledatadir hedera -$ pkg-config --variable=modulequerydir hedera +pkg-config --variable=modulelibdir hedera +pkg-config --variable=moduledatadir hedera +pkg-config --variable=modulequerydir hedera It is also possible to put your files in any other path and tell diff --git a/glade/Makefile.am b/glade/Makefile.am index 0c07c5b..1a768a4 100644 --- a/glade/Makefile.am +++ b/glade/Makefile.am @@ -15,10 +15,12 @@ libgladevn_la_LDFLAGS = -avoid-version libgladevn_la_SOURCES = \ glade-vn.h \ glade-vn.c \ + glade-db-iterator.c \ + glade-eprop-model.c \ glade-vn-batch.c \ - glade-db-sql.c \ glade-db-model.c \ - glade-db-iterator.c + glade-db-model-editor.h \ + glade-db-model-editor.c gladevn_data_DATA = vn.xml diff --git a/glade/glade-db-iterator.c b/glade/glade-db-iterator.c index c3c18c1..e7ee53f 100644 --- a/glade/glade-db-iterator.c +++ b/glade/glade-db-iterator.c @@ -18,108 +18,38 @@ #include "glade-vn.h" #include -static void glade_db_iterator_on_name_changed (GladeProject * project, - GladeWidget * widget) -{ - const gchar * new_name; - gchar * prefix, * old_name; - GList * n, * list; - - if (G_OBJECT_TYPE (glade_widget_get_object (widget)) != VN_TYPE_ITERATOR) - return; - - old_name = g_object_get_data (G_OBJECT (widget), "old-name"); - prefix = g_strconcat (old_name, "-", NULL); - new_name = glade_widget_get_name (widget); - g_object_set_data_full (G_OBJECT (widget), "old-name", - g_strdup (new_name), (GDestroyNotify) g_free); - - list = db_iterator_get_params (DB_ITERATOR (glade_widget_get_object (widget))); - - for (n = list; n; n = n->next) - { - GladeWidget * param = glade_widget_get_from_gobject (G_OBJECT (n->data)); - const gchar * child_name = glade_widget_get_name (param); - - if (g_str_has_prefix (child_name, prefix)) - { - glong offset = g_utf8_strlen (prefix, -1); - gchar * new_child_name = g_strconcat (new_name, "-", child_name + offset, NULL); - glade_project_set_widget_name (project, param, new_child_name); - g_free (new_child_name); - } - } - - g_list_free (list); - g_free (prefix); -} - -void glade_db_iterator_post_create (GladeWidgetAdaptor * adaptor, - DbIterator * iterator, GladeCreateReason * reason) -{ - static gboolean connected = FALSE; - GladeWidget * widget = glade_widget_get_from_gobject (G_OBJECT (iterator)); - GladeProject * project = glade_widget_get_project (widget); - - g_object_set_data_full (G_OBJECT (widget), "old-name", - g_strdup (glade_widget_get_name (widget)), (GDestroyNotify) g_free); - - if (!connected) - { - g_signal_connect (project, "widget-name-changed", - G_CALLBACK (glade_db_iterator_on_name_changed), NULL); - connected = TRUE; - } -} - -static void glade_db_iterator_on_column_name_changed (GladeProperty * property, +static void glade_db_iterator_on_param_col_name_changed (GladeProperty * property, GValue * old, GValue * new, GladeWidget * param) { - const gchar * parent_name; - gchar * prefix; + gchar * name = g_value_dup_string (new); + GladeProject * project; GladeWidget * parent = glade_widget_get_parent (param); - if (!parent + if (!name || name[0] == '\0' || !parent || G_OBJECT_TYPE (glade_widget_get_object (parent)) != VN_TYPE_ITERATOR) return; - parent_name = glade_widget_get_name (parent); - prefix = g_strconcat (parent_name, "-", NULL); - - if (g_str_has_prefix (glade_widget_get_name (param), prefix)) - { - GladeProject * project = glade_widget_get_project (param); - gchar * new_name = g_strconcat (prefix, g_value_get_string (new), NULL); - glade_project_set_widget_name (project, param, new_name); - } - - g_free (prefix); + project = glade_widget_get_project (param); + glade_project_set_widget_name (project, param, g_strdelimit (name, "_", '-')); + g_free (name); } void glade_db_iterator_add_child (GladeWidgetAdaptor * adaptor, DbIterator * parent, DbParam * child) { - gchar * new_name; - const gchar * param_name, * parent_name; GladeWidget * param = glade_widget_get_from_gobject (G_OBJECT (child)); GladeProperty * name_prop = glade_widget_get_property (param, "column-name"); - - param_name = glade_widget_get_name (param); - parent_name = glade_widget_get_name (glade_widget_get_from_gobject (G_OBJECT (parent))); - new_name = g_strconcat (parent_name, "-",param_name, NULL); - glade_project_set_widget_name (glade_widget_get_project (param), param, new_name); - g_free (new_name); g_signal_connect (name_prop, "value-changed", - G_CALLBACK (glade_db_iterator_on_column_name_changed), param); + G_CALLBACK (glade_db_iterator_on_param_col_name_changed), param); - db_iterator_add_param (parent, child); + vn_iterator_add_param (parent, child); } void glade_db_iterator_remove_child (GladeWidgetAdaptor * adaptor, DbIterator * parent, DbParam * child) { -// db_iterator_remove_param (parent, child); + vn_iterator_remove_param (parent, child); } void glade_db_iterator_replace_child (GladeWidgetAdaptor * adaptor, @@ -129,6 +59,21 @@ void glade_db_iterator_replace_child (GladeWidgetAdaptor * adaptor, glade_db_iterator_add_child (adaptor, container, new); } +GList * glade_db_iterator_get_children (GladeWidgetAdaptor * adaptor, + DbIterator * parent) +{ + return vn_iterator_get_params (parent); +} + +static void glade_db_iterator_child_selected (GladeBaseEditor * editor, + GladeWidget * child, gpointer data) +{ + glade_base_editor_add_label (editor, _("Parameter")); + glade_base_editor_add_default_properties (editor, child); + glade_base_editor_add_label (editor, _("Properties")); + glade_base_editor_add_editable (editor, child, GLADE_PAGE_GENERAL); +} + gboolean glade_db_iterator_add_verify (GladeWidgetAdaptor * adaptor, DbIterator * container, DbParam * child, gboolean user_feedback) { @@ -152,28 +97,13 @@ gboolean glade_db_iterator_add_verify (GladeWidgetAdaptor * adaptor, return FALSE; } -GList * glade_db_iterator_get_children (GladeWidgetAdaptor * adaptor, - DbIterator * parent) -{ - return db_iterator_get_params (parent); -} - -static void glade_db_iterator_child_selected (GladeBaseEditor * editor, - GladeWidget * child, gpointer data) -{ - glade_base_editor_add_label (editor, _("Parameter")); - glade_base_editor_add_default_properties (editor, child); - glade_base_editor_add_label (editor, _("Properties")); - glade_base_editor_add_editable (editor, child, GLADE_PAGE_GENERAL); -} - static gboolean glade_db_iterator_move_child (GladeBaseEditor * editor, GladeWidget * parent, GladeWidget * child, gpointer data) { return FALSE; } -static void glade_db_iterator_launch_editor (GObject * iterator) +static void glade_db_iterator_on_launch_editor (GObject * iterator) { GladeBaseEditor * editor; GladeEditable * param_editor; @@ -181,20 +111,21 @@ static void glade_db_iterator_launch_editor (GObject * iterator) GladeWidget * widget = glade_widget_get_from_gobject (iterator); GladeWidgetAdaptor * adaptor = glade_widget_get_adaptor (widget); - widget = glade_widget_get_toplevel (widget); param_editor = glade_widget_adaptor_create_editable (adaptor, GLADE_PAGE_GENERAL); editor = glade_base_editor_new (glade_widget_get_object (widget), param_editor, _("Parameter"), DB_TYPE_PARAM, NULL); - g_signal_connect (editor, "child-selected", G_CALLBACK (glade_db_iterator_child_selected), NULL); - g_signal_connect (editor, "move-child", G_CALLBACK (glade_db_iterator_move_child), NULL); + g_signal_connect (editor, "child-selected", + G_CALLBACK (glade_db_iterator_child_selected), NULL); + g_signal_connect (editor, "move-child", + G_CALLBACK (glade_db_iterator_move_child), NULL); gtk_widget_show (GTK_WIDGET (editor)); window = glade_base_editor_pack_new_window (editor, _("Iterator Editor"), NULL); gtk_widget_show (window); } -static void glade_db_iterator_generate_params (GladeWidget * iterator) +static void glade_db_iterator_on_generate_params (GladeWidget * iterator) { gboolean use_file = TRUE; gchar * sql = NULL; @@ -203,8 +134,8 @@ static void glade_db_iterator_generate_params (GladeWidget * iterator) SqlSelect * select; GladeWidget * model_w; DbModel * model = NULL; - - GList * params = db_iterator_get_params (DB_ITERATOR (glade_widget_get_object (iterator))); + GList * params = vn_iterator_get_params + (DB_ITERATOR (glade_widget_get_object (iterator))); if (params) { @@ -241,30 +172,29 @@ static void glade_db_iterator_generate_params (GladeWidget * iterator) //TODO Cambios cuando se use g_object_get (select, "fields", &fields, NULL) GSList * l, * fields = select->expr; GladeProject * project = glade_widget_get_project (iterator); + fields = g_slist_reverse (fields); for (l = fields; l; l = l->next) { - gchar * column_name; gchar * param_name, * param_new_name = NULL; GladeWidget * param; param = glade_command_create (glade_widget_adaptor_get_by_type (DB_TYPE_PARAM), iterator, NULL, project); - column_name = sql_select_get_column_name (select, SQL_EXPR (l->data)); - param_name = g_strconcat (name, "-" - ,column_name ? column_name : "param" - ,NULL); + param_name = sql_select_get_column_name (select, SQL_EXPR (l->data)); - if (!glade_project_available_widget_name (project, param, param_name)) - param_new_name = glade_project_new_widget_name (project, param, param_name); + if (param_name) + { + if (!glade_project_available_widget_name (project, param, param_name)) + param_new_name = glade_project_new_widget_name (project, param, param_name); - glade_project_set_widget_name (project, param, param_new_name ? param_new_name : param_name); - glade_widget_property_set (param, "column-name", column_name); + glade_project_set_widget_name (project, param, param_new_name ? param_new_name : param_name); + glade_widget_property_set (param, "column-name", param_name); - g_free (column_name); - g_free (param_new_name); - g_free (param_name); + g_free (param_new_name); + g_free (param_name); + } } } } @@ -273,7 +203,75 @@ void glade_db_iterator_action_activate (GladeWidgetAdaptor * adaptor, GObject * object, const gchar * action_path) { if (!g_strcmp0 (action_path, "launch-editor")) - glade_db_iterator_launch_editor (object); + glade_db_iterator_on_launch_editor (object); else if (!g_strcmp0 (action_path, "generate-params")) - glade_db_iterator_generate_params (glade_widget_get_from_gobject (object)); + glade_db_iterator_on_generate_params (glade_widget_get_from_gobject (object)); +} + +// XXX Workaround for an error in Glade while loading child params +static GSList * correction_data = NULL; + +static void clean_correction_data () +{ + GSList * l; + + for (l = correction_data; l; l = l->next) + { + g_free (l->data); + } + g_slist_free (correction_data); + correction_data = NULL; +} + +void glade_db_iterator_read_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, GladeXmlNode * node) +{ + GSList * l; + GList * n, * children; + GladeXmlNode * links_node; + + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; + + GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node); + + if ((links_node = glade_xml_search_child (node, "child")) == NULL) + return; + + // Param name correction + if (!correction_data) + return; + + children = glade_widget_adaptor_get_children (adaptor, + glade_widget_get_object (widget)); + + for (n = children; n; n = n->next) + { + GladeWidget * w = glade_widget_get_from_gobject (G_OBJECT (n->data)); + const gchar * name = glade_widget_get_name (w); + + for (l = correction_data; l; l = l->next) + if (g_str_has_suffix (name, (gchar *)l->data)) + glade_widget_set_name (w, (gchar *) l->data); + } + + clean_correction_data (); +} + +void glade_db_param_read_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, GladeXmlNode * node) +{ + GladeWidget * parent; + + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; + + GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node); + + parent = glade_widget_get_parent (widget); + if (!parent || !DB_IS_ITERATOR (glade_widget_get_object (parent))) + return; + + correction_data = g_slist_prepend (correction_data, + g_strdup (glade_widget_get_name (widget))); } diff --git a/glade/glade-db-model-editor.c b/glade/glade-db-model-editor.c new file mode 100644 index 0000000..95b0dd6 --- /dev/null +++ b/glade/glade-db-model-editor.c @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2014 - Juan Ferrer Toribio + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "glade-db-model-editor.h" + +//+++++++++++++++++++++++++++++++++++++++++++++++++++ GladeModelEditor + +GtkWidget * glade_model_editor_new (GladeWidgetAdaptor * adaptor, + GladeEditable * editable) +{ + GladeModelEditor * obj; + GladeEditorProperty * eprop; + GtkWidget * frame, * alignment, * vbox; + + g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL); + g_return_val_if_fail (GLADE_IS_EDITABLE (editable), NULL); + + obj = g_object_new (GLADE_TYPE_MODEL_EDITOR, NULL); + obj->base = GTK_WIDGET (editable); + gtk_box_pack_start (GTK_BOX (obj), GTK_WIDGET (editable), FALSE, FALSE, 0); + + eprop = glade_widget_adaptor_create_eprop_by_name (adaptor, "links", FALSE, TRUE); + obj->props = g_list_prepend (obj->props, eprop); + + frame = gtk_frame_new (NULL); + gtk_frame_set_label_widget (GTK_FRAME (frame), + glade_editor_property_get_item_label (eprop)); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + gtk_box_pack_start (GTK_BOX (obj), frame, FALSE, FALSE, 12); + + alignment = gtk_alignment_new (0.5F, 0.5F, 1.0F, 1.0F); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 0, 12, 0); + gtk_container_add (GTK_CONTAINER (frame), alignment); + + vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); + gtk_container_add (GTK_CONTAINER (alignment), vbox); + + gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (eprop), FALSE, FALSE, 4); + gtk_widget_set_tooltip_text (vbox, _("List of parameters linked to the model")); + + gtk_widget_show_all (GTK_WIDGET (obj)); + return GTK_WIDGET (obj); +} + +static void glade_model_editor_load (GladeEditable * editable, GladeWidget * widget) +{ + GList *l; + GladeModelEditor * obj = GLADE_MODEL_EDITOR (editable); + GladeEditableIface * iface = g_type_default_interface_peek (GLADE_TYPE_EDITABLE); + iface->load (editable, widget); + + if (obj->base) + glade_editable_load (GLADE_EDITABLE (obj->base), widget); + + for (l = obj->props; l; l = l->next) + glade_editor_property_load_by_widget (GLADE_EDITOR_PROPERTY (l->data), widget); +} + +static void glade_model_editor_set_show_name (GladeEditable * editable, gboolean show_name) +{ + GladeModelEditor * obj = GLADE_MODEL_EDITOR (editable); + glade_editable_set_show_name (GLADE_EDITABLE (obj->base), show_name); +} + +static void glade_model_editor_finalize (GObject * object) +{ + GladeModelEditor * obj = GLADE_MODEL_EDITOR (object); + GObjectClass * parent = g_type_class_peek_parent (GLADE_MODEL_EDITOR_GET_CLASS (obj)); + + if (obj->props) + g_list_free (obj->props); + + obj->props = NULL; + obj->base = NULL; + + glade_editable_load (GLADE_EDITABLE (obj), NULL); + + parent->finalize (G_OBJECT (obj)); +} + +static void glade_model_editor_class_init (GladeModelEditorClass * k) +{ + GObjectClass * klass = G_OBJECT_CLASS (k); + klass->finalize = glade_model_editor_finalize; +} + +static void glade_model_editor_init (GladeModelEditor * obj) +{ +} + +static void glade_model_editor_editable_init (GladeEditableIface * iface) +{ + iface->load = glade_model_editor_load; + iface->set_show_name = glade_model_editor_set_show_name; +} + +G_DEFINE_TYPE_WITH_CODE (GladeModelEditor, glade_model_editor, GTK_TYPE_VBOX, + G_IMPLEMENT_INTERFACE (GLADE_TYPE_EDITABLE, glade_model_editor_editable_init)); + +//+++++++++++++++++++++++++++++++++++++++++++++++++++ GladeDbList + +G_DEFINE_BOXED_TYPE (GladeDbList, glade_db_list, glade_db_list_copy, glade_db_list_free); + +void glade_db_list_free (GladeDbList * list) +{ + if (!list) + return; + + if (list->list) + g_object_unref (list->list); + + g_free (list); + list = NULL; +} + +GladeDbList * glade_db_list_copy (const GladeDbList * list) +{ + GladeDbList * l = g_new (GladeDbList, 1); + l->list = list->list ? g_object_ref (list->list) : NULL; + return l; +} diff --git a/glade/glade-db-model-editor.h b/glade/glade-db-model-editor.h new file mode 100644 index 0000000..f4ea51e --- /dev/null +++ b/glade/glade-db-model-editor.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2014 - Juan Ferrer Toribio + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef GLADE_MODEL_EDITOR_H +#define GLADE_MODEL_EDITOR_H + +#include "glade-vn.h" + +#define GLADE_TYPE_MODEL_EDITOR (glade_model_editor_get_type ()) +#define GLADE_MODEL_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_MODEL_EDITOR, GladeModelEditor)) +#define GLADE_MODEL_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_MODEL_EDITOR, GladeModelEditorClass)) +#define GLADE_IS_MODEL_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_MODEL_EDITOR)) +#define GLADE_IS_MODEL_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_MODEL_EDITOR)) +#define GLADE_MODEL_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_MODEL_EDITOR, GladeModelEditorClass)) + +typedef struct _GladeModelEditor GladeModelEditor; +typedef struct _GladeModelEditorClass GladeModelEditorClass; + +struct _GladeModelEditor +{ + GtkVBox parent; + + GtkWidget * base; + GList * props; +}; + +struct _GladeModelEditorClass +{ + GtkVBoxClass parent; +}; + +GType glade_model_editor_get_type (void) G_GNUC_CONST; +GtkWidget * glade_model_editor_new (GladeWidgetAdaptor * adaptor, + GladeEditable * editable); + +#define GLADE_TYPE_DB_LIST (glade_db_list_get_type()) + +typedef struct _GladeDbList GladeDbList; + +struct _GladeDbList +{ + GtkListStore * list; +}; + +GType glade_db_list_get_type (void) G_GNUC_CONST; +void glade_db_list_free (GladeDbList * list); +GladeDbList * glade_db_list_copy (const GladeDbList * list); + +#endif diff --git a/glade/glade-db-model.c b/glade/glade-db-model.c index 7ddbf9b..1d50e6a 100644 --- a/glade/glade-db-model.c +++ b/glade/glade-db-model.c @@ -16,8 +16,27 @@ */ #include "glade-vn.h" +#include "glade-db-model-editor.h" -//+++++++++++++++++++++++++++++++++++++++++++++++++ DbModel GladeEditorProperty +/* + * Contents of this file: + * definition of the custom property editors for the DbModel properties. + * definition of the SQL statement editor for the "sql" property of the + * DbModel. + * the definition of the param-related properties can be found at their + * own file glade-db-model-links.c and glade-db-model-batch.c + */ + +#ifdef _HAVE_GTKSOURCEVIEW +#include +#include +#include +#include +#endif + +#define NEW_SQL _("New SQL statement") + +//+++++++++++++++++++++++++++++++++++++++++++++++++++ SQL Editor Property typedef struct { @@ -25,332 +44,565 @@ typedef struct GtkWidget * button; GtkWidget * entry; - gboolean connected; - GladeWidget * widget; + gint width; + gint height; } -GladeEPropModel; +GladeEPropSql; -GLADE_MAKE_EPROP (GladeEPropModel, glade_eprop_model) -#define GLADE_TYPE_EPROP_MODEL (glade_eprop_model_get_type()) -#define GLADE_EPROP_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_MODEL, GladeEPropModel)) -#define GLADE_EPROP_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_MODEL, GladeEPropModelClass)) -#define GLADE_IS_EPROP_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_MODEL)) -#define GLADE_IS_EPROP_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_MODEL)) -#define GLADE_EPROP_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_EPROP_MODEL, GladeEPropModelClass)) +GLADE_MAKE_EPROP (GladeEPropSql, glade_eprop_sql) +#define GLADE_TYPE_EPROP_SQL (glade_eprop_sql_get_type()) +#define GLADE_EPROP_SQL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_SQL, GladeEPropSql)) +#define GLADE_EPROP_SQL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_SQL, GladeEPropSqlClass)) +#define GLADE_IS_EPROP_SQL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_SQL)) +#define GLADE_IS_EPROP_SQL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_SQL)) +#define GLADE_EPROP_SQL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_EPROP_SQL, GladeEPropSqlClass)) -static void glade_eprop_model_name_changed (GladeProject * project, - GladeWidget * widget, GladeEPropModel * obj) +static void glade_eprop_sql_show_dialog (GtkButton * button, GladeEditorProperty * eprop) { - if (widget == obj->widget) - gtk_entry_set_text (GTK_ENTRY (obj->entry), glade_widget_get_name (widget)); -} - -static GladeWidget * glade_model_create (GladeProperty * prop) -{ - gboolean use = FALSE; - VnBatch * batch; - GladeWidget * batch_w; - GladeProject * project = glade_widget_get_project (glade_property_get_widget (prop)); - const GList * l, * n, * objects = glade_project_get_objects (project); - - for (n = objects; n; n = n->next) - if (VN_IS_BATCH (n->data)) - { - batch = n->data; - use = TRUE; - - for (l = vn_batch_get_objects (batch); l; l = l->next) - if (!DB_IS_MODEL (l->data)) - { - use = FALSE; - break; - } - - if (use) - break; - } - - if (!use) - { - batch_w = glade_command_create - (glade_widget_adaptor_get_by_type (VN_TYPE_BATCH), NULL, NULL, project); - glade_widget_set_name (batch_w, - glade_project_new_widget_name (project, batch_w, "models")); - } - - else - batch_w = glade_widget_get_from_gobject (batch); - - return glade_command_create - (glade_widget_adaptor_get_by_type (DB_TYPE_MODEL), batch_w, NULL, project); -} - -/* - * glade_eprop_model_show_dialog: - * @button:(allow-none): a #GtkButton or @NULL - * @object: a #GladeEditorPropery or a #GladeWidget - * - * Opens a dialog to edit a #DbModel. - * Can be called by a #GladeEditorProperty or by the "edit" action of a - * #GladeWidgetAdaptor directly (in which case @button is %NULL and @obj is a - * #GladeWidget). - **/ -static void glade_eprop_model_show_dialog (GtkButton * button, GObject * object) -{ - gboolean created = FALSE; - GObject * o; - GtkWidget * box; - GtkDialog * dialog; - GladeWidget * widget; - GladeWidgetAdaptor * adaptor; - GladeEditable * editor; - GladeProperty * p = NULL; - GladeEditorProperty * eprop = NULL; - - if (GLADE_IS_EDITOR_PROPERTY (object)) - { - eprop = GLADE_EDITOR_PROPERTY (object); - p = glade_editor_property_get_property (eprop); - o = g_value_get_object (glade_property_inline_value (p)); - - if (o && DB_IS_MODEL (o)) - widget = glade_widget_get_from_gobject (o); - else - { - GValue val = G_VALUE_INIT; - - glade_command_push_group - (_("Create and set a model for a DbModelHolder")); - - widget = glade_model_create (p); - created = TRUE; - g_value_init (&val, DB_TYPE_MODEL); - g_value_set_object (&val, glade_widget_get_object (widget)); - glade_command_set_property_value (p, &val); - g_value_unset (&val); - - glade_command_pop_group (); - - glade_project_selection_set (glade_widget_get_project (widget), - glade_widget_get_object (glade_property_get_widget (p)), - TRUE); - - if (!GLADE_EPROP_MODEL (eprop)->connected) - { - g_signal_connect (glade_widget_get_project - (glade_property_get_widget (p)), "widget-name-changed", - G_CALLBACK (glade_eprop_model_name_changed), eprop); - GLADE_EPROP_MODEL (eprop)->connected = TRUE; - } - } - } - else - widget = GLADE_WIDGET (object); - - adaptor = glade_widget_get_adaptor (widget); - editor = glade_widget_adaptor_create_editable (adaptor, GLADE_PAGE_GENERAL); - glade_editable_load (editor, widget); - - dialog = GTK_DIALOG (gtk_dialog_new_with_buttons - (eprop ? _("Model configuration") : _("DbModel properties configuration") - ,GTK_WINDOW (glade_app_get_window ()) + gpointer text, buffer; + const gchar * sql; + GladeEPropSql * obj = GLADE_EPROP_SQL (eprop); + PangoFontDescription * font; + GtkWidget * scroll; + GladeProperty * p = glade_editor_property_get_property (eprop); + GtkDialog * dialog = GTK_DIALOG (gtk_dialog_new_with_buttons + (_("SQL Editor") + ,GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (eprop))) ,GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT ,GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL - ,GTK_STOCK_CLEAR, GTK_RESPONSE_REJECT + ,GTK_STOCK_CLEAR, GTK_RESPONSE_REJECT ,GTK_STOCK_OK, GTK_RESPONSE_OK ,NULL )); + gtk_dialog_set_alternative_button_order (dialog, GTK_RESPONSE_OK, GTK_RESPONSE_REJECT, GTK_RESPONSE_CANCEL, -1); gtk_dialog_set_default_response (dialog, GTK_RESPONSE_OK); - gtk_window_set_default_size (GTK_WINDOW (dialog), 400, 300); + gtk_window_set_default_size (GTK_WINDOW (dialog), obj->width, obj->height); - if (!eprop) - gtk_widget_hide (gtk_dialog_get_widget_for_response - (dialog, GTK_RESPONSE_REJECT)); - - box = gtk_alignment_new (0,0,1,1); - gtk_alignment_set_padding (GTK_ALIGNMENT (box), 8, 8, 8, 8); - gtk_container_add (GTK_CONTAINER (box), GTK_WIDGET (editor)); - gtk_widget_show_all (box); + scroll = gtk_scrolled_window_new (gtk_adjustment_new (0,0,0,0,0,0), + gtk_adjustment_new (0,0,0,0,0,0)); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN); + gtk_widget_set_margin_top (scroll, 6); + gtk_widget_set_margin_right (scroll, 6); + gtk_widget_set_margin_bottom (scroll, 6); + gtk_widget_set_margin_left (scroll, 6); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (dialog)), - box, TRUE, TRUE, 0); + scroll, TRUE, TRUE, 6); + +#ifdef _HAVE_GTKSOURCEVIEW + GtkSourceLanguageManager * lm = gtk_source_language_manager_new (); + GtkSourceLanguage * lang = gtk_source_language_manager_get_language (lm, "sql"); + text = gtk_source_view_new (); + gtk_source_view_set_tab_width (text, 4); + gtk_source_view_set_show_line_numbers (text, TRUE); + gtk_source_view_set_highlight_current_line (text, TRUE); + buffer = gtk_text_view_get_buffer (text); + gtk_source_buffer_set_language (buffer, lang); + gtk_source_buffer_set_highlight_matching_brackets (buffer, TRUE); +#else + text = gtk_text_view_new (); + buffer = gtk_text_view_get_buffer (text); +#endif + + font = pango_font_description_from_string ("Monospace"); + gtk_widget_override_font (text, font); + pango_font_description_free (font); + + if ((sql = g_value_get_string (glade_property_inline_value (p)))) + gtk_text_buffer_set_text (buffer, sql, -1); + + gtk_container_add (GTK_CONTAINER (scroll), text); + gtk_widget_show_all (scroll); switch (gtk_dialog_run (dialog)) { case GTK_RESPONSE_OK: { - if (eprop) - { - gtk_entry_set_text (GTK_ENTRY (GLADE_EPROP_MODEL (eprop)->entry), - glade_widget_get_name (widget)); - GLADE_EPROP_MODEL (eprop)->widget = widget; - } + GValue val = G_VALUE_INIT; + GtkTextIter * start = g_new (GtkTextIter, 1), + * end = g_new (GtkTextIter, 1); + g_value_init (&val, G_TYPE_STRING); + gtk_text_buffer_get_bounds (buffer, start, end); + sql = gtk_text_buffer_get_text (buffer, start, end, TRUE); + g_value_set_string (&val, sql); + glade_command_set_property_value (p, &val); + + g_value_unset (&val); + g_free (start); + g_free (end); break; } case GTK_RESPONSE_REJECT: { - if (eprop) - { - glade_command_set_property (p, NULL); - GLADE_EPROP_MODEL (eprop)->widget = NULL; - } - + GValue val = G_VALUE_INIT; + g_value_init (&val, G_TYPE_STRING); + g_value_set_string (&val, ""); + glade_command_set_property_value (p, &val); + g_value_unset (&val); break; } case GTK_RESPONSE_CANCEL: - { - if (created) - { - GList * list = g_list_append (NULL, widget); - GladeWidget * batch = glade_widget_get_parent (widget); - - if (vn_batch_get_length - VN_BATCH (glade_widget_get_object (batch)) == 1) - list = g_list_prepend (list, batch); - - glade_command_delete (list); - g_list_free (list); - GLADE_EPROP_MODEL (eprop)->widget = NULL; - } - - break; - } default: break; } + obj->width = gtk_widget_get_allocated_width (GTK_WIDGET (dialog)); + obj->height = gtk_widget_get_allocated_height (GTK_WIDGET (dialog)); gtk_widget_destroy (GTK_WIDGET (dialog)); } -static void glade_eprop_model_show_object_dialog (GtkButton * button, +static void glade_eprop_sql_entry_text_changed (GtkEntry * entry, GladeEditorProperty * eprop) { + const gchar * text = gtk_entry_get_text (entry); GladeProperty * p = glade_editor_property_get_property (eprop); - // Widget to which the property belongs (e.g. Model Holder) - GladeWidget * widget = glade_property_get_widget (p); - GladeProject * project = glade_widget_get_project (widget); - GObject * object = g_value_get_object (glade_property_inline_value (p)); - // Widget representing the property itself (i.e. DbModel) - widget = object ? glade_widget_get_from_gobject (object) : NULL; - GLADE_EPROP_MODEL (eprop)->widget = widget; - if (glade_editor_property_show_object_dialog (project, - _("Select a DbModel for the property"), NULL, - DB_TYPE_MODEL, NULL, &widget)) + if (text) { - if (widget) - { - GValue val = G_VALUE_INIT; - g_value_init (&val, DB_TYPE_MODEL); - g_value_set_object (&val, glade_widget_get_object (widget)); - glade_command_set_property_value (p, &val); - g_value_unset (&val); - } - else - glade_command_set_property (p, NULL); + GValue val = G_VALUE_INIT; + g_value_init (&val, G_TYPE_STRING); + g_value_set_string (&val, text); + glade_command_set_property_value (p, &val); + g_value_unset (&val); } } -static GtkWidget * glade_eprop_model_create_input (GladeEditorProperty * eprop) +static GtkWidget * glade_eprop_sql_create_input (GladeEditorProperty * eprop) { - GtkWidget * hbox, * box, * object_button; - GladeEPropModel * obj = GLADE_EPROP_MODEL (eprop); + GladeEPropSql * obj = GLADE_EPROP_SQL (eprop); + GtkWidget * box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - obj->button = gtk_button_new_with_label (_("New Model")); - g_signal_connect (G_OBJECT (obj->button), "clicked", - G_CALLBACK (glade_eprop_model_show_dialog), eprop); - - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); obj->entry = gtk_entry_new (); - gtk_editable_set_editable (GTK_EDITABLE (obj->entry), FALSE); gtk_widget_set_hexpand (obj->entry, TRUE); - gtk_container_add (GTK_CONTAINER (hbox), obj->entry); + g_signal_connect (obj->entry, "changed", + G_CALLBACK (glade_eprop_sql_entry_text_changed), obj); + gtk_container_add (GTK_CONTAINER (box), obj->entry); - object_button = gtk_button_new_with_label ("..."); - gtk_container_add (GTK_CONTAINER (hbox), object_button); - g_signal_connect (G_OBJECT (object_button), "clicked", - G_CALLBACK (glade_eprop_model_show_object_dialog), eprop); - - box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - gtk_container_add (GTK_CONTAINER (box), hbox); + obj->button = gtk_button_new_with_label ("..."); + g_signal_connect (obj->button, "clicked", + G_CALLBACK (glade_eprop_sql_show_dialog), obj); + gtk_widget_set_tooltip_text (obj->button, _("Open the SQL Editor")); gtk_container_add (GTK_CONTAINER (box), obj->button); + gtk_widget_show_all (box); - obj->widget = NULL; -/* project = glade_widget_get_project (glade_property_get_widget - (glade_editor_property_get_property (eprop))); - */ + obj->width = 750; + obj->height = 550; return box; } -static void glade_eprop_model_load (GladeEditorProperty * eprop, GladeProperty * property) +static void glade_eprop_sql_load (GladeEditorProperty * eprop, GladeProperty * property) { - gchar * label; - const gchar * text; - GObject * object; + const gchar * sql; + GladeEPropSql * obj = GLADE_EPROP_SQL (eprop); + GladeEditorPropertyClass * parent_class = g_type_class_peek_parent (GLADE_EDITOR_PROPERTY_GET_CLASS (eprop)); parent_class->load (eprop, property); - if (property == NULL) + if (!property) return; - if ((object = g_value_get_object (glade_property_inline_value (property)))) - { - label = _("Edit Model"); - text = glade_widget_get_name (glade_widget_get_from_gobject (object)); - } + if ((sql = g_value_get_string (glade_property_inline_value (property)))) + gtk_entry_set_text (GTK_ENTRY (obj->entry), sql); else - { - label = _("New Model"); - text = ""; - } - - gtk_button_set_label (GTK_BUTTON (GLADE_EPROP_MODEL (eprop)->button), label); - gtk_entry_set_text (GTK_ENTRY (GLADE_EPROP_MODEL (eprop)->entry), text); + gtk_entry_set_text (GTK_ENTRY (obj->entry), ""); } -static void glade_eprop_model_finalize (GObject * object) +static void glade_eprop_sql_finalize (GObject * object) { GObjectClass * parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (object)); G_OBJECT_CLASS (parent_class)->finalize (object); } -//+++++++++++++++++++++++++++++++++++++++++++++++++++ DbModel Action Callback +//+++++++++++++++++++++++++++++++++++++++++++++++++++ Links Editor Property -void glade_db_model_action_activate (GladeWidgetAdaptor * adaptor, - DbModel * model, const gchar * path) +typedef struct { - glade_eprop_model_show_dialog (NULL, - (GObject *) glade_widget_get_from_gobject (model)); + GladeEditorProperty parent; + + GtkTreeView * view; + gchar * path; +} +GladeEPropLinks; + +GLADE_MAKE_EPROP (GladeEPropLinks, glade_eprop_links) +#define GLADE_TYPE_EPROP_LINKS (glade_eprop_links_get_type ()) +#define GLADE_EPROP_LINKS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_LINKS, GladeEPropLinks)) +#define GLADE_EPROP_LINKS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_LINKS, GladeEPropLinksClass)) +#define GLADE_IS_EPROP_LINKS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_LINKS)) +#define GLADE_IS_EPROP_LINKS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_LINKS)) +#define GLADE_EPROP_LINKS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_EPROP_LINKS, GladeEPropLinksClass)) + +enum +{ + FIELD_COL + ,PARAM_COL + ,N_COLS +}; + +static void glade_eprop_links_on_param_col_clicked (GtkEntry * entry, + GtkEntryIconPosition icon_pos, GdkEvent * event, GladeEditorProperty * eprop) +{ + GtkTreeIter iter; + GladeProperty * p = glade_editor_property_get_property (eprop); + GladeWidget * widget = glade_property_get_widget (p); + GladeProject * project = glade_widget_get_project (widget); + GtkListStore * store = ((GladeDbList *) g_value_get_boxed (glade_property_inline_value (p)))->list; + gchar * path = GLADE_EPROP_LINKS (eprop)->path; + + if (!gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), &iter, path)) + return; + + gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, PARAM_COL, &widget, -1); + + if (glade_editor_property_show_object_dialog (project, + _("Select a GvnParam"), NULL, GVN_TYPE_PARAM, NULL, &widget)) + { + if (widget) + gtk_list_store_set (store, &iter, PARAM_COL, widget, -1); + else + gtk_list_store_set (store, &iter, PARAM_COL, NULL, -1); + } } -//++++++++++++++++++++++++++++++++++++++++++++ DbModelHolder GladeWidgetAdaptor +static gboolean glade_eprop_links_on_param_key_pressed (GtkEntry * entry, + GdkEventKey * event, GladeEditorProperty * eprop) +{ + if (event->keyval == GDK_KEY_Return) + { + glade_eprop_links_on_param_col_clicked (entry, 0, NULL, eprop); + return TRUE; + } + else if (event->keyval == GDK_KEY_Delete) + { + GtkTreeIter iter; + gchar * path = GLADE_EPROP_LINKS (eprop)->path; + GladeProperty * p = glade_editor_property_get_property (eprop); + GtkListStore * store = ((GladeDbList *) g_value_get_boxed (glade_property_inline_value (p)))->list; -GladeEditorProperty * glade_db_model_holder_create_eprop (GladeWidgetAdaptor * adaptor, + if (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), &iter, path)) + { + gtk_list_store_set (store, &iter, PARAM_COL, NULL, -1); + return TRUE; + } + } + return FALSE; +} + +void param_col_cell_data (GtkTreeViewColumn * view, GtkCellRenderer * cell, + GtkTreeModel * model, GtkTreeIter * iter, gpointer data) +{ + GladeWidget * param; + gtk_tree_model_get (model, iter, PARAM_COL, ¶m, -1); + + if (param) + g_object_set (cell, "text", glade_widget_get_name (param), NULL); + else + { + g_object_set (cell, "text", "", NULL); + } +} + +static void glade_eporp_links_on_param_col_editing_started (GtkCellRendererText * cell, + GtkEntry * entry, gchar * path, GladeEditorProperty * eprop) +{ + GladeEPropLinks * obj = GLADE_EPROP_LINKS (eprop); + + if (GTK_IS_ENTRY (entry)) + { + GList * n; + gboolean have_params = FALSE; + GladeProperty * p = glade_editor_property_get_property (eprop); + GladeProject * project = glade_widget_get_project + (glade_property_get_widget (p)); + GList * objects = (GList *) glade_project_get_objects (project); + + for (n = objects; n; n = n->next) + if ((have_params = GVN_IS_PARAM (n->data))) + break; + + if (have_params) + { + g_object_set (entry + ,"secondary-icon-name", "content-loading-symbolic" + ,"secondary-icon-sensitive", TRUE + ,"secondary-icon-tooltip-text", _("Select the parameter from a list") + ,NULL); + + if (obj->path) + g_free (obj->path); + + obj->path = g_strdup (path); + + g_signal_connect (entry, "icon-press", + G_CALLBACK (glade_eprop_links_on_param_col_clicked), eprop); + g_signal_connect (entry, "key-press-event", + G_CALLBACK (glade_eprop_links_on_param_key_pressed), eprop); + } + else + { + g_object_set (entry + ,"secondary-icon-name", "dialog-warning-symbolic" + ,"secondary-icon-sensitive", FALSE + ,"secondary-icon-tooltip-text", _("You need to create at least " + "one GvnParam or derived object") + ,NULL); + g_signal_handlers_disconnect_by_data (entry, eprop); + } + + g_object_set (entry + ,"editable", FALSE + ,NULL); + } +} + +static void glade_eporp_links_on_field_col_edited (GtkCellRendererText * cell, + gchar * path, const gchar * text, GladeEditorProperty * eprop) +{ + GtkTreeIter iter; + GladeProperty * p = glade_editor_property_get_property (eprop); + GladeDbList * list = g_value_get_boxed (glade_property_inline_value (p)); + GtkListStore * store = list->list; + + if (!gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), &iter, path)) + return; + + gtk_list_store_set (store, &iter, FIELD_COL, text, -1); +} + +static void glade_widget_on_remove_widget (GladeProject * project, + GladeWidget * widget, GtkListStore * store) +{ + if (g_type_is_a (G_OBJECT_TYPE (glade_widget_get_object (widget)), GVN_TYPE_PARAM)) + { + GtkTreeIter iter; + GtkTreeModel * m = GTK_TREE_MODEL (store); + + if (gtk_tree_model_get_iter_first (m, &iter)) + do + { + GladeWidget * param; + gtk_tree_model_get (m, &iter, PARAM_COL, ¶m, -1); + + if (param == widget) + gtk_list_store_set (store, &iter, PARAM_COL, NULL, -1); + } + while (gtk_tree_model_iter_next (m, &iter)); + } +} + +static void glade_eporp_links_on_add_clicked (GtkButton * button, + GladeEPropLinks * obj) +{ + GtkTreeIter iter; + GtkTreePath * path; + GladeDbList * list; + GtkListStore * store; + GladeProperty * p = glade_editor_property_get_property (GLADE_EDITOR_PROPERTY (obj)); + + if (!(list = g_value_get_boxed (glade_property_inline_value (p)))) + { + list = g_new (GladeDbList, 1); + list->list = gtk_list_store_new (N_COLS, G_TYPE_STRING, GLADE_TYPE_WIDGET); + glade_property_set (p, list); + + g_signal_connect (glade_widget_get_project (glade_property_get_widget (p)), + "remove-widget", G_CALLBACK (glade_widget_on_remove_widget), list->list); + } + + store = list->list; + gtk_tree_view_set_model (obj->view, GTK_TREE_MODEL (store)); + + gtk_list_store_append (store, &iter); + path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter); + + gtk_tree_view_scroll_to_cell (obj->view, path, NULL, FALSE, 0, 0); + gtk_tree_view_set_cursor (obj->view, path, NULL, TRUE); + gtk_widget_grab_focus (GTK_WIDGET (obj->view)); + + gtk_tree_path_free (path); +} + +static void glade_eporp_links_on_remove_clicked (GtkButton * button, + GladeEPropLinks * obj) +{ + GtkTreeIter iter; + GtkListStore * store; + GtkTreeSelection * selection = gtk_tree_view_get_selection (obj->view); + GladeProperty * p; + + if (!gtk_tree_selection_get_selected (selection, (GtkTreeModel **) &store, &iter)) + return; + + p = glade_editor_property_get_property (GLADE_EDITOR_PROPERTY (obj)); + gtk_list_store_remove (store, &iter); + + if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter)) + { + gtk_tree_view_set_model (obj->view, NULL); + glade_command_set_property (p, NULL); + + g_signal_handlers_disconnect_by_func ( + glade_widget_get_project (glade_property_get_widget (p)), + glade_widget_on_remove_widget, store); + } +} + +static gboolean glade_eprop_links_on_view_key_press (GtkWidget * treeview, + GdkEventKey * event, GladeEPropLinks * obj) +{ + if (event->keyval == GDK_KEY_Delete) + { + glade_eporp_links_on_remove_clicked (NULL, obj); + return TRUE; + } + else if ((event->state & GDK_CONTROL_MASK) != 0 + && (event->keyval == GDK_KEY_n || event->keyval == GDK_KEY_N)) + { + glade_eporp_links_on_add_clicked (NULL, obj); + return TRUE; + } + + return FALSE; +} + +static GtkWidget * glade_eprop_links_create_input (GladeEditorProperty * eprop) +{ + GtkCellRenderer * cell; + GtkTreeViewColumn * column; + GladeEPropLinks * obj = GLADE_EPROP_LINKS (eprop); + GtkWidget * scroll, * button, * label, + * hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4), + * box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2); + + label = gtk_label_new (_("Add or remove links")); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + gtk_misc_set_padding (GTK_MISC (label), 2, 4); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + + button = gtk_button_new (); + gtk_button_set_image (GTK_BUTTON (button), + gtk_image_new_from_icon_name ("list-add", GTK_ICON_SIZE_BUTTON)); + g_signal_connect (button, "clicked", + G_CALLBACK (glade_eporp_links_on_add_clicked), obj); + gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); + + button = gtk_button_new (); + gtk_button_set_image (GTK_BUTTON (button), + gtk_image_new_from_icon_name ("list-remove", GTK_ICON_SIZE_BUTTON)); + g_signal_connect (button, "clicked", + G_CALLBACK (glade_eporp_links_on_remove_clicked), obj); + gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); + + gtk_box_pack_start (GTK_BOX (box), hbox, FALSE, FALSE, 0); + + scroll = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_box_pack_start (GTK_BOX (box), scroll, TRUE, TRUE, 0); + + obj->view = GTK_TREE_VIEW (gtk_tree_view_new ()); + gtk_tree_view_set_grid_lines (obj->view, GTK_TREE_VIEW_GRID_LINES_BOTH); + g_signal_connect (obj->view, "key-press-event", + G_CALLBACK (glade_eprop_links_on_view_key_press), obj); + gtk_container_add (GTK_CONTAINER (scroll), GTK_WIDGET (obj->view)); + + cell = gtk_cell_renderer_text_new (); + g_object_set (cell, "editable", TRUE, NULL); + column = gtk_tree_view_column_new_with_attributes (_("Column"), cell, + "text", FIELD_COL, NULL); + gtk_tree_view_column_set_expand (column, TRUE); + g_signal_connect (cell, "edited", + G_CALLBACK (glade_eporp_links_on_field_col_edited), obj); + gtk_tree_view_append_column (obj->view, column); + + cell = gtk_cell_renderer_text_new (); + g_object_set (cell, "editable", TRUE, NULL); + column = gtk_tree_view_column_new_with_attributes (_("Param"), cell, NULL); + gtk_tree_view_column_set_cell_data_func (column, cell, param_col_cell_data, obj, NULL); + gtk_tree_view_column_set_expand (column, TRUE); + g_signal_connect (cell, "editing-started", + G_CALLBACK (glade_eporp_links_on_param_col_editing_started), obj); + gtk_tree_view_append_column (obj->view, column); + + g_object_set (G_OBJECT (box), "height-request", 200, NULL); + gtk_widget_show_all (box); + return box; +} + +static void glade_eprop_links_finalize (GObject * object) +{ + GladeEPropLinks * obj = GLADE_EPROP_LINKS (object); + GObjectClass * parent = + g_type_class_peek_parent (GLADE_EPROP_LINKS_GET_CLASS (obj)); + parent->finalize (G_OBJECT (obj)); +} + +static void glade_eprop_links_load (GladeEditorProperty * eprop, GladeProperty * property) +{ + GladeDbList * list; + GladeEPropLinks * obj = GLADE_EPROP_LINKS (eprop); + GladeEditorPropertyClass * parent_class = + g_type_class_peek_parent (GLADE_EDITOR_PROPERTY_GET_CLASS (eprop)); + parent_class->load (eprop, property); + + if (!property) + return; + + if ((list = g_value_get_boxed (glade_property_inline_value (property)))) + gtk_tree_view_set_model (obj->view, GTK_TREE_MODEL (list->list)); + else + gtk_tree_view_set_model (obj->view, NULL); +} + +//++++++++++++++++++++++++++++++++++++++++++++++++++ DbModel Widget Adaptor + +GladeEditorProperty * glade_db_model_create_eprop (GladeWidgetAdaptor * adaptor, GladePropertyClass * klass, gboolean use_command) { GladeEditorProperty * eprop; GParamSpec * pspec = glade_property_class_get_pspec (klass); - if (pspec->value_type == DB_TYPE_MODEL) - { - eprop = g_object_new (GLADE_TYPE_EPROP_MODEL, + if (!g_strcmp0 (pspec->name, "sql")) + eprop = g_object_new (GLADE_TYPE_EPROP_SQL, + "property-class", klass, + "use-command", use_command, NULL); + else if (pspec->value_type == GLADE_TYPE_DB_LIST) + eprop = g_object_new (GLADE_TYPE_EPROP_LINKS, "property-class", klass, "use-command", use_command, NULL); - } else - eprop = GWA_GET_CLASS (G_TYPE_OBJECT)->create_eprop (adaptor, klass, use_command); + eprop = GWA_GET_CLASS (G_TYPE_OBJECT)->create_eprop (adaptor, + klass, use_command); return eprop; } +GladeEditable * glade_db_model_create_editable (GladeWidgetAdaptor * adaptor, + GladeEditorPageType type) +{ + GladeEditable * editable = + GWA_GET_CLASS (G_TYPE_OBJECT)->create_editable (adaptor, type); + + if (type == GLADE_PAGE_GENERAL) + return GLADE_EDITABLE (glade_model_editor_new (adaptor, editable)); + + return editable; +} + void glade_db_model_write_widget (GladeWidgetAdaptor * adaptor, GladeWidget * widget, GladeXmlContext * context, GladeXmlNode * node) { + GtkTreeIter iter; + GladeDbList * l; + GtkTreeModel * m; + GladeXmlNode * links_node; GladeProperty * prop; if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) @@ -363,4 +615,123 @@ void glade_db_model_write_widget (GladeWidgetAdaptor * adaptor, glade_property_write (prop, context, node); GWA_GET_CLASS (G_TYPE_OBJECT)->write_widget (adaptor, widget, context, node); + + prop = glade_widget_get_property (widget, "links"); +// Custom tag for the "links" property, e.g.: +// +// +// + if (!(l = g_value_get_boxed (glade_property_inline_value (prop)))) + return; + + m = GTK_TREE_MODEL (l->list); + + if (!gtk_tree_model_get_iter_first (m, &iter)) + return; + + links_node = glade_xml_node_new (context, "links"); + + do + { + gchar * field; + GladeWidget * param; + GladeXmlNode * link_node; + + gtk_tree_model_get (m, &iter, FIELD_COL, &field, PARAM_COL, ¶m, -1); + + link_node = glade_xml_node_new (context, "link"); + glade_xml_node_append_child (links_node, link_node); + glade_xml_node_set_property_string (link_node, "field", + field ? field : ""); + glade_xml_node_set_property_string (link_node, "param", + param ? glade_widget_get_name (param) : ""); + + g_free (field); + } + while (gtk_tree_model_iter_next (m, &iter)); + + if (!glade_xml_node_get_children (links_node)) + glade_xml_node_delete (links_node); + else + glade_xml_node_append_child (node, links_node); +} + +typedef struct +{ + GtkListStore * store; + GtkTreeIter * iter; + gchar * param_name; +} +ParseData; + +void glade_db_model_on_parse_finished (GladeProject * p, ParseData * pd) +{ + GladeWidget * param = glade_project_get_widget_by_name (p, pd->param_name); + + gtk_list_store_set (pd->store, pd->iter, PARAM_COL, param, -1); + + g_object_unref (pd->store); + gtk_tree_iter_free (pd->iter); + g_free (pd->param_name); + g_free (pd); +} + +void glade_db_model_read_widget (GladeWidgetAdaptor * adaptor, + GladeWidget * widget, GladeXmlNode * node) +{ + GladeXmlNode * links_node; + GladeProperty * prop; + GladeProject * proj; + GladeDbList * list; + GtkListStore * store; + + if (!glade_xml_node_verify (node, GLADE_XML_TAG_WIDGET)) + return; + + GWA_GET_CLASS (G_TYPE_OBJECT)->read_widget (adaptor, widget, node); + + if ((links_node = glade_xml_search_child (node, "links")) == NULL) + return; + + proj = glade_widget_get_project (widget); + list = g_new (GladeDbList, 1); + store = gtk_list_store_new (N_COLS, G_TYPE_STRING, GLADE_TYPE_WIDGET); + list->list = store; + + for (links_node = glade_xml_node_get_children (links_node); links_node; + links_node = glade_xml_node_next (links_node)) + { + GtkTreeIter iter; + gint col = PARAM_COL; + gchar * field = glade_xml_get_property_string (links_node, "field"), + * param_name = glade_xml_get_property_string (links_node, "param"); + GladeWidget * param = glade_project_get_widget_by_name (proj, param_name); + + gtk_list_store_append (store, &iter); + + if (!param) + { + ParseData * pd; + pd = g_new (ParseData, 1); + pd->store = g_object_ref (store); + pd->iter = gtk_tree_iter_copy (&iter); + pd->param_name = g_strdup (param_name); + + g_signal_connect (proj, "parse-finished", + G_CALLBACK (glade_db_model_on_parse_finished), pd); + + col = -1; + } + + gtk_list_store_set (store, &iter + ,FIELD_COL, field + ,col, param + ,-1); + + g_free (field); + g_free (param_name); + } + + prop = glade_widget_get_property (widget, "links"); + glade_property_set (prop, list); } diff --git a/glade/glade-db-sql.c b/glade/glade-db-sql.c deleted file mode 100644 index e65d2d2..0000000 --- a/glade/glade-db-sql.c +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright (C) 2013 - Juan Ferrer Toribio - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "glade-vn.h" - -#ifdef _HAVE_GTKSOURCEVIEW -#include -#include -#include -#include -#endif - -#define NEW_SQL _("New SQL statement") - -//+++++++++++++++++++++++++++++++++++++++++++++++++++ GladeEPropSql - -typedef struct -{ - GladeEditorProperty parent; - - GtkWidget * button; - GtkWidget * entry; - gint width; - gint height; -} -GladeEPropSql; - -GLADE_MAKE_EPROP (GladeEPropSql, glade_eprop_sql) -#define GLADE_TYPE_EPROP_SQL (glade_eprop_sql_get_type()) -#define GLADE_EPROP_SQL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_SQL, GladeEPropSql)) -#define GLADE_EPROP_SQL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_SQL, GladeEPropSqlClass)) -#define GLADE_IS_EPROP_SQL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_SQL)) -#define GLADE_IS_EPROP_SQL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_SQL)) -#define GLADE_EPROP_SQL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_EPROP_SQL, GladeEPropSqlClass)) - -static void glade_eprop_sql_show_dialog (GtkButton * button, GladeEditorProperty * eprop) -{ - gpointer text, buffer; - const gchar * sql; - GladeEPropSql * obj = GLADE_EPROP_SQL (eprop); - PangoFontDescription * font; - GtkWidget * scroll; - GladeProperty * p = glade_editor_property_get_property (eprop); - GtkDialog * dialog = GTK_DIALOG (gtk_dialog_new_with_buttons - (_("SQL Editor") - ,GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (eprop))) - ,GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT - ,GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL - ,GTK_STOCK_CLEAR, GTK_RESPONSE_REJECT - ,GTK_STOCK_OK, GTK_RESPONSE_OK - ,NULL - )); - - gtk_dialog_set_alternative_button_order (dialog, - GTK_RESPONSE_OK, GTK_RESPONSE_REJECT, GTK_RESPONSE_CANCEL, -1); - gtk_dialog_set_default_response (dialog, GTK_RESPONSE_OK); - gtk_window_set_default_size (GTK_WINDOW (dialog), obj->width, obj->height); - - scroll = gtk_scrolled_window_new (gtk_adjustment_new (0,0,0,0,0,0), - gtk_adjustment_new (0,0,0,0,0,0)); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN); - gtk_widget_set_margin_top (scroll, 6); - gtk_widget_set_margin_right (scroll, 6); - gtk_widget_set_margin_bottom (scroll, 6); - gtk_widget_set_margin_left (scroll, 6); - gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (dialog)), - scroll, TRUE, TRUE, 6); - -#ifdef _HAVE_GTKSOURCEVIEW - GtkSourceLanguageManager * lm = gtk_source_language_manager_new (); - GtkSourceLanguage * lang = gtk_source_language_manager_get_language (lm, "sql"); - text = gtk_source_view_new (); - gtk_source_view_set_tab_width (text, 4); - gtk_source_view_set_show_line_numbers (text, TRUE); - gtk_source_view_set_highlight_current_line (text, TRUE); - buffer = gtk_text_view_get_buffer (text); - gtk_source_buffer_set_language (buffer, lang); - gtk_source_buffer_set_highlight_matching_brackets (buffer, TRUE); -#else - text = gtk_text_view_new (); - buffer = gtk_text_view_get_buffer (text); -#endif - - font = pango_font_description_from_string ("Monospace"); - gtk_widget_override_font (text, font); - pango_font_description_free (font); - - sql = g_value_get_string (glade_property_inline_value (p)); - - if (sql) - gtk_text_buffer_set_text (buffer, sql, -1); - - gtk_container_add (GTK_CONTAINER (scroll), text); - gtk_widget_show_all (scroll); - - switch (gtk_dialog_run (dialog)) - { - case GTK_RESPONSE_OK: - { - GValue val = G_VALUE_INIT; - GtkTextIter * start = g_new (GtkTextIter, 1), - * end = g_new (GtkTextIter, 1); - g_value_init (&val, G_TYPE_STRING); - gtk_text_buffer_get_bounds (buffer, start, end); - - sql = gtk_text_buffer_get_text (buffer, start, end, TRUE); - g_value_set_string (&val, sql); - glade_command_set_property_value (p, &val); - - g_value_unset (&val); - g_free (start); - g_free (end); - break; - } - case GTK_RESPONSE_REJECT: - { - GValue val = G_VALUE_INIT; - g_value_init (&val, G_TYPE_STRING); - g_value_set_string (&val, ""); - glade_command_set_property_value (p, &val); - g_value_unset (&val); - break; - } - case GTK_RESPONSE_CANCEL: - default: - break; - } - - obj->width = gtk_widget_get_allocated_width (GTK_WIDGET (dialog)); - obj->height = gtk_widget_get_allocated_height (GTK_WIDGET (dialog)); - gtk_widget_destroy (GTK_WIDGET (dialog)); -} - -static void glade_eprop_sql_entry_text_changed (GtkEntry * entry, - GladeEditorProperty * eprop) -{ - const gchar * text = gtk_entry_get_text (entry); - GladeProperty * p = glade_editor_property_get_property (eprop); - - if (text) - { - GValue val = G_VALUE_INIT; - g_value_init (&val, G_TYPE_STRING); - g_value_set_string (&val, text); - - glade_command_set_property_value (p, &val); - - g_value_unset (&val); - } -} - -static GtkWidget * glade_eprop_sql_create_input (GladeEditorProperty * eprop) -{ - GladeEPropSql * obj = GLADE_EPROP_SQL (eprop); - GtkWidget * box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - - obj->entry = gtk_entry_new (); - gtk_widget_set_hexpand (obj->entry, TRUE); - g_signal_connect (obj->entry, "changed", - G_CALLBACK (glade_eprop_sql_entry_text_changed), obj); - gtk_container_add (GTK_CONTAINER (box), obj->entry); - - obj->button = gtk_button_new_with_label ("..."); - g_signal_connect (obj->button, "clicked", - G_CALLBACK (glade_eprop_sql_show_dialog), obj); - gtk_widget_set_tooltip_text (obj->button, _("Open the SQL Editor")); - gtk_container_add (GTK_CONTAINER (box), obj->button); - - gtk_widget_show_all (box); - - obj->width = 750; - obj->height = 550; - - return box; -} - -static void glade_eprop_sql_load (GladeEditorProperty * eprop, GladeProperty * property) -{ - const gchar * sql; - GladeEPropSql * obj = GLADE_EPROP_SQL (eprop); - - GladeEditorPropertyClass * parent_class = - g_type_class_peek_parent (GLADE_EDITOR_PROPERTY_GET_CLASS (eprop)); - parent_class->load (eprop, property); - - if (!property) - return; - - if ((sql = g_value_get_string (glade_property_inline_value (property)))) - gtk_entry_set_text (GTK_ENTRY (obj->entry), sql); -} - -static void glade_eprop_sql_finalize (GObject * object) -{ - GObjectClass * parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (object)); - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -//++++++++++++++++++++++++++++++++++++++++++++++++++ DbModel GladeWidgetAdaptor - -GladeEditorProperty * glade_db_sql_create_eprop (GladeWidgetAdaptor * adaptor, - GladePropertyClass * klass, gboolean use_command) -{ - GladeEditorProperty * eprop; - GParamSpec * pspec = glade_property_class_get_pspec (klass); - - if (!g_strcmp0 (pspec->name, "sql")) - { - eprop = g_object_new (GLADE_TYPE_EPROP_SQL, - "property-class", klass, - "use-command", use_command, NULL); - } - else - eprop = GWA_GET_CLASS (G_TYPE_OBJECT)->create_eprop (adaptor, klass, use_command); - - return eprop; -} diff --git a/glade/glade-eprop-model.c b/glade/glade-eprop-model.c new file mode 100644 index 0000000..acdaef9 --- /dev/null +++ b/glade/glade-eprop-model.c @@ -0,0 +1,354 @@ +/* + * Copyright (C) 2013 - Juan Ferrer Toribio + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "glade-vn.h" +#include + +/* + * Contents of this file: + * definition of the DbModel editor as a property for objects implementing + * the DbModelHolder interface. + */ + +//+++++++++++++++++++++++++++++++++++++++++++++++++ DbModel GladeEditorProperty + +typedef struct +{ + GladeEditorProperty parent; + + GtkWidget * button; + GtkWidget * entry; + gboolean connected; + GladeWidget * widget; +} +GladeEPropModel; + +GLADE_MAKE_EPROP (GladeEPropModel, glade_eprop_model) +#define GLADE_TYPE_EPROP_MODEL (glade_eprop_model_get_type()) +#define GLADE_EPROP_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_EPROP_MODEL, GladeEPropModel)) +#define GLADE_EPROP_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_EPROP_MODEL, GladeEPropModelClass)) +#define GLADE_IS_EPROP_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_EPROP_MODEL)) +#define GLADE_IS_EPROP_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_EPROP_MODEL)) +#define GLADE_EPROP_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_EPROP_MODEL, GladeEPropModelClass)) + +static void glade_eprop_model_name_changed (GladeProject * project, + GladeWidget * widget, GladeEPropModel * obj) +{ + if (widget == obj->widget) + gtk_entry_set_text (GTK_ENTRY (obj->entry), glade_widget_get_name (widget)); +} + +static GladeWidget * glade_model_create (GladeProperty * prop) +{ + gboolean use = FALSE; + VnBatch * batch; + GladeWidget * batch_w; + GladeProject * project = glade_widget_get_project (glade_property_get_widget (prop)); + const GList * l, * n, * objects = glade_project_get_objects (project); + + for (n = objects; n; n = n->next) + if (VN_IS_BATCH (n->data)) + { + batch = n->data; + use = TRUE; + + for (l = vn_batch_get_objects (batch); l; l = l->next) + if (!DB_IS_MODEL (l->data)) + { + use = FALSE; + break; + } + + if (use) + break; + } + + if (!use) + { + batch_w = glade_command_create + (glade_widget_adaptor_get_by_type (VN_TYPE_BATCH), NULL, NULL, project); + glade_widget_set_name (batch_w, + glade_project_new_widget_name (project, batch_w, "models")); + } + else + batch_w = glade_widget_get_from_gobject (batch); + + return glade_command_create + (glade_widget_adaptor_get_by_type (VN_TYPE_MODEL), batch_w, NULL, project); +} + +/* + * glade_eprop_model_show_dialog: + * @button:(allow-none): a #GtkButton or @NULL + * @object: a #GladeEditorPropery or a #GladeWidget + * + * Opens a dialog to edit a #DbModel. + * Can be called by a #GladeEditorProperty or by the "edit" action of a + * #GladeWidgetAdaptor directly (in which case @button is %NULL and @obj is a + * #GladeWidget). + **/ +static void glade_eprop_model_show_dialog (GtkButton * button, GObject * object) +{ + gboolean created = FALSE; + GObject * o; + GtkWidget * box; + GtkDialog * dialog; + GladeWidget * widget; + GladeWidgetAdaptor * adaptor; + GladeEditable * editor; + GladeProperty * p = NULL; + GladeEditorProperty * eprop = NULL; + + if (GLADE_IS_EDITOR_PROPERTY (object)) + { + eprop = GLADE_EDITOR_PROPERTY (object); + p = glade_editor_property_get_property (eprop); + o = g_value_get_object (glade_property_inline_value (p)); + + if (o && DB_IS_MODEL (o)) + widget = glade_widget_get_from_gobject (o); + else + { + GValue val = G_VALUE_INIT; + + glade_command_push_group + (_("Create and set a model for a DbModelHolder")); + + widget = glade_model_create (p); + created = TRUE; + g_value_init (&val, DB_TYPE_MODEL); + g_value_set_object (&val, glade_widget_get_object (widget)); + glade_command_set_property_value (p, &val); + g_value_unset (&val); + + glade_command_pop_group (); + + glade_project_selection_set (glade_widget_get_project (widget), + glade_widget_get_object (glade_property_get_widget (p)), + TRUE); + + if (!GLADE_EPROP_MODEL (eprop)->connected) + { + g_signal_connect (glade_widget_get_project + (glade_property_get_widget (p)), "widget-name-changed", + G_CALLBACK (glade_eprop_model_name_changed), eprop); + GLADE_EPROP_MODEL (eprop)->connected = TRUE; + } + } + } + else + widget = GLADE_WIDGET (object); + + adaptor = glade_widget_get_adaptor (widget); + editor = glade_widget_adaptor_create_editable (adaptor, GLADE_PAGE_GENERAL); + glade_editable_load (editor, widget); + + dialog = GTK_DIALOG (gtk_dialog_new_with_buttons + (eprop ? _("Model configuration") : _("Model properties configuration") + ,GTK_WINDOW (glade_app_get_window ()) + ,GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT + ,GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL + ,GTK_STOCK_CLEAR, GTK_RESPONSE_REJECT + ,GTK_STOCK_OK, GTK_RESPONSE_OK + ,NULL + )); + gtk_dialog_set_alternative_button_order (dialog, + GTK_RESPONSE_OK, GTK_RESPONSE_REJECT, GTK_RESPONSE_CANCEL, -1); + gtk_dialog_set_default_response (dialog, GTK_RESPONSE_OK); + gtk_window_set_default_size (GTK_WINDOW (dialog), 400, 300); + + if (!eprop) + gtk_widget_hide (gtk_dialog_get_widget_for_response + (dialog, GTK_RESPONSE_REJECT)); + + box = gtk_alignment_new (0,0,1,1); + gtk_alignment_set_padding (GTK_ALIGNMENT (box), 8, 8, 8, 8); + gtk_container_add (GTK_CONTAINER (box), GTK_WIDGET (editor)); + gtk_widget_show_all (box); + gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (dialog)), + box, TRUE, TRUE, 0); + + switch (gtk_dialog_run (dialog)) + { + case GTK_RESPONSE_OK: + { + if (eprop) + { + gtk_entry_set_text (GTK_ENTRY (GLADE_EPROP_MODEL (eprop)->entry), + glade_widget_get_name (widget)); + GLADE_EPROP_MODEL (eprop)->widget = widget; + } + + break; + } + case GTK_RESPONSE_REJECT: + { + if (eprop) + { + glade_command_set_property (p, NULL); + GLADE_EPROP_MODEL (eprop)->widget = NULL; + } + + break; + } + case GTK_RESPONSE_CANCEL: + { + if (created) + { + GList * list = g_list_append (NULL, widget); + GladeWidget * batch = glade_widget_get_parent (widget); + + if (vn_batch_get_length + VN_BATCH (glade_widget_get_object (batch)) == 1) + list = g_list_prepend (list, batch); + + glade_command_delete (list); + g_list_free (list); + GLADE_EPROP_MODEL (eprop)->widget = NULL; + } + + break; + } + default: + break; + } + + gtk_widget_destroy (GTK_WIDGET (dialog)); +} + +static void glade_eprop_model_show_object_dialog (GtkButton * button, + GladeEditorProperty * eprop) +{ + GladeProperty * p = glade_editor_property_get_property (eprop); + // Widget to which the property belongs (e.g. Model Holder) + GladeWidget * widget = glade_property_get_widget (p); + GladeProject * project = glade_widget_get_project (widget); + GObject * object = g_value_get_object (glade_property_inline_value (p)); + // Widget representing the property itself (i.e. VnModel) + widget = object ? glade_widget_get_from_gobject (object) : NULL; + GLADE_EPROP_MODEL (eprop)->widget = widget; + + if (glade_editor_property_show_object_dialog (project, + _("Select a VnModel for the property"), NULL, + DB_TYPE_MODEL, NULL, &widget)) + { + if (widget) + { + GValue val = G_VALUE_INIT; + g_value_init (&val, DB_TYPE_MODEL); + g_value_set_object (&val, glade_widget_get_object (widget)); + glade_command_set_property_value (p, &val); + g_value_unset (&val); + } + else + glade_command_set_property (p, NULL); + } +} + +static GtkWidget * glade_eprop_model_create_input (GladeEditorProperty * eprop) +{ + GtkWidget * hbox, * box, * object_button; + GladeEPropModel * obj = GLADE_EPROP_MODEL (eprop); + + obj->button = gtk_button_new_with_label (_("New Model")); + g_signal_connect (G_OBJECT (obj->button), "clicked", + G_CALLBACK (glade_eprop_model_show_dialog), eprop); + + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + obj->entry = gtk_entry_new (); + gtk_editable_set_editable (GTK_EDITABLE (obj->entry), FALSE); + gtk_widget_set_hexpand (obj->entry, TRUE); + gtk_container_add (GTK_CONTAINER (hbox), obj->entry); + + object_button = gtk_button_new_with_label ("..."); + gtk_container_add (GTK_CONTAINER (hbox), object_button); + g_signal_connect (G_OBJECT (object_button), "clicked", + G_CALLBACK (glade_eprop_model_show_object_dialog), eprop); + + box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); + gtk_container_add (GTK_CONTAINER (box), hbox); + gtk_container_add (GTK_CONTAINER (box), obj->button); + gtk_widget_show_all (box); + + obj->widget = NULL; +/* project = glade_widget_get_project (glade_property_get_widget + (glade_editor_property_get_property (eprop))); +*/ + return box; +} + +static void glade_eprop_model_load (GladeEditorProperty * eprop, GladeProperty * property) +{ + gchar * label; + const gchar * text; + GObject * object; + GladeEditorPropertyClass * parent_class = + g_type_class_peek_parent (GLADE_EDITOR_PROPERTY_GET_CLASS (eprop)); + parent_class->load (eprop, property); + + if (property == NULL) + return; + + if ((object = g_value_get_object (glade_property_inline_value (property)))) + { + label = _("Edit Model"); + text = glade_widget_get_name (glade_widget_get_from_gobject (object)); + } + else + { + label = _("New Model"); + text = ""; + } + + gtk_button_set_label (GTK_BUTTON (GLADE_EPROP_MODEL (eprop)->button), label); + gtk_entry_set_text (GTK_ENTRY (GLADE_EPROP_MODEL (eprop)->entry), text); +} + +static void glade_eprop_model_finalize (GObject * object) +{ + GObjectClass * parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (object)); + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +//++++++++++++++++++++++++++++++++++++++++++++ DbModelHolder GladeWidgetAdaptor + +GladeEditorProperty * glade_db_model_holder_create_eprop (GladeWidgetAdaptor * adaptor, + GladePropertyClass * klass, gboolean use_command) +{ + GladeEditorProperty * eprop; + GParamSpec * pspec = glade_property_class_get_pspec (klass); + + if (pspec->value_type == DB_TYPE_MODEL) + { + eprop = g_object_new (GLADE_TYPE_EPROP_MODEL, + "property-class", klass, + "use-command", use_command, NULL); + } + else + eprop = GWA_GET_CLASS (G_TYPE_OBJECT)->create_eprop (adaptor, klass, use_command); + + return eprop; +} + +//+++++++++++++++++++++++++++++++++++++++++++++++++++ DbModel Action Callback + +void glade_db_model_action_activate (GladeWidgetAdaptor * adaptor, + DbModel * model, const gchar * path) +{ + glade_eprop_model_show_dialog (NULL, + (GObject *) glade_widget_get_from_gobject (model)); +} \ No newline at end of file diff --git a/glade/glade-vn-batch.c b/glade/glade-vn-batch.c index 803c215..a54e2bc 100644 --- a/glade/glade-vn-batch.c +++ b/glade/glade-vn-batch.c @@ -17,29 +17,6 @@ #include "glade-vn.h" -gboolean glade_vn_batch_add_verify (GladeWidgetAdaptor * adaptor, - VnBatch * container, GObject * child, gboolean user_feedback) -{ - if (G_IS_OBJECT (child)) - return TRUE; - - if (user_feedback) - { - GladeWidgetAdaptor * object_adaptor = - glade_widget_adaptor_get_by_type (G_TYPE_OBJECT); - - glade_util_ui_message (glade_app_get_window () - ,GLADE_UI_INFO - ,NULL - ,"Only objects of type %s can be added to objects of type %s." - ,glade_widget_adaptor_get_name (object_adaptor) - ,glade_widget_adaptor_get_name (adaptor) - ); - } - - return FALSE; -} - void glade_vn_batch_add_child (GladeWidgetAdaptor * adaptor, VnBatch * group, GObject * child) { @@ -67,3 +44,26 @@ GList * glade_vn_batch_get_children (GladeWidgetAdaptor * adaptor, { return vn_batch_get_objects_list (group); } + +gboolean glade_vn_batch_add_verify (GladeWidgetAdaptor * adaptor, + VnBatch * container, GObject * child, gboolean user_feedback) +{ + if (G_IS_OBJECT (child)) + return TRUE; + + if (user_feedback) + { + GladeWidgetAdaptor * object_adaptor = + glade_widget_adaptor_get_by_type (G_TYPE_OBJECT); + + glade_util_ui_message (glade_app_get_window () + ,GLADE_UI_INFO + ,NULL + ,"Only objects of type %s can be added to objects of type %s." + ,glade_widget_adaptor_get_name (object_adaptor) + ,glade_widget_adaptor_get_name (adaptor) + ); + } + + return FALSE; +} diff --git a/glade/glade-vn.c b/glade/glade-vn.c index 3f12661..6b9dde8 100644 --- a/glade/glade-vn.c +++ b/glade/glade-vn.c @@ -17,7 +17,44 @@ #include "glade-vn.h" +gboolean glade_vn_set_first_catalog (gpointer catalog_name) +{ + GList * l, * catalogs = glade_app_get_catalogs (), + * clone = NULL; + GladeCatalog * catalog = NULL; + + for (l = catalogs; l; l = l->next) + if (!g_strcmp0 (catalog_name, glade_catalog_get_name (l->data))) + catalog = l->data; + else + clone = g_list_prepend (clone, l->data); + + if (catalog) + { + GList * trash = catalogs->next; + catalogs->data = catalog; + clone = g_list_reverse (clone); + catalogs->next = clone; + + if (clone) + clone->prev = catalogs; + + if (trash) + { + trash->prev = NULL; + g_list_free (trash); + } + + return G_SOURCE_REMOVE; + } + + g_list_free (clone); + return G_SOURCE_CONTINUE; +} + void glade_vn_init () { g_message ("Hedera objects loaded!"); -} \ No newline at end of file + + g_idle_add (glade_vn_set_first_catalog, "vn"); +} diff --git a/glade/glade.sh b/glade/glade.sh index ff01e02..7142e50 100755 --- a/glade/glade.sh +++ b/glade/glade.sh @@ -4,4 +4,6 @@ MODULE_PATH=../build/glade/ export GLADE_MODULE_SEARCH_PATH="$MODULE_PATH/.libs" export GLADE_CATALOG_SEARCH_PATH=. -glade + +glade $@ + diff --git a/glade/vn.xml b/glade/vn.xml index f12fa0c..c3900de 100644 --- a/glade/vn.xml +++ b/glade/vn.xml @@ -13,19 +13,36 @@ - + + + + + + + + + + + + GParamBoxed + GladeDbList + + List of parameters linked to the model + + glade_db_model_create_eprop + glade_db_model_create_editable + glade_db_model_write_widget + glade_db_model_read_widget + glade_db_model_action_activate - glade_db_model_action_activate - glade_db_sql_create_eprop - glade_db_model_write_widget @@ -35,20 +52,22 @@ GParamObject DbModel + The model held by the object glade_db_model_holder_create_eprop - - - - - glade_db_iterator_action_activate glade_db_iterator_post_create glade_db_iterator_add_verify glade_db_iterator_add_child glade_db_iterator_remove_child glade_db_iterator_replace_child glade_db_iterator_get_children + glade_db_iterator_read_widget + glade_db_iterator_action_activate + + + + @@ -57,6 +76,7 @@ + glade_db_param_read_widget GParamObject DbModel + The model held by the object glade_db_model_holder_create_eprop @@ -118,6 +139,7 @@ GParamObject DbModel + The model held by the object @@ -133,6 +155,7 @@ GParamObject DbModel + The model held by the object @@ -168,9 +191,10 @@ - + + diff --git a/gvn/gvn-value.c b/gvn/gvn-value.c index ffe9db2..28afc1d 100644 --- a/gvn/gvn-value.c +++ b/gvn/gvn-value.c @@ -488,6 +488,7 @@ gboolean gvn_value_ccopy (const GValue * src, GValue * dst) * gvn_value_to_format_string: **/ void gvn_value_to_format_string (const GValue * src, guint digits, GValue * dst) +//void gvn_value_to_format_string (const GValue * src, const gchar * format, GValue * dst) { GType type = G_VALUE_TYPE (src); @@ -495,6 +496,10 @@ void gvn_value_to_format_string (const GValue * src, guint digits, GValue * dst) switch (type) { + case G_TYPE_BOOLEAN: + break; + case G_TYPE_INT://y variantes + break; case G_TYPE_FLOAT: case G_TYPE_DOUBLE: { @@ -514,7 +519,11 @@ void gvn_value_to_format_string (const GValue * src, guint digits, GValue * dst) break; } default: - if (!gvn_value_is_null (src)) + if (type == G_TYPE_DATE) + {} + else if (type == G_TYPE_DATE_TIME) + {} + else if (!gvn_value_is_null (src)) g_value_transform (src, dst); else g_value_set_string (dst, ""); diff --git a/plugin/mysql/db-mysql.c b/plugin/mysql/db-mysql.c index 4c200e2..9903e7f 100644 --- a/plugin/mysql/db-mysql.c +++ b/plugin/mysql/db-mysql.c @@ -196,7 +196,7 @@ static DbResultSet * db_mysql_query (DbMysql * obj, const gchar * sql, GError ** gint i, j; guint errno = 0; gulong * lengths; - GValue def = {0}; + GValue def = G_VALUE_INIT; MYSQL_ROW myrow; MYSQL_RES * res; MYSQL_FIELD * field; diff --git a/po/POTFILES.in b/po/POTFILES.in index f784f74..db2d285 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -21,7 +21,7 @@ db/db-request.c db/db-file-loader.c vn/vn-gui.c -vn/vn-model.c +vn/vn-grid-model.c vn/vn-grid.c vn/vn-handler.c vn/vn-form.c @@ -45,9 +45,11 @@ vn/gui/main.glade vn/gui/child-window.glade vn/gui/actions.glade -glade/glade-db-sql.c glade/glade-db-model.c +glade/glade-db-model-editor.c +glade/glade-eprop-model.c glade/glade-db-iterator.c +[type: gettext/glade]glade/vn.xml [type: gettext/glade]module/data/example.xml module/data/consulter.glade diff --git a/po/ca.po b/po/ca.po index 7099de6..74825b2 100644 --- a/po/ca.po +++ b/po/ca.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: hedera 1.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2014-01-10 15:00+0100\n" +"POT-Creation-Date: 2014-02-12 12:39+0100\n" "PO-Revision-Date: 2013-06-04 13:38+0200\n" "Last-Translator: Alejandro T. Colombini Gómez \n" "Language-Team: Catalan\n" @@ -201,7 +201,7 @@ msgstr "" msgid "The character used for delimite the name of fields, tables..." msgstr "" -#: ../sql/sql-value.c:228 +#: ../sql/sql-value.c:228 ../glade/glade-db-model.c:497 msgid "Param" msgstr "" @@ -318,31 +318,31 @@ msgstr "" msgid "The type of the operation applied over the function" msgstr "" -#: ../db/db-calc.c:347 +#: ../db/db-calc.c:346 msgid "Function" msgstr "" -#: ../db/db-calc.c:348 +#: ../db/db-calc.c:347 msgid "The function to execute" msgstr "" -#: ../db/db-calc.c:354 +#: ../db/db-calc.c:353 msgid "Data" msgstr "" -#: ../db/db-calc.c:355 +#: ../db/db-calc.c:354 msgid "The user provided data for the function" msgstr "" -#: ../db/db-calc.c:361 +#: ../db/db-calc.c:360 ../glade/glade-db-model.c:488 msgid "Column" msgstr "" -#: ../db/db-calc.c:362 +#: ../db/db-calc.c:361 msgid "A column to apply the operations over it" msgstr "" -#: ../db/db-param.c:251 ../vn/vn-grid.c:483 ../vn/vn-field.c:532 +#: ../db/db-param.c:251 ../vn/vn-grid.c:491 ../vn/vn-field.c:532 msgid "Iterator" msgstr "" @@ -556,17 +556,7 @@ msgstr "" msgid "The application handler for the entire program" msgstr "" -#: ../vn/vn-model.c:317 -#, c-format -msgid "Function vn_model_set_sort_func not implemented" -msgstr "Funció vn_model_set_sort_func no implementada" - -#: ../vn/vn-model.c:324 -#, c-format -msgid "Function vn_model_set_default_sort_func not implemented" -msgstr "Funció vn_model_set_default_sort_func no implementada" - -#: ../vn/vn-grid.c:484 +#: ../vn/vn-grid.c:492 msgid "The iterator used by VnGrid" msgstr "" @@ -679,8 +669,8 @@ msgstr "" msgid "The current value of the field" msgstr "" -#: ../vn/vn-field.c:525 ../glade/glade-db-iterator.c:164 -#: ../glade/glade-db-iterator.c:187 +#: ../vn/vn-field.c:525 ../glade/glade-db-iterator.c:95 +#: ../glade/glade-db-iterator.c:117 msgid "Parameter" msgstr "" @@ -705,12 +695,12 @@ msgid "Whether the field value can be of type GVN_TYPE_NULL" msgstr "" #: ../vn/field/vn-entry.c:153 ../vn/field/vn-spin.c:172 -#: ../vn/column/vn-column-entry.c:119 ../vn/column/vn-column-spin.c:183 +#: ../vn/column/vn-column-entry.c:119 ../vn/column/vn-column-spin.c:226 msgid "Digits" msgstr "" #: ../vn/field/vn-entry.c:154 ../vn/field/vn-spin.c:173 -#: ../vn/column/vn-column-entry.c:120 ../vn/column/vn-column-spin.c:184 +#: ../vn/column/vn-column-entry.c:120 ../vn/column/vn-column-spin.c:227 msgid "The number of decimal places to display." msgstr "" @@ -805,35 +795,35 @@ msgstr "" msgid "Order in which the tab selects the columns for edition" msgstr "" -#: ../vn/column/vn-column-spin.c:175 +#: ../vn/column/vn-column-spin.c:218 msgid "Climb rate" msgstr "" -#: ../vn/column/vn-column-spin.c:176 +#: ../vn/column/vn-column-spin.c:219 msgid "The acceleration rate when you hold down a button." msgstr "" -#: ../vn/column/vn-column-spin.c:191 +#: ../vn/column/vn-column-spin.c:234 msgid "Minimum value" msgstr "" -#: ../vn/column/vn-column-spin.c:192 +#: ../vn/column/vn-column-spin.c:235 msgid "The minimum value of the adjustment." msgstr "" -#: ../vn/column/vn-column-spin.c:199 +#: ../vn/column/vn-column-spin.c:242 msgid "Maximum value" msgstr "" -#: ../vn/column/vn-column-spin.c:200 +#: ../vn/column/vn-column-spin.c:243 msgid "The maximum value of the adjustment." msgstr "" -#: ../vn/column/vn-column-spin.c:207 +#: ../vn/column/vn-column-spin.c:250 msgid "Step Increment" msgstr "" -#: ../vn/column/vn-column-spin.c:208 +#: ../vn/column/vn-column-spin.c:251 msgid "The step increment of the adjustment" msgstr "" @@ -1012,64 +1002,88 @@ msgctxt "View menu option" msgid "Tool_bar" msgstr "" -#: ../glade/glade-db-sql.c:27 +#: ../glade/glade-db-model.c:37 msgid "New SQL statement" msgstr "" -#: ../glade/glade-db-sql.c:59 +#: ../glade/glade-db-model.c:69 msgid "SQL Editor" msgstr "" -#: ../glade/glade-db-sql.c:180 +#: ../glade/glade-db-model.c:186 msgid "Open the SQL Editor" msgstr "" -#: ../glade/glade-db-model.c:123 +#: ../glade/glade-db-model.c:263 +msgid "Select a GvnParam" +msgstr "" + +#: ../glade/glade-db-model.c:331 +msgid "Select the parameter from a list" +msgstr "" + +#: ../glade/glade-db-model.c:349 +msgid "You need to create at least one GvnParam or derived object" +msgstr "" + +#: ../glade/glade-db-model.c:452 +msgid "Add or remove links" +msgstr "" + +#: ../glade/glade-db-model-editor.c:53 +msgid "List of parameters linked to the model" +msgstr "" + +#: ../glade/glade-eprop-model.c:129 msgid "Create and set a model for a DbModelHolder" msgstr "" -#: ../glade/glade-db-model.c:155 +#: ../glade/glade-eprop-model.c:161 msgid "Model configuration" msgstr "" -#: ../glade/glade-db-model.c:155 -msgid "DbModel properties configuration" +#: ../glade/glade-eprop-model.c:161 +msgid "Model properties configuration" msgstr "" -#: ../glade/glade-db-model.c:240 -msgid "Select a DbModel for the property" +#: ../glade/glade-eprop-model.c:246 +msgid "Select a VnModel for the property" msgstr "" -#: ../glade/glade-db-model.c:261 ../glade/glade-db-model.c:308 +#: ../glade/glade-eprop-model.c:267 ../glade/glade-eprop-model.c:313 msgid "New Model" msgstr "" -#: ../glade/glade-db-model.c:303 +#: ../glade/glade-eprop-model.c:308 msgid "Edit Model" msgstr "" -#: ../glade/glade-db-iterator.c:166 +#: ../glade/glade-db-iterator.c:97 msgid "Properties" msgstr "" -#: ../glade/glade-db-iterator.c:193 +#: ../glade/glade-db-iterator.c:125 msgid "Iterator Editor" msgstr "" -#: ../glade/glade-db-iterator.c:201 +#: ../glade/glade-db-iterator.c:133 msgid "The model must have \"SQL\" set and \"Use file\" set to 'No'." msgstr "" -#: ../glade/glade-db-iterator.c:212 +#: ../glade/glade-db-iterator.c:144 #, c-format msgid "%s can't have children before automatic generation." msgstr "" -#: ../glade/glade-db-iterator.c:223 +#: ../glade/glade-db-iterator.c:155 #, c-format msgid "%s must have \"Model\" set. %s" msgstr "" +#: ../glade/vn.xml.h:1 +msgid "The model held by the object" +msgstr "" + #: ../module/data/example.xml.h:1 msgid "Example" msgstr "" @@ -1120,3 +1134,11 @@ msgstr "" #: ../module/src/vn-consulter.c:217 msgid "Message" msgstr "" + +#, fuzzy +#~ msgid "Function vn_grid_model_set_sort_func not implemented" +#~ msgstr "Funció vn_model_set_sort_func no implementada" + +#, fuzzy +#~ msgid "Function vn_grid_model_set_default_sort_func not implemented" +#~ msgstr "Funció vn_model_set_default_sort_func no implementada" diff --git a/po/es.po b/po/es.po index 9cd428d..5791a8b 100644 --- a/po/es.po +++ b/po/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: hedera 1.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2014-01-10 15:00+0100\n" +"POT-Creation-Date: 2014-02-12 12:39+0100\n" "PO-Revision-Date: 2013-06-04 13:36+0200\n" "Last-Translator: Alejandro T. Colombini Gómez \n" "Language-Team: Spanish\n" @@ -203,7 +203,7 @@ msgstr "Delimitador" msgid "The character used for delimite the name of fields, tables..." msgstr "El carácter usado para delimitar los nombres de campos, tablas..." -#: ../sql/sql-value.c:228 +#: ../sql/sql-value.c:228 ../glade/glade-db-model.c:497 msgid "Param" msgstr "Parámetro" @@ -326,31 +326,31 @@ msgstr "Tipo de operación" msgid "The type of the operation applied over the function" msgstr "El tipo de operación aplicada sobre la función" -#: ../db/db-calc.c:347 +#: ../db/db-calc.c:346 msgid "Function" msgstr "Función" -#: ../db/db-calc.c:348 +#: ../db/db-calc.c:347 msgid "The function to execute" msgstr "Función a ejecutar" -#: ../db/db-calc.c:354 +#: ../db/db-calc.c:353 msgid "Data" msgstr "Datos" -#: ../db/db-calc.c:355 +#: ../db/db-calc.c:354 msgid "The user provided data for the function" msgstr "Datos proporcionados por el usuario" -#: ../db/db-calc.c:361 +#: ../db/db-calc.c:360 ../glade/glade-db-model.c:488 msgid "Column" msgstr "Columna" -#: ../db/db-calc.c:362 +#: ../db/db-calc.c:361 msgid "A column to apply the operations over it" msgstr "Una columna sobre la que se aplicarán las operaciones" -#: ../db/db-param.c:251 ../vn/vn-grid.c:483 ../vn/vn-field.c:532 +#: ../db/db-param.c:251 ../vn/vn-grid.c:491 ../vn/vn-field.c:532 msgid "Iterator" msgstr "Iterator" @@ -568,17 +568,7 @@ msgstr "Aplicación" msgid "The application handler for the entire program" msgstr "El manejador de la aplicación para todo el programa" -#: ../vn/vn-model.c:317 -#, c-format -msgid "Function vn_model_set_sort_func not implemented" -msgstr "Función vn_model_set_sort_func no implementada" - -#: ../vn/vn-model.c:324 -#, c-format -msgid "Function vn_model_set_default_sort_func not implemented" -msgstr "Función vn_model_set_default_sort_func no implementada" - -#: ../vn/vn-grid.c:484 +#: ../vn/vn-grid.c:492 msgid "The iterator used by VnGrid" msgstr "El Iterator empleado por VnGrid" @@ -691,8 +681,8 @@ msgstr "El identificador de la aplicación" msgid "The current value of the field" msgstr "El valor actual del campo" -#: ../vn/vn-field.c:525 ../glade/glade-db-iterator.c:164 -#: ../glade/glade-db-iterator.c:187 +#: ../vn/vn-field.c:525 ../glade/glade-db-iterator.c:95 +#: ../glade/glade-db-iterator.c:117 msgid "Parameter" msgstr "Parámetro" @@ -717,12 +707,12 @@ msgid "Whether the field value can be of type GVN_TYPE_NULL" msgstr "Si el campo puede ser del tipo GVN_TYPE_NULL" #: ../vn/field/vn-entry.c:153 ../vn/field/vn-spin.c:172 -#: ../vn/column/vn-column-entry.c:119 ../vn/column/vn-column-spin.c:183 +#: ../vn/column/vn-column-entry.c:119 ../vn/column/vn-column-spin.c:226 msgid "Digits" msgstr "Dígitos" #: ../vn/field/vn-entry.c:154 ../vn/field/vn-spin.c:173 -#: ../vn/column/vn-column-entry.c:120 ../vn/column/vn-column-spin.c:184 +#: ../vn/column/vn-column-entry.c:120 ../vn/column/vn-column-spin.c:227 msgid "The number of decimal places to display." msgstr "El número de posiciones decimales que se muestran" @@ -817,35 +807,35 @@ msgstr "Tab index" msgid "Order in which the tab selects the columns for edition" msgstr "Orden en el cual el tabulador selecciona las columnas para editar" -#: ../vn/column/vn-column-spin.c:175 +#: ../vn/column/vn-column-spin.c:218 msgid "Climb rate" msgstr "Tasa de subida" -#: ../vn/column/vn-column-spin.c:176 +#: ../vn/column/vn-column-spin.c:219 msgid "The acceleration rate when you hold down a button." msgstr "La tasa de aceleración cuando se mantiene apretado el botón." -#: ../vn/column/vn-column-spin.c:191 +#: ../vn/column/vn-column-spin.c:234 msgid "Minimum value" msgstr "Valor mínimo" -#: ../vn/column/vn-column-spin.c:192 +#: ../vn/column/vn-column-spin.c:235 msgid "The minimum value of the adjustment." msgstr "Valor mínimo del ajuste." -#: ../vn/column/vn-column-spin.c:199 +#: ../vn/column/vn-column-spin.c:242 msgid "Maximum value" msgstr "Valor máximo" -#: ../vn/column/vn-column-spin.c:200 +#: ../vn/column/vn-column-spin.c:243 msgid "The maximum value of the adjustment." msgstr "Valor máximo del ajuste" -#: ../vn/column/vn-column-spin.c:207 +#: ../vn/column/vn-column-spin.c:250 msgid "Step Increment" msgstr "Incremento del paso" -#: ../vn/column/vn-column-spin.c:208 +#: ../vn/column/vn-column-spin.c:251 msgid "The step increment of the adjustment" msgstr "El incremento del paso del ajuste" @@ -1044,64 +1034,88 @@ msgctxt "View menu option" msgid "Tool_bar" msgstr "_Barra de herramientas" -#: ../glade/glade-db-sql.c:27 +#: ../glade/glade-db-model.c:37 msgid "New SQL statement" msgstr "Nueva consulta SQL" -#: ../glade/glade-db-sql.c:59 +#: ../glade/glade-db-model.c:69 msgid "SQL Editor" msgstr "Editor SQL" -#: ../glade/glade-db-sql.c:180 +#: ../glade/glade-db-model.c:186 msgid "Open the SQL Editor" msgstr "Abrir el Editor SQL" -#: ../glade/glade-db-model.c:123 +#: ../glade/glade-db-model.c:263 +msgid "Select a GvnParam" +msgstr "Elige un GvnParam" + +#: ../glade/glade-db-model.c:331 +msgid "Select the parameter from a list" +msgstr "Eligir un parametro de una lista" + +#: ../glade/glade-db-model.c:349 +msgid "You need to create at least one GvnParam or derived object" +msgstr "Necesitas crear por lo menos un GvnParam o algun objeto derivado" + +#: ../glade/glade-db-model.c:452 +msgid "Add or remove links" +msgstr "Añadir o quitar enlaces" + +#: ../glade/glade-db-model-editor.c:53 +msgid "List of parameters linked to the model" +msgstr "Lista de parámetros vinculados al modelo" + +#: ../glade/glade-eprop-model.c:129 msgid "Create and set a model for a DbModelHolder" -msgstr "Crear y configurar un modelo para un DbModelHolder" +msgstr "Crear y poner el modelo a un DbModelHolder" -#: ../glade/glade-db-model.c:155 +#: ../glade/glade-eprop-model.c:161 msgid "Model configuration" -msgstr "Configuración del Model" +msgstr "Configuración del modelo" -#: ../glade/glade-db-model.c:155 -msgid "DbModel properties configuration" -msgstr "Configuración de propiedades de DbModelo" +#: ../glade/glade-eprop-model.c:161 +msgid "Model properties configuration" +msgstr "Configuración de propiedades del modelo" -#: ../glade/glade-db-model.c:240 -msgid "Select a DbModel for the property" -msgstr "Selecciona un DbModel para la propiedad" +#: ../glade/glade-eprop-model.c:246 +msgid "Select a VnModel for the property" +msgstr "Elige un VnModel para la propiedad" -#: ../glade/glade-db-model.c:261 ../glade/glade-db-model.c:308 +#: ../glade/glade-eprop-model.c:267 ../glade/glade-eprop-model.c:313 msgid "New Model" msgstr "Nuevo Modelo" -#: ../glade/glade-db-model.c:303 +#: ../glade/glade-eprop-model.c:308 msgid "Edit Model" msgstr "Editar Modelo" -#: ../glade/glade-db-iterator.c:166 +#: ../glade/glade-db-iterator.c:97 msgid "Properties" msgstr "Propiedades" -#: ../glade/glade-db-iterator.c:193 +#: ../glade/glade-db-iterator.c:125 msgid "Iterator Editor" msgstr "Editor del Iterator" -#: ../glade/glade-db-iterator.c:201 +#: ../glade/glade-db-iterator.c:133 msgid "The model must have \"SQL\" set and \"Use file\" set to 'No'." msgstr "El modelo debe tener \"SQL\" asignado y \"Usa fichero\" puesto a 'No'." -#: ../glade/glade-db-iterator.c:212 +#: ../glade/glade-db-iterator.c:144 #, c-format msgid "%s can't have children before automatic generation." msgstr "%s no puede tener hijos antes de la generación automatica." -#: ../glade/glade-db-iterator.c:223 +#: ../glade/glade-db-iterator.c:155 #, c-format msgid "%s must have \"Model\" set. %s" msgstr "%s debe tener \"Modelo\" asignado. %s" +#: ../glade/vn.xml.h:1 +msgid "The model held by the object" +msgstr "La conexión empleada por el objeto" + #: ../module/data/example.xml.h:1 msgid "Example" msgstr "Ejemplo" @@ -1150,14 +1164,8 @@ msgstr "Cambios inmediatos" #: ../module/src/vn-consulter.c:215 msgid "Type or select a query" -msgstr "Escribe o selecciona la consulta" +msgstr "Escribe o elige una consulta" #: ../module/src/vn-consulter.c:217 msgid "Message" msgstr "Mensaje" - -#~ msgid "Filter field" -#~ msgstr "Campo de filtro" - -#~ msgid "Name of the field to be used as query filter by the model" -#~ msgstr "Nombre del campo que se usará como filtro en la consulta del modelo" diff --git a/po/nl.po b/po/nl.po index d63980a..3198f57 100644 --- a/po/nl.po +++ b/po/nl.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: hedera 1.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2014-01-10 15:00+0100\n" +"POT-Creation-Date: 2014-02-12 12:39+0100\n" "PO-Revision-Date: 2012-10-09 11:38+0200\n" "Last-Translator: Alejandro T. Colombini Gómez \n" "Language-Team: Dutch\n" @@ -203,7 +203,7 @@ msgstr "" msgid "The character used for delimite the name of fields, tables..." msgstr "" -#: ../sql/sql-value.c:228 +#: ../sql/sql-value.c:228 ../glade/glade-db-model.c:497 msgid "Param" msgstr "" @@ -319,31 +319,31 @@ msgstr "" msgid "The type of the operation applied over the function" msgstr "" -#: ../db/db-calc.c:347 +#: ../db/db-calc.c:346 msgid "Function" msgstr "" -#: ../db/db-calc.c:348 +#: ../db/db-calc.c:347 msgid "The function to execute" msgstr "" -#: ../db/db-calc.c:354 +#: ../db/db-calc.c:353 msgid "Data" msgstr "" -#: ../db/db-calc.c:355 +#: ../db/db-calc.c:354 msgid "The user provided data for the function" msgstr "" -#: ../db/db-calc.c:361 +#: ../db/db-calc.c:360 ../glade/glade-db-model.c:488 msgid "Column" msgstr "" -#: ../db/db-calc.c:362 +#: ../db/db-calc.c:361 msgid "A column to apply the operations over it" msgstr "" -#: ../db/db-param.c:251 ../vn/vn-grid.c:483 ../vn/vn-field.c:532 +#: ../db/db-param.c:251 ../vn/vn-grid.c:491 ../vn/vn-field.c:532 msgid "Iterator" msgstr "" @@ -557,17 +557,7 @@ msgstr "" msgid "The application handler for the entire program" msgstr "" -#: ../vn/vn-model.c:317 -#, c-format -msgid "Function vn_model_set_sort_func not implemented" -msgstr "" - -#: ../vn/vn-model.c:324 -#, c-format -msgid "Function vn_model_set_default_sort_func not implemented" -msgstr "" - -#: ../vn/vn-grid.c:484 +#: ../vn/vn-grid.c:492 msgid "The iterator used by VnGrid" msgstr "" @@ -680,8 +670,8 @@ msgstr "" msgid "The current value of the field" msgstr "" -#: ../vn/vn-field.c:525 ../glade/glade-db-iterator.c:164 -#: ../glade/glade-db-iterator.c:187 +#: ../vn/vn-field.c:525 ../glade/glade-db-iterator.c:95 +#: ../glade/glade-db-iterator.c:117 msgid "Parameter" msgstr "" @@ -706,12 +696,12 @@ msgid "Whether the field value can be of type GVN_TYPE_NULL" msgstr "" #: ../vn/field/vn-entry.c:153 ../vn/field/vn-spin.c:172 -#: ../vn/column/vn-column-entry.c:119 ../vn/column/vn-column-spin.c:183 +#: ../vn/column/vn-column-entry.c:119 ../vn/column/vn-column-spin.c:226 msgid "Digits" msgstr "" #: ../vn/field/vn-entry.c:154 ../vn/field/vn-spin.c:173 -#: ../vn/column/vn-column-entry.c:120 ../vn/column/vn-column-spin.c:184 +#: ../vn/column/vn-column-entry.c:120 ../vn/column/vn-column-spin.c:227 msgid "The number of decimal places to display." msgstr "" @@ -806,35 +796,35 @@ msgstr "" msgid "Order in which the tab selects the columns for edition" msgstr "" -#: ../vn/column/vn-column-spin.c:175 +#: ../vn/column/vn-column-spin.c:218 msgid "Climb rate" msgstr "" -#: ../vn/column/vn-column-spin.c:176 +#: ../vn/column/vn-column-spin.c:219 msgid "The acceleration rate when you hold down a button." msgstr "" -#: ../vn/column/vn-column-spin.c:191 +#: ../vn/column/vn-column-spin.c:234 msgid "Minimum value" msgstr "" -#: ../vn/column/vn-column-spin.c:192 +#: ../vn/column/vn-column-spin.c:235 msgid "The minimum value of the adjustment." msgstr "" -#: ../vn/column/vn-column-spin.c:199 +#: ../vn/column/vn-column-spin.c:242 msgid "Maximum value" msgstr "" -#: ../vn/column/vn-column-spin.c:200 +#: ../vn/column/vn-column-spin.c:243 msgid "The maximum value of the adjustment." msgstr "" -#: ../vn/column/vn-column-spin.c:207 +#: ../vn/column/vn-column-spin.c:250 msgid "Step Increment" msgstr "" -#: ../vn/column/vn-column-spin.c:208 +#: ../vn/column/vn-column-spin.c:251 msgid "The step increment of the adjustment" msgstr "" @@ -1012,64 +1002,88 @@ msgctxt "View menu option" msgid "Tool_bar" msgstr "" -#: ../glade/glade-db-sql.c:27 +#: ../glade/glade-db-model.c:37 msgid "New SQL statement" msgstr "" -#: ../glade/glade-db-sql.c:59 +#: ../glade/glade-db-model.c:69 msgid "SQL Editor" msgstr "" -#: ../glade/glade-db-sql.c:180 +#: ../glade/glade-db-model.c:186 msgid "Open the SQL Editor" msgstr "" -#: ../glade/glade-db-model.c:123 +#: ../glade/glade-db-model.c:263 +msgid "Select a GvnParam" +msgstr "" + +#: ../glade/glade-db-model.c:331 +msgid "Select the parameter from a list" +msgstr "" + +#: ../glade/glade-db-model.c:349 +msgid "You need to create at least one GvnParam or derived object" +msgstr "" + +#: ../glade/glade-db-model.c:452 +msgid "Add or remove links" +msgstr "" + +#: ../glade/glade-db-model-editor.c:53 +msgid "List of parameters linked to the model" +msgstr "" + +#: ../glade/glade-eprop-model.c:129 msgid "Create and set a model for a DbModelHolder" msgstr "" -#: ../glade/glade-db-model.c:155 +#: ../glade/glade-eprop-model.c:161 msgid "Model configuration" msgstr "" -#: ../glade/glade-db-model.c:155 -msgid "DbModel properties configuration" +#: ../glade/glade-eprop-model.c:161 +msgid "Model properties configuration" msgstr "" -#: ../glade/glade-db-model.c:240 -msgid "Select a DbModel for the property" +#: ../glade/glade-eprop-model.c:246 +msgid "Select a VnModel for the property" msgstr "" -#: ../glade/glade-db-model.c:261 ../glade/glade-db-model.c:308 +#: ../glade/glade-eprop-model.c:267 ../glade/glade-eprop-model.c:313 msgid "New Model" msgstr "" -#: ../glade/glade-db-model.c:303 +#: ../glade/glade-eprop-model.c:308 msgid "Edit Model" msgstr "" -#: ../glade/glade-db-iterator.c:166 +#: ../glade/glade-db-iterator.c:97 msgid "Properties" msgstr "" -#: ../glade/glade-db-iterator.c:193 +#: ../glade/glade-db-iterator.c:125 msgid "Iterator Editor" msgstr "" -#: ../glade/glade-db-iterator.c:201 +#: ../glade/glade-db-iterator.c:133 msgid "The model must have \"SQL\" set and \"Use file\" set to 'No'." msgstr "" -#: ../glade/glade-db-iterator.c:212 +#: ../glade/glade-db-iterator.c:144 #, c-format msgid "%s can't have children before automatic generation." msgstr "" -#: ../glade/glade-db-iterator.c:223 +#: ../glade/glade-db-iterator.c:155 #, c-format msgid "%s must have \"Model\" set. %s" msgstr "" +#: ../glade/vn.xml.h:1 +msgid "The model held by the object" +msgstr "" + #: ../module/data/example.xml.h:1 msgid "Example" msgstr "" diff --git a/sql/parser/gram.y b/sql/parser/gram.y index d540e96..17c65c1 100644 --- a/sql/parser/gram.y +++ b/sql/parser/gram.y @@ -639,7 +639,7 @@ static inline SqlOperation * sql_parser_create_operation operation(A) ::= MINUS expr(X). [SIGN] { - GValue value = {0}; + GValue value = G_VALUE_INIT; SqlExpr * minus = sql_value_new (); g_value_init (&value, G_TYPE_INT); g_value_set_int (&value, -1); @@ -705,7 +705,7 @@ operation(A) ::= expr(X) IS expr(Y). value(A) ::= INTEGER(X). { - GValue value = {0}; + GValue value = G_VALUE_INIT; SqlExpr * v = sql_value_new (); g_value_set_int (g_value_init (&value, G_TYPE_INT), atoi (X)); sql_value_set_value (SQL_VALUE (v), &value); @@ -715,7 +715,7 @@ value(A) ::= INTEGER(X). value(A) ::= FLOAT(X). { - GValue value = {0}; + GValue value = G_VALUE_INIT; SqlExpr * v = sql_value_new (); g_value_set_double (g_value_init (&value, G_TYPE_DOUBLE), g_ascii_strtod (X, NULL)); @@ -726,7 +726,7 @@ value(A) ::= FLOAT(X). value(A) ::= STRING(X). { - GValue value = {0}; + GValue value = G_VALUE_INIT; SqlExpr * v = sql_value_new (); g_value_set_string (g_value_init (&value, G_TYPE_STRING), X); sql_value_set_value (SQL_VALUE (v), &value); @@ -736,7 +736,7 @@ value(A) ::= STRING(X). value(A) ::= BOOLEAN(X). { - GValue value = {0}; + GValue value = G_VALUE_INIT; SqlExpr * v = sql_value_new (); g_value_set_boolean (g_value_init (&value, G_TYPE_BOOLEAN) ,(!g_strcmp0 (X, "TRUE") || !g_strcmp0 (X, "true")) ? TRUE : FALSE); diff --git a/sql/parser/scan.rl b/sql/parser/scan.rl index 5306ae0..a454d1b 100644 --- a/sql/parser/scan.rl +++ b/sql/parser/scan.rl @@ -265,3 +265,55 @@ SqlObject * sql_parser_parse (const gchar * sql, GError ** err) return object; } + +/** + * sql_parser_parse_field: + * @field: a string containing a field name + * + * Parses a qualified or unqualified SQL field name to an #SqlField object. The + * field can be specified using both ` or " as quotes. This object must be + * unreferenced using g_object_unref(). + * + * Return value: an #SqlField + **/ +SqlField * sql_parser_parse_field (const gchar * field) +{ + gchar ** split; + SqlExpr * object = NULL; + + if (!field || !g_strcmp0 (field, "")) + return NULL; + + split = g_strsplit (field, ".", 0); + + switch (g_strv_length (split)) + { + case 3: + { + object = sql_field_new + (g_strstrip (g_strdelimit (split[2], "`\"", ' ')) + ,g_strstrip (g_strdelimit (split[1], "`\"", ' ')) + ,g_strstrip (g_strdelimit (split[0], "`\"", ' '))); + break; + } + case 2: + { + object = sql_field_new + (g_strstrip (g_strdelimit (split[1], "`\"", ' ')) + ,g_strstrip (g_strdelimit (split[0], "`\"", ' ')) + ,NULL); + break; + } + case 1: + { + object = sql_field_new + (g_strstrip (g_strdelimit (split[0], "`\"", ' ')) + ,NULL + ,NULL); + break; + } + } + + g_strfreev (split); + return (SqlField *) object; +} diff --git a/sql/sql-parser.h b/sql/sql-parser.h index 52f77fa..2f49683 100644 --- a/sql/sql-parser.h +++ b/sql/sql-parser.h @@ -19,12 +19,13 @@ #define SQL_PARSER_H #include "sql-object.h" +#include "sql-field.h" #define SQL_PARSER_LOG_DOMAIN (g_quark_from_string ("SqlParser")) /** * sql_parser_parse: - * @sql: An string containing an SQL query + * @sql: a string containing an SQL query * @err: (out) (allow-none): a return location of a #GError or %NULL to ignore * errors * @@ -34,4 +35,14 @@ */ SqlObject * sql_parser_parse (const gchar * sql, GError ** err) G_GNUC_WARN_UNUSED_RESULT; +/** + * sql_parser_parse_field: + * @field: a string containing a qualified (or not) SQL field + * + * Parses a qualified SQL field and returns the corresponding @SqlField object. + * + * Return value: (transfer full): an #SqlField + */ +SqlField * sql_parser_parse_field (const gchar * field); + #endif \ No newline at end of file diff --git a/sql/sql-string.c b/sql/sql-string.c index 90f4656..329942d 100644 --- a/sql/sql-string.c +++ b/sql/sql-string.c @@ -93,7 +93,7 @@ void sql_string_add_value (SqlString * obj, GType type, gconstpointer content) { g_return_if_fail (SQL_IS_STRING (obj)); - GValue value = {0}; + GValue value = G_VALUE_INIT; SqlExpr * expr; gvn_value_new_with_content (&value, type, content); diff --git a/vn/Makefile.am b/vn/Makefile.am index c6ef633..e14b295 100644 --- a/vn/Makefile.am +++ b/vn/Makefile.am @@ -13,7 +13,7 @@ vn_include_HEADERS = \ vn-gui.h \ vn-mod.h \ vn-form.h \ - vn-model.h \ + vn-grid-model.h \ vn-grid.h \ vn-handler.h \ vn-batch.h \ @@ -31,7 +31,7 @@ libvn_la_LIBADD = \ $(top_builddir)/db/libdb.la \ $(top_builddir)/vn/field/libvnfield.la \ $(top_builddir)/vn/column/libvncolumn.la -libvn_la_SOURCES = \ +libvn_files = \ $(vn_include_HEADERS) \ vn-field.c \ vn-column.c \ @@ -39,12 +39,18 @@ libvn_la_SOURCES = \ vn-gui.c \ vn-mod.c \ vn-form.c \ - vn-model.c \ + vn-grid-model.c \ vn-grid.c \ vn-handler.c \ - vn-batch.c \ + vn-batch.c +glade_files = \ $(top_srcdir)/vn/glade/vn-iterator.h \ - $(top_srcdir)/vn/glade/vn-iterator.c + $(top_srcdir)/vn/glade/vn-iterator.c \ + $(top_srcdir)/vn/glade/vn-model.h \ + $(top_srcdir)/vn/glade/vn-model.c +libvn_la_SOURCES = \ + $(libvn_files) \ + $(glade_files) pkgconfig_DATA = vn.pc @@ -91,7 +97,7 @@ INTROSPECTION_COMPILER_ARGS = \ --includedir=$(top_builddir)/db introspection_sources = \ - $(libvn_la_SOURCES) \ + $(libvn_files) \ $(top_srcdir)/vn/field/vn-*.h \ $(top_srcdir)/vn/column/vn-*.h diff --git a/vn/column/vn-column-check.c b/vn/column/vn-column-check.c index ee2ccd3..1aca0c7 100644 --- a/vn/column/vn-column-check.c +++ b/vn/column/vn-column-check.c @@ -27,7 +27,7 @@ static void vn_column_check_cb_toggled (GtkCellRendererToggle * cell, gint col; DbIter iter; DbModel * model; - GValue new_value = {0}; + GValue new_value = G_VALUE_INIT; const GValue * old_value; col = vn_column_get_column_index (obj); @@ -55,7 +55,7 @@ static void vn_column_check_set_editable (VnColumn * obj, gboolean editable) static void vn_column_check_set_value (VnColumnCheck * obj, GtkTreeModel * model, GtkTreeIter * iter, GtkCellRendererToggle * cell, const GValue * value) { - GValue new_value = {0}; + GValue new_value = G_VALUE_INIT; g_value_init (&new_value, G_TYPE_BOOLEAN); if (!gvn_value_is_null (value)) diff --git a/vn/column/vn-column-combo.c b/vn/column/vn-column-combo.c index 76674a8..d56ed6d 100644 --- a/vn/column/vn-column-combo.c +++ b/vn/column/vn-column-combo.c @@ -16,7 +16,7 @@ */ #include "vn-column-combo.h" -#include "../vn-model.h" +#include "../vn-grid-model.h" static void vn_column_combo_model_holder_init (DbModelHolderInterface * iface); @@ -107,7 +107,7 @@ static void vn_column_combo_on_edited (GtkCellRendererText * renderer, gchar * path, gchar * new_text, VnColumnCombo * obj) { DbIter iter; - GValue value = {0}; + GValue value = G_VALUE_INIT; if (!g_strcmp0 (new_text, "")) { @@ -216,7 +216,7 @@ static void vn_column_combo_set_model (VnColumnCombo * obj, if (model) { obj->model = model; - obj->tree_model = GTK_TREE_MODEL (vn_model_new (model)); + obj->tree_model = GTK_TREE_MODEL (vn_grid_model_new (model)); g_signal_connect (model, "status-changed", G_CALLBACK (vn_column_combo_on_status_changed), obj); diff --git a/vn/column/vn-column-entry.c b/vn/column/vn-column-entry.c index c388018..2d60b38 100644 --- a/vn/column/vn-column-entry.c +++ b/vn/column/vn-column-entry.c @@ -24,7 +24,7 @@ G_DEFINE_TYPE (VnColumnEntry, vn_column_entry, VN_TYPE_COLUMN); static void vn_column_entry_cb_edited (GtkCellRendererText * cell, const gchar * path, gchar * text, VnColumnEntry * obj) { - GValue value = {0}; + GValue value = G_VALUE_INIT; if (g_strcmp0 (text, "")) { @@ -53,7 +53,7 @@ static void vn_column_entry_set_editable (VnColumn * obj, gboolean editable) static void vn_column_entry_set_value (VnColumnEntry * obj, GtkTreeModel * model, GtkTreeIter * iter, GObject * cell, const GValue * value) { - GValue new_value = {0}; + GValue new_value = G_VALUE_INIT; gvn_value_to_format_string (value, obj->digits, &new_value); g_object_set_property (cell, "text", &new_value); g_value_unset (&new_value); diff --git a/vn/column/vn-column-image.c b/vn/column/vn-column-image.c index 1ea865b..0e81441 100644 --- a/vn/column/vn-column-image.c +++ b/vn/column/vn-column-image.c @@ -16,7 +16,7 @@ */ #include "vn-column-image.h" -#include "../vn-model.h" +#include "../vn-grid-model.h" #define LOAD_IMAGE _IMAGE_DIR"/load.gif" @@ -223,7 +223,7 @@ static void vn_column_image_on_download (DbFileLoader * obj, GBytes * bytes, if (error) vn_column_image_download_error (data->obj, error); - else if (bytes && vn_model_iter_is_valid (data->iter, data->model)) + else if (bytes && vn_grid_model_iter_is_valid (data->iter, data->model)) { if (data->obj->loaded) g_hash_table_replace (data->obj->loaded, g_strdup (data->name), diff --git a/vn/column/vn-column-spin.c b/vn/column/vn-column-spin.c index 2e2d8a4..5f7039b 100644 --- a/vn/column/vn-column-spin.c +++ b/vn/column/vn-column-spin.c @@ -16,14 +16,14 @@ */ #include "vn-column-spin.h" -#include "../vn-model.h" +#include "../vn-grid-model.h" G_DEFINE_TYPE (VnColumnSpin, vn_column_spin, VN_TYPE_COLUMN); static void vn_column_spin_on_edited (GtkCellRendererSpin * cell, const gchar * path, gchar * text, VnColumnSpin * obj) { - GValue value = {0}; + GValue value = G_VALUE_INIT; DbModelStatus status = db_model_get_status (vn_column_get_model (VN_COLUMN (obj))); if (status != DB_MODEL_STATUS_READY) @@ -116,7 +116,7 @@ static void vn_column_spin_set_value (VnColumnSpin * obj, GtkTreeModel * model, GtkTreeIter * iter, GObject * cell, const GValue * value) { gint digits; - GValue new_value = {0}; + GValue new_value = G_VALUE_INIT; g_object_get (cell, "digits", &digits, NULL); gvn_value_to_format_string (value, digits, &new_value); diff --git a/vn/column/vn-column-spin.h b/vn/column/vn-column-spin.h index 31270ec..b495e93 100644 --- a/vn/column/vn-column-spin.h +++ b/vn/column/vn-column-spin.h @@ -34,6 +34,7 @@ struct _VnColumnSpin { VnColumn parent; GtkAdjustment * adjustment; + gchar * format; }; struct _VnColumnSpinClass diff --git a/vn/field/vn-calendar.c b/vn/field/vn-calendar.c index 986748c..6d59666 100644 --- a/vn/field/vn-calendar.c +++ b/vn/field/vn-calendar.c @@ -49,7 +49,7 @@ static void vn_calendar_cb_day_selected (GtkCalendar * calendar, VnCalendar * ob guint month; guint day; GDate new_date; - GValue value = {0}; + GValue value = G_VALUE_INIT; gtk_calendar_clear_marks (calendar); gtk_calendar_get_date (calendar, &year, &month, &day); @@ -102,7 +102,7 @@ static void vn_calendar_set_value (VnCalendar * obj, const GValue * value) if (G_VALUE_TYPE (value) != G_TYPE_DATE) { - GValue new_value = {0}; + GValue new_value = G_VALUE_INIT; g_value_init (&new_value, G_TYPE_DATE); g_value_transform (value, &new_value); date = g_value_get_boxed (&new_value); diff --git a/vn/field/vn-check.c b/vn/field/vn-check.c index 61d3aec..d785637 100644 --- a/vn/field/vn-check.c +++ b/vn/field/vn-check.c @@ -45,7 +45,7 @@ VnField * vn_check_new () static void vn_check_changed (VnCheck * obj) { - GValue value = {0}; + GValue value = G_VALUE_INIT; if (!gtk_toggle_button_get_inconsistent (obj->button)) { @@ -85,7 +85,7 @@ static gboolean vn_check_on_secondary_button (GtkToggleButton * button, GdkEvent static void vn_check_set_value (VnCheck * obj, const GValue * value) { - GValue new_value = {0}; + GValue new_value = G_VALUE_INIT; if (!gvn_value_is_null (value)) { diff --git a/vn/field/vn-combo.c b/vn/field/vn-combo.c index 93b33e0..a27a166 100644 --- a/vn/field/vn-combo.c +++ b/vn/field/vn-combo.c @@ -16,7 +16,7 @@ */ #include "vn-combo.h" -#include "../vn-model.h" +#include "../vn-grid-model.h" #include /** @@ -55,7 +55,7 @@ VnField * vn_combo_new (DbModel * model) static void vn_combo_cb_changed (GtkComboBox * combo, VnCombo * obj) { GtkTreeIter iter; - GValue value = {0}; + GValue value = G_VALUE_INIT; if (gtk_combo_box_get_active_iter (combo, &iter)) gtk_tree_model_get_value (obj->tree, &iter, obj->index_column, &value); @@ -127,7 +127,7 @@ static void vn_combo_set_model (VnCombo * obj, DbModel * model) } if (model) { - obj->tree = GTK_TREE_MODEL (vn_model_new (model)); + obj->tree = GTK_TREE_MODEL (vn_grid_model_new (model)); obj->model = g_object_ref (model); g_signal_connect (model, "status-changed", G_CALLBACK (vn_combo_cb_status_changed), obj); diff --git a/vn/field/vn-completion.c b/vn/field/vn-completion.c index 13d329a..352897f 100644 --- a/vn/field/vn-completion.c +++ b/vn/field/vn-completion.c @@ -17,7 +17,7 @@ #include "vn-completion.h" #include -#include +#include #include #define set_icon(obj,icon_name) (gtk_entry_set_icon_from_icon_name (obj->entry, GTK_ENTRY_ICON_SECONDARY, icon_name)) @@ -64,7 +64,7 @@ static void vn_completion_cb_status_changed (DbModel * model, if (status == DB_MODEL_STATUS_READY) { - GtkTreeModel * tree = GTK_TREE_MODEL (vn_model_new (model)); + GtkTreeModel * tree = GTK_TREE_MODEL (vn_grid_model_new (model)); gtk_entry_completion_set_model (obj->completion, tree); g_signal_emit_by_name (obj->entry, "changed"); g_object_unref (tree); @@ -104,7 +104,7 @@ static void vn_completion_cb_changed (GtkEditable * entry, VnCompletion * obj) && (!obj->last_match || g_strcmp0 (text, obj->last_match))) { gchar * pattern; - GValue value = {0}; + GValue value = G_VALUE_INIT; set_icon (obj, "edit-find-symbolic"); @@ -164,7 +164,7 @@ static void vn_completion_cb_activate (GtkEntry * entry, VnCompletion * obj) if (!ok) { - GValue value = {0}; + GValue value = G_VALUE_INIT; g_value_init (&value, GVN_TYPE_NULL); VN_FIELD_GET_CLASS (obj)->value_changed (VN_FIELD (obj), &value); diff --git a/vn/field/vn-date-chooser.c b/vn/field/vn-date-chooser.c index a83a115..b531b07 100644 --- a/vn/field/vn-date-chooser.c +++ b/vn/field/vn-date-chooser.c @@ -87,7 +87,7 @@ static void vn_date_chooser_set_value (VnDateChooser * obj, const GValue * value if (G_VALUE_TYPE (value) != G_TYPE_DATE) { - GValue new_value = {0}; + GValue new_value = G_VALUE_INIT; g_value_init (&new_value, G_TYPE_DATE); g_value_transform (value, &new_value); date = g_value_get_boxed (&new_value); @@ -109,7 +109,7 @@ static void vn_date_chooser_on_day_selected (GtkCalendar * calendar, VnDateChoos guint month; guint day; GDate new_date; - GValue value = {0}; + GValue value = G_VALUE_INIT; gtk_calendar_get_date (calendar, &year, &month, &day); month++; diff --git a/vn/field/vn-entry.c b/vn/field/vn-entry.c index 18d7ab7..c7734f8 100644 --- a/vn/field/vn-entry.c +++ b/vn/field/vn-entry.c @@ -45,7 +45,7 @@ VnField * vn_entry_new (VnEntry * obj) static void vn_entry_cb_editing_done (GtkEntry * entry, VnField * obj) { - GValue value = {0}; + GValue value = G_VALUE_INIT; const gchar * text = gtk_entry_get_text (entry); if (g_strcmp0 (text, "") || !vn_field_get_null (obj)) @@ -68,7 +68,7 @@ static gboolean vn_entry_cb_focus_out (GtkEntry * entry, GdkEvent * event, VnFie static void vn_entry_set_value (VnEntry * obj, const GValue * value) { - GValue new_value = {0}; + GValue new_value = G_VALUE_INIT; gvn_value_to_format_string (value, obj->digits, &new_value); g_signal_handlers_block_by_func (obj->entry, diff --git a/vn/field/vn-image.c b/vn/field/vn-image.c index 075232d..137acdf 100644 --- a/vn/field/vn-image.c +++ b/vn/field/vn-image.c @@ -155,7 +155,7 @@ static gboolean vn_image_cb_event (VnField * field, GdkEvent * event, VnImage * if (g_file_get_contents (filename, &data, &len, &err)) { - GValue value = {0}; + GValue value = G_VALUE_INIT; g_value_init (&value, G_TYPE_BYTES); g_value_take_boxed (&value, g_bytes_new_take (data, len)); diff --git a/vn/field/vn-spin.c b/vn/field/vn-spin.c index d0c5a67..1b5fa94 100644 --- a/vn/field/vn-spin.c +++ b/vn/field/vn-spin.c @@ -45,7 +45,7 @@ VnField * vn_spin_new () static void vn_spin_on_value_changed (GtkSpinButton * spin, VnField * obj) { - GValue value = {0}; + GValue value = G_VALUE_INIT; if (g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (spin)), "")) { @@ -81,7 +81,7 @@ static void vn_spin_set_value (VnSpin * obj, const GValue * value) if (!gvn_value_is_null (value)) { - GValue new_value = {0}; + GValue new_value = G_VALUE_INIT; g_value_init (&new_value, G_TYPE_DOUBLE); g_value_transform (value, &new_value); gtk_spin_button_set_value (obj->spin, diff --git a/vn/glade/vn-iterator.c b/vn/glade/vn-iterator.c index d5c8cb1..2cf5524 100644 --- a/vn/glade/vn-iterator.c +++ b/vn/glade/vn-iterator.c @@ -17,20 +17,60 @@ #include "vn-iterator.h" +static void vn_iterator_buildable_init (GtkBuildableIface * iface); + +G_DEFINE_TYPE_WITH_CODE (VnIterator, vn_iterator, DB_TYPE_ITERATOR, + G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, + vn_iterator_buildable_init) +); + +//+++++++++++++++++++++++++++++++++++++++++++++++++++ Methods for Glade + +void vn_iterator_add_param (DbIterator * obj, DbParam * param) +{ + VnIterator * i = (VnIterator *) obj; + g_return_if_fail (DB_IS_ITERATOR (obj)); + g_return_if_fail (DB_IS_PARAM (param)); + + i->params = g_list_prepend (i->params, param); +} + +void vn_iterator_remove_param (DbIterator * obj, DbParam * param) +{ + VnIterator * i = (VnIterator *) obj; + g_return_if_fail (DB_IS_ITERATOR (obj)); + g_return_if_fail (DB_IS_PARAM (param)); + + i->params = g_list_remove (i->params, param); +} + +GList * vn_iterator_get_params (DbIterator * obj) +{ + g_return_if_fail (DB_IS_ITERATOR (obj)); + + return g_list_copy (((VnIterator *) obj)->params); +} + //+++++++++++++++++++++++++++++++++++++++++++++++++++ GtkBuildable static void vn_iterator_buildable_add_child (GtkBuildable * obj, GtkBuilder * builder, GObject * child, const gchar * type) { - db_iterator_add_param (DB_ITERATOR (obj), DB_PARAM (child)); + db_iterator_add_param ((DbIterator *) obj, (DbParam *) child); } //+++++++++++++++++++++++++++++++++++++++++++++++++++ Class +static void vn_iterator_init (VnIterator * obj) +{ + obj->params = NULL; +} + static void vn_iterator_finalize (VnIterator * obj) { - GObjectClass * parent = g_type_class_peek_parent (VN_ITERATOR_GET_CLASS (obj)); - parent->finalize (G_OBJECT (obj)); + g_list_free_full (obj->params, g_object_unref); + + G_OBJECT_CLASS (vn_iterator_parent_class)->finalize (G_OBJECT (obj)); } static void vn_iterator_class_init (VnIteratorClass * klass) @@ -39,15 +79,7 @@ static void vn_iterator_class_init (VnIteratorClass * klass) k->finalize = (GObjectFinalizeFunc) vn_iterator_finalize; } -static void vn_iterator_buildable_interface_init (GtkBuildableIface * iface) +static void vn_iterator_buildable_init (GtkBuildableIface * iface) { iface->add_child = vn_iterator_buildable_add_child; } - -static void vn_iterator_init (VnIterator * obj) -{} - -G_DEFINE_TYPE_WITH_CODE (VnIterator, vn_iterator, DB_TYPE_ITERATOR, - G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, - vn_iterator_buildable_interface_init) -); diff --git a/vn/glade/vn-iterator.h b/vn/glade/vn-iterator.h index 1182c56..76bddd8 100644 --- a/vn/glade/vn-iterator.h +++ b/vn/glade/vn-iterator.h @@ -34,6 +34,7 @@ typedef struct _VnIteratorClass VnIteratorClass; struct _VnIterator { DbIterator iterator; + GList * params; }; struct _VnIteratorClass @@ -43,4 +44,8 @@ struct _VnIteratorClass GType vn_iterator_get_type (); +void vn_iterator_add_param (DbIterator * obj, DbParam * param); +void vn_iterator_remove_param (DbIterator * obj, DbParam * param); +GList * vn_iterator_get_params (DbIterator * obj); + #endif diff --git a/vn/glade/vn-model.c b/vn/glade/vn-model.c new file mode 100644 index 0000000..a0cdbf8 --- /dev/null +++ b/vn/glade/vn-model.c @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2012 - Juan Ferrer Toribio + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "vn-model.h" + +static void vn_model_buildable_init (GtkBuildableIface * iface); + +G_DEFINE_TYPE_WITH_CODE (VnModel, vn_model, DB_TYPE_MODEL, + G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, + vn_model_buildable_init) +); + +/* GtkBuildable custom tag implementation + * + * + * + * ... + * + */ + +typedef struct +{ + GtkBuilder * builder; + DbModel * model; + GSList * fields; + GSList * params; +} +VnModelData; + +//+++++++++++++++++++++++++++++++++++++++++++++++++++ GtkBuildable + +static void vn_model_start_element (GMarkupParseContext * context, + const gchar * element, const gchar ** names, + const gchar ** values, gpointer data, GError ** err) +{ + guint i; + VnModelData * d = (VnModelData *) data; + + for (i = 0; names[i]; i++) + if (!g_strcmp0 (names[i], "field")) + d->fields = g_slist_prepend (d->fields, g_strdup (values[i])); + else if (!g_strcmp0 (names[i], "param")) + d->params = g_slist_prepend (d->params, g_strdup (values[i])); +} + +static void vn_model_end_element (GMarkupParseContext * context, + const gchar * element, gpointer data, GError ** error) +{ + GSList * f, * p; + VnModelData * d = (VnModelData *) data; + + g_return_if_fail (d->builder); + + if (g_strcmp0 (element, "links")) + return; + + d->fields = g_slist_reverse (d->fields); + d->params = g_slist_reverse (d->params); + + for (f = d->fields, p = d->params; f && p; f = f->next, p = p->next) + { + gchar * field = f->data; + GvnParam * param = GVN_PARAM (gtk_builder_get_object (d->builder, p->data)); + + db_model_set_default_value_from_param (d->model, field, param); + + g_free (f->data); + g_free (p->data); + } + + g_slist_free (d->fields); + g_slist_free (d->params); + g_slice_free (VnModelData, d); +} + +static const GMarkupParser vn_model_parser = +{ + vn_model_start_element + ,vn_model_end_element +}; + +static gboolean vn_model_buildable_custom_tag_start (GtkBuildable *buildable, + GtkBuilder * builder, GObject * child, const gchar * tag, + GMarkupParser * parser, gpointer * data) +{ + if (child) + return FALSE; + + if (!g_strcmp0 (tag, "links")) + { + VnModelData * data_ptr = g_slice_new (VnModelData); + data_ptr->builder = builder; + data_ptr->model = DB_MODEL (buildable); + data_ptr->fields = NULL; + data_ptr->params = NULL; + + *data = data_ptr; + *parser = vn_model_parser; + + return TRUE; + } + + return FALSE; +} + +//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class + +static void vn_model_finalize (VnModel * obj) +{ + G_OBJECT_CLASS (vn_model_parent_class)->finalize (G_OBJECT (obj)); +} + +static void vn_model_class_init (VnModelClass * klass) +{ + GObjectClass * k = G_OBJECT_CLASS (klass); + k->finalize = (GObjectFinalizeFunc) vn_model_finalize; +} + +static void vn_model_buildable_init (GtkBuildableIface * iface) +{ + iface->custom_tag_start = vn_model_buildable_custom_tag_start; +} + +static void vn_model_init (VnModel * obj) +{} + diff --git a/vn/glade/vn-model.h b/vn/glade/vn-model.h new file mode 100644 index 0000000..0721c87 --- /dev/null +++ b/vn/glade/vn-model.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2012 - Juan Ferrer Toribio + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef VN_MODEL_H +#define VN_MODEL_H + +#include +#include + +#define VN_TYPE_MODEL (vn_model_get_type ()) +#define VN_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, VN_TYPE_MODEL, VnModel)) +#define VN_IS_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, VN_TYPE_MODEL)) +#define VN_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST (klass, VN_TYPE_MODEL, VnModelClass)) +#define VN_IS_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE (klass, VN_TYPE_MODEL)) +#define VN_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS (obj, VN_TYPE_MODEL, VnModelClass)) + +typedef struct _VnModel VnModel; +typedef struct _VnModelClass VnModelClass; + +struct _VnModel +{ + DbModel model; +}; + +struct _VnModelClass +{ + DbModelClass parent; +}; + +GType vn_model_get_type (); + +#endif diff --git a/vn/vn-batch.c b/vn/vn-batch.c index acc2cd5..02cbf6b 100644 --- a/vn/vn-batch.c +++ b/vn/vn-batch.c @@ -25,6 +25,13 @@ * A group of GObjects. */ +static void vn_batch_buildable_interface_init (GtkBuildableIface * iface); + +G_DEFINE_TYPE_WITH_CODE (VnBatch, vn_batch, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, + vn_batch_buildable_interface_init) +); + //+++++++++++++++++++++++++++++++++++++++++++++++++++ Methods /** @@ -140,8 +147,3 @@ static void vn_batch_buildable_interface_init (GtkBuildableIface * iface) { iface->add_child = vn_batch_buildable_add_child; } - -G_DEFINE_TYPE_WITH_CODE (VnBatch, vn_batch, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, - vn_batch_buildable_interface_init) -); diff --git a/vn/vn-column.c b/vn/vn-column.c index 83ecc53..4410532 100644 --- a/vn/vn-column.c +++ b/vn/vn-column.c @@ -41,14 +41,14 @@ static void vn_column_data_func (GtkTreeViewColumn * col, GtkCellRenderer * cell DbIter dbiter; DbModelRowOp ops; - GValue value = {0}; + GValue value = G_VALUE_INIT; gtk_tree_model_get_value (model, iter, obj->column_index, &value); obj->set_value (obj, model, iter, cell, &value); g_value_unset (&value); vn_gtk_tree_iter_to_db_iter (iter, &dbiter); ops = db_model_get_row_operations ( - vn_model_get_model (VN_MODEL (model)) + vn_grid_model_get_model (VN_GRID_MODEL (model)) ,&dbiter ); diff --git a/vn/vn-grid-model.c b/vn/vn-grid-model.c new file mode 100644 index 0000000..4e85ffe --- /dev/null +++ b/vn/vn-grid-model.c @@ -0,0 +1,445 @@ +/* + * Copyright (C) 2012 - Juan Ferrer Toribio + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "vn-grid-model.h" + +static void vn_grid_model_tree_model_init (GtkTreeModelIface * iface); +static void vn_grid_model_tree_sortable_init (GtkTreeSortableIface * iface); + +G_DEFINE_TYPE_WITH_CODE (VnGridModel, vn_grid_model, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL, + vn_grid_model_tree_model_init) + G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_SORTABLE, + vn_grid_model_tree_sortable_init) +); + +/** + * vn_grid_model_new: + * @model: a #DbModel + * + * Creates a new #VnGridModel with @model as the data model. + * + * Return value: (transfer full): a #VnGridModel. + **/ +VnGridModel * vn_grid_model_new (DbModel * model) +{ + return g_object_new (VN_TYPE_GRID_MODEL, "model", model, NULL); +} + +/** + * vn_grid_model_get_model: + * @obj: a #VnGridModel + * + * Passes the #DbModel used internally by @model. + * + * Return value: (transfer none): a #DbModel. + **/ +DbModel * vn_grid_model_get_model (VnGridModel * obj) +{ + g_return_val_if_fail (VN_IS_GRID_MODEL (obj), NULL); + + return obj->model; +} +/** + * vn_gtk_tree_iter_from_db_iter: + * @dest_iter: the #GtkTreeIter to set using the data on @src_iter + * @src_iter: a valid #DbIter + * + * Sets a #GtkTreeIter with the data of a #DbIter. This function is mostly used + * internally. + **/ +void gtk_tree_iter_from_db_iter (GtkTreeIter * dest_iter, const DbIter * src_iter) +{ + dest_iter->stamp = src_iter->stamp; + dest_iter->user_data = src_iter->data; +} + +/** + * vn_gtk_tree_iter_to_db_iter: + * @src_iter: a valid #GtkTreeIter + * @dest_iter: the #DbIter to set using the data on @src_iter + * + * Sets a with #DbIter the data of a #GtkTreeIter. This function is mostly used + * internally. + **/ +void gtk_tree_iter_to_db_iter (const GtkTreeIter * src_iter, DbIter * dest_iter) +{ + dest_iter->stamp = src_iter->stamp; + dest_iter->data = src_iter->user_data; +} + +/** + * vn_grid_model_iter_is_valid: + * @iter: a #GtkTreeIter + * @model: a #GtkTreeModel + * + * Checks if @iter is a valid #GtkTreeIter pointing inside #GtkTreeModel. + **/ +gboolean vn_grid_model_iter_is_valid (GtkTreeIter * iter, GtkTreeModel * model) +{ + DbIter db_iter; + + g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE); + + gtk_tree_iter_to_db_iter (iter, &db_iter); + return db_model_iter_is_valid (&db_iter, VN_GRID_MODEL (model)->model); +} + +static gint vn_grid_model_get_nrows (GtkTreeModel * obj) +{ + return db_model_get_nrows (VN_GRID_MODEL (obj)->model); +} + +//++++ Broadcast of GtkTreeModel and GtkTreeSortable signals: + +static void vn_grid_model_on_line_updated (DbModel * model, DbIter * db_iter, GtkTreeModel * obj) +{ + GtkTreeIter iter; + gtk_tree_iter_from_db_iter (&iter, db_iter); + + GtkTreePath * path = gtk_tree_path_new (); + gtk_tree_path_append_index (path, db_model_get_path (model, db_iter)); + + gtk_tree_model_row_changed (obj, path, &iter); + + gtk_tree_path_free (path); +} + +static void vn_grid_model_on_line_inserted (DbModel * model, DbIter * db_iter, GtkTreeModel * obj) +{ + GtkTreeIter iter; + gtk_tree_iter_from_db_iter (&iter, db_iter); + + GtkTreePath * path = gtk_tree_path_new (); + gtk_tree_path_append_index (path, + db_model_get_path (model, db_iter)); + + gtk_tree_model_row_inserted (obj, path, &iter); + + gtk_tree_path_free (path); +} + +static void vn_grid_model_on_line_deleted (DbModel * model, gint position, GtkTreeModel * obj) +{ + GtkTreePath * path = gtk_tree_path_new (); + gtk_tree_path_append_index (path, position); + + if (gtk_tree_path_get_indices (path)) + gtk_tree_model_row_deleted (obj, path); + + gtk_tree_path_free (path); +} + +static void vn_grid_model_on_lines_reordered (DbModel * model, guint col, gint * new_order, GtkTreeModel * obj) +{ + GtkTreePath * path = gtk_tree_path_new (); + gtk_tree_model_rows_reordered (obj, path, NULL, new_order); + gtk_tree_path_free (path); +} + +static void vn_grid_model_on_sort_changed (DbModel * model, GtkTreeSortable * obj) +{ + g_signal_emit_by_name (obj, "sort-column-changed"); +} + +//++++ Implementation of GtkTreeModel methods (using DbModel methods) + +static GtkTreeModelFlags vn_grid_model_get_flags (GtkTreeModel * obj) +{ + return GTK_TREE_MODEL_ITERS_PERSIST | GTK_TREE_MODEL_LIST_ONLY; +} + +static gint vn_grid_model_get_ncols (GtkTreeModel * obj) +{ + return db_model_get_ncols (VN_GRID_MODEL (obj)->model); +} + +static GType vn_grid_model_get_column_type (GtkTreeModel * obj, gint index_) +{ + return db_model_get_column_type (VN_GRID_MODEL (obj)->model, index_); +} + +static gboolean vn_grid_model_get_iter (GtkTreeModel * obj, GtkTreeIter * iter, + GtkTreePath * path) +{ + DbIter db_iter; + gint p = gtk_tree_path_get_indices (path)[0]; + + gboolean ret = db_model_get_iter (VN_GRID_MODEL (obj)->model, &db_iter, p); + + if (ret) + gtk_tree_iter_from_db_iter (iter, &db_iter); + + return ret; +} + +static GtkTreePath * vn_grid_model_get_path (GtkTreeModel * obj, GtkTreeIter * iter) +{ + GtkTreePath * path; + DbIter db_iter; + + gtk_tree_iter_to_db_iter (iter, &db_iter); + + path = gtk_tree_path_new (); + gtk_tree_path_append_index (path, + db_model_get_path (VN_GRID_MODEL (obj)->model, &db_iter)); + + return path; +} + +static void vn_grid_model_get_value (GtkTreeModel * obj, GtkTreeIter * iter, + gint column, GValue * value) +{ + const GValue * v; + DbIter db_iter; + + gtk_tree_iter_to_db_iter (iter, &db_iter); + + v = db_model_get_value (VN_GRID_MODEL (obj)->model, &db_iter, column, NULL); + + if (v) + { + g_value_init (value, G_VALUE_TYPE (v)); + g_value_copy (v, value); + } + else + g_value_init (value, GVN_TYPE_NULL); +} + +static gboolean vn_grid_model_iter_next (GtkTreeModel * obj, GtkTreeIter * iter) +{ + DbIter db_iter; + gtk_tree_iter_to_db_iter (iter, &db_iter); + + gboolean ret_val = db_model_iter_next (VN_GRID_MODEL (obj)->model, &db_iter); + + iter->user_data = db_iter.data; + + return ret_val; +} + +static gboolean vn_grid_model_iter_previous (GtkTreeModel * obj, GtkTreeIter * iter) +{ + DbIter db_iter; + gtk_tree_iter_to_db_iter (iter, &db_iter); + + gboolean ret_val = db_model_iter_prev (VN_GRID_MODEL (obj)->model, &db_iter); + + iter->user_data = db_iter.data; + + return ret_val; +} + +static gboolean vn_grid_model_iter_children (GtkTreeModel * obj, GtkTreeIter * iter, + GtkTreeIter * parent) +{ + if (parent == NULL) + { + DbIter db_iter; + + gboolean ret_val = db_model_get_iter_first (VN_GRID_MODEL (obj)->model + ,&db_iter); + + if (ret_val) + gtk_tree_iter_from_db_iter (iter, &db_iter); + + return ret_val; + } + + return FALSE; +} + +static gboolean vn_grid_model_iter_has_child (GtkTreeModel * obj, GtkTreeIter * iter) +{ + return FALSE; +} + +static gint vn_grid_model_iter_n_children (GtkTreeModel * obj, GtkTreeIter * iter) +{ + if (iter == NULL) + return vn_grid_model_get_nrows (obj); + + return 0; +} + +static gboolean vn_grid_model_iter_nth_child (GtkTreeModel * obj, GtkTreeIter * iter + ,GtkTreeIter * parent, gint n) +{ + if (parent == NULL) + { + DbIter db_iter; + gboolean ret = db_model_get_iter (VN_GRID_MODEL (obj)->model, &db_iter, n); + + if (ret) + gtk_tree_iter_from_db_iter (iter, &db_iter); + } + + return FALSE; +} + +static gboolean vn_grid_model_iter_parent (GtkTreeModel * obj, GtkTreeIter * iter, + GtkTreeIter * child) +{ + return FALSE; +} + +//++++ Implementation of GtkTreeSortable methods (using DbModel methods) + +static gboolean vn_grid_model_get_sort_column_id (GtkTreeSortable * obj, + gint * sort_column_id, + GtkSortType * order) +{ + return db_model_get_sort_column_id (VN_GRID_MODEL (obj)->model + ,sort_column_id, (DbSortType *) order); +} + +static void vn_grid_model_set_sort_column_id (GtkTreeSortable * obj, gint sort_column_id, + GtkSortType order) +{ + DbSortType db_order; + + if (order == GTK_SORT_ASCENDING) + db_order = DB_SORT_ASCENDING; + else + db_order = DB_SORT_DESCENDING; + + db_model_set_sort_column_id (VN_GRID_MODEL (obj)->model, sort_column_id, db_order); +} + +static void vn_grid_model_set_sort_func (GtkTreeSortable *sortable, gint sort_column_id, + GtkTreeIterCompareFunc sort_func, gpointer user_data, GDestroyNotify destroy) +{ + g_log (g_quark_to_string (VN_GRID_MODEL_LOG_DOMAIN) + ,G_LOG_LEVEL_WARNING, "Function vn_grid_model_set_sort_func not implemented"); +} + +static void vn_grid_model_set_default_sort_func (GtkTreeSortable *sortable, + GtkTreeIterCompareFunc sort_func, gpointer user_data, GDestroyNotify destroy) +{ + g_log (g_quark_to_string (VN_GRID_MODEL_LOG_DOMAIN) + ,G_LOG_LEVEL_WARNING, "Function vn_grid_model_set_default_sort_func not implemented"); +} + +static gboolean vn_grid_model_has_default_sort_func (GtkTreeSortable * obj) +{ + return TRUE; +} + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Properties + +typedef enum +{ + PROP_MODEL = 1 +} +VnGridModelProp; + +static void vn_grid_model_set_property (VnGridModel * obj, guint property_id, + const GValue * value, GParamSpec * pspec) +{ + switch (property_id) + { + case PROP_MODEL: + obj->model = g_value_get_object (value); + g_object_ref_sink (obj->model); + g_object_connect (obj->model + ,"signal-after::line-updated", vn_grid_model_on_line_updated, obj + ,"signal::line-inserted", vn_grid_model_on_line_inserted, obj + ,"signal-after::line-deleted", vn_grid_model_on_line_deleted, obj + ,"signal::lines-reordered", vn_grid_model_on_lines_reordered, obj + ,"signal::sort-changed", vn_grid_model_on_sort_changed, obj, NULL); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec); + } +} + +static void vn_grid_model_get_property (VnGridModel * obj, guint property_id, + GValue * value, GParamSpec * pspec) +{ + switch (property_id) + { + case PROP_MODEL: + g_value_set_object (value, obj->model); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec); + } +} + +//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Class + +static void vn_grid_model_finalize (VnGridModel * obj) +{ + g_object_disconnect (obj->model + ,"any_signal", vn_grid_model_on_line_updated, obj + ,"any_signal", vn_grid_model_on_line_inserted, obj + ,"any_signal", vn_grid_model_on_line_deleted, obj + ,"any_signal", vn_grid_model_on_lines_reordered, obj + ,"any_signal", vn_grid_model_on_sort_changed, obj, NULL); + + g_object_unref (obj->model); + + G_OBJECT_CLASS (vn_grid_model_parent_class)->finalize (G_OBJECT (obj)); +} + +static void vn_grid_model_class_init (VnGridModelClass * k) +{ + GObjectClass * klass = G_OBJECT_CLASS (k); + klass->set_property = (GObjectSetPropertyFunc) vn_grid_model_set_property; + klass->get_property = (GObjectGetPropertyFunc) vn_grid_model_get_property; + klass->finalize = (GObjectFinalizeFunc) vn_grid_model_finalize; + + g_object_class_install_property (klass, PROP_MODEL, + g_param_spec_object ("model" + ,"Model" + ,"The #DbModel with the data used by the #VnGridModel" + ,DB_TYPE_MODEL + ,G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE + )); +} + +static void vn_grid_model_tree_model_init (GtkTreeModelIface * iface) +{ + iface->get_flags = vn_grid_model_get_flags; + iface->get_n_columns = vn_grid_model_get_ncols; + iface->get_column_type = vn_grid_model_get_column_type; + iface->get_iter = vn_grid_model_get_iter; + iface->get_path = vn_grid_model_get_path; + iface->get_value = vn_grid_model_get_value; + iface->iter_next = vn_grid_model_iter_next; + iface->iter_previous = vn_grid_model_iter_previous; + + iface->iter_children = vn_grid_model_iter_children; + iface->iter_has_child = vn_grid_model_iter_has_child; + iface->iter_n_children = vn_grid_model_iter_n_children; + iface->iter_nth_child = vn_grid_model_iter_nth_child; + iface->iter_parent = vn_grid_model_iter_parent; +} + +static void vn_grid_model_tree_sortable_init (GtkTreeSortableIface * iface) +{ + iface->get_sort_column_id = vn_grid_model_get_sort_column_id; + iface->set_sort_column_id = vn_grid_model_set_sort_column_id; + iface->set_sort_func = vn_grid_model_set_sort_func; + iface->set_default_sort_func = vn_grid_model_set_default_sort_func; + iface->has_default_sort_func = vn_grid_model_has_default_sort_func; +} + +static void vn_grid_model_init (VnGridModel * obj) +{ + obj->model = NULL; +} diff --git a/vn/vn-model.h b/vn/vn-grid-model.h similarity index 52% rename from vn/vn-model.h rename to vn/vn-grid-model.h index 0fa87cd..670f128 100644 --- a/vn/vn-model.h +++ b/vn/vn-grid-model.h @@ -15,44 +15,44 @@ * along with this program. If not, see . */ -#ifndef VN_MODEL_H -#define VN_MODEL_H +#ifndef VN_GRID_MODEL_H +#define VN_GRID_MODEL_H #include #include #include -#define VN_TYPE_MODEL (vn_model_get_type()) -#define VN_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VN_TYPE_MODEL, VnModel)) -#define VN_IS_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VN_TYPE_MODEL)) -#define VN_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VN_TYPE_MODEL, VnModelClass)) -#define VN_IS_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VN_TYPE_MODEL)) -#define VN_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VN_TYPE_MODEL, VnModelClass)) +#define VN_TYPE_GRID_MODEL (vn_grid_model_get_type()) +#define VN_GRID_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VN_TYPE_GRID_MODEL, VnGridModel)) +#define VN_IS_GRID_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VN_TYPE_GRID_MODEL)) +#define VN_GRID_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VN_TYPE_GRID_MODEL, VnGridModelClass)) +#define VN_IS_GRID_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VN_TYPE_GRID_MODEL)) +#define VN_GRID_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VN_TYPE_GRID_MODEL, VnGridModelClass)) -#define VN_MODEL_LOG_DOMAIN (g_quark_from_string ("VnModel")) +#define VN_GRID_MODEL_LOG_DOMAIN (g_quark_from_string ("VnGridModel")) #define gtk_tree_iter_from_db_iter(d,s) vn_gtk_tree_iter_from_db_iter(d,s) #define gtk_tree_iter_to_db_iter(s,d) vn_gtk_tree_iter_to_db_iter(s,d) -typedef struct _VnModel VnModel; -typedef struct _VnModelClass VnModelClass; +typedef struct _VnGridModel VnGridModel; +typedef struct _VnGridModelClass VnGridModelClass; -struct _VnModel +struct _VnGridModel { GObject parent; DbModel * model; }; -struct _VnModelClass +struct _VnGridModelClass { /* */ GObjectClass parent; }; -GType vn_model_get_type (); -VnModel * vn_model_new (DbModel * model); -DbModel * vn_model_get_model (VnModel * obj); -gboolean vn_model_iter_is_valid (GtkTreeIter * iter, GtkTreeModel * model); +GType vn_grid_model_get_type (); +VnGridModel * vn_grid_model_new (DbModel * model); +DbModel * vn_grid_model_get_model (VnGridModel * obj); +gboolean vn_grid_model_iter_is_valid (GtkTreeIter * iter, GtkTreeModel * model); void vn_gtk_tree_iter_from_db_iter (GtkTreeIter * dest_iter ,const DbIter * src_iter); void vn_gtk_tree_iter_to_db_iter (const GtkTreeIter * src_iter diff --git a/vn/vn-grid.c b/vn/vn-grid.c index b91553a..562a94a 100644 --- a/vn/vn-grid.c +++ b/vn/vn-grid.c @@ -109,7 +109,7 @@ static void vn_grid_on_status_changed (DbIterator * iterator, gboolean ready, Vn if (ready) { - GtkTreeModel * tree_model = GTK_TREE_MODEL (vn_model_new (obj->model)); + GtkTreeModel * tree_model = GTK_TREE_MODEL (vn_grid_model_new (obj->model)); gtk_tree_view_set_model (GTK_TREE_VIEW (obj), tree_model); vn_grid_on_iter_changed (obj->iterator, GTK_TREE_VIEW (obj)); g_object_unref (tree_model); diff --git a/vn/vn-grid.h b/vn/vn-grid.h index f99cdf2..3d1f9a3 100644 --- a/vn/vn-grid.h +++ b/vn/vn-grid.h @@ -20,7 +20,7 @@ #include #include -#include "vn-model.h" +#include "vn-grid-model.h" #include "vn-column.h" #define VN_TYPE_GRID (vn_grid_get_type ()) diff --git a/vn/vn-gui.c b/vn/vn-gui.c index 1e3079c..c42927f 100644 --- a/vn/vn-gui.c +++ b/vn/vn-gui.c @@ -699,7 +699,7 @@ static gboolean vn_gui_reconnect_idle (GuiData * gui_data) if (!gui_data->aux) vn_gui_show_error (gui_data->obj, gui_data->error); - return FALSE; + return G_SOURCE_REMOVE; } /* @@ -737,7 +737,7 @@ static gboolean vn_gui_logout_idle (GuiData * gui_data) else g_signal_emit (gui_data->obj, signals[LOGOUT], 0); - return FALSE; + return G_SOURCE_REMOVE; } /* diff --git a/vn/vn-login.c b/vn/vn-login.c index 658474f..2bee37c 100644 --- a/vn/vn-login.c +++ b/vn/vn-login.c @@ -307,7 +307,7 @@ static gboolean vn_login_done (ConnectData * connect_data) } vn_login_set_loading (obj, FALSE); - return FALSE; + return G_SOURCE_REMOVE; } /* diff --git a/vn/vn-model.c b/vn/vn-model.c deleted file mode 100644 index debf93d..0000000 --- a/vn/vn-model.c +++ /dev/null @@ -1,447 +0,0 @@ -/* - * Copyright (C) 2012 - Juan Ferrer Toribio - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "vn-model.h" - -/** - * vn_model_new: - * @model: a #DbModel - * - * Creates a new #VnModel with @model as the data model. - * - * Return value: (transfer full): a #VnModel. - **/ -VnModel * vn_model_new (DbModel * model) -{ - return g_object_new (VN_TYPE_MODEL, "model", model, NULL); -} - -/** - * vn_model_get_model: - * @obj: a #VnModel - * - * Passes the #DbModel used internally by @model. - * - * Return value: (transfer none): a #DbModel. - **/ -DbModel * vn_model_get_model (VnModel * obj) -{ - g_return_val_if_fail (VN_IS_MODEL (obj), NULL); - - return obj->model; -} -/** - * vn_gtk_tree_iter_from_db_iter: - * @dest_iter: the #GtkTreeIter to set using the data on @src_iter - * @src_iter: a valid #DbIter - * - * Sets a #GtkTreeIter with the data of a #DbIter. This function is mostly used - * internally. - **/ -void gtk_tree_iter_from_db_iter (GtkTreeIter * dest_iter, const DbIter * src_iter) -{ - dest_iter->stamp = src_iter->stamp; - dest_iter->user_data = src_iter->data; -} - -/** - * vn_gtk_tree_iter_to_db_iter: - * @src_iter: a valid #GtkTreeIter - * @dest_iter: the #DbIter to set using the data on @src_iter - * - * Sets a with #DbIter the data of a #GtkTreeIter. This function is mostly used - * internally. - **/ -void gtk_tree_iter_to_db_iter (const GtkTreeIter * src_iter, DbIter * dest_iter) -{ - dest_iter->stamp = src_iter->stamp; - dest_iter->data = src_iter->user_data; -} - -/** - * vn_model_iter_is_valid: - * @iter: a #GtkTreeIter - * @model: a #GtkTreeModel - * - * Checks if @iter is a valid #GtkTreeIter pointing inside #GtkTreeModel. - **/ -gboolean vn_model_iter_is_valid (GtkTreeIter * iter, GtkTreeModel * model) -{ - DbIter db_iter; - - g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE); - - gtk_tree_iter_to_db_iter (iter, &db_iter); - return db_model_iter_is_valid (&db_iter, VN_MODEL (model)->model); -} - -static gint vn_model_get_nrows (GtkTreeModel * obj) -{ - return db_model_get_nrows (VN_MODEL (obj)->model); -} - -//++++ Broadcast of GtkTreeModel and GtkTreeSortable signals: - -static void vn_model_on_line_updated (DbModel * model, DbIter * db_iter, GtkTreeModel * obj) -{ - GtkTreeIter iter; - gtk_tree_iter_from_db_iter (&iter, db_iter); - - GtkTreePath * path = gtk_tree_path_new (); - gtk_tree_path_append_index (path, db_model_get_path (model, db_iter)); - - gtk_tree_model_row_changed (obj, path, &iter); - - gtk_tree_path_free (path); -} - -static void vn_model_on_line_inserted (DbModel * model, DbIter * db_iter, GtkTreeModel * obj) -{ - GtkTreeIter iter; - gtk_tree_iter_from_db_iter (&iter, db_iter); - - GtkTreePath * path = gtk_tree_path_new (); - gtk_tree_path_append_index (path, - db_model_get_path (model, db_iter)); - - gtk_tree_model_row_inserted (obj, path, &iter); - - gtk_tree_path_free (path); -} - -static void vn_model_on_line_deleted (DbModel * model, gint position, GtkTreeModel * obj) -{ - GtkTreePath * path = gtk_tree_path_new (); - gtk_tree_path_append_index (path, position); - - if (gtk_tree_path_get_indices (path)) - gtk_tree_model_row_deleted (obj, path); - - gtk_tree_path_free (path); -} - -static void vn_model_on_lines_reordered (DbModel * model, guint col, gint * new_order, GtkTreeModel * obj) -{ - GtkTreePath * path = gtk_tree_path_new (); - gtk_tree_model_rows_reordered (obj, path, NULL, new_order); - gtk_tree_path_free (path); -} - -static void vn_model_on_sort_changed (DbModel * model, GtkTreeSortable * obj) -{ - g_signal_emit_by_name (obj, "sort-column-changed"); -} - -//++++ Implementation of GtkTreeModel methods (using DbModel methods) - -static GtkTreeModelFlags vn_model_get_flags (GtkTreeModel * obj) -{ - return GTK_TREE_MODEL_ITERS_PERSIST | GTK_TREE_MODEL_LIST_ONLY; -} - -static gint vn_model_get_ncols (GtkTreeModel * obj) -{ - return db_model_get_ncols (VN_MODEL (obj)->model); -} - -static GType vn_model_get_column_type (GtkTreeModel * obj, gint index_) -{ - return db_model_get_column_type (VN_MODEL (obj)->model, index_); -} - -static gboolean vn_model_get_iter (GtkTreeModel * obj, GtkTreeIter * iter, - GtkTreePath * path) -{ - DbIter db_iter; - gint p = gtk_tree_path_get_indices (path)[0]; - - gboolean ret = db_model_get_iter (VN_MODEL (obj)->model, &db_iter, p); - - if (ret) - gtk_tree_iter_from_db_iter (iter, &db_iter); - - return ret; -} - -static GtkTreePath * vn_model_get_path (GtkTreeModel * obj, GtkTreeIter * iter) -{ - GtkTreePath * path; - DbIter db_iter; - - gtk_tree_iter_to_db_iter (iter, &db_iter); - - path = gtk_tree_path_new (); - gtk_tree_path_append_index (path, - db_model_get_path (VN_MODEL (obj)->model, &db_iter)); - - return path; -} - -static void vn_model_get_value (GtkTreeModel * obj, GtkTreeIter * iter, - gint column, GValue * value) -{ - const GValue * v; - DbIter db_iter; - - gtk_tree_iter_to_db_iter (iter, &db_iter); - - v = db_model_get_value (VN_MODEL (obj)->model, &db_iter, column, NULL); - - if (v) - { - g_value_init (value, G_VALUE_TYPE (v)); - g_value_copy (v, value); - } - else - g_value_init (value, GVN_TYPE_NULL); -} - -static gboolean vn_model_iter_next (GtkTreeModel * obj, GtkTreeIter * iter) -{ - DbIter db_iter; - gtk_tree_iter_to_db_iter (iter, &db_iter); - - gboolean ret_val = db_model_iter_next (VN_MODEL (obj)->model, &db_iter); - - iter->user_data = db_iter.data; - - return ret_val; -} - -static gboolean vn_model_iter_previous (GtkTreeModel * obj, GtkTreeIter * iter) -{ - DbIter db_iter; - gtk_tree_iter_to_db_iter (iter, &db_iter); - - gboolean ret_val = db_model_iter_prev (VN_MODEL (obj)->model, &db_iter); - - iter->user_data = db_iter.data; - - return ret_val; -} - -static gboolean vn_model_iter_children (GtkTreeModel * obj, GtkTreeIter * iter, - GtkTreeIter * parent) -{ - if (parent == NULL) - { - DbIter db_iter; - - gboolean ret_val = db_model_get_iter_first (VN_MODEL (obj)->model - ,&db_iter); - - if (ret_val) - gtk_tree_iter_from_db_iter (iter, &db_iter); - - return ret_val; - } - - return FALSE; -} - -static gboolean vn_model_iter_has_child (GtkTreeModel * obj, GtkTreeIter * iter) -{ - return FALSE; -} - -static gint vn_model_iter_n_children (GtkTreeModel * obj, GtkTreeIter * iter) -{ - if (iter == NULL) - return vn_model_get_nrows (obj); - - return 0; -} - -static gboolean vn_model_iter_nth_child (GtkTreeModel * obj, GtkTreeIter * iter - ,GtkTreeIter * parent, gint n) -{ - if (parent == NULL) - { - DbIter db_iter; - gboolean ret = db_model_get_iter (VN_MODEL (obj)->model, &db_iter, n); - - if (ret) - gtk_tree_iter_from_db_iter (iter, &db_iter); - } - - return FALSE; -} - -static gboolean vn_model_iter_parent (GtkTreeModel * obj, GtkTreeIter * iter, - GtkTreeIter * child) -{ - return FALSE; -} - -//++++ Implementation of GtkTreeSortable methods (using DbModel methods) - -static gboolean vn_model_get_sort_column_id (GtkTreeSortable * obj, - gint * sort_column_id, - GtkSortType * order) -{ - return db_model_get_sort_column_id (VN_MODEL (obj)->model - ,sort_column_id, (DbSortType *) order); -} - -static void vn_model_set_sort_column_id (GtkTreeSortable * obj, gint sort_column_id, - GtkSortType order) -{ - DbSortType db_order; - - if (order == GTK_SORT_ASCENDING) - db_order = DB_SORT_ASCENDING; - else - db_order = DB_SORT_DESCENDING; - - db_model_set_sort_column_id (VN_MODEL (obj)->model, sort_column_id, db_order); -} - -static void vn_model_set_sort_func (GtkTreeSortable *sortable, gint sort_column_id, - GtkTreeIterCompareFunc sort_func, gpointer user_data, GDestroyNotify destroy) -{ - g_log (g_quark_to_string (VN_MODEL_LOG_DOMAIN) - ,G_LOG_LEVEL_WARNING, _("Function vn_model_set_sort_func not implemented")); -} - -static void vn_model_set_default_sort_func (GtkTreeSortable *sortable, - GtkTreeIterCompareFunc sort_func, gpointer user_data, GDestroyNotify destroy) -{ - g_log (g_quark_to_string (VN_MODEL_LOG_DOMAIN) - ,G_LOG_LEVEL_WARNING, _("Function vn_model_set_default_sort_func not implemented")); -} - -static gboolean vn_model_has_default_sort_func (GtkTreeSortable * obj) -{ - return TRUE; -} - -//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Properties - -typedef enum -{ - PROP_MODEL = 1 -} -VnModelProp; - -static void vn_model_set_property (VnModel * obj, guint property_id, - const GValue * value, GParamSpec * pspec) -{ - switch (property_id) - { - case PROP_MODEL: - obj->model = g_value_get_object (value); - g_object_ref_sink (obj->model); - g_object_connect (obj->model - ,"signal-after::line-updated", vn_model_on_line_updated, obj - ,"signal::line-inserted", vn_model_on_line_inserted, obj - ,"signal-after::line-deleted", vn_model_on_line_deleted, obj - ,"signal::lines-reordered", vn_model_on_lines_reordered, obj - ,"signal::sort-changed", vn_model_on_sort_changed, obj, NULL); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec); - } -} - -static void vn_model_get_property (VnModel * obj, guint property_id, - GValue * value, GParamSpec * pspec) -{ - switch (property_id) - { - case PROP_MODEL: - g_value_set_object (value, obj->model); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec); - } -} - -//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Class - -static void vn_model_finalize (VnModel * obj) -{ - GObjectClass * parent; - parent = g_type_class_peek_parent (VN_MODEL_GET_CLASS (obj)); - - g_object_disconnect (obj->model - ,"any_signal", vn_model_on_line_updated, obj - ,"any_signal", vn_model_on_line_inserted, obj - ,"any_signal", vn_model_on_line_deleted, obj - ,"any_signal", vn_model_on_lines_reordered, obj - ,"any_signal", vn_model_on_sort_changed, obj, NULL); - - g_object_unref (obj->model); - - parent->finalize (G_OBJECT (obj)); -} - -static void vn_model_class_init (VnModelClass * k) -{ - GObjectClass * klass = G_OBJECT_CLASS (k); - klass->set_property = (GObjectSetPropertyFunc) vn_model_set_property; - klass->get_property = (GObjectGetPropertyFunc) vn_model_get_property; - klass->finalize = (GObjectFinalizeFunc) vn_model_finalize; - - g_object_class_install_property (klass, PROP_MODEL, - g_param_spec_object ("model" - ,"Model" - ,"The #DbModel with the data used by the #VnModel" - ,DB_TYPE_MODEL - ,G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE - )); -} - -// tienen que implementarse con métodos heredados de db-model -static void vn_model_tree_model_interface_init (GtkTreeModelIface * iface) -{ - iface->get_flags = vn_model_get_flags; - iface->get_n_columns = vn_model_get_ncols; - iface->get_column_type = vn_model_get_column_type; - iface->get_iter = vn_model_get_iter; - iface->get_path = vn_model_get_path; - iface->get_value = vn_model_get_value; - iface->iter_next = vn_model_iter_next; - iface->iter_previous = vn_model_iter_previous; - - iface->iter_children = vn_model_iter_children; - iface->iter_has_child = vn_model_iter_has_child; - iface->iter_n_children = vn_model_iter_n_children; - iface->iter_nth_child = vn_model_iter_nth_child; - iface->iter_parent = vn_model_iter_parent; -} - -static void vn_model_tree_sortable_interface_init (GtkTreeSortableIface * iface) -{ - iface->get_sort_column_id = vn_model_get_sort_column_id; - iface->set_sort_column_id = vn_model_set_sort_column_id; - iface->set_sort_func = vn_model_set_sort_func; - iface->set_default_sort_func = vn_model_set_default_sort_func; - iface->has_default_sort_func = vn_model_has_default_sort_func; - -} - -static void vn_model_init (VnModel * obj) -{ - obj->model = NULL; -} - -G_DEFINE_TYPE_WITH_CODE (VnModel, vn_model, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL, - vn_model_tree_model_interface_init) - G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_SORTABLE, - vn_model_tree_sortable_interface_init) -); diff --git a/vn/vn.h b/vn/vn.h index e8188cb..8e1c125 100644 --- a/vn/vn.h +++ b/vn/vn.h @@ -20,7 +20,7 @@ #include #include -#include "vn-model.h" +#include "vn-grid-model.h" #include "vn-handler.h" #include "vn-grid.h" #include "vn-login.h"