diff --git a/src/app/browser.rs b/src/app/browser.rs index e7a6b5a9..6dda47c7 100644 --- a/src/app/browser.rs +++ b/src/app/browser.rs @@ -1,13 +1,11 @@ mod about; mod action; mod database; -mod welcome; mod widget; mod window; use about::About; use action::Action; -//use welcome::Welcome; use widget::Widget; use window::Window; @@ -22,7 +20,6 @@ use std::rc::Rc; pub struct Browser { action: Rc, - profile: Rc, widget: Rc, window: Rc, } @@ -95,7 +92,6 @@ impl Browser { // Return new activated `Self` Self { action, - profile, widget, window, } @@ -172,17 +168,7 @@ impl Browser { } pub fn present(&self) -> &Self { - // Show main window self.widget.gobject().present(); - - // Show welcome dialog on profile not selected yet (e.g. first launch) - /* @TODO - currently this feature inactive, because profile auto-generated on first application launch - see also: src/app/browser/welcome.rs - if self.profile.database.active().is_none() { - Welcome::new(self.profile.clone(), self.widget.gobject().clone()).present(); - } */ - self } diff --git a/src/app/browser/welcome.rs b/src/app/browser/welcome.rs deleted file mode 100644 index b85af542..00000000 --- a/src/app/browser/welcome.rs +++ /dev/null @@ -1,63 +0,0 @@ -// @TODO prototype -// do not use it as currently profile get auto-generating on application startup! - -mod widget; -use gtk::glib::DateTime; -use widget::Widget; - -use crate::profile::Profile; -use adw::ApplicationWindow; -use std::rc::Rc; - -pub struct Welcome { - profile: Rc, - widget: Rc, -} - -impl Welcome { - // Construct - - /// Create new `Self` for given Profile - pub fn new(profile: Rc, parent: ApplicationWindow) -> Self { - // Init widget - let widget = Rc::new(Widget::new(parent)); - - // Init events - widget.connect_response({ - let profile = profile.clone(); - move |value| { - match value { - Some(id) => { - // Activate selected profile by record ID - let _ = profile.database.activate(id); - } - None => { - // Create and select new profile - let _ = profile - .database - .add(true, DateTime::now_local().unwrap(), None); - } - } // @TODO handle result - } - }); - - // Return activated `Self` - Self { profile, widget } - } - - // Actions - - /// Show dialog for parent [Window](https://docs.gtk.org/gtk4/class.Window.html) - pub fn present(&self) { - // Collect Profile list - let mut responses = Vec::new(); - for record in self.profile.database.records() { - responses.push(( - record.id.to_string(), - record.time.format_iso8601().unwrap().to_string(), - )) - } - // Show dialog - self.widget.present(responses); - } -} diff --git a/src/app/browser/welcome/widget.rs b/src/app/browser/welcome/widget.rs deleted file mode 100644 index 2e6ce00f..00000000 --- a/src/app/browser/welcome/widget.rs +++ /dev/null @@ -1,88 +0,0 @@ -use adw::{ - prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual}, - AlertDialog, ApplicationWindow, ResponseAppearance, -}; -use gtk::prelude::GtkWindowExt; -use std::cell::RefCell; - -const HEADING: &str = "Welcome!"; -const BODY: &str = "Select profile for personal data"; -const RESPONSE_QUIT: (&str, &str) = ("quit", "Quit"); -const RESPONSE_CREATE: (&str, &str) = ("create", "Create new profile"); -const RESPONSE_IMPORT: (&str, &str) = ("import", "Import.."); - -pub struct Widget { - gobject: AlertDialog, - parent: ApplicationWindow, - responses: RefCell>, // wanted to cleanup previous preset by key -} - -impl Widget { - // Constructors - - /// Create new `Self` for [Window](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.3/class.ApplicationWindow.html) - pub fn new(parent: ApplicationWindow) -> Self { - // Init gobject - let gobject = AlertDialog::builder() - .heading(HEADING) - .body(BODY) - .close_response(RESPONSE_QUIT.0) - .default_response(RESPONSE_CREATE.0) - .build(); - - // Set response variants - gobject.add_responses(&[RESPONSE_QUIT, RESPONSE_CREATE, RESPONSE_IMPORT]); - - // Deactivate not implemented feature @TODO - gobject.set_response_enabled(RESPONSE_IMPORT.0, false); - - // Decorate default response preset - gobject.set_response_appearance(RESPONSE_CREATE.0, ResponseAppearance::Suggested); - gobject.set_response_appearance(RESPONSE_QUIT.0, ResponseAppearance::Destructive); - - // Return new `Self` - Self { - gobject, - parent, - responses: RefCell::new(Vec::new()), - } - } - - // Actions - - /// Wrapper for default [response](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/signal.AlertDialog.response.html) signal - /// * return profile ID, new record request on `None` or immediately close `self.parent` given on construction - pub fn connect_response(&self, callback: impl Fn(Option) + 'static) { - self.gobject.connect_response(None, { - let parent = self.parent.clone(); - move |_, response| match response { - id if id == RESPONSE_CREATE.0 => callback(None), - id if id == RESPONSE_QUIT.0 => parent.close(), - _ => callback(Some(response.parse::().unwrap())), - } - }); - } - - /// Show dialog with new profile responses preset - pub fn present(&self, profiles: Vec<(String, String)>) { - // Borrow current index to update - let mut index = self.responses.borrow_mut(); - - // Remove previous responses from widget - for response in index.iter() { - self.gobject.remove_response(response) - } - - // Reset index - index.clear(); - - // Build new preset - for (id, label) in profiles { - self.gobject.add_response(&id, &label); - index.push(id) - } - - // Show dialog - self.gobject.present(Some(&self.parent)) - } -} diff --git a/src/app/browser/window/tab.rs b/src/app/browser/window/tab.rs index 754b2d3c..b4ed630d 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -50,6 +50,7 @@ impl Tab { let state = tab_page.map(|this| tab_view.page_position(this)); // Update actions with new state value + action.bookmark().change_state(state); action.close_all().change_state(state); action.close().change_state(state); action.history_back().change_state(state); diff --git a/src/profile.rs b/src/profile.rs index f6f6ae63..75445af7 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -1,7 +1,7 @@ mod bookmark; mod database; -mod history; -mod identity; +//mod history; +//mod identity; use bookmark::Bookmark; use database::Database; @@ -108,8 +108,9 @@ pub fn migrate(tx: &Transaction) -> Result<(), String> { // Delegate migration to children components bookmark::migrate(tx)?; - history::migrate(tx)?; - identity::migrate(tx)?; + // @TODO not in use yet + // history::migrate(tx)?; + // identity::migrate(tx)?; // Success Ok(()) diff --git a/src/profile/bookmark/database.rs b/src/profile/bookmark/database.rs index 410ade25..45b70d4a 100644 --- a/src/profile/bookmark/database.rs +++ b/src/profile/bookmark/database.rs @@ -4,7 +4,7 @@ use std::{rc::Rc, sync::RwLock}; pub struct Table { pub id: i64, - pub profile_id: i64, + //pub profile_id: i64, pub time: DateTime, pub request: String, } @@ -112,15 +112,10 @@ pub fn select( WHERE `profile_id` = ? AND `request` LIKE ?", )?; - let filter = match request { - Some(value) => value, - None => "%", - }; - - let result = stmt.query_map((profile_id, filter), |row| { + let result = stmt.query_map((profile_id, request.unwrap_or("%")), |row| { Ok(Table { id: row.get(0)?, - profile_id: row.get(1)?, + //profile_id: row.get(1)?, time: DateTime::from_unix_local(row.get(2)?).unwrap(), request: row.get(3)?, }) diff --git a/src/profile/database.rs b/src/profile/database.rs index b21491ac..d5df732c 100644 --- a/src/profile/database.rs +++ b/src/profile/database.rs @@ -32,12 +32,7 @@ impl Database { /// Get active profile record if exist pub fn active(&self) -> Option { - for record in self.records() { - if record.is_active { - return Some(record); - } - } - None + self.records().into_iter().find(|record| record.is_active) } // Setters @@ -69,6 +64,7 @@ impl Database { } } + /* @TODO not in use /// Set `is_active` status `true` for the record with given profile ID /// * reset other records to `false` pub fn activate(&self, id: i64) -> Result<(), ()> { @@ -92,7 +88,7 @@ impl Database { Ok(_) => Ok(()), Err(_) => Err(()), } // @TODO make sure ID exist and was changed - } + } */ } // Low-level DB API diff --git a/src/profile/history/database.rs b/src/profile/history/database.rs index 1645f49f..232ca3ae 100644 --- a/src/profile/history/database.rs +++ b/src/profile/history/database.rs @@ -54,12 +54,7 @@ pub fn select( WHERE `profile_id` = ? AND `request` LIKE ?", )?; - let filter = match request { - Some(value) => value, - None => format!("%"), - }; - - let result = stmt.query_map((profile_id, filter), |row| { + let result = stmt.query_map((profile_id, request.unwrap_or("%")), |row| { Ok(Table { id: row.get(0)?, profile_id: row.get(1)?,