Add switch to enable cards
This commit is contained in:
@@ -1,21 +1,20 @@
|
||||
use std::borrow::Borrow;
|
||||
use std::cell::RefCell;
|
||||
use std::fs;
|
||||
use std::io::ErrorKind;
|
||||
use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::card::*;
|
||||
use crate::db::*;
|
||||
use crate::ui::cards::new::*;
|
||||
use crate::widgets::card_entry::CardEntry;
|
||||
use crate::card::Card;
|
||||
use glib::subclass::InitializingObject;
|
||||
use gtk::glib::object::ObjectExt;
|
||||
use gtk::glib::{clone, closure_local};
|
||||
use gtk::prelude::WidgetExt;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::ListBox;
|
||||
use gtk::{gio, glib, Box, Button, CompositeTemplate, ScrolledWindow, SearchEntry, Window};
|
||||
use gtk::{gio, glib, Button, CompositeTemplate, ScrolledWindow, SearchEntry, Window};
|
||||
use gtk::{prelude::*, FileDialog};
|
||||
use rusqlite::Connection;
|
||||
use sha256::try_digest;
|
||||
@@ -111,7 +110,7 @@ impl MemoryCardsEditScene {
|
||||
};
|
||||
|
||||
let sql =
|
||||
format!("SELECT imagename, hieroglyph, reading, translation FROM cards {selector}");
|
||||
format!("SELECT imagename, hieroglyph, reading, translation, is_learning FROM cards {selector}");
|
||||
let mut stmt = conn.prepare(sql.as_str()).unwrap();
|
||||
let cards_iter = stmt
|
||||
.query_map([], |row| {
|
||||
@@ -119,12 +118,15 @@ impl MemoryCardsEditScene {
|
||||
Ok(path) => path,
|
||||
Err(_) => String::from(""),
|
||||
};
|
||||
let image_path: String = get_images_store_path() + &image_path;
|
||||
let hieroglyph: String = row.get(1).unwrap();
|
||||
let reading: String = row.get(2).unwrap();
|
||||
let hieroglyph = format!("{} ({})", hieroglyph, reading);
|
||||
let translation: String = row.get(3).unwrap();
|
||||
let entry = CardEntry::new(&image_path, &hieroglyph, &translation);
|
||||
let c = Card::new(
|
||||
Some(get_images_store_path() + &image_path),
|
||||
Some(row.get(1).unwrap()),
|
||||
Some(row.get(2).unwrap()),
|
||||
Some(row.get(3).unwrap()),
|
||||
Some(row.get(4).unwrap())
|
||||
);
|
||||
let entry = CardEntry::new(&c);
|
||||
entry.update_state();
|
||||
Ok(entry)
|
||||
})
|
||||
.unwrap();
|
||||
@@ -156,21 +158,12 @@ impl MemoryCardsEditScene {
|
||||
|
||||
card.get_edit_button_widget().connect_closure("clicked", false, closure_local!(@strong self_binding as binding, @strong card => move |_b: &Button| {
|
||||
let new_win = Rc::new(MemoryCardsNewScene::new(&binding.application().unwrap()));
|
||||
//parsing hieroglyph and its reading from a card
|
||||
let hieroglyph_and_reading: String = card.hieroglyph();
|
||||
|
||||
let reading_start = hieroglyph_and_reading.find("(").unwrap();
|
||||
let reading_end = hieroglyph_and_reading.find(")").unwrap();
|
||||
|
||||
let hieroglyph = hieroglyph_and_reading[..reading_start-1].to_owned();
|
||||
let reading = hieroglyph_and_reading[reading_start+1..reading_end].to_owned();
|
||||
let translation = card.translation();
|
||||
|
||||
//setting corresponding properties
|
||||
new_win.get_picture_widget().set_file(Some(&gio::File::for_path(card.imagepath())));
|
||||
new_win.get_hieroglyph_entry().set_text(&hieroglyph);
|
||||
new_win.get_reading_entry().set_text(&reading);
|
||||
new_win.get_translation_entry().set_text(&translation);
|
||||
new_win.get_hieroglyph_entry().set_text(&card.hieroglyph());
|
||||
new_win.get_reading_entry().set_text(&card.reading());
|
||||
new_win.get_translation_entry().set_text(&card.translation());
|
||||
|
||||
new_win.get_file_choose_button().connect_clicked(clone!(@strong new_win, @strong card => move |b: &Button| {
|
||||
b.set_visible(false);
|
||||
@@ -230,7 +223,7 @@ async fn new_card_setup<W: IsA<gtk::Window>>(window: Rc<W>) {
|
||||
let translation = w.get_translation_input();
|
||||
let conn = Connection::open(get_db_path()).unwrap();
|
||||
|
||||
let query = "INSERT OR REPLACE INTO cards (id, imagename, hieroglyph, reading, translation) VALUES((SELECT id FROM cards WHERE hieroglyph = ?2), ?1, ?2, ?3, ?4)";
|
||||
let query = "INSERT OR REPLACE INTO cards (id, imagename, hieroglyph, reading, translation, is_learning) VALUES((SELECT id FROM cards WHERE hieroglyph = ?2), ?1, ?2, ?3, ?4, (SELECT is_learning FROM cards WHERE hieroglyph = ?2))";
|
||||
conn.execute(query, (&new_filename, &hieroglyph, &reading, &translation)).unwrap();
|
||||
println!("new imagepath: {new_filename}");
|
||||
w.close();
|
||||
|
||||
Reference in New Issue
Block a user