]> saetta.ns0.it Git - zakauthe/plugins/db/commitdiff
Migrated to ZakForm.
authorAndrea Zagli <azagli@libero.it>
Mon, 18 Jul 2016 10:02:56 +0000 (12:02 +0200)
committerAndrea Zagli <azagli@libero.it>
Mon, 18 Jul 2016 10:02:56 +0000 (12:02 +0200)
configure.ac
data/libzakauthedb/form/user.form
src/user.c

index e43a6b727c7f9258bad0b3c5659c855496f062b4..6ba2870879a8008957fbb0a003870bd42e39f33c 100644 (file)
@@ -2,7 +2,7 @@
 # Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.59)
-AC_INIT([libzakauthedb], [0.5.0], [azagli@libero.it])
+AC_INIT([libzakauthedb], [0.5.99], [azagli@libero.it])
 AC_CONFIG_SRCDIR([src/aute_db.c])
 AC_CONFIG_HEADER([config.h])
 
@@ -20,9 +20,20 @@ AC_LIBTOOL_WIN32_DLL
 AC_PROG_CC
 AC_PROG_LIBTOOL
 
+dnl ******************************
+dnl Translations
+dnl ******************************
+GETTEXT_PACKAGE=zakformtests
+AC_SUBST(GETTEXT_PACKAGE)
+AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE",
+                   [The prefix for our gettext translation domains.])
+AM_GLIB_GNU_GETTEXT
+
 # Checks for libraries.
 PKG_CHECK_MODULES(LIBAUTEDB, [libzakauthe >= 0.5.0
-                              libgtkform >= 0.5.0])
+                              libzakform
+                              libzakformgtk
+                              libzakformgdaex])
 
 AC_SUBST(LIBAUTEDB_CFLAGS)
 AC_SUBST(LIBAUTEDB_LIBS)
index 3c8a12276e7a27a301200deb193c271eb19219b1..8df9ec67a6f6533c645288b02d3fdefc8055d867 100644 (file)
@@ -1,45 +1,57 @@
 <?xml version="1.0"?>
-<gtkform>
-
-       <table>users</table>
-
-       <widget type="entry" name="entry1" label="label6">
-               <field type="text" name="code">
-                       <is-key>t</is-key>
-                       <obligatory>t</obligatory>
-               </field>
-       </widget>
-
-       <widget type="label" name="label14">
-               <field type="text" name="password">
-               </field>
-       </widget>
-
-       <widget type="entry" name="entry2" label="label7">
-               <field type="text" name="surname">
-                       <obligatory>t</obligatory>
-               </field>
-       </widget>
-
-       <widget type="entry" name="entry3" label="label8">
-               <field type="text" name="name" />
-       </widget>
-
-       <widget type="checkbox" name="checkbutton1" label="label9">
-               <field type="boolean" name="enabled">
-                       <default>t</default>
-               </field>
-       </widget>
-
-       <widget type="entry" name="entry4" label="label11">
-               <field type="datetime" name="password_expiration">
-                       <datetime-type>datetime</datetime-type>
-                       <display-format>%d/%m/%Y %H.%M.%S</display-format>
-               </field>
-       </widget>
-
-       <widget type="textview" name="textview1" label="label12">
-               <field type="text" name="notes" />
-       </widget>
-
-</gtkform>
+<zakform>
+
+  <element type="zak_form_gtk_form_element_entry">
+       <name>code</name>
+       <type>string</type>
+       <is-key>TRUE</is-key>
+       <widget>entry1</widget>
+       <label>label6</label>
+       <validator type="zak_form_element_validator_notempty"></validator>
+  </element>
+
+  <element type="zak_form_gtk_form_element_label">
+       <name>password</name>
+       <type>string</type>
+       <widget>label14</widget>
+  </element>
+
+  <element type="zak_form_gtk_form_element_entry">
+       <name>surname</name>
+       <type>string</type>
+       <widget>entry2</widget>
+       <label>label7</label>
+       <validator type="zak_form_element_validator_notempty"></validator>
+  </element>
+
+  <element type="zak_form_gtk_form_element_entry">
+       <name>name</name>
+       <type>string</type>
+       <widget>entry3</widget>
+       <label>label8</label>
+  </element>
+
+  <element type="zak_form_gtk_form_element_check">
+       <name>enabled</name>
+       <type>boolean</type>
+       <widget>checkbutton1</widget>
+       <label>label11</label>
+  </element>
+
+  <element type="zak_form_gtk_form_element_entry">
+       <name>password_expiration</name>
+       <type>datetime</type>
+       <format>%d/%m/%Y %H.%M.%S</format>
+       <widget>entry4</widget>
+       <label>label11</label>
+       <validator type="zak_form_element_validator_date">%d/%m/%Y %H.%M.%S</validator>
+  </element>
+
+  <element type="zak_form_gtk_form_element_textview">
+       <name>notes</name>
+       <type>string</type>
+       <widget>textview1</widget>
+       <label>label12</label>
+  </element>
+
+</zakform>
index d27aa6ca3a59f641d8ca93f299525dd7ba2db1ab..d3f76abe1e95555c9a8e6ba0e25fed27960098e7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2015 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-2016 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
  *
  */
 
-#include <libgtkform/form.h>
+#ifdef HAVE_CONFIG_H
+       #include "config.h"
+#endif
+
+#include <libzakform/libzakform.h>
+#include <libzakformgtk/libzakformgtk.h>
+#include <libzakformgdaex/libzakformgdaex.h>
 
 #include "user.h"
 #include "aute_db.h"
