]> saetta.ns0.it Git - zakform/libzakform/commitdiff
Added ZakFormIProvider.
authorAndrea Zagli <azagli@libero.it>
Tue, 1 Dec 2015 10:09:21 +0000 (11:09 +0100)
committerAndrea Zagli <azagli@libero.it>
Tue, 1 Dec 2015 10:09:21 +0000 (11:09 +0100)
src/Makefile.am
src/form.c
src/form.h
src/formiprovider.c [new file with mode: 0644]
src/formiprovider.h [new file with mode: 0644]
src/libzakform.h

index 26b354fcaa104d5c3b1ec68731404f319d2ad3ab..c0380a304bac61c432e2435b7c441a15b5f6f5c4 100644 (file)
@@ -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
 
index 71bbfc578f08a6f2a322c7096df5f78511f87c60..e02ee79cf61db33a7c553a97d03783028b43d32a 100644 (file)
@@ -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
index e1b3ef70f208cafdb4cbbbaba073c8d102679c22..41569d9ab9d0e643ef7e77894244849ddb1a53df 100644 (file)
@@ -25,6 +25,7 @@
 #include <libxml/tree.h>
 
 #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 (file)
index 0000000..dd5c661
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ *
+ * 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 <config.h>
+#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 (file)
index 0000000..cabb51e
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ *
+ * 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 <glib-object.h>
+
+
+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__ */
index b41c41646771d89900d71343b25b735bdf333837..03753c27bbd520b1e19af9ee365e59e9734a113e 100644 (file)
@@ -31,5 +31,7 @@
 #include <libzakform/formelementvalidatornotempty.h>
 #include <libzakform/formelementvalidatorregex.h>
 
+#include <libzakform/formiprovider.h>
+
 
 #endif /* __LIBZAKFORM_H__ */