Added KLocalizedString Wrapper.
Only added applicationDomain related methods.
This commit is contained in:
parent
5cf6a34302
commit
cb934ff6dc
32
src/klocalizedstring.rs
Normal file
32
src/klocalizedstring.rs
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
use cpp::{cpp, cpp_class};
|
||||||
|
use qmetaobject::QByteArray;
|
||||||
|
use std::ffi::CStr;
|
||||||
|
|
||||||
|
cpp! {{
|
||||||
|
#include <KLocalizedString>
|
||||||
|
#include <QtCore/QByteArray>
|
||||||
|
}}
|
||||||
|
|
||||||
|
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();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -46,4 +46,9 @@
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
pub mod klocalizedcontext;
|
pub mod klocalizedcontext;
|
||||||
pub use klocalizedcontext::KLocalizedContext;
|
pub mod klocalizedstring;
|
||||||
|
|
||||||
|
pub mod prelude {
|
||||||
|
pub use crate::klocalizedcontext::KLocalizedContext;
|
||||||
|
pub use crate::klocalizedstring::KLocalizedString;
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use ki18n_rs::KLocalizedContext;
|
use ki18n_rs::klocalizedcontext::KLocalizedContext;
|
||||||
use qmetaobject::prelude::*;
|
use qmetaobject::prelude::*;
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
|
|
14
tests/klocalizedstring_tests.rs
Normal file
14
tests/klocalizedstring_tests.rs
Normal file
|
@ -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");
|
||||||
|
}
|
Loading…
Reference in a new issue