]> saetta.ns0.it Git - zakaudit/libzakaudit/commitdiff
Use of GdaExGrid for the changes widget.
authorAndrea Zagli <azagli@libero.it>
Fri, 3 Jan 2020 14:10:13 +0000 (15:10 +0100)
committerAndrea Zagli <azagli@libero.it>
Fri, 3 Jan 2020 14:10:13 +0000 (15:10 +0100)
configure.ac
data/libzakaudit/gui/libzakaudit.ui
src/audit.c
tests/test1.c

index 513fb3aed80936063dde559d475f1635aeedec81..c254cafb828b0f1a910832bcd6dba1c260d62f6d 100644 (file)
@@ -45,7 +45,8 @@ if test "x$HAVE_PKGCONFIG" = "xno"; then
   AC_MSG_ERROR(you need to have pkgconfig installed !)
 fi
 
-PKG_CHECK_MODULES(LIBZAKAUDIT, [libgdaex >= 0.5.0])
+PKG_CHECK_MODULES(LIBZAKAUDIT, [libgdaex >= 0.5.0
+                                libgdaexgrid])
 
 AC_SUBST(LIBZAKAUDIT_CFLAGS)
 AC_SUBST(LIBZAKAUDIT_LIBS)
index 395822ae6e49cc4b150716896f028268ac667ff3..6696d4f7cc5904d4d5f20dae90c0f2655f7dc97e 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
 <interface>
-  <requires lib="gtk+" version="2.24"/>
-  <!-- interface-naming-policy project-wide -->
+  <requires lib="gtk+" version="3.0"/>
   <object class="GtkWindow" id="w_changes">
     <property name="can_focus">False</property>
     <property name="modal">True</property>
@@ -9,6 +9,9 @@
     <property name="default_width">600</property>
     <property name="default_height">400</property>
     <property name="destroy_with_parent">True</property>
+    <child>
+      <placeholder/>
+    </child>
     <child>
       <object class="GtkVBox" id="vbox1">
         <property name="visible">True</property>
           <object class="GtkScrolledWindow" id="scrolledwindow1">
             <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">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="rules_hint">True</property>
-              </object>
+              <placeholder/>
             </child>
           </object>
           <packing>
index c5c3ede6692fef14dd59846241119b4e02953daa..80b4455880d983d5eb140d67dc86b4ffcdfef6ac 100644 (file)
@@ -34,6 +34,8 @@
 
 #include <libgda/sql-parser/gda-sql-parser.h>
 
+#include <libgdaexgrid/libgdaexgrid.h>
+
 #include "libzakaudit.h"
 
 static guint debug;
@@ -1791,7 +1793,6 @@ GtkWidget
        guint rows;
        ChangesColumn *column;
        GHashTable *ht_columns;
-       GType *gtype;
 
        gchar *sql;
        GString *sql_where;
@@ -1799,10 +1800,11 @@ GtkWidget
        GdaDataModel *dm;
        GdaDataModel *dm_tmp;
 
-       GtkTreeView *tview;
-       GtkCellRenderer *renderer;
-       GtkTreeViewColumn *vcolumn;
-       GtkListStore *lstore;
+       GtkWidget *wgrid;
+       GdaExGrid *gdaexgrid;
+       GdaExGridColumn *gdaexgridcolumn;
+       GtkTreeStore *tstore;
+
        GtkTreeIter iter;
        GtkTreeIter *iter_prev;
 
@@ -1875,51 +1877,29 @@ GtkWidget
                                                strtol (field_value, NULL, 10));
                }
 
