1#include <gtk/gtk.h>
2
3#include "exampleapp.h"
4#include "exampleappwin.h"
5
6struct _ExampleApp
7{
8 GtkApplication parent;
9};
10
11G_DEFINE_TYPE(ExampleApp, example_app, GTK_TYPE_APPLICATION);
12
13static void
14example_app_init (ExampleApp *app)
15{
16}
17
18static void
19preferences_activated (GSimpleAction *action,
20 GVariant *parameter,
21 gpointer app)
22{
23}
24
25static void
26quit_activated (GSimpleAction *action,
27 GVariant *parameter,
28 gpointer app)
29{
30 g_application_quit (G_APPLICATION (app));
31}
32
33static GActionEntry app_entries[] =
34{
35 { "preferences", preferences_activated, NULL, NULL, NULL },
36 { "quit", quit_activated, NULL, NULL, NULL }
37};
38
39static void
40example_app_startup (GApplication *app)
41{
42 const char *quit_accels[2] = { "<Ctrl>Q", NULL };
43
44 G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
45
46 g_action_map_add_action_entries (G_ACTION_MAP (app),
47 entries: app_entries, G_N_ELEMENTS (app_entries),
48 user_data: app);
49 gtk_application_set_accels_for_action (GTK_APPLICATION (app),
50 detailed_action_name: "app.quit",
51 accels: quit_accels);
52}
53
54static void
55example_app_activate (GApplication *app)
56{
57 ExampleAppWindow *win;
58
59 win = example_app_window_new (app: EXAMPLE_APP (ptr: app));
60 gtk_window_present (GTK_WINDOW (win));
61}
62
63static void
64example_app_open (GApplication *app,
65 GFile **files,
66 int n_files,
67 const char *hint)
68{
69 GList *windows;
70 ExampleAppWindow *win;
71 int i;
72
73 windows = gtk_application_get_windows (GTK_APPLICATION (app));
74 if (windows)
75 win = EXAMPLE_APP_WINDOW (ptr: windows->data);
76 else
77 win = example_app_window_new (app: EXAMPLE_APP (ptr: app));
78
79 for (i = 0; i < n_files; i++)
80 example_app_window_open (win, file: files[i]);
81
82 gtk_window_present (GTK_WINDOW (win));
83}
84
85static void
86example_app_class_init (ExampleAppClass *class)
87{
88 G_APPLICATION_CLASS (class)->startup = example_app_startup;
89 G_APPLICATION_CLASS (class)->activate = example_app_activate;
90 G_APPLICATION_CLASS (class)->open = example_app_open;
91}
92
93ExampleApp *
94example_app_new (void)
95{
96 return g_object_new (EXAMPLE_APP_TYPE,
97 first_property_name: "application-id", "org.gtk.exampleapp",
98 "flags", G_APPLICATION_HANDLES_OPEN,
99 NULL);
100}
101

source code of gtk/examples/application5/exampleapp.c