From: Andrea Zagli Date: Thu, 12 May 2016 10:03:45 +0000 (+0200) Subject: Added functions Session::set_from_form and ::fill_form (closes #994). X-Git-Tag: v0.1.0~3^2~6 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=61bcd4080c2262e44f623286a2354468aebf6d2c;p=libzakcgi Added functions Session::set_from_form and ::fill_form (closes #994). --- diff --git a/configure.ac b/configure.ac index 2c91479..a02bbbf 100644 --- a/configure.ac +++ b/configure.ac @@ -34,7 +34,8 @@ PKG_CHECK_MODULES(ZAKCGI, [glib-2.0 >= 2.36 gobject-2.0 >= 2.36 gio-2.0 >= 2.36 gio-unix-2.0 >= 2.36 - libzakform >= 0.0.1]) + libzakform >= 0.0.1 + libzakformini]) AC_SUBST(ZAKCGI_CFLAGS) AC_SUBST(ZAKCGI_LIBS) diff --git a/libzakcgi.pc.in b/libzakcgi.pc.in index 453643a..5b736f5 100644 --- a/libzakcgi.pc.in +++ b/libzakcgi.pc.in @@ -6,6 +6,6 @@ includedir=@includedir@ Name: @PACKAGE_NAME@ Description: Class for CGI. Version: @PACKAGE_VERSION@ -Requires: glib-2.0 >= 2.36 gobject-2.0 gio-2.0 gio-unix-2.0 +Requires: glib-2.0 >= 2.36 gobject-2.0 gio-2.0 gio-unix-2.0 libzakform libzakformini Libs: -L${libdir} -lzakcgi Cflags: -I${includedir} diff --git a/src/session.c b/src/session.c index 1439ce3..abcc82a 100644 --- a/src/session.c +++ b/src/session.c @@ -26,6 +26,8 @@ #include +#include + #include "session.h" static void zak_cgi_session_class_init (ZakCgiSessionClass *class); @@ -54,6 +56,7 @@ struct _ZakCgiSessionPrivate gchar *sid; GFile *gfile; GKeyFile *kfile; + ZakFormIniProvider *zakformini; }; G_DEFINE_TYPE (ZakCgiSession, zak_cgi_session, G_TYPE_OBJECT) @@ -81,6 +84,7 @@ zak_cgi_session_init (ZakCgiSession *zak_cgi_session) priv->path = NULL; priv->gfile = NULL; priv->kfile = NULL; + priv->zakformini = NULL; } /** @@ -512,6 +516,47 @@ zak_cgi_session_get_value_full_boolean (ZakCgiSession *session, const gchar *gro return (gboolean)zak_cgi_session_get_value_full_int (session, group, name); } +static void +zak_cgi_session_get_form_ini_provider (ZakCgiSession *session) +{ + ZakCgiSessionPrivate *priv = ZAK_CGI_SESSION_GET_PRIVATE (session); + + if (priv->zakformini == NULL) + { + priv->zakformini = zak_form_ini_provider_new_from_gkeyfile (priv->kfile, g_file_get_path (priv->gfile)); + } +} + +/** + * zak_cgi_session_set_from_form: + * @session: + * @form: + * + */ +void +zak_cgi_session_set_from_form (ZakCgiSession *session, ZakFormForm *form) +{ + ZakCgiSessionPrivate *priv = ZAK_CGI_SESSION_GET_PRIVATE (session); + + zak_cgi_session_get_form_ini_provider (session); + zak_form_form_insert (ZAK_FORM_FORM (form), ZAK_FORM_IPROVIDER (priv->zakformini)); +} + +/** + * zak_cgi_session_fill_form: + * @session: + * @form: + * + */ +void +zak_cgi_session_fill_form (ZakCgiSession *session, ZakFormForm *form) +{ + ZakCgiSessionPrivate *priv = ZAK_CGI_SESSION_GET_PRIVATE (session); + + zak_cgi_session_get_form_ini_provider (session); + zak_form_form_load (ZAK_FORM_FORM (form), ZAK_FORM_IPROVIDER (priv->zakformini)); +} + /** * zak_cgi_session_close: * @session: diff --git a/src/session.h b/src/session.h index ce238a6..1bb0943 100644 --- a/src/session.h +++ b/src/session.h @@ -22,6 +22,8 @@ #include +#include + #include "main.h" @@ -71,6 +73,9 @@ gint zak_cgi_session_get_value_full_int (ZakCgiSession *session, const gchar *gr gdouble zak_cgi_session_get_value_full_double (ZakCgiSession *session, const gchar *group, const gchar *name); gboolean zak_cgi_session_get_value_full_boolean (ZakCgiSession *session, const gchar *group, const gchar *name); +void zak_cgi_session_set_from_form (ZakCgiSession *session, ZakFormForm *form); +void zak_cgi_session_fill_form (ZakCgiSession *session, ZakFormForm *form); + void zak_cgi_session_close (ZakCgiSession *session);