[five-or-more/gsoc-vala-port: 5/29] Add Vala application window



commit e59a6267b8438b9a99ac343f3adb5ced57417637
Author: Ruxandra Simion <ruxandra simion93 gmail com>
Date:   Sun May 27 20:40:16 2018 +0300

    Add Vala application window

 data/five-or-more-vala.ui                 | 93 +++++++++++++++++++++++++++++++
 data/meson.build                          |  4 ++
 data/org.gnome.five-or-more.gresource.xml |  6 ++
 meson.build                               | 15 +++--
 src-vala/config.vapi                      |  4 ++
 src-vala/main.vala                        | 20 +++++++
 src-vala/meson.build                      | 23 ++++++++
 src-vala/window.vala                      |  9 +++
 8 files changed, 170 insertions(+), 4 deletions(-)
---
diff --git a/data/five-or-more-vala.ui b/data/five-or-more-vala.ui
new file mode 100644
index 0000000..33aef5d
--- /dev/null
+++ b/data/five-or-more-vala.ui
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkAccelGroup" id="accelgroup"/>
+  <template class="FiveOrMoreWindow" parent="GtkApplicationWindow">
+    <property name="can_focus">False</property>
+    <property name="default_width">320</property>
+    <property name="default_height">400</property>
+    <property name="icon_name">glines</property>
+    <accel-groups>
+      <group name="accelgroup"/>
+    </accel-groups>
+    <child type="titlebar">
+      <object class="GtkHeaderBar" id="headerbar">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="show_close_button">True</property>
+        <property name="title" translatable="yes">Five or More</property>
+        <child>
+          <object class="GtkBox" id="preview_hbox">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="orientation">horizontal</property>
+            <child>
+              <object class="GtkLabel" id="labelNext">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="margin_start">2</property>
+                <property name="margin_end">2</property>
+                <property name="label" translatable="yes">Next:</property>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                </attributes>
+              </object>
+              <packing>
+                <property name="pack_type">start</property>
+              </packing>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="scorelabel">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="margin_end">2</property>
+            <property name="label">0</property>
+          </object>
+          <packing>
+            <property name="pack_type">end</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="labelScore">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">Score:</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+            </attributes>
+          </object>
+          <packing>
+            <property name="pack_type">end</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <child>
+      <object class="GtkBox" id="hbox">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">horizontal</property>
+        <child>
+          <object class="GtkButton" id="new_game_button">
+                <property name="visible">True</property>
+                <property name="use_underline">True</property>
+                <property name="label" translatable="yes">_New Game</property>
+                <property name="halign">center</property>
+                <property name="valign">end</property>
+                <property name="action-name">app.new-game</property>
+                <property name="tooltip-text" translatable="yes">Start a new puzzle</property>
+                <property name="width-request">120</property>
+                <property name="height-request">60</property>
+            </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="pack_type">end</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/data/meson.build b/data/meson.build
index c234589..92f18d2 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -47,6 +47,10 @@ install_data('org.gnome.five-or-more.gschema.xml',
        install_dir: join_paths(data_dir, 'glib-2.0', 'schemas')
 )
 
+# Gresource
+resource_files = files('org.gnome.five-or-more.gresource.xml')
+resources = gnome.compile_resources('five-or-more', resource_files)
+
 # Manpage
 install_man(
        'five-or-more.6'
diff --git a/data/org.gnome.five-or-more.gresource.xml b/data/org.gnome.five-or-more.gresource.xml
new file mode 100644
index 0000000..330568f
--- /dev/null
+++ b/data/org.gnome.five-or-more.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/five-or-more/ui">
+    <file>five-or-more-vala.ui</file>
+  </gresource>
+</gresources>
diff --git a/meson.build b/meson.build
index 4112562..06747c5 100644
--- a/meson.build
+++ b/meson.build
@@ -1,7 +1,7 @@
-project('five-or-more', ['c'],
-       version: '3.29.3',
-       meson_version: '>= 0.43.0',
-       license: 'GPLv2'
+project('five-or-more', ['c', 'vala'],
+  version: '3.29.3',
+  meson_version: '>= 0.43.0',
+  license: 'GPLv2'
 )
 
 gnome = import('gnome')
@@ -37,6 +37,12 @@ conf.set_quoted('VERSION', meson.project_version())
 configure_file(output: 'config.h', configuration: conf)
 config_h_dir = include_directories('.')
 
+add_project_arguments([
+    '-include', 'config.h'
+  ],
+  language: 'c'
+)
+
 # Extra scripts
 meson.add_install_script('meson_post_install.py')
 
@@ -45,3 +51,4 @@ subdir('data')
 subdir('help')
 subdir('po')
 subdir('src')
+subdir('src-vala')
diff --git a/src-vala/config.vapi b/src-vala/config.vapi
new file mode 100644
index 0000000..e567943
--- /dev/null
+++ b/src-vala/config.vapi
@@ -0,0 +1,4 @@
+public const string DATADIR;
+public const string GETTEXT_PACKAGE;
+public const string LOCALEDIR;
+public const string VERSION;
diff --git a/src-vala/main.vala b/src-vala/main.vala
new file mode 100644
index 0000000..a730e1a
--- /dev/null
+++ b/src-vala/main.vala
@@ -0,0 +1,20 @@
+public class FiveOrMoreApp: Gtk.Application {
+    private Gtk.Window window;
+
+    public FiveOrMoreApp () {
+        Object (application_id: "org.gnome.five-or-more", flags: ApplicationFlags.FLAGS_NONE);
+    }
+
+    public override void activate () {
+        window = new FiveOrMore.Window(this);
+        window.present ();
+    }
+
+    public static int main (string[] args) {
+        Environment.set_application_name (_("Five or More"));
+        Gtk.Window.set_default_icon_name ("five-or-more");
+
+        var app = new FiveOrMoreApp ();
+        return app.run (args);
+    }
+}
diff --git a/src-vala/meson.build b/src-vala/meson.build
new file mode 100644
index 0000000..1cbc0eb
--- /dev/null
+++ b/src-vala/meson.build
@@ -0,0 +1,23 @@
+#five-or-more executable
+
+five_or_more_sources = [
+  'config.vapi',
+  'main.vala',
+  'window.vala',
+  resources
+]
+
+five_or_more_deps = [
+  gio_dep,
+  gtk_dep,
+]
+
+five_or_more_vala_args = [
+  '--gresources', resource_files,
+]
+
+executable('five-or-more-vala', five_or_more_sources,
+  dependencies: five_or_more_deps,
+  vala_args: five_or_more_vala_args,
+  install: true,
+)
diff --git a/src-vala/window.vala b/src-vala/window.vala
new file mode 100644
index 0000000..67e87d3
--- /dev/null
+++ b/src-vala/window.vala
@@ -0,0 +1,9 @@
+namespace FiveOrMore {
+    [GtkTemplate (ui = "/org/gnome/five-or-more/ui/five-or-more-vala.ui")]
+    public class Window : Gtk.ApplicationWindow {
+
+        public Window (Gtk.Application app) {
+            Object (application: app);
+        }
+    }
+}


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