From 6f99f2974ff543137caf40d28a0601e73736f822 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Wed, 7 May 2025 21:04:16 -0400 Subject: [PATCH] Add an option to input the Lodestone ID instead on the desktop version --- src/bin/auracite/Main.qml | 50 +++++++++++++++++++++++++++++--------- src/bin/auracite/bridge.rs | 43 +++++++++++++++++++++++++++++--- 2 files changed, 79 insertions(+), 14 deletions(-) diff --git a/src/bin/auracite/Main.qml b/src/bin/auracite/Main.qml index 13d5cca..cedf467 100644 --- a/src/bin/auracite/Main.qml +++ b/src/bin/auracite/Main.qml @@ -59,28 +59,52 @@ Kirigami.ApplicationWindow { maximumWidth: Kirigami.Units.gridUnit * 20 - FormCard.FormTextFieldDelegate { - id: characterNameField - label: i18n("Character Name") - placeholderText: "Full name of the character" - focus: true + FormCard.FormRadioSelectorDelegate { + consistentWidth: true + actions: [ + Kirigami.Action { + id: nameAction + text: i18nc("@option:radio", "Name") + }, + Kirigami.Action { + id: idAction + text: i18nc("@option:radio", "ID") + } + ] } - FormCard.FormDelegateSeparator {} + FormCard.AbstractFormDelegate { + id: inputDelegate + + contentItem: QQC2.TextField { + id: inputField + placeholderText: nameAction.checked ? i18nc("@info:placeholder", "Character name") : i18nc("@info:placeholder", "Lodestone ID") + focus: true + } + } + + FormCard.FormDelegateSeparator { + above: inputDelegate + below: dalamudCheckbox + } FormCard.FormCheckDelegate { id: dalamudCheckbox - text: i18n("Use Dalamud Plugin") + text: i18n("Connect to the Dalamud Plugin") } - FormCard.FormDelegateSeparator {} + FormCard.FormDelegateSeparator { + above: dalamudCheckbox + below: loginButton + } FormCard.FormButtonDelegate { id: loginButton + icon.name: "cloud-download-symbolic" text: i18nc("@action:button", "Archive") - enabled: characterNameField.text.length > 0 + enabled: inputField.text.length > 0 onClicked: { - fileDialog.selectedFile = characterNameField.text; + fileDialog.selectedFile = inputField.text; fileDialog.open(); } } @@ -127,7 +151,11 @@ Kirigami.ApplicationWindow { let path = selectedFile.toString(); // Remove file:// path = path.replace(/^(file:\/{2})/,""); - root.backend.archiveCharacter(characterNameField.text, dalamudCheckbox.checked, path); + if (nameAction.checked) { + root.backend.archiveCharacterByName(inputField.text, dalamudCheckbox.checked, path); + } else { + root.backend.archiveCharacterById(inputField.text, dalamudCheckbox.checked, path); + } root.lastArchiveFile = path; } } diff --git a/src/bin/auracite/bridge.rs b/src/bin/auracite/bridge.rs index d6d1e8d..008f855 100644 --- a/src/bin/auracite/bridge.rs +++ b/src/bin/auracite/bridge.rs @@ -21,13 +21,22 @@ pub mod bridge { unsafe extern "RustQt" { #[qinvokable] - #[cxx_name = "archiveCharacter"] - fn archive_character( + #[cxx_name = "archiveCharacterByName"] + fn archive_character_by_name( self: Pin<&mut Backend>, character_name: &QString, use_dalamud: bool, filename: &QString, ); + + #[qinvokable] + #[cxx_name = "archiveCharacterById"] + fn archive_character_by_id( + self: Pin<&mut Backend>, + character_id: &QString, + use_dalamud: bool, + filename: &QString, + ); } } @@ -41,7 +50,7 @@ use std::pin::Pin; pub struct BackendRust {} impl bridge::Backend { - pub fn archive_character( + pub fn archive_character_by_name( mut self: Pin<&mut Self>, character_name: &QString, use_dalamud: bool, @@ -72,4 +81,32 @@ impl bridge::Backend { } } } + + pub fn archive_character_by_id( + mut self: Pin<&mut Self>, + character_id: &QString, + use_dalamud: bool, + filename: &QString, + ) { + let id = character_id.to_string().parse().unwrap(); + match archive_character_blocking(id, use_dalamud, &filename.to_string()) { + Ok(_) => self.archive_successful(), + Err(err) => { + match err { + // TODO: Pass the URL up + ArchiveError::DownloadFailed(_) => { + self.archive_failed(&i18n("Download failed")) + } + ArchiveError::CharacterNotFound => { + self.archive_failed(&i18n("Character not found")) + } + ArchiveError::ParsingError => self.archive_failed(&i18n("Parsing error")), + ArchiveError::UnknownError => self.archive_failed(&i18n("Unknown error")), + ArchiveError::CouldNotConnectToDalamud => { + self.archive_failed(&i18n("Could not connect to Dalamud plugin")) + } + } + } + } + } }