[gnome-builder/wip/chergert/meson-templates] wip: use application/window in meson templates



commit a1c0fdded0c4a679ff1de76f8d61ded8fd1170fc
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jun 12 00:46:37 2017 -0700

    wip: use application/window in meson templates

 .../meson_templates/resources/src/application.c    |   65 ++++++++++++++++++++
 .../meson_templates/resources/src/application.h    |   18 ++++++
 .../meson_templates/resources/src/main.c           |   17 +++--
 .../meson_templates/resources/src/window.c         |   25 ++++++++
 .../meson_templates/resources/src/window.h         |   10 +++
 .../meson_templates/resources/src/window.ui        |   17 +++++
 6 files changed, 146 insertions(+), 6 deletions(-)
---
diff --git a/plugins/meson-templates/meson_templates/resources/src/application.c 
b/plugins/meson-templates/meson_templates/resources/src/application.c
new file mode 100644
index 0000000..f1ea630
--- /dev/null
+++ b/plugins/meson-templates/meson_templates/resources/src/application.c
@@ -0,0 +1,65 @@
+{{include "license.c"}}
+
+#include "{{module}}-application.h"
+#include "{{module}}-window.h"
+
+/**
+ * SECTION:{{module}}-application
+ * @title: {{Module}}Application
+ * @short_description: The {{module}} application controller
+ *
+ * The #{{Module}}Application is responsible for managing the application
+ * process. This includes showing windows, driving integration with the
+ * desktop, and other global process management.
+ */
+
+struct _{{Module}}Application
+{
+  GtkApplication parent_instance;
+};
+
+G_DECLARE_TYPE ({{Module}}Application, {{module}}_application, GTK_TYPE_APPLICATION)
+
+static void
+{{module}}_application_activate (GApplication *app)
+{
+  GtkWindow *window;
+
+  g_assert ({{MODULE}}_IS_APPLICATION (app));
+
+  window = gtk_application_get_active_window (GTK_APPLICATION (app));
+  if (window == NULL)
+    window = g_object_new ({{MODULE}}_TYPE_WINDOW,
+                           "application", app,
+                           NULL);
+
+  gtk_window_present (window);
+}
+
+static void
+{{module}}_application_class_init ({{Module}}ApplicationClass *klass)
+{
+  GApplicationClass *app_class = G_APPLICATION_CLASS (klass);
+
+  app_class->activate = {{module}}_application_activate;
+}
+
+static void
+{{module}}_application_init ({{Module}}Application *self)
+{
+}
+
+/**
+ * {{module}}_application_new:
+ *
+ * Creates a new instance of the #{{Module}}Application.
+ *
+ * Returns: (transfer full): A #{{Module}}Application.
+ */
+{{Module}}Application *
+{{module}}_application_new (void)
+{
+  return g_object_new ({{MODULE}}_TYPE_APPLICATION,
+                       "application-id", "{{application_id}}",
+                       NULL);
+}
diff --git a/plugins/meson-templates/meson_templates/resources/src/application.h 
b/plugins/meson-templates/meson_templates/resources/src/application.h
new file mode 100644
index 0000000..602fa79
--- /dev/null
+++ b/plugins/meson-templates/meson_templates/resources/src/application.h
@@ -0,0 +1,18 @@
+{{include "license.h"}}
+
+#ifndef {{MODULE}}_APPLICATION_H
+#define {{MODULE}}_APPLICATION_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define {{MODULE}}_TYPE_APPLICATION ({{module}}_application_get_type())
+
+G_DECLARE_FINAL_TYPE ({{Module}}Application, {{module}}_application, {{MODULE}}, APPLICATION, GtkApplication)
+
+{{Module}}Application *{{module}}_application_new (void);
+
+G_END_DECLS
+
+#endif /* {{MODULE}}_APPLICATION_H */
diff --git a/plugins/meson-templates/meson_templates/resources/src/main.c 
b/plugins/meson-templates/meson_templates/resources/src/main.c
index a501eb2..241f386 100644
--- a/plugins/meson-templates/meson_templates/resources/src/main.c
+++ b/plugins/meson-templates/meson_templates/resources/src/main.c
@@ -1,21 +1,26 @@
 {{include "license.c"}}
 
-#ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
 
 {{if enable_i18n}}#include <glib/gi18n.h>{{end}}
-#include <glib.h>
+
+#include "{{module}}-application.h"
 
 int
-main(int   argc,
-     char *argv[])
+main (int   argc,
+      char *argv[])
 {
+  g_autoptr({{Module}}Application) app = NULL;
+  gint ret;
+
 {{if enable_i18n}}
   bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
   textdomain (GETTEXT_PACKAGE);
 {{end}}
 
-  return 0;
+  app = {{module}}_application_new ();
+  ret = g_application_run (G_APPLICATION (app), argc, argv);
+
+  return ret;
 }
diff --git a/plugins/meson-templates/meson_templates/resources/src/window.c 
b/plugins/meson-templates/meson_templates/resources/src/window.c
new file mode 100644
index 0000000..af8d576
--- /dev/null
+++ b/plugins/meson-templates/meson_templates/resources/src/window.c
@@ -0,0 +1,25 @@
+{{include "license.c"}}
+
+#include "{{module}}-window.h"
+
+struct _{{Module}}Window
+{
+  GtkApplicationWindow parent_instance;
+
+  GtkHeaderBar *header_bar;
+};
+
+static void
+{{module}}_window_class_init ({{Module}}WindowClass *klass)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  gtk_widget_class_set_template_from_resource (widget_class, "{{application_path}}");
+  gtk_widget_class_bind_template_child (widget_class, {{Module}}Window, header_bar);
+}
+
+static void
+{{module}}_window_init ({{Module}}Window *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
diff --git a/plugins/meson-templates/meson_templates/resources/src/window.h 
b/plugins/meson-templates/meson_templates/resources/src/window.h
new file mode 100644
index 0000000..b4d95c3
--- /dev/null
+++ b/plugins/meson-templates/meson_templates/resources/src/window.h
@@ -0,0 +1,10 @@
+{{include "license.h"}}
+
+#ifndef {{MODULE}}_WINDOW_H
+#define {{MODULE}}_WINDOW_H
+
+#define {{MODULE}}_TYPE_WINDOW ({{module}}_window_get_type())
+
+G_DECLARE_FINAL_TYPE ({{Module}}Window, {{module}}_window, {{MODULE}}, WINDOW, GtkApplicationWindow)
+
+#endif /* {{MODULE}}_WINDOW_H */
diff --git a/plugins/meson-templates/meson_templates/resources/src/window.ui 
b/plugins/meson-templates/meson_templates/resources/src/window.ui
new file mode 100644
index 0000000..3023d31
--- /dev/null
+++ b/plugins/meson-templates/meson_templates/resources/src/window.ui
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="{{Module}}Window" parent="GtkApplicationWindow">
+    <child type="titlebar">
+      <object class"GtkHeaderBar" id="header_bar">
+        <property name="visible">true</property>
+        <property name="show-close-button">true</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkLabel">
+        <property name="label">Hello, World!</property>
+        <property name="visible">true</property>
+      </object>
+    </child>
+  </template>
+</interface>


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