|
|
@ -13,8 +13,8 @@ use gtk::{ |
|
|
|
}, |
|
|
|
}, |
|
|
|
glib::{gformat, GString, Priority, Regex, RegexCompileFlags, RegexMatchFlags, Uri, UriFlags}, |
|
|
|
glib::{gformat, GString, Priority, Regex, RegexCompileFlags, RegexMatchFlags, Uri, UriFlags}, |
|
|
|
prelude::{ |
|
|
|
prelude::{ |
|
|
|
ActionMapExtManual, BoxExt, IOStreamExt, InputStreamExtManual, OutputStreamExtManual, |
|
|
|
ActionExt, ActionMapExtManual, BoxExt, IOStreamExt, InputStreamExtManual, |
|
|
|
SocketClientExt, StaticVariantType, WidgetExt, |
|
|
|
OutputStreamExtManual, SocketClientExt, StaticVariantType, WidgetExt, |
|
|
|
}, |
|
|
|
}, |
|
|
|
Box, Orientation, |
|
|
|
Box, Orientation, |
|
|
|
}; |
|
|
|
}; |
|
|
@ -23,6 +23,9 @@ use std::{cell::RefCell, path::Path, sync::Arc}; |
|
|
|
pub struct Page { |
|
|
|
pub struct Page { |
|
|
|
// GTK
|
|
|
|
// GTK
|
|
|
|
widget: Box, |
|
|
|
widget: Box, |
|
|
|
|
|
|
|
// Actions
|
|
|
|
|
|
|
|
// action_tab_page_reload: Arc<SimpleAction>,
|
|
|
|
|
|
|
|
action_update: Arc<SimpleAction>, |
|
|
|
// Components
|
|
|
|
// Components
|
|
|
|
navigation: Arc<Navigation>, |
|
|
|
navigation: Arc<Navigation>, |
|
|
|
content: Arc<Content>, |
|
|
|
content: Arc<Content>, |
|
|
@ -42,8 +45,8 @@ impl Page { |
|
|
|
let content = Arc::new(Content::new()); |
|
|
|
let content = Arc::new(Content::new()); |
|
|
|
let navigation = Arc::new(Navigation::new( |
|
|
|
let navigation = Arc::new(Navigation::new( |
|
|
|
navigation_request_text, |
|
|
|
navigation_request_text, |
|
|
|
action_tab_page_reload, |
|
|
|
action_tab_page_reload.clone(), |
|
|
|
action_update, |
|
|
|
action_update.clone(), |
|
|
|
)); |
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
// Init widget
|
|
|
|
// Init widget
|
|
|
@ -55,7 +58,7 @@ impl Page { |
|
|
|
widget.append(navigation.widget()); |
|
|
|
widget.append(navigation.widget()); |
|
|
|
widget.append(content.widget()); |
|
|
|
widget.append(content.widget()); |
|
|
|
|
|
|
|
|
|
|
|
// Init actions @TODO move actions init outside
|
|
|
|
// Init actions @TODO use object container
|
|
|
|
let action_open = ActionEntry::builder("open") |
|
|
|
let action_open = ActionEntry::builder("open") |
|
|
|
.parameter_type(Some(&String::static_variant_type())) |
|
|
|
.parameter_type(Some(&String::static_variant_type())) |
|
|
|
.activate({ |
|
|
|
.activate({ |
|
|
@ -84,9 +87,15 @@ impl Page { |
|
|
|
|
|
|
|
|
|
|
|
// Result
|
|
|
|
// Result
|
|
|
|
Self { |
|
|
|
Self { |
|
|
|
|
|
|
|
// GTK
|
|
|
|
widget, |
|
|
|
widget, |
|
|
|
|
|
|
|
// Actions
|
|
|
|
|
|
|
|
// action_tab_page_reload,
|
|
|
|
|
|
|
|
action_update, |
|
|
|
|
|
|
|
// Components
|
|
|
|
content, |
|
|
|
content, |
|
|
|
navigation, |
|
|
|
navigation, |
|
|
|
|
|
|
|
// Extras
|
|
|
|
meta, |
|
|
|
meta, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -99,7 +108,7 @@ impl Page { |
|
|
|
// Init shared objects for async access
|
|
|
|
// Init shared objects for async access
|
|
|
|
let content = self.content.clone(); |
|
|
|
let content = self.content.clone(); |
|
|
|
let meta = self.meta.clone(); |
|
|
|
let meta = self.meta.clone(); |
|
|
|
let widget = self.widget.clone(); |
|
|
|
let action_update = self.action_update.clone(); |
|
|
|
|
|
|
|
|
|
|
|
// Update
|
|
|
|
// Update
|
|
|
|
meta.borrow_mut().mime = None; |
|
|
|
meta.borrow_mut().mime = None; |
|
|
@ -107,9 +116,7 @@ impl Page { |
|
|
|
meta.borrow_mut().description = None; |
|
|
|
meta.borrow_mut().description = None; |
|
|
|
meta.borrow_mut().progress_fraction = 0.0; |
|
|
|
meta.borrow_mut().progress_fraction = 0.0; |
|
|
|
|
|
|
|
|
|
|
|
widget |
|
|
|
action_update.activate(None); |
|
|
|
.activate_action("win.update", None) |
|
|
|
|
|
|
|
.expect("Action `win.update` not found"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*let _uri = */ |
|
|
|
/*let _uri = */ |
|
|
|
match Uri::parse(&request_text, UriFlags::NONE) { |
|
|
|
match Uri::parse(&request_text, UriFlags::NONE) { |
|
|
@ -130,9 +137,7 @@ impl Page { |
|
|
|
meta.borrow_mut().progress_fraction = 0.25; |
|
|
|
meta.borrow_mut().progress_fraction = 0.25; |
|
|
|
meta.borrow_mut().description = Some(gformat!("Connect {host}..")); |
|
|
|
meta.borrow_mut().description = Some(gformat!("Connect {host}..")); |
|
|
|
|
|
|
|
|
|
|
|
widget |
|
|
|
action_update.activate(None); |
|
|
|
.activate_action("win.update", None) |
|
|
|
|
|
|
|
.expect("Action `win.update` not found"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create new connection
|
|
|
|
// Create new connection
|
|
|
|
let cancellable = Cancellable::new(); |
|
|
|
let cancellable = Cancellable::new(); |
|
|
@ -153,7 +158,7 @@ impl Page { |
|
|
|
meta.borrow_mut().progress_fraction = 0.50; |
|
|
|
meta.borrow_mut().progress_fraction = 0.50; |
|
|
|
meta.borrow_mut().description = Some(gformat!("Connected to {host}..")); |
|
|
|
meta.borrow_mut().description = Some(gformat!("Connected to {host}..")); |
|
|
|
|
|
|
|
|
|
|
|
widget.activate_action("win.update", None).expect("Action `win.update` not found"); |
|
|
|
action_update.activate(None); |
|
|
|
|
|
|
|
|
|
|
|
// Send request
|
|
|
|
// Send request
|
|
|
|
connection.output_stream().write_all_async( |
|
|
|
connection.output_stream().write_all_async( |
|
|
@ -166,7 +171,7 @@ impl Page { |
|
|
|
meta.borrow_mut().progress_fraction = 0.75; |
|
|
|
meta.borrow_mut().progress_fraction = 0.75; |
|
|
|
meta.borrow_mut().description = Some(gformat!("Request data from {host}..")); |
|
|
|
meta.borrow_mut().description = Some(gformat!("Request data from {host}..")); |
|
|
|
|
|
|
|
|
|
|
|
widget.activate_action("win.update", None).expect("Action `win.update` not found"); |
|
|
|
action_update.activate(None); |
|
|
|
|
|
|
|
|
|
|
|
// Read response
|
|
|
|
// Read response
|
|
|
|
connection.input_stream().read_all_async( |
|
|
|
connection.input_stream().read_all_async( |
|
|
@ -244,20 +249,14 @@ impl Page { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Update
|
|
|
|
// Update
|
|
|
|
widget.activate_action( |
|
|
|
action_update.activate(None); |
|
|
|
"win.update", |
|
|
|
|
|
|
|
None, |
|
|
|
|
|
|
|
).expect("Action `win.update` not found"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
Err(e) => { |
|
|
|
Err(e) => { |
|
|
|
meta.borrow_mut().title = Some(gformat!("Oops")); |
|
|
|
meta.borrow_mut().title = Some(gformat!("Oops")); |
|
|
|
meta.borrow_mut().description = Some(gformat!("Failed to read buffer data: {e}")); |
|
|
|
meta.borrow_mut().description = Some(gformat!("Failed to read buffer data: {e}")); |
|
|
|
meta.borrow_mut().progress_fraction = 1.0; |
|
|
|
meta.borrow_mut().progress_fraction = 1.0; |
|
|
|
|
|
|
|
|
|
|
|
widget.activate_action( |
|
|
|
action_update.activate(None); |
|
|
|
"win.update", |
|
|
|
|
|
|
|
None, |
|
|
|
|
|
|
|
).expect("Action `win.update` not found"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -272,10 +271,7 @@ impl Page { |
|
|
|
meta.borrow_mut().description = Some(gformat!("Failed to read response: {:?}", e)); |
|
|
|
meta.borrow_mut().description = Some(gformat!("Failed to read response: {:?}", e)); |
|
|
|
meta.borrow_mut().progress_fraction = 1.0; |
|
|
|
meta.borrow_mut().progress_fraction = 1.0; |
|
|
|
|
|
|
|
|
|
|
|
widget.activate_action( |
|
|
|
action_update.activate(None); |
|
|
|
"win.update", |
|
|
|
|
|
|
|
None, |
|
|
|
|
|
|
|
).expect("Action `win.update` not found"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Close connection
|
|
|
|
// Close connection
|
|
|
|
if let Err(e) = connection.close(Some(&cancellable)) { |
|
|
|
if let Err(e) = connection.close(Some(&cancellable)) { |
|
|
@ -291,10 +287,7 @@ impl Page { |
|
|
|
meta.borrow_mut().description = Some(gformat!("Failed to read request: {:?}", e)); |
|
|
|
meta.borrow_mut().description = Some(gformat!("Failed to read request: {:?}", e)); |
|
|
|
meta.borrow_mut().progress_fraction = 1.0; |
|
|
|
meta.borrow_mut().progress_fraction = 1.0; |
|
|
|
|
|
|
|
|
|
|
|
widget.activate_action( |
|
|
|
action_update.activate(None); |
|
|
|
"win.update", |
|
|
|
|
|
|
|
None, |
|
|
|
|
|
|
|
).expect("Action `win.update` not found"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Close connection
|
|
|
|
// Close connection
|
|
|
|
if let Err(e) = connection.close(Some(&cancellable)) { |
|
|
|
if let Err(e) = connection.close(Some(&cancellable)) { |
|
|
@ -310,10 +303,7 @@ impl Page { |
|
|
|
meta.borrow_mut().description = Some(gformat!("Failed to connect: {:?}", e)); |
|
|
|
meta.borrow_mut().description = Some(gformat!("Failed to connect: {:?}", e)); |
|
|
|
meta.borrow_mut().progress_fraction = 1.0; |
|
|
|
meta.borrow_mut().progress_fraction = 1.0; |
|
|
|
|
|
|
|
|
|
|
|
widget.activate_action( |
|
|
|
action_update.activate(None); |
|
|
|
"win.update", |
|
|
|
|
|
|
|
None, |
|
|
|
|
|
|
|
).expect("Action `win.update` not found"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
); |
|
|
|
); |
|
|
@ -328,9 +318,7 @@ impl Page { |
|
|
|
Some(gformat!("Protocol {scheme} not supported")); |
|
|
|
Some(gformat!("Protocol {scheme} not supported")); |
|
|
|
meta.borrow_mut().progress_fraction = 1.0; |
|
|
|
meta.borrow_mut().progress_fraction = 1.0; |
|
|
|
|
|
|
|
|
|
|
|
widget |
|
|
|
action_update.activate(None); |
|
|
|
.activate_action("win.update", None) |
|
|
|
|
|
|
|
.expect("Action `win.update` not found"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|