mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-09-12 15:02:17 +00:00
draft properties update method
This commit is contained in:
parent
50f18cad15
commit
1273f9947d
@ -78,12 +78,15 @@ impl Exit {
|
||||
.auth
|
||||
.remove_ref(profile_identity_gemini_id)
|
||||
{
|
||||
Ok(_) => match list.update(profile_identity_gemini_id) {
|
||||
Some(_) => {
|
||||
Ok(_) => match list.selected().update(&profile, "") {
|
||||
Ok(_) => {
|
||||
button.set_css_classes(&["success"]);
|
||||
button.set_label("Identity successfully disconnected");
|
||||
button.set_label("Identity successfully disconnected")
|
||||
}
|
||||
Err(e) => {
|
||||
button.set_css_classes(&["error"]);
|
||||
button.set_label(&e.to_string())
|
||||
}
|
||||
None => todo!(),
|
||||
},
|
||||
Err(e) => {
|
||||
button.set_css_classes(&["error"]);
|
||||
|
@ -18,7 +18,6 @@ use gtk::{
|
||||
pub struct List {
|
||||
pub dropdown: DropDown,
|
||||
list_store: ListStore,
|
||||
// profile: Rc<Profile>,
|
||||
}
|
||||
|
||||
impl List {
|
||||
@ -140,7 +139,6 @@ impl List {
|
||||
Self {
|
||||
dropdown,
|
||||
list_store,
|
||||
// profile,
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,7 +152,7 @@ impl List {
|
||||
})
|
||||
}
|
||||
|
||||
/// Remove list item by `profile_identity_gemini_id` (stores ID)
|
||||
/// Remove list item by `profile_identity_gemini_id`
|
||||
/// * return `position` of removed list item
|
||||
pub fn remove(&self, profile_identity_gemini_id: i64) -> Option<u32> {
|
||||
match self.find(profile_identity_gemini_id) {
|
||||
@ -166,18 +164,6 @@ impl List {
|
||||
}
|
||||
}
|
||||
|
||||
/// Update list item by `profile_identity_gemini_id` (stores ID)
|
||||
/// * return `position` of updated list item
|
||||
pub fn update(&self, profile_identity_gemini_id: i64) -> Option<u32> {
|
||||
match self.find(profile_identity_gemini_id) {
|
||||
Some(position) => {
|
||||
// @TODO
|
||||
Some(position)
|
||||
}
|
||||
None => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
/// Get selected `Item` GObject
|
||||
|
@ -6,8 +6,6 @@ mod title;
|
||||
mod tooltip;
|
||||
pub mod value;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
pub use error::Error;
|
||||
pub use value::Value;
|
||||
|
||||
@ -16,6 +14,7 @@ use gtk::{
|
||||
gio::TlsCertificate,
|
||||
glib::{self, Object},
|
||||
};
|
||||
use std::rc::Rc;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct Item(ObjectSubclass<imp::Item>);
|
||||
@ -69,7 +68,7 @@ impl Item {
|
||||
// Extract certificate details from PEM string
|
||||
Ok(ref pem) => match TlsCertificate::from_pem(pem) {
|
||||
// Collect certificate scopes for item
|
||||
Ok(ref certificate) => match scope(profile.clone(), profile_identity_gemini_id) {
|
||||
Ok(ref certificate) => match scope(&profile, profile_identity_gemini_id) {
|
||||
// Ready to build `Item` GObject
|
||||
Ok(ref scope) => Ok(Object::builder()
|
||||
.property("value", profile_identity_gemini_id)
|
||||
@ -88,7 +87,7 @@ impl Item {
|
||||
.property(
|
||||
"is_active",
|
||||
is_active::new_for_profile_identity_gemini_id(
|
||||
profile,
|
||||
&profile,
|
||||
profile_identity_gemini_id,
|
||||
auth_url,
|
||||
),
|
||||
@ -102,6 +101,59 @@ impl Item {
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/// Update properties for `Self` for given `Profile` and `auth_url`
|
||||
pub fn update(&self, profile: &Rc<Profile>, auth_url: &str) -> Result<(), Error> {
|
||||
// Update item depending on value type
|
||||
match self.value_enum() {
|
||||
Value::ProfileIdentityGeminiId(profile_identity_gemini_id) => {
|
||||
// Get PEM by ID
|
||||
match profile
|
||||
.identity
|
||||
.gemini
|
||||
.memory
|
||||
.get(profile_identity_gemini_id)
|
||||
{
|
||||
// Extract certificate details from PEM string
|
||||
Ok(ref pem) => match TlsCertificate::from_pem(pem) {
|
||||
Ok(ref certificate) => {
|
||||
// Get current scope
|
||||
let ref scope = scope(profile, profile_identity_gemini_id)?;
|
||||
|
||||
// Update properties
|
||||
self.set_title(title::new_for_profile_identity_gemini_id(certificate));
|
||||
|
||||
self.set_subtitle(subtitle::new_for_profile_identity_gemini_id(
|
||||
certificate,
|
||||
scope,
|
||||
));
|
||||
|
||||
self.set_tooltip(tooltip::new_for_profile_identity_gemini_id(
|
||||
certificate,
|
||||
scope,
|
||||
));
|
||||
|
||||
self.set_is_active(is_active::new_for_profile_identity_gemini_id(
|
||||
profile,
|
||||
profile_identity_gemini_id,
|
||||
auth_url,
|
||||
));
|
||||
|
||||
// @TODO emit update request
|
||||
}
|
||||
Err(e) => return Err(Error::TlsCertificate(e)),
|
||||
},
|
||||
Err(_) => todo!(),
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
// nothing to update yet..
|
||||
}
|
||||
}
|
||||
Ok(()) // @TODO
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
/// Get `Self` C-value as `Value`
|
||||
@ -118,7 +170,7 @@ impl Item {
|
||||
// Tools
|
||||
|
||||
/// Collect certificate scope vector from `Profile` database for `profile_identity_gemini_id`
|
||||
fn scope(profile: Rc<Profile>, profile_identity_gemini_id: i64) -> Result<Vec<String>, Error> {
|
||||
fn scope(profile: &Rc<Profile>, profile_identity_gemini_id: i64) -> Result<Vec<String>, Error> {
|
||||
match profile.identity.gemini.auth.database.records_scope(None) {
|
||||
Ok(result) => {
|
||||
let mut scope = Vec::new();
|
||||
|
@ -2,7 +2,7 @@ use crate::profile::Profile;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub fn new_for_profile_identity_gemini_id(
|
||||
profile: Rc<Profile>,
|
||||
profile: &Rc<Profile>,
|
||||
profile_identity_gemini_id: i64,
|
||||
auth_url: &str,
|
||||
) -> bool {
|
||||
|
Loading…
x
Reference in New Issue
Block a user