basic updates to make cxx-qt work with 6.0
This commit is contained in:
parent
6b3559b4ef
commit
5d571a7e6f
2 changed files with 171 additions and 170 deletions
|
@ -1,7 +1,5 @@
|
||||||
#[cxx_qt::bridge]
|
#[cxx_qt::bridge]
|
||||||
mod service_thing {
|
mod service_thing {
|
||||||
use cxx_qt_lib::QVariantValue;
|
|
||||||
|
|
||||||
unsafe extern "C++" {
|
unsafe extern "C++" {
|
||||||
include!("cxx-qt-lib/qstring.h");
|
include!("cxx-qt-lib/qstring.h");
|
||||||
type QString = cxx_qt_lib::QString;
|
type QString = cxx_qt_lib::QString;
|
||||||
|
@ -9,75 +7,73 @@ mod service_thing {
|
||||||
type QVariant = cxx_qt_lib::QVariant;
|
type QVariant = cxx_qt_lib::QVariant;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
unsafe extern "RustQt" {
|
||||||
#[cxx_qt::qobject]
|
#[qobject]
|
||||||
pub struct ServiceThing {
|
#[qml_element]
|
||||||
#[qproperty]
|
#[qproperty(QString, name)]
|
||||||
name: QString,
|
#[qproperty(QString, kind)]
|
||||||
#[qproperty]
|
#[qproperty(QString, background)]
|
||||||
kind: QString,
|
#[qproperty(QString, background_type)]
|
||||||
#[qproperty]
|
#[qproperty(QString, text)]
|
||||||
background: QString,
|
#[qproperty(QString, audio)]
|
||||||
#[qproperty]
|
#[qproperty(QString, font)]
|
||||||
background_type: QString,
|
#[qproperty(QString, font_size)]
|
||||||
#[qproperty]
|
#[qproperty(bool, active)]
|
||||||
text: QString,
|
#[qproperty(bool, selected)]
|
||||||
#[qproperty]
|
type ServiceThing = super::ServiceThingRust;
|
||||||
audio: QString,
|
|
||||||
#[qproperty]
|
|
||||||
font: QString,
|
|
||||||
#[qproperty]
|
|
||||||
font_size: QString,
|
|
||||||
#[qproperty]
|
|
||||||
active: bool,
|
|
||||||
#[qproperty]
|
|
||||||
selected: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for ServiceThing {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
name: QString::from(""),
|
|
||||||
kind: QString::from(""),
|
|
||||||
background: QString::from(""),
|
|
||||||
background_type: QString::from(""),
|
|
||||||
text: QString::from(""),
|
|
||||||
audio: QString::from(""),
|
|
||||||
font: QString::from(""),
|
|
||||||
font_size: QString::from(""),
|
|
||||||
active: false,
|
|
||||||
selected: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl qobject::ServiceThing {
|
|
||||||
#[qinvokable]
|
|
||||||
pub fn activate(self: Pin<&mut Self>) {
|
|
||||||
println!("{}", self.active());
|
|
||||||
let active: bool = *self.active();
|
|
||||||
self.set_active(!active);
|
|
||||||
println!("{}", !active);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn check_active(self: Pin<&mut Self>) {
|
fn activate(self: Pin<&mut ServiceThing>);
|
||||||
println!("Are we active?: {}", self.active());
|
|
||||||
}
|
|
||||||
|
|
||||||
// #[qinvokable]
|
#[qinvokable]
|
||||||
// pub fn slap_variant_around(self: Pin<&mut Self>, variant: &QVariant) {
|
fn check_active(self: Pin<&mut ServiceThing>);
|
||||||
// println!("wow!");
|
}
|
||||||
// let sname: String;
|
}
|
||||||
// match variant.value() {
|
|
||||||
// QVariantValue::QString(string) => {
|
use cxx_qt_lib::QString;
|
||||||
// let nstr = string.to_string();
|
|
||||||
// self.set_name(QString::from(nstr.as_str()));
|
#[derive(Clone)]
|
||||||
// sname = nstr;
|
pub struct ServiceThingRust {
|
||||||
// println!("New name is: {}", sname);
|
name: QString,
|
||||||
// }
|
kind: QString,
|
||||||
// _ => println!("Unknown QVariant type"),
|
background: QString,
|
||||||
// };
|
background_type: QString,
|
||||||
// }
|
text: QString,
|
||||||
|
audio: QString,
|
||||||
|
font: QString,
|
||||||
|
font_size: QString,
|
||||||
|
active: bool,
|
||||||
|
selected: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ServiceThingRust {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
name: QString::from(""),
|
||||||
|
kind: QString::from(""),
|
||||||
|
background: QString::from(""),
|
||||||
|
background_type: QString::from(""),
|
||||||
|
text: QString::from(""),
|
||||||
|
audio: QString::from(""),
|
||||||
|
font: QString::from(""),
|
||||||
|
font_size: QString::from(""),
|
||||||
|
active: false,
|
||||||
|
selected: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl qobject::ServiceThing {
|
||||||
|
#[qinvokable]
|
||||||
|
pub fn activate(self: Pin<&mut Self>) {
|
||||||
|
println!("{}", self.active());
|
||||||
|
let active: bool = *self.active();
|
||||||
|
self.set_active(!active);
|
||||||
|
println!("{}", !active);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[qinvokable]
|
||||||
|
pub fn check_active(self: Pin<&mut Self>) {
|
||||||
|
println!("Are we active?: {}", self.active());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
#[cxx_qt::bridge]
|
#[cxx_qt::bridge]
|
||||||
mod settings {
|
mod settings {
|
||||||
|
|
||||||
use configparser::ini::Ini;
|
|
||||||
use dirs;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
unsafe extern "C++" {
|
unsafe extern "C++" {
|
||||||
include!("cxx-qt-lib/qstring.h");
|
include!("cxx-qt-lib/qstring.h");
|
||||||
type QString = cxx_qt_lib::QString;
|
type QString = cxx_qt_lib::QString;
|
||||||
|
@ -12,115 +7,125 @@ mod settings {
|
||||||
type QUrl = cxx_qt_lib::QUrl;
|
type QUrl = cxx_qt_lib::QUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// In order for settings to save to the ini file,
|
unsafe extern "RustQt" {
|
||||||
// I'll need to create my own setting functions I think.
|
#[qobject]
|
||||||
#[derive(Clone)]
|
#[qml_element]
|
||||||
#[cxx_qt::qobject]
|
#[qproperty(QString, screen)]
|
||||||
pub struct Settings {
|
#[qproperty(QString, sound_effect)]
|
||||||
config: Ini,
|
#[qproperty(QUrl, last_save_file)]
|
||||||
|
#[qproperty(QUrl, loaded_file)]
|
||||||
#[qproperty]
|
type Settings = super::SettingsRust;
|
||||||
screen: QString,
|
|
||||||
#[qproperty]
|
|
||||||
sound_effect: QString,
|
|
||||||
#[qproperty]
|
|
||||||
last_save_file: QUrl,
|
|
||||||
#[qproperty]
|
|
||||||
loaded_file: QUrl,
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for Settings {
|
use configparser::ini::Ini;
|
||||||
fn default() -> Self {
|
use dirs;
|
||||||
Self {
|
use std::path::PathBuf;
|
||||||
config: Ini::new(),
|
|
||||||
screen: QString::from(""),
|
// In order for settings to save to the ini file,
|
||||||
sound_effect: QString::from(""),
|
// I'll need to create my own setting functions I think.
|
||||||
last_save_file: QUrl::from(""),
|
#[derive(Clone)]
|
||||||
loaded_file: QUrl::from(""),
|
pub struct SettingsRust {
|
||||||
}
|
config: Ini,
|
||||||
|
|
||||||
|
#[qproperty]
|
||||||
|
screen: QString,
|
||||||
|
#[qproperty]
|
||||||
|
sound_effect: QString,
|
||||||
|
#[qproperty]
|
||||||
|
last_save_file: QUrl,
|
||||||
|
#[qproperty]
|
||||||
|
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 {
|
impl qobject::Settings {
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn print_sound(self: Pin<&mut Self>) {
|
pub fn print_sound(self: Pin<&mut Self>) {
|
||||||
let mut config = Ini::new();
|
let mut config = Ini::new();
|
||||||
let _map = config.load("~/.config/lumina/lumina.conf");
|
let _map = config.load("~/.config/lumina/lumina.conf");
|
||||||
|
|
||||||
println!("{}", self.sound_effect());
|
println!("{}", self.sound_effect());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn setup(mut self: Pin<&mut Self>) {
|
pub fn setup(mut self: Pin<&mut Self>) {
|
||||||
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");
|
||||||
match self.as_mut().config_mut().load(conf) {
|
match self.as_mut().config_mut().load(conf) {
|
||||||
Ok(map) => {
|
Ok(map) => {
|
||||||
// println!("{:?}", self.rust().config);
|
// println!("{:?}", self.rust().config);
|
||||||
let sf = self
|
let sf = self
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.config()
|
.config()
|
||||||
.get("General", "lastSaveFile");
|
.get("General", "lastSaveFile");
|
||||||
println!("{:?}", sf);
|
println!("{:?}", sf);
|
||||||
if let Some(s) = 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: {:?}",
|
|
||||||
self.as_mut()
|
self.as_mut()
|
||||||
.config_mut()
|
.set_last_save_file(QUrl::from(&s));
|
||||||
.get("General", "lastSaveFile")
|
self.as_mut().set_loaded_file(QUrl::from(&s));
|
||||||
);
|
println!("{s}");
|
||||||
if let Err(e) = self.as_mut().write() {
|
} else {
|
||||||
println!("error: {:?}", e)
|
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) => {
|
Err(e) => {
|
||||||
println!("error: {:?}", e);
|
println!("settings_load_error: {:?}", e)
|
||||||
Err(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: {:?}",
|
||||||
|
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