Added KLocalizedString Wrapper.

Only added applicationDomain related methods.
This commit is contained in:
Ayush Singh 2021-12-14 18:15:49 +05:30
parent 5cf6a34302
commit cb934ff6dc
4 changed files with 53 additions and 2 deletions

32
src/klocalizedstring.rs Normal file
View 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();
})
}
}

View file

@ -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;
}

View file

@ -1,4 +1,4 @@
use ki18n_rs::KLocalizedContext; use ki18n_rs::klocalizedcontext::KLocalizedContext;
use qmetaobject::prelude::*; use qmetaobject::prelude::*;
mod common; mod common;

View 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");
}