]> saetta.ns0.it Git - zakauthe/plugins/db/commitdiff
Started management gui.
authorAndrea Zagli <azagli@libero.it>
Sun, 8 Aug 2010 08:48:45 +0000 (10:48 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 8 Aug 2010 08:48:45 +0000 (10:48 +0200)
data/libaute-db/form/Makefile.am
data/libaute-db/form/autedb.form [deleted file]
data/libaute-db/form/user.form [new file with mode: 0644]
data/libaute-db/gui/Makefile.am
src/Makefile.am
src/aute_db.c
src/user.c [new file with mode: 0644]
src/user.h [new file with mode: 0644]

index cb45d2a59ad2b5f0d25c21e4faba59249747e13c..cb7c395f808c3a6d1941f900b595e185893d526f 100644 (file)
@@ -1,5 +1,5 @@
 formdir = $(datadir)/libaute-db/form
 
-form_DATA = autedb.form
+form_DATA = user.form
 
 EXTRA_DIST = $(form_DATA)
diff --git a/data/libaute-db/form/autedb.form b/data/libaute-db/form/autedb.form
deleted file mode 100644 (file)
index b591d4b..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-<?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="label114">
-               <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>
diff --git a/data/libaute-db/form/user.form b/data/libaute-db/form/user.form
new file mode 100644 (file)
index 0000000..b591d4b
--- /dev/null
@@ -0,0 +1,45 @@
+<?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="label114">
+               <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>
index 30dc7449a313934457a7c875c085965946329beb..21349571ab0285562dbeb5237f464d2d9664b639 100644 (file)
@@ -1,5 +1,5 @@
 guidir = $(datadir)/libaute-db/gui
 
-gui_DATA = autedb.glade
+gui_DATA = autedb.gui
 
 EXTRA_DIST = $(gui_DATA)
index dc8bd35964b32015376da75e1b2324204da5c12f..9234dbd326bf0b02c94df8a5052d813f3f4bd278 100644 (file)
@@ -1,9 +1,11 @@
 guidir = $(datadir)/libaute-db/gui
+formdir = $(datadir)/libaute-db/form
 
 AM_CPPFLAGS = $(LIBAUTEDB_CFLAGS) \
               $(LIBGCRYPT_CFLAGS) \
               $(LIBCONFI_CFLAGS) \
-              -DGUIDIR=\""$(guidir)"\"
+              -DGUIDIR=\""$(guidir)"\" \
+              -DFORMDIR=\""$(formdir)"\"
 
 LIBS = $(LIBAUTEDB_LIBS) \
        $(LIBGCRYPT_LIBS) \
@@ -12,6 +14,8 @@ LIBS = $(LIBAUTEDB_LIBS) \
 libaute_pluginsdir = $(libdir)/libaute/plugins
 libaute_plugins_LTLIBRARIES = libaute-db.la
 
-libaute_db_la_SOURCES = aute_db.c
+libaute_db_la_SOURCES = aute_db.c \
+                        user.c \
+                        user.h
 
 libaute_db_la_LDFLAGS = -no-undefined
index 265454dce264e283df1c15c0c30bc04b7280c411..ebff62e1c338d3bbf22ea761222a12456478b535 100644 (file)
        #include <libconfi.h>
 #endif
 
+#include "user.h"
+
 static GtkBuilder *gtkbuilder;
 static GdaEx *gdaex;
 
+static gchar *guifile;
+static gchar *formdir;
+
 static GtkWidget *txt_utente;
 static GtkWidget *txt_password;
 static GtkWidget *exp_cambio;
@@ -237,10 +242,33 @@ autedb_load_users_list ()
                }
 }
 
+static void
+autedb_on_user_aggiornato (gpointer instance, gpointer user_data)
+{
+       autedb_load_users_list ();
+}
+
 static void
 autedb_on_btn_new_clicked (GtkButton *button,
                            gpointer user_data)
 {
+       GtkWidget *w;
+
+       User *u = user_new (gtkbuilder, gdaex, guifile, formdir, NULL);
+
+       g_signal_connect (G_OBJECT (u), "aggiornato",
+                         G_CALLBACK (autedb_on_user_aggiornato), NULL);
+
+       w = user_get_widget (u);
+       /*if (priv->selezione)
+               {
+                       gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (priv->widget));
+               }
+       else
+               {
+                       gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")));
+               }*/
+       gtk_widget_show (w);
 }
   
 static void
