~julienxx/castor

b41aef9608c98ea34bac421bc2d3fe2142962014 — Ciarán Ainsworth 7 months ago 029db99
Add support for mailto, xmpp, irc links
2 files changed, 36 insertions(+), 0 deletions(-)

M src/draw.rs
M src/gemini/link.rs
M src/draw.rs => src/draw.rs +30 -0
@@ 280,6 280,36 @@ pub fn gemini_link(gui: &Arc<Gui>, link_item: String) {

            insert_external_button(&gui, url, &www_label);
        }
        Ok(GeminiLink::Email(url, label)) => {
            let button_label = if label.is_empty() {
                url.to_string()
            } else {
                label
            };
            let email_label = format!("{} [MAILTO]", button_label);

            insert_external_button(&gui, url, &email_label);
        }
        Ok(GeminiLink::XMPP(url, label)) => {
            let button_label = if label.is_empty() {
                url.to_string()
            } else {
                label
            };
            let xmpp_label = format!("{} [XMPP]", button_label);

            insert_external_button(&gui, url, &xmpp_label);
        }
        Ok(GeminiLink::IRC(url, label)) => {
            let button_label = if label.is_empty() {
                url.to_string()
            } else {
                label
            };
            let irc_label = format!("{} [IRC]", button_label);

            insert_external_button(&gui, url, &irc_label);
        }
        Ok(GeminiLink::Relative(url, label)) => {
            let new_url = Gemini { source: url }.to_absolute_url().unwrap();
            insert_button(&gui, new_url, label);

M src/gemini/link.rs => src/gemini/link.rs +6 -0
@@ 9,6 9,9 @@ pub enum Link {
    Gemini(Url, String),
    Gopher(Url, String),
    Http(Url, String),
    Email(Url, String),
    IRC(Url, String),
    XMPP(Url, String),
    Relative(String, String),
    Unknown(Url, String),
}


@@ 56,6 59,9 @@ fn make_link(url: String, label: String) -> Option<Link> {
            "gopher" => Some(Link::Gopher(url, label)),
            "http" => Some(Link::Http(url, label)),
            "https" => Some(Link::Http(url, label)),
            "mailto" => Some(Link::Email(url, label)),
            "xmpp" => Some(Link::XMPP(url, label)),
            "irc" => Some(Link::IRC(url, label)),
            _ => Some(Link::Unknown(url, label)),
        },
        Err(url::ParseError::RelativeUrlWithoutBase) => Some(Link::Relative(url, label)),