summaryrefslogtreecommitdiff
path: root/schist_desktop_gui/src/dialog/import_from_actualbudget_dialog.rs
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2025-08-25 16:35:45 +0000
committerjoeac <me@joeac.net>2025-08-25 16:35:45 +0000
commitfe85652e4d3e8906824baddaafd05d19105579b8 (patch)
tree31b56e31cbf289a34ec1d6707becf3c60933b56f /schist_desktop_gui/src/dialog/import_from_actualbudget_dialog.rs
parentd082a30de6a0cbd1fbe2ab5a4316db0891004129 (diff)
task-072
Co-authored-by: Joe Carstairs <jcarstairs@scottlogic.com> Reviewed-on: https://git.joeac.net/joeac/schist/pulls/3 Co-authored-by: Joe Carstairs <me@joeac.net> Co-committed-by: Joe Carstairs <me@joeac.net>
Diffstat (limited to 'schist_desktop_gui/src/dialog/import_from_actualbudget_dialog.rs')
-rw-r--r--schist_desktop_gui/src/dialog/import_from_actualbudget_dialog.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/schist_desktop_gui/src/dialog/import_from_actualbudget_dialog.rs b/schist_desktop_gui/src/dialog/import_from_actualbudget_dialog.rs
new file mode 100644
index 0000000..10d4ec6
--- /dev/null
+++ b/schist_desktop_gui/src/dialog/import_from_actualbudget_dialog.rs
@@ -0,0 +1,26 @@
+use actualbudget_to_schist_transformer::{
+ actualbudget_state::read_actualbudget_state, schist_state::SchistState,
+ transform_state::transform_state,
+};
+use anyhow::anyhow;
+use diesel::{Connection, SqliteConnection};
+
+pub fn import_from_actualbudget_dialog(
+) -> Option<Result<SchistState, (std::path::PathBuf, anyhow::Error)>> {
+ let path = rfd::FileDialog::new()
+ .add_filter("SQLite database", &["sqlite"])
+ .set_title("Import Actualbudget database")
+ .pick_file();
+
+ path.as_ref()
+ .map(|path| import_from_actualbudget(path).map_err(|err| (path.clone(), err)))
+}
+
+fn import_from_actualbudget(path: &std::path::PathBuf) -> anyhow::Result<SchistState> {
+ let path = path
+ .to_str()
+ .ok_or_else(|| anyhow!("Failed to stringify path: {:?}", path))?;
+ SqliteConnection::establish(path)
+ .map(|mut conn| read_actualbudget_state(&mut conn))?
+ .map(transform_state)?
+}