mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
FileTransferParams as member of Context
This commit is contained in:
@@ -36,6 +36,7 @@ extern crate tui;
|
||||
use super::{Activity, Context};
|
||||
use crate::filetransfer::FileTransferProtocol;
|
||||
use crate::system::bookmarks_client::BookmarksClient;
|
||||
use crate::ui::context::FileTransferParams;
|
||||
use crate::ui::layout::view::View;
|
||||
use crate::utils::git;
|
||||
|
||||
@@ -68,11 +69,6 @@ const STORE_KEY_LATEST_VERSION: &str = "AUTH_LATEST_VERSION";
|
||||
///
|
||||
/// AuthActivity is the data holder for the authentication activity
|
||||
pub struct AuthActivity {
|
||||
pub address: String,
|
||||
pub port: String,
|
||||
pub protocol: FileTransferProtocol,
|
||||
pub username: String,
|
||||
pub password: String,
|
||||
pub submit: bool, // becomes true after user has submitted fields
|
||||
pub quit: bool, // Becomes true if user has pressed esc
|
||||
pub setup: bool, // Becomes true if user has requested setup
|
||||
@@ -96,11 +92,6 @@ impl AuthActivity {
|
||||
/// Instantiates a new AuthActivity
|
||||
pub fn new() -> AuthActivity {
|
||||
AuthActivity {
|
||||
address: String::new(),
|
||||
port: String::from("22"),
|
||||
protocol: FileTransferProtocol::Sftp,
|
||||
username: String::new(),
|
||||
password: String::new(),
|
||||
submit: false,
|
||||
quit: false,
|
||||
setup: false,
|
||||
@@ -157,7 +148,9 @@ impl Activity for AuthActivity {
|
||||
/// `on_create` is the function which must be called to initialize the activity.
|
||||
/// `on_create` must initialize all the data structures used by the activity
|
||||
/// Context is taken from activity manager and will be released only when activity is destroyed
|
||||
fn on_create(&mut self, context: Context) {
|
||||
fn on_create(&mut self, mut context: Context) {
|
||||
// Initialize file transfer params
|
||||
context.ft_params = Some(FileTransferParams::default());
|
||||
// Set context
|
||||
self.context = Some(context);
|
||||
// Clear terminal
|
||||
|
||||
@@ -25,11 +25,12 @@
|
||||
|
||||
// locals
|
||||
use super::{
|
||||
AuthActivity, COMPONENT_BOOKMARKS_LIST, COMPONENT_INPUT_ADDR, COMPONENT_INPUT_BOOKMARK_NAME,
|
||||
COMPONENT_INPUT_PASSWORD, COMPONENT_INPUT_PORT, COMPONENT_INPUT_USERNAME,
|
||||
COMPONENT_RADIO_BOOKMARK_DEL_BOOKMARK, COMPONENT_RADIO_BOOKMARK_DEL_RECENT,
|
||||
COMPONENT_RADIO_BOOKMARK_SAVE_PWD, COMPONENT_RADIO_PROTOCOL, COMPONENT_RADIO_QUIT,
|
||||
COMPONENT_RECENTS_LIST, COMPONENT_TEXT_ERROR, COMPONENT_TEXT_HELP,
|
||||
AuthActivity, FileTransferParams, COMPONENT_BOOKMARKS_LIST, COMPONENT_INPUT_ADDR,
|
||||
COMPONENT_INPUT_BOOKMARK_NAME, COMPONENT_INPUT_PASSWORD, COMPONENT_INPUT_PORT,
|
||||
COMPONENT_INPUT_USERNAME, COMPONENT_RADIO_BOOKMARK_DEL_BOOKMARK,
|
||||
COMPONENT_RADIO_BOOKMARK_DEL_RECENT, COMPONENT_RADIO_BOOKMARK_SAVE_PWD,
|
||||
COMPONENT_RADIO_PROTOCOL, COMPONENT_RADIO_QUIT, COMPONENT_RECENTS_LIST, COMPONENT_TEXT_ERROR,
|
||||
COMPONENT_TEXT_HELP,
|
||||
};
|
||||
use crate::ui::activities::keymap::*;
|
||||
use crate::ui::layout::{Msg, Payload};
|
||||
@@ -319,12 +320,20 @@ impl AuthActivity {
|
||||
// Match <ENTER> key for all other components
|
||||
self.save_recent();
|
||||
let (address, port, protocol, username, password) = self.get_input();
|
||||
// TOREM: remove this after removing states
|
||||
self.address = address;
|
||||
self.port = port.to_string();
|
||||
self.protocol = protocol;
|
||||
self.username = username;
|
||||
self.password = password;
|
||||
// Set file transfer params to context
|
||||
let mut ft_params: &mut FileTransferParams =
|
||||
&mut self.context.as_mut().unwrap().ft_params.as_mut().unwrap();
|
||||
ft_params.address = address;
|
||||
ft_params.port = port;
|
||||
ft_params.protocol = protocol;
|
||||
ft_params.username = match username.is_empty() {
|
||||
true => None,
|
||||
false => Some(username),
|
||||
};
|
||||
ft_params.password = match password.is_empty() {
|
||||
true => None,
|
||||
false => Some(password),
|
||||
};
|
||||
// Submit true
|
||||
self.submit = true;
|
||||
// Return None
|
||||
|
||||
Reference in New Issue
Block a user