update ui
This commit is contained in:
@@ -60,7 +60,8 @@ impl ObjectImpl for MemoryCardsEditScene {
|
||||
false,
|
||||
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 |_| {
|
||||
new_win.get_file_choose_button().connect_clicked(clone!(@strong new_win => move |b: &Button| {
|
||||
b.set_visible(false);
|
||||
gtk::glib::MainContext::default().spawn_local(file_choose_dialog(Rc::clone(&new_win)));
|
||||
}));
|
||||
new_win.get_done_button().connect_closure("clicked", true, closure_local!(@strong binding => move |_w: &Button| {
|
||||
@@ -144,7 +145,7 @@ impl MemoryCardsEditScene {
|
||||
self_binding.imp().query_cards(None);
|
||||
self_binding.imp().update_card_list();
|
||||
}));
|
||||
card.update_file_for_picture();
|
||||
card.update_file_for_image();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,14 +153,17 @@ impl MemoryCardsEditScene {
|
||||
async fn file_choose_dialog<W: IsA<gtk::Window>>(window: Rc<W>) {
|
||||
let dialog: FileDialog = gtk::FileDialog::builder().build();
|
||||
let answer = dialog.open_future(Some(&*window)).await;
|
||||
let path = answer.unwrap().path().unwrap();
|
||||
let path: &str = path.as_path().to_str().unwrap();
|
||||
let path = match answer {
|
||||
Ok(p) => p,
|
||||
Err(_) => return
|
||||
}.path().unwrap();
|
||||
let path: String = path.as_path().to_str().unwrap().to_owned();
|
||||
let w: &MemoryCardsNewScene = Into::<&Window>::into(window.upcast_ref())
|
||||
.downcast_ref()
|
||||
.unwrap(); // Weird casting from &Window as passed in func to &MemoryCardsNewScene
|
||||
|
||||
w.get_picture_widget()
|
||||
.set_file(Some(&gio::File::for_path(path)));
|
||||
.set_file(Some(&gio::File::for_path(&path)));
|
||||
|
||||
let images_store_path = get_program_home_path() + "/images";
|
||||
|
||||
@@ -167,24 +171,26 @@ async fn file_choose_dialog<W: IsA<gtk::Window>>(window: Rc<W>) {
|
||||
Ok(_) => {}
|
||||
Err(error) => match error.kind() {
|
||||
ErrorKind::AlreadyExists => {}
|
||||
_ => panic!("Could not create directory for storing pictures!"),
|
||||
_ => panic!("Could not create directory for storing images!"),
|
||||
},
|
||||
};
|
||||
|
||||
let hash = try_digest(path).unwrap();
|
||||
let extenstion = Path::new(path).extension().unwrap().to_str().unwrap();
|
||||
let new_filename: String = hash.as_str().to_owned() + "." + extenstion;
|
||||
let stored_image_path = Path::new(&images_store_path).join(&new_filename);
|
||||
fs::copy(path, stored_image_path).expect("Error copying image to store");
|
||||
|
||||
println!("Setting handler");
|
||||
w.get_done_button().connect_closure(
|
||||
"clicked",
|
||||
false,
|
||||
closure_local!(@strong w => move |_b: &Button| {
|
||||
closure_local!(@strong w, @strong path => move |_b: &Button| {
|
||||
let hash = try_digest(&path).unwrap();
|
||||
let extenstion = Path::new(path.as_str()).extension().unwrap().to_str().unwrap();
|
||||
let new_filename: String = hash.as_str().to_owned() + "." + extenstion;
|
||||
let stored_image_path = Path::new(&images_store_path).join(&new_filename);
|
||||
fs::copy(&path, stored_image_path).expect("Error copying image to store");
|
||||
|
||||
let hieroglyph = w.get_hieroglyph_input();
|
||||
let reading = w.get_reading_input();
|
||||
let conn = Connection::open(get_db_path()).unwrap();
|
||||
|
||||
println!("INSERTING NEW IMAGE");
|
||||
|
||||
let query = "INSERT INTO cards (imagename, hieroglyph, reading) VALUES(?1, ?2, ?3)";
|
||||
conn.execute(query, (&new_filename, &hieroglyph, &reading)).unwrap();
|
||||
w.close();
|
||||
|
||||
Reference in New Issue
Block a user