mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
cleanup unused constructions, fix tab state for bookmark action
This commit is contained in:
parent
c511b97d2d
commit
fb8f9904d0
@ -1,13 +1,11 @@
|
|||||||
mod about;
|
mod about;
|
||||||
mod action;
|
mod action;
|
||||||
mod database;
|
mod database;
|
||||||
mod welcome;
|
|
||||||
mod widget;
|
mod widget;
|
||||||
mod window;
|
mod window;
|
||||||
|
|
||||||
use about::About;
|
use about::About;
|
||||||
use action::Action;
|
use action::Action;
|
||||||
//use welcome::Welcome;
|
|
||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
use window::Window;
|
use window::Window;
|
||||||
|
|
||||||
@ -22,7 +20,6 @@ use std::rc::Rc;
|
|||||||
|
|
||||||
pub struct Browser {
|
pub struct Browser {
|
||||||
action: Rc<Action>,
|
action: Rc<Action>,
|
||||||
profile: Rc<Profile>,
|
|
||||||
widget: Rc<Widget>,
|
widget: Rc<Widget>,
|
||||||
window: Rc<Window>,
|
window: Rc<Window>,
|
||||||
}
|
}
|
||||||
@ -95,7 +92,6 @@ impl Browser {
|
|||||||
// Return new activated `Self`
|
// Return new activated `Self`
|
||||||
Self {
|
Self {
|
||||||
action,
|
action,
|
||||||
profile,
|
|
||||||
widget,
|
widget,
|
||||||
window,
|
window,
|
||||||
}
|
}
|
||||||
@ -172,17 +168,7 @@ impl Browser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn present(&self) -> &Self {
|
pub fn present(&self) -> &Self {
|
||||||
// Show main window
|
|
||||||
self.widget.gobject().present();
|
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
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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<Profile>,
|
|
||||||
widget: Rc<Widget>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Welcome {
|
|
||||||
// Construct
|
|
||||||
|
|
||||||
/// Create new `Self` for given Profile
|
|
||||||
pub fn new(profile: Rc<Profile>, 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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -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<Vec<String>>, // 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<i64>) + '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::<i64>().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))
|
|
||||||
}
|
|
||||||
}
|
|
@ -50,6 +50,7 @@ impl Tab {
|
|||||||
let state = tab_page.map(|this| tab_view.page_position(this));
|
let state = tab_page.map(|this| tab_view.page_position(this));
|
||||||
|
|
||||||
// Update actions with new state value
|
// Update actions with new state value
|
||||||
|
action.bookmark().change_state(state);
|
||||||
action.close_all().change_state(state);
|
action.close_all().change_state(state);
|
||||||
action.close().change_state(state);
|
action.close().change_state(state);
|
||||||
action.history_back().change_state(state);
|
action.history_back().change_state(state);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
mod bookmark;
|
mod bookmark;
|
||||||
mod database;
|
mod database;
|
||||||
mod history;
|
//mod history;
|
||||||
mod identity;
|
//mod identity;
|
||||||
|
|
||||||
use bookmark::Bookmark;
|
use bookmark::Bookmark;
|
||||||
use database::Database;
|
use database::Database;
|
||||||
@ -108,8 +108,9 @@ pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
|||||||
|
|
||||||
// Delegate migration to children components
|
// Delegate migration to children components
|
||||||
bookmark::migrate(tx)?;
|
bookmark::migrate(tx)?;
|
||||||
history::migrate(tx)?;
|
// @TODO not in use yet
|
||||||
identity::migrate(tx)?;
|
// history::migrate(tx)?;
|
||||||
|
// identity::migrate(tx)?;
|
||||||
|
|
||||||
// Success
|
// Success
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -4,7 +4,7 @@ use std::{rc::Rc, sync::RwLock};
|
|||||||
|
|
||||||
pub struct Table {
|
pub struct Table {
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
pub profile_id: i64,
|
//pub profile_id: i64,
|
||||||
pub time: DateTime,
|
pub time: DateTime,
|
||||||
pub request: String,
|
pub request: String,
|
||||||
}
|
}
|
||||||
@ -112,15 +112,10 @@ pub fn select(
|
|||||||
WHERE `profile_id` = ? AND `request` LIKE ?",
|
WHERE `profile_id` = ? AND `request` LIKE ?",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let filter = match request {
|
let result = stmt.query_map((profile_id, request.unwrap_or("%")), |row| {
|
||||||
Some(value) => value,
|
|
||||||
None => "%",
|
|
||||||
};
|
|
||||||
|
|
||||||
let result = stmt.query_map((profile_id, filter), |row| {
|
|
||||||
Ok(Table {
|
Ok(Table {
|
||||||
id: row.get(0)?,
|
id: row.get(0)?,
|
||||||
profile_id: row.get(1)?,
|
//profile_id: row.get(1)?,
|
||||||
time: DateTime::from_unix_local(row.get(2)?).unwrap(),
|
time: DateTime::from_unix_local(row.get(2)?).unwrap(),
|
||||||
request: row.get(3)?,
|
request: row.get(3)?,
|
||||||
})
|
})
|
||||||
|
@ -32,12 +32,7 @@ impl Database {
|
|||||||
|
|
||||||
/// Get active profile record if exist
|
/// Get active profile record if exist
|
||||||
pub fn active(&self) -> Option<Table> {
|
pub fn active(&self) -> Option<Table> {
|
||||||
for record in self.records() {
|
self.records().into_iter().find(|record| record.is_active)
|
||||||
if record.is_active {
|
|
||||||
return Some(record);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
@ -69,6 +64,7 @@ impl Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* @TODO not in use
|
||||||
/// Set `is_active` status `true` for the record with given profile ID
|
/// Set `is_active` status `true` for the record with given profile ID
|
||||||
/// * reset other records to `false`
|
/// * reset other records to `false`
|
||||||
pub fn activate(&self, id: i64) -> Result<(), ()> {
|
pub fn activate(&self, id: i64) -> Result<(), ()> {
|
||||||
@ -92,7 +88,7 @@ impl Database {
|
|||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(_) => Err(()),
|
Err(_) => Err(()),
|
||||||
} // @TODO make sure ID exist and was changed
|
} // @TODO make sure ID exist and was changed
|
||||||
}
|
} */
|
||||||
}
|
}
|
||||||
|
|
||||||
// Low-level DB API
|
// Low-level DB API
|
||||||
|
@ -54,12 +54,7 @@ pub fn select(
|
|||||||
WHERE `profile_id` = ? AND `request` LIKE ?",
|
WHERE `profile_id` = ? AND `request` LIKE ?",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let filter = match request {
|
let result = stmt.query_map((profile_id, request.unwrap_or("%")), |row| {
|
||||||
Some(value) => value,
|
|
||||||
None => format!("%"),
|
|
||||||
};
|
|
||||||
|
|
||||||
let result = stmt.query_map((profile_id, filter), |row| {
|
|
||||||
Ok(Table {
|
Ok(Table {
|
||||||
id: row.get(0)?,
|
id: row.get(0)?,
|
||||||
profile_id: row.get(1)?,
|
profile_id: row.get(1)?,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user