Skip to content

Commit

Permalink
Rearrange Torrent Details & Add ETA
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-128 committed Nov 20, 2024
1 parent 2df104c commit a7b39ab
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 15 deletions.
25 changes: 25 additions & 0 deletions qBitControl/Classes/qBittorrentClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,31 @@ class qBittorrent {
return formatter.string(from: fullDate)
}

static func getFormattedTime(time: Int) -> String {
let days = time / (24 * 60 * 60)
let hours = (time / (60 * 60)) % 24
let minutes = (time / 60) % 60
let seconds = time % 60

var components: [String] = []

if days > 0 {
components.append("\(days)d")
components.append("\(hours)h")
} else if hours > 0 {
components.append("\(hours)h")
components.append("\(minutes)m")
} else if minutes > 0 {
components.append("\(minutes)m")
components.append("\(seconds)s")
} else {
components.append("\(seconds)s")
}

return components.joined(separator: " ")
}


static func getGlobalTransferInfo(completionHandler: @escaping (GlobalTransferInfo) -> Void) {
let request = qBitRequest.prepareURLRequest(path: "/api/v2/transfer/info")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class TorrentDetailsViewModel: ObservableObject {
func getMaxRatio() -> String { "\(torrent.max_ratio > -1 ? String(format:"%.2f", torrent.max_ratio) : NSLocalizedString("None", comment: "None"))" }
func getDownloadLimit() -> String { "\(torrent.dl_limit > 0 ? qBittorrent.getFormatedSize(size: torrent.dl_limit)+"/s" : NSLocalizedString("None", comment: "None"))" }
func getUploadLimit() -> String { "\(torrent.up_limit > 0 ? qBittorrent.getFormatedSize(size: torrent.up_limit)+"/s" : NSLocalizedString("None", comment: "None"))" }
func getETA() -> String { torrent.progress < 1 ? qBittorrent.getFormattedTime(time: torrent.eta) : "-" }


func isPaused() -> Bool { state == .paused }
Expand Down
31 changes: 16 additions & 15 deletions qBitControl/Views/TorrentViews/TorrentDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ struct TorrentDetailsView: View {
}
}

Section(header: Text("Status")) {
CustomLabelView(label: "State", value: viewModel.getState())
CustomLabelView(label: "Progress", value: viewModel.getProgress())
CustomLabelView(label: "ETA", value: viewModel.getETA())
CustomLabelView(label: "Download Speed", value: viewModel.getDownloadSpeed())
CustomLabelView(label: "Upload Speed", value: viewModel.getUploadSpeed())
CustomLabelView(label: "Downloaded", value: viewModel.getDownloaded())
CustomLabelView(label: "Uploaded", value: viewModel.getUploaded())
CustomLabelView(label: "Ratio", value: viewModel.getRatio())
}

Section(header: Text("Information")) {
CustomLabelView(label: "Name", value: viewModel.torrent.name)
CustomLabelView(label: "Added On", value: viewModel.getAddedOn())
Expand All @@ -56,6 +67,11 @@ struct TorrentDetailsView: View {
CustomLabelView(label: "Availability", value: viewModel.getAvailability())
}

Section(header: Text("Session")) {
CustomLabelView(label: "Downloaded", value: viewModel.getDownloadedSession())
CustomLabelView(label: "Uploaded", value: viewModel.getUploadedSession())
}

Section(header: Text("Connections")) {
NavigationLink {
PeersView(torrentHash: .constant(viewModel.torrent.hash))
Expand Down Expand Up @@ -83,21 +99,6 @@ struct TorrentDetailsView: View {
}
}

Section(header: Text("Status")) {
CustomLabelView(label: "State", value: viewModel.getState())
CustomLabelView(label: "Progress", value: viewModel.getProgress())
CustomLabelView(label: "Download Speed", value: viewModel.getDownloadSpeed())
CustomLabelView(label: "Upload Speed", value: viewModel.getUploadSpeed())
CustomLabelView(label: "Downloaded", value: viewModel.getDownloaded())
CustomLabelView(label: "Uploaded", value: viewModel.getUploaded())
CustomLabelView(label: "Ratio", value: viewModel.getRatio())
}

Section(header: Text("Session")) {
CustomLabelView(label: "Downloaded", value: viewModel.getDownloadedSession())
CustomLabelView(label: "Uploaded", value: viewModel.getUploadedSession())
}

Section(header: Text("Advanced")) {
Toggle(isOn: $viewModel.isSequentialDownload, label: { Text("Sequential Download") })
.onChange(of: viewModel.isSequentialDownload, perform: { _ in viewModel.toggleSequentialDownload() })
Expand Down

0 comments on commit a7b39ab

Please sign in to comment.