Automatic enable card on adding image
This commit is contained in:
		| @@ -1,3 +0,0 @@ | ||||
| pub struct Card { | ||||
|      | ||||
| } | ||||
| @@ -1,8 +1,5 @@ | ||||
| /* | ||||
| TODOS: | ||||
|     1. remake db scheme for https://raw.githubusercontent.com/schneems/united-dictionary/master/public/languages/japanese/japanese-english.txt | ||||
|     2. parse it | ||||
|     3. add support for it | ||||
|     4. With incorrect answerd card, it shows hieroglyp, reading ant its translation | ||||
| */ | ||||
|  | ||||
|   | ||||
| @@ -4,10 +4,10 @@ use std::io::ErrorKind; | ||||
| use std::path::Path; | ||||
| use std::rc::Rc; | ||||
|  | ||||
| use crate::card::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}; | ||||
| @@ -109,8 +109,9 @@ impl MemoryCardsEditScene { | ||||
|             None => "".to_owned(), | ||||
|         }; | ||||
|  | ||||
|         let sql = | ||||
|             format!("SELECT imagename, hieroglyph, reading, translation, is_learning FROM cards {selector}"); | ||||
|         let sql = 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,11 +120,11 @@ impl MemoryCardsEditScene { | ||||
|                     Err(_) => String::from(""), | ||||
|                 }; | ||||
|                 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()) | ||||
|                     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(); | ||||
| @@ -198,6 +199,7 @@ async fn new_card_setup<W: IsA<gtk::Window>>(window: Rc<W>) { | ||||
|     let path: String = path.as_path().to_str().unwrap().to_owned(); | ||||
|  | ||||
|     picture_widget.set_file(Some(&gio::File::for_path(&path))); | ||||
|     println!("Image path has changed"); | ||||
|  | ||||
|     let images_store_path = get_program_home_path() + "/images"; | ||||
|  | ||||
| @@ -223,10 +225,25 @@ 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, 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}"); | ||||
|             conn.execute("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  | ||||
|                                                 ) | ||||
|                                             )", (&new_filename, &hieroglyph, &reading, &translation)).unwrap(); | ||||
|             conn.execute("UPDATE cards SET is_learning = TRUE WHERE hieroglyph = ?1", [&hieroglyph]).unwrap(); | ||||
|             w.close(); | ||||
|  | ||||
|         }), | ||||
|     ); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user