@@ -253,6 +281,43 @@ static void
 autedb_on_btn_delete_clicked (GtkButton *button,
                            gpointer user_data)
 {
+       GtkWidget *dialog;
+       gboolean risp;
+
+       GtkTreeIter iter;
+       gchar *code;
+
+       if (gtk_tree_selection_get_selected (sel_users, NULL, &iter))
+               {
+                       /*dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")),
+                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                                                        GTK_MESSAGE_QUESTION,
+                                                                                        GTK_BUTTONS_YES_NO,
+                                                                                        "Sicuro di voler eliminare il modello selezionato?");
+                       risp = gtk_dialog_run (GTK_DIALOG (dialog));*/
+                       if (risp == GTK_RESPONSE_YES)
+                               {
+                                       gtk_tree_model_get (GTK_TREE_MODEL (lstore_users), &iter,
+                                                                                       COL_CODE, &code,
+                                                                                       -1);
+
+                                       gdaex_execute (gdaex,
+                                                      g_strdup_printf ("UPDATE users SET status = 'E' WHERE code = '%s'", code));
+
+                                       autedb_load_users_list ();
+                               }
+                       /*gtk_widget_destroy (dialog);*/
+               }
+       else
+               {
+                       /*dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")),
+                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                                                        GTK_MESSAGE_WARNING,
+                                                                                        GTK_BUTTONS_OK,
+                                                                                        "Occorre prima selezionare un modello");
+                       gtk_dialog_run (GTK_DIALOG (dialog));
+                       gtk_widget_destroy (dialog);*/
+               }
 }
   
 static void
@@ -286,7 +351,18 @@ gchar
        GUIDIR = g_build_filename (g_win32_get_package_installation_directory_of_module (NULL), "share", "libaute-db", "gui", NULL);
 #endif
 
