1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use glib::types::{StaticType, Type};
use glib::translate::*;
use ffi;
pub struct SecretValue {
ptr: *mut ffi::SecretValue
}
impl SecretValue{
pub fn new(secret: &str) -> Self {
let content_type = "text/plain";
unsafe {
let ptr = ffi::secret_value_new(
secret.to_glib_none().0,
-1,
content_type.to_glib_none().0
);
SecretValue::from_glib_full(ptr)
}
}
pub fn from_glib_full(ptr: *mut ffi::SecretValue) -> Self {
assert!(!ptr.is_null());
SecretValue {
ptr: ptr
}
}
pub fn to_glib_none(&self) -> *mut ffi::SecretValue {
self.ptr
}
pub fn get(&self) -> Option<String> {
if self.get_content_type() == "text/plain" {
unsafe{
let secret = ffi::secret_value_get_text(self.to_glib_none());
Some(from_glib_none(secret))
}
} else {
None
}
}
pub fn get_content_type(&self) -> String {
unsafe {
let ptr = ffi::secret_value_get_content_type(self.to_glib_none());
from_glib_none(ptr)
}
}
}
impl StaticType for SecretValue {
fn static_type() -> Type{
unsafe {
from_glib(ffi::secret_value_get_type())
}
}
}
impl Clone for SecretValue {
fn clone(&self) -> Self {
unsafe {
let ptr = ffi::secret_value_ref(self.ptr);
SecretValue::from_glib_full(ptr)
}
}
}
impl Drop for SecretValue {
fn drop(&mut self){
unsafe {
ffi::secret_value_unref(self.ptr as *mut _)
}
}
}