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

formatting, small changes

This commit is contained in:
2025-03-26 14:03:23 +01:00
parent 5f2b933a33
commit e5723d6a48
22 changed files with 563 additions and 406 deletions

View File

@@ -1,20 +1,21 @@
#include <gtk/gtk.h>
#include <adwaita.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include "create-category.h"
#include "flashcardsapp.h"
#include "flashcardsappwin.h"
#include "create-category.h"
#include "database.h"
struct _FlashcardsAppWindow
{
struct _FlashcardsAppWindow {
AdwApplicationWindow parent;
sqlite3 *db;
GArray *categories;
GQueue *cards;
card *current_card;
AdwWindowTitle *title;
@@ -23,7 +24,8 @@ struct _FlashcardsAppWindow
AdwNavigationPage *content;
AdwViewStack *main_view;
GtkWidget *placeholder;
GtkWidget *placeholder_category;
GtkWidget *placeholder_card;
GtkWidget *flashcard;
GtkListBox *topics;
@@ -33,66 +35,17 @@ struct _FlashcardsAppWindow
G_DEFINE_TYPE(FlashcardsAppWindow, flashcards_app_window, ADW_TYPE_APPLICATION_WINDOW);
static void on_category_selected(__attribute__((unused)) GtkListBox *box, GtkListBoxRow *row, gpointer user_data)
{
FlashcardsAppWindow *win;
int id;
category c;
win = user_data;
adw_navigation_split_view_set_show_content(ADW_NAVIGATION_SPLIT_VIEW(win->split_view), TRUE);
id = gtk_list_box_row_get_index(row);
printf("%d\n", id);
c = g_array_index(win->categories, category, id);
adw_window_title_set_subtitle(ADW_WINDOW_TITLE(win->title), c.name);
adw_view_stack_set_visible_child(win->main_view, win->flashcard);
}
static void on_add_category(__attribute__((unused)) GtkButton *self,
gpointer user_data)
{
FlashcardsCreateCategoryDialog *dialog;
dialog = flashcards_create_category_dialog_new(user_data);
adw_dialog_present(ADW_DIALOG(dialog), GTK_WIDGET(user_data));
}
static void on_delete_category(__attribute__((unused)) GtkButton *self,
gpointer user_data)
{
FlashcardsAppWindow *win;
win = user_data;
printf("Delete category\n");
gtk_list_box_unselect_all(win->topics);
adw_view_stack_set_visible_child(win->main_view, win->placeholder);
}
static void load_categories(FlashcardsAppWindow *win)
{
GArray *categories;
static void load_categories(FlashcardsAppWindow *win) {
gtk_list_box_remove_all(win->topics);
categories = database_load_categories(win->db);
win->categories = categories;
win->categories = database_load_categories(win->db);
for (guint i = 0; i < categories->len; i++)
{
GtkWidget *child;
GtkWidget *label;
category c;
c = g_array_index(categories, category, i);
for (guint i = 0; i < win->categories->len; i++) {
category c = g_array_index(win->categories, category, i);
printf("%d: %s\n", c.id, c.name);
child = gtk_list_box_row_new();
label = gtk_label_new(c.name);
GtkWidget *child = gtk_list_box_row_new();
GtkWidget *label = gtk_label_new(c.name);
gtk_widget_set_halign(label, GTK_ALIGN_START);
gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_MIDDLE);
gtk_widget_set_tooltip_text(label, c.name);
@@ -102,33 +55,102 @@ static void load_categories(FlashcardsAppWindow *win)
}
}
void flashcards_app_window_test(FlashcardsAppWindow *win, const gchar *test)
{
static void load_cards(FlashcardsAppWindow *win, category c) {
GArray *card_array = database_load_cards(win->db, c.id);
win->cards = g_queue_new();
for (guint i = 0; i < card_array->len; i++) {
g_queue_push_tail(win->cards, &g_array_index(card_array, card, i));
;
}
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);
}
static void on_select_category(__attribute__((unused)) GtkListBox *box, GtkListBoxRow *row, gpointer user_data) {
FlashcardsAppWindow *win = user_data;
adw_navigation_split_view_set_show_content(ADW_NAVIGATION_SPLIT_VIEW(win->split_view), TRUE);
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);
adw_window_title_set_subtitle(ADW_WINDOW_TITLE(win->title), c.name);
adw_view_stack_set_visible_child(win->main_view, win->flashcard);
load_cards(win, c);
}
static void on_add_category(__attribute__((unused)) GtkButton *self, gpointer user_data) {
FlashcardsCreateCategoryDialog *dialog = flashcards_create_category_dialog_new(user_data);
adw_dialog_present(ADW_DIALOG(dialog), GTK_WIDGET(user_data));
}
static void on_delete_category(__attribute__((unused)) GtkButton *self, gpointer user_data) {
FlashcardsAppWindow *win = user_data;
database_delete_category(win->db, 1);
printf("Delete category\n");
gtk_list_box_unselect_all(win->topics);
adw_view_stack_set_visible_child(win->main_view, win->placeholder_category);
}
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));*/
}
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");*/
}
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);
}
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);
}
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);
}
void flashcards_app_window_test(FlashcardsAppWindow *win, const gchar *test) {
GtkWidget *child;
database_save_category(win->db, test);
load_categories(win);
}
static void on_flashcards_app_window_show(GtkWidget *self,
gpointer user_data)
{
FlashcardsAppWindow *win;
win = user_data;
static void on_flashcards_app_window_show(GtkWidget *self, gpointer user_data) {
FlashcardsAppWindow *win = user_data;
printf("Show\n");
load_categories(win);
gtk_list_box_unselect_all(win->topics);
}
static void flashcards_app_window_init(FlashcardsAppWindow *win)
{
gtk_widget_init_template(GTK_WIDGET(win));
win->db = database_connect(g_get_user_data_dir());
static void flashcards_app_window_init(FlashcardsAppWindow *self) {
gtk_widget_init_template(GTK_WIDGET(self));
self->db = database_connect(g_get_user_data_dir());
}
static void flashcards_app_window_class_init(FlashcardsAppWindowClass *class)
{
static void flashcards_app_window_class_init(FlashcardsAppWindowClass *class) {
gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS(class), "/li/sopht/flashcards/window.ui");
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(class), FlashcardsAppWindow, title);
@@ -138,19 +160,25 @@ static void flashcards_app_window_class_init(FlashcardsAppWindowClass *class)
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(class), FlashcardsAppWindow, content);
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(class), FlashcardsAppWindow, main_view);
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(class), FlashcardsAppWindow, placeholder);
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(class), FlashcardsAppWindow, placeholder_category);
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(class), FlashcardsAppWindow, placeholder_card);
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(class), FlashcardsAppWindow, flashcard);
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(class), FlashcardsAppWindow, topics);
gtk_widget_class_bind_template_callback(GTK_WIDGET_CLASS(class), on_category_selected);
gtk_widget_class_bind_template_callback(GTK_WIDGET_CLASS(class), on_flashcards_app_window_show);
gtk_widget_class_bind_template_callback(GTK_WIDGET_CLASS(class), on_select_category);
gtk_widget_class_bind_template_callback(GTK_WIDGET_CLASS(class), on_add_category);
gtk_widget_class_bind_template_callback(GTK_WIDGET_CLASS(class), on_delete_category);
gtk_widget_class_bind_template_callback(GTK_WIDGET_CLASS(class), on_flashcards_app_window_show);
gtk_widget_class_bind_template_callback(GTK_WIDGET_CLASS(class), on_add_card);
gtk_widget_class_bind_template_callback(GTK_WIDGET_CLASS(class), on_delete_card);
gtk_widget_class_bind_template_callback(GTK_WIDGET_CLASS(class), on_answer_easy);
gtk_widget_class_bind_template_callback(GTK_WIDGET_CLASS(class), on_answer_medium);
gtk_widget_class_bind_template_callback(GTK_WIDGET_CLASS(class), on_answer_hard);
}
FlashcardsAppWindow *
flashcards_app_window_new(FlashcardsApp *app)
{
FlashcardsAppWindow *flashcards_app_window_new(FlashcardsApp *app) {
return g_object_new(FLASHCARDS_APP_WINDOW_TYPE, "application", app, NULL);
}