Skip to content

Commit

Permalink
Added pause all & resume all buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-128 committed Dec 5, 2023
1 parent 6077ec1 commit c923cda
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 8 deletions.
8 changes: 8 additions & 0 deletions qBitControl/Classes/qBittorrentClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ class qBittorrent {
qBitRequest.requestTorrentManagement(request: request)
}

static func pauseAllTorrents() {
pauseTorrent(hash: "all")
}

static func resumeTorrent(hash: String) {
let path = "/api/v2/torrents/resume"

Expand All @@ -223,6 +227,10 @@ class qBittorrent {
qBitRequest.requestTorrentManagement(request: request)
}

static func resumeAllTorrents() {
resumeTorrent(hash: "all")
}

static func recheckTorrent(hash: String) {
let path = "/api/v2/torrents/recheck"

Expand Down
48 changes: 42 additions & 6 deletions qBitControl/DemoView/TorrentListViewDemo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct TorrentListViewDemo: View {

let defaults = UserDefaults.standard

@State private var alertIdentifier: AlertIdentifier?

func torrentListHeader() -> some View {
HStack(spacing: 3) {
Expand Down Expand Up @@ -147,13 +148,48 @@ struct TorrentListViewDemo: View {
}
.toolbar() {
ToolbarItem(placement: .navigationBarLeading) {
Button {
//qBittorrent.setCookie(cookie: "")
isDemo = false
Menu {
Button {
alertIdentifier = AlertIdentifier(id: .resumeAll)
} label: {
Image(systemName: "play")
.rotationEffect(.degrees(180))
Text("Resume All Tasks")
}

Button {
alertIdentifier = AlertIdentifier(id: .pauseAll)
} label: {
Image(systemName: "pause")
.rotationEffect(.degrees(180))
Text("Pause All Tasks")
}

Button(role: .destructive) {
alertIdentifier = AlertIdentifier(id: .logOut)
} label: {
Image(systemName: "rectangle.portrait.and.arrow.forward")
.rotationEffect(.degrees(180))
Text("Log out")
}
} label: {
Image(systemName: "rectangle.portrait.and.arrow.forward")
.rotationEffect(.degrees(180))
Text("Log out")
Image(systemName: "ellipsis.circle")
}.alert(item: $alertIdentifier) { alert in
switch(alert.id) {
case .resumeAll:
return Alert(title: Text("Confirm Resume All"), message: Text("Are you sure you want to resume all tasks?"), primaryButton: .default(Text("Resume")) {
//qBittorrent.resumeAllTorrents()
}, secondaryButton: .cancel())
case .pauseAll:
return Alert(title: Text("Confirm Pause All"), message: Text("Are you sure you want to pause all tasks?"), primaryButton: .default(Text("Pause")) {
//qBittorrent.pauseAllTorrents()
}, secondaryButton: .cancel())
case .logOut:
return Alert(title: Text("Confirm Logout"), message: Text("Are you sure you want to log out?"), primaryButton: .destructive(Text("Log Out")) {
qBittorrent.setCookie(cookie: "")
isDemo = false
}, secondaryButton: .cancel())
}
}
}
ToolbarItem(placement: .navigationBarTrailing) {
Expand Down
8 changes: 8 additions & 0 deletions qBitControl/Structures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,11 @@ struct RSS: Decodable {
self.articles = try container.decode([Article].self, forKey: .articles).sorted(by: { $0.date > $1.date })
}
}

struct AlertIdentifier: Identifiable {
enum Choice {
case resumeAll, pauseAll, logOut
}

var id: Choice
}
51 changes: 49 additions & 2 deletions qBitControl/TorrentView/TorrentListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ struct TorrentListView: View {

@Binding var isLoggedIn: Bool

@State private var alertIdentifier: AlertIdentifier?

let defaults = UserDefaults.standard

func getTorrents() {
Expand Down Expand Up @@ -165,14 +167,59 @@ struct TorrentListView: View {
}
.toolbar() {
ToolbarItem(placement: .navigationBarLeading) {
Button {
Menu {
Button {
alertIdentifier = AlertIdentifier(id: .resumeAll)
} label: {
Image(systemName: "play")
.rotationEffect(.degrees(180))
Text("Resume All Tasks")
}

Button {
alertIdentifier = AlertIdentifier(id: .pauseAll)
} label: {
Image(systemName: "pause")
.rotationEffect(.degrees(180))
Text("Pause All Tasks")
}

Button(role: .destructive) {
alertIdentifier = AlertIdentifier(id: .logOut)
} label: {
Image(systemName: "rectangle.portrait.and.arrow.forward")
.rotationEffect(.degrees(180))
Text("Log out")
}
} label: {
Image(systemName: "ellipsis.circle")
}.alert(item: $alertIdentifier) { alert in
switch(alert.id) {
case .resumeAll:
return Alert(title: Text("Confirm Resume All"), message: Text("Are you sure you want to resume all tasks?"), primaryButton: .default(Text("Resume")) {
qBittorrent.resumeAllTorrents()
}, secondaryButton: .cancel())
case .pauseAll:
return Alert(title: Text("Confirm Pause All"), message: Text("Are you sure you want to pause all tasks?"), primaryButton: .default(Text("Pause")) {
qBittorrent.pauseAllTorrents()
}, secondaryButton: .cancel())
case .logOut:
return Alert(title: Text("Confirm Logout"), message: Text("Are you sure you want to log out?"), primaryButton: .destructive(Text("Log Out")) {
qBittorrent.setCookie(cookie: "")
isLoggedIn = false
}, secondaryButton: .cancel())
}
}

//Image(systemName: "ellipsis.circle")
/*Button {
qBittorrent.setCookie(cookie: "")
isLoggedIn = false
} label: {
Image(systemName: "rectangle.portrait.and.arrow.forward")
.rotationEffect(.degrees(180))
Text("Log out")
}
}*/
}
ToolbarItem(placement: .navigationBarTrailing) {
Button {
Expand Down

0 comments on commit c923cda

Please sign in to comment.