[gnome-builder] meson-templates: add gtkmm application template



commit 54ffcd28be1187a0152a570a338b1b4659be7041
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jan 15 01:17:38 2018 -0800

    meson-templates: add gtkmm application template
    
    This does the same sort of HelloWorld gtk application using
    C++ and gtkmm.
    
    Fixes #245

 .../meson-templates/meson-templates.gresource.xml  |   7 +-
 src/plugins/meson-templates/meson_templates.py     |   9 +-
 src/plugins/meson-templates/resources/flatpak.json | 180 +++++++++++++++------
 src/plugins/meson-templates/resources/meson.build  |   8 +-
 src/plugins/meson-templates/resources/src/main.cpp |  49 ++++++
 .../resources/src/meson-c-vala.build               |  17 +-
 .../meson-templates/resources/src/window.cpp       |  18 +++
 .../meson-templates/resources/src/window.hpp       |  19 +++
 .../meson-templates/resources/src/window.ui        |  16 ++
 9 files changed, 266 insertions(+), 57 deletions(-)
---
diff --git a/src/plugins/meson-templates/meson-templates.gresource.xml 
b/src/plugins/meson-templates/meson-templates.gresource.xml
index 67cb444d9..a7042c2c8 100644
--- a/src/plugins/meson-templates/meson-templates.gresource.xml
+++ b/src/plugins/meson-templates/meson-templates.gresource.xml
@@ -17,9 +17,12 @@
     <file compressed="true">resources/src/gi_composites.py</file>
     <file compressed="true">resources/src/main.js</file>
     <file compressed="true">resources/src/main.c</file>
-    <file compressed="true">resources/src/window.py</file>
-    <file compressed="true">resources/src/window.c</file>
+    <file compressed="true">resources/src/main.cpp</file>
     <file compressed="true">resources/src/hello.src.gresource.xml</file>
+    <file compressed="true">resources/src/window.c</file>
+    <file compressed="true">resources/src/window.cpp</file>
+    <file compressed="true">resources/src/window.hpp</file>
+    <file compressed="true">resources/src/window.py</file>
     <file compressed="true">resources/src/window.vala</file>
     <file compressed="true">resources/src/main.vala</file>
     <file compressed="true">resources/src/hello.py.in</file>
diff --git a/src/plugins/meson-templates/meson_templates.py b/src/plugins/meson-templates/meson_templates.py
index b9604a6c9..9ce2aee67 100644
--- a/src/plugins/meson-templates/meson_templates.py
+++ b/src/plugins/meson-templates/meson_templates.py
@@ -150,7 +150,7 @@ class MesonTemplate(Ide.TemplateBase, Ide.ProjectTemplate):
         scope.get('author').assign_string(author_name)
 
         # Just avoiding dealing with template bugs
-        if self.language == 'c':
+        if self.language in ('c', 'c++'):
             ui_file = prefix + '-window.ui'
         else:
             ui_file = 'window.ui'
@@ -226,7 +226,7 @@ class GnomeProjectTemplate(MesonTemplate):
             _('GNOME Application'),
             'pattern-gnome',
             _('Create a new GNOME application'),
-            ['C', 'Python', 'JavaScript', 'Vala']
+            ['C', 'C++', 'Python', 'JavaScript', 'Vala']
          )
 
     def prepare_files(self, files):
@@ -249,6 +249,11 @@ class GnomeProjectTemplate(MesonTemplate):
             files['resources/src/window.c'] = 'src/%(prefix)s-window.c'
             files['resources/src/window.h'] = 'src/%(prefix)s-window.h'
             window_ui_name = 'src/%(prefix)s-window.ui'
+        elif self.language == 'c++':
+            files['resources/src/main.cpp'] = 'src/main.cpp'
+            files['resources/src/window.cpp'] = 'src/%(prefix)s-window.cpp'
+            files['resources/src/window.hpp'] = 'src/%(prefix)s-window.h'
+            window_ui_name = 'src/%(prefix)s-window.ui'
         elif self.language == 'vala':
             files['resources/src/main.vala'] = 'src/main.vala'
             files['resources/src/window.vala'] = 'src/window.vala'
