[glib] Add an example of using GApplication with actions
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Add an example of using GApplication with actions
- Date: Sun, 31 Oct 2010 02:19:46 +0000 (UTC)
commit c34bcefa78faacbda4528de9aeea2e13519c27e0
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Oct 30 22:19:02 2010 -0400
Add an example of using GApplication with actions
gio/tests/Makefile.am | 4 ++
gio/tests/gapplication-example-actions.c | 82 ++++++++++++++++++++++++++++++
2 files changed, 86 insertions(+), 0 deletions(-)
---
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
index 591894d..5e65c08 100644
--- a/gio/tests/Makefile.am
+++ b/gio/tests/Makefile.am
@@ -88,6 +88,7 @@ SAMPLE_PROGS = \
gapplication-example-open \
gapplication-example-cmdline \
gapplication-example-cmdline2 \
+ gapplication-example-actions \
$(NULL)
@@ -319,6 +320,9 @@ gapplication_example_cmdline_LDADD = $(progs_ldadd)
gapplication_example_cmdline2_SOURCES = gapplication-example-cmdline2.c
gapplication_example_cmdline2_LDADD = $(progs_ldadd)
+gapplication_example_actions_SOURCES = gapplication-example-actions.c
+gapplication_example_actions_LDADD = $(progs_ldadd)
+
schema_tests = \
schema-tests/array-default-not-in-choices.gschema.xml \
schema-tests/bad-choice.gschema.xml \
diff --git a/gio/tests/gapplication-example-actions.c b/gio/tests/gapplication-example-actions.c
new file mode 100644
index 0000000..bca0b06
--- /dev/null
+++ b/gio/tests/gapplication-example-actions.c
@@ -0,0 +1,82 @@
+#include <gio/gio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static void
+activate (GApplication *application)
+{
+ g_application_hold (application);
+ g_print ("activated\n");
+ g_application_release (application);
+}
+
+static void
+activate_action (GAction *action,
+ GVariant *parameter,
+ gpointer data)
+{
+ GApplication *application = data;
+
+ g_application_hold (application);
+ g_print ("action %s activated\n", g_action_get_name (action));
+ g_application_release (application);
+}
+
+static void
+activate_toggle_action (GAction *action,
+ GVariant *parameter,
+ gpointer data)
+{
+ GApplication *application = data;
+ GVariant *state;
+ gboolean b;
+
+ g_application_hold (application);
+ g_print ("action %s activated\n", g_action_get_name (action));
+
+ state = g_action_get_state (action);
+ b = g_variant_get_boolean (state);
+ g_variant_unref (state);
+ g_action_set_state (action, g_variant_new_boolean (!b));
+
+ g_application_release (application);
+}
+
+static void
+add_actions (GApplication *app)
+{
+ GSimpleActionGroup *actions;
+ GSimpleAction *action;
+
+ actions = g_simple_action_group_new ();
+
+ action = g_simple_action_new ("simple-action", NULL);
+ g_signal_connect (action, "activate", G_CALLBACK (activate_action), app);
+ g_simple_action_group_insert (actions, G_ACTION (action));
+
+ action = g_simple_action_new_stateful ("toggle-action", NULL,
+ g_variant_new_boolean (FALSE));
+ g_signal_connect (action, "activate", G_CALLBACK (activate_toggle_action), app);
+ g_simple_action_group_insert (actions, G_ACTION (action));
+
+ g_application_set_action_group (app, G_ACTION_GROUP (actions));
+}
+
+int
+main (int argc, char **argv)
+{
+ GApplication *app;
+ int status;
+
+ app = g_application_new ("org.gtk.TestApplication", 0);
+ g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+ g_application_set_inactivity_timeout (app, 10000);
+
+ add_actions (app);
+
+ status = g_application_run (app, argc, argv);
+
+ g_object_unref (app);
+
+ return status;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]