1
Fork 0
mirror of https://github.com/redstrate/Auracite.git synced 2025-04-22 20:57:46 +00:00

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.
This commit is contained in:
Joshua Goins 2024-12-16 21:29:44 -05:00
parent 38eedd0477
commit fd128c3f43
3 changed files with 96 additions and 48 deletions

View file

@ -1,18 +1,48 @@
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 {
property string lastArchiveFile
property Kirigami.Action openArchiveAction: Kirigami.Action {
text: i18nc("@action:button", "Open Archive")
icon.name: "document-open"
onTriggered: Qt.openUrlExternally("file://" + root.lastArchiveFile)
}
pageStack {
defaultColumnWidth: root.width
initialPage: Kirigami.Page {
globalToolBarStyle: Kirigami.ApplicationHeaderStyle.None
header: ColumnLayout {
Kirigami.Separator {
Layout.fillWidth: true
}
Kirigami.InlineMessage {
id: messageBanner
position: Kirigami.InlineMessage.Position.Header
actions: type === Kirigami.MessageType.Information ? [openArchiveAction] : []
Layout.fillWidth: true
}
}
contentItem: ColumnLayout {
anchors {
left: parent.left
@ -46,7 +76,11 @@ Kirigami.ApplicationWindow {
FormCard.FormButtonDelegate {
id: loginButton
text: i18nc("@action:button", "Archive")
onClicked: root.backend.archiveCharacter(characterNameField.text, dalamudCheckbox.checked)
enabled: characterNameField.text.length > 0
onClicked: {
fileDialog.selectedFile = characterNameField.text;
fileDialog.open();
}
}
}
@ -59,11 +93,7 @@ Kirigami.ApplicationWindow {
id: aboutButton
text: i18nc("@action:button Application settings", "Settings")
icon.name: "settings-configure"
onClicked: applicationWindow().pageStack.layers.push(aboutPage)
Component {
id: aboutPage
FormCard.AboutPage {}
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;
}
}
}

View file

@ -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 {

View file

@ -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;
}