[tepl] Amtk: implement AmtkFactory



commit 653b28d753d42f887de82565dfdd53bbed85c35d
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Jul 17 14:34:19 2017 +0200

    Amtk: implement AmtkFactory

 amtk/Makefile.am                     |    2 +
 amtk/amtk-factory.c                  |  152 ++++++++++++++++++++++++++++++++++
 amtk/amtk-factory.h                  |   60 +++++++++++++
 amtk/amtk-types.h                    |    1 +
 amtk/amtk.h                          |    1 +
 docs/reference/tepl-3.0-sections.txt |   16 ++++
 docs/reference/tepl-docs.xml.in      |    1 +
 po/POTFILES.in                       |    1 +
 8 files changed, 234 insertions(+), 0 deletions(-)
---
diff --git a/amtk/Makefile.am b/amtk/Makefile.am
index db2752e..a887715 100644
--- a/amtk/Makefile.am
+++ b/amtk/Makefile.am
@@ -16,6 +16,7 @@ amtk_public_headers =                         \
        amtk-action-info-store.h                \
        amtk-action-map.h                       \
        amtk-application-window.h               \
+       amtk-factory.h                          \
        amtk-menu-factory.h                     \
        amtk-menu-item.h                        \
        amtk-menu-shell.h                       \
@@ -28,6 +29,7 @@ amtk_public_c_files =                         \
        amtk-action-info-store.c                \
        amtk-action-map.c                       \
        amtk-application-window.c               \
+       amtk-factory.c                          \
        amtk-menu-factory.c                     \
        amtk-menu-item.c                        \
        amtk-menu-shell.c                       \
diff --git a/amtk/amtk-factory.c b/amtk/amtk-factory.c
new file mode 100644
index 0000000..ccb5467
--- /dev/null
+++ b/amtk/amtk-factory.c
@@ -0,0 +1,152 @@
+/*
+ * This file is part of Amtk - Actions, Menus and Toolbars Kit
+ *
+ * Copyright 2017 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * Amtk 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.
+ *
+ * Amtk 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "amtk-factory.h"
+
+/**
+ * SECTION:amtk-factory
+ * @Short_description: Factory base class
+ * @Title: AmtkFactory
+ *
+ * #AmtkFactory is a base class to create #GtkWidget's from #AmtkActionInfo's.
+ *
+ * A #GtkApplication can be associated so that when a widget is created,
+ * gtk_application_set_accels_for_action() is called.
+ *
+ * Once the widgets are created, an #AmtkFactory should be freed because it has
+ * a strong reference to the #GtkApplication.
+ */
+
+struct _AmtkFactoryPrivate
+{
+       GtkApplication *app;
+};
+
+enum
+{
+       PROP_0,
+       PROP_APPLICATION,
+       N_PROPERTIES
+};
+
+static GParamSpec *properties[N_PROPERTIES];
+
+G_DEFINE_TYPE_WITH_PRIVATE (AmtkFactory, amtk_factory, G_TYPE_OBJECT)
+
+static void
+amtk_factory_get_property (GObject    *object,
+                           guint       prop_id,
+                           GValue     *value,
+                           GParamSpec *pspec)
+{
+       AmtkFactory *factory = AMTK_FACTORY (object);
+
+       switch (prop_id)
+       {
+               case PROP_APPLICATION:
+                       g_value_set_object (value, amtk_factory_get_application (factory));
+                       break;
+
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                       break;
+       }
+}
+
+static void
+amtk_factory_set_property (GObject      *object,
+                           guint         prop_id,
+                           const GValue *value,
+                           GParamSpec   *pspec)
+{
+       AmtkFactory *factory = AMTK_FACTORY (object);
+
+       switch (prop_id)
+       {
+               case PROP_APPLICATION:
+                       g_assert (factory->priv->app == NULL);
+                       factory->priv->app = g_value_dup_object (value);
+                       break;
+
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                       break;
+       }
+}
+
+static void
+amtk_factory_dispose (GObject *object)
+{
+       AmtkFactory *factory = AMTK_FACTORY (object);
+
+       g_clear_object (&factory->priv->app);
+
+       G_OBJECT_CLASS (amtk_factory_parent_class)->dispose (object);
+}
+
+static void
+amtk_factory_class_init (AmtkFactoryClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       object_class->get_property = amtk_factory_get_property;
+       object_class->set_property = amtk_factory_set_property;
+       object_class->dispose = amtk_factory_dispose;
+
+       /**
+        * AmtkFactory:application:
+        *
+        * The associated #GtkApplication. #AmtkFactory has a strong reference
+        * to the #GtkApplication (which means that once the widgets are created
+        * you should free the #AmtkFactory).
+        *
+        * Since: 3.0
+        */
+       properties[PROP_APPLICATION] =
+               g_param_spec_object ("application",
+                                    "GtkApplication",
+                                    "",
+                                    GTK_TYPE_APPLICATION,
+                                    G_PARAM_READWRITE |
+                                    G_PARAM_CONSTRUCT_ONLY |
+                                    G_PARAM_STATIC_STRINGS);
+
+       g_object_class_install_properties (object_class, N_PROPERTIES, properties);
+}
+
+static void
+amtk_factory_init (AmtkFactory *factory)
+{
+       factory->priv = amtk_factory_get_instance_private (factory);
+}
+
+/**
+ * amtk_factory_get_application:
+ * @factory: an #AmtkFactory.
+ *
+ * Returns: (transfer none): the #AmtkFactory:application.
+ * Since: 3.0
+ */
+GtkApplication *
+amtk_factory_get_application (AmtkFactory *factory)
+{
+       g_return_val_if_fail (AMTK_IS_FACTORY (factory), NULL);
+
+       return factory->priv->app;
+}
diff --git a/amtk/amtk-factory.h b/amtk/amtk-factory.h
new file mode 100644
index 0000000..9fcc701
--- /dev/null
+++ b/amtk/amtk-factory.h
@@ -0,0 +1,60 @@
+/*
+ * This file is part of Amtk - Actions, Menus and Toolbars Kit
+ *
+ * Copyright 2017 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * Amtk 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.
+ *
+ * Amtk 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef AMTK_FACTORY_H
+#define AMTK_FACTORY_H
+
+#if !defined (AMTK_H_INSIDE) && !defined (AMTK_COMPILATION)
+#error "Only <amtk/amtk.h> can be included directly."
+#endif
+
+#include <gtk/gtk.h>
+#include <amtk/amtk-types.h>
+
+G_BEGIN_DECLS
+
+#define AMTK_TYPE_FACTORY             (amtk_factory_get_type ())
+#define AMTK_FACTORY(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), AMTK_TYPE_FACTORY, AmtkFactory))
+#define AMTK_FACTORY_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), AMTK_TYPE_FACTORY, 
AmtkFactoryClass))
+#define AMTK_IS_FACTORY(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AMTK_TYPE_FACTORY))
+#define AMTK_IS_FACTORY_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), AMTK_TYPE_FACTORY))
+#define AMTK_FACTORY_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), AMTK_TYPE_FACTORY, 
AmtkFactoryClass))
+
+typedef struct _AmtkFactoryClass    AmtkFactoryClass;
+typedef struct _AmtkFactoryPrivate  AmtkFactoryPrivate;
+
+struct _AmtkFactory
+{
+       GObject parent;
+
+       AmtkFactoryPrivate *priv;
+};
+
+struct _AmtkFactoryClass
+{
+       GObjectClass parent_class;
+};
+
+GType                  amtk_factory_get_type                   (void);
+
+GtkApplication *       amtk_factory_get_application            (AmtkFactory *factory);
+
+G_END_DECLS
+
+#endif /* AMTK_FACTORY_H */
diff --git a/amtk/amtk-types.h b/amtk/amtk-types.h
index a51ae61..c5f0767 100644
--- a/amtk/amtk-types.h
+++ b/amtk/amtk-types.h
@@ -33,6 +33,7 @@ typedef struct _AmtkActionInfoEntry           AmtkActionInfoEntry;
 typedef struct _AmtkActionInfoStore            AmtkActionInfoStore;
 typedef struct _AmtkActionInfoCentralStore     AmtkActionInfoCentralStore;
 typedef struct _AmtkApplicationWindow          AmtkApplicationWindow;
