draft page info dialog features

This commit is contained in:
yggverse 2025-03-22 05:04:43 +02:00
parent 71ae92cfaa
commit 96230ee476
5 changed files with 133 additions and 4 deletions

View file

@ -75,7 +75,7 @@ impl Gemini {
0.9 0.9
} }
SocketClientEvent::Complete => { SocketClientEvent::Complete => {
i.add_event("Complete".to_string()); i.add_event("Receiving".to_string());
1.0 1.0
} }
_ => panic!(), // alert on API change _ => panic!(), // alert on API change

View file

@ -91,6 +91,7 @@ impl Request {
}); });
entry.connect_icon_release({ entry.connect_icon_release({
let i = info.clone();
let p = profile.clone(); let p = profile.clone();
move |e, position| match position { move |e, position| match position {
EntryIconPosition::Primary => { EntryIconPosition::Primary => {
@ -100,8 +101,14 @@ impl Request {
show_identity_dialog(e, &p) show_identity_dialog(e, &p)
} }
} }
EntryIconPosition::Secondary => e.emit_activate(), EntryIconPosition::Secondary => {
_ => todo!(), // unexpected if is_focused(e) {
e.emit_activate()
} else {
i.borrow().dialog(Some(e));
}
}
_ => panic!(),
} }
}); });

View file

@ -1,3 +1,5 @@
mod dialog;
// Public dependencies // Public dependencies
pub mod event; pub mod event;
@ -5,7 +7,8 @@ pub use event::Event;
// Local dependencies // Local dependencies
use gtk::gio::NetworkAddress; use dialog::Dialog;
use gtk::{gio::NetworkAddress, prelude::IsA};
/// Common, shared `Page` information holder /// Common, shared `Page` information holder
/// * used for the Information dialog window on request indicator activate /// * used for the Information dialog window on request indicator activate
@ -48,6 +51,11 @@ impl Info {
// Actions // Actions
pub fn dialog(&self, parent: Option<&impl IsA<gtk::Widget>>) {
use adw::{PreferencesDialog, prelude::AdwDialogExt};
PreferencesDialog::info(self).present(parent)
}
/// Mark `Self` as deprecated /// Mark `Self` as deprecated
/// * tip: usually called on page handler begin /// * tip: usually called on page handler begin
pub fn deprecate(&mut self) { pub fn deprecate(&mut self) {

View file

@ -0,0 +1,104 @@
use super::Info;
use adw::{
ActionRow, PreferencesDialog, PreferencesGroup, PreferencesPage,
prelude::{PreferencesDialogExt, PreferencesGroupExt, PreferencesPageExt},
};
pub trait Dialog {
fn info(info: &Info) -> Self;
}
impl Dialog for PreferencesDialog {
fn info(info: &Info) -> Self {
let d = PreferencesDialog::builder()
.search_enabled(true)
.title("Page info")
.build();
d.add(&{
let p = PreferencesPage::builder()
.title("General")
.icon_name("help-about-symbolic")
.build();
if info.mime.is_some() {
p.add(&{
let g = PreferencesGroup::builder().title("Meta").build();
if let Some(ref mime) = info.mime {
g.add(&{
let r = ActionRow::builder()
.css_classes(["property"])
.subtitle(mime)
.title("Content type")
.build();
r
})
}
g
});
} // @TODO content language, header size, etc.
if info.size.is_some() {
p.add(&{
let g = PreferencesGroup::builder().title("Size").build();
if let Some(ref size) = info.size {
g.add(&{
use crate::tool::Format;
let r = ActionRow::builder()
.css_classes(["property"])
.subtitle(size.bytes())
.title("Content")
.build();
r
})
}
g
});
} // @TODO header size, total size, etc.
p
});
if let Some(ref redirect) = info.redirect {
d.add(&{
PreferencesPage::builder()
.title("Redirect")
.icon_name("insert-link-symbolic")
.build()
});
// @TODO recursive lookup
}
if !info.event.is_empty() {
d.add(&{
let p = PreferencesPage::builder()
.title("Events")
.icon_name("system-run-symbolic")
.build();
p.add(&{
let g = PreferencesGroup::new();
let e = &info.event[0];
let t = e.time();
let n = e.name();
g.add(&{
let r = ActionRow::builder()
.subtitle(t.format_iso8601().unwrap())
.title(n)
.build();
r
});
for e in &info.event[1..] {
g.add(&{
let r = ActionRow::builder()
.subtitle(gtk::glib::gformat!(
"{} ms",
e.time().difference(t).as_milliseconds()
))
.title(e.name())
.build();
r
})
}
g
});
p
})
}
d
}
}

View file

@ -19,4 +19,14 @@ impl Event {
time: DateTime::now_local().unwrap(), time: DateTime::now_local().unwrap(),
} }
} }
// Getters
pub fn name(&self) -> &str {
&self.name
}
pub fn time(&self) -> &DateTime {
&self.time
}
} }