#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;
}
}
+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
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
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))
{
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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__ */