trying to update save file on save
This commit is contained in:
parent
85f43fcc76
commit
538a001474
2 changed files with 65 additions and 14 deletions
|
@ -222,7 +222,6 @@ Kirigami.ApplicationWindow {
|
||||||
title: "Pick a Sound Effect"
|
title: "Pick a Sound Effect"
|
||||||
folder: shortcuts.home
|
folder: shortcuts.home
|
||||||
/* fileMode: FileDialog.SaveFile */
|
/* fileMode: FileDialog.SaveFile */
|
||||||
/* defaultSuffix: ".pres" */
|
|
||||||
selectExisting: true
|
selectExisting: true
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
soundEffect = loadFileDialog.fileUrl;
|
soundEffect = loadFileDialog.fileUrl;
|
||||||
|
@ -253,6 +252,8 @@ Kirigami.ApplicationWindow {
|
||||||
|
|
||||||
function save(file) {
|
function save(file) {
|
||||||
const saved = mainPage.serviceItems.save(file);
|
const saved = mainPage.serviceItems.save(file);
|
||||||
|
saved ? RSettings.setSaveFile(file)
|
||||||
|
: console.log("File: " + file + " wasn't saved");
|
||||||
saved ? showPassiveNotification("SAVED! " + file)
|
saved ? showPassiveNotification("SAVED! " + file)
|
||||||
: showPassiveNotification("FAILED!");
|
: showPassiveNotification("FAILED!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ mod settings {
|
||||||
|
|
||||||
use configparser::ini::Ini;
|
use configparser::ini::Ini;
|
||||||
use dirs;
|
use dirs;
|
||||||
|
use std::error::Error;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
unsafe extern "C++" {
|
unsafe extern "C++" {
|
||||||
include!("cxx-qt-lib/qstring.h");
|
include!("cxx-qt-lib/qstring.h");
|
||||||
|
@ -14,6 +16,8 @@ mod settings {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
#[cxx_qt::qobject]
|
#[cxx_qt::qobject]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
|
config: Ini,
|
||||||
|
|
||||||
#[qproperty]
|
#[qproperty]
|
||||||
screen: QString,
|
screen: QString,
|
||||||
#[qproperty]
|
#[qproperty]
|
||||||
|
@ -25,6 +29,7 @@ mod settings {
|
||||||
impl Default for Settings {
|
impl Default for Settings {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
config: Ini::new(),
|
||||||
screen: QString::from(""),
|
screen: QString::from(""),
|
||||||
sound_effect: QString::from(""),
|
sound_effect: QString::from(""),
|
||||||
last_save_file: QUrl::from(""),
|
last_save_file: QUrl::from(""),
|
||||||
|
@ -42,18 +47,19 @@ mod settings {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn setup(self: Pin<&mut Self>) {
|
pub fn setup(mut self: Pin<&mut Self>) {
|
||||||
let mut config = Ini::new();
|
|
||||||
let home = dirs::config_dir();
|
let home = dirs::config_dir();
|
||||||
println!("{:?}", home);
|
println!("{:?}", home);
|
||||||
if let Some(mut conf) = home {
|
if let Some(mut conf) = home {
|
||||||
conf.push("lumina");
|
conf.push("lumina");
|
||||||
conf.push("lumina.conf");
|
conf.push("lumina.conf");
|
||||||
let _map = config.load(conf);
|
match self.as_mut().config_mut().load(conf) {
|
||||||
|
Ok(map) => {
|
||||||
println!("{:?}", config);
|
// println!("{:?}", self.rust().config);
|
||||||
println!("{:?}", _map);
|
let sf = self
|
||||||
let sf = config.get("General", "lastSaveFile");
|
.as_ref()
|
||||||
|
.config()
|
||||||
|
.get("General", "lastSaveFile");
|
||||||
println!("{:?}", sf);
|
println!("{:?}", sf);
|
||||||
if let Some(s) = sf {
|
if let Some(s) = sf {
|
||||||
self.set_last_save_file(QUrl::from(&s));
|
self.set_last_save_file(QUrl::from(&s));
|
||||||
|
@ -61,9 +67,53 @@ mod settings {
|
||||||
} else {
|
} else {
|
||||||
println!("error loading last save file");
|
println!("error loading last save file");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("settings_load_error: {:?}", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("Couldn't find home directory");
|
println!("Couldn't find home directory");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[qinvokable]
|
||||||
|
pub fn set_save_file(mut self: Pin<&mut Self>, file: QUrl) {
|
||||||
|
println!("{file}");
|
||||||
|
match self.as_mut().config_mut().set(
|
||||||
|
"General",
|
||||||
|
"lastSaveFile",
|
||||||
|
Some(file.to_string()),
|
||||||
|
) {
|
||||||
|
Some(s) => {
|
||||||
|
println!(
|
||||||
|
"set-save-file: {:?}",
|
||||||
|
self.as_mut()
|
||||||
|
.config_mut()
|
||||||
|
.get("General", "lastSaveFile")
|
||||||
|
);
|
||||||
|
if let Err(e) = self.as_mut().write() {
|
||||||
|
println!("error: {:?}", e)
|
||||||
|
}
|
||||||
|
self.set_last_save_file(file);
|
||||||
|
}
|
||||||
|
_ => println!("error-setting-save-file"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write(
|
||||||
|
mut self: Pin<&mut Self>,
|
||||||
|
) -> std::io::Result<&str> {
|
||||||
|
let mut file = dirs::config_dir().unwrap();
|
||||||
|
file.push("lumina");
|
||||||
|
file.push("lumina.conf");
|
||||||
|
match self.as_mut().config_mut().write(file) {
|
||||||
|
Ok(_s) => Ok("Saved File"),
|
||||||
|
Err(e) => {
|
||||||
|
println!("error: {:?}", e);
|
||||||
|
Err(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue