~julienxx/castor

f78aaecc0f3beb0979746e8544e277a2dc8d95d9 — Julien Blanchard 8 months ago 61a79c0 add-spinner
WIP: add a loading spinner
4 files changed, 26 insertions(+), 1 deletions(-)

A loader.gif
M src/castor.glade
M src/gui.rs
M src/main.rs
A loader.gif => loader.gif +0 -0

M src/castor.glade => src/castor.glade +12 -0
@@ 108,6 108,18 @@
                <property name="position">3</property>
              </packing>
            </child>
            <child>
              <object class="GtkSpinner" id="loader">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="margin_right">1</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">True</property>
                <property name="position">4</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>

M src/gui.rs => src/gui.rs +8 -1
@@ 1,5 1,5 @@
use gtk::prelude::*;
use gtk::{ApplicationWindow, Button, Entry, TextView};
use gtk::{ApplicationWindow, Button, Entry, Spinner, TextView};


pub struct Gui {


@@ 9,6 9,7 @@ pub struct Gui {
    back_button: Button,
    add_bookmark_button: Button,
    show_bookmarks_button: Button,
    spinner: Spinner,
}

impl Gui {


@@ 24,6 25,7 @@ impl Gui {
        let back_button: Button = builder.get_object("back_button").expect("Couldn't get back_button");
        let add_bookmark_button: Button = builder.get_object("add_bookmark_button").expect("Couldn't get add_bookmark_button");
        let show_bookmarks_button: Button = builder.get_object("show_bookmarks_button").expect("Couldn't get show_bookmarks_button");
        let spinner: Spinner = builder.get_object("loader").expect("Couldn't get spinner");

        Gui {
            window,


@@ 32,6 34,7 @@ impl Gui {
            back_button,
            add_bookmark_button,
            show_bookmarks_button,
            spinner,
        }
    }



@@ 65,4 68,8 @@ impl Gui {
    pub fn show_bookmarks_button(&self) -> &Button {
        &self.show_bookmarks_button
    }

    pub fn spinner(&self) -> &Spinner {
        &self.spinner
    }
}

M src/main.rs => src/main.rs +6 -0
@@ 154,6 154,10 @@ fn show_bookmarks(gui: &Arc<Gui>) {
}

fn visit_url<T: AbsoluteUrl + Protocol>(gui: &Arc<Gui>, url: T) {
    let spinner = gui.spinner();
    spinner.show();
    spinner.start();

    if url.get_source_str() == "gemini://::bookmarks" {
        show_bookmarks(&gui);
        return;


@@ 187,6 191,7 @@ fn visit_url<T: AbsoluteUrl + Protocol>(gui: &Arc<Gui>, url: T) {
                                    } else {
                                        // download and try to open the rest.
                                        client::download(new_content);
                                        spinner.stop();
                                    }
                                }
                                Status::Gone(_meta) => {


@@ 401,6 406,7 @@ fn draw_gemini_link(gui: &Arc<Gui>, link_item: String) {
}

fn draw_gopher_link(gui: &Arc<Gui>, link_item: String) {
    println!("{:?}", link_item);
    match GopherLink::from_str(&link_item) {
        Ok(GopherLink::Http(url, label)) => {
            let button_label = if label.is_empty() {