]> saetta.ns0.it Git - zakaudit/libzakaudit/commitdiff
Continued GUI to view changes.
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Wed, 18 Dec 2013 11:50:17 +0000 (12:50 +0100)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Wed, 18 Dec 2013 11:50:17 +0000 (12:50 +0100)
.cproject
.project
src/audit.c
src/libzakaudit.h

index 8913d51d8c582152a8159464670a7783964508e2..c9ddf97ebf57f15251da915c73ed99f152b96676 100644 (file)
--- a/.cproject
+++ b/.cproject
@@ -29,6 +29,7 @@
                                                                        <listOptionValue builtIn="false" value="&quot;C:\mingw\include\glib-2.0&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;C:\mingw\include\gtk-2.0&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;C:\mingw\include\libgda-4.0&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;C:\mingw\include\libgda-4.0\libgda&quot;"/>
                                                                        <listOptionValue builtIn="false" value="&quot;C:\mingw\include\libxml2&quot;"/>
                                                                </option>
                                                                <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.248247095" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
index 3744bb5130e05dfaebd1277952abcfb8456624b6..37cd93d61129b2d9d22fa8b58249f6cf85f89e46 100644 (file)
--- a/.project
+++ b/.project
@@ -25,7 +25,7 @@
        </natures>
        <filteredResources>
                <filter>
-                       <id>1387288872089</id>
+                       <id>1387289817648</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
@@ -34,7 +34,7 @@
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872094</id>
+                       <id>1387289817661</id>
                        <name></name>
                        <type>30</type>
                        <matcher>
@@ -43,7 +43,7 @@
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872099</id>
+                       <id>1387289817665</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
@@ -52,7 +52,7 @@
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872104</id>
+                       <id>1387289817675</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
@@ -61,7 +61,7 @@
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872110</id>
+                       <id>1387289817681</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
@@ -70,7 +70,7 @@
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872114</id>
+                       <id>1387289817685</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
@@ -79,7 +79,7 @@
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872119</id>
+                       <id>1387289817687</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
@@ -88,7 +88,7 @@
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872123</id>
+                       <id>1387289817690</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
@@ -97,7 +97,7 @@
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872127</id>
+                       <id>1387289817692</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872133</id>
+                       <id>1387289817694</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872138</id>
+                       <id>1387289817697</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872142</id>
+                       <id>1387289817715</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872147</id>
+                       <id>1387289817727</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872153</id>
+                       <id>1387289817730</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872158</id>
+                       <id>1387289817743</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872162</id>
+                       <id>1387289817746</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872169</id>
+                       <id>1387289817758</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872173</id>
+                       <id>1387289817761</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872178</id>
+                       <id>1387289817802</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872183</id>
+                       <id>1387289817806</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872188</id>
+                       <id>1387289817809</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872193</id>
+                       <id>1387289817823</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872197</id>
+                       <id>1387289817830</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872201</id>
+                       <id>1387289817842</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
                        </matcher>
                </filter>
                <filter>
-                       <id>1387288872206</id>
+                       <id>1387289817845</id>
                        <name></name>
                        <type>22</type>
                        <matcher>
index 885c1eb0aaddd64912b9288473b36a5af2f3dc91..54ffd97a1b0187e3adf227e85b53c43887b3b43b 100644 (file)
@@ -98,6 +98,10 @@ struct _ZakAuditPrivate
        GList *datasources;
 
        GHashTable *fields_updated;
+
+       gchar *guidir;
+       gchar *guifile;
+       GtkBuilder *gtkbuilder;
 };
 
 /* PRIVATE */
@@ -127,9 +131,42 @@ static ZakAudit
 *zak_audit_new_ ()
 {
        ZakAudit *zak_audit;
+       ZakAuditPrivate *priv;
 
        zak_audit = ZAK_AUDIT (g_object_new (zak_audit_get_type (), NULL));
 
+       priv = ZAK_AUDIT_GET_PRIVATE (zak_audit);
+
+       /* gui */
+#ifdef G_OS_WIN32
+
+       gchar *moddir;
+       gchar *p;
+
+       moddir = g_win32_get_package_installation_directory_of_module (NULL);
+
+       p = g_strrstr (moddir, g_strdup_printf ("%c", G_DIR_SEPARATOR));
+       if (p != NULL
+           && (g_ascii_strcasecmp (p + 1, "src") == 0
+               || g_ascii_strcasecmp (p + 1, ".libs") == 0))
+               {
+                       priv->guidir = g_strdup (GUIDIR);
+               }
+       else
+               {
+                       priv->guidir = g_build_filename (moddir, "share", PACKAGE, "gui", NULL);
+               }
+
+#else
+
+       priv->guidir = g_strdup (GUIDIR);
+
+#endif
+
+       priv->guifile = g_build_filename (priv->guidir, "libzakaudit.ui", NULL);
+
+       priv->gtkbuilder = gtk_builder_new ();
+
        return zak_audit;
 }
 
@@ -1188,9 +1225,158 @@ zak_audit_action_from_gdastatement (ZakAudit *zak_audit,
        return ret;
 }
 
