Skip to content

Commit 53af3ab

Browse files
committed
Use adw::StatusPage for errors and external links
1 parent 5fd5df3 commit 53af3ab

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

src/tab.rs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl Tab {
287287
None
288288
}
289289
Err(e) => {
290-
Self::display_error(&mut req_ctx.draw_ctx, e);
290+
this.display_error(e);
291291
None
292292
}
293293
};
@@ -327,7 +327,7 @@ impl Tab {
327327
Ok(_) => {
328328
info!("Loaded {} from cache", &url);
329329
}
330-
Err(e) => Self::display_error(&mut draw_ctx, e),
330+
Err(e) => this.display_error(e),
331331
}
332332
}
333333
}
@@ -369,10 +369,17 @@ impl Tab {
369369
h.map(|x| self.spawn_request(self.open_history(x)))
370370
.context("retrieving previous item from history")
371371
}
372-
pub fn display_error(ctx: &mut DrawCtx, error: anyhow::Error) {
372+
pub fn display_error(&self, error: anyhow::Error) {
373+
let imp = self.imp();
373374
error!("{:?}", error);
374-
let error_text = format!("Geopard experienced an error:\n {:?}", error);
375-
ctx.insert_paragraph(&mut ctx.text_buffer.end_iter(), &error_text);
375+
376+
let status_page = adw::StatusPage::new();
377+
status_page.set_title("Error");
378+
status_page.set_description(Some(&error.to_string()));
379+
status_page.set_icon_name(Some("dialog-error-symbolic"));
380+
381+
imp.stack.add_child(&status_page);
382+
imp.stack.set_visible_child(&status_page);
376383
}
377384
fn bind_signals(&self) {
378385
let imp = self.imp();
@@ -438,11 +445,10 @@ impl Tab {
438445
}
439446
async fn send_request(&self, req: &mut RequestCtx) -> Result<Option<Vec<u8>>> {
440447
req.draw_ctx.clear();
441-
let this = self.clone();
442448
match req.url.scheme() {
443449
"about" => {
444450
let reader = futures::io::BufReader::new(common::ABOUT_PAGE.as_bytes());
445-
this.display_gemini(reader).await?;
451+
self.display_gemini(reader).await?;
446452
Ok(None)
447453
}
448454
"file" => {
@@ -451,7 +457,7 @@ impl Tab {
451457
}
452458
"gemini" => self.open_gemini_url(req).await,
453459
_ => {
454-
Self::display_url_confirmation(&mut req.draw_ctx, &req.url);
460+
self.display_url_confirmation(&req.url);
455461
Ok(None)
456462
}
457463
}
@@ -624,24 +630,26 @@ impl Tab {
624630
});
625631
}
626632

627-
fn display_url_confirmation(ctx: &mut DrawCtx, url: &Url) {
628-
let mut text_iter = ctx.text_buffer.end_iter();
629-
ctx.insert_paragraph(
630-
&mut text_iter,
631-
"Geopard doesn't support this url scheme.
632-
If you want to open the following link in an external application, \
633-
click on the button below\n",
634-
);
635-
ctx.insert_paragraph(&mut text_iter, &format!("Trying to open: {}\n", url));
633+
fn display_url_confirmation(&self, url: &Url) {
634+
let imp = self.imp();
635+
let status_page = adw::StatusPage::new();
636+
status_page.set_title("External Link");
637+
status_page.set_description(Some(&glib::markup_escape_text(url.as_str())));
638+
status_page.set_icon_name(Some("web-browser-symbolic"));
636639

637-
let button = gtk::Button::with_label("Open Externally");
640+
let button = gtk::Button::with_label("Open");
638641
button.add_css_class("suggested-action");
642+
button.add_css_class("pill");
643+
button.set_halign(gtk::Align::Center);
639644
let url = url.clone();
640645
button.connect_clicked(move |_| {
641646
gtk::show_uri(None::<&gtk::Window>, url.as_str(), 0);
642647
});
643-
ctx.insert_widget(&mut text_iter, &button);
644-
// FIXME: Handle open
648+
649+
status_page.set_child(Some(&button));
650+
651+
imp.stack.add_child(&status_page);
652+
imp.stack.set_visible_child(&status_page);
645653
}
646654
async fn display_gemini<T: AsyncBufRead + Unpin>(
647655
&self,

0 commit comments

Comments
 (0)