+typedef struct _AmtkFactory                    AmtkFactory;
 typedef struct _AmtkMenuFactory                        AmtkMenuFactory;
 typedef struct _AmtkMenuShell                  AmtkMenuShell;
 
diff --git a/amtk/amtk.h b/amtk/amtk.h
index b455feb..c6e8ba3 100644
--- a/amtk/amtk.h
+++ b/amtk/amtk.h
@@ -29,6 +29,7 @@
 #include <amtk/amtk-action-info-central-store.h>
 #include <amtk/amtk-action-map.h>
 #include <amtk/amtk-application-window.h>
+#include <amtk/amtk-factory.h>
 #include <amtk/amtk-menu-factory.h>
 #include <amtk/amtk-menu-item.h>
 #include <amtk/amtk-menu-shell.h>
diff --git a/docs/reference/tepl-3.0-sections.txt b/docs/reference/tepl-3.0-sections.txt
index 71b8fb6..d1143ad 100644
--- a/docs/reference/tepl-3.0-sections.txt
+++ b/docs/reference/tepl-3.0-sections.txt
@@ -91,6 +91,22 @@ amtk_action_map_add_action_entries_check_dups
 </SECTION>
 
 <SECTION>
+<FILE>amtk-factory</FILE>
+AmtkFactory
+amtk_factory_get_application
+<SUBSECTION Standard>
+AMTK_FACTORY
+AMTK_FACTORY_CLASS
+AMTK_FACTORY_GET_CLASS
+AMTK_IS_FACTORY
+AMTK_IS_FACTORY_CLASS
+AMTK_TYPE_FACTORY
+AmtkFactoryClass
+AmtkFactoryPrivate
+amtk_factory_get_type
+</SECTION>
+
+<SECTION>
 <FILE>amtk-menu-factory</FILE>
 AmtkMenuFactory
 amtk_menu_factory_new
diff --git a/docs/reference/tepl-docs.xml.in b/docs/reference/tepl-docs.xml.in
index 74514bf..d82a1a2 100644
--- a/docs/reference/tepl-docs.xml.in
+++ b/docs/reference/tepl-docs.xml.in
@@ -24,6 +24,7 @@
       <xi:include href="xml/amtk-action-info-store.xml"/>
       <xi:include href="xml/amtk-action-info-central-store.xml"/>
       <xi:include href="xml/amtk-action-map.xml"/>
+      <xi:include href="xml/amtk-factory.xml"/>
       <xi:include href="xml/amtk-menu-factory.xml"/>
       <xi:include href="xml/amtk-menu-item.xml"/>
       <xi:include href="xml/amtk-menu-shell.xml"/>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3a2ea84..0bee7e4 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -4,6 +4,7 @@ amtk/amtk-action-info-central-store.c
 amtk/amtk-action-info-store.c
 amtk/amtk-action-map.c
 amtk/amtk-application-window.c
+amtk/amtk-factory.c
 amtk/amtk-menu-factory.c
 amtk/amtk-menu-item.c
 amtk/amtk-menu-shell.c


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]