diff options
author | Ricky Kresslein <rk@lakoliu.com> | 2022-09-23 00:29:26 +0200 |
---|---|---|
committer | Ricky Kresslein <rk@lakoliu.com> | 2022-09-23 00:29:26 +0200 |
commit | 54e7ba5b16045d4e653f392d38f045a4f7183732 (patch) | |
tree | 7162209f596606da225f2d97af358667510beb38 /src/application.rs | |
parent | 83e992c2077a4fb5281a461c74fc6f7265a24bde (diff) | |
download | Furtherance-54e7ba5b16045d4e653f392d38f045a4f7183732.tar.zst |
Import database
Diffstat (limited to 'src/application.rs')
-rwxr-xr-x | src/application.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/application.rs b/src/application.rs index b0972ec..1646a34 100755 --- a/src/application.rs +++ b/src/application.rs @@ -137,6 +137,12 @@ impl FurtheranceApplication { })); self.add_action(&backup_database_action); + let import_database_action = gio::SimpleAction::new("import-database", None); + import_database_action.connect_activate(clone!(@weak self as app => move |_, _| { + app.import_database(); + })); + self.add_action(&import_database_action); + let discard_idle_action = gio::SimpleAction::new("discard-idle-action", None); discard_idle_action.connect_activate(clone!(@weak self as app => move |_, _| { let window = FurtheranceWindow::default(); @@ -326,6 +332,7 @@ impl FurtheranceApplication { } pub fn backup_database(&self) { + // TODO Disable if db is empty let window = self.active_window().unwrap(); let dialog = gtk::FileChooserDialog::new( Some(&gettext("Backup Database")), @@ -362,6 +369,45 @@ impl FurtheranceApplication { dialog.show(); } + + pub fn import_database(&self) { + let window = self.active_window().unwrap(); + let dialog = gtk::FileChooserDialog::new( + Some(&gettext("Backup Database")), + Some(&window), + gtk::FileChooserAction::Open, + &[ + (&gettext("Cancel"), gtk::ResponseType::Reject), + (&gettext("Save"), gtk::ResponseType::Accept), + ] + ); + dialog.set_modal(true); + + // Set a filter to show only SQLite files + let filter = gtk::FileFilter::new(); + gtk::FileFilter::set_name(&filter, Some("*.db")); + filter.add_mime_type("application/x-sqlite3"); + dialog.add_filter(&filter); + + dialog.connect_response( + clone!(@strong dialog, @weak self as this => move |filechooser, resp| { + if resp == gtk::ResponseType::Accept { + if let Some(path) = filechooser.file().and_then(|file| file.path()) { + let path = &path.to_string_lossy(); + let _bkup = database::import_db(path.to_string()); + + let window = FurtheranceWindow::default(); + window.reset_history_box(); + } + dialog.close(); + } else { + dialog.close(); + } + }), + ); + + dialog.show(); + } } impl Default for FurtheranceApplication { |