From: Andrea Zagli Date: Tue, 1 Dec 2015 10:09:21 +0000 (+0100) Subject: Added ZakFormIProvider. X-Git-Tag: debian/0.0.1-1~31 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=9eb0e1b59831c37e7badd1d45eb32278c42214ca;p=zakform%2Flibzakform Added ZakFormIProvider. --- diff --git a/src/Makefile.am b/src/Makefile.am index 26b354f..c0380a3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,7 +14,8 @@ libzakform_la_SOURCES = \ formelementfiltertrim.c \ formelementvalidator.c \ formelementvalidatornotempty.c \ - formelementvalidatorregex.c + formelementvalidatorregex.c \ + formiprovider.c libzakform_la_LDFLAGS = -no-undefined @@ -26,7 +27,8 @@ libzakform_include_HEADERS = \ formelementfiltertrim.h \ formelementvalidator.h \ formelementvalidatornotempty.h \ - formelementvalidatorregex.h + formelementvalidatorregex.h \ + formiprovider.h libzakform_includedir = $(includedir)/libzakform diff --git a/src/form.c b/src/form.c index 71bbfc5..e02ee79 100644 --- a/src/form.c +++ b/src/form.c @@ -440,6 +440,69 @@ zak_form_form_is_valid (ZakFormForm *zakform) return ret; } +/** + * zak_form_form_load: + * @zakform: + * @provider: + * + */ +gboolean +zak_form_form_load (ZakFormForm *zakform, ZakFormIProvider *provider) +{ + ZakFormFormPrivate *priv; + + priv = zak_form_form_get_instance_private (zakform); + + return zak_form_iprovider_load (provider, priv->ar_elements); +} + +/** + * zak_form_form_insert: + * @zakform: + * @provider: + * + */ +gboolean +zak_form_form_insert (ZakFormForm *zakform, ZakFormIProvider *provider) +{ + ZakFormFormPrivate *priv; + + priv = zak_form_form_get_instance_private (zakform); + + return zak_form_iprovider_insert (provider, priv->ar_elements); +} + +/** + * zak_form_form_update: + * @zakform: + * @provider: + * + */ +gboolean +zak_form_form_update (ZakFormForm *zakform, ZakFormIProvider *provider) +{ + ZakFormFormPrivate *priv; + + priv = zak_form_form_get_instance_private (zakform); + + return zak_form_iprovider_update (provider, priv->ar_elements); +} + +/** + * zak_form_form_delete: + * @zakform: + * @provider: + * + */ +gboolean +zak_form_form_delete (ZakFormForm *zakform, ZakFormIProvider *provider) +{ + ZakFormFormPrivate *priv; + + priv = zak_form_form_get_instance_private (zakform); + + return zak_form_iprovider_delete (provider, priv->ar_elements); +} /* PRIVATE */ static void diff --git a/src/form.h b/src/form.h index e1b3ef7..41569d9 100644 --- a/src/form.h +++ b/src/form.h @@ -25,6 +25,7 @@ #include #include "formelement.h" +#include "formiprovider.h" G_BEGIN_DECLS @@ -52,6 +53,11 @@ void zak_form_form_clear (ZakFormForm *zakform); gboolean zak_form_form_is_valid (ZakFormForm *zakform); +gboolean zak_form_form_load (ZakFormForm *zakform, ZakFormIProvider *provider); +gboolean zak_form_form_insert (ZakFormForm *zakform, ZakFormIProvider *provider); +gboolean zak_form_form_update (ZakFormForm *zakform, ZakFormIProvider *provider); +gboolean zak_form_form_delete (ZakFormForm *zakform, ZakFormIProvider *provider); + G_END_DECLS diff --git a/src/formiprovider.c b/src/formiprovider.c new file mode 100644 index 0000000..dd5c661 --- /dev/null +++ b/src/formiprovider.c @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2015 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include "formiprovider.h" + +G_DEFINE_INTERFACE (ZakFormIProvider, zak_form_iprovider, G_TYPE_OBJECT); + +static void +zak_form_iprovider_default_init (ZakFormIProviderInterface *iface) +{ + +} + +gboolean +zak_form_iprovider_load (ZakFormIProvider *self, GPtrArray *elements) +{ + gboolean ret; + + g_return_val_if_fail (ZAK_FORM_IS_IPROVIDER (self), FALSE); + + ret = FALSE; + if (ZAK_FORM_IPROVIDER_GET_IFACE (self)->load != NULL) + { + ZAK_FORM_IPROVIDER_GET_IFACE (self)->load (self, elements); + } + + return ret; +} + +gboolean +zak_form_iprovider_insert (ZakFormIProvider *self, GPtrArray *elements) +{ + gboolean ret; + + g_return_val_if_fail (ZAK_FORM_IS_IPROVIDER (self), FALSE); + + ret = FALSE; + if (ZAK_FORM_IPROVIDER_GET_IFACE (self)->insert != NULL) + { + ZAK_FORM_IPROVIDER_GET_IFACE (self)->insert (self, elements); + } + + return ret; +} + +gboolean +zak_form_iprovider_update (ZakFormIProvider *self, GPtrArray *elements) +{ + gboolean ret; + + g_return_val_if_fail (ZAK_FORM_IS_IPROVIDER (self), FALSE); + + ret = FALSE; + if (ZAK_FORM_IPROVIDER_GET_IFACE (self)->update != NULL) + { + ZAK_FORM_IPROVIDER_GET_IFACE (self)->update (self, elements); + } + + return ret; +} + +gboolean +zak_form_iprovider_delete (ZakFormIProvider *self, GPtrArray *elements) +{ + gboolean ret; + + g_return_val_if_fail (ZAK_FORM_IS_IPROVIDER (self), FALSE); + + ret = FALSE; + if (ZAK_FORM_IPROVIDER_GET_IFACE (self)->delete != NULL) + { + ZAK_FORM_IPROVIDER_GET_IFACE (self)->delete (self, elements); + } + + return ret; +} diff --git a/src/formiprovider.h b/src/formiprovider.h new file mode 100644 index 0000000..cabb51e --- /dev/null +++ b/src/formiprovider.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2015 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __ZAK_FORM_IPROVIDER_H__ +#define __ZAK_FORM_IPROVIDER_H__ + +#include + + +G_BEGIN_DECLS + + +#define ZAK_FORM_TYPE_IPROVIDER zak_form_iprovider_get_type () +G_DECLARE_INTERFACE (ZakFormIProvider, zak_form_iprovider, ZAK_FORM, IPROVIDER, GObject) + +struct _ZakFormIProviderInterface +{ + GTypeInterface parent_iface; + + gboolean (*load) (ZakFormIProvider *self, GPtrArray *elements); + gboolean (*insert) (ZakFormIProvider *self, GPtrArray *elements); + gboolean (*update) (ZakFormIProvider *self, GPtrArray *elements); + gboolean (*delete) (ZakFormIProvider *self, GPtrArray *elements); +}; + +gboolean zak_form_iprovider_load (ZakFormIProvider *self, GPtrArray *elements); +gboolean zak_form_iprovider_insert (ZakFormIProvider *self, GPtrArray *elements); +gboolean zak_form_iprovider_update (ZakFormIProvider *self, GPtrArray *elements); +gboolean zak_form_iprovider_delete (ZakFormIProvider *self, GPtrArray *elements); + + +G_END_DECLS + + +#endif /* __ZAK_FORM_IPROVIDER_H__ */ diff --git a/src/libzakform.h b/src/libzakform.h index b41c416..03753c2 100644 --- a/src/libzakform.h +++ b/src/libzakform.h @@ -31,5 +31,7 @@ #include #include +#include + #endif /* __LIBZAKFORM_H__ */