diff options
Diffstat (limited to 'src/ui')
-rwxr-xr-x | src/ui/history_box.rs | 2 | ||||
-rwxr-xr-x | src/ui/preferences_window.rs | 58 |
2 files changed, 60 insertions, 0 deletions
diff --git a/src/ui/history_box.rs b/src/ui/history_box.rs index 510db07..b36808e 100755 --- a/src/ui/history_box.rs +++ b/src/ui/history_box.rs @@ -94,6 +94,7 @@ impl FurHistoryBox { let app = FurtheranceApplication::default(); app.delete_enabled(false); app.export_csv_enabled(false); + app.backup_database_enabled(false); imp.spinner.set_spinning(false); let name = match view { @@ -105,6 +106,7 @@ impl FurHistoryBox { View::Tasks => { app.delete_enabled(true); app.export_csv_enabled(true); + app.backup_database_enabled(true); "tasks" } }; diff --git a/src/ui/preferences_window.rs b/src/ui/preferences_window.rs index 188a478..6507ee3 100755 --- a/src/ui/preferences_window.rs +++ b/src/ui/preferences_window.rs @@ -16,6 +16,8 @@ use adw::prelude::*; use adw::subclass::prelude::*; +use gettextrs::*; +use glib::clone; use gtk::glib; use gtk::subclass::prelude::*; use gtk::CompositeTemplate; @@ -23,6 +25,7 @@ use gtk::CompositeTemplate; use crate::settings_manager; use crate::ui::FurtheranceWindow; use crate::FurtheranceApplication; +use crate::database; mod imp { use super::*; @@ -69,6 +72,11 @@ mod imp { pub autosave_expander: TemplateChild<adw::ExpanderRow>, #[template_child] pub autosave_spin: TemplateChild<gtk::SpinButton>, + + #[template_child] + pub database_loc_row: TemplateChild<adw::ActionRow>, + #[template_child] + pub database_browse_btn: TemplateChild<gtk::Button>, } #[glib::object_subclass] @@ -127,6 +135,9 @@ impl FurPreferencesWindow { let manager = adw::StyleManager::default(); let support_darkmode = manager.system_supports_color_schemes(); imp.appearance_group.set_visible(!support_darkmode); + + let db_dir = database::get_directory().to_string_lossy().to_string(); + imp.database_loc_row.set_subtitle(&db_dir); } fn setup_signals(&self) { @@ -211,5 +222,52 @@ impl FurPreferencesWindow { let window = FurtheranceWindow::default(); window.refresh_timer(); }); + + imp.database_browse_btn.connect_clicked(clone!(@weak self as this => move |_| { + let window = FurtheranceApplication::default().active_window().unwrap(); + let dialog = gtk::FileChooserDialog::new( + Some(&gettext("Backup Database")), + Some(&window), + gtk::FileChooserAction::Save, + &[ + (&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.set_current_name("furtherance.db"); + + dialog.connect_response( + clone!(@strong dialog, @weak this as this2 => 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::backup_db(path.to_string()); + + let settings = settings_manager::get_settings(); + let _ = settings.set_string("database-loc", &path.to_string()); + + let imp2 = imp::FurPreferencesWindow::from_instance(&this2); + imp2.database_loc_row.set_subtitle(&path.to_string()); + + let window = FurtheranceWindow::default(); + window.reset_history_box(); + } + dialog.close(); + } else { + dialog.close(); + } + }), + ); + + dialog.show(); + + })); } } |