Skip to content

Commit

Permalink
Add rss feeds & folders renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-128 committed Feb 7, 2025
1 parent 0713fd4 commit c238aba
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Localization/Localizations/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -4019,6 +4019,9 @@
}
}
}
},
"New Name" : {

},
"New URL" : {
"localizations" : {
Expand Down Expand Up @@ -5328,6 +5331,9 @@
}
}
}
},
"Rename" : {

},
"Report a bug" : {
"localizations" : {
Expand Down
9 changes: 9 additions & 0 deletions qBitControl/Classes/qBittorrentClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,15 @@ class qBittorrent {
qBitRequest.requestUniversal(request: request)
}

static func moveRSSItem(itemPath: String, destPath: String) {
let request = qBitRequest.prepareURLRequest(path: "/api/v2/rss/moveItem", queryItems: [
URLQueryItem(name: "itemPath", value: itemPath),
URLQueryItem(name: "destPath", value: destPath)
])

qBitRequest.requestUniversal(request: request)
}

static func removeTracker(hash: String, url: String) {
let path = "/api/v2/torrents/removeTrackers"

Expand Down
41 changes: 33 additions & 8 deletions qBitControl/Views/RSSViews/RSSNodeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ struct RSSNodeView: View {

@State private var isAddFeedAlert: Bool = false
@State private var isAddFolderAlert: Bool = false
@State private var isRenameAlert: Bool = false

@State private var newFeedURL = ""
@State private var newFolderName = ""

@State private var newRenameName = ""
@State private var oldRenamePath = ""

func getItemPath(item: String) -> String {
var path = self.path + [item]
path.removeFirst()
return path.joined(separator: "\\")
}

var body: some View {
List {
Section(header: sectionHeader()) {
Expand All @@ -35,6 +44,7 @@ struct RSSNodeView: View {
.toolbar { toolbar() }
.alert("Add Feed", isPresented: $isAddFeedAlert, actions: { addFeedAlert() })
.alert("Add Folder", isPresented: $isAddFolderAlert, actions: { addFolderAlert() })
.alert("New Name", isPresented: $isRenameAlert, actions: { renameAlert() })
}

func sectionHeader() -> Text {
Expand Down Expand Up @@ -88,20 +98,35 @@ struct RSSNodeView: View {
}
}

func renameAlert() -> some View {
VStack {
TextField("Name", text: $newRenameName)
Button("Save") {
let newRenamePath = self.getItemPath(item: newRenameName)
qBittorrent.moveRSSItem(itemPath: oldRenamePath, destPath: newRenamePath)

oldRenamePath = ""
newRenameName = ""
refresh()
}
Button("Cancel", role: .cancel) {}
}
}

func itemContextMenu(itemTitle: String, isFolder: Bool = false) -> some View {
VStack {
if !isFolder {
Button {
var path = self.path + [itemTitle]
path.removeFirst()
print(path.joined(separator: "\\"))
qBittorrent.addRSSRefreshItem(path: path.joined(separator: "\\"))
qBittorrent.addRSSRefreshItem(path: self.getItemPath(item: itemTitle))
} label: { Label("Refresh", systemImage: "arrow.clockwise") }
}
Button {
self.newRenameName = itemTitle
self.oldRenamePath = self.getItemPath(item: itemTitle)
self.isRenameAlert.toggle()
} label: { Label("Rename", systemImage: "pencil") }
Button(role: .destructive) {
var path = self.path + [itemTitle]
path.removeFirst()
qBittorrent.addRSSRemoveItem(path: path.joined(separator: "\\"))
qBittorrent.addRSSRemoveItem(path: self.getItemPath(item: itemTitle))
} label: { Label("Remove", systemImage: "trash") }
}
}
Expand Down

0 comments on commit c238aba

Please sign in to comment.