1 | #include <gtk/gtk.h> |
2 | |
3 | #include "exampleapp.h" |
4 | #include "exampleappwin.h" |
5 | |
6 | struct _ExampleApp |
7 | { |
8 | GtkApplication parent; |
9 | }; |
10 | |
11 | G_DEFINE_TYPE(ExampleApp, example_app, GTK_TYPE_APPLICATION); |
12 | |
13 | static void |
14 | example_app_init (ExampleApp *app) |
15 | { |
16 | } |
17 | |
18 | static void |
19 | preferences_activated (GSimpleAction *action, |
20 | GVariant *parameter, |
21 | gpointer app) |
22 | { |
23 | } |
24 | |
25 | static void |
26 | quit_activated (GSimpleAction *action, |
27 | GVariant *parameter, |
28 | gpointer app) |
29 | { |
30 | g_application_quit (G_APPLICATION (app)); |
31 | } |
32 | |
33 | static GActionEntry app_entries[] = |
34 | { |
35 | { "preferences" , preferences_activated, NULL, NULL, NULL }, |
36 | { "quit" , quit_activated, NULL, NULL, NULL } |
37 | }; |
38 | |
39 | static void |
40 | example_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 | |
54 | static void |
55 | example_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 | |
63 | static void |
64 | example_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 | |
85 | static void |
86 | example_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 | |
93 | ExampleApp * |
94 | example_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 | |