Skip to content

Commit

Permalink
remove extra members
Browse files Browse the repository at this point in the history
  • Loading branch information
yggverse committed Dec 12, 2024
1 parent 1497896 commit 6911559
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 235 deletions.
190 changes: 70 additions & 120 deletions src/app/browser/window/tab/item/page.rs

Large diffs are not rendered by default.

50 changes: 27 additions & 23 deletions src/app/browser/window/tab/item/page/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ mod status;
mod text;

use image::Image;
use status::Status;
use text::Text;

use super::{TabAction, WindowAction};
use adw::StatusPage;
use gtk::{
gdk::Paintable,
gio::{Cancellable, File},
Expand All @@ -19,7 +19,7 @@ use std::{rc::Rc, time::Duration};
pub struct Content {
window_action: Rc<WindowAction>,
tab_action: Rc<TabAction>,
pub gobject: Box,
pub g_box: Box,
}

impl Content {
Expand All @@ -28,7 +28,7 @@ impl Content {
/// Create new container for different components
pub fn new(action: (Rc<WindowAction>, Rc<TabAction>)) -> Self {
Self {
gobject: Box::builder().orientation(Orientation::Vertical).build(),
g_box: Box::builder().orientation(Orientation::Vertical).build(),
window_action: action.0,
tab_action: action.1,
}
Expand All @@ -42,7 +42,7 @@ impl Content {
pub fn to_image(&self, paintable: &impl IsA<Paintable>) -> Image {
self.clean();
let image = Image::new_from_paintable(paintable);
self.gobject.append(&image.picture);
self.g_box.append(&image.picture);
image
}

Expand All @@ -54,50 +54,54 @@ impl Content {
initial_filename: &str,
cancellable: &Cancellable,
on_choose: impl Fn(File, Rc<status::download::Action>) + 'static,
) -> Status {
) -> StatusPage {
self.clean();
let status = Status::new_download(initial_filename, cancellable, on_choose);
self.gobject.append(&status.gobject);
let status = status::download::new(initial_filename, cancellable, on_choose);
self.g_box.append(&status);
status
}

/// Set new `content::Status` component for `Self` with new `status::Failure` preset
///
/// * action removes previous children component from `Self`
pub fn to_status_failure(&self) -> Status {
pub fn to_status_failure(&self) -> StatusPage {
self.clean();
let status = Status::new_failure();
self.gobject.append(&status.gobject);
let status = status::failure::new();
self.g_box.append(&status);
status
}

/// Set new `content::Status` component for `Self` with new `status::Mime` issue preset
///
/// * action removes previous children component from `Self`
pub fn to_status_mime(&self, mime: &str, download: Option<(Rc<TabAction>, GString)>) -> Status {
pub fn to_status_mime(
&self,
mime: &str,
download: Option<(Rc<TabAction>, GString)>,
) -> StatusPage {
self.clean();
let status = Status::new_mime(mime, download);
self.gobject.append(&status.gobject);
let status = status::mime::new(mime, download);
self.g_box.append(&status);
status
}

/// Set new `content::Status` component for `Self` with new `status::Identity` preset
///
/// * action removes previous children component from `Self`
pub fn to_status_identity(&self) -> Status {
pub fn to_status_identity(&self) -> StatusPage {
self.clean();
let status = Status::new_identity(self.tab_action.clone());
self.gobject.append(&status.gobject);
let status = status::identity::new(self.tab_action.clone());
self.g_box.append(&status);
status
}

/// Set new `content::Status` component for `Self` with new `status::Loading` preset
///
/// * action removes previous children component from `Self`
pub fn to_status_loading(&self, show_with_delay: Option<Duration>) -> Status {
pub fn to_status_loading(&self, show_with_delay: Option<Duration>) -> StatusPage {
self.clean();
let status = Status::new_loading(show_with_delay);
self.gobject.append(&status.gobject);
let status = status::loading::new(show_with_delay);
self.g_box.append(&status);
status
}

Expand All @@ -123,21 +127,21 @@ impl Content {
base,
(self.window_action.clone(), self.tab_action.clone()),
);
self.gobject.append(&text.scrolled_window);
self.g_box.append(&text.scrolled_window);
text
}

pub fn to_text_source(&self, data: &str) -> Text {
self.clean();
let text = Text::new_source(data);
self.gobject.append(&text.scrolled_window);
self.g_box.append(&text.scrolled_window);
text
}

/// Remove all children components from `Self`
pub fn clean(&self) {
while let Some(child) = self.gobject.last_child() {
self.gobject.remove(&child);
while let Some(child) = self.g_box.last_child() {
self.g_box.remove(&child);
}
}
}
90 changes: 4 additions & 86 deletions src/app/browser/window/tab/item/page/content/status.rs
Original file line number Diff line number Diff line change
@@ -1,89 +1,7 @@
pub mod download;
mod failure;
mod identity;
mod loading;
mod mime;
pub mod failure;
pub mod identity;
pub mod loading;
pub mod mime;

use super::TabAction;
use adw::StatusPage;
use gtk::{
gio::{Cancellable, File},
glib::GString,
};
use std::{rc::Rc, time::Duration};

pub struct Status {
pub gobject: StatusPage,
}

impl Status {
// Constructors

/// Create new download preset
pub fn new_download(
initial_filename: &str,
cancellable: &Cancellable,
on_choose: impl Fn(File, Rc<download::Action>) + 'static,
) -> Self {
Self {
gobject: download::new(initial_filename, cancellable, on_choose),
}
}

/// Create new failure preset
///
/// Useful as placeholder widget for error handlers
pub fn new_failure() -> Self {
Self {
gobject: failure::new_gobject(),
}
}

/// Create new mime issue preset
///
/// Useful as placeholder widget for mime issue handlers
pub fn new_mime(mime: &str, download: Option<(Rc<TabAction>, GString)>) -> Self {
Self {
gobject: mime::new_gobject(mime, download),
}
}

/// Create new identity preset
///
/// Useful as placeholder for 60 status code
/// https://geminiprotocol.net/docs/protocol-specification.gmi#status-60
pub fn new_identity(action: Rc<crate::app::browser::window::tab::item::Action>) -> Self {
Self {
gobject: identity::new_gobject(action),
}
}

/// Create new loading preset
///
/// Useful as placeholder widget for async operations
pub fn new_loading(show_with_delay: Option<Duration>) -> Self {
Self {
gobject: loading::new_gobject(show_with_delay),
}
}

// Setters

/// Set new title for `Self`
///
/// Return `Self` reference to apply another functions in chain
pub fn set_title(&self, value: &str) -> &Self {
self.gobject.set_title(value);
self
}

/// Set new description for `Self`
///
/// Useful for loading widgets to update byte totals and other dynamically changed information
///
/// Return `Self` reference to apply another functions in chain
pub fn set_description(&self, value: Option<&str>) -> &Self {
self.gobject.set_description(value);
self
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const DEFAULT_ICON_NAME: &str = "dialog-error";

/// Create new default `GObject` preset for failure
/// [StatusPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.StatusPage.html)
pub fn new_gobject() -> StatusPage {
pub fn new() -> StatusPage {
StatusPage::builder()
.title(DEFAULT_TITLE)
.icon_name(DEFAULT_ICON_NAME)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::rc::Rc;

use crate::app::browser::window::tab::item::Action;
use adw::StatusPage;
use gtk::{prelude::ButtonExt, Align, Button};
use std::rc::Rc;

// Defaults
const DEFAULT_ICON_NAME: &str = "avatar-default-symbolic";
Expand All @@ -14,7 +13,7 @@ const DEFAULT_BUTTON_CLASS: &str = "suggested-action";

/// Create new default preset for `Identity`
/// [StatusPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.StatusPage.html)
pub fn new_gobject(action: Rc<Action>) -> StatusPage {
pub fn new(action: Rc<Action>) -> StatusPage {
// Init certificate selection
let button = &Button::builder()
.css_classes([DEFAULT_BUTTON_CLASS])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const DEFAULT_TITLE: &str = "Loading..";

/// Create new default preset for loading
/// [StatusPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.StatusPage.html)
pub fn new_gobject(show_with_delay: Option<Duration>) -> StatusPage {
pub fn new(show_with_delay: Option<Duration>) -> StatusPage {
// Init spinner component
let spinner = Spinner::builder()
.width_request(SPINNER_SIZE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::rc::Rc;

/// Create new default `GObject` preset for mime issue
/// [StatusPage](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.StatusPage.html)
pub fn new_gobject(mime: &str, download: Option<(Rc<TabAction>, GString)>) -> StatusPage {
pub fn new(mime: &str, download: Option<(Rc<TabAction>, GString)>) -> StatusPage {
let status_page = StatusPage::builder()
.description(format!("Content type `{mime}` not supported!"))
.icon_name("dialog-question-symbolic")
Expand Down

0 comments on commit 6911559

Please sign in to comment.