+
 /**
- * zak_audit_destroy:
+ * zak_audit_get_changes_widget:
+ * @zak_audit: an #ZakAudit object.
+ * @datasource_name:
+ * @table_name:
+ * @key_values:
  *
+ * Returns: the #GtkWidget.
+ */
+GtkWidget
+*zak_audit_get_changes_widget (ZakAudit *zak_audit,
+                               const gchar *datasource_name,
+                               const gchar *table_name,
+                               const gchar **key_values)
+{
+       GError *error;
+
+       GtkWidget *ret;
+
+       Datasource *datasource;
+       Table *table;
+       Field *field;
+
+       guint l;
+       guint strpart;
+
+       gchar *field_name;
+       gchar *field_value;
+
+       gchar *sql;
+       GString *sql_where;
+       GdaDataModel *dm;
+
+       GtkTreeStore *tstore;
+       GtkTreeIter iter;
+       GtkTreeIter iter_parent;
+
+       ZakAuditPrivate *priv = ZAK_AUDIT_GET_PRIVATE (zak_audit);
+
+       datasource = get_datasource_from_name (zak_audit, datasource_name);
+       if (datasource == NULL)
+               {
+                       return NULL;
+               }
+
+       table = get_table_from_name (zak_audit, datasource, table_name);
+       if (table == NULL)
+               {
+                       return NULL;
+               }
+
+       l = g_strv_length ((gchar **)key_values);
+       for (strpart = 0; strpart < l; strpart++)
+               {
+                       field_name = (gchar *)key_values[strpart];
+                       if (field_name == NULL) break;
+
+                       field = get_field_from_name (zak_audit, table, field_name);
+
+                       if (strpart + 1 >= l) break;
+
+                       field_value = (gchar *)key_values[++strpart];
+                       if (field_value == NULL) break;
+
+                       /* TODO the db field can be other type than string */
+                       g_string_append_printf (sql_where, " AND (v.id_fields = %d"
+                                               " AND (v.value = '%s' OR v.value LIKE '%s|%%'))",
+                                               field->id,
+                                               field_value,
+                                               field_value);
+               }
+
+       if (sql_where->len == 0)
+               {
+                       return NULL;
+               }
+       else
+               {
+                       g_string_erase (sql_where, 0, 5);
+               }
+
+       sql = g_strdup_printf ("(SELECT a.id, a.type, a.username, a.date,"
+                              " v.value"
+                              " FROM actions AS a"
+                              " INNER JOIN values AS v ON a.id = v.id_actions"
+                              " INNER JOIN fields AS f ON v.id_fields = f.id"
+                              " WHERE a.type = %d"
+                              " AND a.id_tables = %d"
+                              " AND %s"
+                              " AND f.is_key = TRUE)"
+                              " UNION"
+                              " (SELECT a.id, a.type, a.username, a.date,"
+                              " v.value"
+                              " FROM actions AS a"
+                              " INNER JOIN values AS v ON a.id = v.id_actions"
+                              " INNER JOIN fields AS f ON v.id_fields = f.id"
+                              " WHERE a.type = %d"
+                              " AND a.id_tables = %d"
+                              " AND %s"
+                              " AND f.is_key = TRUE)"
+                              " UNION",
+                              " (SELECT a.id, a.type, a.username, a.date,"
+                              " v.value"
+                              " FROM actions AS a"
+                              " INNER JOIN values AS v ON a.id = v.id_actions"
+                              " INNER JOIN fields AS f ON v.id_fields = f.id"
+                              " WHERE a.type = %d"
+                              " AND a.id_tables = %d"
+                              " AND %s"
+                              " AND f.is_key = TRUE)",
+                              ZAK_AUDIT_ACTION_INSERT,
+                              table->id,
+                              sql_where->str,
+                              ZAK_AUDIT_ACTION_AFTER_UPDATE,
+                              table->id,
+                              sql_where->str,
+                              ZAK_AUDIT_ACTION_DELETE,
+                              table->id,
+                              sql_where->str);
+
+       dm = gdaex_query (priv->gdaex, sql);
+       g_free (sql);
+       if (dm != NULL && gda_data_model_get_n_rows (dm) > 0)
+               {
+                       error = NULL;
+                       gtk_builder_add_objects_from_file (priv->gtkbuilder, priv->guifile,
+                                                          g_strsplit ("tstore_changes"
+                                                                      "|w_changes",
+                                                                      "|", -1),
+                                                          &error);
+
+                       tstore = gtk_builder_get_object (priv->gtkbuilder, "tstore_changes");
+
+                       /* TODO check if key field value is changed */
+
+
+               }
+       if (dm != NULL)
+               {
+                       g_object_unref (dm);
+               }
+
+       ret = NULL;
+       g_warning ("The function is still to be implemented");
+
+       return ret;
+}
+
+/**
+ * zak_audit_destroy:
+ * @zak_audit: an #ZakAudit object.
  */
 void
 zak_audit_destroy (ZakAudit *zak_audit)
index 5b3f76d323344cd4b9f92c7126359551141ebcd7..2680638f8abaf0a8a0636ffc79b9a062dd78d49b 100644 (file)
@@ -70,24 +70,29 @@ ZakAudit *zak_audit_new_from_string (const gchar *cnc_string);
 
 gboolean zak_audit_action (ZakAudit *zak_audit,
                        enum ZakAuditActions action,
-                       const gchar *dn,
+                       const gchar *username,
                        const gchar *datasource_name,
                        const gchar *table_name,
                        ...);
 
 gboolean zak_audit_action_v (ZakAudit *zak_audit,
                        enum ZakAuditActions action,
-                       const gchar *dn,
+                       const gchar *username,
                        const gchar *datasource_name,
                        const gchar *table_name,
                        const gchar **fields_values);
 
 gboolean zak_audit_action_from_gdastatement (ZakAudit *zak_audit,
                        enum ZakAuditActions action,
-                       const gchar *dn,
+                       const gchar *username,
                        const gchar *datasource_name,
                        GdaStatement *gda_statement);
 
+GtkWidget *zak_audit_get_changes_widget (ZakAudit *zak_audit,
+                                         const gchar *datasource_name,
+                                         const gchar *table_name,
+                                         const gchar **key_values);
+
 void zak_audit_destroy (ZakAudit *zak_audit);