@@ -50,12 +56,6 @@ static void user_on_btn_salva_clicked (GtkButton *button,
 
 #define USER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_USER, UserPrivate))
 
-enum
-{
-       TXT_CODE,
-       LBL_PASSWORD
-};
-
 typedef struct _UserPrivate UserPrivate;
 struct _UserPrivate
        {
@@ -64,12 +64,11 @@ struct _UserPrivate
                gchar *guifile;
                gchar *formdir;
 
-               GtkForm *form;
+               ZakFormGtkForm *form;
+               ZakFormGdaexProvider *provider;
 
                GtkWidget *w;
 
-               GObject **objects;
-
                gchar *code;
        };
 
@@ -144,19 +143,15 @@ User
                        return NULL;
                }
 
-       priv->form = gtk_form_new ();
-       g_object_set (priv->form, "gdaex", priv->gdaex, NULL);
-       gtk_form_load_from_file (priv->form, g_build_filename (priv->formdir, "user.form", NULL), priv->gtkbuilder);
+       priv->form = zak_form_gtk_form_new ();
+       zak_form_gtk_form_set_gtkbuilder (priv->form, priv->gtkbuilder);
+       zak_form_form_load_from_file (ZAK_FORM_FORM (priv->form), g_build_filename (priv->formdir, "user.form", NULL));
+       zak_form_form_set_as_original (ZAK_FORM_FORM (priv->form));
 
-       g_object_set (priv->form, "gdaex", priv->gdaex, NULL);
+       priv->provider = zak_form_gdaex_provider_new (gdaex, "users");
 
        priv->w = GTK_WIDGET (gtk_builder_get_object (priv->gtkbuilder, "w_user"));
 
-       priv->objects = gtk_form_get_objects_by_name (priv->form,
-                                                     "entry1",
-                                                     "label14",
-                                                     NULL);
-
        g_signal_connect (priv->w,
                          "delete-event", G_CALLBACK (user_on_w_user_delete_event), (gpointer *)a);
 
@@ -171,12 +166,12 @@ User
                }
        if (priv->code == NULL || g_strcmp0 (priv->code, "") == 0)
                {
-                       gtk_form_clear (priv->form);
+                       zak_form_form_clear (ZAK_FORM_FORM (priv->form));
                }
        else
                {
-                       gtk_entry_set_text (GTK_ENTRY (priv->objects[TXT_CODE]), priv->code);
-                       gtk_editable_set_editable (GTK_EDITABLE (priv->objects[TXT_CODE]), FALSE);
+                       gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (priv->gtkbuilder, "entry1")), priv->code);
+                       gtk_editable_set_editable (GTK_EDITABLE (gtk_builder_get_object (priv->gtkbuilder, "entry1")), FALSE);
 
                        user_carica (a);
                }
@@ -203,46 +198,41 @@ user_carica (User *user)
 {
        UserPrivate *priv = USER_GET_PRIVATE (user);
 
-       if (gtk_form_fill_from_table (priv->form))
-               {
-               }
+       zak_form_form_load (ZAK_FORM_FORM (priv->form), ZAK_FORM_IPROVIDER (priv->provider));
 }
 
 static void
 user_salva (User *user)
 {
        GError *error = NULL;
-       gchar *sql;
+       gboolean ret;
        GtkWidget *dialog;
 
-       GDate *da;
-       GDate *a;
-
        UserClass *klass = USER_GET_CLASS (user);
 
        UserPrivate *priv = USER_GET_PRIVATE (user);
 
-       if (!gtk_form_check (priv->form, FALSE, NULL, TRUE, priv->w, TRUE))
+       if (!zak_form_gtk_form_is_valid (priv->form, priv->w))
                {
                        return;
                }
 
        if (priv->code == NULL || g_strcmp0 (priv->code, "") == 0)
                {
-                       gtk_label_set_text (GTK_LABEL (priv->objects[LBL_PASSWORD]),
-                                           zak_authe_db_encrypt_password (gtk_entry_get_text (GTK_ENTRY (priv->objects[TXT_CODE]))));
-                       sql = gtk_form_get_sql (priv->form, GTK_FORM_SQL_INSERT);
+                       gtk_label_set_text (GTK_LABEL (gtk_builder_get_object (priv->gtkbuilder, "label14")),
+                                           zak_authe_db_encrypt_password (gtk_entry_get_text (GTK_ENTRY (gtk_builder_get_object (priv->gtkbuilder, "entry1")))));
+                       ret = zak_form_form_insert (ZAK_FORM_FORM (priv->form), ZAK_FORM_IPROVIDER (priv->provider));
                }
        else
                {
-                       sql = gtk_form_get_sql (priv->form, GTK_FORM_SQL_UPDATE);
+                       ret = zak_form_form_update (ZAK_FORM_FORM (priv->form), ZAK_FORM_IPROVIDER (priv->provider));
                }
 
-       if (gdaex_execute (priv->gdaex, sql) == 1)
+       if (ret)
                {
                        g_signal_emit (user, klass->aggiornato_signal_id, 0);
 
-                       gtk_form_set_as_origin (priv->form);
+                       zak_form_form_set_as_original (ZAK_FORM_FORM (priv->form));
 
                        dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
                                                                                         GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -304,7 +294,7 @@ user_conferma_chiusura (User *user)
        UserPrivate *priv = USER_GET_PRIVATE (user);
 
        ret = TRUE;
-       if (gtk_form_is_changed (priv->form))
+       if (zak_form_form_is_changed (ZAK_FORM_FORM (priv->form)))
                {
                        dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
                                                                 GTK_DIALOG_DESTROY_WITH_PARENT,