mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 09:35:28 +00:00
draft redirection features
This commit is contained in:
parent
aa44325dea
commit
e3a6796627
5 changed files with 320 additions and 133 deletions
|
|
@ -1,11 +1,17 @@
|
|||
use gtk::glib::GString;
|
||||
mod redirect;
|
||||
use redirect::Redirect;
|
||||
|
||||
use gtk::glib::{GString, Uri};
|
||||
use std::{cell::RefCell, sync::Arc};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Status {
|
||||
Complete,
|
||||
Connected,
|
||||
Connecting,
|
||||
Failure,
|
||||
Input,
|
||||
Connecting,
|
||||
Connected,
|
||||
New,
|
||||
ProxyNegotiated,
|
||||
ProxyNegotiating,
|
||||
Redirect,
|
||||
|
|
@ -18,17 +24,88 @@ pub enum Status {
|
|||
}
|
||||
|
||||
pub struct Meta {
|
||||
pub title: Option<GString>,
|
||||
//pub description: Option<GString>,
|
||||
pub status: Option<Status>,
|
||||
status: RefCell<Status>,
|
||||
title: RefCell<GString>,
|
||||
redirect: RefCell<Option<Redirect>>,
|
||||
}
|
||||
|
||||
impl Meta {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
title: None,
|
||||
//description: None,
|
||||
status: None,
|
||||
// Constructors
|
||||
|
||||
pub fn new_arc(status: Status, title: GString) -> Arc<Self> {
|
||||
Arc::new(Self {
|
||||
status: RefCell::new(status),
|
||||
title: RefCell::new(title),
|
||||
redirect: RefCell::new(None),
|
||||
})
|
||||
}
|
||||
|
||||
// Setters
|
||||
|
||||
pub fn set_status(&self, status: Status) -> &Self {
|
||||
match status {
|
||||
Status::Redirect => {
|
||||
if self.redirect.borrow().is_none() {
|
||||
panic!("Set `redirect` before use this status")
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
self.unset_redirect();
|
||||
}
|
||||
};
|
||||
|
||||
self.status.replace(status);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_title(&self, title: &str) -> &Self {
|
||||
self.title.replace(GString::from(title));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_redirect(&self, count: i8, is_follow: bool, target: Uri) -> &Self {
|
||||
self.redirect
|
||||
.replace(Some(Redirect::new(count, is_follow, target)));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn unset_redirect(&self) -> &Self {
|
||||
self.redirect.replace(None);
|
||||
self
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
pub fn status(&self) -> Status {
|
||||
self.status.borrow().clone()
|
||||
}
|
||||
|
||||
pub fn title(&self) -> GString {
|
||||
self.title.borrow().clone()
|
||||
}
|
||||
|
||||
pub fn is_redirect(&self) -> bool {
|
||||
self.redirect.borrow().is_some()
|
||||
}
|
||||
|
||||
pub fn redirect_count(&self) -> Option<i8> {
|
||||
match *self.redirect.borrow() {
|
||||
Some(ref redirect) => Some(redirect.count().clone()),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn redirect_target(&self) -> Option<Uri> {
|
||||
match *self.redirect.borrow() {
|
||||
Some(ref redirect) => Some(redirect.target().clone()),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn redirect_is_follow(&self) -> Option<bool> {
|
||||
match *self.redirect.borrow() {
|
||||
Some(ref redirect) => Some(redirect.is_follow().clone()),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
40
src/app/browser/window/tab/item/page/meta/redirect.rs
Normal file
40
src/app/browser/window/tab/item/page/meta/redirect.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
use gtk::glib::Uri;
|
||||
|
||||
/// # Redirection data holder
|
||||
///
|
||||
/// This component does nothing,
|
||||
/// but useful as the container for temporary redirection data
|
||||
/// operated by external controller
|
||||
///
|
||||
/// ## Members
|
||||
///
|
||||
/// * `count` - to limit redirect attempts
|
||||
/// * `is_follow` - indicates how to process this redirect exactly
|
||||
/// * `target` - destination address
|
||||
pub struct Redirect {
|
||||
count: i8,
|
||||
is_follow: bool,
|
||||
target: Uri,
|
||||
}
|
||||
|
||||
impl Redirect {
|
||||
pub fn new(count: i8, is_follow: bool, target: Uri) -> Self {
|
||||
Self {
|
||||
count,
|
||||
is_follow,
|
||||
target,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn count(&self) -> &i8 {
|
||||
&self.count
|
||||
}
|
||||
|
||||
pub fn is_follow(&self) -> &bool {
|
||||
&self.is_follow
|
||||
}
|
||||
|
||||
pub fn target(&self) -> &Uri {
|
||||
&self.target
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue