mirror of
https://gitlab.cvh-server.de/skrause/flashcards.git
synced 2025-12-12 09:01:37 +01:00
update ui, add metainfo
This commit is contained in:
@@ -14,17 +14,21 @@ struct _FlashcardsAppWindow
|
||||
AdwApplicationWindow parent;
|
||||
|
||||
sqlite3 *db;
|
||||
|
||||
GArray *categories;
|
||||
|
||||
AdwWindowTitle *title;
|
||||
|
||||
AdwNavigationSplitView *split_view;
|
||||
AdwNavigationPage *sidebar;
|
||||
AdwNavigationPage *content;
|
||||
|
||||
AdwDialog *create_category_dialog;
|
||||
AdwViewStack *main_view;
|
||||
GtkWidget *placeholder;
|
||||
GtkWidget *flashcard;
|
||||
|
||||
GtkListBox *topics;
|
||||
|
||||
bool started;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(FlashcardsAppWindow, flashcards_app_window, ADW_TYPE_APPLICATION_WINDOW);
|
||||
@@ -34,20 +38,30 @@ on_category_selected(__attribute__((unused)) GtkListBox *box, GtkListBoxRow *row
|
||||
{
|
||||
FlashcardsAppWindow *win;
|
||||
int id;
|
||||
category c;
|
||||
|
||||
win = user_data;
|
||||
|
||||
if (!win->started)
|
||||
{
|
||||
win->started = true;
|
||||
gtk_list_box_unselect_all(win->topics);
|
||||
return;
|
||||
}
|
||||
|
||||
if (row == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
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(gtk_list_box_get_selected_row(win->topics));
|
||||
printf("%d\n", id);
|
||||
|
||||
char test[2];
|
||||
sprintf(test, "%d", id);
|
||||
adw_window_title_set_subtitle(ADW_WINDOW_TITLE(win->title), test);
|
||||
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
|
||||
@@ -64,35 +78,24 @@ static void
|
||||
on_delete_category(__attribute__((unused)) GtkButton *self,
|
||||
gpointer user_data)
|
||||
{
|
||||
FlashcardsAppWindow *win = user_data;
|
||||
FlashcardsAppWindow *win;
|
||||
|
||||
win = user_data;
|
||||
|
||||
printf("Delete category\n");
|
||||
}
|
||||
|
||||
void flashcards_app_window_test(FlashcardsAppWindow *win, const gchar *test)
|
||||
{
|
||||
GtkWidget *child;
|
||||
|
||||
database_save_category(win->db, test);
|
||||
|
||||
child = adw_action_row_new();
|
||||
adw_preferences_row_set_title(ADW_PREFERENCES_ROW(child), test);
|
||||
|
||||
gtk_list_box_append(GTK_LIST_BOX(win->topics), child);
|
||||
gtk_list_box_unselect_all(win->topics);
|
||||
adw_view_stack_set_visible_child(win->main_view, win->placeholder);
|
||||
}
|
||||
|
||||
static void
|
||||
flashcards_app_window_init(FlashcardsAppWindow *win)
|
||||
load_categories(FlashcardsAppWindow *win)
|
||||
{
|
||||
GArray *categories;
|
||||
|
||||
gtk_widget_init_template(GTK_WIDGET(win));
|
||||
gtk_list_box_remove_all(win->topics);
|
||||
|
||||
win->db = database_connect(g_get_user_data_dir());
|
||||
database_create_tables(win->db);
|
||||
win->categories = database_load_categories(win->db);
|
||||
|
||||
categories = win->categories;
|
||||
categories = database_load_categories(win->db);
|
||||
win->categories = categories;
|
||||
|
||||
for (guint i = 0; i < categories->len; i++)
|
||||
{
|
||||
@@ -105,20 +108,42 @@ flashcards_app_window_init(FlashcardsAppWindow *win)
|
||||
child = adw_action_row_new();
|
||||
adw_preferences_row_set_title(ADW_PREFERENCES_ROW(child), c.name);
|
||||
|
||||
gtk_list_box_append(GTK_LIST_BOX(win->topics), child);
|
||||
gtk_list_box_append(win->topics, child);
|
||||
}
|
||||
}
|
||||
|
||||
void flashcards_app_window_test(FlashcardsAppWindow *win, const gchar *test)
|
||||
{
|
||||
GtkWidget *child;
|
||||
|
||||
database_save_category(win->db, test);
|
||||
load_categories(win);
|
||||
}
|
||||
|
||||
static void
|
||||
flashcards_app_window_init(FlashcardsAppWindow *win)
|
||||
{
|
||||
gtk_widget_init_template(GTK_WIDGET(win));
|
||||
|
||||
win->db = database_connect(g_get_user_data_dir());
|
||||
load_categories(win);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(class), FlashcardsAppWindow, split_view);
|
||||
gtk_widget_class_bind_template_child(GTK_WIDGET_CLASS(class), FlashcardsAppWindow, sidebar);
|
||||
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, 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);
|
||||
|
||||
Reference in New Issue
Block a user