From c27d555f18ea6ab51be5344e0cc1036f2c894407 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 10 Dec 2006 07:40:08 +0000 Subject: [PATCH] Initial import --- AUTHORS | 1 + ChangeLog | 0 Makefile.am | 8 + NEWS | 0 README | 0 config.h.in | 64 ++ configure.ac | 56 ++ docs/Makefile.am | 1 + docs/reference/Makefile.am | 78 ++ docs/reference/libform-docs.sgml | 30 + docs/reference/libform-overrides.txt | 0 docs/reference/libform-sections.txt | 259 +++++++ docs/reference/libform-undocumented.txt | 225 ++++++ docs/reference/libform.types | 27 + docs/reference/tmpl/libform-unused.sgml | 19 + docs/reference/tmpl/libform.sgml | 167 ++++ docs/reference/tmpl/libformfield.sgml | 177 +++++ docs/reference/tmpl/libformfieldboolean.sgml | 149 ++++ docs/reference/tmpl/libformfielddatetime.sgml | 145 ++++ docs/reference/tmpl/libformfieldfloat.sgml | 149 ++++ docs/reference/tmpl/libformfieldinteger.sgml | 149 ++++ docs/reference/tmpl/libformfieldtext.sgml | 149 ++++ docs/reference/tmpl/libformkey.sgml | 136 ++++ docs/reference/tmpl/libformwidget.sgml | 137 ++++ docs/reference/tmpl/libformwidgetcheck.sgml | 107 +++ docs/reference/tmpl/libformwidgetentry.sgml | 107 +++ docs/reference/tmpl/libformwidgetlabel.sgml | 107 +++ docs/reference/tmpl/libformwidgetspin.sgml | 107 +++ .../reference/tmpl/libformwidgettextview.sgml | 107 +++ docs/reference/version.xml.in | 1 + libform.pc.in | 11 + src/Makefile.am | 39 + src/field.c | 311 ++++++++ src/fieldboolean.c | 329 ++++++++ src/fielddatetime.c | 319 ++++++++ src/fieldfloat.c | 310 ++++++++ src/fieldinteger.c | 301 ++++++++ src/fieldtext.c | 301 ++++++++ src/form.c | 417 ++++++++++ src/formkey.c | 223 ++++++ src/libform.h | 83 ++ src/libformfield.h | 82 ++ src/libformfieldboolean.h | 69 ++ src/libformfielddatetime.h | 69 ++ src/libformfieldfloat.h | 69 ++ src/libformfieldinteger.h | 69 ++ src/libformfieldtext.h | 69 ++ src/libformkey.h | 69 ++ src/libformwidget.h | 71 ++ src/libformwidgetcheck.h | 61 ++ src/libformwidgetentry.h | 61 ++ src/libformwidgetlabel.h | 61 ++ src/libformwidgetspin.h | 61 ++ src/libformwidgettextview.h | 61 ++ src/old/form.c | 692 +++++++++++++++++ src/old/libform.h | 81 ++ src/widget.c | 234 ++++++ src/widgetcheck.c | 213 ++++++ src/widgetentry.c | 178 +++++ src/widgetlabel.c | 178 +++++ src/widgetspin.c | 183 +++++ src/widgettextview.c | 190 +++++ test/Makefile.am | 12 + test/main.c | 249 ++++++ test/test.glade | 711 ++++++++++++++++++ 65 files changed, 9099 insertions(+) create mode 100644 AUTHORS create mode 100644 ChangeLog create mode 100644 Makefile.am create mode 100644 NEWS create mode 100644 README create mode 100644 config.h.in create mode 100644 configure.ac create mode 100644 docs/Makefile.am create mode 100644 docs/reference/Makefile.am create mode 100644 docs/reference/libform-docs.sgml create mode 100644 docs/reference/libform-overrides.txt create mode 100644 docs/reference/libform-sections.txt create mode 100644 docs/reference/libform-undocumented.txt create mode 100644 docs/reference/libform.types create mode 100644 docs/reference/tmpl/libform-unused.sgml create mode 100644 docs/reference/tmpl/libform.sgml create mode 100644 docs/reference/tmpl/libformfield.sgml create mode 100644 docs/reference/tmpl/libformfieldboolean.sgml create mode 100644 docs/reference/tmpl/libformfielddatetime.sgml create mode 100644 docs/reference/tmpl/libformfieldfloat.sgml create mode 100644 docs/reference/tmpl/libformfieldinteger.sgml create mode 100644 docs/reference/tmpl/libformfieldtext.sgml create mode 100644 docs/reference/tmpl/libformkey.sgml create mode 100644 docs/reference/tmpl/libformwidget.sgml create mode 100644 docs/reference/tmpl/libformwidgetcheck.sgml create mode 100644 docs/reference/tmpl/libformwidgetentry.sgml create mode 100644 docs/reference/tmpl/libformwidgetlabel.sgml create mode 100644 docs/reference/tmpl/libformwidgetspin.sgml create mode 100644 docs/reference/tmpl/libformwidgettextview.sgml create mode 100644 docs/reference/version.xml.in create mode 100644 libform.pc.in create mode 100644 src/Makefile.am create mode 100644 src/field.c create mode 100644 src/fieldboolean.c create mode 100644 src/fielddatetime.c create mode 100644 src/fieldfloat.c create mode 100644 src/fieldinteger.c create mode 100644 src/fieldtext.c create mode 100644 src/form.c create mode 100644 src/formkey.c create mode 100644 src/libform.h create mode 100644 src/libformfield.h create mode 100644 src/libformfieldboolean.h create mode 100644 src/libformfielddatetime.h create mode 100644 src/libformfieldfloat.h create mode 100644 src/libformfieldinteger.h create mode 100644 src/libformfieldtext.h create mode 100644 src/libformkey.h create mode 100644 src/libformwidget.h create mode 100644 src/libformwidgetcheck.h create mode 100644 src/libformwidgetentry.h create mode 100644 src/libformwidgetlabel.h create mode 100644 src/libformwidgetspin.h create mode 100644 src/libformwidgettextview.h create mode 100644 src/old/form.c create mode 100644 src/old/libform.h create mode 100644 src/widget.c create mode 100644 src/widgetcheck.c create mode 100644 src/widgetentry.c create mode 100644 src/widgetlabel.c create mode 100644 src/widgetspin.c create mode 100644 src/widgettextview.c create mode 100644 test/Makefile.am create mode 100644 test/main.c create mode 100644 test/test.glade diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..948556f --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ +Andrea Zagli diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..e69de29 diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..a6e25de --- /dev/null +++ b/Makefile.am @@ -0,0 +1,8 @@ +DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc + +SUBDIRS = src test docs + +EXTRA_DIST = libform.pc.in + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = libform.pc diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..e69de29 diff --git a/README b/README new file mode 100644 index 0000000..e69de29 diff --git a/config.h.in b/config.h.in new file mode 100644 index 0000000..6928c1b --- /dev/null +++ b/config.h.in @@ -0,0 +1,64 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the header file. */ +#undef HAVE_DLFCN_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the `localeconv' function. */ +#undef HAVE_LOCALECONV + +/* Define to 1 if you have the header file. */ +#undef HAVE_LOCALE_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Version number of package */ +#undef VERSION + +/* Define to empty if `const' does not conform to ANSI C. */ +#undef const diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..80384f0 --- /dev/null +++ b/configure.ac @@ -0,0 +1,56 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.59) +AC_INIT([libform], [0.0.1], [azagli@inwind.it]) +AC_CONFIG_SRCDIR([src/form.c]) +AC_CONFIG_HEADER([config.h]) + +AM_INIT_AUTOMAKE +AM_MAINTAINER_MODE + +AC_CANONICAL_SYSTEM + +AC_LIBTOOL_WIN32_DLL + +# Checks for programs. +AC_PROG_CXX +AC_PROG_CC +AC_PROG_CPP +AC_PROG_INSTALL +AC_PROG_LN_S +AC_PROG_MAKE_SET +AC_PROG_LIBTOOL + +GTK_DOC_CHECK + +# Checks for libraries. +PKG_CHECK_MODULES(FORM, [gtk+-2.0 >= 2.6.0 + libglade-2.0 >= 2.0.0 + libgdaobj >= 0.0.2]) + +AC_SUBST(FORM_CFLAGS) +AC_SUBST(FORM_LIBS) + +# Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS([locale.h string.h stdlib.h]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST + +# Checks for library functions. +AC_CHECK_FUNCS([localeconv]) +AC_FUNC_STRTOD + +# Checks for library functions. +AC_CONFIG_FILES([ + libform.pc + Makefile + src/Makefile + test/Makefile + docs/Makefile + docs/reference/Makefile + docs/reference/version.xml +]) +AC_OUTPUT diff --git a/docs/Makefile.am b/docs/Makefile.am new file mode 100644 index 0000000..f3ddc22 --- /dev/null +++ b/docs/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = reference diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am new file mode 100644 index 0000000..094ba4c --- /dev/null +++ b/docs/reference/Makefile.am @@ -0,0 +1,78 @@ +## Process this file with automake to produce Makefile.in + +# We require automake 1.6 at least. +AUTOMAKE_OPTIONS = 1.6 + +# This is a blank Makefile.am for using gtk-doc. +# Copy this to your project's API docs directory and modify the variables to +# suit your project. See the GTK+ Makefiles in gtk+/docs/reference for examples +# of using the various options. + +# The name of the module, e.g. 'glib'. +DOC_MODULE=libform + +# The top-level SGML file. You can change this if you want to. +DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.sgml + +# The directory containing the source code. Relative to $(srcdir). +# gtk-doc will search all .c & .h files beneath here for inline comments +# documenting the functions and macros. +# e.g. DOC_SOURCE_DIR=../../../gtk +DOC_SOURCE_DIR=../../src + +# Extra options to pass to gtkdoc-scangobj. Not normally needed. +SCANGOBJ_OPTIONS= + +# Extra options to supply to gtkdoc-scan. +# e.g. SCAN_OPTIONS=--deprecated-guards="GTK_DISABLE_DEPRECATED" +SCAN_OPTIONS= + +# Extra options to supply to gtkdoc-mkdb. +# e.g. MKDB_OPTIONS=--sgml-mode --output-format=xml +MKDB_OPTIONS=--sgml-mode --output-format=xml + +# Extra options to supply to gtkdoc-mktmpl +# e.g. MKTMPL_OPTIONS=--only-section-tmpl +MKTMPL_OPTIONS= + +# Extra options to supply to gtkdoc-fixref. Not normally needed. +# e.g. FIXXREF_OPTIONS=--extra-dir=../gdk-pixbuf/html --extra-dir=../gdk/html +FIXXREF_OPTIONS= + +# Used for dependencies. The docs will be rebuilt if any of these change. +# e.g. HFILE_GLOB=$(top_srcdir)/gtk/*.h +# e.g. CFILE_GLOB=$(top_srcdir)/gtk/*.c +HFILE_GLOB=$(top_srcdir)/src/*.h +CFILE_GLOB=$(top_srcdir)/src/*.c + +# Header files to ignore when scanning. +# e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h +IGNORE_HFILES= + +# Images to copy into HTML directory. +# e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png +HTML_IMAGES= + +# Extra SGML files that are included by $(DOC_MAIN_SGML_FILE). +# e.g. content_files=running.sgml building.sgml changes-2.0.sgml +content_files= + +# SGML files where gtk-doc abbrevations (#GtkWidget) are expanded +# These files must be listed here *and* in content_files +# e.g. expand_content_files=running.sgml +expand_content_files= + +# CFLAGS and LDFLAGS for compiling gtkdoc-scangobj with your library. +# Only needed if you are using gtkdoc-scangobj to dynamically query widget +# signals and properties. +# e.g. INCLUDES=-I$(top_srcdir) -I$(top_builddir) $(GTK_DEBUG_FLAGS) +# e.g. GTKDOC_LIBS=$(top_builddir)/gtk/$(gtktargetlib) +INCLUDES=-I$(top_srcdir)/src $(FORM_CFLAGS) +GTKDOC_LIBS=$(top_builddir)/src/libform.la $(FORM_LIBS) + +# This includes the standard gtk-doc make rules, copied by gtkdocize. +include $(top_srcdir)/gtk-doc.make + +# Other files to distribute +# e.g. EXTRA_DIST += version.xml.in +EXTRA_DIST += version.xml.in diff --git a/docs/reference/libform-docs.sgml b/docs/reference/libform-docs.sgml new file mode 100644 index 0000000..19501bb --- /dev/null +++ b/docs/reference/libform-docs.sgml @@ -0,0 +1,30 @@ + + +]> + + + LibForm Reference Manual + for LibForm &version; + + + + LibForm API Reference + + + + + + + + + + + + + + + + + diff --git a/docs/reference/libform-overrides.txt b/docs/reference/libform-overrides.txt new file mode 100644 index 0000000..e69de29 diff --git a/docs/reference/libform-sections.txt b/docs/reference/libform-sections.txt new file mode 100644 index 0000000..badafd9 --- /dev/null +++ b/docs/reference/libform-sections.txt @@ -0,0 +1,259 @@ +
+libform +TYPE_FORM +FORM +FORM_CLASS +IS_FORM +IS_FORM_CLASS +FORM_GET_CLASS +Form +Form +form_get_type +form_new +form_add_field +form_remove_field +form_clear +form_check +FormSqlType +form_get_sql +form_fill_from_datamodel +
+ +
+libformfield +TYPE_FORM_FIELD +FORM_FIELD +FORM_FIELD_CLASS +IS_FORM_FIELD +IS_FORM_FIELD_CLASS +FORM_FIELD_GET_CLASS +FormField +FormField +form_field_get_type +form_field_new +form_field_new_from_form_widget +form_field_get_field_name +form_field_get_value_stringify +form_field_get_value +form_field_get_value_sql +form_field_clear +form_field_is_empty +form_field_set_from_datamodel +
+ +
+libformwidget +TYPE_FORM_WIDGET +FORM_WIDGET +FORM_WIDGET_CLASS +IS_FORM_WIDGET +IS_FORM_WIDGET_CLASS +FORM_WIDGET_GET_CLASS +FormWidget +FormWidget +form_widget_get_type +form_widget_new +form_widget_set_from_glade +form_widget_get_widget +form_widget_get_value_stringify +form_widget_set_value_stringify +
+ +
+libformwidgetlabel +TYPE_FORM_WIDGET_LABEL +FORM_WIDGET_LABEL +FORM_WIDGET_LABEL_CLASS +IS_FORM_WIDGET_LABEL +IS_FORM_WIDGET_LABEL_CLASS +FORM_WIDGET_LABEL_GET_CLASS +FormWidgetLabel +FormWidgetLabel +form_widget_label_get_type +form_widget_label_new +form_widget_label_get_value_stringify +form_widget_label_set_value_stringify +
+ +
+libformfieldtext +TYPE_FORM_FIELD_TEXT +FORM_FIELD_TEXT +FORM_FIELD_TEXT_CLASS +IS_FORM_FIELD_TEXT +IS_FORM_FIELD_TEXT_CLASS +FORM_FIELD_TEXT_GET_CLASS +FormFieldText +FormFieldText +form_field_text_get_type +form_field_text_new +form_field_text_get_value_stringify +form_field_text_get_value +form_field_text_get_value_sql +form_field_text_clear +form_field_text_is_empty +form_field_text_set_from_datamodel +
+ +
+libformkey +TYPE_FORM_KEY +FORM_KEY +FORM_KEY_CLASS +IS_FORM_KEY +IS_FORM_KEY_CLASS +FORM_KEY_GET_CLASS +FormKey +FormKey +form_key_get_type +form_key_new +form_key_add_field +form_key_remove_field +form_key_check +form_key_get_sql +form_key_field_is_key +
+ +
+libformfielddatetime +TYPE_FORM_FIELD_DATETIME +FORM_FIELD_DATETIME +FORM_FIELD_DATETIME_CLASS +IS_FORM_FIELD_DATETIME +IS_FORM_FIELD_DATETIME_CLASS +FORM_FIELD_DATETIME_GET_CLASS +FormFieldDateTime +FormFieldDateTime +form_field_datetime_get_type +form_field_datetime_new +form_field_datetime_get_value_stringify +form_field_datetime_get_value +form_field_datetime_get_value_sql +form_field_datetime_clear +form_field_datetime_is_empty +form_field_datetime_set_from_datamodel +
+ +
+libformfieldinteger +TYPE_FORM_FIELD_INTEGER +FORM_FIELD_INTEGER +FORM_FIELD_INTEGER_CLASS +IS_FORM_FIELD_INTEGER +IS_FORM_FIELD_INTEGER_CLASS +FORM_FIELD_INTEGER_GET_CLASS +FormFieldInteger +FormFieldInteger +form_field_integer_get_type +form_field_integer_new +form_field_integer_get_value_stringify +form_field_integer_get_value +form_field_integer_get_value_sql +form_field_integer_clear +form_field_integer_is_empty +form_field_integer_set_from_datamodel +
+ +
+libformwidgetentry +TYPE_FORM_WIDGET_ENTRY +FORM_WIDGET_ENTRY +FORM_WIDGET_ENTRY_CLASS +IS_FORM_WIDGET_ENTRY +IS_FORM_WIDGET_ENTRY_CLASS +FORM_WIDGET_ENTRY_GET_CLASS +FormWidgetEntry +FormWidgetEntry +form_widget_entry_get_type +form_widget_entry_new +form_widget_entry_get_value_stringify +form_widget_entry_set_value_stringify +
+ +
+libformwidgetspin +TYPE_FORM_WIDGET_SPIN +FORM_WIDGET_SPIN +FORM_WIDGET_SPIN_CLASS +IS_FORM_WIDGET_SPIN +IS_FORM_WIDGET_SPIN_CLASS +FORM_WIDGET_SPIN_GET_CLASS +FormWidgetSpin +FormWidgetSpin +form_widget_spin_get_type +form_widget_spin_new +form_widget_spin_get_value_stringify +form_widget_spin_set_value_stringify +
+ +
+libformfieldboolean +TYPE_FORM_FIELD_BOOLEAN +FORM_FIELD_BOOLEAN +FORM_FIELD_BOOLEAN_CLASS +IS_FORM_FIELD_BOOLEAN +IS_FORM_FIELD_BOOLEAN_CLASS +FORM_FIELD_BOOLEAN_GET_CLASS +FormFieldBoolean +FormFieldBoolean +form_field_boolean_get_type +form_field_boolean_new +form_field_boolean_get_value_stringify +form_field_boolean_get_value +form_field_boolean_get_value_sql +form_field_boolean_clear +form_field_boolean_is_empty +form_field_boolean_set_from_datamodel +
+ +
+libformfieldfloat +TYPE_FORM_FIELD_FLOAT +FORM_FIELD_FLOAT +FORM_FIELD_FLOAT_CLASS +IS_FORM_FIELD_FLOAT +IS_FORM_FIELD_FLOAT_CLASS +FORM_FIELD_FLOAT_GET_CLASS +FormFieldFloat +FormFieldFloat +form_field_float_get_type +form_field_float_new +form_field_float_get_value_stringify +form_field_float_get_value +form_field_float_get_value_sql +form_field_float_clear +form_field_float_is_empty +form_field_float_set_from_datamodel +
+ +
+libformwidgetcheck +TYPE_FORM_WIDGET_CHECK +FORM_WIDGET_CHECK +FORM_WIDGET_CHECK_CLASS +IS_FORM_WIDGET_CHECK +IS_FORM_WIDGET_CHECK_CLASS +FORM_WIDGET_CHECK_GET_CLASS +FormWidgetCheck +FormWidgetCheck +form_widget_check_get_type +form_widget_check_new +form_widget_check_get_value_stringify +form_widget_check_set_value_stringify +
+ +
+libformwidgettextview +TYPE_FORM_WIDGET_TEXTVIEW +FORM_WIDGET_TEXTVIEW +FORM_WIDGET_TEXTVIEW_CLASS +IS_FORM_WIDGET_TEXTVIEW +IS_FORM_WIDGET_TEXTVIEW_CLASS +FORM_WIDGET_TEXTVIEW_GET_CLASS +FormWidgetTextview +FormWidgetTextview +form_widget_textview_get_type +form_widget_textview_new +form_widget_textview_get_value_stringify +form_widget_textview_set_value_stringify +
diff --git a/docs/reference/libform-undocumented.txt b/docs/reference/libform-undocumented.txt new file mode 100644 index 0000000..432c88b --- /dev/null +++ b/docs/reference/libform-undocumented.txt @@ -0,0 +1,225 @@ +6% symbol docs coverage. +13 symbols documented. +1 symbols incomplete. +216 not documented. + + +FORM +FORM_CLASS +FORM_FIELD +FORM_FIELD_BOOLEAN +FORM_FIELD_BOOLEAN_CLASS +FORM_FIELD_BOOLEAN_GET_CLASS +FORM_FIELD_CLASS +FORM_FIELD_DATETIME +FORM_FIELD_DATETIME_CLASS +FORM_FIELD_DATETIME_GET_CLASS +FORM_FIELD_FLOAT +FORM_FIELD_FLOAT_CLASS +FORM_FIELD_FLOAT_GET_CLASS +FORM_FIELD_GET_CLASS +FORM_FIELD_INTEGER +FORM_FIELD_INTEGER_CLASS +FORM_FIELD_INTEGER_GET_CLASS +FORM_FIELD_TEXT +FORM_FIELD_TEXT_CLASS +FORM_FIELD_TEXT_GET_CLASS +FORM_GET_CLASS +FORM_KEY +FORM_KEY_CLASS +FORM_KEY_GET_CLASS +FORM_WIDGET +FORM_WIDGET_CHECK +FORM_WIDGET_CHECK_CLASS +FORM_WIDGET_CHECK_GET_CLASS +FORM_WIDGET_CLASS +FORM_WIDGET_ENTRY +FORM_WIDGET_ENTRY_CLASS +FORM_WIDGET_ENTRY_GET_CLASS +FORM_WIDGET_GET_CLASS +FORM_WIDGET_LABEL +FORM_WIDGET_LABEL_CLASS +FORM_WIDGET_LABEL_GET_CLASS +FORM_WIDGET_SPIN +FORM_WIDGET_SPIN_CLASS +FORM_WIDGET_SPIN_GET_CLASS +FORM_WIDGET_TEXTVIEW +FORM_WIDGET_TEXTVIEW_CLASS +FORM_WIDGET_TEXTVIEW_GET_CLASS +Form +FormField +FormFieldBoolean +FormFieldDateTime +FormFieldFloat +FormFieldInteger +FormFieldText +FormKey +FormSqlType +FormWidget +FormWidgetCheck +FormWidgetEntry +FormWidgetLabel +FormWidgetSpin +FormWidgetTextview +IS_FORM +IS_FORM_CLASS +IS_FORM_FIELD +IS_FORM_FIELD_BOOLEAN +IS_FORM_FIELD_BOOLEAN_CLASS +IS_FORM_FIELD_CLASS +IS_FORM_FIELD_DATETIME +IS_FORM_FIELD_DATETIME_CLASS +IS_FORM_FIELD_FLOAT +IS_FORM_FIELD_FLOAT_CLASS +IS_FORM_FIELD_INTEGER +IS_FORM_FIELD_INTEGER_CLASS +IS_FORM_FIELD_TEXT +IS_FORM_FIELD_TEXT_CLASS +IS_FORM_KEY +IS_FORM_KEY_CLASS +IS_FORM_WIDGET +IS_FORM_WIDGET_CHECK +IS_FORM_WIDGET_CHECK_CLASS +IS_FORM_WIDGET_CLASS +IS_FORM_WIDGET_ENTRY +IS_FORM_WIDGET_ENTRY_CLASS +IS_FORM_WIDGET_LABEL +IS_FORM_WIDGET_LABEL_CLASS +IS_FORM_WIDGET_SPIN +IS_FORM_WIDGET_SPIN_CLASS +IS_FORM_WIDGET_TEXTVIEW +IS_FORM_WIDGET_TEXTVIEW_CLASS +TYPE_FORM +TYPE_FORM_FIELD +TYPE_FORM_FIELD_BOOLEAN +TYPE_FORM_FIELD_DATETIME +TYPE_FORM_FIELD_FLOAT +TYPE_FORM_FIELD_INTEGER +TYPE_FORM_FIELD_TEXT +TYPE_FORM_KEY +TYPE_FORM_WIDGET +TYPE_FORM_WIDGET_CHECK +TYPE_FORM_WIDGET_ENTRY +TYPE_FORM_WIDGET_LABEL +TYPE_FORM_WIDGET_SPIN +TYPE_FORM_WIDGET_TEXTVIEW +form_add_field +form_check +form_clear (Returns) +form_field_boolean_clear +form_field_boolean_get_type +form_field_boolean_get_value +form_field_boolean_get_value_sql +form_field_boolean_get_value_stringify +form_field_boolean_is_empty +form_field_boolean_new +form_field_boolean_set_from_datamodel +form_field_clear +form_field_datetime_clear +form_field_datetime_get_type +form_field_datetime_get_value +form_field_datetime_get_value_sql +form_field_datetime_get_value_stringify +form_field_datetime_is_empty +form_field_datetime_new +form_field_datetime_set_from_datamodel +form_field_float_clear +form_field_float_get_type +form_field_float_get_value +form_field_float_get_value_sql +form_field_float_get_value_stringify +form_field_float_is_empty +form_field_float_new +form_field_float_set_from_datamodel +form_field_get_field_name +form_field_get_type +form_field_get_value +form_field_get_value_sql +form_field_get_value_stringify +form_field_integer_clear +form_field_integer_get_type +form_field_integer_get_value +form_field_integer_get_value_sql +form_field_integer_get_value_stringify +form_field_integer_is_empty +form_field_integer_new +form_field_integer_set_from_datamodel +form_field_is_empty +form_field_new +form_field_new_from_form_widget +form_field_set_from_datamodel +form_field_text_clear +form_field_text_get_type +form_field_text_get_value +form_field_text_get_value_sql +form_field_text_get_value_stringify +form_field_text_is_empty +form_field_text_new +form_field_text_set_from_datamodel +form_fill_from_datamodel +form_get_sql +form_get_type +form_key_add_field +form_key_check +form_key_field_is_key +form_key_get_sql +form_key_get_type +form_key_new +form_key_remove_field +form_new +form_remove_field +form_widget_check_get_type +form_widget_check_get_value_stringify +form_widget_check_new +form_widget_check_set_value_stringify +form_widget_entry_get_type +form_widget_entry_get_value_stringify +form_widget_entry_new +form_widget_entry_set_value_stringify +form_widget_get_type +form_widget_get_value_stringify +form_widget_get_widget +form_widget_label_get_type +form_widget_label_get_value_stringify +form_widget_label_new +form_widget_label_set_value_stringify +form_widget_new +form_widget_set_from_glade +form_widget_set_value_stringify +form_widget_spin_get_type +form_widget_spin_get_value_stringify +form_widget_spin_new +form_widget_spin_set_value_stringify +form_widget_textview_get_type +form_widget_textview_get_value_stringify +form_widget_textview_new +form_widget_textview_set_value_stringify + + +libform:Long_Description +libform:Short_Description +libformfield:Long_Description +libformfield:Short_Description +libformfieldboolean:Long_Description +libformfieldboolean:Short_Description +libformfielddatetime:Long_Description +libformfielddatetime:Short_Description +libformfieldfloat:Long_Description +libformfieldfloat:Short_Description +libformfieldinteger:Long_Description +libformfieldinteger:Short_Description +libformfieldtext:Long_Description +libformfieldtext:Short_Description +libformkey:Long_Description +libformkey:Short_Description +libformwidget:Long_Description +libformwidget:Short_Description +libformwidgetcheck:Long_Description +libformwidgetcheck:Short_Description +libformwidgetentry:Long_Description +libformwidgetentry:Short_Description +libformwidgetlabel:Long_Description +libformwidgetlabel:Short_Description +libformwidgetspin:Long_Description +libformwidgetspin:Short_Description +libformwidgettextview:Short_Description diff --git a/docs/reference/libform.types b/docs/reference/libform.types new file mode 100644 index 0000000..ee162b1 --- /dev/null +++ b/docs/reference/libform.types @@ -0,0 +1,27 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +form_get_type +form_field_get_type +form_field_boolean_get_type +form_field_float_get_type +form_field_integer_get_type +form_field_text_get_type +form_key_get_type +form_widget_get_type +form_widget_check_get_type +form_widget_entry_get_type +form_widget_label_get_type +form_widget_spin_get_type +form_widget_textview_get_type diff --git a/docs/reference/tmpl/libform-unused.sgml b/docs/reference/tmpl/libform-unused.sgml new file mode 100644 index 0000000..ba4290b --- /dev/null +++ b/docs/reference/tmpl/libform-unused.sgml @@ -0,0 +1,19 @@ + + + + + +@form: +@field: +@value: +@Returns: + + + + + + +@form: +@glade: +@Returns: + diff --git a/docs/reference/tmpl/libform.sgml b/docs/reference/tmpl/libform.sgml new file mode 100644 index 0000000..bcdedbb --- /dev/null +++ b/docs/reference/tmpl/libform.sgml @@ -0,0 +1,167 @@ + +Form + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + + + + + + + + + + + + + + + + + +@Returns: + + + + + + + +@Returns: + + + + + + + +@form: +@field: +@Returns: + + + + + + + +@form: +@field: +@Returns: + + + + + + + +@form: +@Returns: + + + + + + + +@form: +@Returns: + + + + + + + +@FORM_SQL_SELECT: +@FORM_SQL_INSERT: +@FORM_SQL_UPDATE: +@FORM_SQL_DELETE: + + + + + + +@form: +@type: +@Returns: + + + + + + + +@form: +@dm: +@row: +@Returns: + + diff --git a/docs/reference/tmpl/libformfield.sgml b/docs/reference/tmpl/libformfield.sgml new file mode 100644 index 0000000..4845e18 --- /dev/null +++ b/docs/reference/tmpl/libformfield.sgml @@ -0,0 +1,177 @@ + +FormField + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@Returns: + + + + + + + +@Returns: + + + + + + + +@fwidget: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@dm: +@row: +@Returns: + + diff --git a/docs/reference/tmpl/libformfieldboolean.sgml b/docs/reference/tmpl/libformfieldboolean.sgml new file mode 100644 index 0000000..96a81c4 --- /dev/null +++ b/docs/reference/tmpl/libformfieldboolean.sgml @@ -0,0 +1,149 @@ + +FormFieldBoolean + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + + + + + + + + + + + + +@Returns: + + + + + + + +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@dm: +@row: +@Returns: + + diff --git a/docs/reference/tmpl/libformfielddatetime.sgml b/docs/reference/tmpl/libformfielddatetime.sgml new file mode 100644 index 0000000..4d96d18 --- /dev/null +++ b/docs/reference/tmpl/libformfielddatetime.sgml @@ -0,0 +1,145 @@ + +FormFieldDateTime + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + +@parent: + + + + + + +@Returns: + + + + + + + +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@dm: +@row: +@Returns: + + diff --git a/docs/reference/tmpl/libformfieldfloat.sgml b/docs/reference/tmpl/libformfieldfloat.sgml new file mode 100644 index 0000000..3016dc1 --- /dev/null +++ b/docs/reference/tmpl/libformfieldfloat.sgml @@ -0,0 +1,149 @@ + +FormFieldFloat + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + + + + + + + + + + + + +@Returns: + + + + + + + +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@dm: +@row: +@Returns: + + diff --git a/docs/reference/tmpl/libformfieldinteger.sgml b/docs/reference/tmpl/libformfieldinteger.sgml new file mode 100644 index 0000000..1e91a9f --- /dev/null +++ b/docs/reference/tmpl/libformfieldinteger.sgml @@ -0,0 +1,149 @@ + +FormFieldInteger + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + + + + + + + + + + + + +@Returns: + + + + + + + +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@dm: +@row: +@Returns: + + diff --git a/docs/reference/tmpl/libformfieldtext.sgml b/docs/reference/tmpl/libformfieldtext.sgml new file mode 100644 index 0000000..c4d8965 --- /dev/null +++ b/docs/reference/tmpl/libformfieldtext.sgml @@ -0,0 +1,149 @@ + +FormFieldText + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + + + + + + + + + + + + +@Returns: + + + + + + + +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@Returns: + + + + + + + +@field: +@dm: +@row: +@Returns: + + diff --git a/docs/reference/tmpl/libformkey.sgml b/docs/reference/tmpl/libformkey.sgml new file mode 100644 index 0000000..2683c34 --- /dev/null +++ b/docs/reference/tmpl/libformkey.sgml @@ -0,0 +1,136 @@ + +FormKey + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + + + + + + + +@Returns: + + + + + + + +@Returns: + + + + + + + +@form_key: +@field: +@Returns: + + + + + + + +@form_key: +@field: +@Returns: + + + + + + + +@form_key: +@Returns: + + + + + + + +@form_key: +@Returns: + + + + + + + +@form_key: +@field: +@Returns: + + diff --git a/docs/reference/tmpl/libformwidget.sgml b/docs/reference/tmpl/libformwidget.sgml new file mode 100644 index 0000000..0aa68ab --- /dev/null +++ b/docs/reference/tmpl/libformwidget.sgml @@ -0,0 +1,137 @@ + +FormWidget + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + + + + + + + + + + + + + + + + + +@Returns: + + + + + + + +@Returns: + + + + + + + +@fwidget: +@glade: +@widget_name: +@Returns: + + + + + + + +@fwidget: +@Returns: + + + + + + + +@fwidget: +@Returns: + + + + + + + +@fwidget: +@value: +@Returns: + + diff --git a/docs/reference/tmpl/libformwidgetcheck.sgml b/docs/reference/tmpl/libformwidgetcheck.sgml new file mode 100644 index 0000000..2f31241 --- /dev/null +++ b/docs/reference/tmpl/libformwidgetcheck.sgml @@ -0,0 +1,107 @@ + +FormWidgetCheck + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + + + + + + + +@Returns: + + + + + + + +@Returns: + + + + + + + +@widget: +@Returns: + + + + + + + +@fwidget: +@value: +@Returns: + + diff --git a/docs/reference/tmpl/libformwidgetentry.sgml b/docs/reference/tmpl/libformwidgetentry.sgml new file mode 100644 index 0000000..8ddb267 --- /dev/null +++ b/docs/reference/tmpl/libformwidgetentry.sgml @@ -0,0 +1,107 @@ + +FormWidgetEntry + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + + + + + + + +@Returns: + + + + + + + +@Returns: + + + + + + + +@widget: +@Returns: + + + + + + + +@fwidget: +@value: +@Returns: + + diff --git a/docs/reference/tmpl/libformwidgetlabel.sgml b/docs/reference/tmpl/libformwidgetlabel.sgml new file mode 100644 index 0000000..a9dfbfc --- /dev/null +++ b/docs/reference/tmpl/libformwidgetlabel.sgml @@ -0,0 +1,107 @@ + +FormWidgetLabel + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + + + + + + + +@Returns: + + + + + + + +@Returns: + + + + + + + +@widget: +@Returns: + + + + + + + +@fwidget: +@value: +@Returns: + + diff --git a/docs/reference/tmpl/libformwidgetspin.sgml b/docs/reference/tmpl/libformwidgetspin.sgml new file mode 100644 index 0000000..4327007 --- /dev/null +++ b/docs/reference/tmpl/libformwidgetspin.sgml @@ -0,0 +1,107 @@ + +FormWidgetSpin + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + + + + + + + +@Returns: + + + + + + + +@Returns: + + + + + + + +@widget: +@Returns: + + + + + + + +@fwidget: +@value: +@Returns: + + diff --git a/docs/reference/tmpl/libformwidgettextview.sgml b/docs/reference/tmpl/libformwidgettextview.sgml new file mode 100644 index 0000000..a743b74 --- /dev/null +++ b/docs/reference/tmpl/libformwidgettextview.sgml @@ -0,0 +1,107 @@ + +FormWidgetTextview + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + +@klass: + + + + + + + +@obj: + + + + + + + + + + + + + +@Returns: + + + + + + + +@Returns: + + + + + + + +@widget: +@Returns: + + + + + + + +@fwidget: +@value: +@Returns: + + diff --git a/docs/reference/version.xml.in b/docs/reference/version.xml.in new file mode 100644 index 0000000..a24f987 --- /dev/null +++ b/docs/reference/version.xml.in @@ -0,0 +1 @@ +@PACKAGE_VERSION@ diff --git a/libform.pc.in b/libform.pc.in new file mode 100644 index 0000000..a001c56 --- /dev/null +++ b/libform.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: @PACKAGE_NAME@ +Description: Class for forms +Version: @PACKAGE_VERSION@ +Requires: gtk+-2.0, libglade-2.0, libgdaobj +Libs: -L${libdir} -lform +Cflags: -I${includedir}/libform diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..b2a4d67 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,39 @@ +LIBS = $(FORM_LIBS) + +AM_CPPFLAGS = $(FORM_CFLAGS) + +lib_LTLIBRARIES = libform.la + +libform_la_SOURCES = form.c \ + formkey.c \ + field.c \ + fieldtext.c \ + fieldinteger.c \ + fieldfloat.c \ + fieldboolean.c \ + fielddatetime.c \ + widget.c \ + widgetlabel.c \ + widgetentry.c \ + widgettextview.c \ + widgetspin.c \ + widgetcheck.c + +libform_la_LDFLAGS = -no-undefined + +libform_include_HEADERS = libform.h \ + libformkey.h \ + libformfield.h \ + libformfieldtext.h \ + libformfieldinteger.h \ + libformfieldfloat.h \ + libformfieldboolean.h \ + libformfielddatetime.h \ + libformwidget.h \ + libformwidgetlabel.h \ + libformwidgetentry.h \ + libformwidgettextview.h \ + libformwidgetspin.h \ + libformwidgetcheck.h + +libform_includedir = $(includedir)/libform diff --git a/src/field.c b/src/field.c new file mode 100644 index 0000000..08ecb7b --- /dev/null +++ b/src/field.c @@ -0,0 +1,311 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#include + +#include "libformwidget.h" +#include "libformfield.h" + +enum +{ + PROP_0, + PROP_FIELD, + PROP_OBLIGATORY, + PROP_DATAMODEL, + PROP_WIDGET +}; + +static void form_field_class_init (FormFieldClass *klass); +static void form_field_init (FormField *form_field); + +static void form_field_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void form_field_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +#define FORM_FIELD_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_FORM_FIELD, FormFieldPrivate)) + +typedef struct _FormFieldPrivate FormFieldPrivate; +struct _FormFieldPrivate + { + gchar *field; + gboolean is_key; + gboolean obligatory; + + GdaDataModel *dm; + + FormWidget *widget; + }; + + +GType +form_field_get_type (void) +{ + static GType form_field_type = 0; + + if (!form_field_type) + { + static const GTypeInfo form_field_info = + { + sizeof (FormFieldClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) form_field_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FormField), + 0, /* n_preallocs */ + (GInstanceInitFunc) form_field_init, + NULL + }; + + form_field_type = g_type_register_static (G_TYPE_OBJECT, "FormField", + &form_field_info, 0); + } + + return form_field_type; +} + +static void +form_field_class_init (FormFieldClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->set_property = form_field_set_property; + object_class->get_property = form_field_get_property; + + klass->get_value_stringify = NULL; + klass->get_value = NULL; + klass->get_value_sql = NULL; + + g_object_class_install_property (object_class, PROP_FIELD, + g_param_spec_string ("field", + "Field", + "Field's name", + "", + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, PROP_OBLIGATORY, + g_param_spec_boolean ("obligatory", + "Obligatory", + "Whether the field could be empty", + FALSE, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, PROP_WIDGET, + g_param_spec_object ("form-widget", + "FormWidget", + "The FormWidget", + TYPE_FORM_WIDGET, + G_PARAM_READWRITE)); + + g_type_class_add_private (object_class, sizeof (FormFieldPrivate)); +} + +static void +form_field_init (FormField *form_field) +{ +} + +/** + * form_field_new: + * + * Returns: the newly created #FormField. + */ +FormField +*form_field_new () +{ + return g_object_new (TYPE_FORM_FIELD, NULL); +} + +/** + * form_field_new_from_form_widget: + * @fwidget: + * + * Returns: the newly created #FormField. + */ +FormField +*form_field_new_from_form_widget (FormWidget *fwidget) +{ + FormField *f = form_field_new (); + + g_object_set (G_OBJECT (f), + "form-widget", fwidget, + NULL); + + return f; +} + +/** + * form_field_get_field_name: + * @field: + * + */ +const gchar +*form_field_get_field_name (FormField *field) +{ + FormFieldPrivate *priv = FORM_FIELD_GET_PRIVATE (field); + + return (const gchar *)g_strdup (priv->field); +} + +/** + * form_field_get_value_stringify: + * @field: + * + */ +const gchar +*form_field_get_value_stringify (FormField *field) +{ + FORM_FIELD_GET_CLASS (field)->get_value_stringify (field); +} + +/** + * form_field_get_value: + * @field: + * + */ +const GValue +*form_field_get_value (FormField *field) +{ + FORM_FIELD_GET_CLASS (field)->get_value (field); +} + +/** + * form_field_get_value_sql: + * @field: + * + */ +const gchar +*form_field_get_value_sql (FormField *field) +{ + FORM_FIELD_GET_CLASS (field)->get_value_sql (field); +} + +/** + * form_field_clear: + * @field: + * + */ +gboolean +form_field_clear (FormField *field) +{ + FORM_FIELD_GET_CLASS (field)->clear (field); +} + +/** + * form_field_is_empty: + * @field: + * + */ +gboolean +form_field_is_empty (FormField *field) +{ + FORM_FIELD_GET_CLASS (field)->is_empty (field); +} + +/** + * form_field_set_from_datamodel: + * @field: + * @dm: + * @row: + * + */ +gboolean +form_field_set_from_datamodel (FormField *field, GdaDataModel *dm, gint row) +{ + FormFieldPrivate *priv = FORM_FIELD_GET_PRIVATE (field); + + if (priv->field != NULL && strcmp (priv->field, "") != 0) + { + FORM_FIELD_GET_CLASS (field)->set_from_datamodel (field, dm, row); + } +} + +/* PRIVATE */ +static void +form_field_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + FormField *field = (FormField *)object; + + FormFieldPrivate *priv = FORM_FIELD_GET_PRIVATE (field); + + switch (property_id) + { + case PROP_FIELD: + priv->field = g_strstrip (g_value_dup_string (value)); + break; + + case PROP_OBLIGATORY: + priv->obligatory = g_value_get_boolean (value); + break; + + case PROP_DATAMODEL: + priv->dm = g_value_get_pointer (value); + break; + + case PROP_WIDGET: + priv->widget = g_value_get_object (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +form_field_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + FormField *field = (FormField *)object; + + FormFieldPrivate *priv = FORM_FIELD_GET_PRIVATE (field); + + switch (property_id) + { + case PROP_FIELD: + g_value_set_string (value, form_field_get_field_name (field)); + break; + + case PROP_OBLIGATORY: + g_value_set_boolean (value, priv->obligatory); + break; + + case PROP_DATAMODEL: + g_value_set_pointer (value, priv->dm); + break; + + case PROP_WIDGET: + g_value_set_object (value, priv->widget); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} diff --git a/src/fieldboolean.c b/src/fieldboolean.c new file mode 100644 index 0000000..758b3be --- /dev/null +++ b/src/fieldboolean.c @@ -0,0 +1,329 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#include + +#include + +#include "libformwidget.h" +#include "libformfieldboolean.h" + +enum +{ + PROP_0, + PROP_DEFAULT +}; + +static void form_field_boolean_class_init (FormFieldBooleanClass *klass); +static void form_field_boolean_init (FormFieldBoolean *form_field); + +static void form_field_boolean_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void form_field_boolean_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static gboolean form_field_boolean_set_value_stringify (FormField *field, const gchar *value); + +static gboolean check_value (const gchar *value); + +#define FORM_FIELD_BOOLEAN_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_FORM_FIELD_BOOLEAN, FormFieldBooleanPrivate)) + +typedef struct _FormFieldBooleanPrivate FormFieldBooleanPrivate; +struct _FormFieldBooleanPrivate + { + gboolean default_value; + }; + + +GType +form_field_boolean_get_type (void) +{ + static GType form_field_boolean_type = 0; + + if (!form_field_boolean_type) + { + static const GTypeInfo form_field_boolean_info = + { + sizeof (FormFieldBooleanClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) form_field_boolean_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FormFieldBoolean), + 0, /* n_preallocs */ + (GInstanceInitFunc) form_field_boolean_init, + NULL + }; + + form_field_boolean_type = g_type_register_static (TYPE_FORM_FIELD, "FormFieldBoolean", + &form_field_boolean_info, 0); + } + + return form_field_boolean_type; +} + +static void +form_field_boolean_class_init (FormFieldBooleanClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + FormFieldClass *field_class = FORM_FIELD_CLASS (klass); + + object_class->set_property = form_field_boolean_set_property; + object_class->get_property = form_field_boolean_get_property; + + field_class->get_value_stringify = form_field_boolean_get_value_stringify; + field_class->get_value = form_field_boolean_get_value; + field_class->get_value_sql = form_field_boolean_get_value_sql; + field_class->clear = form_field_boolean_clear; + field_class->is_empty = form_field_boolean_is_empty; + field_class->set_from_datamodel = form_field_boolean_set_from_datamodel; + + g_object_class_install_property (object_class, PROP_DEFAULT, + g_param_spec_boolean ("default", + "Default", + "Default value", + FALSE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + + g_type_class_add_private (object_class, sizeof (FormFieldBooleanPrivate)); +} + +static void +form_field_boolean_init (FormFieldBoolean *form_field) +{ +} + +/** + * form_field_boolean_new: + * + * Returns: the newly created #FormFieldBoolean. + */ +FormField +*form_field_boolean_new () +{ + return g_object_new (TYPE_FORM_FIELD_BOOLEAN, NULL); +} + +/** + * form_field_boolean_get_value_stringify: + * @field: + * + */ +const gchar +*form_field_boolean_get_value_stringify (FormField *field) +{ + const gchar *ret = NULL; + + FormWidget *fw; + + g_object_get (field, + "form-widget", &fw, + NULL); + + ret = form_widget_get_value_stringify (fw); + + return ret; +} + +/** + * form_field_boolean_get_value: + * @field: + * + */ +const GValue +*form_field_boolean_get_value (FormField *field) +{ + GValue *ret = g_malloc0 (sizeof (GValue)); + + const gchar *value = form_field_boolean_get_value_stringify (field); + + g_value_init (ret, G_TYPE_BOOLEAN); + g_value_set_boolean (ret, strtol (value, NULL, 10)); + + return (const GValue *)ret; +} + +/** + * form_field_boolean_get_value_sql: + * @field: + * + */ +const gchar +*form_field_boolean_get_value_sql (FormField *field) +{ + const gchar *ret = NULL; + const gchar *value = form_field_boolean_get_value_stringify (field); + + if (value != NULL) + { + gboolean bool_value; + + bool_value = check_value (value); + + ret = g_strconcat ("'", (bool_value ? "t" : "f"), "'", NULL); + } + + return ret; +} + +/** + * form_field_boolean_clear: + * @field: + * + */ +gboolean +form_field_boolean_clear (FormField *field) +{ + gboolean ret = FALSE; + + FormFieldBooleanPrivate *priv = FORM_FIELD_BOOLEAN_GET_PRIVATE (field); + + ret = form_field_boolean_set_value_stringify (field, g_strdup_printf ("%d", priv->default_value)); + + return ret; +} + +/** + * form_field_boolean_is_empty: + * @field: + * + */ +gboolean +form_field_boolean_is_empty (FormField *field) +{ + gboolean ret = TRUE; + + return ret; +} + +/** + * form_field_boolean_set_from_datamodel: + * @field: + * @dm: + * @row: + * + */ +gboolean +form_field_boolean_set_from_datamodel (FormField *field, GdaDataModel *dm, gint row) +{ + gboolean ret = FALSE; + const gchar *field_name = form_field_get_field_name (field); + + if (dm != NULL) + { + gchar *value; + + value = g_strdup_printf ("%d", gdao_data_model_get_field_value_boolean_at (dm, row, field_name)); + ret = form_field_boolean_set_value_stringify (field, value); + } + + return ret; +} + +/* PRIVATE */ +static void +form_field_boolean_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + FormFieldBoolean *field = (FormFieldBoolean *)object; + + FormFieldBooleanPrivate *priv = FORM_FIELD_BOOLEAN_GET_PRIVATE (field); + + switch (property_id) + { + case PROP_DEFAULT: + priv->default_value = g_value_get_boolean (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +form_field_boolean_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + FormFieldBoolean *field = (FormFieldBoolean *)object; + + FormFieldBooleanPrivate *priv = FORM_FIELD_BOOLEAN_GET_PRIVATE (field); + + switch (property_id) + { + case PROP_DEFAULT: + g_value_set_boolean (value, priv->default_value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static gboolean +form_field_boolean_set_value_stringify (FormField *field, const gchar *value) +{ + gboolean ret = FALSE; + FormWidget *fw; + + g_object_get (field, + "form-widget", &fw, + NULL); + + ret = form_widget_set_value_stringify (fw, value); + + return ret; +} + +static gboolean +check_value (const gchar *value) +{ + gchar *str_value; + gboolean bool_value = FALSE; + + str_value = g_strstrip (g_strdup (value)); + + if (strcmp (str_value, "0") == 0 + || strcasecmp (str_value, "f") == 0 + || strcasecmp (str_value, "false") == 0 + || strcasecmp (str_value, "n") == 0 + || strcasecmp (str_value, "no") == 0) + { + bool_value = FALSE; + } + else if (strcmp (str_value, "1") == 0 + || strcasecmp (str_value, "t") == 0 + || strcasecmp (str_value, "true") == 0 + || strcasecmp (str_value, "y") == 0 + || strcasecmp (str_value, "yes") == 0) + { + bool_value = TRUE; + } + + return bool_value; +} diff --git a/src/fielddatetime.c b/src/fielddatetime.c new file mode 100644 index 0000000..68f6648 --- /dev/null +++ b/src/fielddatetime.c @@ -0,0 +1,319 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#include +#include + +#include + +#include "libformwidget.h" +#include "libformfielddatetime.h" + +enum +{ + PROP_0, + PROP_DEFAULT +}; + +static void form_field_datetime_class_init (FormFieldDateTimeClass *klass); +static void form_field_datetime_init (FormFieldDateTime *form_field); + +static void form_field_datetime_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void form_field_datetime_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static gboolean form_field_datetime_set_value_stringify (FormField *field, const gchar *value); + +#define FORM_FIELD_DATETIME_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_FORM_FIELD_DATETIME, FormFieldDateTimePrivate)) + +typedef struct _FormFieldDateTimePrivate FormFieldDateTimePrivate; +struct _FormFieldDateTimePrivate + { + struct tm *default_value; + }; + + +GType +form_field_datetime_get_type (void) +{ + static GType form_field_datetime_type = 0; + + if (!form_field_datetime_type) + { + static const GTypeInfo form_field_datetime_info = + { + sizeof (FormFieldDateTimeClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) form_field_datetime_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FormFieldDateTime), + 0, /* n_preallocs */ + (GInstanceInitFunc) form_field_datetime_init, + NULL + }; + + form_field_datetime_type = g_type_register_static (TYPE_FORM_FIELD, "FormFieldDateTime", + &form_field_datetime_info, 0); + } + + return form_field_datetime_type; +} + +static void +form_field_datetime_class_init (FormFieldDateTimeClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + FormFieldClass *field_class = FORM_FIELD_CLASS (klass); + + object_class->set_property = form_field_datetime_set_property; + object_class->get_property = form_field_datetime_get_property; + + field_class->get_value_stringify = form_field_datetime_get_value_stringify; + field_class->get_value = form_field_datetime_get_value; + field_class->get_value_sql = form_field_datetime_get_value_sql; + field_class->clear = form_field_datetime_clear; + field_class->is_empty = form_field_datetime_is_empty; + field_class->set_from_datamodel = form_field_datetime_set_from_datamodel; + + g_object_class_install_property (object_class, PROP_DEFAULT, + g_param_spec_pointer ("default", + "Default", + "Default value", + G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + + g_type_class_add_private (object_class, sizeof (FormFieldDateTimePrivate)); +} + +static void +form_field_datetime_init (FormFieldDateTime *form_field) +{ +} + +/** + * form_field_datetime_new: + * + * Returns: the newly created #FormFieldDateTime. + */ +FormField +*form_field_datetime_new () +{ + return g_object_new (TYPE_FORM_FIELD_DATETIME, NULL); +} + +/** + * form_field_datetime_get_value_stringify: + * @field: + * + */ +const gchar +*form_field_datetime_get_value_stringify (FormField *field) +{ + const gchar *ret = NULL; + + FormWidget *fw; + + g_object_get (field, + "form-widget", &fw, + NULL); + + ret = form_widget_get_value_stringify (fw); + + return ret; +} + +/** + * form_field_datetime_get_value: + * @field: + * + */ +const GValue +*form_field_datetime_get_value (FormField *field) +{ + struct tm datetime; + GValue *ret = g_malloc0 (sizeof (GValue)); + + const gchar *value = form_field_datetime_get_value_stringify (field); + + if (strptime (value, "%F %T", &datetime) != NULL) + { + g_value_init (ret, G_TYPE_POINTER); + g_value_set_pointer (ret, &datetime); + } + + return (const GValue *)ret; +} + +/** + * form_field_datetime_get_value_sql: + * @field: + * + */ +const gchar +*form_field_datetime_get_value_sql (FormField *field) +{ + const gchar *ret = NULL; + const gchar *value = form_field_datetime_get_value_stringify (field); + + if (value != NULL) + { + struct tm datetime; + + if (strptime (value, "%F %T", &datetime) != NULL) + { + char *buf; + + buf = malloc (100); + + if (strftime (buf, 100, "%F %T", &datetime) != 0) + { + ret = g_strconcat ("'", buf, "'", NULL); + } + } + } + + return ret; +} + +/** + * form_field_datetime_clear: + * @field: + * + */ +gboolean +form_field_datetime_clear (FormField *field) +{ + gboolean ret = FALSE; + + FormFieldDateTimePrivate *priv = FORM_FIELD_DATETIME_GET_PRIVATE (field); + + if (priv->default_value != NULL) + { + char *buf; + + buf = malloc (100); + + if (strftime (buf, 100, "%F %T", priv->default_value) != NULL) + { + ret = form_field_datetime_set_value_stringify (field, buf); + } + } + + return ret; +} + +/** + * form_field_datetime_is_empty: + * @field: + * + */ +gboolean +form_field_datetime_is_empty (FormField *field) +{ + gboolean ret = TRUE; + + return ret; +} + +/** + * form_field_datetime_set_from_datamodel: + * @field: + * @dm: + * @row: + * + */ +gboolean +form_field_datetime_set_from_datamodel (FormField *field, GdaDataModel *dm, gint row) +{ + gboolean ret = FALSE; + const gchar *field_name = form_field_get_field_name (field); + + if (dm != NULL) + { + ret = form_field_datetime_set_value_stringify (field, + gdao_data_model_get_field_value_stringify_at (dm, row, field_name)); + } + + return ret; +} + +/* PRIVATE */ +static void +form_field_datetime_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + FormFieldDateTime *field = (FormFieldDateTime *)object; + + FormFieldDateTimePrivate *priv = FORM_FIELD_DATETIME_GET_PRIVATE (field); + + switch (property_id) + { + case PROP_DEFAULT: + priv->default_value = g_value_get_pointer (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +form_field_datetime_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + FormFieldDateTime *field = (FormFieldDateTime *)object; + + FormFieldDateTimePrivate *priv = FORM_FIELD_DATETIME_GET_PRIVATE (field); + + switch (property_id) + { + case PROP_DEFAULT: + g_value_set_pointer (value, priv->default_value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static gboolean +form_field_datetime_set_value_stringify (FormField *field, const gchar *value) +{ + gboolean ret = FALSE; + FormWidget *fw; + + g_object_get (field, + "form-widget", &fw, + NULL); + + ret = form_widget_set_value_stringify (fw, value); + + return ret; +} diff --git a/src/fieldfloat.c b/src/fieldfloat.c new file mode 100644 index 0000000..f4f77fc --- /dev/null +++ b/src/fieldfloat.c @@ -0,0 +1,310 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#include + +#include + +#include + +#include "libformwidget.h" +#include "libformfieldfloat.h" + +enum +{ + PROP_0, + PROP_DEFAULT +}; + +static void form_field_float_class_init (FormFieldFloatClass *klass); +static void form_field_float_init (FormFieldFloat *form_field); + +static void form_field_float_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void form_field_float_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static gboolean form_field_float_set_value_stringify (FormField *field, const gchar *value); + +#define FORM_FIELD_FLOAT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_FORM_FIELD_FLOAT, FormFieldFloatPrivate)) + +typedef struct _FormFieldFloatPrivate FormFieldFloatPrivate; +struct _FormFieldFloatPrivate + { + gfloat default_value; + }; + + +GType +form_field_float_get_type (void) +{ + static GType form_field_float_type = 0; + + if (!form_field_float_type) + { + static const GTypeInfo form_field_float_info = + { + sizeof (FormFieldFloatClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) form_field_float_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FormFieldFloat), + 0, /* n_preallocs */ + (GInstanceInitFunc) form_field_float_init, + NULL + }; + + form_field_float_type = g_type_register_static (TYPE_FORM_FIELD, "FormFieldFloat", + &form_field_float_info, 0); + } + + return form_field_float_type; +} + +static void +form_field_float_class_init (FormFieldFloatClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + FormFieldClass *field_class = FORM_FIELD_CLASS (klass); + + object_class->set_property = form_field_float_set_property; + object_class->get_property = form_field_float_get_property; + + field_class->get_value_stringify = form_field_float_get_value_stringify; + field_class->get_value = form_field_float_get_value; + field_class->get_value_sql = form_field_float_get_value_sql; + field_class->clear = form_field_float_clear; + field_class->is_empty = form_field_float_is_empty; + field_class->set_from_datamodel = form_field_float_set_from_datamodel; + + g_object_class_install_property (object_class, PROP_DEFAULT, + g_param_spec_float ("default", + "Default", + "Default value", + -G_MAXFLOAT, G_MAXFLOAT, 0.0f, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + + g_type_class_add_private (object_class, sizeof (FormFieldFloatPrivate)); +} + +static void +form_field_float_init (FormFieldFloat *form_field) +{ +} + +/** + * form_field_float_new: + * + * Returns: the newly created #FormFieldFloat. + */ +FormField +*form_field_float_new () +{ + return g_object_new (TYPE_FORM_FIELD_FLOAT, NULL); +} + +/** + * form_field_float_get_value_stringify: + * @field: + * + */ +const gchar +*form_field_float_get_value_stringify (FormField *field) +{ + const gchar *ret = NULL; + + FormWidget *fw; + + g_object_get (field, + "form-widget", &fw, + NULL); + + ret = g_strdup_printf ("%f", strtod (form_widget_get_value_stringify (fw), NULL)); + + return ret; +} + +/** + * form_field_float_get_value: + * @field: + * + */ +const GValue +*form_field_float_get_value (FormField *field) +{ + GValue *ret = g_malloc0 (sizeof (GValue)); + + const gchar *value = form_field_float_get_value_stringify (field); + + g_value_init (ret, G_TYPE_FLOAT); + g_value_set_float (ret, strtod (value, NULL)); + + return (const GValue *)ret; +} + +/** + * form_field_float_get_value_sql: + * @field: + * + */ +const gchar +*form_field_float_get_value_sql (FormField *field) +{ + const gchar *ret = NULL; + const gchar *value = form_field_float_get_value_stringify (field); + + if (value != NULL) + { + char *cur = setlocale (LC_NUMERIC, NULL); + gfloat fval = strtod (value, NULL); + + setlocale (LC_NUMERIC, "C"); + + ret = g_strdup_printf ("%f", fval); + + setlocale (LC_NUMERIC, cur); + } + + return ret; +} + +/** + * form_field_float_clear: + * @field: + * + */ +gboolean +form_field_float_clear (FormField *field) +{ + gboolean ret = FALSE; + + FormFieldFloatPrivate *priv = FORM_FIELD_FLOAT_GET_PRIVATE (field); + + ret = form_field_float_set_value_stringify (field, g_strdup_printf ("%f", priv->default_value)); + + return ret; +} + +/** + * form_field_float_is_empty: + * @field: + * + */ +gboolean +form_field_float_is_empty (FormField *field) +{ + gboolean ret = TRUE; + const gchar *value; + + value = form_field_float_get_value_stringify (field); + + if (strtod (value, NULL) == 0.0f) + { + ret = FALSE; + } + + return ret; +} + +/** + * form_field_float_set_from_datamodel: + * @field: + * @dm: + * @row: + * + */ +gboolean +form_field_float_set_from_datamodel (FormField *field, GdaDataModel *dm, gint row) +{ + gboolean ret = FALSE; + const gchar *field_name = form_field_get_field_name (field); + + if (dm != NULL) + { + ret = form_field_float_set_value_stringify (field, + gdao_data_model_get_field_value_stringify_at (dm, row, field_name)); + } + + return ret; +} + +/* PRIVATE */ +static void +form_field_float_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + FormFieldFloat *field = (FormFieldFloat *)object; + + FormFieldFloatPrivate *priv = FORM_FIELD_FLOAT_GET_PRIVATE (field); + + switch (property_id) + { + case PROP_DEFAULT: + priv->default_value = g_value_get_float (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +form_field_float_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + FormFieldFloat *field = (FormFieldFloat *)object; + + FormFieldFloatPrivate *priv = FORM_FIELD_FLOAT_GET_PRIVATE (field); + + switch (property_id) + { + case PROP_DEFAULT: + g_value_set_float (value, priv->default_value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static gboolean +form_field_float_set_value_stringify (FormField *field, const gchar *value) +{ + gboolean ret = FALSE; + FormWidget *fw; + + g_object_get (field, + "form-widget", &fw, + NULL); + + ret = form_widget_set_value_stringify (fw, value); + + return ret; +} diff --git a/src/fieldinteger.c b/src/fieldinteger.c new file mode 100644 index 0000000..5beaffb --- /dev/null +++ b/src/fieldinteger.c @@ -0,0 +1,301 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#include + +#include + +#include "libformwidget.h" +#include "libformfieldinteger.h" + +enum +{ + PROP_0, + PROP_DEFAULT +}; + +static void form_field_integer_class_init (FormFieldIntegerClass *klass); +static void form_field_integer_init (FormFieldInteger *form_field); + +static void form_field_integer_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void form_field_integer_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static gboolean form_field_integer_set_value_stringify (FormField *field, const gchar *value); + +#define FORM_FIELD_INTEGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_FORM_FIELD_INTEGER, FormFieldIntegerPrivate)) + +typedef struct _FormFieldIntegerPrivate FormFieldIntegerPrivate; +struct _FormFieldIntegerPrivate + { + gint default_value; + }; + + +GType +form_field_integer_get_type (void) +{ + static GType form_field_integer_type = 0; + + if (!form_field_integer_type) + { + static const GTypeInfo form_field_integer_info = + { + sizeof (FormFieldIntegerClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) form_field_integer_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FormFieldInteger), + 0, /* n_preallocs */ + (GInstanceInitFunc) form_field_integer_init, + NULL + }; + + form_field_integer_type = g_type_register_static (TYPE_FORM_FIELD, "FormFieldInteger", + &form_field_integer_info, 0); + } + + return form_field_integer_type; +} + +static void +form_field_integer_class_init (FormFieldIntegerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + FormFieldClass *field_class = FORM_FIELD_CLASS (klass); + + object_class->set_property = form_field_integer_set_property; + object_class->get_property = form_field_integer_get_property; + + field_class->get_value_stringify = form_field_integer_get_value_stringify; + field_class->get_value = form_field_integer_get_value; + field_class->get_value_sql = form_field_integer_get_value_sql; + field_class->clear = form_field_integer_clear; + field_class->is_empty = form_field_integer_is_empty; + field_class->set_from_datamodel = form_field_integer_set_from_datamodel; + + g_object_class_install_property (object_class, PROP_DEFAULT, + g_param_spec_int ("default", + "Default", + "Default value", + G_MININT, G_MAXINT, 0, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + + g_type_class_add_private (object_class, sizeof (FormFieldIntegerPrivate)); +} + +static void +form_field_integer_init (FormFieldInteger *form_field) +{ +} + +/** + * form_field_integer_new: + * + * Returns: the newly created #FormFieldInteger. + */ +FormField +*form_field_integer_new () +{ + return g_object_new (TYPE_FORM_FIELD_INTEGER, NULL); +} + +/** + * form_field_integer_get_value_stringify: + * @field: + * + */ +const gchar +*form_field_integer_get_value_stringify (FormField *field) +{ + const gchar *ret = NULL; + + FormWidget *fw; + + g_object_get (field, + "form-widget", &fw, + NULL); + + ret = g_strdup_printf ("%d", strtol (form_widget_get_value_stringify (fw), NULL, 10)); + + return ret; +} + +/** + * form_field_integer_get_value: + * @field: + * + */ +const GValue +*form_field_integer_get_value (FormField *field) +{ + GValue *ret = g_malloc0 (sizeof (GValue)); + + const gchar *value = form_field_integer_get_value_stringify (field); + + g_value_init (ret, G_TYPE_INT); + g_value_set_int (ret, atol (value)); + + return (const GValue *)ret; +} + +/** + * form_field_integer_get_value_sql: + * @field: + * + */ +const gchar +*form_field_integer_get_value_sql (FormField *field) +{ + const gchar *ret = NULL; + const gchar *value = form_field_integer_get_value_stringify (field); + + if (value != NULL) + { + ret = value; + } + + return ret; +} + +/** + * form_field_integer_clear: + * @field: + * + */ +gboolean +form_field_integer_clear (FormField *field) +{ + gboolean ret = FALSE; + + FormFieldIntegerPrivate *priv = FORM_FIELD_INTEGER_GET_PRIVATE (field); + + ret = form_field_integer_set_value_stringify (field, g_strdup_printf ("%d", priv->default_value)); + + return ret; +} + +/** + * form_field_integer_is_empty: + * @field: + * + */ +gboolean +form_field_integer_is_empty (FormField *field) +{ + gboolean ret = TRUE; + const gchar *value; + + value = form_field_integer_get_value_stringify (field); + + if (strtol (value, NULL, 10) == 0) + { + ret = FALSE; + } + + return ret; +} + +/** + * form_field_integer_set_from_datamodel: + * @field: + * @dm: + * @row: + * + */ +gboolean +form_field_integer_set_from_datamodel (FormField *field, GdaDataModel *dm, gint row) +{ + gboolean ret = FALSE; + const gchar *field_name = form_field_get_field_name (field); + + if (dm != NULL) + { + ret = form_field_integer_set_value_stringify (field, + gdao_data_model_get_field_value_stringify_at (dm, row, field_name)); + } + + return ret; +} + +/* PRIVATE */ +static void +form_field_integer_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + FormFieldInteger *field = (FormFieldInteger *)object; + + FormFieldIntegerPrivate *priv = FORM_FIELD_INTEGER_GET_PRIVATE (field); + + switch (property_id) + { + case PROP_DEFAULT: + priv->default_value = g_value_get_int (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +form_field_integer_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + FormFieldInteger *field = (FormFieldInteger *)object; + + FormFieldIntegerPrivate *priv = FORM_FIELD_INTEGER_GET_PRIVATE (field); + + switch (property_id) + { + case PROP_DEFAULT: + g_value_set_int (value, priv->default_value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static gboolean +form_field_integer_set_value_stringify (FormField *field, const gchar *value) +{ + gboolean ret = FALSE; + FormWidget *fw; + + g_object_get (field, + "form-widget", &fw, + NULL); + + ret = form_widget_set_value_stringify (fw, value); + + return ret; +} diff --git a/src/fieldtext.c b/src/fieldtext.c new file mode 100644 index 0000000..774e094 --- /dev/null +++ b/src/fieldtext.c @@ -0,0 +1,301 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#include + +#include + +#include "libformwidget.h" +#include "libformfieldtext.h" + +enum +{ + PROP_0, + PROP_DEFAULT +}; + +static void form_field_text_class_init (FormFieldTextClass *klass); +static void form_field_text_init (FormFieldText *form_field); + +static void form_field_text_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void form_field_text_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static gboolean form_field_text_set_value_stringify (FormField *field, const gchar *value); + +#define FORM_FIELD_TEXT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_FORM_FIELD_TEXT, FormFieldTextPrivate)) + +typedef struct _FormFieldTextPrivate FormFieldTextPrivate; +struct _FormFieldTextPrivate + { + gchar *default_value; + }; + + +GType +form_field_text_get_type (void) +{ + static GType form_field_text_type = 0; + + if (!form_field_text_type) + { + static const GTypeInfo form_field_text_info = + { + sizeof (FormFieldTextClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) form_field_text_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FormFieldText), + 0, /* n_preallocs */ + (GInstanceInitFunc) form_field_text_init, + NULL + }; + + form_field_text_type = g_type_register_static (TYPE_FORM_FIELD, "FormFieldText", + &form_field_text_info, 0); + } + + return form_field_text_type; +} + +static void +form_field_text_class_init (FormFieldTextClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + FormFieldClass *field_class = FORM_FIELD_CLASS (klass); + + object_class->set_property = form_field_text_set_property; + object_class->get_property = form_field_text_get_property; + + field_class->get_value_stringify = form_field_text_get_value_stringify; + field_class->get_value = form_field_text_get_value; + field_class->get_value_sql = form_field_text_get_value_sql; + field_class->clear = form_field_text_clear; + field_class->is_empty = form_field_text_is_empty; + field_class->set_from_datamodel = form_field_text_set_from_datamodel; + + g_object_class_install_property (object_class, PROP_DEFAULT, + g_param_spec_string ("default", + "Default", + "Default value", + "", + G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + + g_type_class_add_private (object_class, sizeof (FormFieldTextPrivate)); +} + +static void +form_field_text_init (FormFieldText *form_field) +{ +} + +/** + * form_field_text_new: + * + * Returns: the newly created #FormFieldText. + */ +FormField +*form_field_text_new () +{ + return g_object_new (TYPE_FORM_FIELD_TEXT, NULL); +} + +/** + * form_field_text_get_value_stringify: + * @field: + * + */ +const gchar +*form_field_text_get_value_stringify (FormField *field) +{ + const gchar *ret = NULL; + + FormWidget *fw; + + g_object_get (field, + "form-widget", &fw, + NULL); + + ret = form_widget_get_value_stringify (fw); + + return ret; +} + +/** + * form_field_text_get_value: + * @field: + * + */ +const GValue +*form_field_text_get_value (FormField *field) +{ + GValue *ret = g_malloc0 (sizeof (GValue)); + + const gchar *value = form_field_text_get_value_stringify (field); + + g_value_init (ret, G_TYPE_STRING); + g_value_set_string (ret, value); + + return (const GValue *)ret; +} + +/** + * form_field_text_get_value_sql: + * @field: + * + */ +const gchar +*form_field_text_get_value_sql (FormField *field) +{ + const gchar *ret = NULL; + const gchar *value = form_field_text_get_value_stringify (field); + + if (value != NULL) + { + ret = g_strconcat ("'", gdao_strescape (value, NULL), "'", NULL); + } + + return ret; +} + +/** + * form_field_text_clear: + * @field: + * + */ +gboolean +form_field_text_clear (FormField *field) +{ + gboolean ret = FALSE; + + FormFieldTextPrivate *priv = FORM_FIELD_TEXT_GET_PRIVATE (field); + + ret = form_field_text_set_value_stringify (field, priv->default_value); + + return ret; +} + +/** + * form_field_text_is_empty: + * @field: + * + */ +gboolean +form_field_text_is_empty (FormField *field) +{ + gboolean ret = TRUE; + const gchar *value; + + value = form_field_text_get_value_stringify (field); + + if (strcmp (value, "") == 0) + { + ret = FALSE; + } + + return ret; +} + +/** + * form_field_text_set_from_datamodel: + * @field: + * @dm: + * @row: + * + */ +gboolean +form_field_text_set_from_datamodel (FormField *field, GdaDataModel *dm, gint row) +{ + gboolean ret = FALSE; + const gchar *field_name = form_field_get_field_name (field); + + if (dm != NULL) + { + ret = form_field_text_set_value_stringify (field, + gdao_data_model_get_field_value_stringify_at (dm, row, field_name)); + } + + return ret; +} + +/* PRIVATE */ +static void +form_field_text_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + FormFieldText *field = (FormFieldText *)object; + + FormFieldTextPrivate *priv = FORM_FIELD_TEXT_GET_PRIVATE (field); + + switch (property_id) + { + case PROP_DEFAULT: + priv->default_value = g_strstrip (g_strdup (g_value_get_string (value))); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +form_field_text_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + FormFieldText *field = (FormFieldText *)object; + + FormFieldTextPrivate *priv = FORM_FIELD_TEXT_GET_PRIVATE (field); + + switch (property_id) + { + case PROP_DEFAULT: + g_value_set_string (value, priv->default_value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static gboolean +form_field_text_set_value_stringify (FormField *field, const gchar *value) +{ + gboolean ret = FALSE; + FormWidget *fw; + + g_object_get (field, + "form-widget", &fw, + NULL); + + ret = form_widget_set_value_stringify (fw, value); + + return ret; +} diff --git a/src/form.c b/src/form.c new file mode 100644 index 0000000..bf10e4c --- /dev/null +++ b/src/form.c @@ -0,0 +1,417 @@ +/* + * Copyright (C) 2005-2006 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 "libform.h" + +enum +{ + PROP_0, + PROP_TABLE, + PROP_KEY +}; + +static void form_class_init (FormClass *class); +static void form_init (Form *form); + +static void form_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void form_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +#define FORM_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_FORM, FormPrivate)) + +typedef struct _FormPrivate FormPrivate; +struct _FormPrivate + { + GList *fields; + + gchar *table; + FormKey *key; + }; + + +GType +form_get_type (void) +{ + static GType form_type = 0; + + if (!form_type) + { + static const GTypeInfo form_info = + { + sizeof (FormClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) form_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (Form), + 0, /* n_preallocs */ + (GInstanceInitFunc) form_init, + NULL + }; + + form_type = g_type_register_static (G_TYPE_OBJECT, "Form", + &form_info, 0); + } + + return form_type; +} + +static void +form_class_init (FormClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + object_class->set_property = form_set_property; + object_class->get_property = form_get_property; + + g_object_class_install_property (object_class, PROP_TABLE, + g_param_spec_string ("table", + "Table", + "Form's table", + "", + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, PROP_KEY, + g_param_spec_object ("key", + "Key", + "Key", + TYPE_FORM_KEY, + G_PARAM_READWRITE)); + + g_type_class_add_private (object_class, sizeof (FormPrivate)); +} + +static void +form_init (Form *form) +{ + FormPrivate *priv = FORM_GET_PRIVATE (form); + + priv->fields = NULL; +} + +/** + * form_new: + * + * Returns: the newly created #Form. + */ +Form +*form_new () +{ + return g_object_new (TYPE_FORM, NULL); +} + +/** + * form_add_field: + * @form: + * @field: + * + */ +gboolean +form_add_field (Form *form, FormField *field) +{ + gboolean ret = FALSE; + + FormPrivate *priv = FORM_GET_PRIVATE (form); + + g_return_val_if_fail (IS_FORM_FIELD (field), FALSE); + + priv->fields = g_list_append (priv->fields, field); + + ret = TRUE; + + return ret; +} + +/** + * form_remove_field: + * @form: + * @field: + * + */ +gboolean +form_remove_field (Form *form, FormField *field) +{ + gboolean ret = FALSE; + + FormPrivate *priv = FORM_GET_PRIVATE (form); + + g_return_val_if_fail (IS_FORM_FIELD (field), FALSE); + + priv->fields = g_list_remove (priv->fields, field); + + ret = TRUE; + + return ret; +} + +/** + * form_clear: + * @form: + * + */ +gboolean +form_clear (Form *form) +{ + FormField *field; + gboolean ret = FALSE; + + FormPrivate *priv = FORM_GET_PRIVATE (form); + + GList *fields = g_list_first (priv->fields); + + while (fields != NULL) + { + field = (FormField *)fields->data; + + form_field_clear (field); + + fields = g_list_next (fields); + } + + ret = TRUE; + + return ret; +} + +/** + * form_check: + * @form: + * + * Returns: TRUE if all obligatory fields are full. + */ +gboolean +form_check (Form *form) +{ + FormField *field; + gboolean ret = TRUE; + gboolean obl = FALSE; + + FormPrivate *priv = FORM_GET_PRIVATE (form); + + GList *fields = g_list_first (priv->fields); + + while (fields != NULL) + { + field = (FormField *)fields->data; + + g_object_get (G_OBJECT (field), + "obligatory", &obl, + NULL); + + if (obl && !form_field_is_empty (field)) + { + ret = FALSE; + break; + } + + fields = g_list_next (fields); + } + + if (ret) + { + ret = form_key_check (priv->key); + } + + return ret; +} + +/** + * form_get_sql: + * @form: + * @type: + * + */ +gchar +*form_get_sql (Form *form, FormSqlType type) +{ + FormField *field; + gchar *sql = ""; + gchar *fields_names = ""; + gchar *values = ""; + const gchar *value; + gchar *where = ""; + const gchar *field_name; + + FormPrivate *priv = FORM_GET_PRIVATE (form); + + GList *fields = g_list_first (priv->fields); + + while (fields != NULL) + { + field = (FormField *)fields->data; + + field_name = form_field_get_field_name (field); + + if (field_name != NULL && strcmp (field_name, "") != 0) + { + switch (type) + { + case FORM_SQL_SELECT: + fields_names = g_strconcat (fields_names, field_name, ", ", NULL); + break; + + case FORM_SQL_INSERT: + value = form_field_get_value_sql (field); + if (value != NULL) + { + fields_names = g_strconcat (fields_names, field_name, ", ", NULL); + values = g_strconcat (values, value, ", ", NULL); + } + break; + + case FORM_SQL_UPDATE: + if (!form_key_field_is_key (priv->key, field)) + { + value = form_field_get_value_sql (field); + if (value != NULL) + { + fields_names = g_strconcat (fields_names, field_name, " = ", value, ", ", NULL); + } + } + break; + } + } + + fields = g_list_next (fields); + } + + if (g_str_has_suffix (fields_names, ", ")) + { + fields_names[strlen (fields_names) - 2] = '\0'; + } + if (g_str_has_suffix (values, ", ")) + { + values[strlen (values) - 2] = '\0'; + } + + switch (type) + { + case FORM_SQL_SELECT: + sql = g_strconcat ("SELECT ", fields_names, " FROM ", priv->table, NULL); + break; + + case FORM_SQL_INSERT: + sql = g_strconcat ("INSERT INTO ", priv->table, " (", fields_names, ") VALUES (", values, ")", NULL); + break; + + case FORM_SQL_UPDATE: + sql = g_strconcat ("UPDATE ", priv->table, " SET ", fields_names, NULL); + break; + + case FORM_SQL_DELETE: + sql = g_strconcat ("DELETE FROM ", priv->table, NULL); + break; + } + + where = form_key_get_sql (priv->key); + if ((type == FORM_SQL_SELECT || type == FORM_SQL_UPDATE || type == FORM_SQL_DELETE) + && where != NULL && strcmp (where, "") != 0) + { + sql = g_strconcat (sql, where, NULL); + } + + return sql; +} + +gboolean +form_fill_from_datamodel (Form *form, GdaDataModel *dm, gint row) +{ + gboolean ret = TRUE; + FormField *field; + gchar *field_name; + + FormPrivate *priv = FORM_GET_PRIVATE (form); + + GList *fields = g_list_first (priv->fields); + + while (fields != NULL) + { + field = (FormField *)fields->data; + + form_field_set_from_datamodel (field, dm, row); + + fields = g_list_next (fields); + } + + return ret; +} + +/* PRIVATE */ +static void +form_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + Form *form = (Form *)object; + + FormPrivate *priv = FORM_GET_PRIVATE (form); + + switch (property_id) + { + case PROP_TABLE: + priv->table = g_strstrip (g_strdup (g_value_get_string (value))); + break; + + case PROP_KEY: + priv->key = g_value_get_object (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +form_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + Form *form = (Form *)object; + + FormPrivate *priv = FORM_GET_PRIVATE (form); + + switch (property_id) + { + case PROP_TABLE: + g_value_set_string (value, priv->table); + break; + + case PROP_KEY: + g_value_set_object (value, priv->key); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} diff --git a/src/formkey.c b/src/formkey.c new file mode 100644 index 0000000..8189c1f --- /dev/null +++ b/src/formkey.c @@ -0,0 +1,223 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#include + +#include "libformkey.h" + +static void form_key_class_init (FormKeyClass *class); +static void form_key_init (FormKey *form_key); + + +#define FORM_KEY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_FORM_KEY, FormKeyPrivate)) + +typedef struct _FormKeyPrivate FormKeyPrivate; +struct _FormKeyPrivate + { + GList *fields; + }; + + +GType +form_key_get_type (void) +{ + static GType form_key_type = 0; + + if (!form_key_type) + { + static const GTypeInfo form_key_info = + { + sizeof (FormKeyClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) form_key_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FormKey), + 0, /* n_preallocs */ + (GInstanceInitFunc) form_key_init, + NULL + }; + + form_key_type = g_type_register_static (G_TYPE_OBJECT, "FormKey", + &form_key_info, 0); + } + + return form_key_type; +} + +static void +form_key_class_init (FormKeyClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + g_type_class_add_private (object_class, sizeof (FormKeyPrivate)); +} + +static void +form_key_init (FormKey *form_key) +{ + FormKeyPrivate *priv = FORM_KEY_GET_PRIVATE (form_key); + + priv->fields = NULL; +} + +/** + * form_key_new: + * + * Returns: the newly created #FormKey. + */ +FormKey +*form_key_new () +{ + return g_object_new (TYPE_FORM_KEY, NULL); +} + +/** + * form_key_add_field: + * @form_key: + * @field: + * + */ +gboolean +form_key_add_field (FormKey *form_key, FormField *field) +{ + gboolean ret = FALSE; + + FormKeyPrivate *priv = FORM_KEY_GET_PRIVATE (form_key); + + g_return_val_if_fail (IS_FORM_FIELD (field), FALSE); + + priv->fields = g_list_append (priv->fields, field); + + ret = TRUE; + + return ret; +} + +/** + * form_key_remove_field: + * @form_key: + * @field: + * + */ +gboolean +form_key_remove_field (FormKey *form_key, FormField *field) +{ + gboolean ret = FALSE; + + FormKeyPrivate *priv = FORM_KEY_GET_PRIVATE (form_key); + + g_return_val_if_fail (IS_FORM_FIELD (field), FALSE); + + priv->fields = g_list_remove (priv->fields, field); + + ret = TRUE; + + return ret; +} + +/** + * form_key_check: + * @form_key: + * + * Returns: TRUE if all obligatory fields are full. + */ +gboolean +form_key_check (FormKey *form_key) +{ + FormField *field; + gboolean ret = FALSE; + + FormKeyPrivate *priv = FORM_KEY_GET_PRIVATE (form_key); + + GList *fields = g_list_first (priv->fields); + + while (fields != NULL) + { + field = (FormField *)fields->data; + + if (form_field_is_empty (field)) + { + ret = TRUE; + break; + } + + fields = g_list_next (fields); + } + + return ret; +} + +/** + * form_key_get_sql: + * @form_key: + * + */ +gchar +*form_key_get_sql (FormKey *form_key) +{ + FormField *field; + gchar *sql = ""; + gchar *field_name; + + g_return_val_if_fail (IS_FORM_KEY (form_key), NULL); + + FormKeyPrivate *priv = FORM_KEY_GET_PRIVATE (form_key); + + GList *fields = g_list_first (priv->fields); + + while (fields != NULL) + { + field = (FormField *)fields->data; + + g_object_get (G_OBJECT (field), + "field", &field_name, + NULL); + + sql = g_strconcat (sql, " AND ", field_name, " = ", + form_field_get_value_sql (field), NULL); + + fields = g_list_next (fields); + } + + if (strcmp (sql, "") != 0) + { + sql = g_strconcat (" WHERE ", g_strdup (sql + 5), NULL); + } + + return sql; +} + +/** + * form_key_field_is_key: + * @form_key: + * @field: + * + * Returns: TRUE if @field is part of @form_key. + */ +gboolean +form_key_field_is_key (FormKey *form_key, FormField *field) +{ + g_return_val_if_fail (IS_FORM_KEY (form_key), FALSE); + g_return_val_if_fail (IS_FORM_FIELD (field), FALSE); + + FormKeyPrivate *priv = FORM_KEY_GET_PRIVATE (form_key); + + return (g_list_index (priv->fields, field) >= 0 ? TRUE : FALSE); +} diff --git a/src/libform.h b/src/libform.h new file mode 100644 index 0000000..9c0f376 --- /dev/null +++ b/src/libform.h @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#ifndef __LIBFORM_H__ +#define __LIBFORM_H__ + +#include +#include + +#include + +#include +#include + + +G_BEGIN_DECLS + + +#define TYPE_FORM (form_get_type ()) +#define FORM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FORM, Form)) +#define FORM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FORM, FormClass)) +#define IS_FORM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FORM)) +#define IS_FORM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FORM)) +#define FORM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FORM, FormClass)) + + +typedef struct _Form Form; +typedef struct _FormClass FormClass; + +struct _Form + { + GObject parent; + }; + +struct _FormClass + { + GObjectClass parent_class; + }; + +GType form_get_type (void) G_GNUC_CONST; + + +Form *form_new (void); + +gboolean form_add_field (Form *form, FormField *field); +gboolean form_remove_field (Form *form, FormField *field); + +gboolean form_clear (Form *form); + +gboolean form_check (Form *form); + +typedef enum +{ + FORM_SQL_SELECT, + FORM_SQL_INSERT, + FORM_SQL_UPDATE, + FORM_SQL_DELETE +} FormSqlType; + +gchar *form_get_sql (Form *form, FormSqlType type); + +gboolean form_fill_from_datamodel (Form *form, GdaDataModel *dm, gint row); + + +G_END_DECLS + + +#endif /* __LIBFORM_H__ */ diff --git a/src/libformfield.h b/src/libformfield.h new file mode 100644 index 0000000..4cc6277 --- /dev/null +++ b/src/libformfield.h @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#ifndef __LIBFORM_FIELD_H__ +#define __LIBFORM_FIELD_H__ + +#include + +#include + +#include + + +G_BEGIN_DECLS + + +#define TYPE_FORM_FIELD (form_field_get_type ()) +#define FORM_FIELD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FORM_FIELD, FormField)) +#define FORM_FIELD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FORM_FIELD, FormFieldClass)) +#define IS_FORM_FIELD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FORM_FIELD)) +#define IS_FORM_FIELD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FORM_FIELD)) +#define FORM_FIELD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FORM_FIELD, FormFieldClass)) + + +typedef struct _FormField FormField; +typedef struct _FormFieldClass FormFieldClass; + +struct _FormField + { + GObject parent; + }; + +struct _FormFieldClass + { + GObjectClass parent_class; + + const gchar *(*get_value_stringify) (FormField *field); + const GValue *(*get_value) (FormField *field); + const gchar *(*get_value_sql) (FormField *field); + + gboolean (*clear) (FormField *field); + gboolean (*is_empty) (FormField *field); + gboolean (*set_from_datamodel) (FormField *field, GdaDataModel *dm, gint row); + }; + +GType form_field_get_type (void) G_GNUC_CONST; + +FormField *form_field_new (void); +FormField *form_field_new_from_form_widget (FormWidget *fwidget); + +const gchar *form_field_get_field_name (FormField *field); + +const gchar *form_field_get_value_stringify (FormField *field); +const GValue *form_field_get_value (FormField *field); +const gchar *form_field_get_value_sql (FormField *field); + +gboolean form_field_clear (FormField *field); + +gboolean form_field_is_empty (FormField *field); + +gboolean form_field_set_from_datamodel (FormField *field, GdaDataModel *dm, gint row); + + +G_END_DECLS + + +#endif /* __LIBFORM_FIELD_H__ */ diff --git a/src/libformfieldboolean.h b/src/libformfieldboolean.h new file mode 100644 index 0000000..a9371ed --- /dev/null +++ b/src/libformfieldboolean.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#ifndef __LIBFORM_FIELD_BOOLEAN_H__ +#define __LIBFORM_FIELD_BOOLEAN_H__ + +#include + +#include + + +G_BEGIN_DECLS + + +#define TYPE_FORM_FIELD_BOOLEAN (form_field_boolean_get_type ()) +#define FORM_FIELD_BOOLEAN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FORM_FIELD_BOOLEAN, FormFieldBoolean)) +#define FORM_FIELD_BOOLEAN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FORM_FIELD_BOOLEAN, FormFieldBooleanClass)) +#define IS_FORM_FIELD_BOOLEAN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FORM_FIELD_BOOLEAN)) +#define IS_FORM_FIELD_BOOLEAN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FORM_FIELD_BOOLEAN)) +#define FORM_FIELD_BOOLEAN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FORM_FIELD_BOOLEAN, FormFieldBooleanClass)) + + +typedef struct _FormFieldBoolean FormFieldBoolean; +typedef struct _FormFieldBooleanClass FormFieldBooleanClass; + +struct _FormFieldBoolean + { + FormField parent; + }; + +struct _FormFieldBooleanClass + { + FormFieldClass parent_class; + }; + +GType form_field_boolean_get_type (void) G_GNUC_CONST; + +FormField *form_field_boolean_new (void); + +const gchar *form_field_boolean_get_value_stringify (FormField *field); +const GValue *form_field_boolean_get_value (FormField *field); +const gchar *form_field_boolean_get_value_sql (FormField *field); + +gboolean form_field_boolean_clear (FormField *field); + +gboolean form_field_boolean_is_empty (FormField *field); + +gboolean form_field_boolean_set_from_datamodel (FormField *field, GdaDataModel *dm, gint row); + + +G_END_DECLS + + +#endif /* __LIBFORM_FIELD_BOOLEAN_H__ */ diff --git a/src/libformfielddatetime.h b/src/libformfielddatetime.h new file mode 100644 index 0000000..8236d6a --- /dev/null +++ b/src/libformfielddatetime.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#ifndef __LIBFORM_FIELD_DATETIME_H__ +#define __LIBFORM_FIELD_DATETIME_H__ + +#include + +#include + + +G_BEGIN_DECLS + + +#define TYPE_FORM_FIELD_DATETIME (form_field_datetime_get_type ()) +#define FORM_FIELD_DATETIME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FORM_FIELD_DATETIME, FormFieldDateTime)) +#define FORM_FIELD_DATETIME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FORM_FIELD_DATETIME, FormFieldDateTimeClass)) +#define IS_FORM_FIELD_DATETIME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FORM_FIELD_DATETIME)) +#define IS_FORM_FIELD_DATETIME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FORM_FIELD_DATETIME)) +#define FORM_FIELD_DATETIME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FORM_FIELD_DATETIME, FormFieldDateTimeClass)) + + +typedef struct _FormFieldDateTime FormFieldDateTime; +typedef struct _FormFieldDateTimeClass FormFieldDateTimeClass; + +struct _FormFieldDateTime + { + FormField parent; + }; + +struct _FormFieldDateTimeClass + { + FormFieldClass parent_class; + }; + +GType form_field_datetime_get_type (void) G_GNUC_CONST; + +FormField *form_field_datetime_new (void); + +const gchar *form_field_datetime_get_value_stringify (FormField *field); +const GValue *form_field_datetime_get_value (FormField *field); +const gchar *form_field_datetime_get_value_sql (FormField *field); + +gboolean form_field_datetime_clear (FormField *field); + +gboolean form_field_datetime_is_empty (FormField *field); + +gboolean form_field_datetime_set_from_datamodel (FormField *field, GdaDataModel *dm, gint row); + + +G_END_DECLS + + +#endif /* __LIBFORM_FIELD_DATETIME_H__ */ diff --git a/src/libformfieldfloat.h b/src/libformfieldfloat.h new file mode 100644 index 0000000..1749ed7 --- /dev/null +++ b/src/libformfieldfloat.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#ifndef __LIBFORM_FIELD_FLOAT_H__ +#define __LIBFORM_FIELD_FLOAT_H__ + +#include + +#include + + +G_BEGIN_DECLS + + +#define TYPE_FORM_FIELD_FLOAT (form_field_float_get_type ()) +#define FORM_FIELD_FLOAT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FORM_FIELD_FLOAT, FormFieldFloat)) +#define FORM_FIELD_FLOAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FORM_FIELD_FLOAT, FormFieldFloatClass)) +#define IS_FORM_FIELD_FLOAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FORM_FIELD_FLOAT)) +#define IS_FORM_FIELD_FLOAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FORM_FIELD_FLOAT)) +#define FORM_FIELD_FLOAT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FORM_FIELD_FLOAT, FormFieldFloatClass)) + + +typedef struct _FormFieldFloat FormFieldFloat; +typedef struct _FormFieldFloatClass FormFieldFloatClass; + +struct _FormFieldFloat + { + FormField parent; + }; + +struct _FormFieldFloatClass + { + FormFieldClass parent_class; + }; + +GType form_field_float_get_type (void) G_GNUC_CONST; + +FormField *form_field_float_new (void); + +const gchar *form_field_float_get_value_stringify (FormField *field); +const GValue *form_field_float_get_value (FormField *field); +const gchar *form_field_float_get_value_sql (FormField *field); + +gboolean form_field_float_clear (FormField *field); + +gboolean form_field_float_is_empty (FormField *field); + +gboolean form_field_float_set_from_datamodel (FormField *field, GdaDataModel *dm, gint row); + + +G_END_DECLS + + +#endif /* __LIBFORM_FIELD_FLOAT_H__ */ diff --git a/src/libformfieldinteger.h b/src/libformfieldinteger.h new file mode 100644 index 0000000..c4ee43b --- /dev/null +++ b/src/libformfieldinteger.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#ifndef __LIBFORM_FIELD_INTEGER_H__ +#define __LIBFORM_FIELD_INTEGER_H__ + +#include + +#include + + +G_BEGIN_DECLS + + +#define TYPE_FORM_FIELD_INTEGER (form_field_integer_get_type ()) +#define FORM_FIELD_INTEGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FORM_FIELD_INTEGER, FormFieldInteger)) +#define FORM_FIELD_INTEGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FORM_FIELD_INTEGER, FormFieldIntegerClass)) +#define IS_FORM_FIELD_INTEGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FORM_FIELD_INTEGER)) +#define IS_FORM_FIELD_INTEGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FORM_FIELD_INTEGER)) +#define FORM_FIELD_INTEGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FORM_FIELD_INTEGER, FormFieldIntegerClass)) + + +typedef struct _FormFieldInteger FormFieldInteger; +typedef struct _FormFieldIntegerClass FormFieldIntegerClass; + +struct _FormFieldInteger + { + FormField parent; + }; + +struct _FormFieldIntegerClass + { + FormFieldClass parent_class; + }; + +GType form_field_integer_get_type (void) G_GNUC_CONST; + +FormField *form_field_integer_new (void); + +const gchar *form_field_integer_get_value_stringify (FormField *field); +const GValue *form_field_integer_get_value (FormField *field); +const gchar *form_field_integer_get_value_sql (FormField *field); + +gboolean form_field_integer_clear (FormField *field); + +gboolean form_field_integer_is_empty (FormField *field); + +gboolean form_field_integer_set_from_datamodel (FormField *field, GdaDataModel *dm, gint row); + + +G_END_DECLS + + +#endif /* __LIBFORM_FIELD_INTEGER_H__ */ diff --git a/src/libformfieldtext.h b/src/libformfieldtext.h new file mode 100644 index 0000000..7f4c26c --- /dev/null +++ b/src/libformfieldtext.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#ifndef __LIBFORM_FIELD_TEXT_H__ +#define __LIBFORM_FIELD_TEXT_H__ + +#include + +#include + + +G_BEGIN_DECLS + + +#define TYPE_FORM_FIELD_TEXT (form_field_text_get_type ()) +#define FORM_FIELD_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FORM_FIELD_TEXT, FormFieldText)) +#define FORM_FIELD_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FORM_FIELD_TEXT, FormFieldTextClass)) +#define IS_FORM_FIELD_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FORM_FIELD_TEXT)) +#define IS_FORM_FIELD_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FORM_FIELD_TEXT)) +#define FORM_FIELD_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FORM_FIELD_TEXT, FormFieldTextClass)) + + +typedef struct _FormFieldText FormFieldText; +typedef struct _FormFieldTextClass FormFieldTextClass; + +struct _FormFieldText + { + FormField parent; + }; + +struct _FormFieldTextClass + { + FormFieldClass parent_class; + }; + +GType form_field_text_get_type (void) G_GNUC_CONST; + +FormField *form_field_text_new (void); + +const gchar *form_field_text_get_value_stringify (FormField *field); +const GValue *form_field_text_get_value (FormField *field); +const gchar *form_field_text_get_value_sql (FormField *field); + +gboolean form_field_text_clear (FormField *field); + +gboolean form_field_text_is_empty (FormField *field); + +gboolean form_field_text_set_from_datamodel (FormField *field, GdaDataModel *dm, gint row); + + +G_END_DECLS + + +#endif /* __LIBFORM_FIELD_TEXT_H__ */ diff --git a/src/libformkey.h b/src/libformkey.h new file mode 100644 index 0000000..816dd10 --- /dev/null +++ b/src/libformkey.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#ifndef __LIBFORM_KEY_H__ +#define __LIBFORM_KEY_H__ + +#include + +#include + + +G_BEGIN_DECLS + + +#define TYPE_FORM_KEY (form_key_get_type ()) +#define FORM_KEY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FORM_KEY, FormKey)) +#define FORM_KEY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FORM_KEY, FormKeyClass)) +#define IS_FORM_KEY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FORM_KEY)) +#define IS_FORM_KEY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FORM_KEY)) +#define FORM_KEY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FORM_KEY, FormKeyClass)) + + +typedef struct _FormKey FormKey; +typedef struct _FormKeyClass FormKeyClass; + +struct _FormKey + { + GObject parent; + }; + +struct _FormKeyClass + { + GObjectClass parent_class; + }; + +GType form_key_get_type (void) G_GNUC_CONST; + + +FormKey *form_key_new (void); + +gboolean form_key_add_field (FormKey *form_key, FormField *field); +gboolean form_key_remove_field (FormKey *form_key, FormField *field); + +gboolean form_key_check (FormKey *form_key); + +gchar *form_key_get_sql (FormKey *form_key); + +gboolean form_key_field_is_key (FormKey *form_key, FormField *field); + + +G_END_DECLS + + +#endif /* __LIBFORM_KEY_H__ */ diff --git a/src/libformwidget.h b/src/libformwidget.h new file mode 100644 index 0000000..e715189 --- /dev/null +++ b/src/libformwidget.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#ifndef __LIBFORM_WIDGET_H__ +#define __LIBFORM_WIDGET_H__ + +#include +#include +#include + + +G_BEGIN_DECLS + + +#define TYPE_FORM_WIDGET (form_widget_get_type ()) +#define FORM_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FORM_WIDGET, FormWidget)) +#define FORM_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FORM_WIDGET, FormWidgetClass)) +#define IS_FORM_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FORM_WIDGET)) +#define IS_FORM_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FORM_WIDGET)) +#define FORM_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FORM_WIDGET, FormWidgetClass)) + + +typedef struct _FormWidget FormWidget; +typedef struct _FormWidgetClass FormWidgetClass; + +struct _FormWidget + { + GObject parent; + }; + +struct _FormWidgetClass + { + GObjectClass parent_class; + + const gchar *(*get_value_stringify) (FormWidget *fwidget); + + gboolean (*set_value_stringify) (FormWidget *fwidget, const gchar *value); + }; + +GType form_widget_get_type (void) G_GNUC_CONST; + +FormWidget *form_widget_new (void); + +gboolean form_widget_set_from_glade (FormWidget *fwidget, GladeXML *glade, const gchar *widget_name); + +GtkWidget *form_widget_get_widget (FormWidget *fwidget); + +const gchar *form_widget_get_value_stringify (FormWidget *fwidget); + +gboolean form_widget_set_value_stringify (FormWidget *fwidget, const gchar *value); + + +G_END_DECLS + + +#endif /* __LIBFORM_WIDGET_H__ */ diff --git a/src/libformwidgetcheck.h b/src/libformwidgetcheck.h new file mode 100644 index 0000000..d0ccb0d --- /dev/null +++ b/src/libformwidgetcheck.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#ifndef __LIBFORM_WIDGET_CHECK_H__ +#define __LIBFORM_WIDGET_CHECK_H__ + +#include + + +G_BEGIN_DECLS + + +#define TYPE_FORM_WIDGET_CHECK (form_widget_check_get_type ()) +#define FORM_WIDGET_CHECK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FORM_WIDGET_CHECK, FormWidgetCheck)) +#define FORM_WIDGET_CHECK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FORM_WIDGET_CHECK, FormWidgetCheckClass)) +#define IS_FORM_WIDGET_CHECK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FORM_WIDGET_CHECK)) +#define IS_FORM_WIDGET_CHECK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FORM_WIDGET_CHECK)) +#define FORM_WIDGET_CHECK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FORM_WIDGET_CHECK, FormWidgetCheckClass)) + + +typedef struct _FormWidgetCheck FormWidgetCheck; +typedef struct _FormWidgetCheckClass FormWidgetCheckClass; + +struct _FormWidgetCheck + { + FormWidget parent; + }; + +struct _FormWidgetCheckClass + { + FormWidgetClass parent_class; + }; + +GType form_widget_check_get_type (void) G_GNUC_CONST; + +FormWidget *form_widget_check_new (void); + +const gchar *form_widget_check_get_value_stringify (FormWidget *widget); + +gboolean form_widget_check_set_value_stringify (FormWidget *fwidget, const gchar *value); + + +G_END_DECLS + + +#endif /* __LIBFORM_WIDGET_CHECK_H__ */ diff --git a/src/libformwidgetentry.h b/src/libformwidgetentry.h new file mode 100644 index 0000000..11d1de3 --- /dev/null +++ b/src/libformwidgetentry.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#ifndef __LIBFORM_WIDGET_ENTRY_H__ +#define __LIBFORM_WIDGET_ENTRY_H__ + +#include + + +G_BEGIN_DECLS + + +#define TYPE_FORM_WIDGET_ENTRY (form_widget_entry_get_type ()) +#define FORM_WIDGET_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FORM_WIDGET_ENTRY, FormWidgetEntry)) +#define FORM_WIDGET_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FORM_WIDGET_ENTRY, FormWidgetEntryClass)) +#define IS_FORM_WIDGET_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FORM_WIDGET_ENTRY)) +#define IS_FORM_WIDGET_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FORM_WIDGET_ENTRY)) +#define FORM_WIDGET_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FORM_WIDGET_ENTRY, FormWidgetEntryClass)) + + +typedef struct _FormWidgetEntry FormWidgetEntry; +typedef struct _FormWidgetEntryClass FormWidgetEntryClass; + +struct _FormWidgetEntry + { + FormWidget parent; + }; + +struct _FormWidgetEntryClass + { + FormWidgetClass parent_class; + }; + +GType form_widget_entry_get_type (void) G_GNUC_CONST; + +FormWidget *form_widget_entry_new (void); + +const gchar *form_widget_entry_get_value_stringify (FormWidget *widget); + +gboolean form_widget_entry_set_value_stringify (FormWidget *fwidget, const gchar *value); + + +G_END_DECLS + + +#endif /* __LIBFORM_WIDGET_ENTRY_H__ */ diff --git a/src/libformwidgetlabel.h b/src/libformwidgetlabel.h new file mode 100644 index 0000000..0ffab9a --- /dev/null +++ b/src/libformwidgetlabel.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#ifndef __LIBFORM_WIDGET_LABEL_H__ +#define __LIBFORM_WIDGET_LABEL_H__ + +#include + + +G_BEGIN_DECLS + + +#define TYPE_FORM_WIDGET_LABEL (form_widget_label_get_type ()) +#define FORM_WIDGET_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FORM_WIDGET_LABEL, FormWidgetLabel)) +#define FORM_WIDGET_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FORM_WIDGET_LABEL, FormWidgetLabelClass)) +#define IS_FORM_WIDGET_LABEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FORM_WIDGET_LABEL)) +#define IS_FORM_WIDGET_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FORM_WIDGET_LABEL)) +#define FORM_WIDGET_LABEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FORM_WIDGET_LABEL, FormWidgetLabelClass)) + + +typedef struct _FormWidgetLabel FormWidgetLabel; +typedef struct _FormWidgetLabelClass FormWidgetLabelClass; + +struct _FormWidgetLabel + { + FormWidget parent; + }; + +struct _FormWidgetLabelClass + { + FormWidgetClass parent_class; + }; + +GType form_widget_label_get_type (void) G_GNUC_CONST; + +FormWidget *form_widget_label_new (void); + +const gchar *form_widget_label_get_value_stringify (FormWidget *widget); + +gboolean form_widget_label_set_value_stringify (FormWidget *fwidget, const gchar *value); + + +G_END_DECLS + + +#endif /* __LIBFORM_WIDGET_LABEL_H__ */ diff --git a/src/libformwidgetspin.h b/src/libformwidgetspin.h new file mode 100644 index 0000000..b58450e --- /dev/null +++ b/src/libformwidgetspin.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#ifndef __LIBFORM_WIDGET_SPIN_H__ +#define __LIBFORM_WIDGET_SPIN_H__ + +#include + + +G_BEGIN_DECLS + + +#define TYPE_FORM_WIDGET_SPIN (form_widget_spin_get_type ()) +#define FORM_WIDGET_SPIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FORM_WIDGET_SPIN, FormWidgetSpin)) +#define FORM_WIDGET_SPIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FORM_WIDGET_SPIN, FormWidgetSpinClass)) +#define IS_FORM_WIDGET_SPIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FORM_WIDGET_SPIN)) +#define IS_FORM_WIDGET_SPIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FORM_WIDGET_SPIN)) +#define FORM_WIDGET_SPIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FORM_WIDGET_SPIN, FormWidgetSpinClass)) + + +typedef struct _FormWidgetSpin FormWidgetSpin; +typedef struct _FormWidgetSpinClass FormWidgetSpinClass; + +struct _FormWidgetSpin + { + FormWidget parent; + }; + +struct _FormWidgetSpinClass + { + FormWidgetClass parent_class; + }; + +GType form_widget_spin_get_type (void) G_GNUC_CONST; + +FormWidget *form_widget_spin_new (void); + +const gchar *form_widget_spin_get_value_stringify (FormWidget *widget); + +gboolean form_widget_spin_set_value_stringify (FormWidget *fwidget, const gchar *value); + + +G_END_DECLS + + +#endif /* __LIBFORM_WIDGET_SPIN_H__ */ diff --git a/src/libformwidgettextview.h b/src/libformwidgettextview.h new file mode 100644 index 0000000..9f9ffe5 --- /dev/null +++ b/src/libformwidgettextview.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#ifndef __LIBFORM_WIDGET_TEXTVIEW_H__ +#define __LIBFORM_WIDGET_TEXTVIEW_H__ + +#include + + +G_BEGIN_DECLS + + +#define TYPE_FORM_WIDGET_TEXTVIEW (form_widget_textview_get_type ()) +#define FORM_WIDGET_TEXTVIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FORM_WIDGET_TEXTVIEW, FormWidgetTextview)) +#define FORM_WIDGET_TEXTVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FORM_WIDGET_TEXTVIEW, FormWidgetTextviewClass)) +#define IS_FORM_WIDGET_TEXTVIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FORM_WIDGET_TEXTVIEW)) +#define IS_FORM_WIDGET_TEXTVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FORM_WIDGET_TEXTVIEW)) +#define FORM_WIDGET_TEXTVIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FORM_WIDGET_TEXTVIEW, FormWidgetTextviewClass)) + + +typedef struct _FormWidgetTextview FormWidgetTextview; +typedef struct _FormWidgetTextviewClass FormWidgetTextviewClass; + +struct _FormWidgetTextview + { + FormWidget parent; + }; + +struct _FormWidgetTextviewClass + { + FormWidgetClass parent_class; + }; + +GType form_widget_textview_get_type (void) G_GNUC_CONST; + +FormWidget *form_widget_textview_new (void); + +const gchar *form_widget_textview_get_value_stringify (FormWidget *widget); + +gboolean form_widget_textview_set_value_stringify (FormWidget *fwidget, const gchar *value); + + +G_END_DECLS + + +#endif /* __LIBFORM_WIDGET_TEXTVIEW_H__ */ diff --git a/src/old/form.c b/src/old/form.c new file mode 100644 index 0000000..6148922 --- /dev/null +++ b/src/old/form.c @@ -0,0 +1,692 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#include +#include + +#include + +#include "libform.h" + +static void form_class_init (FormClass *class); +static void form_init (Form *form); + +static Field *form_get_field (Form *form, const gchar *name); +static gchar *form_field_get_value_sql (Field *f); +static gboolean form_field_check_struct (Field *f); + + +#define FORM_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_FORM, FormPrivate)) + +typedef struct _FormPrivate FormPrivate; +struct _FormPrivate + { + GList fields; + GladeXML *glade; + + struct lconv *loc; + }; + + +GType +form_get_type (void) +{ + static GType form_type = 0; + + if (!form_type) + { + static const GTypeInfo form_info = + { + sizeof (FormClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) form_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (Form), + 0, /* n_preallocs */ + (GInstanceInitFunc) form_init, + NULL + }; + + form_type = g_type_register_static (G_TYPE_OBJECT, "Form", + &form_info, 0); + } + + return form_type; +} + +static void +form_class_init (FormClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + g_type_class_add_private (object_class, sizeof (FormPrivate)); +} + +static void +form_init (Form *form) +{ + FormPrivate *priv = FORM_GET_PRIVATE (form); + + priv->fields = NULL; + priv->glade = NULL; + priv->loc = localeconv (); +} + +/** + * form_new: + * + * Returns: the newly created #Form. + */ +Form +*form_new () +{ + return FORM (g_object_new (form_get_type (), NULL)); +} + +/** + * form_set_glade: + * @glade: + * + * Returns: the newly created #Form. + */ +gboolean +form_set_glade (Form *form, GladeXML *glade) +{ + gboolean ret = FALSE; + + FormPrivate *priv = FORM_GET_PRIVATE (form); + + priv->glade = glade; + + /* TO DO */ + /* setting fields with glade attributes */ + + ret = TRUE; + + return ret; +} + +gboolean +form_add_field (Form *form, FormField *field) +{ + gboolean ret = FALSE; + + FormPrivate *priv = FORM_GET_PRIVATE (form); + + priv->field = g_list_append (priv->fields, field); + + if (priv->glade != NULL) + { + /* TO DO */ + /* setting fields with glade attributes */ + } + + ret = TRUE; + + return ret; +} + +gboolean +form_remove_field (Form *form, FormField *field) +{ + gboolean ret = FALSE; + + FormPrivate *priv = FORM_GET_PRIVATE (form); + + priv->field = g_list_remove (priv->fields, field); + + ret = TRUE; + + return ret; +} + +/** + * form_sql_get: + * @form: a #Form. + * @type: + * @table: + * + */ +gchar +*form_get_sql (Form *form, FrmSqlType type, const gchar *table, ...) +{ + gchar *sql, *fields = "", *keys, *pkeys = NULL, *pname; + gint i; + Field *f; + gboolean with_key; + va_list ap; + + if (table == NULL) + { + return NULL; + } + + FormPrivate *priv = FORM_GET_PRIVATE (form); + + with_key = (type == FRM_SQL_TYPE_UPDATE || + type == FRM_SQL_TYPE_DELETE); + + va_start (ap, table); + + while (TRUE) + { + pname = va_arg (ap, gchar *); + if (pname == NULL) + { + break; + } + + if (strcmp (pname, "with-key") == 0) + { + with_key = va_arg (ap, gboolean); + } + else + { + pkeys = g_strjoin (NULL, " AND ", pname, " = ", NULL); + f = form_get_field (form, pname); + switch (f->field_type) + { + case FRM_FIELD_TYPE_TEXT: + pkeys = g_strjoin (NULL, pkeys, "'", + s_strescape (va_arg (ap, gchar *), NULL), + "'", NULL); + break; + + case FRM_FIELD_TYPE_INTEGER: + pkeys = g_strjoin (NULL, pkeys, + g_strdup_printf ("%d", va_arg (ap, gint)), + NULL); + break; + + case FRM_FIELD_TYPE_FLOAT: + pkeys = g_strjoin (NULL, pkeys, + g_strdup_printf ("%f", va_arg (ap, double)), + NULL); + break; + + case FRM_FIELD_TYPE_BOOLEAN: + pkeys = g_strjoin (NULL, pkeys, "'", + (va_arg (ap, gboolean) == TRUE ? "-1" : "0"), + "'", NULL); + break; + + case FRM_FIELD_TYPE_DATE: + { + GDate *date = va_arg (ap, GDate *); + pkeys = g_strjoin (NULL, pkeys, "'", + g_strdup_printf ("%04d%02d%02d", + g_date_get_year (date), + g_date_get_month (date), + g_date_get_day (date)), + "'", NULL); + } + break; + } + } + } + + va_end (ap); + + switch (type) + { + case FRM_SQL_TYPE_SELECT: + { + sql = g_strdup ("SELECT "); + + for (i = 0; i < priv->nfields; i++) + { + f = priv->fields[i]; + + if (strcmp (f->table_name, table) == 0) + { + if (with_key && pkeys == NULL && f->key) + { + keys = g_strjoin (NULL, keys, " AND ", f->field_name, " = ", + form_field_get_value_sql (f), NULL); + } + fields = g_strjoin (NULL, fields, f->field_name, ", ", NULL); + } + } + + fields[strlen (fields) - 2] = ' '; + + sql = g_strjoin (NULL, sql, fields, "FROM ", g_strdup_printf ("%s", table), NULL); + if (with_key) + { + sql = g_strjoin (NULL, sql, " WHERE TRUE", (pkeys != NULL ? pkeys : keys), NULL); + } + break; + } + + case FRM_SQL_TYPE_INSERT: + { + gchar *values = "("; + + sql = g_strdup_printf ("INSERT INTO %s ", table); + + for (i = 0; i < priv->nfields; i++) + { + f = priv->fields[i]; + + if (strcmp (f->table_name, table) == 0) + { + fields = g_strjoin (NULL, fields, f->field_name, ", ", NULL); + values = g_strjoin (NULL, values, form_field_get_value_sql (f), ", ", NULL); + } + } + + fields[strlen (fields) - 2] = ')'; + values[strlen (values) - 2] = ')'; + + sql = g_strjoin (NULL, sql, "(", fields, " VALUES ", values, NULL); + break; + } + + case FRM_SQL_TYPE_UPDATE: + { + sql = g_strdup_printf ("UPDATE %s SET ", table); + + for (i = 0; i < priv->nfields; i++) + { + f = priv->fields[i]; + + if (strcmp (f->table_name, table) == 0) + { + if (with_key && f->key) + { + keys = g_strjoin (NULL, keys, " AND ", f->field_name, " = ", + form_field_get_value_sql (f), NULL); + } + else + { + fields = g_strjoin (NULL, fields, f->field_name, " = ", form_field_get_value_sql (f), ", ", NULL); + } + } + } + + fields[strlen (fields) - 2] = ' '; + + sql = g_strjoin (NULL, sql, fields, keys, NULL); + break; + } + + case FRM_SQL_TYPE_DELETE: + { + sql = g_strdup_printf ("DELETE FROM %s%s", table, (with_key ? " WHERE TRUE" : "")); + + if (with_key) + { + if (pkeys != NULL) + { + sql = g_strjoin (NULL, sql, pkeys, NULL); + } + else + { + for (i = 0; i < priv->nfields; i++) + { + f = priv->fields[i]; + + if (strcmp (f->table_name, table) == 0 && f->key) + { + sql = g_strjoin (NULL, sql, " AND ", f->field_name, "=", + form_field_get_value_sql (f), NULL); + } + } + } + } + break; + } + } + + return sql; +} + +/** + * form_clear: + * @form: a #Form. + * + * Clears the form. + */ +gboolean +form_clear (Form *form) +{ + gint i; + Field *f; + + FormPrivate *priv = FORM_GET_PRIVATE (form); + + for (i = 0; i < priv->nfields; i++) + { + f = priv->fields[i]; + + if (f->widget_type == GTK_TYPE_LABEL) + { + gtk_label_set_text (GTK_LABEL (f->widget), f->default_value); + } + else if (f->widget_type == GTK_TYPE_ENTRY) + { + gtk_entry_set_text (GTK_ENTRY (f->widget), f->default_value); + } + else if (f->widget_type == GTK_TYPE_SPIN_BUTTON) + { + gtk_spin_button_set_value (GTK_SPIN_BUTTON (f->widget), atof (f->default_value)); + } + else if (f->widget_type == GTK_TYPE_COMBO_BOX) + { + gtk_combo_box_set_active (GTK_COMBO_BOX (f->widget), atoi (f->default_value)); + } + } +} + +/** + * form_fill_from_datamodel: + * @form: a #Form. + * @dm: + * + */ +gboolean +form_fill_from_datamodel (Form *form, GdaDataModel *dm, gint row) +{ + gint nfield; + Field *f; + + FormPrivate *priv = FORM_GET_PRIVATE (form); + + for (nfield = 0; nfield < priv->nfields; nfield++) + { + f = priv->fields[nfield]; + + if (f->widget_type == GTK_TYPE_LABEL) + { + gtk_label_set_text (GTK_LABEL (f->widget), + gdao_data_model_get_field_value_stringify_at (dm, row, f->field_name)); + } + else if (f->widget_type == GTK_TYPE_ENTRY) + { + gtk_entry_set_text (GTK_ENTRY (f->widget), + gdao_data_model_get_field_value_stringify_at (dm, row, f->field_name)); + } + else if (f->widget_type == GTK_TYPE_SPIN_BUTTON) + { + gtk_spin_button_set_value (GTK_SPIN_BUTTON (f->widget), + gdao_data_model_get_field_value_double_at (dm, row, f->field_name)); + } + else if (f->widget_type == GTK_TYPE_COMBO_BOX) + { + } + } + + return TRUE; +} + +/** + * form_check: + * @form: a #Form. + * + */ +gboolean +form_check (Form *form) +{ + gboolean ret = FALSE; + gint i; + Field *f; + + FormPrivate *priv = FORM_GET_PRIVATE (form); + + for (i = 0; i < priv->nfields; i++) + { + f = priv->fields[i]; + switch (f->field_type) + { + case FRM_FIELD_TYPE_TEXT: + { + if (f->obligatory && strcmp (gtk_entry_get_text (GTK_ENTRY (f->widget)), "") == 0) + { + return FALSE; + } + break; + } + + case FRM_FIELD_TYPE_INTEGER: + case FRM_FIELD_TYPE_FLOAT: + { + break; + } + } + } + + return ret; +} + +/** + * form_field_get: + * @form: + * @field: + * @value: + * + */ +gboolean +form_field_get (Form *form, gint field, GValue *value) +{ + FormPrivate *priv = FORM_GET_PRIVATE (form); + + if (field > priv->nfields) + { + return FALSE; + } + + Field *f = priv->fields[field]; + + if (f->widget_type == GTK_TYPE_LABEL) + { + g_value_init (value, G_TYPE_STRING); + g_value_set_string (value, gtk_label_get_text (GTK_LABEL (f->widget))); + } + else if (f->widget_type == GTK_TYPE_ENTRY) + { + g_value_init (value, G_TYPE_STRING); + g_value_set_string (value, gtk_entry_get_text (GTK_ENTRY (f->widget))); + } + else if (f->widget_type == GTK_TYPE_SPIN_BUTTON) + { + if (f->field_type == FRM_FIELD_TYPE_INTEGER) + { + g_value_init (value, G_TYPE_INT); + g_value_set_int (value, gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (f->widget))); + } + else if (f->field_type == FRM_FIELD_TYPE_FLOAT) + { + g_value_init (value, G_TYPE_FLOAT); + g_value_set_float (value, gtk_spin_button_get_value_as_float (GTK_SPIN_BUTTON (f->widget))); + } + } + else if (f->widget_type == GTK_TYPE_COMBO_BOX) + { + } + + return TRUE; +} + +/* PRIVATE */ +static Field +*form_get_field (Form *form, const gchar *name) +{ + gint i; + Field *f = NULL; + + FormPrivate *priv = FORM_GET_PRIVATE (form); + + for (i = 0; i < priv->nfields; i++) + { + f = priv->fields[i]; + if (strcmp (f->field_name, name) == 0) + { + break; + } + } + + return f; +} + +static gchar +*form_field_get_value_sql (Field *f) +{ + gchar *ret = ""; + + FormPrivate *priv = FORM_GET_PRIVATE (f->form); + + if (f->widget_type == GTK_TYPE_LABEL) + { + ret = (gchar *)gtk_label_get_text (GTK_LABEL (f->widget)); + } + else if (f->widget_type == GTK_TYPE_ENTRY) + { + ret = (gchar *)gtk_entry_get_text (GTK_ENTRY (f->widget)); + } + else if (f->widget_type == GTK_TYPE_SPIN_BUTTON) + { + if (f->field_type == FRM_FIELD_TYPE_INTEGER) + { + ret = g_strdup_printf ("%d", gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (f->widget))); + } + else if (f->field_type == FRM_FIELD_TYPE_FLOAT) + { + ret = g_strdup_printf ("%f", gtk_spin_button_get_value_as_float (GTK_SPIN_BUTTON (f->widget))); + ret = g_strjoinv (".", g_strsplit (ret, priv->loc->decimal_point, -1)); + } + } + + switch (f->field_type) + { + case FRM_FIELD_TYPE_TEXT: + ret = g_strjoin (NULL, "'", s_strescape(ret, NULL), "'", NULL); + break; + } + + return ret; +} + +static gboolean +form_field_check_struct (Field *f) +{ + if (f->widget != NULL) + { + if (f->widget_type == 0) + { + f->widget_type = GTK_WIDGET_TYPE (f->widget); + } + } + else + { + return FALSE; + } + + if (f->field_type == 0) + { + if (f->widget_type == GTK_TYPE_LABEL || f->widget_type == GTK_TYPE_ENTRY) + { + f->field_type = FRM_FIELD_TYPE_TEXT; + } + else if (f->widget_type == GTK_TYPE_SPIN_BUTTON) + { + if (gtk_spin_button_get_digits (GTK_SPIN_BUTTON (f->widget)) > 0) + { + f->field_type = FRM_FIELD_TYPE_FLOAT; + } + else + { + f->field_type = FRM_FIELD_TYPE_INTEGER; + } + } + else if (f->widget_type == GTK_TYPE_COMBO_BOX) + { + f->field_type = FRM_FIELD_TYPE_INTEGER; + } + } + + switch (f->field_type) + { + case FRM_FIELD_TYPE_TEXT: + { + if (f->default_value == NULL) + { + if (f->widget_type == GTK_TYPE_COMBO_BOX) + { + f->default_value = g_strdup ("0"); + } + else + { + f->default_value = g_strdup (""); + } + } + break; + } + + case FRM_FIELD_TYPE_INTEGER: + { + if (f->default_value == NULL) + { + f->default_value = g_strdup ("0"); + } + else + { + f->default_value = g_strdup_printf ("%d", atoi (f->default_value)); + } + break; + } + + case FRM_FIELD_TYPE_FLOAT: + { + if (f->default_value == NULL) + { + f->default_value = g_strdup ("0.0"); + } + else + { + f->default_value = g_strdup_printf ("%f", atof (f->default_value)); + } + break; + } + + case FRM_FIELD_TYPE_BOOLEAN: + { + if (f->default_value == NULL) + { + f->default_value = g_strdup ("0"); + } + else + { + f->default_value = g_strdup_printf ("%d", + atoi (f->default_value) == 0 || + atoi (f->default_value) == 1 ? + atoi (f->default_value) : 0); + } + break; + } + } + + if (f->key) + { + /* a key is always obligatory */ + f->obligatory = TRUE; + } + + return TRUE; +} diff --git a/src/old/libform.h b/src/old/libform.h new file mode 100644 index 0000000..c147eef --- /dev/null +++ b/src/old/libform.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#ifndef __LIBFORM_H__ +#define __LIBFORM_H__ + +#include +#include + +#include + +G_BEGIN_DECLS + + +#define TYPE_FORM (form_get_type ()) +#define FORM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FORM, Form)) +#define FORM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FORM, FormClass)) +#define IS_FORM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FORM)) +#define IS_FORM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FORM)) +#define FORM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FORM, FormClass)) + + +typedef struct _Form Form; +typedef struct _FormClass FormClass; + +struct _Form + { + GObject parent; + }; + +struct _FormClass + { + GObjectClass parent_class; + }; + +GType form_get_type (void) G_GNUC_CONST; + + +Form *form_new (void); + +gboolean form_set_glade (Form *form, GladeXML *glade); + +gboolean form_add_field (Form *form, FormField *field); +gboolean form_remove_field (Form *form, FormField *field); + +typedef enum +{ + FRM_SQL_TYPE_SELECT, + FRM_SQL_TYPE_UPDATE, + FRM_SQL_TYPE_INSERT, + FRM_SQL_TYPE_DELETE +} FormSqlType; + +gchar *form_get_sql (Form *form, FormSqlType type, const gchar *table, ...); + +gboolean form_clear (Form *form); +gboolean form_fill_from_datamodel (Form *form, GdaDataModel *dm, gint row); + +gboolean form_check (Form *form); + +gboolean form_field_get (Form *form, gint field, GValue *value); + + +G_END_DECLS + +#endif /* __LIBFORM_H__ */ diff --git a/src/widget.c b/src/widget.c new file mode 100644 index 0000000..47f05ba --- /dev/null +++ b/src/widget.c @@ -0,0 +1,234 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#include + +#include "libformwidget.h" + +enum +{ + PROP_0, + PROP_WIDGET, + PROP_NAME +}; + +static void form_widget_class_init (FormWidgetClass *klass); +static void form_widget_init (FormWidget *form_widget); + +static void form_widget_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void form_widget_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +#define FORM_WIDGET_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_FORM_WIDGET, FormWidgetPrivate)) + +typedef struct _FormWidgetPrivate FormWidgetPrivate; +struct _FormWidgetPrivate + { + GtkWidget *widget; + gchar *widget_name; + }; + + +GType +form_widget_get_type (void) +{ + static GType form_widget_type = 0; + + if (!form_widget_type) + { + static const GTypeInfo form_widget_info = + { + sizeof (FormWidgetClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) form_widget_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FormWidget), + 0, /* n_preallocs */ + (GInstanceInitFunc) form_widget_init, + NULL + }; + + form_widget_type = g_type_register_static (G_TYPE_OBJECT, "FormWidget", + &form_widget_info, 0); + } + + return form_widget_type; +} + +static void +form_widget_class_init (FormWidgetClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->set_property = form_widget_set_property; + object_class->get_property = form_widget_get_property; + + g_object_class_install_property (object_class, PROP_WIDGET, + g_param_spec_object ("widget", + "GtkWidget", + "The GtkWidget", + GTK_TYPE_WIDGET, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, PROP_NAME, + g_param_spec_string ("widget-name", + "Widget's name", + "Widget's name", + "", + G_PARAM_READWRITE)); + + g_type_class_add_private (object_class, sizeof (FormWidgetPrivate)); +} + +static void +form_widget_init (FormWidget *form_widget) +{ +} + +/** + * form_widget_new: + * + * Returns: the newly created #FormWidget. + */ +FormWidget +*form_widget_new () +{ + return g_object_new (TYPE_FORM_WIDGET, NULL); +} + +/** + * form_widget_set_from_glade: + * @fwidget: + * @glade: + * @widget_name: + * + */ +gboolean +form_widget_set_from_glade (FormWidget *fwidget, GladeXML *glade, const gchar *widget_name) +{ + gboolean ret = FALSE; + + GtkWidget *w = glade_xml_get_widget (glade, widget_name); + if (w != NULL) + { + g_object_set (fwidget, + "widget", w, + "widget-name", widget_name, + NULL); + + ret = TRUE; + } + + return ret; +} + +/** + * form_widget_get_widget: + * @fwidget: + * + */ +GtkWidget +*form_widget_get_widget (FormWidget *fwidget) +{ + FormWidgetPrivate *priv = FORM_WIDGET_GET_PRIVATE (fwidget); + + return priv->widget; +} + +/** + * form_widget_get_value_stringify: + * @fwidget: + * + */ +const gchar +*form_widget_get_value_stringify (FormWidget *fwidget) +{ + FORM_WIDGET_GET_CLASS (fwidget)->get_value_stringify (fwidget); +} + +/** + * form_widget_set_value_stringify: + * @fwidget: + * @value: + * + */ +gboolean +form_widget_set_value_stringify (FormWidget *fwidget, const gchar *value) +{ + FORM_WIDGET_GET_CLASS (fwidget)->set_value_stringify (fwidget, value); +} + +/* PRIVATE */ +static void +form_widget_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + FormWidget *fwidget = (FormWidget *)object; + + FormWidgetPrivate *priv = FORM_WIDGET_GET_PRIVATE (fwidget); + + switch (property_id) + { + case PROP_WIDGET: + priv->widget = g_value_get_object (value); + break; + + case PROP_NAME: + priv->widget_name = g_strstrip (g_strdup (g_value_get_string (value))); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +form_widget_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + FormWidget *fwidget = (FormWidget *)object; + + FormWidgetPrivate *priv = FORM_WIDGET_GET_PRIVATE (fwidget); + + switch (property_id) + { + case PROP_WIDGET: + g_value_set_object (value, priv->widget); + break; + + case PROP_NAME: + g_value_set_string (value, priv->widget_name); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} diff --git a/src/widgetcheck.c b/src/widgetcheck.c new file mode 100644 index 0000000..f8c6a46 --- /dev/null +++ b/src/widgetcheck.c @@ -0,0 +1,213 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#include + +#include + +#include "libformwidgetcheck.h" + +enum +{ + PROP_0 +}; + +static void form_widget_check_class_init (FormWidgetCheckClass *klass); +static void form_widget_check_init (FormWidgetCheck *form_widget_check); + +static void form_widget_check_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void form_widget_check_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static gboolean check_value (const gchar *value); + +#define FORM_WIDGET_CHECK_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_FORM_WIDGET_CHECK, FormWidgetCheckPrivate)) + +typedef struct _FormWidgetCheckPrivate FormWidgetCheckPrivate; +struct _FormWidgetCheckPrivate + { + }; + + +GType +form_widget_check_get_type (void) +{ + static GType form_widget_check_type = 0; + + if (!form_widget_check_type) + { + static const GTypeInfo form_widget_check_info = + { + sizeof (FormWidgetCheckClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) form_widget_check_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FormWidgetCheck), + 0, /* n_preallocs */ + (GInstanceInitFunc) form_widget_check_init, + NULL + }; + + form_widget_check_type = g_type_register_static (TYPE_FORM_WIDGET, "FormWidgetCheck", + &form_widget_check_info, 0); + } + + return form_widget_check_type; +} + +static void +form_widget_check_class_init (FormWidgetCheckClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + FormWidgetClass *widget_class = FORM_WIDGET_CLASS (klass); + + object_class->set_property = form_widget_check_set_property; + object_class->get_property = form_widget_check_get_property; + + widget_class->get_value_stringify = form_widget_check_get_value_stringify; + widget_class->set_value_stringify = form_widget_check_set_value_stringify; + + g_type_class_add_private (object_class, sizeof (FormWidgetCheckPrivate)); +} + +static void +form_widget_check_init (FormWidgetCheck *form_widget_check) +{ +} + +/** + * form_widget_check_new: + * + * Returns: the newly created #FormWidgetCheck. + */ +FormWidget +*form_widget_check_new () +{ + return g_object_new (TYPE_FORM_WIDGET_CHECK, NULL); +} + +/** + * form_widget_check_get_value_stringify: + * @widget: + * + */ +const gchar +*form_widget_check_get_value_stringify (FormWidget *fwidget) +{ + GtkWidget *w = form_widget_get_widget (fwidget); + + return g_strdup_printf ("%d", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w))); +} + +/** + * form_widget_check_set_value_stringify: + * @fwidget: + * @value: + * + */ +gboolean +form_widget_check_set_value_stringify (FormWidget *fwidget, const gchar *value) +{ + gboolean ret = FALSE; + GtkWidget *w; + gboolean active = FALSE; + + g_object_get (G_OBJECT (fwidget), + "widget", &w, + NULL); + + active = check_value (value); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), active); + + ret = TRUE; + + return ret; +} + +/* PRIVATE */ +static void +form_widget_check_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + FormWidgetCheck *widget_check = (FormWidgetCheck *)object; + + FormWidgetCheckPrivate *priv = FORM_WIDGET_CHECK_GET_PRIVATE (widget_check); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +form_widget_check_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + FormWidgetCheck *widget_check = (FormWidgetCheck *)object; + + FormWidgetCheckPrivate *priv = FORM_WIDGET_CHECK_GET_PRIVATE (widget_check); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static gboolean +check_value (const gchar *value) +{ + gchar *str_value; + gboolean active = FALSE; + + str_value = g_strstrip (g_strdup (value)); + + if (strcmp (str_value, "0") == 0 + || strcasecmp (str_value, "f") == 0 + || strcasecmp (str_value, "false") == 0 + || strcasecmp (str_value, "n") == 0 + || strcasecmp (str_value, "no") == 0) + { + active = FALSE; + } + else if (strcmp (str_value, "1") == 0 + || strcasecmp (str_value, "t") == 0 + || strcasecmp (str_value, "true") == 0 + || strcasecmp (str_value, "y") == 0 + || strcasecmp (str_value, "yes") == 0) + { + active = TRUE; + } + + return active; +} diff --git a/src/widgetentry.c b/src/widgetentry.c new file mode 100644 index 0000000..c91424e --- /dev/null +++ b/src/widgetentry.c @@ -0,0 +1,178 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#include + +#include "libformwidgetentry.h" + +enum +{ + PROP_0 +}; + +static void form_widget_entry_class_init (FormWidgetEntryClass *klass); +static void form_widget_entry_init (FormWidgetEntry *form_widget_entry); + +static void form_widget_entry_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void form_widget_entry_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +#define FORM_WIDGET_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_FORM_WIDGET_ENTRY, FormWidgetEntryPrivate)) + +typedef struct _FormWidgetEntryPrivate FormWidgetEntryPrivate; +struct _FormWidgetEntryPrivate + { + }; + + +GType +form_widget_entry_get_type (void) +{ + static GType form_widget_entry_type = 0; + + if (!form_widget_entry_type) + { + static const GTypeInfo form_widget_entry_info = + { + sizeof (FormWidgetEntryClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) form_widget_entry_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FormWidgetEntry), + 0, /* n_preallocs */ + (GInstanceInitFunc) form_widget_entry_init, + NULL + }; + + form_widget_entry_type = g_type_register_static (TYPE_FORM_WIDGET, "FormWidgetEntry", + &form_widget_entry_info, 0); + } + + return form_widget_entry_type; +} + +static void +form_widget_entry_class_init (FormWidgetEntryClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + FormWidgetClass *widget_class = FORM_WIDGET_CLASS (klass); + + object_class->set_property = form_widget_entry_set_property; + object_class->get_property = form_widget_entry_get_property; + + widget_class->get_value_stringify = form_widget_entry_get_value_stringify; + widget_class->set_value_stringify = form_widget_entry_set_value_stringify; + + g_type_class_add_private (object_class, sizeof (FormWidgetEntryPrivate)); +} + +static void +form_widget_entry_init (FormWidgetEntry *form_widget_entry) +{ +} + +/** + * form_widget_entry_new: + * + * Returns: the newly created #FormWidgetEntry. + */ +FormWidget +*form_widget_entry_new () +{ + return g_object_new (TYPE_FORM_WIDGET_ENTRY, NULL); +} + +/** + * form_widget_entry_get_value_stringify: + * @widget: + * + */ +const gchar +*form_widget_entry_get_value_stringify (FormWidget *fwidget) +{ + GtkWidget *w = form_widget_get_widget (fwidget); + + return gtk_entry_get_text (GTK_ENTRY (w)); +} + +/** + * form_widget_entry_set_value_stringify: + * @fwidget: + * @value: + * + */ +gboolean +form_widget_entry_set_value_stringify (FormWidget *fwidget, const gchar *value) +{ + gboolean ret = FALSE; + GtkWidget *w; + + g_object_get (G_OBJECT (fwidget), + "widget", &w, + NULL); + + gtk_entry_set_text (GTK_ENTRY (w), value); + + ret = TRUE; + + return ret; +} + +/* PRIVATE */ +static void +form_widget_entry_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + FormWidgetEntry *widget_entry = (FormWidgetEntry *)object; + + FormWidgetEntryPrivate *priv = FORM_WIDGET_ENTRY_GET_PRIVATE (widget_entry); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +form_widget_entry_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + FormWidgetEntry *widget_entry = (FormWidgetEntry *)object; + + FormWidgetEntryPrivate *priv = FORM_WIDGET_ENTRY_GET_PRIVATE (widget_entry); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} diff --git a/src/widgetlabel.c b/src/widgetlabel.c new file mode 100644 index 0000000..650a890 --- /dev/null +++ b/src/widgetlabel.c @@ -0,0 +1,178 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#include + +#include "libformwidgetlabel.h" + +enum +{ + PROP_0 +}; + +static void form_widget_label_class_init (FormWidgetLabelClass *klass); +static void form_widget_label_init (FormWidgetLabel *form_widget_label); + +static void form_widget_label_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void form_widget_label_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +#define FORM_WIDGET_LABEL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_FORM_WIDGET_LABEL, FormWidgetLabelPrivate)) + +typedef struct _FormWidgetLabelPrivate FormWidgetLabelPrivate; +struct _FormWidgetLabelPrivate + { + }; + + +GType +form_widget_label_get_type (void) +{ + static GType form_widget_label_type = 0; + + if (!form_widget_label_type) + { + static const GTypeInfo form_widget_label_info = + { + sizeof (FormWidgetLabelClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) form_widget_label_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FormWidgetLabel), + 0, /* n_preallocs */ + (GInstanceInitFunc) form_widget_label_init, + NULL + }; + + form_widget_label_type = g_type_register_static (TYPE_FORM_WIDGET, "FormWidgetLabel", + &form_widget_label_info, 0); + } + + return form_widget_label_type; +} + +static void +form_widget_label_class_init (FormWidgetLabelClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + FormWidgetClass *widget_class = FORM_WIDGET_CLASS (klass); + + object_class->set_property = form_widget_label_set_property; + object_class->get_property = form_widget_label_get_property; + + widget_class->get_value_stringify = form_widget_label_get_value_stringify; + widget_class->set_value_stringify = form_widget_label_set_value_stringify; + + g_type_class_add_private (object_class, sizeof (FormWidgetLabelPrivate)); +} + +static void +form_widget_label_init (FormWidgetLabel *form_widget_label) +{ +} + +/** + * form_widget_label_new: + * + * Returns: the newly created #FormWidgetLabel. + */ +FormWidget +*form_widget_label_new () +{ + return g_object_new (TYPE_FORM_WIDGET_LABEL, NULL); +} + +/** + * form_widget_label_get_value_stringify: + * @widget: + * + */ +const gchar +*form_widget_label_get_value_stringify (FormWidget *fwidget) +{ + GtkWidget *w = form_widget_get_widget (fwidget);; + + return gtk_label_get_text (GTK_LABEL (w)); +} + +/** + * form_widget_label_set_value_stringify: + * @fwidget: + * @value: + * + */ +gboolean +form_widget_label_set_value_stringify (FormWidget *fwidget, const gchar *value) +{ + gboolean ret = FALSE; + GtkWidget *w; + + g_object_get (G_OBJECT (fwidget), + "widget", &w, + NULL); + + gtk_label_set_text (GTK_LABEL (w), value); + + ret = TRUE; + + return ret; +} + +/* PRIVATE */ +static void +form_widget_label_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + FormWidgetLabel *widget_label = (FormWidgetLabel *)object; + + FormWidgetLabelPrivate *priv = FORM_WIDGET_LABEL_GET_PRIVATE (widget_label); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +form_widget_label_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + FormWidgetLabel *widget_label = (FormWidgetLabel *)object; + + FormWidgetLabelPrivate *priv = FORM_WIDGET_LABEL_GET_PRIVATE (widget_label); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} diff --git a/src/widgetspin.c b/src/widgetspin.c new file mode 100644 index 0000000..dfd0882 --- /dev/null +++ b/src/widgetspin.c @@ -0,0 +1,183 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#include + +#include + +#include "libformwidgetspin.h" + +enum +{ + PROP_0 +}; + +static void form_widget_spin_class_init (FormWidgetSpinClass *klass); +static void form_widget_spin_init (FormWidgetSpin *form_widget_spin); + +static void form_widget_spin_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void form_widget_spin_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +#define FORM_WIDGET_SPIN_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_FORM_WIDGET_SPIN, FormWidgetSpinPrivate)) + +typedef struct _FormWidgetSpinPrivate FormWidgetSpinPrivate; +struct _FormWidgetSpinPrivate + { + }; + + +GType +form_widget_spin_get_type (void) +{ + static GType form_widget_spin_type = 0; + + if (!form_widget_spin_type) + { + static const GTypeInfo form_widget_spin_info = + { + sizeof (FormWidgetSpinClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) form_widget_spin_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FormWidgetSpin), + 0, /* n_preallocs */ + (GInstanceInitFunc) form_widget_spin_init, + NULL + }; + + form_widget_spin_type = g_type_register_static (TYPE_FORM_WIDGET, "FormWidgetSpin", + &form_widget_spin_info, 0); + } + + return form_widget_spin_type; +} + +static void +form_widget_spin_class_init (FormWidgetSpinClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + FormWidgetClass *widget_class = FORM_WIDGET_CLASS (klass); + + object_class->set_property = form_widget_spin_set_property; + object_class->get_property = form_widget_spin_get_property; + + widget_class->get_value_stringify = form_widget_spin_get_value_stringify; + widget_class->set_value_stringify = form_widget_spin_set_value_stringify; + + g_type_class_add_private (object_class, sizeof (FormWidgetSpinPrivate)); +} + +static void +form_widget_spin_init (FormWidgetSpin *form_widget_spin) +{ +} + +/** + * form_widget_spin_new: + * + * Returns: the newly created #FormWidgetSpin. + */ +FormWidget +*form_widget_spin_new () +{ + return g_object_new (TYPE_FORM_WIDGET_SPIN, NULL); +} + +/** + * form_widget_spin_get_value_stringify: + * @widget: + * + */ +const gchar +*form_widget_spin_get_value_stringify (FormWidget *fwidget) +{ + GtkWidget *w = form_widget_get_widget (fwidget); + gchar *ret = NULL; + + ret = g_strdup_printf ("%f", gtk_spin_button_get_value (GTK_SPIN_BUTTON (w))); + + return ret; +} + +/** + * form_widget_spin_set_value_stringify: + * @fwidget: + * @value: + * + */ +gboolean +form_widget_spin_set_value_stringify (FormWidget *fwidget, const gchar *value) +{ + gboolean ret = FALSE; + GtkWidget *w; + + g_object_get (G_OBJECT (fwidget), + "widget", &w, + NULL); + + gtk_spin_button_set_value (GTK_SPIN_BUTTON (w), strtod (value, NULL)); + + ret = TRUE; + + return ret; +} + +/* PRIVATE */ +static void +form_widget_spin_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + FormWidgetSpin *widget_spin = (FormWidgetSpin *)object; + + FormWidgetSpinPrivate *priv = FORM_WIDGET_SPIN_GET_PRIVATE (widget_spin); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +form_widget_spin_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + FormWidgetSpin *widget_spin = (FormWidgetSpin *)object; + + FormWidgetSpinPrivate *priv = FORM_WIDGET_SPIN_GET_PRIVATE (widget_spin); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} diff --git a/src/widgettextview.c b/src/widgettextview.c new file mode 100644 index 0000000..787abce --- /dev/null +++ b/src/widgettextview.c @@ -0,0 +1,190 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#include + +#include "libformwidgettextview.h" + +enum +{ + PROP_0 +}; + +static void form_widget_textview_class_init (FormWidgetTextviewClass *klass); +static void form_widget_textview_init (FormWidgetTextview *form_widget_textview); + +static void form_widget_textview_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void form_widget_textview_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +#define FORM_WIDGET_TEXTVIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_FORM_WIDGET_TEXTVIEW, FormWidgetTextviewPrivate)) + +typedef struct _FormWidgetTextviewPrivate FormWidgetTextviewPrivate; +struct _FormWidgetTextviewPrivate + { + }; + + +GType +form_widget_textview_get_type (void) +{ + static GType form_widget_textview_type = 0; + + if (!form_widget_textview_type) + { + static const GTypeInfo form_widget_textview_info = + { + sizeof (FormWidgetTextviewClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) form_widget_textview_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FormWidgetTextview), + 0, /* n_preallocs */ + (GInstanceInitFunc) form_widget_textview_init, + NULL + }; + + form_widget_textview_type = g_type_register_static (TYPE_FORM_WIDGET, "FormWidgetTextview", + &form_widget_textview_info, 0); + } + + return form_widget_textview_type; +} + +static void +form_widget_textview_class_init (FormWidgetTextviewClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + FormWidgetClass *widget_class = FORM_WIDGET_CLASS (klass); + + object_class->set_property = form_widget_textview_set_property; + object_class->get_property = form_widget_textview_get_property; + + widget_class->get_value_stringify = form_widget_textview_get_value_stringify; + widget_class->set_value_stringify = form_widget_textview_set_value_stringify; + + g_type_class_add_private (object_class, sizeof (FormWidgetTextviewPrivate)); +} + +static void +form_widget_textview_init (FormWidgetTextview *form_widget_textview) +{ +} + +/** + * form_widget_textview_new: + * + * Returns: the newly created #FormWidgetTextview. + */ +FormWidget +*form_widget_textview_new () +{ + return g_object_new (TYPE_FORM_WIDGET_TEXTVIEW, NULL); +} + +/** + * form_widget_textview_get_value_stringify: + * @widget: + * + */ +const gchar +*form_widget_textview_get_value_stringify (FormWidget *fwidget) +{ + gchar *ret = NULL; + GtkWidget *w; + GtkTextBuffer *buf; + GtkTextIter start; + GtkTextIter end; + + w = form_widget_get_widget (fwidget); + + buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (w)); + gtk_text_buffer_get_bounds (buf, &start, &end); + ret = gtk_text_buffer_get_text (buf, &start, &end, FALSE); + + return ret; +} + +/** + * form_widget_textview_set_value_stringify: + * @fwidget: + * @value: + * + */ +gboolean +form_widget_textview_set_value_stringify (FormWidget *fwidget, const gchar *value) +{ + gboolean ret = FALSE; + GtkWidget *w; + GtkTextBuffer *buf; + + g_object_get (G_OBJECT (fwidget), + "widget", &w, + NULL); + + buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (w)); + gtk_text_buffer_set_text (buf, value, -1); + + ret = TRUE; + + return ret; +} + +/* PRIVATE */ +static void +form_widget_textview_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + FormWidgetTextview *widget_textview = (FormWidgetTextview *)object; + + FormWidgetTextviewPrivate *priv = FORM_WIDGET_TEXTVIEW_GET_PRIVATE (widget_textview); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +form_widget_textview_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + FormWidgetTextview *widget_textview = (FormWidgetTextview *)object; + + FormWidgetTextviewPrivate *priv = FORM_WIDGET_TEXTVIEW_GET_PRIVATE (widget_textview); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} diff --git a/test/Makefile.am b/test/Makefile.am new file mode 100644 index 0000000..80a6cc5 --- /dev/null +++ b/test/Makefile.am @@ -0,0 +1,12 @@ +LIBS = $(FORM_LIBS) \ + -export-dynamic + +AM_CPPFLAGS = $(FORM_CFLAGS) \ + -I$(top_srcdir)/src \ + -DGLADEDIR="\"@abs_builddir@\"" + +noinst_PROGRAMS = test + +test_SOURCES = main.c + +test_LDADD = $(top_builddir)/src/libform.la diff --git a/test/main.c b/test/main.c new file mode 100644 index 0000000..08016d0 --- /dev/null +++ b/test/main.c @@ -0,0 +1,249 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +Form *form; + +FormField *ftext; +FormField *fint; +FormField *ffloat; +FormField *fbool; +FormField *fdatetime; + +FormWidget *wlabel; +FormWidget *wentry; +FormWidget *wtxtv; +FormWidget *wspin; +FormWidget *wcheck; + +GtkWidget *w; +GtkWidget *txtvSql; + +void +on_btnClear_clicked (GtkButton *button, + gpointer user_data) +{ + form_clear (form); +} + +void +on_btnCheck_clicked (GtkButton *button, + gpointer user_data) +{ + if (!form_check (form)) + { + GtkWidget *diag = gtk_message_dialog_new (GTK_WINDOW (w), + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + "Some obligatory field is empty."); + gtk_dialog_run (GTK_DIALOG (diag)); + gtk_widget_destroy (diag); + } +} + +void +on_btnSqlSelect_clicked (GtkButton *button, + gpointer user_data) +{ + GtkTextBuffer *buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (txtvSql)); + gchar *sql = form_get_sql (form, FORM_SQL_SELECT); + + gtk_text_buffer_set_text (buf, sql, strlen (sql)); +} + +void +on_btnSqlUpdate_clicked (GtkButton *button, + gpointer user_data) +{ + GtkTextBuffer *buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (txtvSql)); + gchar *sql = form_get_sql (form, FORM_SQL_UPDATE); + + gtk_text_buffer_set_text (buf, sql, strlen (sql)); +} + +void +on_btnSqlInsert_clicked (GtkButton *button, + gpointer user_data) +{ + GtkTextBuffer *buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (txtvSql)); + gchar *sql = form_get_sql (form, FORM_SQL_INSERT); + + gtk_text_buffer_set_text (buf, sql, strlen (sql)); +} + +void +on_btnSqlDelete_clicked (GtkButton *button, + gpointer user_data) +{ + GtkTextBuffer *buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (txtvSql)); + gchar *sql = form_get_sql (form, FORM_SQL_DELETE); + + gtk_text_buffer_set_text (buf, sql, strlen (sql)); +} + +int +main (int argc, char **argv) +{ + GladeXML *glade; + FormKey *key; + time_t time_now; + struct tm *now; + + gtk_init (&argc, &argv); + + glade = glade_xml_new (GLADEDIR "/test.glade", NULL, NULL); + + w = glade_xml_get_widget (glade, "wMain"); + + form = form_new (); + if (form == NULL) return 0; + + key = form_key_new (); + g_object_set (G_OBJECT (form), + "table", "names", + "key", key, + NULL); + + /* LABEL - INTEGER */ + wlabel = form_widget_label_new (); + form_widget_set_from_glade (wlabel, glade, "lblID"); + + fint = form_field_integer_new (); + g_object_set (fint, + "field", "id", + "form-widget", wlabel, + "default", 15, + NULL); + form_add_field (form, fint); + form_key_add_field (key, fint); + + /* LABEL - TEXT */ + wlabel = form_widget_label_new (); + form_widget_set_from_glade (wlabel, glade, "lblText"); + + ftext = form_field_text_new (); + g_object_set (ftext, + "field", "id", + "form-widget", wlabel, + "default", "default value", + NULL); + form_add_field (form, ftext); + + /* ENTRY - TEXT */ + wentry = form_widget_entry_new (); + form_widget_set_from_glade (wentry, glade, "txtName"); + + ftext = form_field_text_new (); + g_object_set (ftext, + "field", "name", + "obligatory", TRUE, + "form-widget", wentry, + "default", "entry default value", + NULL); + form_add_field (form, ftext); + + /* SPIN - INTEGER */ + wspin = form_widget_spin_new (); + form_widget_set_from_glade (wspin, glade, "spnAge"); + + fint = form_field_integer_new (); + g_object_set (fint, + "field", "age", + "form-widget", wspin, + "default", 23, + NULL); + form_add_field (form, fint); + + /* SPIN - FLOAT */ + wspin = form_widget_spin_new (); + form_widget_set_from_glade (wspin, glade, "spnAmount"); + + ffloat = form_field_float_new (); + g_object_set (ffloat, + "field", "amount", + "form-widget", wspin, + "default", 12.45f, + NULL); + form_add_field (form, ffloat); + + /* CHECK - BOOL*/ + wcheck = form_widget_check_new (); + form_widget_set_from_glade (wcheck, glade, "chkMarried"); + + fbool = form_field_boolean_new (); + g_object_set (fbool, + "field", "married", + "form-widget", wcheck, + NULL); + form_add_field (form, fbool); + + /* TEXTVIEW - TEXT */ + wtxtv = form_widget_textview_new (); + form_widget_set_from_glade (wtxtv, glade, "txtvDescription"); + + ftext = form_field_text_new (); + g_object_set (ftext, + "field", "description", + "form-widget", wtxtv, + "default", "the default value\nfor this text view\nwith also line feed\nand\tt\ta\tb", + NULL); + form_add_field (form, ftext); + + /* LABEL - DATETIME */ + time (&time_now); + now = localtime (&time_now); + + wlabel = form_widget_label_new (); + form_widget_set_from_glade (wlabel, glade, "lblDateTime"); + + fdatetime = form_field_datetime_new (); + g_object_set (fdatetime, + "field", "now", + "form-widget", wlabel, + "default", now, + NULL); + form_add_field (form, fdatetime); + + txtvSql = glade_xml_get_widget (glade, "txtvSql"); + + glade_xml_signal_autoconnect (glade); + + gtk_main (); + + return 0; +} diff --git a/test/test.glade b/test/test.glade new file mode 100644 index 0000000..3d8cdb5 --- /dev/null +++ b/test/test.glade @@ -0,0 +1,711 @@ + + + + + + + True + test libform + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + True + False + + + + + 3 + True + False + 0 + + + + 3 + True + 9 + 2 + False + 3 + 3 + + + + True + Label (id) + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + GtkEntry (name) + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 1 + 2 + 0 + 1 + fill + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 1 + 2 + + + + + + + True + GtkSpinButton (Integer) (age) + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 2 + 3 + fill + + + + + + + True + True + 1 + 0 + False + GTK_UPDATE_ALWAYS + False + False + 1 0 100 1 10 10 + + + 1 + 2 + 2 + 3 + + + + + + + True + GtkSpinButton (Float) (amount) + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 3 + 4 + fill + + + + + + + True + True + 1 + 2 + False + GTK_UPDATE_ALWAYS + False + False + 1 0 100 1 10 10 + + + 1 + 2 + 3 + 4 + + + + + + + True + GtkComboBox + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 4 + 5 + fill + + + + + + + True + False + True + + + 1 + 2 + 4 + 5 + fill + fill + + + + + + True + Label (?) (text) + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 5 + 6 + fill + + + + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 1 + 2 + 5 + 6 + fill + + + + + + + True + GtkCheckButton (married) + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 6 + 7 + fill + + + + + + + True + True + + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 1 + 2 + 6 + 7 + fill + + + + + + + True + GtkTextView (description) + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 7 + 8 + fill + + + + + + + True + True + GTK_POLICY_ALWAYS + GTK_POLICY_ALWAYS + GTK_SHADOW_NONE + GTK_CORNER_TOP_LEFT + + + + True + True + True + False + True + GTK_JUSTIFY_LEFT + GTK_WRAP_NONE + True + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 1 + 2 + 7 + 8 + fill + fill + + + + + + True + Label (DateTime) (now) + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 8 + 9 + fill + + + + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 1 + 2 + 8 + 9 + fill + + + + + + 0 + False + True + + + + + + True + GTK_BUTTONBOX_DEFAULT_STYLE + 0 + + + + True + True + True + gtk-clear + True + GTK_RELIEF_NORMAL + True + + + + + + + True + True + True + Check Form + True + GTK_RELIEF_NORMAL + True + + + + + + 0 + False + True + + + + + + True + GTK_BUTTONBOX_DEFAULT_STYLE + 0 + + + + True + True + True + Sql _UPDATE + True + GTK_RELIEF_NORMAL + True + + + + + + + True + True + True + Sql _INSERT INTO + True + GTK_RELIEF_NORMAL + True + + + + + + + True + True + True + Sql _DELETE + True + GTK_RELIEF_NORMAL + True + + + + + + + True + True + True + Sql _SELECT + True + GTK_RELIEF_NORMAL + True + + + + + + 0 + False + True + + + + + + True + 1 + 2 + False + 0 + 0 + + + + True + SQL + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + True + GTK_POLICY_ALWAYS + GTK_POLICY_ALWAYS + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + True + False + True + GTK_JUSTIFY_LEFT + GTK_WRAP_NONE + True + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + 1 + 2 + 0 + 1 + + + + + 0 + True + True + + + + + + + -- 2.49.0