[libdazzle] example-app: start putting together an example app
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libdazzle] example-app: start putting together an example app
- Date: Wed, 7 Jun 2017 04:49:29 +0000 (UTC)
commit a750d157a961453ad92ee7187ee1ee3a7004fee2
Author: Christian Hergert <chergert redhat com>
Date: Tue Jun 6 21:49:06 2017 -0700
example-app: start putting together an example app
This is some stubs for how to use various components. Of
course, there is still plenty to do.
examples/app/README.md | 6 ++
examples/app/example-application.c | 87 +++++++++++++++++++++++++++++++++++
examples/app/example-application.h | 14 ++++++
examples/app/example-window.c | 32 +++++++++++++
examples/app/example-window.h | 16 ++++++
examples/app/example-window.ui | 10 ++++
examples/app/example.gresources.xml | 10 ++++
examples/app/gtk/menus.ui | 20 ++++++++
examples/app/main.c | 17 +++++++
examples/app/meson.build | 20 ++++++++
meson.build | 1 +
11 files changed, 233 insertions(+), 0 deletions(-)
---
diff --git a/examples/app/README.md b/examples/app/README.md
new file mode 100644
index 0000000..0c5a29d
--- /dev/null
+++ b/examples/app/README.md
@@ -0,0 +1,6 @@
+# Example Application
+
+This directory contains a sample application built using various components of libdazzle.
+It can service as a tutorial of how to build your application to get the most out of libdazzle.
+
+
diff --git a/examples/app/example-application.c b/examples/app/example-application.c
new file mode 100644
index 0000000..681db96
--- /dev/null
+++ b/examples/app/example-application.c
@@ -0,0 +1,87 @@
+#include "example-application.h"
+#include "example-window.h"
+
+struct _ExampleApplication
+{
+ DzlApplication parent_instance;
+};
+
+G_DEFINE_TYPE (ExampleApplication, example_application, DZL_TYPE_APPLICATION)
+
+static void
+example_application_activate (GApplication *app)
+{
+ GtkWindow *window;
+
+ window = gtk_application_get_active_window (GTK_APPLICATION (app));
+
+ if (window == NULL)
+ window = g_object_new (EXAMPLE_TYPE_WINDOW,
+ "application", app,
+ "default-width", 800,
+ "default-height", 600,
+ "title", "Example Window",
+ NULL);
+
+ gtk_window_present (window);
+}
+
+static void
+example_application_class_init (ExampleApplicationClass *klass)
+{
+ GApplicationClass *app_class = G_APPLICATION_CLASS (klass);
+
+ app_class->activate = example_application_activate;
+}
+
+static void
+about_activate (GSimpleAction *action,
+ GVariant *variant,
+ gpointer user_data)
+{
+ GtkAboutDialog *dialog;
+
+ dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
+ "copyright", "Copyright 2017 Christian Hergert",
+ "logo-icon-name", "org.gnome.clocks",
+ "website", "https://wiki.gnome.org/Apps/Builder",
+ "version", DZL_VERSION_S,
+ NULL);
+
+ gtk_window_present (GTK_WINDOW (dialog));
+}
+
+static void
+quit_activate (GSimpleAction *action,
+ GVariant *variant,
+ gpointer user_data)
+{
+ g_application_quit (G_APPLICATION (user_data));
+}
+
+static void
+shortcuts_activate (GSimpleAction *action,
+ GVariant *variant,
+ gpointer user_data)
+{
+ DzlShortcutsWindow *window;
+ DzlShortcutManager *manager;
+
+ manager = dzl_application_get_shortcut_manager (user_data);
+
+ window = g_object_new (DZL_TYPE_SHORTCUTS_WINDOW, NULL);
+ dzl_shortcut_manager_add_shortcuts_to_window (manager, window);
+ gtk_window_present (GTK_WINDOW (window));
+}
+
+static void
+example_application_init (ExampleApplication *self)
+{
+ static GActionEntry entries[] = {
+ { "about", about_activate },
+ { "quit", quit_activate },
+ { "shortcuts", shortcuts_activate },
+ };
+
+ g_action_map_add_action_entries (G_ACTION_MAP (self), entries, G_N_ELEMENTS (entries), self);
+}
diff --git a/examples/app/example-application.h b/examples/app/example-application.h
new file mode 100644
index 0000000..8ad96f7
--- /dev/null
+++ b/examples/app/example-application.h
@@ -0,0 +1,14 @@
+#ifndef EXAMPLE_APPLICATION_H
+#define EXAMPLE_APPLICATION_H
+
+#include <dazzle.h>
+
+G_BEGIN_DECLS
+
+#define EXAMPLE_TYPE_APPLICATION (example_application_get_type())
+
+G_DECLARE_FINAL_TYPE (ExampleApplication, example_application, EXAMPLE, APPLICATION, DzlApplication)
+
+G_END_DECLS
+
+#endif /* EXAMPLE_APPLICATION_H */
diff --git a/examples/app/example-window.c b/examples/app/example-window.c
new file mode 100644
index 0000000..96af722
--- /dev/null
+++ b/examples/app/example-window.c
@@ -0,0 +1,32 @@
+#include <dazzle.h>
+
+#include "example-window.h"
+
+struct _ExampleWindow
+{
+ GtkWindow parent_instance;
+ DzlDockBin *dockbin;
+};
+
+G_DEFINE_TYPE (ExampleWindow, example_window, GTK_TYPE_WINDOW)
+
+static void
+example_window_class_init (ExampleWindowClass *klass)
+{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/example/ui/example-window.ui");
+ gtk_widget_class_bind_template_child (widget_class, ExampleWindow, dockbin);
+}
+
+static void
+example_window_init (ExampleWindow *self)
+{
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+GtkWidget *
+example_window_new (void)
+{
+ return g_object_new (EXAMPLE_TYPE_WINDOW, NULL);
+}
diff --git a/examples/app/example-window.h b/examples/app/example-window.h
new file mode 100644
index 0000000..f848403
--- /dev/null
+++ b/examples/app/example-window.h
@@ -0,0 +1,16 @@
+#ifndef EXAMPLE_WINDOW_H
+#define EXAMPLE_WINDOW_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define EXAMPLE_TYPE_WINDOW (example_window_get_type())
+
+G_DECLARE_FINAL_TYPE (ExampleWindow, example_window, EXAMPLE, WINDOW, GtkWindow)
+
+GtkWidget *example_window_new (void);
+
+G_END_DECLS
+
+#endif /* EXAMPLE_WINDOW_H */
diff --git a/examples/app/example-window.ui b/examples/app/example-window.ui
new file mode 100644
index 0000000..1d971e2
--- /dev/null
+++ b/examples/app/example-window.ui
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="ExampleWindow" parent="GtkWindow">
+ <child>
+ <object class="DzlDockBin" id="dockbin">
+ <property name="visible">true</property>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/examples/app/example.gresources.xml b/examples/app/example.gresources.xml
new file mode 100644
index 0000000..6a6b401
--- /dev/null
+++ b/examples/app/example.gresources.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gnome/example/ui">
+ <file>example-window.ui</file>
+ </gresource>
+
+ <gresource prefix="/org/gnome/example">
+ <file>gtk/menus.ui</file>
+ </gresource>
+</gresources>
diff --git a/examples/app/gtk/menus.ui b/examples/app/gtk/menus.ui
new file mode 100644
index 0000000..765091b
--- /dev/null
+++ b/examples/app/gtk/menus.ui
@@ -0,0 +1,20 @@
+<?xml version="1.0"?>
+<interface>
+ <menu id="app-menu">
+ <section id="app-menu-help-section">
+ <attribute name="id">help-section</attribute>
+ <item>
+ <attribute name="label" translatable="yes">Keyboard _Shortcuts</attribute>
+ <attribute name="action">app.shortcuts</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_About</attribute>
+ <attribute name="action">app.about</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Quit</attribute>
+ <attribute name="action">app.quit</attribute>
+ </item>
+ </section>
+ </menu>
+</interface>
diff --git a/examples/app/main.c b/examples/app/main.c
new file mode 100644
index 0000000..2b00ed9
--- /dev/null
+++ b/examples/app/main.c
@@ -0,0 +1,17 @@
+#include "example-application.h"
+
+int
+main (int argc,
+ char *argv[])
+{
+ g_autoptr(ExampleApplication) app = NULL;
+ gint ret;
+
+ app = g_object_new (EXAMPLE_TYPE_APPLICATION,
+ "application-id", "org.gnome.Example",
+ "resource-base-path", "/org/gnome/example",
+ NULL);
+ ret = g_application_run (G_APPLICATION (app), argc, argv);
+
+ return ret;
+}
diff --git a/examples/app/meson.build b/examples/app/meson.build
new file mode 100644
index 0000000..f52063a
--- /dev/null
+++ b/examples/app/meson.build
@@ -0,0 +1,20 @@
+example_resources = gnome.compile_resources(
+ 'example-resources',
+ 'example.gresources.xml',
+ c_name: 'example',
+)
+
+example_application_sources = [
+ 'example-application.c',
+ 'example-application.h',
+ 'example-window.c',
+ 'example-window.h',
+ 'main.c',
+ example_resources,
+]
+
+example_application = executable('example-application', example_application_sources,
+ c_args: test_cflags,
+ link_args: test_link_args,
+ dependencies: libdazzle_dep,
+)
diff --git a/meson.build b/meson.build
index 945d190..4ae1605 100644
--- a/meson.build
+++ b/meson.build
@@ -91,3 +91,4 @@ gnome = import('gnome')
subdir('src')
subdir('tests')
+subdir('examples/app')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]