-       tview = GTK_TREE_VIEW (gtk_builder_get_object (priv->gtkbuilder, "treeview1"));
+       gdaexgrid = gdaex_grid_new ();
 
        sql = g_strdup_printf ("SELECT *"
                               " FROM fields"
-                              " WHERE id_tables = %d",
+                              " WHERE id_tables = %d"
+                              " ORDER BY id",
                               table->id);
        dm = gdaex_query (priv->gdaex, sql);
        if (dm != NULL && gda_data_model_get_n_rows (dm) > 0)
                {
                        rows = gda_data_model_get_n_rows (dm);
 
-                       gtype = g_new0 (GType, CHANGES_STATIC_COLUMNS + rows);
-
-                       gtype[COL_CHANGES_ID] = G_TYPE_INT;     /* id */
-                       renderer = gtk_cell_renderer_spin_new ();
-                       gtk_cell_renderer_set_alignment (renderer, 1.0, 0.5);
-                       vcolumn = gtk_tree_view_column_new ();
-                       gtk_tree_view_column_pack_start (vcolumn, renderer, TRUE);
-                       gtk_tree_view_column_set_title (vcolumn, _("ID"));
-                       gtk_tree_view_column_add_attribute (vcolumn, renderer, "text", COL_CHANGES_ID);
-                       gtk_tree_view_append_column (tview, vcolumn);
-
-                       gtype[COL_CHANGES_DATE] = G_TYPE_STRING;        /* date */
-                       renderer = gtk_cell_renderer_text_new ();
-                       vcolumn = gtk_tree_view_column_new ();
-                       gtk_tree_view_column_pack_start (vcolumn, renderer, TRUE);
-                       gtk_tree_view_column_set_title (vcolumn, _("Date"));
-                       gtk_tree_view_column_add_attribute (vcolumn, renderer, "text", COL_CHANGES_DATE);
-                       gtk_tree_view_append_column (tview, vcolumn);
-
-                       gtype[COL_CHANGES_OPERATION] = G_TYPE_STRING;   /* type */
-                       renderer = gtk_cell_renderer_text_new ();
-                       vcolumn = gtk_tree_view_column_new ();
-                       gtk_tree_view_column_pack_start (vcolumn, renderer, TRUE);
-                       gtk_tree_view_column_set_title (vcolumn, _("Operation"));
-                       gtk_tree_view_column_add_attribute (vcolumn, renderer, "text", COL_CHANGES_OPERATION);
-                       gtk_tree_view_append_column (tview, vcolumn);
-
-                       gtype[COL_CHANGES_USER] = G_TYPE_STRING;        /* username */
-                       renderer = gtk_cell_renderer_text_new ();
-                       vcolumn = gtk_tree_view_column_new ();
-                       gtk_tree_view_column_pack_start (vcolumn, renderer, TRUE);
-                       gtk_tree_view_column_set_title (vcolumn, _("User"));
-                       gtk_tree_view_column_add_attribute (vcolumn, renderer, "text", COL_CHANGES_USER);
-                       gtk_tree_view_append_column (tview, vcolumn);
+                       gdaexgridcolumn = gdaex_grid_column_new (_("ID"), "id", G_TYPE_INT, TRUE, TRUE, TRUE, TRUE, -1);
+                       gdaex_grid_add_column (gdaexgrid, gdaexgridcolumn);
+
+                       gdaexgridcolumn = gdaex_grid_column_new_defaults (_("Date"), "date", G_TYPE_STRING);
+                       gdaex_grid_add_column (gdaexgrid, gdaexgridcolumn);
+
+                       gdaexgridcolumn = gdaex_grid_column_new_defaults (_("Operation"), NULL, G_TYPE_STRING);
+                       gdaex_grid_add_column (gdaexgrid, gdaexgridcolumn);
+
+                       gdaexgridcolumn = gdaex_grid_column_new_defaults (_("User"), NULL, G_TYPE_STRING);
+                       gdaex_grid_add_column (gdaexgrid, gdaexgridcolumn);
 
                        for (row = 0; row < rows; row++)
                                {
@@ -1935,17 +1915,10 @@ GtkWidget
                                         * column->field_value =
                                         */
 
-                                       gtype[CHANGES_STATIC_COLUMNS + row] = G_TYPE_STRING;
-                                       renderer = gtk_cell_renderer_text_new ();
-                                       vcolumn = gtk_tree_view_column_new ();
-                                       gtk_tree_view_column_pack_start (vcolumn, renderer, TRUE);
-                                       gtk_tree_view_column_set_title (vcolumn, column->field_name);
-                                       gtk_tree_view_column_add_attribute (vcolumn, renderer, "text", CHANGES_STATIC_COLUMNS + row);
-                                       gtk_tree_view_append_column (tview, vcolumn);
+                                       gdaexgridcolumn = gdaex_grid_column_new_defaults (column->field_name, NULL, G_TYPE_STRING);
+                                       gdaex_grid_add_column (gdaexgrid, gdaexgridcolumn);
 
                                        g_hash_table_insert (ht_columns, (gpointer)column->field_name, (gpointer)column);
-
-                                       gtype[CHANGES_STATIC_COLUMNS + row] = G_TYPE_STRING;
                                }
                }
        else
