Added function GtkForm::get_key_as_hashtable.
Added function GtkFormKey::get_values_as_hashtable.
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1534144287" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.mingw.base.1110736935" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.base">
- <option id="gnu.c.compiler.option.include.paths.467981111" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
+ <option id="gnu.c.compiler.option.include.paths.467981111" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
+ <listOptionValue builtIn="false" value=""C:\mingw\include""/>
<listOptionValue builtIn="false" value=""C:\mingw\include\glib-2.0""/>
<listOptionValue builtIn="false" value=""C:\mingw\include\gtk-2.0""/>
<listOptionValue builtIn="false" value=""C:\mingw\include\libxml2""/>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
- <storageModule moduleId="scannerConfiguration">
- <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
- </storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="libgtkform.null.143602593" name="libgtkform"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
+ <storageModule moduleId="refreshScope"/>
+ <storageModule moduleId="scannerConfiguration">
+ <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+ <scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.2062724017;cdt.managedbuild.toolchain.gnu.mingw.base.2062724017.62298528;cdt.managedbuild.tool.gnu.cpp.compiler.mingw.base.1801393322;cdt.managedbuild.tool.gnu.cpp.compiler.input.1534144287">
+ <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"/>
+ </scannerConfigBuildInfo>
+ <scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.mingw.base.2062724017;cdt.managedbuild.toolchain.gnu.mingw.base.2062724017.62298528;cdt.managedbuild.tool.gnu.c.compiler.mingw.base.1110736935;cdt.managedbuild.tool.gnu.c.compiler.input.120046929">
+ <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
+ </scannerConfigBuildInfo>
+ </storageModule>
</cproject>
/*
- * Copyright (C) 2005-2012 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2013 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
return sql;
}
+gchar
+*gtk_form_get_sql_from_hashtable (GtkForm *form,
+ GtkFormSqlType type,
+ GHashTable *ht_keys,
+ GHashTable *ht_fields)
+{
+ GtkFormPrivate *priv;
+
+ gchar *sql;
+
+ GHashTable *_ht_fields;
+
+ GHashTableIter ht_iter_fields;
+
+ gpointer key_fields;
+ gpointer value_fields;
+
+ GtkFormField *ffield;
+
+ GdaExSqlType gdaexsqltype;
+
+ g_return_val_if_fail (IS_GTK_FORM (form), "");
+
+ priv = GTK_FORM_GET_PRIVATE (form);
+
+ g_return_val_if_fail (IS_GDAEX (priv->gdaex), "");
+
+ sql = "";
+
+ _ht_fields = g_hash_table_new (g_str_hash, g_str_equal);
+
+ g_hash_table_iter_init (&ht_iter_fields, ht_fields);
+ while (g_hash_table_iter_next (&ht_iter_fields, &key_fields, &value_fields))
+ {
+ ffield = gtk_form_get_form_field_from_name (form, (const gchar *)key_fields);
+ if (ffield != NULL)
+ {
+ switch (type)
+ {
+ case GTK_FORM_SQL_SELECT:
+ gdaexsqltype = GDAEX_SQL_SELECT;
+ if (gtk_form_field_is_to_load (ffield))
+ {
+ g_hash_table_insert (_ht_fields, key_fields, value_fields);
+ }
+ break;
+
+ case GTK_FORM_SQL_INSERT:
+ gdaexsqltype = GDAEX_SQL_INSERT;
+ if (gtk_form_field_is_to_save (ffield))
+ {
+ g_hash_table_insert (_ht_fields, key_fields, value_fields);
+ }
+ break;
+
+ case GTK_FORM_SQL_UPDATE:
+ gdaexsqltype = GDAEX_SQL_UPDATE;
+ if (gtk_form_field_is_to_save (ffield)
+ && (!IS_GTK_FORM_KEY (priv->key) ||
+ !gtk_form_key_field_is_key (priv->key, ffield)))
+ {
+ g_hash_table_insert (_ht_fields, key_fields, value_fields);
+ }
+ break;
+
+ case GTK_FORM_SQL_DELETE:
+ gdaexsqltype = GDAEX_SQL_DELETE;
+ break;
+ }
+ }
+ }
+
+ sql = g_strdup (gdaex_get_sql_from_hashtable (priv->gdaex,
+ gdaexsqltype,
+ priv->table,
+ ht_keys,
+ _ht_fields));
+
+ return sql;
+}
+
/**
* gtk_form_fill_from_datamodel:
* @form: a #GtkForm object.
return ret;
}
+GHashTable
+*gtk_form_get_key_as_hashtable (GtkForm *form)
+{
+ GtkFormPrivate *priv;
+ GHashTable *ht;
+
+ g_return_val_if_fail (IS_GTK_FORM (form), NULL);
+
+ priv = GTK_FORM_GET_PRIVATE (form);
+
+ ht = gtk_form_key_get_values_as_hashtable (priv->key);
+
+ return ht;
+}
+
/**
* gtk_form_get_values_as_xml:
* @form:
/*
- * Copyright (C) 2005-2012 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2013 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
gchar *gtk_form_get_sql (GtkForm *form, GtkFormSqlType type);
+gchar *gtk_form_get_sql_from_hashtable (GtkForm *form, GtkFormSqlType type, GHashTable *ht_keys, GHashTable *ht_fields);
+
gboolean gtk_form_fill_from_datamodel (GtkForm *form, GdaDataModel *dm, gint row);
gboolean gtk_form_fill_from_table (GtkForm *form);
GHashTable *gtk_form_get_original_values_as_hashtable (GtkForm *form);
gboolean gtk_form_fill_from_hashtable (GtkForm *form, GHashTable *hashtable);
+GHashTable *gtk_form_get_key_as_hashtable (GtkForm *form);
+
xmlNode *gtk_form_get_values_as_xml (GtkForm *form);
gboolean gtk_form_fill_from_xml (GtkForm *form, xmlNode *xnode);
return sql;
}
+/**
+ * gtk_form_key_get_valus_as_hashtable:
+ * @gtk_form_key: a #GtkFormKey object.
+ *
+ */
+GHashTable
+*gtk_form_key_get_values_as_hashtable (GtkFormKey *gtk_form_key)
+{
+ GHashTable *ht_ret;
+
+ GtkFormField *field;
+ gchar *field_name;
+ GValue *gval;
+
+ GtkFormKeyPrivate *priv;
+ GSList *fields;
+
+ g_return_val_if_fail (IS_GTK_FORM_KEY (gtk_form_key), NULL);
+
+ ht_ret = NULL;
+
+ priv = GTK_FORM_KEY_GET_PRIVATE (gtk_form_key);
+
+ fields = priv->fields;
+
+ if (fields != NULL)
+ {
+ ht_ret = g_hash_table_new (g_str_hash, g_str_equal);
+ }
+
+ while (fields != NULL)
+ {
+ field = (GtkFormField *)fields->data;
+
+ field_name = gtk_form_field_get_field_name (field);
+
+ gval = gtk_form_field_get_value (field);
+ if (gval != NULL)
+ {
+ /* TODO check if the field already exists */
+ g_hash_table_insert (ht_ret, field_name, gval);
+ }
+
+ fields = g_slist_next (fields);
+ }
+
+ g_free (field_name);
+
+ return ht_ret;
+}
+
/**
* gtk_form_key_field_is_key:
* @gtk_form_key: a #GtkFormKey object.
/*
- * Copyright (C) 2005-2009 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2013 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
gchar *gtk_form_key_get_sql (GtkFormKey *gtk_form_key);
+GHashTable *gtk_form_key_get_values_as_hashtable (GtkFormKey *gtk_form_key);
+
gboolean gtk_form_key_field_is_key (GtkFormKey *gtk_form_key, GtkFormField *field);
GtkWidget *lbl_id;
GtkWidget *txtv_sql;
GtkWidget *btn_new;
-GtkWidget *btn_edit;
+GtkWidget *btn_save;
GtkWidget *btn_delete;
GtkWidget *cb_customers;
GtkWidget *btn_open;
GtkWidget *btn_cancel;
+GtkWidget *btn_save_ht;
+GtkWidget *btn_delete_ht;
+GtkWidget *btn_open_ht;
+
GtkListStore *lstore_customers;
GtkTextBuffer *buf;
gtk_form_reset (form);
}
+G_MODULE_EXPORT void
+on_btn_save_ht_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ GHashTable *ht_keys;
+ GHashTable *ht_fields;
+
+ gchar *sql;
+
+ if (!gtk_form_check (form, FALSE, NULL, TRUE, w, FALSE))
+ {
+ return;
+ }
+
+ ht_keys = gtk_form_get_key_as_hashtable (form);
+ ht_fields = gtk_form_get_values_as_hashtable (form);
+
+ if (current_id == 0)
+ {
+ /* must find new id */
+ GdaDataModel *dm;
+ gint new_id = 0;
+
+ sql = "SELECT MAX(id) FROM customers";
+ dm = gdaex_query (gdaex, sql);
+
+ if (dm != NULL)
+ {
+ new_id = gdaex_data_model_get_value_integer_at (dm, 0, 0);
+ }
+ new_id++;
+
+ gtk_label_set_text (GTK_LABEL (lbl_id), g_strdup_printf ("%d", new_id));
+
+ sql = gtk_form_get_sql_from_hashtable (form, GTK_FORM_SQL_INSERT, ht_keys, ht_fields);
+ }
+ else
+ {
+ sql = gtk_form_get_sql_from_hashtable (form, GTK_FORM_SQL_UPDATE, ht_keys, ht_fields);
+ }
+
+ gtk_text_buffer_set_text (buf, sql, strlen (sql));
+
+ gdaex_execute (gdaex, sql);
+
+ fill_cb_customers ();
+ on_btn_new_clicked (NULL, NULL);}
+
+G_MODULE_EXPORT void
+on_btn_delete_ht_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ GHashTable *ht_keys;
+
+ ht_keys = gtk_form_get_key_as_hashtable (form);
+ gchar *sql = gtk_form_get_sql_from_hashtable (form, GTK_FORM_SQL_DELETE, ht_keys, NULL);
+
+ gtk_text_buffer_set_text (buf, sql, strlen (sql));
+
+ gdaex_execute (gdaex, sql);
+
+ fill_cb_customers ();
+ on_btn_new_clicked (NULL, NULL);
+}
+
+G_MODULE_EXPORT void
+on_btn_open_ht_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ GtkTreeIter iter;
+
+ gint id;
+
+ GHashTable *ht_keys;
+ GHashTable *ht_fields;
+
+ GdaDataModel *dm;
+
+ if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (cb_customers), &iter))
+ {
+ return;
+ }
+
+ gtk_tree_model_get (GTK_TREE_MODEL (lstore_customers), &iter,
+ 0, &id,
+ -1);
+
+ gtk_label_set_text (GTK_LABEL (lbl_id), g_strdup_printf ("%d", id));
+
+ ht_keys = gtk_form_get_key_as_hashtable (form);
+ ht_fields = gtk_form_get_values_as_hashtable (form);
+ gchar *sql = gtk_form_get_sql_from_hashtable (form, GTK_FORM_SQL_SELECT, ht_keys, ht_fields);
+
+ gtk_text_buffer_set_text (buf, sql, strlen (sql));
+
+ dm = gdaex_query (gdaex, sql);
+ if (dm == NULL)
+ {
+ on_btn_new_clicked (NULL, NULL);
+ return;
+ }
+
+ gtk_form_fill_from_datamodel (form, dm, 0);
+ current_id = id;
+}
+
void
fill_cb_customers (void)
{
form = gtk_form_new_from_file (GUIDIR "/test_db.xml", NULL);
if (form == NULL) return 0;
+ g_object_set (G_OBJECT (form), "gdaex", gdaex, NULL);
+
gtkbuilder = gtk_form_get_gtkbuilder (form);
error = NULL;
lbl_id = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "lbl_id"));
btn_new = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "btn_new"));
- btn_edit = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "btn_edit"));
+ btn_save = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "btn_save"));
btn_delete = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "btn_delete"));
cb_customers = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "cb_customers"));
btn_open = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "btn_open"));
btn_cancel = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "btn_cancel"));
+ btn_save_ht = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "btn_save_ht"));
+ btn_delete_ht = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "btn_delete_ht"));
+ btn_open_ht = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "btn_open_ht"));
+
lstore_customers = GTK_LIST_STORE (gtk_builder_get_object (gtkbuilder, "lstore_customers"));
fill_cb_customers ();
<property name="position">2</property>
</packing>
</child>
+ <child>
+ <object class="GtkHButtonBox" id="hbuttonbox3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="layout_style">center</property>
+ <child>
+ <object class="GtkButton" id="btn_save_ht">
+ <property name="label" translatable="yes">Salva HashTable</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked" handler="on_btn_save_ht_clicked" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="btn_delete_ht">
+ <property name="label" translatable="yes">Elimina HashTable</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked" handler="on_btn_delete_ht_clicked" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="btn_open_ht">
+ <property name="label" translatable="yes">Apri HashTable</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked" handler="on_btn_open_ht_clicked" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
<child>
<object class="GtkTable" id="table2">
<property name="visible">True</property>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">3</property>
+ <property name="position">4</property>
</packing>
</child>
</object>