1
0
mirror of https://gitlab.cvh-server.de/skrause/flashcards.git synced 2025-12-12 09:01:37 +01:00

more stuff!

This commit is contained in:
2025-04-05 08:55:56 +02:00
parent 9f5f951a9f
commit 48918ba4bf
13 changed files with 275 additions and 97 deletions

View File

@@ -1,14 +1,12 @@
#include <adwaita.h>
#include <gtk/gtk.h>
#include "flashcardsappwin.h"
#include <glib/gi18n.h>
#include "create-category.h"
#include "flashcardsapp.h"
#include "flashcardsappwin.h"
#include "database.h"
#include "create-card.h"
#include "create-category.h"
struct _FlashcardsAppWindow
{
AdwApplicationWindow parent;
@@ -16,10 +14,15 @@ struct _FlashcardsAppWindow
sqlite3 *db;
GArray *categories;
GQueue *cards;
category current_category;
card *current_card;
AdwWindowTitle *title;
GtkButton *add_card_button;
GtkButton *delete_card_button;
GtkButton *delete_category_button;
AdwNavigationSplitView *split_view;
AdwNavigationPage *sidebar;
AdwNavigationPage *content;
@@ -31,6 +34,8 @@ struct _FlashcardsAppWindow
GtkListBox *topics;
GtkLabel *card_title;
bool started;
};
@@ -60,6 +65,18 @@ load_categories (FlashcardsAppWindow *win)
}
}
static void
next_card (FlashcardsAppWindow *win)
{
if (win->cards->length <= 0)
{
adw_view_stack_set_visible_child (win->main_view, win->placeholder_card);
return;
}
win->current_card = g_queue_pop_head (win->cards);
gtk_label_set_label (win->card_title, win->current_card->title);
}
static void
load_cards (FlashcardsAppWindow *win, category c)
{
@@ -73,13 +90,7 @@ load_cards (FlashcardsAppWindow *win, category c)
}
printf ("Flashcards: %d\n", win->cards->length);
if (win->cards->length <= 0)
{
adw_view_stack_set_visible_child (win->main_view, win->placeholder_card);
return;
}
win->current_card = g_queue_pop_head (win->cards);
next_card (win);
}
static void
@@ -91,14 +102,19 @@ on_select_category (__attribute__ ((unused)) GtkListBox *box,
adw_navigation_split_view_set_show_content (
ADW_NAVIGATION_SPLIT_VIEW (win->split_view), TRUE);
int id = gtk_list_box_row_get_index (row);
const int id = gtk_list_box_row_get_index (row);
category c = g_array_index (win->categories, category, id);
printf ("%d: %d\n", id, c.id);
win->current_category = c;
adw_window_title_set_subtitle (ADW_WINDOW_TITLE (win->title), c.name);
adw_view_stack_set_visible_child (win->main_view, win->flashcard);
gtk_widget_set_visible (GTK_WIDGET (win->add_card_button), TRUE);
gtk_widget_set_visible (GTK_WIDGET (win->delete_card_button), TRUE);
gtk_widget_set_visible (GTK_WIDGET (win->delete_category_button), TRUE);
load_cards (win, c);
}
@@ -115,56 +131,84 @@ on_delete_category (__attribute__ ((unused)) GtkButton *self,
gpointer user_data)
{
FlashcardsAppWindow *win = user_data;
database_delete_category (win->db, 1);
database_delete_category (win->db, win->current_category.id);
printf ("Delete category\n");
gtk_list_box_unselect_all (win->topics);
adw_view_stack_set_visible_child (win->main_view, win->placeholder_category);
gtk_widget_set_visible (GTK_WIDGET (win->add_card_button), FALSE);
gtk_widget_set_visible (GTK_WIDGET (win->delete_card_button), FALSE);
gtk_widget_set_visible (GTK_WIDGET (win->delete_category_button), FALSE);
load_categories (win);
}
static void
on_add_card (__attribute__ ((unused)) GtkButton *self, gpointer user_data)
{
/*FlashcardsAppWindow *win = user_data;
FlashcardsCreateCardDialog *dialog = flashcards_create_card_dialog_new(win);
adw_dialog_present(ADW_DIALOG(dialog), GTK_WIDGET(win));*/
FlashcardsAppWindow *win = user_data;
FlashcardsCreateCardDialog *dialog = flashcards_create_card_dialog_new (win);
adw_dialog_present (ADW_DIALOG (dialog), GTK_WIDGET (win));
}
static void
on_delete_card (__attribute__ ((unused)) GtkButton *self, gpointer user_data)
{
/*FlashcardsAppWindow *win = user_data;
database_delete_card(win->db, 1);
printf("Delete card\n");*/
FlashcardsAppWindow *win = user_data;
database_delete_card (win->db, win->current_card->id);
next_card (win);
}
static void
on_answer_easy (__attribute__ ((unused)) GtkButton *self, gpointer user_data)
{
FlashcardsAppWindow *win = user_data;
adw_view_stack_set_visible_child (win->main_view, win->placeholder_category);
card *c = win->current_card;
database_schedule_card (
win->db, c->id, g_date_time_add_hours (g_date_time_new_now_utc (), 24));
next_card (win);
}
static void
on_answer_medium (__attribute__ ((unused)) GtkButton *self, gpointer user_data)
{
FlashcardsAppWindow *win = user_data;
adw_view_stack_set_visible_child (win->main_view, win->placeholder_category);
card *c = win->current_card;
database_schedule_card (
win->db, c->id, g_date_time_add_hours (g_date_time_new_now_utc (), 12));
next_card (win);
}
static void
on_answer_hard (__attribute__ ((unused)) GtkButton *self, gpointer user_data)
{
FlashcardsAppWindow *win = user_data;
adw_view_stack_set_visible_child (win->main_view, win->placeholder_category);
card *c = win->current_card;
database_schedule_card (
win->db, c->id, g_date_time_add_hours (g_date_time_new_now_utc (), 6));
next_card (win);
}
static void
on_flip_card (__attribute__ ((unused)) GtkWidget *self, gpointer user_data)
{
FlashcardsAppWindow *win = user_data;
gtk_label_set_text (GTK_LABEL (win->card_title), win->current_card->answer);
}
void
flashcards_app_window_test (FlashcardsAppWindow *win, const gchar *test)
flashcards_app_window_add_card (FlashcardsAppWindow *win, const gchar *title,
const gchar *answer)
{
GtkWidget *child;
database_save_card (win->db, win->current_category.id, title, answer);
printf ("Added card\n");
}
database_save_category (win->db, test);
void
flashcards_app_window_add_category (FlashcardsAppWindow *win,
const gchar *title)
{
database_save_category (win->db, title);
load_categories (win);
}
@@ -194,6 +238,13 @@ flashcards_app_window_class_init (FlashcardsAppWindowClass *class)
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class),
FlashcardsAppWindow, title);
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class),
FlashcardsAppWindow, add_card_button);
gtk_widget_class_bind_template_child (
GTK_WIDGET_CLASS (class), FlashcardsAppWindow, delete_card_button);
gtk_widget_class_bind_template_child (
GTK_WIDGET_CLASS (class), FlashcardsAppWindow, delete_category_button);
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class),
FlashcardsAppWindow, split_view);
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class),
@@ -213,6 +264,9 @@ flashcards_app_window_class_init (FlashcardsAppWindowClass *class)
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class),
FlashcardsAppWindow, topics);
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class),
FlashcardsAppWindow, card_title);
gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (class),
on_flashcards_app_window_show);
@@ -233,6 +287,9 @@ flashcards_app_window_class_init (FlashcardsAppWindowClass *class)
on_answer_medium);
gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (class),
on_answer_hard);
gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (class),
on_flip_card);
}
FlashcardsAppWindow *