mirror of
https://gitlab.cvh-server.de/skrause/flashcards.git
synced 2025-12-12 06:41:38 +01:00
92 lines
2.6 KiB
C
92 lines
2.6 KiB
C
#include <adwaita.h>
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include "flashcardsapp.h"
|
|
#include "flashcardsappwin.h"
|
|
|
|
struct _FlashcardsApp
|
|
{
|
|
AdwApplication parent;
|
|
};
|
|
|
|
G_DEFINE_TYPE (FlashcardsApp, flashcards_app, ADW_TYPE_APPLICATION);
|
|
|
|
static void
|
|
flashcards_app_quit (__attribute__ ((unused)) GSimpleAction *action,
|
|
__attribute__ ((unused)) GVariant *parameter,
|
|
gpointer user_data)
|
|
{
|
|
FlashcardsApp *self = user_data;
|
|
g_application_quit (G_APPLICATION (self));
|
|
}
|
|
|
|
static void
|
|
flashcards_app_about (__attribute__ ((unused)) GSimpleAction *action,
|
|
__attribute__ ((unused)) GVariant *parameter,
|
|
gpointer user_data)
|
|
{
|
|
FlashcardsApp *self = user_data;
|
|
|
|
GtkWindow *window
|
|
= gtk_application_get_active_window (GTK_APPLICATION (self));
|
|
|
|
AdwDialog *dialog = adw_about_dialog_new_from_appdata (
|
|
"/li/sopht/flashcards/appdata", nullptr);
|
|
adw_dialog_present (dialog, GTK_WIDGET (window));
|
|
}
|
|
|
|
static const GActionEntry app_actions[] = {
|
|
{ "quit", flashcards_app_quit, nullptr, nullptr, nullptr, { 0, 0, 0 } },
|
|
{ "about", flashcards_app_about, nullptr, nullptr, nullptr, { 0, 0, 0 } },
|
|
};
|
|
|
|
static void
|
|
flashcards_app_init (FlashcardsApp *app)
|
|
{
|
|
g_action_map_add_action_entries (G_ACTION_MAP (app), app_actions,
|
|
G_N_ELEMENTS (app_actions), app);
|
|
gtk_application_set_accels_for_action (
|
|
GTK_APPLICATION (app), "app.quit",
|
|
(const char *[]){ "<primary>q", nullptr });
|
|
}
|
|
|
|
static void
|
|
flashcards_app_activate (GApplication *app)
|
|
{
|
|
FlashcardsAppWindow *win = flashcards_app_window_new (FLASHCARDS_APP (app));
|
|
gtk_window_present (GTK_WINDOW (win));
|
|
}
|
|
|
|
static void
|
|
flashcards_app_open (GApplication *app, __attribute__ ((unused)) GFile **files,
|
|
__attribute__ ((unused)) int n_files,
|
|
__attribute__ ((unused)) const char *hint)
|
|
{
|
|
FlashcardsAppWindow *win;
|
|
|
|
GList *windows = gtk_application_get_windows (GTK_APPLICATION (app));
|
|
if (windows)
|
|
win = FLASHCARDS_APP_WINDOW (windows->data);
|
|
else
|
|
win = flashcards_app_window_new (FLASHCARDS_APP (app));
|
|
|
|
gtk_window_present (GTK_WINDOW (win));
|
|
}
|
|
|
|
static void
|
|
flashcards_app_class_init (FlashcardsAppClass *klass)
|
|
{
|
|
G_APPLICATION_CLASS (klass)->activate = flashcards_app_activate;
|
|
G_APPLICATION_CLASS (klass)->open = flashcards_app_open;
|
|
}
|
|
|
|
FlashcardsApp *
|
|
flashcards_app_new (void)
|
|
{
|
|
return g_object_new (FLASHCARDS_APP_TYPE, "application-id",
|
|
"li.sopht.Flashcards", "flags",
|
|
G_APPLICATION_DEFAULT_FLAGS, NULL);
|
|
}
|