@@ -1962,8 +1935,10 @@ GtkWidget
                        g_object_unref (dm);
                }
 
-       lstore = GTK_LIST_STORE (gtk_list_store_newv (CHANGES_STATIC_COLUMNS + rows, gtype));
-       gtk_tree_view_set_model (tview, GTK_TREE_MODEL (lstore));
+       wgrid = gdaex_grid_get_widget (gdaexgrid);
+       gtk_container_add (GTK_CONTAINER (gtk_builder_get_object (priv->gtkbuilder, "scrolledwindow1")), wgrid);
+       gtk_widget_show (wgrid);
+       tstore = GTK_TREE_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (wgrid)));
 
        /* find the last action
         * go backward
@@ -1996,15 +1971,15 @@ GtkWidget
 
                                        if (gdaex_data_model_get_field_value_integer_at (dm, row_action, "type") == ZAK_AUDIT_ACTION_DELETE)
                                                {
-                                                       gtk_list_store_append (lstore, &iter);
-                                                       gtk_list_store_set (lstore, &iter,
+                                                       gtk_tree_store_append (tstore, &iter, NULL);
+                                                       gtk_tree_store_set (tstore, &iter,
                                                                            COL_CHANGES_ID, gdaex_data_model_get_field_value_integer_at (dm, row_action, "id"),
                                                                            COL_CHANGES_DATE, g_date_time_format (gdaex_data_model_get_field_value_gdatetime_at (dm, row_action, "date"), "%d/%m/%Y %H.%M.%S"),
                                                                            COL_CHANGES_OPERATION, _("Deleted"),
                                                                            COL_CHANGES_USER, gdaex_data_model_get_field_value_stringify_at (dm, row_action, "username"),
                                                                            -1);
 
-                                                       gtk_list_store_append (lstore, &iter);
+                                                       gtk_tree_store_append (tstore, &iter, NULL);
 
                                                        /* last values are stored in zakaudit tables */
                                                        sql = g_strdup_printf ("SELECT v.*, f.name"
@@ -2023,7 +1998,7 @@ GtkWidget
                                                                                        if (column != NULL)
                                                                                                {
                                                                                                        column->field_value = gdaex_data_model_get_field_value_stringify_at (dm_tmp, row, "value");
-                                                                                                       gtk_list_store_set (lstore, &iter,
+                                                                                                       gtk_tree_store_set (tstore, &iter,
                                                                                                                            column->col, column->field_value,
                                                                                                                            -1);
                                                                                                }
@@ -2042,7 +2017,7 @@ GtkWidget
                                                                }
                                                        else
                                                                {
-                                                                       gtk_list_store_append (lstore, &iter);
+                                                                       gtk_tree_store_append (tstore, &iter, NULL);
 
                                                                        /* last values are stored in datasource audited */
                                                                        sql = g_strdup_printf ("SELECT *"
@@ -2061,7 +2036,7 @@ GtkWidget
                                                                                                        if (column != NULL)
                                                                                                                {
                                                                                                                        column->field_value = gdaex_data_model_get_value_stringify_at (dm_tmp, 0, col);
-                                                                                                                       gtk_list_store_set (lstore, &iter,
+                                                                                                                       gtk_tree_store_set (tstore, &iter,
                                                                                                                                            column->col, column->field_value,
                                                                                                                                            -1);
                                                                                                                }
@@ -2070,7 +2045,7 @@ GtkWidget
                                                                                }
                                                                }
 
-                                                       gtk_list_store_set (lstore, &iter,
+                                                       gtk_tree_store_set (tstore, &iter,
                                                                            COL_CHANGES_ID, gdaex_data_model_get_field_value_integer_at (dm, row_action, "id"),
                                                                            COL_CHANGES_DATE, g_date_time_format (gdaex_data_model_get_field_value_gdatetime_at (dm, row_action, "date"), "%d/%m/%Y %H.%M.%S"),
                                                                            COL_CHANGES_OPERATION, gdaex_data_model_get_field_value_integer_at (dm, row_action, "type") == ZAK_AUDIT_ACTION_AFTER_UPDATE ? _("Edited") :
@@ -2085,17 +2060,17 @@ GtkWidget
                                                                        continue;
                                                                }
 
-                                                       gtk_list_store_append (lstore, &iter);
+                                                       gtk_tree_store_append (tstore, &iter, NULL);
 
                                                        /* copy iter_prev to iter */
                                                        gchar *field_value;
 
                                                        for (col = 0; col < g_list_length (table->fields); col++)
                                                                {
-                                                                       gtk_tree_model_get (GTK_TREE_MODEL (lstore), iter_prev,
+                                                                       gtk_tree_model_get (GTK_TREE_MODEL (tstore), iter_prev,
                                                                                            col + CHANGES_STATIC_COLUMNS, &field_value,
                                                                                            -1);
-                                                                       gtk_list_store_set (lstore, &iter,
+                                                                       gtk_tree_store_set (tstore, &iter,
                                                                                            col + CHANGES_STATIC_COLUMNS, field_value,
                                                                                            -1);
                                                                }
@@ -2137,7 +2112,7 @@ GtkWidget
                                                                                                                {
                                                                                                                        column->field_value = gdaex_data_model_get_field_value_stringify_at (dm_tmp, row, "value");
                                                                                                                }
-                                                                                                       gtk_list_store_set (lstore, &iter,
+                                                                                                       gtk_tree_store_set (tstore, &iter,
                                                                                                                            column->col, column->field_value,
                                                                                                                            -1);
                                                                                                }
index da1b2f1ffe661ab80435273084c47f38ef71841b..c12cff20e2206d880bdf619a043de90cc3c26bb8 100644 (file)
@@ -154,6 +154,10 @@ main (int argc, char *argv[])
        gdaex_execute (gdaex, "UPDATE test1 SET age=99 WHERE id IN (3, 4)");
        zak_audit_action_from_where (audit, ZAK_AUDIT_ACTION_AFTER_UPDATE, "I", "audit_test1", "test1", "id IN (3, 4)");
 
+       zak_audit_action_from_where (audit, ZAK_AUDIT_ACTION_BEFORE_UPDATE, "Y", "audit_test1", "test1", "id = 3");
+       gdaex_execute (gdaex, "UPDATE test1 SET name='im the law' WHERE id = 3");
+       zak_audit_action_from_where (audit, ZAK_AUDIT_ACTION_AFTER_UPDATE, "Y", "audit_test1", "test1", "id = 3");
+
        zak_audit_action_from_where (audit, ZAK_AUDIT_ACTION_DELETE, "I", "audit_test1", "test1", "id IN (3, 4)");
        gdaex_execute (gdaex, "DELETE FROM test1 WHERE id IN (3, 4)");
 
@@ -163,7 +167,7 @@ main (int argc, char *argv[])
        g_warning ("User insertion: %s",
                   zak_audit_get_user_insertion (audit, "audit_test1", "test1", (const gchar **)g_strsplit ("id|2", "|", -1)));
 
-       w = zak_audit_get_changes_widget (audit, "audit_test1", "test1", (const gchar **)g_strsplit ("id|5", "|", -1));
+       w = zak_audit_get_changes_widget (audit, "audit_test1", "test1", (const gchar **)g_strsplit ("id|3", "|", -1));
 
        g_signal_connect (w, "delete-event", G_CALLBACK (on_w_delete_event), NULL);
        g_signal_connect (w, "destroy", gtk_main_quit, NULL);