attempting to switch to new version of cxx-qt to try newer api
This commit is contained in:
parent
d82a0ac503
commit
5163a39317
6 changed files with 170 additions and 161 deletions
|
@ -6,7 +6,7 @@ pub mod presentation_model;
|
|||
pub mod reveal_js;
|
||||
pub mod schema;
|
||||
mod service_item_model;
|
||||
mod service_thing;
|
||||
// mod service_thing;
|
||||
pub mod settings;
|
||||
pub mod slide_model;
|
||||
mod slide_obj;
|
||||
|
|
|
@ -24,6 +24,13 @@ mod service_item_model {
|
|||
type QUrl = cxx_qt_lib::QUrl;
|
||||
}
|
||||
|
||||
// extern "RustQt" {
|
||||
// #[qobject]
|
||||
// #[base = "QAbstractListModel"]
|
||||
// #[qml_element]
|
||||
// type ServiceItemModel = super::ServiceItemMod;
|
||||
// }
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[cxx_qt::qobject]
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -1130,15 +1137,6 @@ mod service_item_model {
|
|||
);
|
||||
|
||||
// cxx-qt can't build this function for some reason
|
||||
// unsafe fn begin_move_rows(
|
||||
// self: Pin<&mut qobject::ServiceItemMod>,
|
||||
// source_parent: &QModelIndex,
|
||||
// source_first: i32,
|
||||
// source_last: i32,
|
||||
// destination_parent: &QModelIndex,
|
||||
// destination_child: i32,
|
||||
// );
|
||||
|
||||
unsafe fn end_move_rows(
|
||||
self: Pin<&mut qobject::ServiceItemMod>,
|
||||
);
|
||||
|
@ -1169,6 +1167,17 @@ mod service_item_model {
|
|||
parent: &QModelIndex,
|
||||
) -> bool;
|
||||
|
||||
#[cxx_name = "beginMoveRows"]
|
||||
fn begin_move_rows(
|
||||
self: Pin<&mut qobject::ServiceItemMod>,
|
||||
#[cxx_name = "sourceParent"] source_parent: &QModelIndex,
|
||||
#[cxx_name = "sourceFirst"] source_first: i32,
|
||||
#[cxx_name = "sourceLast"] source_last: i32,
|
||||
#[cxx_name = "destinationParent"]
|
||||
destination_parent: &QModelIndex,
|
||||
#[cxx_name = "desitnationChild"] destination_child: i32,
|
||||
);
|
||||
|
||||
fn index(
|
||||
self: &qobject::ServiceItemMod,
|
||||
row: i32,
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
#[cxx_qt::bridge]
|
||||
mod settings {
|
||||
|
||||
use configparser::ini::Ini;
|
||||
use dirs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
unsafe extern "C++" {
|
||||
include!("cxx-qt-lib/qstring.h");
|
||||
type QString = cxx_qt_lib::QString;
|
||||
|
@ -12,115 +8,125 @@ mod settings {
|
|||
type QUrl = cxx_qt_lib::QUrl;
|
||||
}
|
||||
|
||||
// In order for settings to save to the ini file,
|
||||
// I'll need to create my own setting functions I think.
|
||||
#[derive(Clone)]
|
||||
#[cxx_qt::qobject]
|
||||
pub struct Settings {
|
||||
config: Ini,
|
||||
unsafe extern "RustQt" {
|
||||
#[qobject]
|
||||
#[qml_element]
|
||||
#[qproperty(QString, screen)]
|
||||
#[qproperty(QString, sound_effect)]
|
||||
#[qproperty(QUrl, last_save_file)]
|
||||
#[qproperty(QUrl, loaded_file)]
|
||||
type Settings = super::SettingsRust;
|
||||
|
||||
#[qinvokable]
|
||||
fn print_sound(self: Pin<&mut Settings>);
|
||||
#[qinvokable]
|
||||
fn setup(self: Pin<&mut Settings>);
|
||||
#[qinvokable]
|
||||
fn set_save_file(self: Pin<&mut Settings>, file: QUrl);
|
||||
|
||||
#[qproperty]
|
||||
screen: QString,
|
||||
#[qproperty]
|
||||
sound_effect: QString,
|
||||
#[qproperty]
|
||||
last_save_file: QUrl,
|
||||
#[qproperty]
|
||||
loaded_file: QUrl,
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Settings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
config: Ini::new(),
|
||||
screen: QString::from(""),
|
||||
sound_effect: QString::from(""),
|
||||
last_save_file: QUrl::from(""),
|
||||
loaded_file: QUrl::from(""),
|
||||
}
|
||||
use configparser::ini::Ini;
|
||||
use dirs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
// In order for settings to save to the ini file,
|
||||
// I'll need to create my own setting functions I think.
|
||||
#[derive(Clone)]
|
||||
pub struct SettingsRust {
|
||||
config: Ini,
|
||||
screen: QString,
|
||||
sound_effect: QString,
|
||||
last_save_file: QUrl,
|
||||
loaded_file: QUrl,
|
||||
}
|
||||
|
||||
impl Default for SettingsRust {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
config: Ini::new(),
|
||||
screen: QString::from(""),
|
||||
sound_effect: QString::from(""),
|
||||
last_save_file: QUrl::from(""),
|
||||
loaded_file: QUrl::from(""),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl qobject::Settings {
|
||||
#[qinvokable]
|
||||
pub fn print_sound(self: Pin<&mut Self>) {
|
||||
let mut config = Ini::new();
|
||||
let _map = config.load("~/.config/lumina/lumina.conf");
|
||||
impl ffi::SettingsRust {
|
||||
pub fn print_sound(self: Pin<&mut Self>) {
|
||||
let mut config = Ini::new();
|
||||
let _map = config.load("~/.config/lumina/lumina.conf");
|
||||
|
||||
println!("{}", self.sound_effect());
|
||||
}
|
||||
println!("{}", self.sound_effect());
|
||||
}
|
||||
|
||||
#[qinvokable]
|
||||
pub fn setup(mut self: Pin<&mut Self>) {
|
||||
let home = dirs::config_dir();
|
||||
println!("{:?}", home);
|
||||
if let Some(mut conf) = home {
|
||||
conf.push("lumina");
|
||||
conf.push("lumina.conf");
|
||||
match self.as_mut().config_mut().load(conf) {
|
||||
Ok(map) => {
|
||||
// println!("{:?}", self.rust().config);
|
||||
let sf = self
|
||||
.as_ref()
|
||||
.config()
|
||||
.get("General", "lastSaveFile");
|
||||
println!("{:?}", sf);
|
||||
if let Some(s) = sf {
|
||||
self.as_mut()
|
||||
.set_last_save_file(QUrl::from(&s));
|
||||
self.as_mut()
|
||||
.set_loaded_file(QUrl::from(&s));
|
||||
println!("{s}");
|
||||
} else {
|
||||
println!("error loading last save file");
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("settings_load_error: {:?}", e)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
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: {:?}",
|
||||
pub fn setup(mut self: Pin<&mut Self>) {
|
||||
let home = dirs::config_dir();
|
||||
println!("{:?}", home);
|
||||
if let Some(mut conf) = home {
|
||||
conf.push("lumina");
|
||||
conf.push("lumina.conf");
|
||||
match self.as_mut().config_mut().load(conf) {
|
||||
Ok(map) => {
|
||||
// println!("{:?}", self.rust().config);
|
||||
let sf = self
|
||||
.as_ref()
|
||||
.config()
|
||||
.get("General", "lastSaveFile");
|
||||
println!("{:?}", sf);
|
||||
if let Some(s) = sf {
|
||||
self.as_mut()
|
||||
.config_mut()
|
||||
.get("General", "lastSaveFile")
|
||||
);
|
||||
if let Err(e) = self.as_mut().write() {
|
||||
println!("error: {:?}", e)
|
||||
.set_last_save_file(QUrl::from(&s));
|
||||
self.as_mut().set_loaded_file(QUrl::from(&s));
|
||||
println!("{s}");
|
||||
} else {
|
||||
println!("error loading last save file");
|
||||
}
|
||||
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)
|
||||
println!("settings_load_error: {:?}", e)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
println!("Couldn't find home directory");
|
||||
}
|
||||
}
|
||||
|
||||
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