]> saetta.ns0.it Git - zakform/gtk/commitdiff
Sarting of uifactory tool. uifactory
authorAndrea Zagli <azagli@libero.it>
Mon, 25 May 2020 16:33:10 +0000 (18:33 +0200)
committerAndrea Zagli <azagli@libero.it>
Mon, 25 May 2020 16:33:10 +0000 (18:33 +0200)
.gitignore
Makefile.am
configure.ac
src/form.c
src/form.h
src/formelement.c
src/formelement.h
tools/Makefile.am [new file with mode: 0644]
tools/uifactory.c [new file with mode: 0644]

index 7f925fa8f87a4ed5ae6bf5898e94a918366d9671..8a0c03ef85cc8f5a4989ff8053cf597d4861031b 100644 (file)
@@ -51,4 +51,5 @@ Rules-quot
 *.exe
 *.csv
 *.gir
-*.typelib
\ No newline at end of file
+*.typelib
+tools/uifactory
\ No newline at end of file
index 5e943c525b2bec302a23f88a17efc7d1555cfd4b..b937748bb8ab38f636918c1bdc2545fa19f899df 100644 (file)
@@ -1,6 +1,6 @@
 DISTCHECK_CONFIGURE_FLAGS = --enable-introspection
 
-SUBDIRS = src tests
+SUBDIRS = src tests tools
 
 ACLOCAL_AMFLAGS = -I m4
 
index f367880f126a339966abe43feee332aa0af90734..82c19d759a05ece98a42881ee392504757229635 100644 (file)
@@ -77,5 +77,6 @@ AC_CONFIG_FILES([
        Makefile
        src/Makefile
        tests/Makefile
+       tools/Makefile
 ])
 AC_OUTPUT
index aa73cf3765b0f9c5db098abac74597c9a4cbd61a..d814fd1d8abb0e37de8e108e202e1c53bbe32097 100644 (file)
@@ -255,6 +255,64 @@ GObject
        return ret;
 }
 
