mirror of
https://gitlab.cvh-server.de/skrause/flashcards.git
synced 2025-12-12 06:41:38 +01:00
small fixes and description
This commit is contained in:
18
README.md
18
README.md
@@ -1,7 +1,25 @@
|
||||
# Flashcards
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Meson
|
||||
- C Compiler
|
||||
- GTK4
|
||||
- Libadwaita
|
||||
- SQLite
|
||||
|
||||
## Build
|
||||
|
||||
```
|
||||
meson setup builddir
|
||||
cd ./builddir
|
||||
meson compile
|
||||
```
|
||||
|
||||
## Docs
|
||||
|
||||
[Flashcards.pdf](https://gitlab.cvh-server.de/skrause/flashcards/-/jobs/artifacts/main/raw/Flashcards.pdf?job=docs)
|
||||
|
||||
## Download
|
||||
|
||||
[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',
|
||||
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 = [
|
||||
@@ -90,7 +90,7 @@ foreach arg: test_c_args
|
||||
project_c_args += arg
|
||||
endif
|
||||
endforeach
|
||||
# add_project_arguments(project_c_args, language: 'c')
|
||||
add_project_arguments(project_c_args, language: 'c')
|
||||
|
||||
executable('flashcards',
|
||||
sourcefiles,
|
||||
|
||||
@@ -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,8 +35,9 @@ void database_create_tables(sqlite3 *db)
|
||||
{
|
||||
int rc;
|
||||
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,"
|
||||
"`task` TEXT NOT NULL,"
|
||||
"`solution` TEXT NOT NULL"
|
||||
@@ -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