rollback to gtk 4.8
This commit is contained in:
parent
ada58bc37b
commit
a2c4dbcb8e
|
@ -6,7 +6,7 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
gtk = { version = "0.8.1", package = "gtk4", features = ["v4_12"] }
|
gtk = { version = "0.8.1", package = "gtk4", features = ["v4_8"] }
|
||||||
|
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
rusqlite = "0.31.0"
|
rusqlite = "0.31.0"
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
// There's no way to pack an appinage with gtk 4.12 as there's no way to put glibc inside an appimage according to https://github.com/AppImageCommunity/pkg2appimage/blob/master/excludelist
|
||||||
|
// The only way to do that is rollback to gtk 4.8 and rewrite neccesary parts of the program.
|
||||||
|
|
||||||
#![windows_subsystem = "windows"]
|
#![windows_subsystem = "windows"]
|
||||||
|
|
||||||
mod db;
|
mod db;
|
||||||
|
|
|
@ -4,25 +4,26 @@ use std::fs;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
use std::path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
|
||||||
use crate::card::Card;
|
use crate::card::Card;
|
||||||
use crate::db::*;
|
use crate::db::*;
|
||||||
use crate::ui::cards::new::*;
|
use crate::ui::cards::new::*;
|
||||||
use crate::widgets::card_entry::CardEntry;
|
use crate::widgets::card_entry::CardEntry;
|
||||||
use glib::subclass::InitializingObject;
|
use glib::subclass::InitializingObject;
|
||||||
|
use gtk::ffi::GtkFileChooserDialog;
|
||||||
use gtk::gio::ListStore;
|
use gtk::gio::ListStore;
|
||||||
|
use gtk::glib::closure::IntoClosureReturnValue;
|
||||||
use gtk::glib::object::ObjectExt;
|
use gtk::glib::object::ObjectExt;
|
||||||
use gtk::glib::{clone, closure_local, Object};
|
use gtk::glib::{clone, closure_local, Object};
|
||||||
use gtk::prelude::WidgetExt;
|
use gtk::prelude::WidgetExt;
|
||||||
|
use gtk::prelude::*;
|
||||||
use gtk::subclass::prelude::*;
|
use gtk::subclass::prelude::*;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio, glib, Button, CompositeTemplate, ListView, NoSelection, ScrolledWindow, SearchEntry,
|
gio, glib, ApplicationWindow, Button, CompositeTemplate, FileChooserAction, ListView,
|
||||||
Switch, Window,
|
NoSelection, ResponseType, ScrolledWindow, SearchEntry, Switch, Window,
|
||||||
};
|
};
|
||||||
use gtk::{prelude::*, FileDialog};
|
|
||||||
use gtk::{ListItem, SignalListItemFactory};
|
use gtk::{ListItem, SignalListItemFactory};
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use sha256::try_digest;
|
use sha256::try_digest;
|
||||||
|
@ -217,7 +218,6 @@ impl MemoryCardsEditScene {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn query_cards(&self, options: Option<String>) {
|
pub fn query_cards(&self, options: Option<String>) {
|
||||||
|
|
||||||
let conn = Connection::open(get_db_path()).unwrap();
|
let conn = Connection::open(get_db_path()).unwrap();
|
||||||
|
|
||||||
let selector = match options {
|
let selector = match options {
|
||||||
|
@ -251,7 +251,11 @@ impl MemoryCardsEditScene {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
self.displaying_cards.lock().unwrap().borrow_mut().clear();
|
self.displaying_cards.lock().unwrap().borrow_mut().clear();
|
||||||
for c in cards_iter {
|
for c in cards_iter {
|
||||||
self.displaying_cards.lock().unwrap().borrow_mut().push(c.unwrap());
|
self.displaying_cards
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.borrow_mut()
|
||||||
|
.push(c.unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -262,18 +266,24 @@ async fn new_card_setup<W: IsA<gtk::Window>>(window: Rc<W>) {
|
||||||
.unwrap(); // Weird casting from &Window as passed in func to &MemoryCardsNewScene
|
.unwrap(); // Weird casting from &Window as passed in func to &MemoryCardsNewScene
|
||||||
|
|
||||||
let picture_widget = w.get_picture_widget();
|
let picture_widget = w.get_picture_widget();
|
||||||
|
let dialog = gtk::FileChooserDialog::new(
|
||||||
|
Some("Open File"),
|
||||||
|
Some(Into::<&Window>::into(w.upcast_ref())),
|
||||||
|
FileChooserAction::Open,
|
||||||
|
&[
|
||||||
|
("_Cancel", ResponseType::Cancel),
|
||||||
|
("_Open", ResponseType::Accept),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
let dialog: FileDialog = gtk::FileDialog::builder().build();
|
let path = RefCell::new(String::from(""));
|
||||||
let answer = dialog.open_future(Some(&*window)).await;
|
dialog.run_async(clone!( @strong path, @strong w, @strong picture_widget => move |a, _b| {
|
||||||
let path = match answer {
|
let c = a.file().unwrap().path().unwrap().as_os_str().to_owned().to_str().unwrap().to_string();
|
||||||
Ok(p) => p,
|
println!("{c}");
|
||||||
Err(_) => return,
|
*path.borrow_mut() = c;
|
||||||
}
|
a.close();
|
||||||
.path()
|
|
||||||
.unwrap();
|
|
||||||
let path: String = path.as_path().to_str().unwrap().to_owned();
|
|
||||||
|
|
||||||
picture_widget.set_file(Some(&gio::File::for_path(&path)));
|
picture_widget.set_file(Some(&gio::File::for_path(Path::new(path.borrow().as_str()))));
|
||||||
|
|
||||||
let images_store_path = get_program_home_path() + "/images";
|
let images_store_path = get_program_home_path() + "/images";
|
||||||
|
|
||||||
|
@ -289,11 +299,13 @@ async fn new_card_setup<W: IsA<gtk::Window>>(window: Rc<W>) {
|
||||||
"clicked",
|
"clicked",
|
||||||
false,
|
false,
|
||||||
closure_local!(@strong w, @strong path => move |_b: &Button| {
|
closure_local!(@strong w, @strong path => move |_b: &Button| {
|
||||||
let hash = try_digest(&path).unwrap();
|
let p = path.borrow();
|
||||||
let extenstion = Path::new(path.as_str()).extension().unwrap().to_str().unwrap();
|
let p = p.as_str();
|
||||||
|
let hash = try_digest(path.borrow().as_str()).unwrap();
|
||||||
|
let extenstion = Path::new(p).extension().unwrap().to_str().unwrap();
|
||||||
let new_filename: String = hash.as_str().to_owned() + "." + extenstion;
|
let new_filename: String = hash.as_str().to_owned() + "." + extenstion;
|
||||||
let stored_image_path = Path::new(&images_store_path).join(&new_filename);
|
let stored_image_path = Path::new(&images_store_path).join(&new_filename);
|
||||||
fs::copy(&path, stored_image_path).expect("Error copying image to store");
|
fs::copy(&p, stored_image_path).expect("Error copying image to store");
|
||||||
|
|
||||||
let hieroglyph = w.get_hieroglyph_input();
|
let hieroglyph = w.get_hieroglyph_input();
|
||||||
let conn = Connection::open(get_db_path()).unwrap();
|
let conn = Connection::open(get_db_path()).unwrap();
|
||||||
|
@ -302,6 +314,20 @@ async fn new_card_setup<W: IsA<gtk::Window>>(window: Rc<W>) {
|
||||||
conn.execute("UPDATE cards SET is_learning = TRUE WHERE hieroglyph = ?1", [&hieroglyph]).unwrap();
|
conn.execute("UPDATE cards SET is_learning = TRUE WHERE hieroglyph = ?1", [&hieroglyph]).unwrap();
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
// let dialog: FileDialog = gtk::FileDialog::builder().build();
|
||||||
|
// let answer = Ok("");
|
||||||
|
// let answer = dialog.open_future(Some(&*window)).await;
|
||||||
|
// let path = match answer {
|
||||||
|
// Ok(p) => p,
|
||||||
|
// Err(_) => return,
|
||||||
|
// };
|
||||||
|
// .path()
|
||||||
|
// .unwrap();
|
||||||
|
// let path: String = path.as_path().to_str().unwrap().to_owned();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WidgetImpl for MemoryCardsEditScene {}
|
impl WidgetImpl for MemoryCardsEditScene {}
|
||||||
|
|
Loading…
Reference in New Issue