From 5163a393179824c9696d902d4ae2994692ceefc9 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Wed, 11 Oct 2023 11:09:07 -0500 Subject: [PATCH] attempting to switch to new version of cxx-qt to try newer api --- Cargo.lock | 86 +++++++------- Cargo.toml | 10 +- build.rs | 2 +- src/rust/lib.rs | 2 +- src/rust/service_item_model.rs | 27 +++-- src/rust/settings.rs | 204 +++++++++++++++++---------------- 6 files changed, 170 insertions(+), 161 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ca5bc27..0ede124 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -353,12 +353,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clang-format" -version = "0.1.3" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c6a49aa81aee4ac71d780395eb37788414b1fdb85033b52b5f13e80cd6b9f4a" -dependencies = [ - "once_cell", -] +checksum = "88dfe5eb75e066e696abfca68fb70db71236441b7335975ecf79caf0875e3175" [[package]] name = "codespan-reporting" @@ -465,9 +462,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.94" +version = "1.0.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f61f1b6389c3fe1c316bf8a4dccc90a38208354b330925bce1f74a6c4756eb93" +checksum = "292b4841d939b20ba44fff686a35808b0ab31a3256e3629917d9aedd43eb7b3a" dependencies = [ "cc", "cxxbridge-flags", @@ -477,9 +474,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.94" +version = "1.0.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12cee708e8962df2aeb38f594aae5d827c022b6460ac71a7a3e2c3c2aae5a07b" +checksum = "5c0c11acd0e63bae27dcd2afced407063312771212b7a823b4fd72d633be30fb" dependencies = [ "cc", "codespan-reporting", @@ -492,9 +489,9 @@ dependencies = [ [[package]] name = "cxx-gen" -version = "0.7.94" +version = "0.7.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee165c38de64e6761c2f38b7e9beee0721110f8585165987ef9db2a753ee4176" +checksum = "e3e3046e039458644430340593c4b0e175c240f9a9aee09c20786db994abf62b" dependencies = [ "codespan-reporting", "proc-macro2", @@ -505,21 +502,19 @@ dependencies = [ [[package]] name = "cxx-qt" version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2002fa000d687f8cf21abce76d85d4eceef638dcd2a146dc3f61b47e67d89220" +source = "git+https://github.com/KDAB/cxx-qt#83a82685e3c289458614de4bc54678e5face8874" dependencies = [ - "cxx-qt-gen", - "proc-macro2", - "syn 1.0.109", + "cxx", + "cxx-qt-macro", ] [[package]] name = "cxx-qt-build" version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e83a15e8f8f39677d2f9e62850bb79218db25d7a352b0f2134932bf5eb3fdff2" +source = "git+https://github.com/KDAB/cxx-qt#83a82685e3c289458614de4bc54678e5face8874" dependencies = [ "cc", + "codespan-reporting", "convert_case", "cxx-gen", "cxx-qt-gen", @@ -527,27 +522,26 @@ dependencies = [ "proc-macro2", "qt-build-utils", "quote", + "version_check", ] [[package]] name = "cxx-qt-gen" version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "389cd0e44b265d2a23124006c2100571040bda5c0b74e98e9a3740f9abf309db" +source = "git+https://github.com/KDAB/cxx-qt#83a82685e3c289458614de4bc54678e5face8874" dependencies = [ "clang-format", "convert_case", "indoc", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.28", ] [[package]] name = "cxx-qt-lib" version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cee7ccaf5fc9f0a4562aae0dcd387756dda0772571e0b9d0f255f542a970b50" +source = "git+https://github.com/KDAB/cxx-qt#83a82685e3c289458614de4bc54678e5face8874" dependencies = [ "cxx", "cxx-build", @@ -558,20 +552,29 @@ dependencies = [ [[package]] name = "cxx-qt-lib-headers" version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7fa7bf31bd520d00536d27b9e26a265a1cba6d84ec544175f254c755406110c" +source = "git+https://github.com/KDAB/cxx-qt#83a82685e3c289458614de4bc54678e5face8874" + +[[package]] +name = "cxx-qt-macro" +version = "0.5.3" +source = "git+https://github.com/KDAB/cxx-qt#83a82685e3c289458614de4bc54678e5face8874" +dependencies = [ + "cxx-qt-gen", + "proc-macro2", + "syn 2.0.28", +] [[package]] name = "cxxbridge-flags" -version = "1.0.94" +version = "1.0.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7944172ae7e4068c533afbb984114a56c46e9ccddda550499caa222902c7f7bb" +checksum = "d7030aff1908ba2b7eb639466df50792b2a3fdf02bea9557c4ee1a531975554b" [[package]] name = "cxxbridge-macro" -version = "1.0.94" +version = "1.0.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5" +checksum = "79418ecb0c2322a7926a5fa5a9660535432b5b3588b947e1eb484cc509edbe3c" dependencies = [ "proc-macro2", "quote", @@ -1073,15 +1076,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "itertools" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", -] - [[package]] name = "itertools" version = "0.11.0" @@ -1187,9 +1181,9 @@ dependencies = [ [[package]] name = "link-cplusplus" -version = "1.0.8" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" +checksum = "9d240c6f7e1ba3a28b0249f774e6a9dd0175054b52dfbb61b16eb8505c3785c9" dependencies = [ "cc", ] @@ -1640,9 +1634,9 @@ dependencies = [ [[package]] name = "qt-build-utils" version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5ce806205819a87696bb9275c831be88a79592f035d4cc17d01625395cbe1da" +source = "git+https://github.com/KDAB/cxx-qt#83a82685e3c289458614de4bc54678e5face8874" dependencies = [ + "cc", "thiserror", "versions", ] @@ -2040,7 +2034,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b7b278788e7be4d0d29c0f39497a0eef3fba6bbc8e70d8bf7fde46edeaa9e85" dependencies = [ - "itertools 0.11.0", + "itertools", "nom", "unicode_categories", ] @@ -2634,11 +2628,11 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "versions" -version = "4.1.0" +version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee97e1d97bd593fb513912a07691b742361b3dd64ad56f2c694ea2dbfe0665d3" +checksum = "c73a36bc44e3039f51fbee93e39f41225f6b17b380eb70cc2aab942df06b34dd" dependencies = [ - "itertools 0.10.5", + "itertools", "nom", ] diff --git a/Cargo.toml b/Cargo.toml index 2859c3a..90a5d62 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,9 +18,9 @@ configparser = "3.0.2" serde = "1.0.152" serde_derive = "1.0.152" quote = "1.0.27" -cxx = "1.0.83" -cxx-qt = "0.5.3" -cxx-qt-lib = "0.5.3" +cxx = "1.0.95" +cxx-qt = { git = "https://github.com/KDAB/cxx-qt" } +cxx-qt-lib = { git = "https://github.com/KDAB/cxx-qt" } # home = "0.5.4" dirs = "5.0.0" diesel = { version = "2.0.3", features = ["sqlite"] } @@ -42,8 +42,8 @@ time = { version = "0.3.29", features = ["formatting", "macros"] } # cxx-qt-build generates C++ code from the `#[cxx_qt::bridge]` module # and compiles it together with the Rust static library [build-dependencies] -cxx-qt-build = "0.5.3" -qt-build-utils = "0.5.3" +cxx-qt-build = { git = "https://github.com/KDAB/cxx-qt" } +qt-build-utils = { git = "https://github.com/KDAB/cxx-qt" } # [dependencies.confy] # features = ["yaml_conf"] diff --git a/build.rs b/build.rs index ee5f750..bb4d786 100644 --- a/build.rs +++ b/build.rs @@ -2,7 +2,7 @@ use cxx_qt_build::CxxQtBuilder; fn main() { CxxQtBuilder::new() - .file("src/rust/service_thing.rs") + // .file("src/rust/service_thing.rs") .file("src/rust/settings.rs") .file("src/rust/file_helper.rs") .file("src/rust/slide_obj.rs") diff --git a/src/rust/lib.rs b/src/rust/lib.rs index 23e5aa0..11ee6e4 100644 --- a/src/rust/lib.rs +++ b/src/rust/lib.rs @@ -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; diff --git a/src/rust/service_item_model.rs b/src/rust/service_item_model.rs index 3302bbd..1646c38 100644 --- a/src/rust/service_item_model.rs +++ b/src/rust/service_item_model.rs @@ -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, diff --git a/src/rust/settings.rs b/src/rust/settings.rs index 0b5e0ba..12ab68f 100644 --- a/src/rust/settings.rs +++ b/src/rust/settings.rs @@ -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) + } } } }