diff --git a/src/plugins/meson-templates/resources/flatpak.json 
b/src/plugins/meson-templates/resources/flatpak.json
index 3bd4e93b0..282c1864a 100644
--- a/src/plugins/meson-templates/resources/flatpak.json
+++ b/src/plugins/meson-templates/resources/flatpak.json
@@ -1,52 +1,134 @@
 {
-  "app-id": "{{appid}}",
-  "runtime": "org.gnome.Platform",
-  "runtime-version": "master",
-  "sdk": "org.gnome.Sdk",
-  "command": "{{exec_name}}",
-  "finish-args": [
-    "--share=network",
-    "--share=ipc",
-    "--socket=x11",
-    "--socket=wayland",
-    "--filesystem=xdg-run/dconf",
-    "--filesystem=~/.config/dconf:ro",
-    "--talk-name=ca.desrt.dconf",
-    "--env=DCONF_USER_CONFIG_DIR=.config/dconf"
-  ],
-  "build-options": {
-    "cflags": "-O2 -g",
-    "cxxflags": "-O2 -g",
-    "env": {
-      "V": "1"
-    }
-  },
-  "cleanup": [
-    "/include",
-    "/lib/pkgconfig",
-    "/man",
-    "/share/doc",
-    "/share/gtk-doc",
-    "/share/man",
-    "/share/pkgconfig",
-{{if language == "vala"}}    "/share/vala",{{end}}
-    "*.la",
-    "*.a"
-  ],
-  "modules": [
-    {
-      "name": "{{name}}",
-      "buildsystem": "meson",
-      "config-opts": [
-        "--libdir=lib"
-      ],
-      "builddir": true,
-      "sources": [
-        {
-          "type": "git",
-          "url": "file://{{project_path}}"
+    "app-id": "{{appid}}",
+    "runtime": "org.gnome.Platform",
+    "runtime-version": "master",
+    "sdk": "org.gnome.Sdk",
+    "command": "{{exec_name}}",
+    "finish-args": [
+        "--share=network",
+        "--share=ipc",
+        "--socket=x11",
+        "--socket=wayland",
+        "--filesystem=xdg-run/dconf",
+        "--filesystem=~/.config/dconf:ro",
+        "--talk-name=ca.desrt.dconf",
+        "--env=DCONF_USER_CONFIG_DIR=.config/dconf"
+    ],
+    "build-options": {
+        "cflags": "-O2 -g",
+        "cxxflags": "-O2 -g",
+        "env": {
+            "V": "1"
         }
-      ]
-    }
-  ]
+    },
+    "cleanup": [
+        "/include",
+        "/lib/pkgconfig",
+        "/man",
+        "/share/doc",
+        "/share/gtk-doc",
+        "/share/man",
+        "/share/pkgconfig",
+{{if language == "vala"}}
+        "/share/vala",
+{{end}}
+        "*.la",
+        "*.a"
+    ],
+    "modules": [
+{{if template == "gnome-app"}}
+{{if language == "c++"}}
+        {
+           "name": "mm-common",
+           "cleanup": [ "/" ],
+           "sources": [
+               {
+                   "type": "archive",
+                   "url": "http://ftp.gnome.org/pub/GNOME/sources/mm-common/0.9/mm-common-0.9.9.tar.xz";,
+                   "sha256": "9d00bc77e77794e0bd2ae68132c4b4136aa115d255e34b310f7449b29db50b7a"
+               }
+           ]
+        },
+        {
+            "name": "sigc++",
+            "config-opts": [ "--disable-documentation" ],
+            "sources": [
+                {
+                    "type": "archive",
+                    "url": "http://ftp.gnome.org/pub/GNOME/sources/libsigc++/2.9/libsigc++-2.9.3.tar.xz";,
+                    "sha256": "0bf9b301ad6198c550986c51150a646df198e8d1d235270c16486b0dda30097f"
+                }
+            ]
+        },
+        {
+            "name": "glibmm",
+            "config-opts": [ "--disable-documentation" ],
+            "sources": [
+                {
+                    "type": "archive",
+                    "url": "http://ftp.acc.umu.se/pub/GNOME/sources/glibmm/2.50/glibmm-2.50.1.tar.xz";,
+                    "sha256": "1fd85051da9cb402cc8348cec72dfe4d79f9345df4a1dbf68703a4ded45846a4"
+                }
+            ]
+        },
+        {
+            "name": "cairomm",
+            "config-opts": [ "--disable-documentation" ],
+            "sources": [
+                {
+                    "type": "archive",
+                    "url": "http://cairographics.org/releases/cairomm-1.12.0.tar.gz";,
+                    "sha256": "50435aec6fdd976934b791e808993160113ad19ca53a5634a9b64ccbe55874cc"
+                }
+            ]
+        },
+        {
+            "name": "pangomm",
+            "config-opts": [ "--disable-documentation" ],
+            "sources": [
+                {
+                    "type": "archive",
+                    "url": "http://ftp.acc.umu.se/pub/GNOME/sources/pangomm/2.40/pangomm-2.40.1.tar.xz";,
+                    "sha256": "9762ee2a2d5781be6797448d4dd2383ce14907159b30bc12bf6b08e7227be3af"
+                }
+            ]
+        },
+        {
+            "name": "atkmm",
+            "config-opts": [ "--disable-documentation" ],
+            "sources": [
+                {
+                    "type": "archive",
+                    "url": "http://ftp.gnome.org/pub/GNOME/sources/atkmm/2.24/atkmm-2.24.2.tar.xz";,
+                    "sha256": "ff95385759e2af23828d4056356f25376cfabc41e690ac1df055371537e458bd"
+                }
+            ]
+        },
+        {
+            "name": "gtkmm",
+            "config-opts": [ "--disable-documentation" ],
+            "build-options": { "cxxflags": "-O2 -g -std=c++11" },
+            "sources": [
+                {
+                    "type": "archive",
+                    "url": "http://ftp.gnome.org/pub/GNOME/sources/gtkmm/3.22/gtkmm-3.22.2.tar.xz";,
+                    "sha256": "91afd98a31519536f5f397c2d79696e3d53143b80b75778521ca7b48cb280090"
+                }
+            ]
+        }, 
+{{end}}
+{{end}}
+        {
+            "name": "{{name}}",
+            "buildsystem": "meson",
+            "config-opts": [ "--libdir=lib" ],
+            "builddir": true,
+            "sources": [
+                {
+                    "type": "git",
+                    "url": "file://{{project_path}}"
+                }
+            ]
+        }
+    ]
 }
diff --git a/src/plugins/meson-templates/resources/meson.build 
b/src/plugins/meson-templates/resources/meson.build
index 3ee0032f8..9b6c822b1 100644
--- a/src/plugins/meson-templates/resources/meson.build
+++ b/src/plugins/meson-templates/resources/meson.build
@@ -2,8 +2,14 @@ project('{{name}}',{{if language == "c"}} 'c',{{else if language == "c++"}} 'cpp
         version: '{{project_version}}',
   meson_version: '>= 0.40.0',
 )
+
 {{if enable_i18n}}
-i18n = import('i18n'){{end}}
+i18n = import('i18n')
+{{end}}
+
+{{if language == "c++"}}
+add_languages('c')
+{{end}}
 
 {{if language == "c"}}
 config_h = configuration_data()
diff --git a/src/plugins/meson-templates/resources/src/main.cpp 
b/src/plugins/meson-templates/resources/src/main.cpp
new file mode 100644
index 000000000..f8ae8aed6
--- /dev/null
+++ b/src/plugins/meson-templates/resources/src/main.cpp
@@ -0,0 +1,49 @@
+{{include "license.cpp"}}
+
+#include "{{prefix}}-window.h"
+
+static void
+on_activate (Glib::RefPtr<Gtk::Application> app)
+{
+       // Get the current window. If there is not one, we will create it.
+       Gtk::Window *window = app->get_active_window();
+
+       if (!window) {
+               window = new {{Prefix}}Window();
+               window->property_application() = app;
+               window->property_default_width() = 600;
+               window->property_default_height() = 300;
+               app->add_window(*window);
+       }
+
+       // Ask the window manager/compositor to present the window to the user.
+       window->present();
+}
+
+int
+main (int argc, char *argv[])
+{
+       int ret;
+
+       // Create a new Gtk::Application. The application manages our main loop,
+       // application windows, integration with the window manager/compositor, and
+       // desktop features such as file opening and single-instance applications.
+       Glib::RefPtr<Gtk::Application> app =
+               Gtk::Application::create("{{appid}}", Gio::APPLICATION_FLAGS_NONE);
+
+       // We connect to the activate signal to create a window when the application
+       // has been lauched. Additionally, this signal notifies us when the user
+       // tries to launch a "second instance" of the application. When they try
+       // to do that, we'll just present any existing window.
+       //
+       // Bind the app object to be passed to the callback "on_activate"
+       app->signal_activate().connect(sigc::bind(&on_activate, app));
+
+       // Run the application. This function will block until the applicaiton
+       // exits. Upon return, we have our exit code to return to the shell. (This
+       // is the code you see when you do `echo $?` after running a command in a
+       // terminal.
+       ret = app->run(argc, argv);
+
+       return ret;
+}
diff --git a/src/plugins/meson-templates/resources/src/meson-c-vala.build 
b/src/plugins/meson-templates/resources/src/meson-c-vala.build
index 4b0a34bae..baf5414d4 100644
--- a/src/plugins/meson-templates/resources/src/meson-c-vala.build
+++ b/src/plugins/meson-templates/resources/src/meson-c-vala.build
@@ -1,12 +1,23 @@
 {{name_}}_sources = [
-  {{if language == "c"}}'main.c',
-  '{{prefix}}-window.c',{{else if  language == "vala"}}'main.vala',
-  'window.vala',{{end}}
+{{if language == "c"}}
+  'main.c',
+  '{{prefix}}-window.c',
+{{else if language == "c++"}}
+  'main.cpp',
+  '{{prefix}}-window.cpp',
+{{else if language == "vala"}}
+  'main.vala',
+  'window.vala',
+{{end}}
 ]
 
 {{name_}}_deps = [
+{{if language == "c++"}}
+  dependency('gtkmm-3.0', version: '>= 3.18'),
+{{else}}
   dependency('gio-2.0', version: '>= 2.50'),
   dependency('gtk+-3.0', version: '>= 3.22'),
+{{end}}
 ]
 
 gnome = import('gnome')
diff --git a/src/plugins/meson-templates/resources/src/window.cpp 
b/src/plugins/meson-templates/resources/src/window.cpp
new file mode 100644
index 000000000..44060f0d8
--- /dev/null
+++ b/src/plugins/meson-templates/resources/src/window.cpp
@@ -0,0 +1,18 @@
+{{include "license.cpp"}}
+
+#include "{{prefix}}-window.h"
+
+{{Prefix}}Window::{{Prefix}}Window()
+       : Glib::ObjectBase("{{Prefix}}Window")
+       , Gtk::Window()
+       , headerbar(nullptr)
+       , label(nullptr)
+{
+       builder = Gtk::Builder::create_from_resource("{{appid_path}}/{{ui_file}}");
+       builder->get_widget("headerbar", headerbar);
+       builder->get_widget("label", label);
+       add(*label);
+       label->show();
+       set_titlebar(*headerbar);
+       headerbar->show();
+}
diff --git a/src/plugins/meson-templates/resources/src/window.hpp 
b/src/plugins/meson-templates/resources/src/window.hpp
new file mode 100644
index 000000000..e1151cb66
--- /dev/null
+++ b/src/plugins/meson-templates/resources/src/window.hpp
@@ -0,0 +1,19 @@
+{{include "license.cpp"}}
+
+#pragma once
+
+#include <gtkmm/builder.h>
+#include <gtkmm/headerbar.h>
+#include <gtkmm/label.h>
+#include <gtkmm/window.h>
+
+class {{Prefix}}Window : public Gtk::Window
+{
+public:
+       {{Prefix}}Window();
+
+private:
+       Gtk::HeaderBar *headerbar;
+       Gtk::Label *label;
+       Glib::RefPtr<Gtk::Builder> builder;
+};
diff --git a/src/plugins/meson-templates/resources/src/window.ui 
b/src/plugins/meson-templates/resources/src/window.ui
index c95713524..3478b2b72 100644
--- a/src/plugins/meson-templates/resources/src/window.ui
+++ b/src/plugins/meson-templates/resources/src/window.ui
@@ -1,5 +1,20 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
+{{if language == "c++"}}
+  <object class="GtkHeaderBar" id="headerbar">
+    <property name="can_focus">False</property>
+    <property name="title">Hello, World!</property>
+    <property name="show_close_button">True</property>
+  </object>
+  <object class="GtkLabel" id="label">
+    <property name="can_focus">False</property>
+    <property name="label">Hello, World!</property>
+    <attributes>
+      <attribute name="weight" value="bold"/>
+      <attribute name="scale" value="2"/>
+    </attributes>
+  </object>
+{{else}}
   <template class="{{PreFix}}Window" parent="GtkApplicationWindow">
     <property name="default-width">600</property>
     <property name="default-height">300</property>
@@ -21,4 +36,5 @@
       </object>
     </child>
   </template>
+{{end}}
 </interface>


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