Skip to content

Commit

Permalink
add more headers
Browse files Browse the repository at this point in the history
  • Loading branch information
micielski committed Jul 5, 2024
1 parent cc095a1 commit 1477010
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 15 deletions.
4 changes: 2 additions & 2 deletions rm-config/defaults/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ free_space_refresh = 10

[torrents_tab]
# Available fields:
# Name, SizeWhenDone, Progress, DownloadRate, UploadRate, DownloadDir,
# Padding
# Id, Name, SizeWhenDone, Progress, DownloadRate, UploadRate, DownloadDir,
# Padding, UploadRatio, UploadedEver
headers = ["Name", "SizeWhenDone", "Progress", "DownloadRate", "UploadRate"]
9 changes: 9 additions & 0 deletions rm-config/src/main_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ pub enum Header {
UploadRate,
DownloadDir,
Padding,
UploadRatio,
UploadedEver,
Id,
}

impl Header {
Expand All @@ -75,6 +78,9 @@ impl Header {
Header::UploadRate => Constraint::Length(12),
Header::DownloadDir => Constraint::Max(70),
Header::Padding => Constraint::Length(2),
Header::UploadRatio => Constraint::Length(6),
Header::UploadedEver => Constraint::Length(12),
Header::Id => Constraint::Length(4),
}
}

Expand All @@ -88,6 +94,9 @@ impl Header {
Header::UploadRate => "Upload",
Header::DownloadDir => "Directory",
Header::Padding => "",
Header::UploadRatio => "Ratio",
Header::UploadedEver => "Up Ever",
Header::Id => "Id",
}
}
}
Expand Down
1 change: 1 addition & 0 deletions rm-main/src/transmission/fetchers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub async fn torrents(ctx: app::Ctx, table_manager: Arc<Mutex<TableManager>>) {
TorrentGetField::RateDownload,
TorrentGetField::Status,
TorrentGetField::DownloadDir,
TorrentGetField::UploadedEver,
];
let rpc_response = ctx
.client
Expand Down
43 changes: 30 additions & 13 deletions rm-main/src/ui/tabs/torrents/rustmission_torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,15 @@ pub struct RustmissionTorrent {
pub eta_secs: String,
pub download_speed: String,
pub upload_speed: String,
pub uploaded_ever: String,
pub upload_ratio: String,
status: TorrentStatus,
pub style: Style,
pub id: Id,
pub download_dir: String,
}

impl RustmissionTorrent {
fn header_to_line(&self, header: Header) -> Line {
match header {
Header::Name => Line::from(self.torrent_name.as_str()),
Header::SizeWhenDone => Line::from(self.size_when_done.as_str()),
Header::Progress => Line::from(self.progress.as_str()),
Header::Eta => Line::from(self.eta_secs.as_str()),
Header::DownloadRate => Line::from(download_speed_format(&self.download_speed)),
Header::UploadRate => Line::from(upload_speed_format(&self.upload_speed)),
Header::DownloadDir => Line::from(self.download_dir.as_str()),
Header::Padding => Line::raw(""),
}
}

pub fn to_row(&self, headers: &Vec<Header>) -> ratatui::widgets::Row {
headers
.iter()
Expand Down Expand Up @@ -75,6 +64,25 @@ impl RustmissionTorrent {
Row::new(cells)
}

fn header_to_line(&self, header: Header) -> Line {
match header {
Header::Name => Line::from(self.torrent_name.as_str()),
Header::SizeWhenDone => Line::from(self.size_when_done.as_str()),
Header::Progress => Line::from(self.progress.as_str()),
Header::Eta => Line::from(self.eta_secs.as_str()),
Header::DownloadRate => Line::from(download_speed_format(&self.download_speed)),
Header::UploadRate => Line::from(upload_speed_format(&self.upload_speed)),
Header::DownloadDir => Line::from(self.download_dir.as_str()),
Header::Padding => Line::raw(""),
Header::Id => match &self.id {
Id::Id(id) => Line::from(id.to_string()),
Id::Hash(hash) => Line::from(hash.as_str()),
},
Header::UploadRatio => Line::from(self.upload_ratio.as_str()),
Header::UploadedEver => Line::from(self.uploaded_ever.as_str()),
}
}

pub const fn status(&self) -> TorrentStatus {
self.status
}
Expand Down Expand Up @@ -128,6 +136,13 @@ impl From<&Torrent> for RustmissionTorrent {

let download_dir = t.download_dir.clone().expect("field requested");

let uploaded_ever = bytes_to_human_format(t.uploaded_ever.expect("field requested"));

let upload_ratio = {
let ratio = t.upload_ratio.expect("field requested");
format!("{:.1}", ratio)
};

Self {
torrent_name,
size_when_done,
Expand All @@ -139,6 +154,8 @@ impl From<&Torrent> for RustmissionTorrent {
style,
id,
download_dir,
uploaded_ever,
upload_ratio,
}
}
}

0 comments on commit 1477010

Please sign in to comment.