From: Andrea Zagli Date: Thu, 30 Jan 2014 16:05:47 +0000 (+0100) Subject: GUI to show changes: now it shows the first (last) action. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;p=zakaudit%2Flibzakaudit GUI to show changes: now it shows the first (last) action. --- diff --git a/data/libzakaudit/gui/libzakaudit.ui b/data/libzakaudit/gui/libzakaudit.ui index 489a408..395822a 100644 --- a/data/libzakaudit/gui/libzakaudit.ui +++ b/data/libzakaudit/gui/libzakaudit.ui @@ -6,6 +6,8 @@ False True center-on-parent + 600 + 400 True diff --git a/src/audit.c b/src/audit.c index 9e6a523..4e2ff90 100644 --- a/src/audit.c +++ b/src/audit.c @@ -1315,6 +1315,8 @@ GtkWidget "|", -1), &error); + ret = GTK_WIDGET (gtk_builder_get_object (priv->gtkbuilder, "w_changes")); + sql_where = g_string_new (""); for (strpart = 0; strpart < l; strpart++) @@ -1357,6 +1359,7 @@ GtkWidget 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 (); @@ -1364,6 +1367,7 @@ GtkWidget 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 (); @@ -1371,6 +1375,7 @@ GtkWidget 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 (); @@ -1378,6 +1383,7 @@ GtkWidget 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); for (row = 0; row < rows; row++) { @@ -1393,6 +1399,14 @@ 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); + g_hash_table_insert (ht_columns, (gpointer)column->field_name, (gpointer)column); gtype[CHANGES_STATIC_COLUMNS + row] = G_TYPE_STRING; @@ -1412,7 +1426,7 @@ GtkWidget g_object_unref (dm); } - lstore = GTK_LIST_STORE (gtk_list_store_newv (4 + rows, gtype)); + lstore = GTK_LIST_STORE (gtk_list_store_newv (CHANGES_STATIC_COLUMNS + rows, gtype)); gtk_tree_view_set_model (tview, GTK_TREE_MODEL (lstore)); /* find the last action @@ -1447,14 +1461,14 @@ GtkWidget /* TODO check if key field value is changed */ - /* TODO i could find field that there's not in columns (the dm passed)*/ + /* TODO i could find field that there's not in columns (the dm passed) */ if (gdaex_data_model_get_field_value_integer_at (dm, 0, "type") == ZAK_AUDIT_ACTION_DELETE) { /* last values are stored in zakaudit tables */ sql = g_strdup_printf ("SELECT v.*, f.name" " FROM values AS v" - " INNSER JOIN fields AS f ON v.id_fields = f.id" + " INNER JOIN fields AS f ON v.id_fields = f.id" " WHERE v.id_actions = %d", gdaex_data_model_get_field_value_integer_at (dm, 0, "id")); dm = gdaex_query (priv->gdaex, sql); @@ -1508,7 +1522,6 @@ GtkWidget g_object_unref (dm); } - ret = NULL; g_warning ("The function is still to be implemented"); return ret; diff --git a/tests/test1.c b/tests/test1.c index 2e7d512..445b8e0 100644 --- a/tests/test1.c +++ b/tests/test1.c @@ -1,7 +1,7 @@ /* * test1.c * - * Copyright (C) 2005-2013 Andrea Zagli + * Copyright (C) 2005-2014 Andrea Zagli * * This file is part of libaudit. * @@ -34,6 +34,14 @@ static GOptionEntry entries[] = { NULL } }; +gboolean +on_w_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer user_data) +{ + return FALSE; +} + int main (int argc, char *argv[]) { @@ -51,7 +59,9 @@ main (int argc, char *argv[]) cnc_zakaudit = NULL; cnc_db = NULL; - g_type_init (); + GtkWidget *w; + + gtk_init (&argc, &argv); ctx = g_option_context_new (""); g_option_context_add_main_entries (ctx, entries, "audit_test1"); @@ -132,6 +142,15 @@ 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|2", "|", -1)); + + g_signal_connect (w, "delete-event", G_CALLBACK (on_w_delete_event), NULL); + g_signal_connect (w, "destroy", gtk_main_quit, NULL); + + gtk_widget_show_all (w); + + gtk_main (); + zak_audit_destroy (audit); return 0;