1 | #include "config.h" |
2 | #include <gtk/gtk.h> |
3 | |
4 | #include "iconbrowserapp.h" |
5 | #include "iconbrowserwin.h" |
6 | |
7 | #include "demo_conf.h" |
8 | |
9 | struct _IconBrowserApp |
10 | { |
11 | GtkApplication parent; |
12 | }; |
13 | |
14 | struct _IconBrowserAppClass |
15 | { |
16 | GtkApplicationClass parent_class; |
17 | }; |
18 | |
19 | G_DEFINE_TYPE(IconBrowserApp, icon_browser_app, GTK_TYPE_APPLICATION); |
20 | |
21 | static void |
22 | icon_browser_app_init (IconBrowserApp *app) |
23 | { |
24 | } |
25 | |
26 | static void |
27 | quit_activated (GSimpleAction *action, |
28 | GVariant *parameter, |
29 | gpointer app) |
30 | { |
31 | g_application_quit (G_APPLICATION (app)); |
32 | } |
33 | |
34 | static void |
35 | inspector_activated (GSimpleAction *action, |
36 | GVariant *parameter, |
37 | gpointer app) |
38 | { |
39 | gtk_window_set_interactive_debugging (TRUE); |
40 | } |
41 | |
42 | static void |
43 | about_activated (GSimpleAction *action, |
44 | GVariant *parameter, |
45 | gpointer user_data) |
46 | { |
47 | GtkApplication *app = user_data; |
48 | const char *authors[] = { |
49 | "The GTK Team" , |
50 | NULL |
51 | }; |
52 | char *icon_theme; |
53 | char *version; |
54 | GString *s; |
55 | char *os_name; |
56 | char *os_version; |
57 | |
58 | g_object_get (object: gtk_settings_get_default (), |
59 | first_property_name: "gtk-icon-theme-name" , &icon_theme, |
60 | NULL); |
61 | |
62 | s = g_string_new (init: "" ); |
63 | |
64 | os_name = g_get_os_info (G_OS_INFO_KEY_NAME); |
65 | os_version = g_get_os_info (G_OS_INFO_KEY_VERSION_ID); |
66 | if (os_name && os_version) |
67 | g_string_append_printf (string: s, format: "OS\t%s %s\n\n" , os_name, os_version); |
68 | g_string_append (string: s, val: "System libraries\n" ); |
69 | g_string_append_printf (string: s, format: "\tGLib\t%d.%d.%d\n" , |
70 | glib_major_version, |
71 | glib_minor_version, |
72 | glib_micro_version); |
73 | g_string_append_printf (string: s, format: "\tPango\t%s\n" , |
74 | pango_version_string ()); |
75 | g_string_append_printf (string: s, format: "\tGTK \t%d.%d.%d\n" , |
76 | gtk_get_major_version (), |
77 | gtk_get_minor_version (), |
78 | gtk_get_micro_version ()); |
79 | g_string_append_printf (string: s, format: "\nIcon theme\n\t%s" , icon_theme); |
80 | version = g_strdup_printf (format: "%s%s%s\nRunning against GTK %d.%d.%d" , |
81 | PACKAGE_VERSION, |
82 | g_strcmp0 (str1: PROFILE, str2: "devel" ) == 0 ? "-" : "" , |
83 | g_strcmp0 (str1: PROFILE, str2: "devel" ) == 0 ? VCS_TAG : "" , |
84 | gtk_get_major_version (), |
85 | gtk_get_minor_version (), |
86 | gtk_get_micro_version ()); |
87 | |
88 | gtk_show_about_dialog (GTK_WINDOW (gtk_application_get_active_window (app)), |
89 | first_property_name: "program-name" , g_strcmp0 (str1: PROFILE, str2: "devel" ) == 0 |
90 | ? "GTK Icon Browser (Development)" |
91 | : "GTK Icon Browser" , |
92 | "version" , version, |
93 | "copyright" , "© 1997—2021 The GTK Team" , |
94 | "license-type" , GTK_LICENSE_LGPL_2_1, |
95 | "website" , "http://www.gtk.org" , |
96 | "comments" , "Program to browse themed icons" , |
97 | "authors" , authors, |
98 | "logo-icon-name" , "org.gtk.IconBrowser4" , |
99 | "title" , "About GTK Icon Browser" , |
100 | "system-information" , s->str, |
101 | NULL); |
102 | |
103 | g_string_free (string: s, TRUE); |
104 | g_free (mem: version); |
105 | g_free (mem: icon_theme); |
106 | g_free (mem: os_name); |
107 | g_free (mem: os_version); |
108 | } |
109 | |
110 | static GActionEntry app_entries[] = |
111 | { |
112 | { "quit" , quit_activated, NULL, NULL, NULL }, |
113 | { "inspector" , inspector_activated, NULL, NULL, NULL }, |
114 | { "about" , about_activated, NULL, NULL, NULL } |
115 | }; |
116 | |
117 | static void |
118 | icon_browser_app_startup (GApplication *app) |
119 | { |
120 | const char *quit_accels[2] = { "<Ctrl>Q" , NULL }; |
121 | |
122 | G_APPLICATION_CLASS (icon_browser_app_parent_class)->startup (app); |
123 | |
124 | g_action_map_add_action_entries (G_ACTION_MAP (app), |
125 | entries: app_entries, G_N_ELEMENTS (app_entries), |
126 | user_data: app); |
127 | gtk_application_set_accels_for_action (GTK_APPLICATION (app), |
128 | detailed_action_name: "app.quit" , |
129 | accels: quit_accels); |
130 | } |
131 | |
132 | static void |
133 | icon_browser_app_activate (GApplication *app) |
134 | { |
135 | IconBrowserWindow *win; |
136 | |
137 | win = icon_browser_window_new (ICON_BROWSER_APP (app)); |
138 | |
139 | if (g_strcmp0 (str1: PROFILE, str2: "devel" ) == 0) |
140 | gtk_widget_add_css_class (GTK_WIDGET (win), css_class: "devel" ); |
141 | |
142 | gtk_window_present (GTK_WINDOW (win)); |
143 | } |
144 | |
145 | static void |
146 | icon_browser_app_class_init (IconBrowserAppClass *class) |
147 | { |
148 | G_APPLICATION_CLASS (class)->startup = icon_browser_app_startup; |
149 | G_APPLICATION_CLASS (class)->activate = icon_browser_app_activate; |
150 | } |
151 | |
152 | IconBrowserApp * |
153 | icon_browser_app_new (void) |
154 | { |
155 | return g_object_new (ICON_BROWSER_APP_TYPE, |
156 | first_property_name: "application-id" , "org.gtk.IconBrowser4" , |
157 | NULL); |
158 | } |
159 | |