From 573de68e6760e3823ef25f8afc6183013e7882bd Mon Sep 17 00:00:00 2001 From: Miraty Date: Thu, 8 Dec 2022 14:02:18 +0100 Subject: [PATCH] Second commit --- Cargo.toml | 6 ++--- src/main.rs | 67 ++++++++++++++++++++++++++++++----------------------- 2 files changed, 41 insertions(+), 32 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9c3b69a..6e3228c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -gtk = { version = "0.5.1", package = "gtk4"} -html_parser = "0.6.3" -hyper-rustls = "0.23.0" +gtk = { version = "0.5", package = "gtk4"} +html_parser = "0.6" +hyper-rustls = "0.23" diff --git a/src/main.rs b/src/main.rs index 7f551bf..38332df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,39 +1,52 @@ use gtk::prelude::*; -use gtk::{ScrolledWindow, Label, Align, Button, Application, LinkButton, PasswordEntry, ApplicationWindow, Box, Orientation, PolicyType}; -use html_parser::{Dom, Node, Result}; +use gtk::{TextView, Expander, ScrolledWindow, Label, Align, Button, Application, LinkButton, PasswordEntry, ApplicationWindow, Box, Orientation, PolicyType}; +use html_parser::{Dom, Node}; const APP_ID: &str = "org.antopie.AshBat"; -fn parse() -> Result> { +fn parse(gtk_box: &Box) { let html = include_str!("test.html"); - let dom = Dom::parse(html)?; - let iter = dom.children.get(0).unwrap().into_iter(); + 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); let hrefs = iter.filter_map(|item| match item { - Node::Element(ref element) if element.name == "a" => element.attributes["href"].clone(), - _ => None, + 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(()), }); - println!("\nThe following links where found:"); - let mut vec: Vec = Vec::new(); - for (index, href) in hrefs.enumerate() { - println!("{}: {}", index + 1, &href); - vec.push(href); + for _href in hrefs { + println!("Affichage !"); } - - Ok(vec) } fn build_ui(app: &Application) { - - let vec = parse().expect("Nope"); - - let link_button = LinkButton::new("matrix:r/antopie-synapse:matrix.antopie.org"); let password_entry = PasswordEntry::new(); password_entry.set_show_peek_icon(true); - let text = Label::new(Some("If characters in @str are preceded by an underscore, they are underlined. If you need a literal underscore character in a label, use ‘__’ (two underscores). The first underlined character represents a keyboard accelerator called a mnemonic. The key can be used to activate another widget, chosen automatically, or explicitly using set_mnemonic_widget().")); - Label::set_wrap(&text, true); + + let text = Label::new(Some("text gjero jgier iogrejgoi jriogjiog iorgjoiergoi eroi gjoiergjioregj erjgierojg oierjg ierjiog jreoi gjoierg jiergoirejgoierjoig jreio gjorieg jioergis cool!")); + text.set_wrap(true); + text.set_use_markup(true); + let button = Button::from_icon_name("go-next"); + 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)); let gtk_box = Box::builder() .margin_top(12) @@ -49,17 +62,11 @@ fn build_ui(app: &Application) { gtk_box.append(&password_entry); gtk_box.append(&text); gtk_box.append(&button); - let mut vec_button = Vec::new(); - for x in &vec { - vec_button.push(LinkButton::new(x)); - } - - for x in &vec_button { - gtk_box.append(x); - } + gtk_box.append(&expander); + gtk_box.append(&text_view); let scrolled_window = ScrolledWindow::builder() - .hscrollbar_policy(PolicyType::Never) // Disable horizontal scrolling + .hscrollbar_policy(PolicyType::Never) .min_content_width(700) .min_content_height(950) .child(>k_box) @@ -74,6 +81,8 @@ fn build_ui(app: &Application) { window.present(); gtk_box.append(&Button::from_icon_name("go-next")); + + parse(>k_box); } fn main() {