mirror of
https://gitlab.cvh-server.de/skrause/flashcards.git
synced 2025-12-12 07:51:38 +01:00
small fixes and description
This commit is contained in:
18
README.md
18
README.md
@@ -1,7 +1,25 @@
|
|||||||
# Flashcards
|
# Flashcards
|
||||||
|
|
||||||
|
## Dependencies
|
||||||
|
|
||||||
|
- Meson
|
||||||
|
- C Compiler
|
||||||
|
- GTK4
|
||||||
|
- Libadwaita
|
||||||
|
- SQLite
|
||||||
|
|
||||||
|
## Build
|
||||||
|
|
||||||
|
```
|
||||||
|
meson setup builddir
|
||||||
|
cd ./builddir
|
||||||
|
meson compile
|
||||||
|
```
|
||||||
|
|
||||||
## Docs
|
## Docs
|
||||||
|
|
||||||
[Flashcards.pdf](https://gitlab.cvh-server.de/skrause/flashcards/-/jobs/artifacts/main/raw/Flashcards.pdf?job=docs)
|
[Flashcards.pdf](https://gitlab.cvh-server.de/skrause/flashcards/-/jobs/artifacts/main/raw/Flashcards.pdf?job=docs)
|
||||||
|
|
||||||
## Download
|
## Download
|
||||||
|
|
||||||
[Flatpak](https://gitlab.cvh-server.de/skrause/flashcards/-/jobs/artifacts/main/raw/li.sopht.Flashcards.flatpak?job=flatpak)
|
[Flatpak](https://gitlab.cvh-server.de/skrause/flashcards/-/jobs/artifacts/main/raw/li.sopht.Flashcards.flatpak?job=flatpak)
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
project('flashcards', 'c',
|
project('flashcards', 'c',
|
||||||
version: '1.0.0',
|
version: '1.0.0',
|
||||||
meson_version: '>= 1.0.0',
|
meson_version: '>= 1.0.0',
|
||||||
default_options: [ 'warning_level=2', 'werror=false', 'c_std=gnu11', ],
|
default_options: [ 'warning_level=2', 'werror=false', 'c_std=gnu23', ],
|
||||||
)
|
)
|
||||||
|
|
||||||
flashcards_deps = [
|
flashcards_deps = [
|
||||||
@@ -90,7 +90,7 @@ foreach arg: test_c_args
|
|||||||
project_c_args += arg
|
project_c_args += arg
|
||||||
endif
|
endif
|
||||||
endforeach
|
endforeach
|
||||||
# add_project_arguments(project_c_args, language: 'c')
|
add_project_arguments(project_c_args, language: 'c')
|
||||||
|
|
||||||
executable('flashcards',
|
executable('flashcards',
|
||||||
sourcefiles,
|
sourcefiles,
|
||||||
|
|||||||
@@ -5,9 +5,11 @@
|
|||||||
sqlite3 *database_connect(const char *path)
|
sqlite3 *database_connect(const char *path)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
gchar *file;
|
||||||
gchar *file = g_build_filename(path, "cards.db", NULL);
|
|
||||||
sqlite3 *db;
|
sqlite3 *db;
|
||||||
|
|
||||||
|
file = g_build_filename(path, "cards.db", NULL);
|
||||||
|
|
||||||
rc = sqlite3_open(file, &db);
|
rc = sqlite3_open(file, &db);
|
||||||
|
|
||||||
if (rc)
|
if (rc)
|
||||||
@@ -33,12 +35,13 @@ void database_create_tables(sqlite3 *db)
|
|||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
|
const char *sql;
|
||||||
|
|
||||||
char *sql = "CREATE TABLE IF NOT EXISTS `cards` ("
|
sql = "CREATE TABLE IF NOT EXISTS `cards` ("
|
||||||
"`category` INTEGER NOT NULL,"
|
"`category` INTEGER NOT NULL,"
|
||||||
"`task` TEXT NOT NULL,"
|
"`task` TEXT NOT NULL,"
|
||||||
"`solution` TEXT NOT NULL"
|
"`solution` TEXT NOT NULL"
|
||||||
")";
|
")";
|
||||||
|
|
||||||
rc = sqlite3_prepare_v2(db, sql, -1, &stmt, 0);
|
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 *database_load_categories(sqlite3 *db)
|
||||||
{
|
{
|
||||||
GArray *categories = g_array_new(TRUE, FALSE, sizeof(category));
|
GArray *categories;
|
||||||
|
|
||||||
int rc;
|
int rc;
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
|
|
||||||
|
categories = g_array_new(TRUE, FALSE, sizeof(category));
|
||||||
|
|
||||||
rc = sqlite3_prepare_v2(db, "SELECT * FROM categories", -1, &stmt, 0);
|
rc = sqlite3_prepare_v2(db, "SELECT * FROM categories", -1, &stmt, 0);
|
||||||
|
|
||||||
if (rc != SQLITE_OK)
|
if (rc != SQLITE_OK)
|
||||||
@@ -109,10 +113,8 @@ GArray *database_load_categories(sqlite3 *db)
|
|||||||
while (sqlite3_step(stmt) == SQLITE_ROW)
|
while (sqlite3_step(stmt) == SQLITE_ROW)
|
||||||
{
|
{
|
||||||
int id = sqlite3_column_int(stmt, 0);
|
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};
|
category c = {id, name};
|
||||||
g_array_append_val(categories, c);
|
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 *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;
|
return cards;
|
||||||
}
|
}
|
||||||
@@ -31,15 +31,18 @@ G_DEFINE_TYPE(FlashcardsAppWindow, flashcards_app_window, ADW_TYPE_APPLICATION_W
|
|||||||
static void
|
static void
|
||||||
on_category_selected(GtkListBox *box, GtkListBoxRow *row, gpointer user_data)
|
on_category_selected(GtkListBox *box, GtkListBoxRow *row, gpointer user_data)
|
||||||
{
|
{
|
||||||
|
FlashcardsAppWindow *win;
|
||||||
|
int id;
|
||||||
|
|
||||||
if (row == NULL)
|
if (row == NULL)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
printf("Test\n");
|
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);
|
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);
|
printf("%d\n", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,15 +50,19 @@ static void
|
|||||||
on_add_category(GtkButton *self,
|
on_add_category(GtkButton *self,
|
||||||
gpointer user_data)
|
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));
|
adw_dialog_present(ADW_DIALOG(dialog), GTK_WIDGET(user_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
void flashcards_app_window_test(FlashcardsAppWindow *win, const gchar *test)
|
void flashcards_app_window_test(FlashcardsAppWindow *win, const gchar *test)
|
||||||
{
|
{
|
||||||
|
GtkWidget *child;
|
||||||
|
|
||||||
database_save_category(win->db, test);
|
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);
|
adw_preferences_row_set_title(ADW_PREFERENCES_ROW(child), test);
|
||||||
|
|
||||||
gtk_list_box_append(GTK_LIST_BOX(win->topics), child);
|
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
|
static void
|
||||||
flashcards_app_window_init(FlashcardsAppWindow *win)
|
flashcards_app_window_init(FlashcardsAppWindow *win)
|
||||||
{
|
{
|
||||||
|
GArray *categories;
|
||||||
|
|
||||||
gtk_widget_init_template(GTK_WIDGET(win));
|
gtk_widget_init_template(GTK_WIDGET(win));
|
||||||
|
|
||||||
win->db = database_connect(g_get_user_data_dir());
|
win->db = database_connect(g_get_user_data_dir());
|
||||||
database_create_tables(win->db);
|
database_create_tables(win->db);
|
||||||
win->categories = database_load_categories(win->db);
|
win->categories = database_load_categories(win->db);
|
||||||
|
|
||||||
GArray *categories = win->categories;
|
categories = win->categories;
|
||||||
|
|
||||||
for (int i = 0; i < categories->len; i++)
|
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);
|
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);
|
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(GTK_LIST_BOX(win->topics), child);
|
||||||
|
|||||||
Reference in New Issue
Block a user