From d5f1abb9c84ef7b8d479e2b453947373b24a7306 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Mon, 7 Aug 2023 13:40:50 -0400 Subject: Initial commit --- src/erable-application.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++ src/erable-application.h | 34 ++++++++++++++ src/erable-window.c | 52 ++++++++++++++++++++ src/erable-window.h | 31 ++++++++++++ src/erable-window.ui | 111 +++++++++++++++++++++++++++++++++++++++++++ src/erable.gresource.xml | 7 +++ src/gtk/help-overlay.ui | 29 ++++++++++++ src/main.c | 42 +++++++++++++++++ src/meson.build | 20 ++++++++ 9 files changed, 446 insertions(+) create mode 100644 src/erable-application.c create mode 100644 src/erable-application.h create mode 100644 src/erable-window.c create mode 100644 src/erable-window.h create mode 100644 src/erable-window.ui create mode 100644 src/erable.gresource.xml create mode 100644 src/gtk/help-overlay.ui create mode 100644 src/main.c create mode 100644 src/meson.build (limited to 'src') diff --git a/src/erable-application.c b/src/erable-application.c new file mode 100644 index 0000000..b13583a --- /dev/null +++ b/src/erable-application.c @@ -0,0 +1,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 . + * + * 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 *[]) { "q", NULL }); +} diff --git a/src/erable-application.h b/src/erable-application.h new file mode 100644 index 0000000..8be0fa7 --- /dev/null +++ b/src/erable-application.h @@ -0,0 +1,34 @@ +/* erable-application.h + * + * 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define ERABLE_TYPE_APPLICATION (erable_application_get_type()) + +G_DECLARE_FINAL_TYPE (ErableApplication, erable_application, ERABLE, APPLICATION, AdwApplication) + +ErableApplication *erable_application_new (const char *application_id, + GApplicationFlags flags); + +G_END_DECLS diff --git a/src/erable-window.c b/src/erable-window.c new file mode 100644 index 0000000..9ff80f2 --- /dev/null +++ b/src/erable-window.c @@ -0,0 +1,52 @@ +/* erable-window.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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "config.h" + +#include "erable-window.h" + +struct _ErableWindow +{ + AdwApplicationWindow parent_instance; + + /* Template widgets */ + GtkHeaderBar *header_bar; + GtkButton *play_button; + GtkButton *browse_button; +}; + +G_DEFINE_FINAL_TYPE (ErableWindow, erable_window, ADW_TYPE_APPLICATION_WINDOW) + +static void +erable_window_class_init (ErableWindowClass *klass) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + gtk_widget_class_set_template_from_resource (widget_class, "/me/alee14/erable/erable-window.ui"); + gtk_widget_class_bind_template_child (widget_class, ErableWindow, header_bar); + gtk_widget_class_bind_template_child (widget_class, ErableWindow, play_button); + gtk_widget_class_bind_template_child (widget_class, ErableWindow, browse_button); +} + +static void +erable_window_init (ErableWindow *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); +} diff --git a/src/erable-window.h b/src/erable-window.h new file mode 100644 index 0000000..5672491 --- /dev/null +++ b/src/erable-window.h @@ -0,0 +1,31 @@ +/* erable-window.h + * + * 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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define ERABLE_TYPE_WINDOW (erable_window_get_type()) + +G_DECLARE_FINAL_TYPE (ErableWindow, erable_window, ERABLE, WINDOW, AdwApplicationWindow) + +G_END_DECLS diff --git a/src/erable-window.ui b/src/erable-window.ui new file mode 100644 index 0000000..9f4000a --- /dev/null +++ b/src/erable-window.ui @@ -0,0 +1,111 @@ + + + + + + +
+ + _Preferences + app.preferences + + + _Keyboard Shortcuts + win.show-help-overlay + + + _About Erable + app.about + +
+
+
diff --git a/src/erable.gresource.xml b/src/erable.gresource.xml new file mode 100644 index 0000000..98cda15 --- /dev/null +++ b/src/erable.gresource.xml @@ -0,0 +1,7 @@ + + + + erable-window.ui + gtk/help-overlay.ui + + diff --git a/src/gtk/help-overlay.ui b/src/gtk/help-overlay.ui new file mode 100644 index 0000000..ef12f02 --- /dev/null +++ b/src/gtk/help-overlay.ui @@ -0,0 +1,29 @@ + + + + True + + + shortcuts + 10 + + + General + + + Show Shortcuts + win.show-help-overlay + + + + + Quit + app.quit + + + + + + + + diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..5a2a977 --- /dev/null +++ b/src/main.c @@ -0,0 +1,42 @@ +/* main.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 . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "config.h" + +#include + +#include "erable-application.h" + +int +main (int argc, + char *argv[]) +{ + g_autoptr(ErableApplication) app = NULL; + int ret; + + bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + textdomain (GETTEXT_PACKAGE); + + app = erable_application_new ("me.alee14.erable", G_APPLICATION_DEFAULT_FLAGS); + ret = g_application_run (G_APPLICATION (app), argc, argv); + + return ret; +} diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..ca066fe --- /dev/null +++ b/src/meson.build @@ -0,0 +1,20 @@ +erable_sources = [ + 'main.c', + 'erable-application.c', + 'erable-window.c', +] + +erable_deps = [ + dependency('gtk4'), + dependency('libadwaita-1', version: '>= 1.2'), +] + +erable_sources += gnome.compile_resources('erable-resources', + 'erable.gresource.xml', + c_name: 'erable' +) + +executable('erable', erable_sources, + dependencies: erable_deps, + install: true, +) -- cgit v1.2.3