From 9a08c6630c02ed902e1cd8b386e29baaf36ff1d9 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Wed, 11 Oct 2023 20:23:39 +0000 Subject: [PATCH] Revert "attempting to switch to new version of cxx-qt to try newer api" This reverts commit 5163a393179824c9696d902d4ae2994692ceefc9 --- 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 | 206 ++++++++++++++++----------------- 6 files changed, 162 insertions(+), 171 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0ede124..ca5bc27 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -353,9 +353,12 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clang-format" -version = "0.2.0" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88dfe5eb75e066e696abfca68fb70db71236441b7335975ecf79caf0875e3175" +checksum = "3c6a49aa81aee4ac71d780395eb37788414b1fdb85033b52b5f13e80cd6b9f4a" +dependencies = [ + "once_cell", +] [[package]] name = "codespan-reporting" @@ -462,9 +465,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.108" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "292b4841d939b20ba44fff686a35808b0ab31a3256e3629917d9aedd43eb7b3a" +checksum = "f61f1b6389c3fe1c316bf8a4dccc90a38208354b330925bce1f74a6c4756eb93" dependencies = [ "cc", "cxxbridge-flags", @@ -474,9 +477,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.97" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c0c11acd0e63bae27dcd2afced407063312771212b7a823b4fd72d633be30fb" +checksum = "12cee708e8962df2aeb38f594aae5d827c022b6460ac71a7a3e2c3c2aae5a07b" dependencies = [ "cc", "codespan-reporting", @@ -489,9 +492,9 @@ dependencies = [ [[package]] name = "cxx-gen" -version = "0.7.108" +version = "0.7.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3e3046e039458644430340593c4b0e175c240f9a9aee09c20786db994abf62b" +checksum = "ee165c38de64e6761c2f38b7e9beee0721110f8585165987ef9db2a753ee4176" dependencies = [ "codespan-reporting", "proc-macro2", @@ -502,19 +505,21 @@ dependencies = [ [[package]] name = "cxx-qt" version = "0.5.3" -source = "git+https://github.com/KDAB/cxx-qt#83a82685e3c289458614de4bc54678e5face8874" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2002fa000d687f8cf21abce76d85d4eceef638dcd2a146dc3f61b47e67d89220" dependencies = [ - "cxx", - "cxx-qt-macro", + "cxx-qt-gen", + "proc-macro2", + "syn 1.0.109", ] [[package]] name = "cxx-qt-build" version = "0.5.3" -source = "git+https://github.com/KDAB/cxx-qt#83a82685e3c289458614de4bc54678e5face8874" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e83a15e8f8f39677d2f9e62850bb79218db25d7a352b0f2134932bf5eb3fdff2" dependencies = [ "cc", - "codespan-reporting", "convert_case", "cxx-gen", "cxx-qt-gen", @@ -522,26 +527,27 @@ dependencies = [ "proc-macro2", "qt-build-utils", "quote", - "version_check", ] [[package]] name = "cxx-qt-gen" version = "0.5.3" -source = "git+https://github.com/KDAB/cxx-qt#83a82685e3c289458614de4bc54678e5face8874" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389cd0e44b265d2a23124006c2100571040bda5c0b74e98e9a3740f9abf309db" dependencies = [ "clang-format", "convert_case", "indoc", "proc-macro2", "quote", - "syn 2.0.28", + "syn 1.0.109", ] [[package]] name = "cxx-qt-lib" version = "0.5.3" -source = "git+https://github.com/KDAB/cxx-qt#83a82685e3c289458614de4bc54678e5face8874" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cee7ccaf5fc9f0a4562aae0dcd387756dda0772571e0b9d0f255f542a970b50" dependencies = [ "cxx", "cxx-build", @@ -552,29 +558,20 @@ dependencies = [ [[package]] name = "cxx-qt-lib-headers" version = "0.5.3" -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", -] +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7fa7bf31bd520d00536d27b9e26a265a1cba6d84ec544175f254c755406110c" [[package]] name = "cxxbridge-flags" -version = "1.0.108" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7030aff1908ba2b7eb639466df50792b2a3fdf02bea9557c4ee1a531975554b" +checksum = "7944172ae7e4068c533afbb984114a56c46e9ccddda550499caa222902c7f7bb" [[package]] name = "cxxbridge-macro" -version = "1.0.108" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79418ecb0c2322a7926a5fa5a9660535432b5b3588b947e1eb484cc509edbe3c" +checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5" dependencies = [ "proc-macro2", "quote", @@ -1076,6 +1073,15 @@ 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" @@ -1181,9 +1187,9 @@ dependencies = [ [[package]] name = "link-cplusplus" -version = "1.0.9" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d240c6f7e1ba3a28b0249f774e6a9dd0175054b52dfbb61b16eb8505c3785c9" +checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" dependencies = [ "cc", ] @@ -1634,9 +1640,9 @@ dependencies = [ [[package]] name = "qt-build-utils" version = "0.5.3" -source = "git+https://github.com/KDAB/cxx-qt#83a82685e3c289458614de4bc54678e5face8874" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5ce806205819a87696bb9275c831be88a79592f035d4cc17d01625395cbe1da" dependencies = [ - "cc", "thiserror", "versions", ] @@ -2034,7 +2040,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b7b278788e7be4d0d29c0f39497a0eef3fba6bbc8e70d8bf7fde46edeaa9e85" dependencies = [ - "itertools", + "itertools 0.11.0", "nom", "unicode_categories", ] @@ -2628,11 +2634,11 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "versions" -version = "5.0.1" +version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c73a36bc44e3039f51fbee93e39f41225f6b17b380eb70cc2aab942df06b34dd" +checksum = "ee97e1d97bd593fb513912a07691b742361b3dd64ad56f2c694ea2dbfe0665d3" dependencies = [ - "itertools", + "itertools 0.10.5", "nom", ] diff --git a/Cargo.toml b/Cargo.toml index 90a5d62..2859c3a 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.95" -cxx-qt = { git = "https://github.com/KDAB/cxx-qt" } -cxx-qt-lib = { git = "https://github.com/KDAB/cxx-qt" } +cxx = "1.0.83" +cxx-qt = "0.5.3" +cxx-qt-lib = "0.5.3" # 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 = { git = "https://github.com/KDAB/cxx-qt" } -qt-build-utils = { git = "https://github.com/KDAB/cxx-qt" } +cxx-qt-build = "0.5.3" +qt-build-utils = "0.5.3" # [dependencies.confy] # features = ["yaml_conf"] diff --git a/build.rs b/build.rs index bb4d786..ee5f750 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 11ee6e4..23e5aa0 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 1646c38..3302bbd 100644 --- a/src/rust/service_item_model.rs +++ b/src/rust/service_item_model.rs @@ -24,13 +24,6 @@ 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)] @@ -1137,6 +1130,15 @@ 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>, ); @@ -1167,17 +1169,6 @@ 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 12ab68f..0b5e0ba 100644 --- a/src/rust/settings.rs +++ b/src/rust/settings.rs @@ -1,6 +1,10 @@ #[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; @@ -8,125 +12,115 @@ mod settings { type QUrl = cxx_qt_lib::QUrl; } - 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); + // 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, + #[qproperty] + screen: QString, + #[qproperty] + sound_effect: QString, + #[qproperty] + last_save_file: QUrl, + #[qproperty] + loaded_file: QUrl, } -} -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 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(""), + } } } -} -impl ffi::SettingsRust { - pub fn print_sound(self: Pin<&mut Self>) { - let mut config = Ini::new(); - let _map = config.load("~/.config/lumina/lumina.conf"); + 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"); - println!("{}", self.sound_effect()); - } + println!("{}", self.sound_effect()); + } - 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"); + #[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: {:?}", + 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!("settings_load_error: {:?}", e) + println!("error: {:?}", e); + Err(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) - } } } }