Second commit

This commit is contained in:
Miraty 2022-12-08 14:02:18 +01:00
parent f89133c4d8
commit 573de68e67
2 changed files with 41 additions and 32 deletions

View file

@ -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"

View file

@ -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<Vec<String>> {
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<String> = 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 <mnemonic> 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("<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);
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(&gtk_box)
@ -74,6 +81,8 @@ fn build_ui(app: &Application) {
window.present();
gtk_box.append(&Button::from_icon_name("go-next"));
parse(&gtk_box);
}
fn main() {