From fd128c3f435726b7660394a8898d1190302c8a72 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Mon, 16 Dec 2024 21:29:44 -0500 Subject: [PATCH] Improve the desktop UI You can now select where to save the character archive. Errors and other information is passed up to the UI, and the page stack is improved a bit. --- src/bin/auracite/Main.qml | 132 +++++++++++++++++++++++++------------ src/bin/auracite/bridge.rs | 6 +- src/bin/auracite/main.rs | 6 +- 3 files changed, 96 insertions(+), 48 deletions(-) diff --git a/src/bin/auracite/Main.qml b/src/bin/auracite/Main.qml index 5334810..1d2a52b 100644 --- a/src/bin/auracite/Main.qml +++ b/src/bin/auracite/Main.qml @@ -1,69 +1,99 @@ +import QtCore import QtQuick import QtQuick.Layouts +import QtQuick.Dialogs import QtQuick.Controls as QQC2 + import org.kde.kirigami as Kirigami import org.kde.kirigamiaddons.formcard as FormCard + import zone.xiv.auracite Kirigami.ApplicationWindow { id: root - title: "Auracite" - readonly property Backend backend: Backend {} - pageStack.initialPage: Kirigami.Page { - contentItem: ColumnLayout { - anchors { - left: parent.left - right: parent.right - verticalCenter: parent.verticalCenter - } + property string lastArchiveFile - spacing: Kirigami.Units.largeSpacing + property Kirigami.Action openArchiveAction: Kirigami.Action { + text: i18nc("@action:button", "Open Archive") + icon.name: "document-open" + onTriggered: Qt.openUrlExternally("file://" + root.lastArchiveFile) + } - FormCard.FormCard { - Layout.topMargin: Kirigami.Units.largeSpacing + pageStack { + defaultColumnWidth: root.width - maximumWidth: Kirigami.Units.gridUnit * 20 + initialPage: Kirigami.Page { + globalToolBarStyle: Kirigami.ApplicationHeaderStyle.None - FormCard.FormTextFieldDelegate { - id: characterNameField - label: i18n("Character Name") - placeholderText: "Full name of the character" - focus: true + header: ColumnLayout { + Kirigami.Separator { + Layout.fillWidth: true } - FormCard.FormDelegateSeparator {} + Kirigami.InlineMessage { + id: messageBanner - FormCard.FormCheckDelegate { - id: dalamudCheckbox - text: i18n("Use Dalamud Plugin") - } + position: Kirigami.InlineMessage.Position.Header + actions: type === Kirigami.MessageType.Information ? [openArchiveAction] : [] - FormCard.FormDelegateSeparator {} - - FormCard.FormButtonDelegate { - id: loginButton - text: i18nc("@action:button", "Archive") - onClicked: root.backend.archiveCharacter(characterNameField.text, dalamudCheckbox.checked) + Layout.fillWidth: true } } - FormCard.FormCard { - Layout.topMargin: Kirigami.Units.largeSpacing + contentItem: ColumnLayout { + anchors { + left: parent.left + right: parent.right + verticalCenter: parent.verticalCenter + } - maximumWidth: Kirigami.Units.gridUnit * 20 + spacing: Kirigami.Units.largeSpacing - FormCard.FormButtonDelegate { - id: aboutButton - text: i18nc("@action:button Application settings", "Settings") - icon.name: "settings-configure" - onClicked: applicationWindow().pageStack.layers.push(aboutPage) + FormCard.FormCard { + Layout.topMargin: Kirigami.Units.largeSpacing - Component { - id: aboutPage - FormCard.AboutPage {} + maximumWidth: Kirigami.Units.gridUnit * 20 + + FormCard.FormTextFieldDelegate { + id: characterNameField + label: i18n("Character Name") + placeholderText: "Full name of the character" + focus: true + } + + FormCard.FormDelegateSeparator {} + + FormCard.FormCheckDelegate { + id: dalamudCheckbox + text: i18n("Use Dalamud Plugin") + } + + FormCard.FormDelegateSeparator {} + + FormCard.FormButtonDelegate { + id: loginButton + text: i18nc("@action:button", "Archive") + enabled: characterNameField.text.length > 0 + onClicked: { + fileDialog.selectedFile = characterNameField.text; + fileDialog.open(); + } + } + } + + FormCard.FormCard { + Layout.topMargin: Kirigami.Units.largeSpacing + + maximumWidth: Kirigami.Units.gridUnit * 20 + + FormCard.FormButtonDelegate { + id: aboutButton + text: i18nc("@action:button Application settings", "Settings") + icon.name: "settings-configure" + onClicked: applicationWindow().pageStack.push(Qt.createComponent("org.kde.kirigamiaddons.formcard", "AboutPage")) } } } @@ -74,11 +104,29 @@ Kirigami.ApplicationWindow { target: backend function onArchiveSuccessful(): void { - console.info("Archive done!"); + messageBanner.type = Kirigami.MessageType.Information; + messageBanner.text = i18n("Archive completed!"); + messageBanner.visible = true; } function onArchiveFailed(message: string): void { - console.error("Failed: " + message); + messageBanner.type = Kirigami.MessageType.Error; + messageBanner.text = message; + messageBanner.visible = true; + } + } + + FileDialog { + id: fileDialog + fileMode: FileDialog.SaveFile + nameFilters: ["ZIP files (*.zip)"] + currentFolder: StandardPaths.standardLocations(StandardPaths.DocumentsLocation)[0] + onAccepted: { + let path = selectedFile.toString(); + // Remove file:// + path = path.replace(/^(file:\/{2})/,""); + root.backend.archiveCharacter(characterNameField.text, dalamudCheckbox.checked, path); + root.lastArchiveFile = path; } } } \ No newline at end of file diff --git a/src/bin/auracite/bridge.rs b/src/bin/auracite/bridge.rs index 0969870..74da90b 100644 --- a/src/bin/auracite/bridge.rs +++ b/src/bin/auracite/bridge.rs @@ -22,7 +22,7 @@ pub mod bridge { unsafe extern "RustQt" { #[qinvokable] #[cxx_name = "archiveCharacter"] - fn archive_character(self: Pin<&mut Backend>, character_name: &QString, use_dalamud: bool); + fn archive_character(self: Pin<&mut Backend>, character_name: &QString, use_dalamud: bool, filename: &QString); } } @@ -37,8 +37,8 @@ pub struct BackendRust { } impl bridge::Backend { - pub fn archive_character(mut self: Pin<&mut Self>, character_name: &QString, use_dalamud: bool) { - match archive_character_blocking(&character_name.to_string(), use_dalamud) { + pub fn archive_character(mut self: Pin<&mut Self>, character_name: &QString, use_dalamud: bool, filename: &QString) { + match archive_character_blocking(&character_name.to_string(), use_dalamud, &filename.to_string()) { Ok(_) => { self.archive_successful() } Err(err) => { match err { diff --git a/src/bin/auracite/main.rs b/src/bin/auracite/main.rs index 78ea626..74f628b 100644 --- a/src/bin/auracite/main.rs +++ b/src/bin/auracite/main.rs @@ -8,14 +8,14 @@ use auracite::{archive_character, ArchiveError}; pub mod bridge; -fn archive_character_blocking(character_name: &String, use_dalamud: bool) -> Result<(), ArchiveError> { +fn archive_character_blocking(character_name: &String, use_dalamud: bool, filename: &String) -> Result<(), ArchiveError> { let rt = tokio::runtime::Builder::new_current_thread() .enable_all() .build() .map_err(|_| ArchiveError::UnknownError)?; let inner = rt.block_on(archive_character(&character_name.to_string(), use_dalamud))?; - write("/home/josh/test.zip", inner)?; + write(filename, inner)?; Ok(()) } @@ -70,7 +70,7 @@ fn main() { println!("Downloading character data for {}...", character_name); - archive_character_blocking(&character_name, command_line_parser.is_set(&QString::from("dalamud"))); + archive_character_blocking(&character_name, command_line_parser.is_set(&QString::from("dalamud")), &format!("{}.zip", character_name)); return; }