-       if (!gtk_builder_add_objects_from_file (gtkbuilder, g_build_filename (GUIDIR, "autedb.gui", NULL),
+#ifdef G_OS_WIN32
+#undef FORMDIR
+
+       gchar *FORMDIR;
+
+       FORMDIR = g_build_filename (g_win32_get_package_installation_directory_of_module (NULL), "share", "libaute-db", "form", NULL);
+#endif
+
+       formdir = g_strdup (FORMDIR);
+
+       guifile = g_build_filename (GUIDIR, "autedb.gui", NULL);
+       if (!gtk_builder_add_objects_from_file (gtkbuilder, guifile,
                                                g_strsplit ("diag_main", "|", -1),
                                                &error))
                {
diff --git a/src/user.c b/src/user.c
new file mode 100644 (file)
index 0000000..581ae3b
--- /dev/null
@@ -0,0 +1,344 @@
+/* 
+ * Copyright (C) 2010 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include <libgtkform/form.h>
+
+#include "user.h"
+
+static void user_class_init (UserClass *klass);
+static void user_init (User *user);
+
+static void user_carica (User *user);
+static void user_salva (User *user);
+
+static gboolean user_conferma_chiusura (User *user);
+
+static void user_set_property (GObject *object,
+                                     guint property_id,
+                                     const GValue *value,
+                                     GParamSpec *pspec);
+static void user_get_property (GObject *object,
+                                     guint property_id,
+                                     GValue *value,
+                                     GParamSpec *pspec);
+
+static gboolean user_on_w_user_delete_event (GtkWidget *widget,
+                               GdkEvent *event,
+                               gpointer user_data);
+
+static void user_on_btn_annulla_clicked (GtkButton *button,
+                                    gpointer user_data);
+static void user_on_btn_salva_clicked (GtkButton *button,
+                                  gpointer user_data);
+
+#define USER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_USER, UserPrivate))
+
+enum
+{
+       TXT_CODE
+};
+
+typedef struct _UserPrivate UserPrivate;
+struct _UserPrivate
+       {
+               GtkBuilder *gtkbuilder;
+               GdaEx *gdaex;
+               gchar *guifile;
+               gchar *formdir;
+
+               GtkForm *form;
+
+               GtkWidget *w;
+
+               GObject **objects;
+
+               gchar *code;
+       };
+
+G_DEFINE_TYPE (User, user, G_TYPE_OBJECT)
+
+static void
+user_class_init (UserClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       g_type_class_add_private (object_class, sizeof (UserPrivate));
+
+       object_class->set_property = user_set_property;
+       object_class->get_property = user_get_property;
+
+       /**
+        * User::aggiornato:
+        * @user:
+        *
+        */
+       klass->aggiornato_signal_id = g_signal_new ("aggiornato",
+                                                      G_TYPE_FROM_CLASS (object_class),
+                                                      G_SIGNAL_RUN_LAST,
+                                                      0,
+                                                      NULL,
+                                                      NULL,
+                                                      g_cclosure_marshal_VOID__VOID,
+                                                      G_TYPE_NONE,
+                                                      0);
+}
+
+static void
+user_init (User *user)
+{
+       UserPrivate *priv = USER_GET_PRIVATE (user);
+
+       priv->code = NULL;
+}
+
+/**
+ * user_new:
+ * @gtkbuilder:
+ * @gdaex:
+ * @guifile:
+ * @formdir:
+ * @code:
+ *
+ * Returns: the newly created #User object.
+ */
+User
+*user_new (GtkBuilder *gtkbuilder, GdaEx *gdaex,
+           const gchar *guifile, const gchar *formdir, const gchar *code)
+{
+       GError *error;
+
+       User *a = USER (g_object_new (user_get_type (), NULL));
+
+       UserPrivate *priv = USER_GET_PRIVATE (a);
+
+       priv->gtkbuilder = gtkbuilder;
+       priv->gdaex = gdaex;
+       priv->guifile = g_strdup (guifile);
+       priv->formdir = g_strdup (formdir);
+
+       error = NULL;
+       gtk_builder_add_objects_from_file (priv->gtkbuilder, priv->guifile,
+                                          g_strsplit ("w_user", "|", -1),
+                                          &error);
+       if (error != NULL)
+               {
+                       g_warning ("Errore: %s.", error->message);
+                       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);
+
+       g_object_set (priv->form, "gdaex", priv->gdaex, NULL);
+
+       priv->w = GTK_WIDGET (gtk_builder_get_object (priv->gtkbuilder, "w_user"));
+
+       priv->objects = gtk_form_get_objects_by_name (priv->form,
+                                                     "entry1",
+                                                     NULL);
+
+       g_signal_connect (priv->w,
+                         "delete-event", G_CALLBACK (user_on_w_user_delete_event), (gpointer *)a);
+
+       g_signal_connect (gtk_builder_get_object (priv->gtkbuilder, "button5"),
+                         "clicked", G_CALLBACK (user_on_btn_annulla_clicked), (gpointer *)a);
+       g_signal_connect (gtk_builder_get_object (priv->gtkbuilder, "button6"),
+                         "clicked", G_CALLBACK (user_on_btn_salva_clicked), (gpointer *)a);
+
+       if (code != NULL)
+               {
+                       priv->code = g_strstrip (g_strdup (code));
+               }
+       if (priv->code == NULL || g_strcmp0 (priv->code, "") == 0)
+               {
+                       gtk_form_clear (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);
+
+                       user_carica (a);
+               }
+
+       return a;
+}
+
+/**
+ * user_get_widget:
+ * @user:
+ *
+ */
+GtkWidget
+*user_get_widget (User *user)
+{
+       UserPrivate *priv = USER_GET_PRIVATE (user);
+
+       return priv->w;
+}
+
+/* PRIVATE */
+static void
+user_carica (User *user)
+{
+       UserPrivate *priv = USER_GET_PRIVATE (user);
+
+       if (gtk_form_fill_from_table (priv->form))
+               {
+               }
+}
+
+static void
+user_salva (User *user)
+{
+       GError *error = NULL;
+       gchar *sql;
+       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))
+               {
+                       return;
+               }
+
+       if (priv->code == NULL || g_strcmp0 (priv->code, "") == 0)
+               {
+                       sql = gtk_form_get_sql (priv->form, GTK_FORM_SQL_INSERT);
+               }
+       else
+               {
+                       sql = gtk_form_get_sql (priv->form, GTK_FORM_SQL_UPDATE);
+               }
+
+       if (gdaex_execute (priv->gdaex, sql) == 1)
+               {
+                       g_signal_emit (user, klass->aggiornato_signal_id, 0);
+
+                       gtk_form_set_as_origin (priv->form);
+
+                       dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                                                        GTK_MESSAGE_INFO,
+                                                                                        GTK_BUTTONS_OK,
+                                                                                        "Salvataggio eseguito con successo.");
+                       gtk_dialog_run (GTK_DIALOG (dialog));
+                       gtk_widget_destroy (dialog);
+               }
+       else
+               {
+                       dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+                                                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                                                        GTK_MESSAGE_WARNING,
+                                                                                        GTK_BUTTONS_OK,
+                                                                                        "Errore durante il salvataggio.");
+                       gtk_dialog_run (GTK_DIALOG (dialog));
+                       gtk_widget_destroy (dialog);
+               }
+}
+
+static void
+user_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+       User *user = USER (object);
+
+       UserPrivate *priv = USER_GET_PRIVATE (user);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static void
+user_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+       User *user = USER (object);
+
+       UserPrivate *priv = USER_GET_PRIVATE (user);
+
+       switch (property_id)
+               {
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+               }
+}
+
+static gboolean
+user_conferma_chiusura (User *user)
+{
+       GtkWidget *dialog;
+
+       gboolean ret;
+
+       UserPrivate *priv = USER_GET_PRIVATE (user);
+
+       ret = TRUE;
+       if (gtk_form_is_changed (priv->form))
+               {
+                       dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+                                                                GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                                GTK_MESSAGE_QUESTION,
+                                                                GTK_BUTTONS_YES_NO,
+                                                                "Sicuro di voler chiudere senza salvare?");
+                       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_NO)
+                               {
+                                       ret = FALSE;
+                               }
+                       gtk_widget_destroy (dialog);
+               }
+
+       return ret;
+}
+
+/* CALLBACK */
+static gboolean
+user_on_w_user_delete_event (GtkWidget *widget,
+                               GdkEvent *event,
+                               gpointer user_data)
+{
+       return !user_conferma_chiusura ((User *)user_data);
+}
+
+static void
+user_on_btn_annulla_clicked (GtkButton *button,
+                        gpointer user_data)
+{
+       User *user = (User *)user_data;
+
+       UserPrivate *priv = USER_GET_PRIVATE (user);
+
+       if (user_conferma_chiusura (user)) gtk_widget_destroy (priv->w);
+}
+
+static void
+user_on_btn_salva_clicked (GtkButton *button,
+                      gpointer user_data)
+{
+       user_salva ((User *)user_data);
+}
diff --git a/src/user.h b/src/user.h
new file mode 100644 (file)
index 0000000..63e0d06
--- /dev/null
@@ -0,0 +1,65 @@
+/* 
+ * Copyright (C) 2010 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef __USER_H__
+#define __USER_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <gtk/gtk.h>
+#include <libgdaex.h>
+
+G_BEGIN_DECLS
+
+
+#define TYPE_USER                 (user_get_type ())
+#define USER(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_USER, User))
+#define USER_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_USER, UserClass))
+#define IS_USER(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_USER))
+#define IS_USER_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_USER))
+#define USER_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_USER, UserClass))
+
+
+typedef struct _User User;
+typedef struct _UserClass UserClass;
+
+struct _User
+       {
+               GObject parent;
+       };
+
+struct _UserClass
+       {
+               GObjectClass parent_class;
+
+               guint aggiornato_signal_id;
+       };
+
+GType user_get_type (void) G_GNUC_CONST;
+
+User *user_new (GtkBuilder *gtkbuilder, GdaEx *gdaex,
+                const gchar *guifile, const gchar *formdir, const gchar *code);
+
+GtkWidget *user_get_widget (User *user);
+
+
+G_END_DECLS
+
+#endif /* __USER_H__ */