summaryrefslogtreecommitdiff
path: root/examples/application7/exampleapp.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2013-07-20 00:21:48 -0400
committerMatthias Clasen <mclasen@redhat.com>2013-07-20 23:04:47 -0400
commit8087bb7a22303064fef947fc72639fcf70ce1515 (patch)
tree6f27902fc47b4d89f831eeb125a0ede3de1d3d17 /examples/application7/exampleapp.c
parent68025551e13eebcd8c610b104d309494a3aa973d (diff)
downloadgtk+-8087bb7a22303064fef947fc72639fcf70ce1515.tar.gz
Add a new example app
Add a new example to the getting started part of the docs. The focus of this example is on 'new stuff': GtkApplication, templates, settings, gmenu, gaction, GtkStack, GtkHeaderBar, GtkSearchBar, GtkRevealer, GtkListBox, GtkMenuButton, etc. It is being developed in several steps. Each step is put in a separate directory below examples/: application1, ..., application8. This is a little repetitive, but lets us use the code of all examples in the documentation.
Diffstat (limited to 'examples/application7/exampleapp.c')
-rw-r--r--examples/application7/exampleapp.c112
1 files changed, 112 insertions, 0 deletions
diff --git a/examples/application7/exampleapp.c b/examples/application7/exampleapp.c
new file mode 100644
index 0000000000..633216c692
--- /dev/null
+++ b/examples/application7/exampleapp.c
@@ -0,0 +1,112 @@
+#include <gtk/gtk.h>
+
+#include "exampleapp.h"
+#include "exampleappwin.h"
+#include "exampleappprefs.h"
+
+struct ExampleApp {
+ GtkApplication parent;
+};
+
+struct ExampleAppClass {
+ GtkApplicationClass parent_class;
+};
+
+G_DEFINE_TYPE(ExampleApp, example_app, GTK_TYPE_APPLICATION);
+
+static void
+example_app_init (ExampleApp *app)
+{
+}
+
+static void
+preferences_activated (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer app)
+{
+ ExampleAppPrefs *prefs;
+ GtkWindow *win;
+
+ win = gtk_application_get_active_window (GTK_APPLICATION (app));
+ prefs = example_app_prefs_new (EXAMPLE_APP_WINDOW (win));
+ gtk_window_present (GTK_WINDOW (prefs));
+}
+
+static void
+quit_activated (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer app)
+{
+ g_application_quit (G_APPLICATION (app));
+}
+
+static GActionEntry app_entries[] = {
+ { "preferences", preferences_activated, NULL, NULL, NULL },
+ { "quit", quit_activated, NULL, NULL, NULL }
+};
+
+static void
+example_app_startup (GApplication *app)
+{
+ GtkBuilder *builder;
+ GMenuModel *app_menu;
+
+ G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
+
+ g_action_map_add_action_entries (G_ACTION_MAP (app),
+ app_entries, G_N_ELEMENTS (app_entries),
+ app);
+
+ builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
+ app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
+ gtk_application_set_app_menu (GTK_APPLICATION (app), app_menu);
+ g_object_unref (builder);
+}
+
+static void
+example_app_activate (GApplication *app)
+{
+ ExampleAppWindow *win;
+
+ win = example_app_window_new (EXAMPLE_APP (app));
+ gtk_window_present (GTK_WINDOW (win));
+}
+
+static void
+example_app_open (GApplication *app,
+ GFile **files,
+ gint n_files,
+ const gchar *hint)
+{
+ GList *windows;
+ ExampleAppWindow *win;
+ int i;
+
+ windows = gtk_application_get_windows (GTK_APPLICATION (app));
+ if (windows)
+ win = EXAMPLE_APP_WINDOW (windows->data);
+ else
+ win = example_app_window_new (EXAMPLE_APP (app));
+
+ for (i = 0; i < n_files; i++)
+ example_app_window_open (win, files[i]);
+
+ gtk_window_present (GTK_WINDOW (win));
+}
+
+static void
+example_app_class_init (ExampleAppClass *class)
+{
+ G_APPLICATION_CLASS (class)->startup = example_app_startup;
+ G_APPLICATION_CLASS (class)->activate = example_app_activate;
+ G_APPLICATION_CLASS (class)->open = example_app_open;
+}
+
+ExampleApp *
+example_app_new (void)
+{
+ return g_object_new (EXAMPLE_APP_TYPE,
+ "application-id", "org.gtk.exampleapp",
+ "flags", G_APPLICATION_HANDLES_OPEN,
+ NULL);
+}