From: Andrea Zagli <azagli@libero.it> Date: Sun, 8 Aug 2010 13:51:30 +0000 (+0200) Subject: Start coding groups. X-Git-Tag: v0.1.1~13 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=d9d2cac6050ed183aaf0fb62fd8962e6a03cd41d;p=zakauthe%2Fplugins%2Fsmbldap Start coding groups. --- diff --git a/data/libaute-smbldap/gui/autesmbldap.gui b/data/libaute-smbldap/gui/autesmbldap.gui index f7c1e04..bc8a74f 100644 --- a/data/libaute-smbldap/gui/autesmbldap.gui +++ b/data/libaute-smbldap/gui/autesmbldap.gui @@ -205,18 +205,6 @@ <action-widget response="-5">okbutton1</action-widget> </action-widgets> </object> - <object class="GtkListStore" id="lstore_users"> - <columns> - <!-- column-name status --> - <column type="gchararray"/> - <!-- column-name code --> - <column type="gchararray"/> - <!-- column-name surname_name --> - <column type="gchararray"/> - <!-- column-name password_expiration --> - <column type="gchararray"/> - </columns> - </object> <object class="GtkWindow" id="w_users_list"> <child> <object class="GtkVBox" id="vbx_users_list"> @@ -225,62 +213,134 @@ <property name="orientation">vertical</property> <property name="spacing">5</property> <child> - <object class="GtkScrolledWindow" id="scrolledwindow1"> + <object class="GtkNotebook" id="notebook1"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="hscrollbar_policy">automatic</property> - <property name="vscrollbar_policy">automatic</property> - <property name="shadow_type">etched-in</property> <child> - <object class="GtkTreeView" id="treeview1"> + <object class="GtkScrolledWindow" id="scrolledwindow1"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="model">lstore_users</property> + <property name="hscrollbar_policy">automatic</property> + <property name="vscrollbar_policy">automatic</property> + <property name="shadow_type">etched-in</property> <child> - <object class="GtkTreeViewColumn" id="treeviewcolumn1"> - <property name="title">Status</property> + <object class="GtkTreeView" id="treeview1"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="model">lstore_users</property> + <property name="headers_clickable">False</property> + <property name="search_column">0</property> <child> - <object class="GtkCellRendererText" id="cellrenderertext1"/> - <attributes> - <attribute name="text">0</attribute> - </attributes> + <object class="GtkTreeViewColumn" id="treeviewcolumn1"> + <property name="title">Status</property> + <child> + <object class="GtkCellRendererText" id="cellrenderertext1"/> + <attributes> + <attribute name="text">0</attribute> + </attributes> + </child> + </object> + </child> + <child> + <object class="GtkTreeViewColumn" id="treeviewcolumn3"> + <property name="title">CN</property> + <child> + <object class="GtkCellRendererText" id="cellrenderertext3"/> + <attributes> + <attribute name="text">1</attribute> + </attributes> + </child> + </object> </child> - </object> - </child> - <child> - <object class="GtkTreeViewColumn" id="treeviewcolumn3"> - <property name="title">Code</property> <child> - <object class="GtkCellRendererText" id="cellrenderertext3"/> - <attributes> - <attribute name="text">1</attribute> - </attributes> + <object class="GtkTreeViewColumn" id="treeviewcolumn2"> + <property name="title">Name</property> + <child> + <object class="GtkCellRendererText" id="cellrenderertext2"/> + <attributes> + <attribute name="text">2</attribute> + </attributes> + </child> + </object> </child> - </object> - </child> - <child> - <object class="GtkTreeViewColumn" id="treeviewcolumn2"> - <property name="title">Name</property> <child> - <object class="GtkCellRendererText" id="cellrenderertext2"/> - <attributes> - <attribute name="text">2</attribute> - </attributes> + <object class="GtkTreeViewColumn" id="treeviewcolumn5"> + <property name="title">UID</property> + <child> + <object class="GtkCellRendererSpin" id="cellrenderertext5"> + <property name="xalign">1</property> + </object> + <attributes> + <attribute name="text">3</attribute> + </attributes> + </child> + </object> </child> </object> </child> + </object> + </child> + <child type="tab"> + <object class="GtkLabel" id="label10"> + <property name="visible">True</property> + <property name="label" translatable="yes">Users</property> + </object> + <packing> + <property name="tab_fill">False</property> + </packing> + </child> + <child> + <object class="GtkScrolledWindow" id="scrolledwindow3"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="hscrollbar_policy">automatic</property> + <property name="vscrollbar_policy">automatic</property> + <property name="shadow_type">etched-in</property> <child> - <object class="GtkTreeViewColumn" id="treeviewcolumn5"> - <property name="title">Password expiration</property> + <object class="GtkTreeView" id="treeview2"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="model">lstore_groups</property> + <child> + <object class="GtkTreeViewColumn" id="treeviewcolumn4"> + <property name="title">CN</property> + <child> + <object class="GtkCellRendererText" id="cellrenderertext4"/> + <attributes> + <attribute name="text">0</attribute> + </attributes> + </child> + </object> + </child> <child> - <object class="GtkCellRendererText" id="cellrenderertext5"/> - <attributes> - <attribute name="text">3</attribute> - </attributes> + <object class="GtkTreeViewColumn" id="treeviewcolumn6"> + <property name="title">GID</property> + <child> + <object class="GtkCellRendererSpin" id="cellrendererspin1"> + <property name="xalign">1</property> + </object> + <attributes> + <attribute name="text">1</attribute> + </attributes> + </child> + </object> </child> </object> </child> </object> + <packing> + <property name="position">1</property> + </packing> + </child> + <child type="tab"> + <object class="GtkLabel" id="label13"> + <property name="visible">True</property> + <property name="label" translatable="yes">Groups</property> + </object> + <packing> + <property name="position">1</property> + <property name="tab_fill">False</property> + </packing> </child> </object> <packing> @@ -464,6 +524,7 @@ <property name="right_attach">2</property> <property name="top_attach">3</property> <property name="bottom_attach">4</property> + <property name="y_options">GTK_FILL</property> </packing> </child> <child> @@ -476,6 +537,7 @@ <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> + <property name="y_options">GTK_FILL</property> </packing> </child> <child> @@ -490,6 +552,7 @@ <property name="right_attach">2</property> <property name="top_attach">1</property> <property name="bottom_attach">2</property> + <property name="y_options">GTK_FILL</property> </packing> </child> <child> @@ -504,6 +567,7 @@ <property name="right_attach">2</property> <property name="top_attach">2</property> <property name="bottom_attach">3</property> + <property name="y_options">GTK_FILL</property> </packing> </child> <child> @@ -518,6 +582,7 @@ <property name="right_attach">2</property> <property name="top_attach">4</property> <property name="bottom_attach">5</property> + <property name="y_options">GTK_FILL</property> </packing> </child> <child> @@ -602,4 +667,112 @@ </object> </child> </object> + <object class="GtkListStore" id="lstore_groups"> + <columns> + <!-- column-name cn --> + <column type="gchararray"/> + <!-- column-name gid --> + <column type="guint"/> + </columns> + </object> + <object class="GtkListStore" id="lstore_users"> + <columns> + <!-- column-name status --> + <column type="gchararray"/> + <!-- column-name cn --> + <column type="gchararray"/> + <!-- column-name display_name --> + <column type="gchararray"/> + <!-- column-name uid --> + <column type="guint"/> + </columns> + </object> + <object class="GtkWindow" id="w_group"> + <property name="title" translatable="yes">Group</property> + <property name="modal">True</property> + <property name="window_position">center-on-parent</property> + <property name="destroy_with_parent">True</property> + <child> + <object class="GtkVBox" id="vbox2"> + <property name="visible">True</property> + <property name="border_width">5</property> + <property name="orientation">vertical</property> + <property name="spacing">5</property> + <child> + <object class="GtkTable" id="table4"> + <property name="visible">True</property> + <property name="n_columns">2</property> + <property name="column_spacing">5</property> + <property name="row_spacing">5</property> + <child> + <object class="GtkLabel" id="label15"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">CN</property> + </object> + <packing> + <property name="x_options">GTK_FILL</property> + <property name="y_options">GTK_FILL</property> + </packing> + </child> + <child> + <object class="GtkEntry" id="entry5"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="max_length">10</property> + <property name="invisible_char">●</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="y_options">GTK_FILL</property> + </packing> + </child> + </object> + <packing> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkHButtonBox" id="hbuttonbox3"> + <property name="visible">True</property> + <property name="spacing">5</property> + <property name="layout_style">end</property> + <child> + <object class="GtkButton" id="button7"> + <property name="label">gtk-cancel</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkButton" id="button8"> + <property name="label">gtk-save</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="position">1</property> + </packing> + </child> + </object> + </child> + </object> </interface> diff --git a/src/Makefile.am b/src/Makefile.am index 2082de6..241e481 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,6 +19,8 @@ libaute_plugins_LTLIBRARIES = libaute-smbldap.la libaute_smbldap_la_SOURCES = aute_smbldap.c \ aute_smbldap.h \ user.c \ - user.h + user.h \ + group.c \ + group.h libaute_smbldap_la_LDFLAGS = -no-undefined diff --git a/src/group.c b/src/group.c new file mode 100644 index 0000000..8e09784 --- /dev/null +++ b/src/group.c @@ -0,0 +1,347 @@ +/* + * 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 "group.h" +#include "aute_smbldap.h" + +static void group_class_init (GroupClass *klass); +static void group_init (Group *group); + +static void group_carica (Group *group); +static void group_salva (Group *group); + +static gboolean group_conferma_chiusura (Group *group); + +static void group_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void group_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static gboolean group_on_w_group_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer group_data); + +static void group_on_btn_annulla_clicked (GtkButton *button, + gpointer group_data); +static void group_on_btn_salva_clicked (GtkButton *button, + gpointer group_data); + +#define GROUP_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GROUP, GroupPrivate)) + +enum +{ + TXT_CODE, + LBL_PASSWORD +}; + +typedef struct _GroupPrivate GroupPrivate; +struct _GroupPrivate + { + GtkBuilder *gtkbuilder; + GdaEx *gdaex; + gchar *guifile; + gchar *formdir; + + GtkForm *form; + + GtkWidget *w; + + GObject **objects; + + gchar *code; + }; + +G_DEFINE_TYPE (Group, group, G_TYPE_OBJECT) + +static void +group_class_init (GroupClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (GroupPrivate)); + + object_class->set_property = group_set_property; + object_class->get_property = group_get_property; + + /** + * Group::aggiornato: + * @group: + * + */ + 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 +group_init (Group *group) +{ + GroupPrivate *priv = GROUP_GET_PRIVATE (group); + + priv->code = NULL; +} + +/** + * group_new: + * @gtkbuilder: + * @gdaex: + * @guifile: + * @formdir: + * @code: + * + * Returns: the newly created #Group object. + */ +Group +*group_new (GtkBuilder *gtkbuilder, GdaEx *gdaex, + const gchar *guifile, const gchar *formdir, const gchar *code) +{ + GError *error; + + Group *a = GROUP (g_object_new (group_get_type (), NULL)); + + GroupPrivate *priv = GROUP_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_group", "|", -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, "group.form", NULL), priv->gtkbuilder); + + g_object_set (priv->form, "gdaex", priv->gdaex, NULL); + + priv->w = GTK_WIDGET (gtk_builder_get_object (priv->gtkbuilder, "w_group")); + + priv->objects = gtk_form_get_objects_by_name (priv->form, + "entry1", + "label14", + NULL); + + g_signal_connect (priv->w, + "delete-event", G_CALLBACK (group_on_w_group_delete_event), (gpointer *)a); + + g_signal_connect (gtk_builder_get_object (priv->gtkbuilder, "button5"), + "clicked", G_CALLBACK (group_on_btn_annulla_clicked), (gpointer *)a); + g_signal_connect (gtk_builder_get_object (priv->gtkbuilder, "button6"), + "clicked", G_CALLBACK (group_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); + + group_carica (a); + } + + return a; +} + +/** + * group_get_widget: + * @group: + * + */ +GtkWidget +*group_get_widget (Group *group) +{ + GroupPrivate *priv = GROUP_GET_PRIVATE (group); + + return priv->w; +} + +/* PRIVATE */ +static void +group_carica (Group *group) +{ + GroupPrivate *priv = GROUP_GET_PRIVATE (group); + + if (gtk_form_fill_from_table (priv->form)) + { + } +} + +static void +group_salva (Group *group) +{ + GError *error = NULL; + gchar *sql; + GtkWidget *dialog; + + GDate *da; + GDate *a; + + GroupClass *klass = GROUP_GET_CLASS (group); + + GroupPrivate *priv = GROUP_GET_PRIVATE (group); + + 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 (group, 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 +group_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + Group *group = GROUP (object); + + GroupPrivate *priv = GROUP_GET_PRIVATE (group); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +group_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + Group *group = GROUP (object); + + GroupPrivate *priv = GROUP_GET_PRIVATE (group); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static gboolean +group_conferma_chiusura (Group *group) +{ + GtkWidget *dialog; + + gboolean ret; + + GroupPrivate *priv = GROUP_GET_PRIVATE (group); + + 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 +group_on_w_group_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer group_data) +{ + return !group_conferma_chiusura ((Group *)group_data); +} + +static void +group_on_btn_annulla_clicked (GtkButton *button, + gpointer group_data) +{ + Group *group = (Group *)group_data; + + GroupPrivate *priv = GROUP_GET_PRIVATE (group); + + if (group_conferma_chiusura (group)) gtk_widget_destroy (priv->w); +} + +static void +group_on_btn_salva_clicked (GtkButton *button, + gpointer group_data) +{ + group_salva ((Group *)group_data); +} diff --git a/src/group.h b/src/group.h new file mode 100644 index 0000000..6d2cd20 --- /dev/null +++ b/src/group.h @@ -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 __GROUP_H__ +#define __GROUP_H__ + +#include <glib.h> +#include <glib-object.h> + +#include <gtk/gtk.h> +#include <libgdaex.h> + +G_BEGIN_DECLS + + +#define TYPE_GROUP (group_get_type ()) +#define GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GROUP, Group)) +#define GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GROUP, GroupClass)) +#define IS_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GROUP)) +#define IS_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GROUP)) +#define GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_GROUP, GroupClass)) + + +typedef struct _Group Group; +typedef struct _GroupClass GroupClass; + +struct _Group + { + GObject parent; + }; + +struct _GroupClass + { + GObjectClass parent_class; + + guint aggiornato_signal_id; + }; + +GType group_get_type (void) G_GNUC_CONST; + +Group *group_new (GtkBuilder *gtkbuilder, GdaEx *gdaex, + const gchar *guifile, const gchar *formdir, const gchar *code); + +GtkWidget *group_get_widget (Group *group); + + +G_END_DECLS + +#endif /* __GROUP_H__ */