From f50b4cae8b88b8a0ad31b8b1d9ca4a6bf44ee2c1 Mon Sep 17 00:00:00 2001 From: leca Date: Thu, 25 Apr 2024 16:34:31 +0300 Subject: [PATCH] images are now updating instantly --- src/ui/cards/edit/imp.rs | 24 ++++++++++++++++-------- src/ui/cards/edit/mod.rs | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/ui/cards/edit/imp.rs b/src/ui/cards/edit/imp.rs index c2f2ae8..351f6d5 100644 --- a/src/ui/cards/edit/imp.rs +++ b/src/ui/cards/edit/imp.rs @@ -1,7 +1,6 @@ use std::cell::RefCell; use std::fs; use std::io::ErrorKind; -use std::ops::Deref; use std::path::Path; use std::rc::Rc; @@ -79,6 +78,11 @@ impl ObjectImpl for MemoryCardsEditScene { })); self.search_entry.connect_closure("activate", false, closure_local!(@strong binding => move |e: &SearchEntry| { + + // Put query to the separate thread so that cards load on fly. + // gio::spawn_blocking(move || { + + // }); binding.imp().query_cards( match e.text().as_str() { "" => None, @@ -145,7 +149,7 @@ impl MemoryCardsEditScene { let hieroglyph = w.get_hieroglyph_input(); let reading = w.get_reading_input(); let translation = w.get_translation_input(); - + let imagepath = w.get_picture_widget().file(); conn.execute("INSERT OR REPLACE INTO cards ( id, hieroglyph, reading, @@ -160,17 +164,23 @@ impl MemoryCardsEditScene { (SELECT is_learning FROM cards WHERE hieroglyph = ?1), (SELECT imagename FROM cards WHERE hieroglyph = ?1) )", (&hieroglyph, &reading, &translation)).unwrap(); - + let b = imagepath.unwrap().path().unwrap(); + let a = b.to_str(); + println!("a {}", a.unwrap()); + card.set_imagepath(a.unwrap()); + // card.get_image_widget().set_file(a); card.set_hieroglyph(hieroglyph); card.set_reading(reading); card.set_translation(translation); + // println!("{}", card.get_image_widget().file().unwrap().to_string()); + card.update_file_for_image(); - // binding.imp().query_cards(None); - binding.imp().update_state(); + binding.imp().update_state(); w.close(); })); new_win.present(); })); + card_object_to_display.get_is_learning_switch_widget().connect_closure("state-set", false, closure_local!(@strong card_object as card => move |_s: &Switch, is_enabled: bool| { let connection = Connection::open(get_db_path()).unwrap(); let is_learning = is_enabled; @@ -178,6 +188,7 @@ impl MemoryCardsEditScene { connection.execute("UPDATE cards SET is_learning = ?1 WHERE hieroglyph = ?2", (&is_learning, &hieroglyph)).unwrap(); glib::Propagation::Proceed })); + card_object_to_display.get_delete_button_widget().connect_closure("clicked", false, closure_local!(@strong card_object as card, @strong self_binding => move |_b: &Button| { let connection = Connection::open(get_db_path()).unwrap(); let imagepath = &card.imagepath(); @@ -199,8 +210,6 @@ impl MemoryCardsEditScene { card_object_to_display.set_islearning(card_object.islearning()); })); - // factory.connect_bind(); - let no_selection_model = NoSelection::new(Some(model)); let list_view = ListView::new(Some(no_selection_model), Some(factory)); self.cards_scrolled_window.set_child(Some(&list_view)); @@ -305,7 +314,6 @@ async fn new_card_setup>(window: Rc) { // ) // )", (&new_filename, &hieroglyph, &reading, &translation)).unwrap(); // println!("") - conn.execute("UPDATE cards SET imagename = ?1 WHERE hieroglyph = ?2", (&new_filename, &hieroglyph)).unwrap(); // conn.execute("INSERT OR REPLACE INTO cards (id, imagename) VALUES ((SELECT id FROM cards WHERE hieroglyph = ?1), ?2)", (&hieroglyph, &new_filename)).unwrap(); conn.execute("UPDATE cards SET is_learning = TRUE WHERE hieroglyph = ?1", [&hieroglyph]).unwrap(); diff --git a/src/ui/cards/edit/mod.rs b/src/ui/cards/edit/mod.rs index e8e071c..e430bcd 100644 --- a/src/ui/cards/edit/mod.rs +++ b/src/ui/cards/edit/mod.rs @@ -1,6 +1,6 @@ mod imp; use glib::Object; -use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, Application, Button, ListBox}; +use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, Application, Button}; glib::wrapper! { pub struct MemoryCardsEditScene(ObjectSubclass)