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

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