mirror of
https://gitlab.cvh-server.de/skrause/flashcards.git
synced 2025-12-12 09:01:37 +01:00
small fixes and description
This commit is contained in:
@@ -5,9 +5,11 @@
|
||||
sqlite3 *database_connect(const char *path)
|
||||
{
|
||||
int rc;
|
||||
|
||||
gchar *file = g_build_filename(path, "cards.db", NULL);
|
||||
gchar *file;
|
||||
sqlite3 *db;
|
||||
|
||||
file = g_build_filename(path, "cards.db", NULL);
|
||||
|
||||
rc = sqlite3_open(file, &db);
|
||||
|
||||
if (rc)
|
||||
@@ -33,12 +35,13 @@ void database_create_tables(sqlite3 *db)
|
||||
{
|
||||
int rc;
|
||||
sqlite3_stmt *stmt;
|
||||
const char *sql;
|
||||
|
||||
char *sql = "CREATE TABLE IF NOT EXISTS `cards` ("
|
||||
"`category` INTEGER NOT NULL,"
|
||||
"`task` TEXT NOT NULL,"
|
||||
"`solution` TEXT NOT NULL"
|
||||
")";
|
||||
sql = "CREATE TABLE IF NOT EXISTS `cards` ("
|
||||
"`category` INTEGER NOT NULL,"
|
||||
"`task` TEXT NOT NULL,"
|
||||
"`solution` TEXT NOT NULL"
|
||||
")";
|
||||
|
||||
rc = sqlite3_prepare_v2(db, sql, -1, &stmt, 0);
|
||||
|
||||
@@ -94,11 +97,12 @@ void database_save_category(sqlite3 *db, const char *c)
|
||||
|
||||
GArray *database_load_categories(sqlite3 *db)
|
||||
{
|
||||
GArray *categories = g_array_new(TRUE, FALSE, sizeof(category));
|
||||
|
||||
GArray *categories;
|
||||
int rc;
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
categories = g_array_new(TRUE, FALSE, sizeof(category));
|
||||
|
||||
rc = sqlite3_prepare_v2(db, "SELECT * FROM categories", -1, &stmt, 0);
|
||||
|
||||
if (rc != SQLITE_OK)
|
||||
@@ -109,10 +113,8 @@ GArray *database_load_categories(sqlite3 *db)
|
||||
while (sqlite3_step(stmt) == SQLITE_ROW)
|
||||
{
|
||||
int id = sqlite3_column_int(stmt, 0);
|
||||
const char *temp_name = (const char *)sqlite3_column_text(stmt, 1);
|
||||
char *name = strdup((const char *)sqlite3_column_text(stmt, 1));
|
||||
|
||||
char *name = g_new0(char, strlen(temp_name) + 1);
|
||||
strncpy(name, temp_name, strlen(temp_name) + 1);
|
||||
category c = {id, name};
|
||||
g_array_append_val(categories, c);
|
||||
}
|
||||
@@ -146,7 +148,9 @@ void database_save_card(sqlite3 *db, card c)
|
||||
|
||||
GArray *database_load_cards(sqlite3 *db)
|
||||
{
|
||||
GArray *cards = g_array_new(TRUE, FALSE, sizeof(card));
|
||||
GArray *cards;
|
||||
|
||||
cards = g_array_new(TRUE, FALSE, sizeof(card));
|
||||
|
||||
return cards;
|
||||
}
|
||||
@@ -31,15 +31,18 @@ G_DEFINE_TYPE(FlashcardsAppWindow, flashcards_app_window, ADW_TYPE_APPLICATION_W
|
||||
static void
|
||||
on_category_selected(GtkListBox *box, GtkListBoxRow *row, gpointer user_data)
|
||||
{
|
||||
FlashcardsAppWindow *win;
|
||||
int id;
|
||||
|
||||
if (row == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
printf("Test\n");
|
||||
FlashcardsAppWindow *win = user_data;
|
||||
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(gtk_list_box_get_selected_row(win->topics));
|
||||
id = gtk_list_box_row_get_index(gtk_list_box_get_selected_row(win->topics));
|
||||
printf("%d\n", id);
|
||||
}
|
||||
|
||||
@@ -47,15 +50,19 @@ static void
|
||||
on_add_category(GtkButton *self,
|
||||
gpointer user_data)
|
||||
{
|
||||
FlashcardsCreateCategoryDialog *dialog = flashcards_create_category_dialog_new(user_data);
|
||||
FlashcardsCreateCategoryDialog *dialog;
|
||||
|
||||
dialog = flashcards_create_category_dialog_new(user_data);
|
||||
adw_dialog_present(ADW_DIALOG(dialog), GTK_WIDGET(user_data));
|
||||
}
|
||||
|
||||
void flashcards_app_window_test(FlashcardsAppWindow *win, const gchar *test)
|
||||
{
|
||||
GtkWidget *child;
|
||||
|
||||
database_save_category(win->db, test);
|
||||
|
||||
GtkWidget *child = adw_action_row_new();
|
||||
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);
|
||||
@@ -64,20 +71,25 @@ void flashcards_app_window_test(FlashcardsAppWindow *win, const gchar *test)
|
||||
static void
|
||||
flashcards_app_window_init(FlashcardsAppWindow *win)
|
||||
{
|
||||
GArray *categories;
|
||||
|
||||
gtk_widget_init_template(GTK_WIDGET(win));
|
||||
|
||||
win->db = database_connect(g_get_user_data_dir());
|
||||
database_create_tables(win->db);
|
||||
win->categories = database_load_categories(win->db);
|
||||
|
||||
GArray *categories = win->categories;
|
||||
categories = win->categories;
|
||||
|
||||
for (int i = 0; i < categories->len; i++)
|
||||
{
|
||||
category c = g_array_index(categories, category, i);
|
||||
GtkWidget *child;
|
||||
category c;
|
||||
|
||||
c = g_array_index(categories, category, i);
|
||||
printf("%d: %s\n", c.id, c.name);
|
||||
|
||||
GtkWidget *child = adw_action_row_new();
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user