Skip to content

Conversation

@yqx1110
Copy link
Contributor

@yqx1110 yqx1110 commented Jan 29, 2026

Inspired by Vuetorrent similar feature: VueTorrent/VueTorrent#2501

Uses getDirectoryContent API

Screenshots:

image image

}

searchDirectoriesJob = viewModelScope.launch {
kotlinx.coroutines.delay(300)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to use the fully qualified name here. Import kotlinx.coroutines.delay and call it as delay(300).

var savePathExpanded by remember { mutableStateOf(false) }

// Hide suggestions when IME is folded
val density = androidx.compose.ui.platform.LocalDensity.current
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous one.


fun searchDirectories(serverId: Int, path: String) {
searchDirectoriesJob?.cancel()
if (path.isBlank() || !path.startsWith("/")) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (path.isBlank() || !path.startsWith("/")) {
if (path.isBlank()) {

You also need to consider Windows users. It’s also possible that they are using network drives on Windows, which start with \\, etc. I think it’s better to remove this check altogether.

// if path doesn't ends with a slash, we need to also check the parent directory for suggestions
// e.g. for /downloads/m, check if there's a directory's name under /downloads starts with "m"
if (!path.endsWith("/")) {
val lastSeparatorIndex = path.lastIndexOf('/')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to handle the Windows case here as well. I don’t think there’s a way to get the operating system from the API, so you can check whether the path contains / and treat it as Unix in that case.

is RequestResult.Success -> {
suggestions.addAll(result.data)
}
else -> {}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else -> {}
is RequestResult.Error -> {}

is RequestResult.Success -> {
suggestions.addAll(result.data)
}
else -> {}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else -> {}
is RequestResult.Error -> {}

onClick = {
savePath = TextFieldValue(
text = suggestion,
selection = androidx.compose.ui.text.TextRange(suggestion.length),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this fully qualified name as well.


fun searchDirectories(serverId: Int, path: String) {
searchDirectoriesJob?.cancel()
if (path.isBlank() || !path.startsWith("/")) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getDirectoryContent was added in qBittorrent 5.0.0, so you need to account for that. Inject RequestManager in the constructor, then you can check the version like this:

val version = requestManager.getQBittorrentVersion(serverId)
if (version >= QBittorrentVersion(5, 0, 0)) {
    // ..
}

Comment on lines +237 to +255
when (val result = repository.getDirectoryContent(serverId, path)) {
is RequestResult.Success -> {
suggestions.addAll(result.data)
}
else -> {}
}

// if path doesn't ends with a slash, we need to also check the parent directory for suggestions
// e.g. for /downloads/m, check if there's a directory's name under /downloads starts with "m"
if (!path.endsWith("/")) {
val lastSeparatorIndex = path.lastIndexOf('/')
val parent = path.take(lastSeparatorIndex + 1)
when (val result = repository.getDirectoryContent(serverId, parent)) {
is RequestResult.Success -> {
suggestions.addAll(result.data)
}
else -> {}
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s better to run these network requests in parallel. Launch two more coroutines, one for each request, have both return lists, then combine the results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants