mirror of
https://gitlab.cvh-server.de/skrause/flashcards.git
synced 2025-12-12 07:51:38 +01:00
small changes, fix lang in flatpak
This commit is contained in:
@@ -4,8 +4,8 @@
|
|||||||
"runtime-version": "47",
|
"runtime-version": "47",
|
||||||
"sdk": "org.gnome.Sdk",
|
"sdk": "org.gnome.Sdk",
|
||||||
"command": "flashcards",
|
"command": "flashcards",
|
||||||
|
"separate-locales": false,
|
||||||
"finish-args": [
|
"finish-args": [
|
||||||
"--share=network",
|
|
||||||
"--share=ipc",
|
"--share=ipc",
|
||||||
"--socket=fallback-x11",
|
"--socket=fallback-x11",
|
||||||
"--device=dri",
|
"--device=dri",
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ template $FlashcardsAppWindow : Adw.ApplicationWindow {
|
|||||||
title: _("Flashcards");
|
title: _("Flashcards");
|
||||||
|
|
||||||
Adw.Breakpoint {
|
Adw.Breakpoint {
|
||||||
condition ( "max-width: 400sp" )
|
condition ( "max-width: 600sp" )
|
||||||
setters {
|
setters {
|
||||||
split_view.collapsed: true;
|
split_view.collapsed: true;
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ template $FlashcardsAppWindow : Adw.ApplicationWindow {
|
|||||||
|
|
||||||
Adw.NavigationSplitView split_view {
|
Adw.NavigationSplitView split_view {
|
||||||
[sidebar]
|
[sidebar]
|
||||||
Adw.NavigationPage sidebar{
|
Adw.NavigationPage sidebar {
|
||||||
title: _("Categories");
|
title: _("Categories");
|
||||||
|
|
||||||
Box {
|
Box {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ on_response(AdwAlertDialog *dialog,
|
|||||||
gchar *response,
|
gchar *response,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
FlashcardsCreateCategoryDialog *self = FLASHCARDS_CREATE_CATEGORY_DIALOG(user_data);
|
FlashcardsCreateCategoryDialog *self = user_data;
|
||||||
|
|
||||||
const gchar *category = gtk_editable_get_text(self->entry);
|
const gchar *category = gtk_editable_get_text(self->entry);
|
||||||
|
|
||||||
|
|||||||
@@ -1,37 +1,35 @@
|
|||||||
#include "database.h"
|
#include "database.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sqlite3.h>
|
|
||||||
|
|
||||||
sqlite3 *db;
|
sqlite3 *database_connect(const char *path)
|
||||||
|
|
||||||
void database_connect(const char *path)
|
|
||||||
{
|
{
|
||||||
// char *zErrMsg = 0;
|
|
||||||
|
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
gchar *file = g_build_filename(path, "cards.db", NULL);
|
gchar *file = g_build_filename(path, "cards.db", NULL);
|
||||||
|
sqlite3 *db;
|
||||||
rc = sqlite3_open(file, &db);
|
rc = sqlite3_open(file, &db);
|
||||||
|
|
||||||
if (rc)
|
if (rc)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
|
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
|
||||||
return;
|
return NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Opened database successfully\n");
|
fprintf(stderr, "Opened database successfully\n");
|
||||||
}
|
}
|
||||||
g_free(file);
|
g_free(file);
|
||||||
|
|
||||||
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
void database_close()
|
void database_close(sqlite3 *db)
|
||||||
{
|
{
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
void database_create_tables()
|
void database_create_tables(sqlite3 *db)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
@@ -69,7 +67,7 @@ void database_create_tables()
|
|||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void database_save_category(const char *c)
|
void database_save_category(sqlite3 *db, const char *c)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
@@ -94,7 +92,7 @@ void database_save_category(const char *c)
|
|||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
GArray *database_load_categories()
|
GArray *database_load_categories(sqlite3 *db)
|
||||||
{
|
{
|
||||||
GArray *categories = g_array_new(TRUE, FALSE, sizeof(category));
|
GArray *categories = g_array_new(TRUE, FALSE, sizeof(category));
|
||||||
|
|
||||||
@@ -123,7 +121,7 @@ GArray *database_load_categories()
|
|||||||
return categories;
|
return categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
void database_save_card(card c)
|
void database_save_card(sqlite3 *db, card c)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
@@ -146,7 +144,7 @@ void database_save_card(card c)
|
|||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
GArray *database_load_cards()
|
GArray *database_load_cards(sqlite3 *db)
|
||||||
{
|
{
|
||||||
GArray *cards = g_array_new(TRUE, FALSE, sizeof(card));
|
GArray *cards = g_array_new(TRUE, FALSE, sizeof(card));
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#include <sqlite3.h>
|
||||||
|
|
||||||
typedef struct category
|
typedef struct category
|
||||||
{
|
{
|
||||||
@@ -13,16 +14,16 @@ typedef struct card
|
|||||||
char *solution;
|
char *solution;
|
||||||
} card;
|
} card;
|
||||||
|
|
||||||
void database_connect(const char *path);
|
sqlite3 *database_connect(const char *path);
|
||||||
|
|
||||||
void database_close();
|
void database_close(sqlite3 *db);
|
||||||
|
|
||||||
void database_create_tables();
|
void database_create_tables(sqlite3 *db);
|
||||||
|
|
||||||
void database_save_category();
|
void database_save_category(sqlite3 *db, const char *c);
|
||||||
|
|
||||||
GArray *database_load_categories();
|
GArray *database_load_categories(sqlite3 *db);
|
||||||
|
|
||||||
void database_save_card(card c);
|
void database_save_card(sqlite3 *db, card c);
|
||||||
|
|
||||||
GArray *database_load_cards();
|
GArray *database_load_cards(sqlite3 *db);
|
||||||
@@ -16,9 +16,9 @@ struct _FlashcardsApp
|
|||||||
G_DEFINE_TYPE(FlashcardsApp, flashcards_app, ADW_TYPE_APPLICATION);
|
G_DEFINE_TYPE(FlashcardsApp, flashcards_app, ADW_TYPE_APPLICATION);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
flashcards_app_quit_action(GSimpleAction *action,
|
flashcards_app_quit(__attribute__((unused)) GSimpleAction *action,
|
||||||
GVariant *parameter,
|
__attribute__((unused)) GVariant *parameter,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
FlashcardsApp *self = user_data;
|
FlashcardsApp *self = user_data;
|
||||||
g_assert(FLASHCARDS_IS_APP(self));
|
g_assert(FLASHCARDS_IS_APP(self));
|
||||||
@@ -26,9 +26,9 @@ flashcards_app_quit_action(GSimpleAction *action,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
flashcards_app_about_action(GSimpleAction *action,
|
flashcards_app_about(__attribute__((unused)) GSimpleAction *action,
|
||||||
GVariant *parameter,
|
__attribute__((unused)) GVariant *parameter,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
static const char *developers[] = {"Sophie Krause", NULL};
|
static const char *developers[] = {"Sophie Krause", NULL};
|
||||||
FlashcardsApp *self = user_data;
|
FlashcardsApp *self = user_data;
|
||||||
@@ -51,8 +51,8 @@ flashcards_app_about_action(GSimpleAction *action,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const GActionEntry app_actions[] = {
|
static const GActionEntry app_actions[] = {
|
||||||
{"quit", flashcards_app_quit_action},
|
{"quit", flashcards_app_quit, NULL, NULL, NULL, {0, 0, 0}},
|
||||||
{"about", flashcards_app_about_action},
|
{"about", flashcards_app_about, NULL, NULL, NULL, {0, 0, 0}},
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -77,13 +77,12 @@ flashcards_app_activate(GApplication *app)
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
flashcards_app_open(GApplication *app,
|
flashcards_app_open(GApplication *app,
|
||||||
GFile **files,
|
__attribute__((unused)) GFile **files,
|
||||||
int n_files,
|
__attribute__((unused)) int n_files,
|
||||||
const char *hint)
|
__attribute__((unused)) const char *hint)
|
||||||
{
|
{
|
||||||
GList *windows;
|
GList *windows;
|
||||||
FlashcardsAppWindow *win;
|
FlashcardsAppWindow *win;
|
||||||
int i;
|
|
||||||
|
|
||||||
windows = gtk_application_get_windows(GTK_APPLICATION(app));
|
windows = gtk_application_get_windows(GTK_APPLICATION(app));
|
||||||
if (windows)
|
if (windows)
|
||||||
@@ -91,9 +90,6 @@ flashcards_app_open(GApplication *app,
|
|||||||
else
|
else
|
||||||
win = flashcards_app_window_new(FLASHCARDS_APP(app));
|
win = flashcards_app_window_new(FLASHCARDS_APP(app));
|
||||||
|
|
||||||
for (i = 0; i < n_files; i++)
|
|
||||||
flashcards_app_window_open(win, files[i]);
|
|
||||||
|
|
||||||
gtk_window_present(GTK_WINDOW(win));
|
gtk_window_present(GTK_WINDOW(win));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ struct _FlashcardsAppWindow
|
|||||||
{
|
{
|
||||||
AdwApplicationWindow parent;
|
AdwApplicationWindow parent;
|
||||||
|
|
||||||
|
sqlite3 *db;
|
||||||
|
|
||||||
GArray *categories;
|
GArray *categories;
|
||||||
|
|
||||||
AdwNavigationSplitView *split_view;
|
AdwNavigationSplitView *split_view;
|
||||||
@@ -34,7 +36,7 @@ on_category_selected(GtkListBox *box, GtkListBoxRow *row, gpointer user_data)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
printf("Test\n");
|
printf("Test\n");
|
||||||
FlashcardsAppWindow *win = FLASHCARDS_APP_WINDOW(gtk_widget_get_root(GTK_WIDGET(box)));
|
FlashcardsAppWindow *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));
|
int id = gtk_list_box_row_get_index(gtk_list_box_get_selected_row(win->topics));
|
||||||
@@ -51,7 +53,7 @@ on_add_category(GtkButton *self,
|
|||||||
|
|
||||||
void flashcards_app_window_test(FlashcardsAppWindow *win, const gchar *test)
|
void flashcards_app_window_test(FlashcardsAppWindow *win, const gchar *test)
|
||||||
{
|
{
|
||||||
database_save_category(test);
|
database_save_category(win->db, test);
|
||||||
|
|
||||||
GtkWidget *child = adw_action_row_new();
|
GtkWidget *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);
|
||||||
@@ -64,9 +66,9 @@ flashcards_app_window_init(FlashcardsAppWindow *win)
|
|||||||
{
|
{
|
||||||
gtk_widget_init_template(GTK_WIDGET(win));
|
gtk_widget_init_template(GTK_WIDGET(win));
|
||||||
|
|
||||||
database_connect(g_get_user_data_dir());
|
win->db = database_connect(g_get_user_data_dir());
|
||||||
database_create_tables();
|
database_create_tables(win->db);
|
||||||
win->categories = database_load_categories();
|
win->categories = database_load_categories(win->db);
|
||||||
|
|
||||||
GArray *categories = win->categories;
|
GArray *categories = win->categories;
|
||||||
|
|
||||||
@@ -102,7 +104,3 @@ flashcards_app_window_new(FlashcardsApp *app)
|
|||||||
{
|
{
|
||||||
return g_object_new(FLASHCARDS_APP_WINDOW_TYPE, "application", app, NULL);
|
return g_object_new(FLASHCARDS_APP_WINDOW_TYPE, "application", app, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void flashcards_app_window_open(FlashcardsAppWindow *win, GFile *file)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,8 +9,6 @@
|
|||||||
G_DECLARE_FINAL_TYPE(FlashcardsAppWindow, flashcards_app_window, FLASHCARDS, APP_WINDOW, AdwApplicationWindow)
|
G_DECLARE_FINAL_TYPE(FlashcardsAppWindow, flashcards_app_window, FLASHCARDS, APP_WINDOW, AdwApplicationWindow)
|
||||||
|
|
||||||
FlashcardsAppWindow *flashcards_app_window_new(FlashcardsApp *app);
|
FlashcardsAppWindow *flashcards_app_window_new(FlashcardsApp *app);
|
||||||
void flashcards_app_window_open(FlashcardsAppWindow *win,
|
|
||||||
GFile *file);
|
|
||||||
void flashcards_app_window_test(FlashcardsAppWindow *win, const gchar *test);
|
void flashcards_app_window_test(FlashcardsAppWindow *win, const gchar *test);
|
||||||
|
|
||||||
#endif /* __FLASHCARDSAPPWIN_H */
|
#endif /* __FLASHCARDSAPPWIN_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user