diff --git a/src/klocalizedstring.rs b/src/klocalizedstring.rs new file mode 100644 index 0000000..d0e7872 --- /dev/null +++ b/src/klocalizedstring.rs @@ -0,0 +1,32 @@ +use cpp::{cpp, cpp_class}; +use qmetaobject::QByteArray; +use std::ffi::CStr; + +cpp! {{ + #include + #include +}} + +cpp_class!( + /// Wrapper around [`KLocalizedString`][class] class + /// + /// [class]: https://api.kde.org/frameworks/ki18n/html/classKLocalizedString.html + pub unsafe struct KLocalizedString as "KLocalizedString" +); + +impl KLocalizedString { + /// Set Application Domain + pub fn set_application_domain(domain: &CStr) { + let domain_ptr = domain.as_ptr(); + cpp!(unsafe [domain_ptr as "char*"] { + KLocalizedString::setApplicationDomain(domain_ptr); + }); + } + + /// Get Application Domain + pub fn application_domain() -> QByteArray { + cpp!(unsafe [] -> QByteArray as "QByteArray" { + return KLocalizedString::applicationDomain(); + }) + } +} diff --git a/src/lib.rs b/src/lib.rs index fab00b0..46a5d3c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,4 +46,9 @@ //! ``` pub mod klocalizedcontext; -pub use klocalizedcontext::KLocalizedContext; +pub mod klocalizedstring; + +pub mod prelude { + pub use crate::klocalizedcontext::KLocalizedContext; + pub use crate::klocalizedstring::KLocalizedString; +} diff --git a/tests/klocalizedcontext_tests.rs b/tests/klocalizedcontext_tests.rs index 7c4ebec..0ff2cfc 100644 --- a/tests/klocalizedcontext_tests.rs +++ b/tests/klocalizedcontext_tests.rs @@ -1,4 +1,4 @@ -use ki18n_rs::KLocalizedContext; +use ki18n_rs::klocalizedcontext::KLocalizedContext; use qmetaobject::prelude::*; mod common; diff --git a/tests/klocalizedstring_tests.rs b/tests/klocalizedstring_tests.rs new file mode 100644 index 0000000..38d29dc --- /dev/null +++ b/tests/klocalizedstring_tests.rs @@ -0,0 +1,14 @@ +use ki18n_rs::klocalizedstring::KLocalizedString; +use std::ffi::CString; + +#[test] +fn application_domain() { + const APPLICATION_DOMAIN: &str = "KI18n"; + let domain = CString::new(APPLICATION_DOMAIN).unwrap(); + + KLocalizedString::set_application_domain(&domain); + let domain = KLocalizedString::application_domain(); + println!("{:#?}", domain); + + assert_eq!(domain.to_str().unwrap(), "KI18n"); +}