aboutsummaryrefslogtreecommitdiff
path: root/src/erable-application.c
blob: b13583a0854d47db5717b932a72c4d41cd95fef2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* erable-application.c
 *
 * Copyright 2023 Andrew Lee
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include "config.h"

#include "erable-application.h"
#include "erable-window.h"

struct _ErableApplication
{
	AdwApplication parent_instance;
};

G_DEFINE_TYPE (ErableApplication, erable_application, ADW_TYPE_APPLICATION)

ErableApplication *
erable_application_new (const char        *application_id,
                        GApplicationFlags  flags)
{
	g_return_val_if_fail (application_id != NULL, NULL);

	return g_object_new (ERABLE_TYPE_APPLICATION,
	                     "application-id", application_id,
	                     "flags", flags,
	                     NULL);
}

static void
erable_application_activate (GApplication *app)
{
	GtkWindow *window;

	g_assert (ERABLE_IS_APPLICATION (app));

	window = gtk_application_get_active_window (GTK_APPLICATION (app));

	if (window == NULL)
		window = g_object_new (ERABLE_TYPE_WINDOW,
		                       "application", app,
		                       NULL);

	gtk_window_present (window);
}

static void
erable_application_class_init (ErableApplicationClass *klass)
{
	GApplicationClass *app_class = G_APPLICATION_CLASS (klass);

	app_class->activate = erable_application_activate;
}

static void
erable_application_about_action (GSimpleAction *action,
                                 GVariant      *parameter,
                                 gpointer       user_data)
{
	static const char *developers[] = {"Andrew Lee", NULL};
	ErableApplication *self = user_data;
	GtkWindow *window = NULL;

	g_assert (ERABLE_IS_APPLICATION (self));

	window = gtk_application_get_active_window (GTK_APPLICATION (self));

	adw_show_about_window (window,
	                       "application-name", "Erable",
	                       "application-icon", "me.alee14.erable",
	                       "developer-name", "Andrew Lee",
	                       "version", "0.1.0",
	                       "developers", developers,
	                       "copyright", "© 2023 Andrew Lee\n\nThis application comes with absolutely no warranty. See the GNU General Public License, version 3 or later for details.",
	                       NULL);
}

static void
erable_application_quit_action (GSimpleAction *action,
                                GVariant      *parameter,
                                gpointer       user_data)
{
	ErableApplication *self = user_data;

	g_assert (ERABLE_IS_APPLICATION (self));

	g_application_quit (G_APPLICATION (self));
}

static const GActionEntry app_actions[] = {
	{ "quit", erable_application_quit_action },
	{ "about", erable_application_about_action },
};

static void
erable_application_init (ErableApplication *self)
{
	g_action_map_add_action_entries (G_ACTION_MAP (self),
	                                 app_actions,
	                                 G_N_ELEMENTS (app_actions),
	                                 self);
	gtk_application_set_accels_for_action (GTK_APPLICATION (self),
	                                       "app.quit",
	                                       (const char *[]) { "<primary>q", NULL });
}