+xmlNode
+*zak_form_gtk_form_get_ui_xml (ZakFormGtkForm *form)
+{
+       ZakFormGtkFormPrivate *priv;
+
+       xmlNode *root;
+       xmlNode *parent;
+       xmlNode *cur;
+
+       GPtrArray *elements;
+       guint i;
+
+       g_return_val_if_fail (ZAK_FORM_GTK_IS_FORM (form), NULL);
+
+       priv = ZAK_FORM_GTK_FORM_GET_PRIVATE (form);
+
+       root = xmlNewNode (NULL, (const xmlChar *)"interface");
+
+       cur = xmlNewNode (NULL, (const xmlChar *)"object");
+       xmlSetProp (cur, (const xmlChar *)"class", (const xmlChar *)"GtkWindow");
+       xmlAddChild (root, cur);
+
+       parent = cur;
+       cur = xmlNewNode (NULL, (const xmlChar *)"child");
+       xmlAddChild (parent, cur);
+
+       parent = cur;
+       cur = xmlNewNode (NULL, (const xmlChar *)"object");
+       xmlSetProp (cur, (const xmlChar *)"class", (const xmlChar *)"GtkBox");
+       xmlAddChild (parent, cur);
+
+       parent = cur;
+       cur = xmlNewNode (NULL, (const xmlChar *)"property");
+       xmlSetProp (cur, (const xmlChar *)"name", (const xmlChar *)"orientation");
+       xmlNodeSetContent (cur, (const xmlChar *)"vertical");
+       xmlAddChild (parent, cur);
+
+       cur = xmlNewNode (NULL, (const xmlChar *)"child");
+       xmlAddChild (parent, cur);
+
+       parent = cur;
+       cur = xmlNewNode (NULL, (const xmlChar *)"object");
+       xmlSetProp (cur, (const xmlChar *)"class", (const xmlChar *)"GtkGrid");
+       xmlAddChild (parent, cur);
+
+       elements = zak_form_form_get_elements (ZAK_FORM_FORM (form));
+       for (i = 0; i < elements->len; i++)
+               {
+                       cur = zak_form_gtk_form_element_get_ui_xml (ZAK_FORM_GTK_FORM_ELEMENT (g_ptr_array_index (elements, i)));
+                       if (cur != NULL)
+                               {
+
+                               }
+               }
+
+       return root;
+}
+
 /* PRIVATE */
 static void
 zak_form_gtk_form_set_property (GObject *object,
index 688e398c6576954603a9c7b590043da71470c193..c9955350079a3a7d2b9a94c071f742ad32f48ede 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2020 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
@@ -47,6 +47,8 @@ gboolean zak_form_gtk_form_is_valid (ZakFormGtkForm *form, GtkWidget *parent_win
 
 GObject **zak_form_gtk_form_get_gobjects_by_name (ZakFormGtkForm *form, ...);
 
+xmlNode *zak_form_gtk_form_get_ui_xml (ZakFormGtkForm *form);
+
 
 G_END_DECLS
 
index 0306f87d8bf690abd0cc293e64c94c4c2d4a3fff..c48db44844fbfa1cb24ff9f6af5cec81ec709138 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015-2017 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2020 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
@@ -292,6 +292,19 @@ zak_form_gtk_form_element_set_label (ZakFormGtkFormElement *element, GtkWidget *
                                                                        gtk_label_get_text (GTK_LABEL (priv->label)));
 }
 
+xmlNode
+*zak_form_gtk_form_element_get_ui_xml (ZakFormGtkFormElement *element)
+{
+       if (ZAK_FORM_GTK_FORM_ELEMENT_GET_CLASS (element)->get_ui_xml != NULL)
+               {
+                       return ZAK_FORM_GTK_FORM_ELEMENT_GET_CLASS (element)->get_ui_xml (ZAK_FORM_ELEMENT (element));
+               }
+       else
+               {
+                       return NULL;
+               }
+}
+
 /* PRIVATE */
 static void
 zak_form_gtk_form_element_set_property (GObject *object,
@@ -414,14 +427,28 @@ zak_form_gtk_form_element_xml_parsing (ZakFormElement *element, xmlNode *xmlnode
        cur = xmlnode->children;
        while (cur != NULL)
                {
-                       if (xmlStrcmp (cur->name, (const xmlChar *)"widget") == 0)
+                       if (priv->builder != NULL)
                                {
-                                       zak_form_gtk_form_element_set_widget_from_gtkbuilder (ZAK_FORM_GTK_FORM_ELEMENT (element), priv->builder, (gchar *)xmlNodeGetContent (cur));
+                                       if (xmlStrcmp (cur->name, (const xmlChar *)"widget") == 0)
+                                               {
+                                                       zak_form_gtk_form_element_set_widget_from_gtkbuilder (ZAK_FORM_GTK_FORM_ELEMENT (element), priv->builder, (gchar *)xmlNodeGetContent (cur));
+                                               }
+                                       else if (xmlStrcmp (cur->name, (const xmlChar *)"label") == 0)
+                                               {
+                                                       zak_form_gtk_form_element_set_label (ZAK_FORM_GTK_FORM_ELEMENT (element),
+                                                                                            GTK_WIDGET (gtk_builder_get_object (priv->builder, (gchar *)xmlNodeGetContent (cur))));
+                                               }
                                }
-                       else if (xmlStrcmp (cur->name, (const xmlChar *)"label") == 0)
+                       else
                                {
-                                       zak_form_gtk_form_element_set_label (ZAK_FORM_GTK_FORM_ELEMENT (element),
-                                                                                                                GTK_WIDGET (gtk_builder_get_object (priv->builder, (gchar *)xmlNodeGetContent (cur))));
+                                       if (xmlStrcmp (cur->name, (const xmlChar *)"label") == 0)
+                                               {
+                                                       GtkWidget *lbl;
+
+                                                       lbl = gtk_label_new ((gchar *)xmlNodeGetContent (cur));
+                                                       zak_form_gtk_form_element_set_label (ZAK_FORM_GTK_FORM_ELEMENT (element), lbl);
+                                               }
+
                                }
 
                        cur = cur->next;
index 4440288a6b359200f9fc28e9513328b2d9c8a99a..643d9bd9ecbf1a1735ee7a92c26b5d49314c4668 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015-2017 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2020 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
@@ -40,6 +40,7 @@ struct _ZakFormGtkFormElementClass
                ZakFormElementClass parent_class;
 
                void (*xml_parsing) (ZakFormElement *element, xmlNode *xmlnode);
+               xmlNode *(*get_ui_xml) (ZakFormElement *element);
        };
 
 
@@ -47,8 +48,8 @@ void zak_form_gtk_form_element_set_gtkbuilder (ZakFormGtkFormElement *element, G
 GtkBuilder *zak_form_gtk_form_element_get_gtkbuilder (ZakFormGtkFormElement *element);
 
 gboolean zak_form_gtk_form_element_set_widget_from_gtkbuilder (ZakFormGtkFormElement *element,
-                                                                                                                          GtkBuilder *gtkbuilder,
-                                                                                                                          const gchar *widget_name);
+                                                               GtkBuilder *gtkbuilder,
+                                                               const gchar *widget_name);
 
 GtkWidget *zak_form_gtk_form_element_get_widget (ZakFormGtkFormElement *element);
 void zak_form_gtk_form_element_set_widget (ZakFormGtkFormElement *element, GtkWidget *widget, const gchar *widget_name);
@@ -58,6 +59,8 @@ gchar *zak_form_gtk_form_element_get_widget_name (ZakFormGtkFormElement *element
 GtkWidget *zak_gtk_form_element_get_label (ZakFormGtkFormElement *element);
 void zak_form_gtk_form_element_set_label (ZakFormGtkFormElement *element, GtkWidget *label);
 
+xmlNode *zak_form_gtk_form_element_get_ui_xml (ZakFormGtkFormElement *element);
+
 
 G_END_DECLS
 
diff --git a/tools/Makefile.am b/tools/Makefile.am
new file mode 100644 (file)
index 0000000..aa2d4ec
--- /dev/null
@@ -0,0 +1,15 @@
+AM_CPPFLAGS = $(WARN_CFLAGS) \
+              $(DISABLE_DEPRECATED_CFLAGS) \
+              $(ZAKFORMGTK_CFLAGS) \
+              -I$(top_srcdir)/src \
+              -DGUIDIR="\"@abs_builddir@\""
+
+LIBS = $(ZAKFORMGTK_LIBS) \
+       -export-dynamic
+
+LDADD = $(top_builddir)/src/libzakformgtk.la
+
+noinst_PROGRAMS = \
+                  uifactory
+
+EXTRA_DIST =
diff --git a/tools/uifactory.c b/tools/uifactory.c
new file mode 100644 (file)
index 0000000..480b807
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2020 Andrea Zagli <azagli@libero.it>
+ *
+ *  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 <gtk/gtk.h>
+
+#include "form.h"
+
+int
+main (int argc, char *argv[])
+{
+       ZakFormGtkForm *form;
+
+       xmlDoc *doc;
+       xmlNode *root;
+
+       gtk_init (&argc, &argv);
+
+       form = zak_form_gtk_form_new ();
+
+       zak_form_form_load_from_file (ZAK_FORM_FORM (form), argv[1]);
+
+       doc = xmlNewDoc ("1.0");
+
+       root = zak_form_gtk_form_get_ui_xml (form);
+
+       xmlDocSetRootElement (doc, root);
+
+       xmlSaveFormatFileEnc ("did.ui", doc, "UTF-8", 2);
+
+       return 0;
+}