From 5a55f69338d1a6b4d9f2c8c843e63063e1141bc7 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Mon, 2 May 2016 17:29:04 +0200 Subject: [PATCH] Test ini provider. --- .gitignore | 1 + configure.ac | 5 +- src/Makefile.am | 3 +- src/gtk_ini.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 src/gtk_ini.c diff --git a/.gitignore b/.gitignore index e503f7c..4d90450 100644 --- a/.gitignore +++ b/.gitignore @@ -51,3 +51,4 @@ Rules-quot *.exe *.csv gtk_gdaex +gtk_ini \ No newline at end of file diff --git a/configure.ac b/configure.ac index 8233143..e45c10d 100644 --- a/configure.ac +++ b/configure.ac @@ -34,8 +34,9 @@ AM_GLIB_GNU_GETTEXT # Checks for libraries. PKG_CHECK_MODULES(ZAKFORMTESTS, [libzakform - libzakformgtk - libzakformgdaex]) + libzakformgtk + libzakformgdaex + libzakformini]) AC_SUBST(ZAKFORMTESTS_CFLAGS) AC_SUBST(ZAKFORMTESTS_LIBS) diff --git a/src/Makefile.am b/src/Makefile.am index 0e17ba8..d5f5a58 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,4 +8,5 @@ AM_CPPFLAGS = $(WARN_CFLAGS) \ LIBS = $(ZAKFORMTESTS_LIBS) noinst_PROGRAMS = \ - gtk_gdaex + gtk_gdaex \ + gtk_ini diff --git a/src/gtk_ini.c b/src/gtk_ini.c new file mode 100644 index 0000000..cf17500 --- /dev/null +++ b/src/gtk_ini.c @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2016 Andrea Zagli + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include +#include +#include + +GtkWidget *w; + +ZakFormGtkForm *form; +ZakFormIniProvider *provider; + +void +load_clicked (GtkButton *button, + gpointer user_data) +{ + zak_form_form_load (ZAK_FORM_FORM (form), ZAK_FORM_IPROVIDER (provider)); +} + +void +insert_clicked (GtkButton *button, + gpointer user_data) +{ + zak_form_form_insert (ZAK_FORM_FORM (form), ZAK_FORM_IPROVIDER (provider)); +} + +void +update_clicked (GtkButton *button, + gpointer user_data) +{ + zak_form_form_update (ZAK_FORM_FORM (form), ZAK_FORM_IPROVIDER (provider)); +} + +void +is_valid_clicked (GtkButton *button, + gpointer user_data) +{ + zak_form_gtk_form_is_valid (form, w); +} + +void +is_changed_clicked (GtkButton *button, + gpointer user_data) +{ + if (zak_form_form_is_changed (ZAK_FORM_FORM (form))) + { + GtkWidget *dialog; + + dialog = gtk_message_dialog_new (GTK_WINDOW (w), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_OK, + "Form is changed."); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + } +} + +int +main (int argc, char *argv[]) +{ + GtkBuilder *builder; + + gtk_init (&argc, &argv); + + builder = gtk_builder_new (); + gtk_builder_add_objects_from_file (builder, GUIDIR "/main.ui", + g_strsplit ("w_main" + "|adjustment1", "|", -1), NULL); + + w = GTK_WIDGET (gtk_builder_get_object (builder, "w_main")); + + g_signal_connect (w, "delete-event", + gtk_main_quit, NULL); + + g_signal_connect (gtk_builder_get_object (builder, "button1"), "clicked", + G_CALLBACK (load_clicked), NULL); + g_signal_connect (gtk_builder_get_object (builder, "button2"), "clicked", + G_CALLBACK (insert_clicked), NULL); + g_signal_connect (gtk_builder_get_object (builder, "button3"), "clicked", + G_CALLBACK (update_clicked), NULL); + g_signal_connect (gtk_builder_get_object (builder, "button4"), "clicked", + G_CALLBACK (is_valid_clicked), NULL); + g_signal_connect (gtk_builder_get_object (builder, "button5"), "clicked", + G_CALLBACK (is_changed_clicked), NULL); + + form = zak_form_gtk_form_new (); + zak_form_gtk_form_set_gtkbuilder (form, builder); + zak_form_form_load_from_file (ZAK_FORM_FORM (form), XMLDIR "/main.xml"); + zak_form_form_clear (ZAK_FORM_FORM (form)); + zak_form_form_set_as_original (ZAK_FORM_FORM (form)); + + provider = zak_form_ini_provider_new_from_file (argv[1], "clients"); + + gtk_widget_show_all (w); + + gtk_main (); + + return 0; +} -- 2.49.0