diff --git a/Cargo.toml b/Cargo.toml
index 40ba618..b3f78be 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,6 +9,7 @@ edition = "2021"
gtk = { version = "0.8.1", package = "gtk4", features = ["v4_12"] }
rand = "0.8.5"
+sqlite = "0.34.0"
[build-dependencies]
dirs = "5.0.1"
diff --git a/cards.drawio b/cards.drawio
new file mode 100644
index 0000000..f4482f3
--- /dev/null
+++ b/cards.drawio
@@ -0,0 +1,65 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/db.rs b/src/db.rs
new file mode 100644
index 0000000..c494340
--- /dev/null
+++ b/src/db.rs
@@ -0,0 +1,33 @@
+use sqlite;
+use std::{path::PathBuf, process::Command};
+
+pub fn init() {
+ let program_home_path = if cfg!(target_os = "windows") {
+ let binding = std::env::var("APP_DATA").expect("No APP_DATA directory");
+ let mut appdata = PathBuf::from(&binding);
+
+ appdata = appdata.join("learn-hieroglyph");
+ Command::new("mkdir").arg(&appdata);
+
+ appdata
+ } else {
+ let binding = std::env::var("HOME").expect("No HOME directory");
+ let mut home = PathBuf::from(&binding);
+
+ home = home.join(".config/learn-hieroglyph");
+ Command::new("mkdir").args(["-p", &home.to_str().unwrap()]).spawn().expect(&format!("Cannot create program's home: {}", &home.to_str().unwrap()));
+
+ home
+ };
+
+ println!("Program's home: {}", program_home_path.as_path().to_str().unwrap());
+
+ let connection = sqlite::open(program_home_path.join("db.sqlite")).unwrap();
+
+ connection.execute("CREATE TABLE IF NOT EXISTS cards (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ image_hash CHAR(64),
+ hieroglyph VARCHAR(2),
+ translation VARCHAR(128)
+ )").unwrap();
+}
diff --git a/src/main.rs b/src/main.rs
index 6c34c53..fba4bc7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,7 @@
mod game;
mod ui;
mod widgets;
+mod db;
use crate::ui::menu::MenuScene;
@@ -12,6 +13,8 @@ const APP_ID: &str = "org.foxarmy.learn-hieroglyph";
fn main() -> glib::ExitCode {
gio::resources_register_include!("compiled.gresource").expect("Cannot include gresources");
+ db::init();
+
let app: Application = Application::builder().application_id(APP_ID).build();
app.connect_activate(test_ui);
diff --git a/src/ui/cards/edit/imp.rs b/src/ui/cards/edit/imp.rs
index cbdbb25..e8bf643 100644
--- a/src/ui/cards/edit/imp.rs
+++ b/src/ui/cards/edit/imp.rs
@@ -6,6 +6,7 @@ use gtk::glib::{clone, closure_local};
use gtk::subclass::prelude::*;
use gtk::{glib, Button, CompositeTemplate, ScrolledWindow, SearchEntry, Window};
use gtk::{prelude::*, FileDialog};
+use sqlite;
use crate::ui::cards::new::*;
use crate::widgets::card_entry::CardEntry;
@@ -49,9 +50,7 @@ impl ObjectImpl for MemoryCardsEditScene {
closure_local!(@strong binding => move |_b: &Button| {
let new_win = Rc::new(MemoryCardsNewScene::new(&binding.application().unwrap()));
new_win.get_file_choose_button().connect_clicked(clone!(@strong new_win => move |_| {
- let path = Rc::new(String::from(""));
- gtk::glib::MainContext::default().spawn_local(file_choose_dialog(Rc::clone(&new_win), Rc::clone(&path)));
- println!("{}", path); // this is empty cuz it's not waiting for user
+ gtk::glib::MainContext::default().spawn_local(file_choose_dialog(Rc::clone(&new_win)));
}));
new_win.present();
}));
@@ -63,14 +62,17 @@ impl ObjectImpl for MemoryCardsEditScene {
}
}
-async fn file_choose_dialog>(window: Rc, mut _p: Rc) {
+async fn file_choose_dialog>(window: Rc) {
let dialog: FileDialog = gtk::FileDialog::builder().build();
let answer = dialog.open_future(Some(&*window)).await;
let path = answer.unwrap().path().unwrap();
let path = path.as_path().to_str();
- // _p = Rc::new(path.into_os_string().into_string().unwrap());
let w: &MemoryCardsNewScene = Into::<&Window>::into(window.upcast_ref()).downcast_ref().unwrap(); // Weird casting from &Window as passed in func to &MemoryCardsNewScene
w.get_image_widget().set_file(path);
+
+ let conn = sqlite::open("test.db").unwrap();
+
+ conn.execute("CREATE TABLE test(field_one TEXT, field_two INTEGER); INSERT INTO test VALUES ('Suka', 15);").unwrap();
}
impl WidgetImpl for MemoryCardsEditScene {}