diff --git a/AGENTS.md b/AGENTS.md index 2c1e45c6e..93271b652 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1385,8 +1385,12 @@ docker/ # Docker image of `ketch server` (Dockerfile, entrypoint, compose may save at (`DestinationGuard.checkMove`, 403 `path_rejected`). A copy between volumes whose original cannot be deleted afterwards still counts as moved, with a warning, and a moved task removed with its files before it runs again takes them as its own first (`v1Store` and - `v2Store` with `adopt`). The - apps have no control for it yet + `v2Store` with `adopt`). In + the apps, a finished torrent's row menu offers Move files… (`RowAction.MoveFiles`, + `RowCommands.moveFiles`, `TaskCommand.MoveFiles`) on this device where the system's folder + dialog names a file path (`FilePicker.picksFilePaths`: not Android's document trees, nor the + web): it asks for a folder, starting where the torrent is saved, and moves the files there. + Remote devices have no control for it yet - Editing trackers: `TorrentController.editTrackers(taskId, TorrentTrackerEdit(add, remove))` (REST `PUT /api/torrents/{id}/trackers`, answering the list; capability `tracker-edit`) removes the trackers at the endpoints `remove` names and appends each announce URL of `add` as a tier diff --git a/app/shared/src/androidMain/kotlin/com/linroid/ketch/app/platform/FilePicker.android.kt b/app/shared/src/androidMain/kotlin/com/linroid/ketch/app/platform/FilePicker.android.kt index 182936dc9..7fd88c524 100644 --- a/app/shared/src/androidMain/kotlin/com/linroid/ketch/app/platform/FilePicker.android.kt +++ b/app/shared/src/androidMain/kotlin/com/linroid/ketch/app/platform/FilePicker.android.kt @@ -50,6 +50,7 @@ private class AndroidFilePicker( private val torrentLauncher: ManagedActivityResultLauncher, List>, ) : FilePicker { override val canPickFolder: Boolean = true + override val picksFilePaths: Boolean = false override suspend fun pickFolder(initialFolder: String?): String? { val initial = initialFolder?.takeIf { it.startsWith(CONTENT_SCHEME) } diff --git a/app/shared/src/commonMain/composeResources/values-de/strings_downloads.xml b/app/shared/src/commonMain/composeResources/values-de/strings_downloads.xml index f643369f2..4a497f2d1 100644 --- a/app/shared/src/commonMain/composeResources/values-de/strings_downloads.xml +++ b/app/shared/src/commonMain/composeResources/values-de/strings_downloads.xml @@ -242,6 +242,7 @@ Dateien für %1$s konnten auf %2$s nicht geändert werden Seeden für %1$s konnte auf %2$s nicht geändert werden Dateien von %1$s konnten auf %2$s nicht geprüft werden + Dateien von %1$s konnten auf %2$s nicht verschoben werden %1$d Download pausiert diff --git a/app/shared/src/commonMain/composeResources/values-de/strings_tasks.xml b/app/shared/src/commonMain/composeResources/values-de/strings_tasks.xml index 4b79cb8dd..370077afe 100644 --- a/app/shared/src/commonMain/composeResources/values-de/strings_tasks.xml +++ b/app/shared/src/commonMain/composeResources/values-de/strings_tasks.xml @@ -144,6 +144,7 @@ Alle Dateien herunterladen Seeden beenden Dateien prüfen + Dateien verschieben… Seeden %1$d Download pausieren diff --git a/app/shared/src/commonMain/composeResources/values-es/strings_downloads.xml b/app/shared/src/commonMain/composeResources/values-es/strings_downloads.xml index 799ca4d0f..ec2968b0d 100644 --- a/app/shared/src/commonMain/composeResources/values-es/strings_downloads.xml +++ b/app/shared/src/commonMain/composeResources/values-es/strings_downloads.xml @@ -242,6 +242,7 @@ Error al cambiar los archivos de %1$s en %2$s Error al cambiar el sembrado de %1$s en %2$s Error al comprobar los archivos de %1$s en %2$s + Error al mover los archivos de %1$s en %2$s Se pausó %1$d descarga diff --git a/app/shared/src/commonMain/composeResources/values-es/strings_tasks.xml b/app/shared/src/commonMain/composeResources/values-es/strings_tasks.xml index 67356d08c..79e8e4490 100644 --- a/app/shared/src/commonMain/composeResources/values-es/strings_tasks.xml +++ b/app/shared/src/commonMain/composeResources/values-es/strings_tasks.xml @@ -144,6 +144,7 @@ Descargar todos los archivos Dejar de sembrar Comprobar archivos + Mover archivos… Sembrar Pausar %1$d descarga diff --git a/app/shared/src/commonMain/composeResources/values-fr/strings_downloads.xml b/app/shared/src/commonMain/composeResources/values-fr/strings_downloads.xml index 1023799f8..82b7e7a99 100644 --- a/app/shared/src/commonMain/composeResources/values-fr/strings_downloads.xml +++ b/app/shared/src/commonMain/composeResources/values-fr/strings_downloads.xml @@ -242,6 +242,7 @@ Impossible de modifier les fichiers de %1$s sur %2$s Impossible de modifier le partage de %1$s sur %2$s Impossible de vérifier les fichiers de %1$s sur %2$s + Impossible de déplacer les fichiers de %1$s sur %2$s %1$d téléchargement mis en pause diff --git a/app/shared/src/commonMain/composeResources/values-fr/strings_tasks.xml b/app/shared/src/commonMain/composeResources/values-fr/strings_tasks.xml index bf5b49927..a5945cf84 100644 --- a/app/shared/src/commonMain/composeResources/values-fr/strings_tasks.xml +++ b/app/shared/src/commonMain/composeResources/values-fr/strings_tasks.xml @@ -144,6 +144,7 @@ Télécharger tous les fichiers Arrêter le partage Vérifier les fichiers + Déplacer les fichiers… Partager Mettre en pause %1$d téléchargement diff --git a/app/shared/src/commonMain/composeResources/values-ja/strings_downloads.xml b/app/shared/src/commonMain/composeResources/values-ja/strings_downloads.xml index 8f747e9fb..c6700088a 100644 --- a/app/shared/src/commonMain/composeResources/values-ja/strings_downloads.xml +++ b/app/shared/src/commonMain/composeResources/values-ja/strings_downloads.xml @@ -228,6 +228,7 @@ %2$sで%1$sのファイルを変更できませんでした %2$sで%1$sのシードを変更できませんでした %2$sで%1$sのファイルを確認できませんでした + %2$sで%1$sのファイルを移動できませんでした %1$d件のダウンロードを一時停止しました diff --git a/app/shared/src/commonMain/composeResources/values-ja/strings_tasks.xml b/app/shared/src/commonMain/composeResources/values-ja/strings_tasks.xml index 06c2d5ce5..32fc96f49 100644 --- a/app/shared/src/commonMain/composeResources/values-ja/strings_tasks.xml +++ b/app/shared/src/commonMain/composeResources/values-ja/strings_tasks.xml @@ -141,6 +141,7 @@ すべてのファイルをダウンロード シードを停止 ファイルを確認 + ファイルを移動… シード %1$d件のダウンロードを一時停止 diff --git a/app/shared/src/commonMain/composeResources/values-ko/strings_downloads.xml b/app/shared/src/commonMain/composeResources/values-ko/strings_downloads.xml index fc059a00b..7f8691d97 100644 --- a/app/shared/src/commonMain/composeResources/values-ko/strings_downloads.xml +++ b/app/shared/src/commonMain/composeResources/values-ko/strings_downloads.xml @@ -228,6 +228,7 @@ %2$s에서 %1$s의 파일을 변경할 수 없음 %2$s에서 %1$s의 시딩을 변경할 수 없음 %2$s에서 %1$s의 파일을 검사할 수 없음 + %2$s에서 %1$s의 파일을 이동할 수 없음 다운로드 %1$d개 일시정지됨 diff --git a/app/shared/src/commonMain/composeResources/values-ko/strings_tasks.xml b/app/shared/src/commonMain/composeResources/values-ko/strings_tasks.xml index abe3a0209..96b461451 100644 --- a/app/shared/src/commonMain/composeResources/values-ko/strings_tasks.xml +++ b/app/shared/src/commonMain/composeResources/values-ko/strings_tasks.xml @@ -141,6 +141,7 @@ 모든 파일 다운로드 시딩 중지 파일 검사 + 파일 이동… 시드 다운로드 %1$d개 일시정지 diff --git a/app/shared/src/commonMain/composeResources/values-pt/strings_downloads.xml b/app/shared/src/commonMain/composeResources/values-pt/strings_downloads.xml index bd9f31ae0..5f39d7427 100644 --- a/app/shared/src/commonMain/composeResources/values-pt/strings_downloads.xml +++ b/app/shared/src/commonMain/composeResources/values-pt/strings_downloads.xml @@ -242,6 +242,7 @@ Não foi possível alterar os arquivos de %1$s (%2$s) Não foi possível alterar o semeio de %1$s (%2$s) Não foi possível verificar os arquivos de %1$s (%2$s) + Não foi possível mover os arquivos de %1$s (%2$s) %1$d download pausado diff --git a/app/shared/src/commonMain/composeResources/values-pt/strings_tasks.xml b/app/shared/src/commonMain/composeResources/values-pt/strings_tasks.xml index b485b53bc..ff9e7251f 100644 --- a/app/shared/src/commonMain/composeResources/values-pt/strings_tasks.xml +++ b/app/shared/src/commonMain/composeResources/values-pt/strings_tasks.xml @@ -144,6 +144,7 @@ Baixar todos os arquivos Parar de semear Verificar arquivos + Mover arquivos… Semear Pausar %1$d download diff --git a/app/shared/src/commonMain/composeResources/values-ru/strings_downloads.xml b/app/shared/src/commonMain/composeResources/values-ru/strings_downloads.xml index 1f7a670e7..f4fbd6385 100644 --- a/app/shared/src/commonMain/composeResources/values-ru/strings_downloads.xml +++ b/app/shared/src/commonMain/composeResources/values-ru/strings_downloads.xml @@ -270,6 +270,7 @@ Не удалось изменить файлы %1$s на устройстве «%2$s» Не удалось изменить раздачу %1$s на устройстве «%2$s» Не удалось проверить файлы %1$s на устройстве «%2$s» + Не удалось переместить файлы %1$s на устройстве «%2$s» Приостановлена %1$d загрузка diff --git a/app/shared/src/commonMain/composeResources/values-ru/strings_tasks.xml b/app/shared/src/commonMain/composeResources/values-ru/strings_tasks.xml index 26bd0fc44..1d0b70bae 100644 --- a/app/shared/src/commonMain/composeResources/values-ru/strings_tasks.xml +++ b/app/shared/src/commonMain/composeResources/values-ru/strings_tasks.xml @@ -150,6 +150,7 @@ Скачать все файлы Остановить раздачу Проверить файлы + Переместить файлы… Раздавать Приостановить %1$d загрузку diff --git a/app/shared/src/commonMain/composeResources/values-zh-rTW/strings_downloads.xml b/app/shared/src/commonMain/composeResources/values-zh-rTW/strings_downloads.xml index 0e4a3d0cd..abf916fe5 100644 --- a/app/shared/src/commonMain/composeResources/values-zh-rTW/strings_downloads.xml +++ b/app/shared/src/commonMain/composeResources/values-zh-rTW/strings_downloads.xml @@ -228,6 +228,7 @@ 無法在 %2$s 上變更 %1$s 的檔案 無法在 %2$s 上變更 %1$s 的做種 無法在 %2$s 上檢查 %1$s 的檔案 + 無法在 %2$s 上移動 %1$s 的檔案 已暫停 %1$d 個下載項目 diff --git a/app/shared/src/commonMain/composeResources/values-zh-rTW/strings_tasks.xml b/app/shared/src/commonMain/composeResources/values-zh-rTW/strings_tasks.xml index be0027cac..26c8c275e 100644 --- a/app/shared/src/commonMain/composeResources/values-zh-rTW/strings_tasks.xml +++ b/app/shared/src/commonMain/composeResources/values-zh-rTW/strings_tasks.xml @@ -141,6 +141,7 @@ 下載全部檔案 停止做種 檢查檔案 + 移動檔案… 做種 暫停 %1$d 個下載項目 diff --git a/app/shared/src/commonMain/composeResources/values-zh/strings_downloads.xml b/app/shared/src/commonMain/composeResources/values-zh/strings_downloads.xml index e321ddedd..837f5fb3a 100644 --- a/app/shared/src/commonMain/composeResources/values-zh/strings_downloads.xml +++ b/app/shared/src/commonMain/composeResources/values-zh/strings_downloads.xml @@ -228,6 +228,7 @@ 无法在 %2$s 上更改 %1$s 的文件 无法在 %2$s 上更改 %1$s 的做种 无法在 %2$s 上校验 %1$s 的文件 + 无法在 %2$s 上移动 %1$s 的文件 已暂停 %1$d 个下载 diff --git a/app/shared/src/commonMain/composeResources/values-zh/strings_tasks.xml b/app/shared/src/commonMain/composeResources/values-zh/strings_tasks.xml index 962b48917..08b63b8bc 100644 --- a/app/shared/src/commonMain/composeResources/values-zh/strings_tasks.xml +++ b/app/shared/src/commonMain/composeResources/values-zh/strings_tasks.xml @@ -141,6 +141,7 @@ 下载全部文件 停止做种 校验文件 + 移动文件… 做种 暂停 %1$d 个下载 diff --git a/app/shared/src/commonMain/composeResources/values/strings_downloads.xml b/app/shared/src/commonMain/composeResources/values/strings_downloads.xml index 0d5fd6f3e..6f124323d 100644 --- a/app/shared/src/commonMain/composeResources/values/strings_downloads.xml +++ b/app/shared/src/commonMain/composeResources/values/strings_downloads.xml @@ -308,6 +308,7 @@ Couldn't change files for %1$s on %2$s Couldn't change seeding for %1$s on %2$s Couldn't check the files of %1$s on %2$s + Couldn't move the files of %1$s on %2$s diff --git a/app/shared/src/commonMain/composeResources/values/strings_tasks.xml b/app/shared/src/commonMain/composeResources/values/strings_tasks.xml index 9ba2af72d..c02336813 100644 --- a/app/shared/src/commonMain/composeResources/values/strings_tasks.xml +++ b/app/shared/src/commonMain/composeResources/values/strings_tasks.xml @@ -184,6 +184,7 @@ Stop seeding Check files + Move files… Seed diff --git a/app/shared/src/commonMain/kotlin/com/linroid/ketch/app/platform/FilePicker.kt b/app/shared/src/commonMain/kotlin/com/linroid/ketch/app/platform/FilePicker.kt index 1b0bcdb20..0cb500043 100644 --- a/app/shared/src/commonMain/kotlin/com/linroid/ketch/app/platform/FilePicker.kt +++ b/app/shared/src/commonMain/kotlin/com/linroid/ketch/app/platform/FilePicker.kt @@ -7,6 +7,12 @@ interface FilePicker { /** Whether [pickFolder] can choose a folder here; the web cannot. */ val canPickFolder: Boolean + /** + * Whether [pickFolder] answers a file path, which a download's files can be moved into, rather + * than a document tree, as on Android. + */ + val picksFilePaths: Boolean get() = true + /** * Asks the user for a folder to save downloads in. * diff --git a/app/shared/src/commonMain/kotlin/com/linroid/ketch/app/state/RowAction.kt b/app/shared/src/commonMain/kotlin/com/linroid/ketch/app/state/RowAction.kt index 23faf610d..ada4615e1 100644 --- a/app/shared/src/commonMain/kotlin/com/linroid/ketch/app/state/RowAction.kt +++ b/app/shared/src/commonMain/kotlin/com/linroid/ketch/app/state/RowAction.kt @@ -9,6 +9,7 @@ import com.linroid.ketch.app.util.isTorrent import com.linroid.ketch.app.util.toCopy import ketch.app.shared.generated.resources.Res import ketch.app.shared.generated.resources.action_row_check_files +import ketch.app.shared.generated.resources.action_row_move_files import ketch.app.shared.generated.resources.action_row_choose_files import ketch.app.shared.generated.resources.action_row_connections import ketch.app.shared.generated.resources.action_row_copy_details @@ -149,6 +150,9 @@ sealed class RowAction(val label: UiText, val destructive: Boolean = false) { */ data object CheckFiles : RowAction(Res.string.action_row_check_files.text()) + /** Moves a finished torrent's files into a folder chosen with the system's folder dialog. */ + data object MoveFiles : RowAction(Res.string.action_row_move_files.text()) + /** Cancels the task after confirmation; its progress cannot be resumed. */ data object StopAndDiscard : RowAction(Res.string.action_row_stop_and_discard.text(), destructive = true) @@ -323,6 +327,7 @@ private fun completed( // comes with its torrent snapshot, which the inspector follows and rows do not. RowAction.StopSeeding.takeIf { seeding }, RowAction.CheckFiles.takeIf { torrent }, + RowAction.MoveFiles.takeIf { torrent && local }, RowAction.CopyLink, RowAction.CopyPath, RowAction.SendTo, diff --git a/app/shared/src/commonMain/kotlin/com/linroid/ketch/app/ui/downloads/actions/RowActionRunner.kt b/app/shared/src/commonMain/kotlin/com/linroid/ketch/app/ui/downloads/actions/RowActionRunner.kt index ca65ba15d..f64efaa14 100644 --- a/app/shared/src/commonMain/kotlin/com/linroid/ketch/app/ui/downloads/actions/RowActionRunner.kt +++ b/app/shared/src/commonMain/kotlin/com/linroid/ketch/app/ui/downloads/actions/RowActionRunner.kt @@ -26,6 +26,7 @@ import com.linroid.ketch.app.i18n.verbatim import com.linroid.ketch.app.instance.InstanceEntry import com.linroid.ketch.app.platform.FileActions import com.linroid.ketch.app.platform.rememberFileActions +import com.linroid.ketch.app.platform.rememberFilePicker import com.linroid.ketch.app.platform.rememberSystemClipboard import com.linroid.ketch.app.state.AppState import com.linroid.ketch.app.state.LocalAppState @@ -570,8 +571,9 @@ internal fun rememberRowCommands(state: AppState): RowCommands { val clipboard = rememberSystemClipboard() val uriHandler = LocalUriHandler.current val scope = rememberCoroutineScope() - return remember(state, files, clipboard, uriHandler, scope) { - RowCommands(state, files, clipboard, scope, uriHandler::openUri) + val picker = rememberFilePicker() + return remember(state, files, clipboard, uriHandler, scope, picker) { + RowCommands(state, files, clipboard, scope, picker, uriHandler::openUri) } } diff --git a/app/shared/src/commonMain/kotlin/com/linroid/ketch/app/ui/downloads/actions/RowMenu.kt b/app/shared/src/commonMain/kotlin/com/linroid/ketch/app/ui/downloads/actions/RowMenu.kt index ed08a59ba..11b707cde 100644 --- a/app/shared/src/commonMain/kotlin/com/linroid/ketch/app/ui/downloads/actions/RowMenu.kt +++ b/app/shared/src/commonMain/kotlin/com/linroid/ketch/app/ui/downloads/actions/RowMenu.kt @@ -628,6 +628,7 @@ internal val RowAction.icon: KetchIcon RowAction.StopSeeding -> KetchIcon.Stop RowAction.Seed -> KetchIcon.Send RowAction.CheckFiles -> KetchIcon.CheckCircle + RowAction.MoveFiles -> KetchIcon.Folder RowAction.StopAndDiscard -> KetchIcon.Stop RowAction.Remove -> KetchIcon.Trash } diff --git a/app/shared/src/commonMain/kotlin/com/linroid/ketch/app/ui/list/RowCommands.kt b/app/shared/src/commonMain/kotlin/com/linroid/ketch/app/ui/list/RowCommands.kt index fb43a6ea1..c1ba1abd5 100644 --- a/app/shared/src/commonMain/kotlin/com/linroid/ketch/app/ui/list/RowCommands.kt +++ b/app/shared/src/commonMain/kotlin/com/linroid/ketch/app/ui/list/RowCommands.kt @@ -13,15 +13,18 @@ import com.linroid.ketch.app.i18n.load import com.linroid.ketch.app.i18n.text import com.linroid.ketch.app.i18n.verbatim import com.linroid.ketch.app.platform.FileActions +import com.linroid.ketch.app.platform.FilePicker import com.linroid.ketch.app.platform.SystemClipboard import com.linroid.ketch.app.state.AppState import com.linroid.ketch.app.state.DiscoverRequest import com.linroid.ketch.app.state.IntakeRequest import com.linroid.ketch.app.state.IntakeSeed +import com.linroid.ketch.app.state.LOCAL_DEVICE_ID import com.linroid.ketch.app.state.RowAction import com.linroid.ketch.app.state.TaskKey import com.linroid.ketch.app.state.TaskRow import com.linroid.ketch.app.state.catchingUnlessCancelled +import com.linroid.ketch.app.state.isDocumentTree import com.linroid.ketch.app.util.errorDetails import com.linroid.ketch.app.util.referer import com.linroid.ketch.torrent.api.TorrentCommandContext @@ -51,6 +54,7 @@ import ketch.app.shared.generated.resources.downloads_failed_resume import ketch.app.shared.generated.resources.downloads_failed_retry import ketch.app.shared.generated.resources.downloads_failed_reveal import ketch.app.shared.generated.resources.downloads_failed_check_files +import ketch.app.shared.generated.resources.downloads_failed_move_files import ketch.app.shared.generated.resources.downloads_failed_seeding import ketch.app.shared.generated.resources.downloads_failed_speed_limit import ketch.app.shared.generated.resources.downloads_open_source_failed @@ -90,7 +94,10 @@ internal enum class TaskCommand(val key: String, private val failure: StringReso Seed("seed", Res.string.downloads_failed_seeding), /** Checks a finished torrent's files again. */ - CheckFiles("check-files", Res.string.downloads_failed_check_files); + CheckFiles("check-files", Res.string.downloads_failed_check_files), + + /** Moves a torrent's files into another folder. */ + MoveFiles("move-files", Res.string.downloads_failed_move_files); /** * The failure of this command on [what], a task's name or a number of downloads, on [device]: @@ -143,6 +150,7 @@ internal enum class CopiedText( * @property files opens and reveals downloaded files; `null` where they are out of reach. * @property clipboard receives copied links, paths and error details; `null` where there is none. * @property scope runs clipboard writes. + * @property picker chooses the folder a torrent's files move into; `null` where there is none. * @param openUri opens a web page, such as the page a link was captured from. */ internal class RowCommands( @@ -150,6 +158,7 @@ internal class RowCommands( val files: FileActions?, val clipboard: SystemClipboard?, val scope: CoroutineScope, + val picker: FilePicker? = null, private val openUri: (String) -> Unit, ) { /** Whether [action] can run on [row] here; files need [files] and copies a clipboard. */ @@ -162,6 +171,10 @@ internal class RowCommands( RowAction.FindAnotherSource -> row.device.capabilities.canDiscover RowAction.StopSeeding, RowAction.Seed, RowAction.CheckFiles -> state.torrentControllerOf(row.key.deviceId) != null + // On this device only, where the system's dialog names a folder its files can move into. + RowAction.MoveFiles -> picker?.canPickFolder == true && picker.picksFilePaths && + row.key.deviceId == LOCAL_DEVICE_ID && row.outputFile?.let(::isDocumentTree) == false && + state.torrentControllerOf(row.key.deviceId) != null else -> true } @@ -211,6 +224,7 @@ internal class RowCommands( RowAction.StopSeeding -> setSeeding(row, seeding = false) RowAction.Seed -> setSeeding(row, seeding = true) RowAction.CheckFiles -> checkFiles(row) + RowAction.MoveFiles -> moveFiles(row) RowAction.EditLink, RowAction.RetryWithOptions, RowAction.EnterCredentials -> state.openIntake(retryRequest(row)) @@ -274,6 +288,24 @@ internal class RowCommands( } } + /** + * Asks for a folder, starting where [row]'s torrent is saved, and moves its files there + * through its device's [TorrentController]; nothing happens when no folder is chosen. + */ + fun moveFiles(row: TaskRow): Job { + val app = state + val picker = picker + return scope.launch { + val saved = row.outputFile?.let(::folderHolding) + val folder = picker?.pickFolder(saved) ?: return@launch + command(row, TaskCommand.MoveFiles) { + val controller = app.torrentControllerOf(row.key.deviceId) + ?: throw UnsupportedOperationException() + controller.relocate(taskId, folder) + } + } + } + private fun command( row: TaskRow, command: TaskCommand, @@ -373,6 +405,13 @@ private val WEB_SCHEMES = listOf("https://", "http://") private fun folderPath(row: TaskRow): String? = row.outputFile ?: row.request.destination?.takeUnless(Destination::isName)?.value +/** The folder holding [path], with either separator; `null` when it names none. */ +private fun folderHolding(path: String): String? { + val trimmed = path.trimEnd('/', '\\') + return trimmed.take(trimmed.lastIndexOfAny(charArrayOf('/', '\\')).coerceAtLeast(0)) + .ifEmpty { null } +} + /** A new idempotency key for a [TorrentController] command. */ @OptIn(ExperimentalUuidApi::class) internal fun newCommandKey(): String = Uuid.random().toString() diff --git a/app/shared/src/commonTest/kotlin/com/linroid/ketch/app/ui/downloads/actions/ActionsFixture.kt b/app/shared/src/commonTest/kotlin/com/linroid/ketch/app/ui/downloads/actions/ActionsFixture.kt index 583632d19..cddde6489 100644 --- a/app/shared/src/commonTest/kotlin/com/linroid/ketch/app/ui/downloads/actions/ActionsFixture.kt +++ b/app/shared/src/commonTest/kotlin/com/linroid/ketch/app/ui/downloads/actions/ActionsFixture.kt @@ -41,7 +41,8 @@ internal class ActionsFixture( val files = FakeFileActions(revealLabel, canTrash) val clipboard = FakeClipboard() val state: AppState get() = controller.state - val commands = RowCommands(controller.state, files, clipboard, scope.backgroundScope, openUri) + val commands = RowCommands(controller.state, files, clipboard, scope.backgroundScope, + openUri = openUri) val runner = RowActionRunner(commands) /** Adds a task in [state] to the device. */ diff --git a/app/shared/src/commonTest/kotlin/com/linroid/ketch/app/util/RowContentTest.kt b/app/shared/src/commonTest/kotlin/com/linroid/ketch/app/util/RowContentTest.kt index a72a7d3e3..183a93238 100644 --- a/app/shared/src/commonTest/kotlin/com/linroid/ketch/app/util/RowContentTest.kt +++ b/app/shared/src/commonTest/kotlin/com/linroid/ketch/app/util/RowContentTest.kt @@ -274,6 +274,10 @@ class RowContentTest { assertTrue(RowAction.CheckFiles in taskActions(torrent, state, local).menu) assertTrue(RowAction.CheckFiles in taskActions(torrent, state, remote).menu) assertFalse(RowAction.CheckFiles in taskActions(request, state, local).menu) + // Its files can be moved on this device, where a folder can be chosen. + assertTrue(RowAction.MoveFiles in taskActions(torrent, state, local).menu) + assertFalse(RowAction.MoveFiles in taskActions(torrent, state, remote).menu) + assertFalse(RowAction.MoveFiles in taskActions(request, state, local).menu) assertFalse( RowAction.StopSeeding in taskActions(request, state.copy(sharing = false), local).menu ) diff --git a/app/shared/src/jvmTest/kotlin/com/linroid/ketch/app/snapshot/RowActionsSnapshots.kt b/app/shared/src/jvmTest/kotlin/com/linroid/ketch/app/snapshot/RowActionsSnapshots.kt index dba7b87e4..33d55e613 100644 --- a/app/shared/src/jvmTest/kotlin/com/linroid/ketch/app/snapshot/RowActionsSnapshots.kt +++ b/app/shared/src/jvmTest/kotlin/com/linroid/ketch/app/snapshot/RowActionsSnapshots.kt @@ -59,7 +59,9 @@ import com.linroid.ketch.app.components.PriorityGlyph import com.linroid.ketch.app.components.StatusDot import com.linroid.ketch.app.components.StatusDotDefaults import com.linroid.ketch.app.i18n.resolve +import com.linroid.ketch.app.platform.DroppedFile import com.linroid.ketch.app.platform.FileActions +import com.linroid.ketch.app.platform.FilePicker import com.linroid.ketch.app.state.AppController import com.linroid.ketch.app.state.AppState import com.linroid.ketch.app.state.LocalAppState @@ -423,7 +425,7 @@ private fun StandInDownloads( val rows = view.rows val scope = rememberCoroutineScope() val runner = remember(state, files) { - val commands = RowCommands(state, files, SnapshotClipboard(), scope) {} + val commands = RowCommands(state, files, SnapshotClipboard(), scope, SnapshotFolders) {} RowActionRunner(commands) } val actions = rememberListActions(rows, state, runner) @@ -742,3 +744,12 @@ private fun bandSnapshot( } } } + +/** A folder dialog that is there and never answers, so menus offer what needs one. */ +private object SnapshotFolders : FilePicker { + override val canPickFolder: Boolean = true + + override suspend fun pickFolder(initialFolder: String?): String? = null + + override suspend fun pickTorrentFiles(): List = emptyList() +} diff --git a/docs/torrent.md b/docs/torrent.md index ea5e46733..ce36e8b8b 100644 --- a/docs/torrent.md +++ b/docs/torrent.md @@ -549,10 +549,11 @@ answers the new list; SDK: `TorrentController.editTrackers(taskId, TorrentTracke ### Moving a torrent's files -A torrent's files can be moved to another folder without adding it again: +A torrent's files can be moved to another folder without adding it again. In the desktop app, +right-click a finished torrent saved on this computer and choose **Move files…**, then pick the +folder; the phone apps and torrents on other devices have no button for it yet. REST: `PUT /api/torrents/{id}/location` with `{"directory": "/absolute/folder"}`, on devices listing -the `relocate` capability (SDK: `TorrentController.relocate(taskId, directory)`); the apps have -no button for it yet. The files keep their name inside the new folder. A downloading torrent +the `relocate` capability (SDK: `TorrentController.relocate(taskId, directory)`). The files keep their name inside the new folder. A downloading torrent stops for the move and goes on after it; a finished one is checked at its new place and seeds again if it was seeding; a paused one is checked when it next starts. On the same volume the move is a rename; between volumes the files are copied and the originals deleted once the copy is