From 1ff25a87a2c2801a5183e8224c656e8a4ea05003 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Fri, 13 Aug 2010 12:22:34 +0200 Subject: [PATCH] Started opening audit datasource management. --- data/audit-gui/gui/audit-gui.gui | 1 + src/Makefile.am | 8 +- src/main.c | 23 ++- src/openauditds.c | 233 +++++++++++++++++++++++++++++++ src/openauditds.h | 66 +++++++++ 5 files changed, 321 insertions(+), 10 deletions(-) create mode 100644 src/openauditds.c create mode 100644 src/openauditds.h diff --git a/data/audit-gui/gui/audit-gui.gui b/data/audit-gui/gui/audit-gui.gui index 9d431f5..82fefe3 100644 --- a/data/audit-gui/gui/audit-gui.gui +++ b/data/audit-gui/gui/audit-gui.gui @@ -29,6 +29,7 @@ True True True + diff --git a/src/Makefile.am b/src/Makefile.am index 1789045..966bcfb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,9 +1,7 @@ guidir = $(datadir)/$(PACKAGE)/gui -formdir = $(datadir)/$(PACKAGE)/form AM_CPPFLAGS = $(AUDITGUI_CFLAGS) \ - -DGUIDIR=\""$(guidir)"\" \ - -DFORMDIR=\""$(formdir)"\" + -DGUIDIR=\""$(guidir)"\" LIBS = $(AUDITGUI_LIBS) \ -export-dynamic @@ -12,4 +10,6 @@ bin_PROGRAMS = audit-gui audit_gui_SOURCES = \ commons.h \ - main.c \ No newline at end of file + main.c \ + openauditds.c \ + openauditds.h \ No newline at end of file diff --git a/src/main.c b/src/main.c index 5400c25..1820dd6 100644 --- a/src/main.c +++ b/src/main.c @@ -28,6 +28,7 @@ #include #include "commons.h" +#include "openauditds.h" static Commons *commons; @@ -48,18 +49,28 @@ main_set_vbx_body_child (GtkWidget *child) gtk_box_pack_start (GTK_BOX (vbx_body), vbx_body_child, TRUE, TRUE, 0); } -/*G_MODULE_EXPORT void -on_mnu_view_nodi_activate (GtkMenuItem *menuitem, +static void +main_on_ds_opened (gpointer instance, const gchar *arg1, gpointer user_data) +{ + g_message ("OPENED"); +} + +G_MODULE_EXPORT void +on_mnu_file_open_audit_ds_activate (GtkMenuItem *menuitem, gpointer user_data) { GtkWidget *vbx; - Nodi *m = nodi_new (commons, FALSE); + OpenAuditDS *m = open_audit_ds_new (commons); + + vbx = open_audit_ds_get_widget (m); - vbx = nodi_get_widget (m); + g_signal_connect (G_OBJECT (m), "opened", + G_CALLBACK (main_on_ds_opened), NULL); - main_set_vbx_body_child (vbx); -}*/ + gtk_window_set_transient_for (GTK_WINDOW (vbx), GTK_WINDOW (w)); + gtk_widget_show_all (vbx); +} G_MODULE_EXPORT void on_mnu_help_about_activate (GtkMenuItem *menuitem, diff --git a/src/openauditds.c b/src/openauditds.c new file mode 100644 index 0000000..f99a67b --- /dev/null +++ b/src/openauditds.c @@ -0,0 +1,233 @@ +/* + * Copyright (C) 2010 Andrea Zagli + * + * 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 + +#include "openauditds.h" + +static void open_audit_ds_class_init (OpenAuditDSClass *klass); +static void open_audit_ds_init (OpenAuditDS *open_audit_ds); + +static void open_audit_ds_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void open_audit_ds_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static void open_audit_ds_on_wlogin_changed (GdauiLogin *gdauilogin, + gboolean arg1, + gpointer user_data); + +static void open_audit_ds_on_btn_cancel_clicked (GtkButton *button, + gpointer user_data); +static void open_audit_ds_on_btn_open_clicked (GtkButton *button, + gpointer user_data); + +#define OPEN_AUDIT_DS_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_OPEN_AUDIT_DS, OpenAuditDSPrivate)) + +typedef struct _OpenAuditDSPrivate OpenAuditDSPrivate; +struct _OpenAuditDSPrivate + { + Commons *commons; + + GtkWidget *w; + GtkWidget *wlogin; + }; + +G_DEFINE_TYPE (OpenAuditDS, open_audit_ds, G_TYPE_OBJECT) + +static void +open_audit_ds_class_init (OpenAuditDSClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (OpenAuditDSPrivate)); + + object_class->set_property = open_audit_ds_set_property; + object_class->get_property = open_audit_ds_get_property; + + /** + * OpenAuditDS::opened: + * @open_audit_ds: + * + */ + klass->opened_signal_id = g_signal_new ("opened", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST, + 0, + NULL, + NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, + 1, G_TYPE_STRING); +} + +static void +open_audit_ds_init (OpenAuditDS *open_audit_ds) +{ + OpenAuditDSPrivate *priv = OPEN_AUDIT_DS_GET_PRIVATE (open_audit_ds); +} + +/** + * open_audit_ds_new: + * @commons: + * @id: + * + * Returns: the newly created #OpenAuditDS object. + */ +OpenAuditDS +*open_audit_ds_new (Commons *commons) +{ + GError *error; + + GdauiLoginMode mode; + + OpenAuditDS *a = OPEN_AUDIT_DS (g_object_new (open_audit_ds_get_type (), NULL)); + + OpenAuditDSPrivate *priv = OPEN_AUDIT_DS_GET_PRIVATE (a); + + priv->commons = commons; + + error = NULL; + gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile, + g_strsplit ("w_open_audit_datasource", "|", -1), + &error); + if (error != NULL) + { + g_warning ("Errore: %s.", error->message); + return NULL; + } + + priv->w = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_open_audit_datasource")); + + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button1"), + "clicked", G_CALLBACK (open_audit_ds_on_btn_cancel_clicked), (gpointer *)a); + g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button2"), + "clicked", G_CALLBACK (open_audit_ds_on_btn_open_clicked), (gpointer *)a); + + /* creating login widget */ + priv->wlogin = gdaui_login_new (NULL); + + g_object_get (G_OBJECT (priv->wlogin), "mode", &mode, NULL); + mode |= GDA_UI_LOGIN_HIDE_DSN_SELECTION_MODE; + gdaui_login_set_mode (GDAUI_LOGIN (priv->wlogin), mode); + + g_signal_connect (G_OBJECT (priv->wlogin), "changed", + G_CALLBACK (open_audit_ds_on_wlogin_changed), (gpointer *)a); + + gtk_box_pack_start (GTK_BOX (gtk_builder_get_object (priv->commons->gtkbuilder, "vbox2")), + priv->wlogin, TRUE, TRUE, 0); + gtk_box_reorder_child (GTK_BOX (gtk_builder_get_object (priv->commons->gtkbuilder, "vbox2")), + priv->wlogin, 0); + + gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button2")), FALSE); + + return a; +} + +/** + * open_audit_ds_get_widget: + * @open_audit_ds: + * + */ +GtkWidget +*open_audit_ds_get_widget (OpenAuditDS *open_audit_ds) +{ + OpenAuditDSPrivate *priv = OPEN_AUDIT_DS_GET_PRIVATE (open_audit_ds); + + return priv->w; +} + +/* PRIVATE */ +static void +open_audit_ds_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + OpenAuditDS *open_audit_ds = OPEN_AUDIT_DS (object); + + OpenAuditDSPrivate *priv = OPEN_AUDIT_DS_GET_PRIVATE (open_audit_ds); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +open_audit_ds_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + OpenAuditDS *open_audit_ds = OPEN_AUDIT_DS (object); + + OpenAuditDSPrivate *priv = OPEN_AUDIT_DS_GET_PRIVATE (open_audit_ds); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +/* CALLBACK */ +static void +open_audit_ds_on_wlogin_changed (GdauiLogin *gdauilogin, + gboolean arg1, + gpointer user_data) +{ + OpenAuditDS *open_audit_ds = (OpenAuditDS *)user_data; + + OpenAuditDSPrivate *priv = OPEN_AUDIT_DS_GET_PRIVATE (open_audit_ds); + + gboolean is_valid; + + g_object_get (G_OBJECT (priv->wlogin), "valid", &is_valid, NULL); + gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "button2")), + is_valid); +} + +static void +open_audit_ds_on_btn_cancel_clicked (GtkButton *button, + gpointer user_data) +{ + OpenAuditDS *open_audit_ds = (OpenAuditDS *)user_data; + + OpenAuditDSPrivate *priv = OPEN_AUDIT_DS_GET_PRIVATE (open_audit_ds); + + gtk_widget_destroy (priv->w); +} + +static void +open_audit_ds_on_btn_open_clicked (GtkButton *button, + gpointer user_data) +{ + OpenAuditDS *open_audit_ds = (OpenAuditDS *)user_data; + OpenAuditDSPrivate *priv = OPEN_AUDIT_DS_GET_PRIVATE (open_audit_ds); + OpenAuditDSClass *klass = OPEN_AUDIT_DS_GET_CLASS (open_audit_ds); + + const GdaDsnInfo *info; + info = gdaui_login_get_connection_information (GDAUI_LOGIN (priv->wlogin)); + + g_signal_emit (open_audit_ds, klass->opened_signal_id, 0, info->cnc_string); + + gtk_widget_destroy (priv->w); +} diff --git a/src/openauditds.h b/src/openauditds.h new file mode 100644 index 0000000..f5b8385 --- /dev/null +++ b/src/openauditds.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2010 Andrea Zagli + * + * 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 __OPEN_AUDIT_DS_H__ +#define __OPEN_AUDIT_DS_H__ + +#include +#include + +#include +#include + +#include "commons.h" + +G_BEGIN_DECLS + + +#define TYPE_OPEN_AUDIT_DS (open_audit_ds_get_type ()) +#define OPEN_AUDIT_DS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_OPEN_AUDIT_DS, OpenAuditDS)) +#define OPEN_AUDIT_DS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_OPEN_AUDIT_DS, OpenAuditDSClass)) +#define IS_OPEN_AUDIT_DS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_OPEN_AUDIT_DS)) +#define IS_OPEN_AUDIT_DS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_OPEN_AUDIT_DS)) +#define OPEN_AUDIT_DS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_OPEN_AUDIT_DS, OpenAuditDSClass)) + + +typedef struct _OpenAuditDS OpenAuditDS; +typedef struct _OpenAuditDSClass OpenAuditDSClass; + +struct _OpenAuditDS + { + GObject parent; + }; + +struct _OpenAuditDSClass + { + GObjectClass parent_class; + + guint opened_signal_id; + }; + +GType open_audit_ds_get_type (void) G_GNUC_CONST; + +OpenAuditDS *open_audit_ds_new (Commons *commons); + +GtkWidget *open_audit_ds_get_widget (OpenAuditDS *open_audit_ds); + + +G_END_DECLS + +#endif /* __OPEN_AUDIT_DS_H__ */ -- 2.49.0