mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
add optional download button for unknown mime types
This commit is contained in:
parent
549c3fd946
commit
f2dadee082
@ -679,7 +679,10 @@ impl Page {
|
|||||||
},
|
},
|
||||||
mime => {
|
mime => {
|
||||||
// Init children widget
|
// Init children widget
|
||||||
let status = content.to_status_mime(mime);
|
let status = content.to_status_mime(
|
||||||
|
mime,
|
||||||
|
Some((tab_action.clone(), navigation.request.download()))
|
||||||
|
);
|
||||||
|
|
||||||
// Update page meta
|
// Update page meta
|
||||||
meta.set_status(Status::Failure)
|
meta.set_status(Status::Failure)
|
||||||
|
@ -6,11 +6,11 @@ use image::Image;
|
|||||||
use status::Status;
|
use status::Status;
|
||||||
use text::Text;
|
use text::Text;
|
||||||
|
|
||||||
use crate::app::browser::window::{tab::item::Action as TabAction, Action as WindowAction};
|
use super::{TabAction, WindowAction};
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gdk::Paintable,
|
gdk::Paintable,
|
||||||
gio::{Cancellable, File},
|
gio::{Cancellable, File},
|
||||||
glib::Uri,
|
glib::{GString, Uri},
|
||||||
prelude::{BoxExt, IsA, WidgetExt},
|
prelude::{BoxExt, IsA, WidgetExt},
|
||||||
Box, Orientation,
|
Box, Orientation,
|
||||||
};
|
};
|
||||||
@ -74,9 +74,9 @@ impl Content {
|
|||||||
/// Set new `content::Status` component for `Self` with new `status::Mime` issue preset
|
/// Set new `content::Status` component for `Self` with new `status::Mime` issue preset
|
||||||
///
|
///
|
||||||
/// * action removes previous children component from `Self`
|
/// * action removes previous children component from `Self`
|
||||||
pub fn to_status_mime(&self, mime: &str) -> Status {
|
pub fn to_status_mime(&self, mime: &str, download: Option<(Rc<TabAction>, GString)>) -> Status {
|
||||||
self.clean();
|
self.clean();
|
||||||
let status = Status::new_mime(mime);
|
let status = Status::new_mime(mime, download);
|
||||||
self.gobject.append(status.gobject());
|
self.gobject.append(status.gobject());
|
||||||
status
|
status
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,12 @@ mod identity;
|
|||||||
mod loading;
|
mod loading;
|
||||||
mod mime;
|
mod mime;
|
||||||
|
|
||||||
|
use super::TabAction;
|
||||||
use adw::StatusPage;
|
use adw::StatusPage;
|
||||||
use gtk::gio::{Cancellable, File};
|
use gtk::{
|
||||||
|
gio::{Cancellable, File},
|
||||||
|
glib::GString,
|
||||||
|
};
|
||||||
use std::{rc::Rc, time::Duration};
|
use std::{rc::Rc, time::Duration};
|
||||||
|
|
||||||
pub struct Status {
|
pub struct Status {
|
||||||
@ -38,9 +42,9 @@ impl Status {
|
|||||||
/// Create new mime issue preset
|
/// Create new mime issue preset
|
||||||
///
|
///
|
||||||
/// Useful as placeholder widget for mime issue handlers
|
/// Useful as placeholder widget for mime issue handlers
|
||||||
pub fn new_mime(mime: &str) -> Self {
|
pub fn new_mime(mime: &str, download: Option<(Rc<TabAction>, GString)>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
gobject: mime::new_gobject(mime),
|
gobject: mime::new_gobject(mime, download),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,31 @@
|
|||||||
|
use super::TabAction;
|
||||||
use adw::StatusPage;
|
use adw::StatusPage;
|
||||||
|
use gtk::{glib::GString, prelude::ButtonExt, Align, Button};
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
/// Create new default `GObject` preset for mime issue
|
/// Create new default `GObject` preset for mime issue
|
||||||
/// [StatusPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.StatusPage.html)
|
/// [StatusPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.StatusPage.html)
|
||||||
pub fn new_gobject(mime: &str) -> StatusPage {
|
pub fn new_gobject(mime: &str, download: Option<(Rc<TabAction>, GString)>) -> StatusPage {
|
||||||
StatusPage::builder()
|
let status_page = StatusPage::builder()
|
||||||
.title("Oops")
|
|
||||||
.description(format!("Content type `{mime}` not supported!"))
|
.description(format!("Content type `{mime}` not supported!"))
|
||||||
.icon_name("dialog-question-symbolic")
|
.icon_name("dialog-question-symbolic")
|
||||||
.build()
|
.title("Oops")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
if let Some((action, request)) = download {
|
||||||
|
let button = Button::builder()
|
||||||
|
.css_classes(["accent"])
|
||||||
|
.halign(Align::Center)
|
||||||
|
.label("Download")
|
||||||
|
.tooltip_text("Download as file to open with other application")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
button.connect_clicked(move |_| {
|
||||||
|
action.load.activate(Some(request.as_str()), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
status_page.set_child(Some(&button));
|
||||||
|
}
|
||||||
|
|
||||||
|
status_page
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user