2022-11-03 15:23:59 +01:00
|
|
|
use gtk::prelude::*;
|
2022-12-08 14:02:18 +01:00
|
|
|
use gtk::{TextView, Expander, ScrolledWindow, Label, Align, Button, Application, LinkButton, PasswordEntry, ApplicationWindow, Box, Orientation, PolicyType};
|
|
|
|
use html_parser::{Dom, Node};
|
2022-11-03 15:23:59 +01:00
|
|
|
|
|
|
|
const APP_ID: &str = "org.antopie.AshBat";
|
|
|
|
|
2022-12-08 14:02:18 +01:00
|
|
|
fn parse(gtk_box: &Box) {
|
2022-11-03 15:23:59 +01:00
|
|
|
let html = include_str!("test.html");
|
2022-12-08 14:02:18 +01:00
|
|
|
let dom = Dom::parse(html);
|
|
|
|
let dom_valid = match dom {
|
|
|
|
Ok(dom) => dom,
|
|
|
|
Err(_) => panic!("Aaaaaahhhhhh !!!")
|
|
|
|
};
|
|
|
|
let iter = dom_valid.children.get(0).unwrap().into_iter();
|
|
|
|
println!("{:#?}", dom_valid);
|
2022-11-03 15:23:59 +01:00
|
|
|
|
|
|
|
let hrefs = iter.filter_map(|item| match item {
|
2022-12-08 14:02:18 +01:00
|
|
|
Node::Element(ref element) if element.name == "a" => {
|
|
|
|
match element.attributes["href"].clone() {
|
|
|
|
Some(href) => Some(gtk_box.append(&LinkButton::new(&href))),
|
|
|
|
_ => Some(()),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Node::Text(text) => Some(gtk_box.append(&Label::new(Some(&text)))),
|
|
|
|
_ => Some(()),
|
2022-11-03 15:23:59 +01:00
|
|
|
});
|
|
|
|
|
2022-12-08 14:02:18 +01:00
|
|
|
for _href in hrefs {
|
|
|
|
println!("Affichage !");
|
2022-11-03 15:23:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn build_ui(app: &Application) {
|
|
|
|
let password_entry = PasswordEntry::new();
|
|
|
|
password_entry.set_show_peek_icon(true);
|
2022-12-08 14:02:18 +01:00
|
|
|
|
|
|
|
let text = Label::new(Some("<span size=\"x-large\">text</span> gjero jgier iogrejgoi jriogjiog iorgjoiergoi eroi gjoiergjioregj erjgierojg oierjg ierjiog jreoi gjoierg jiergoirejgoierjoig jreio gjorieg jioerg<a title=\"https://antopie.org/\" href=\"https://antopie.org/\">is</a> <i>cool</i>!"));
|
|
|
|
text.set_wrap(true);
|
|
|
|
text.set_use_markup(true);
|
|
|
|
|
2022-11-03 15:23:59 +01:00
|
|
|
let button = Button::from_icon_name("go-next");
|
2022-12-08 14:02:18 +01:00
|
|
|
let link_button = LinkButton::new("matrix:r/antopie-synapse:matrix.antopie.org");
|
|
|
|
|
|
|
|
let text_view = TextView::new();
|
|
|
|
text_view.set_editable(false);
|
|
|
|
|
|
|
|
let text2 = Label::new(Some("Message caché !"));
|
|
|
|
let expander = Expander::new(Some("Détails"));
|
|
|
|
expander.set_child(Some(&text2));
|
2022-11-03 15:23:59 +01:00
|
|
|
|
|
|
|
let gtk_box = Box::builder()
|
|
|
|
.margin_top(12)
|
|
|
|
.margin_bottom(12)
|
|
|
|
.margin_start(12)
|
|
|
|
.margin_end(12)
|
|
|
|
.valign(Align::Center)
|
|
|
|
.halign(Align::Center)
|
|
|
|
.spacing(12)
|
|
|
|
.orientation(Orientation::Vertical)
|
|
|
|
.build();
|
|
|
|
gtk_box.append(&link_button);
|
|
|
|
gtk_box.append(&password_entry);
|
|
|
|
gtk_box.append(&text);
|
|
|
|
gtk_box.append(&button);
|
2022-12-08 14:02:18 +01:00
|
|
|
gtk_box.append(&expander);
|
|
|
|
gtk_box.append(&text_view);
|
2022-11-03 15:23:59 +01:00
|
|
|
|
|
|
|
let scrolled_window = ScrolledWindow::builder()
|
2022-12-08 14:02:18 +01:00
|
|
|
.hscrollbar_policy(PolicyType::Never)
|
2022-11-03 15:23:59 +01:00
|
|
|
.min_content_width(700)
|
|
|
|
.min_content_height(950)
|
|
|
|
.child(>k_box)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let window = ApplicationWindow::builder()
|
|
|
|
.application(app)
|
|
|
|
.title("AshBat")
|
|
|
|
.child(&scrolled_window)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
window.present();
|
|
|
|
|
|
|
|
gtk_box.append(&Button::from_icon_name("go-next"));
|
2022-12-08 14:02:18 +01:00
|
|
|
|
|
|
|
parse(>k_box);
|
2022-11-03 15:23:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let app = Application::builder().application_id(APP_ID).build();
|
|
|
|
|
|
|
|
app.connect_activate(build_ui);
|
|
|
|
|
|
|
|
app.run();
|
|
|
|
}
|