1 /*
2  * This file is part of libsecret-d.
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/
7  */
8 
9 // generated automatically - do not change
10 // find conversion definition on APILookup.txt
11 
12 
13 module libsecret.Value;
14 
15 private import glib.ConstructionException;
16 private import glib.Str;
17 private import gobject.ObjectG;
18 private import libsecret.c.functions;
19 public  import libsecret.c.types;
20 
21 
22 /**
23  * A secret value, like a password or other binary secret.
24  */
25 public class Value
26 {
27 	/** the main Gtk struct */
28 	protected SecretValue* secretValue;
29 	protected bool ownedRef;
30 
31 	/** Get the main Gtk struct */
32 	public SecretValue* getValueStruct(bool transferOwnership = false)
33 	{
34 		if (transferOwnership)
35 			ownedRef = false;
36 		return secretValue;
37 	}
38 
39 	/** the main Gtk struct as a void* */
40 	protected void* getStruct()
41 	{
42 		return cast(void*)secretValue;
43 	}
44 
45 	/**
46 	 * Sets our main struct and passes it to the parent class.
47 	 */
48 	public this (SecretValue* secretValue, bool ownedRef = false)
49 	{
50 		this.secretValue = secretValue;
51 		this.ownedRef = ownedRef;
52 	}
53 
54 	~this ()
55 	{
56 		if ( ownedRef )
57 			secret_value_unref(secretValue);
58 	}
59 
60 
61 	/** */
62 	public static GType getType()
63 	{
64 		return secret_value_get_type();
65 	}
66 
67 	/**
68 	 * Create a #SecretValue for the secret data passed in. The secret data is
69 	 * copied into non-pageable 'secure' memory.
70 	 *
71 	 * If the length is less than zero, then @secret is assumed to be
72 	 * null-terminated.
73 	 *
74 	 * Params:
75 	 *     secret = the secret data
76 	 *     length = the length of the data
77 	 *     contentType = the content type of the data
78 	 *
79 	 * Returns: the new #SecretValue
80 	 *
81 	 * Throws: ConstructionException GTK+ fails to create the object.
82 	 */
83 	public this(string secret, ptrdiff_t length, string contentType)
84 	{
85 		auto p = secret_value_new(Str.toStringz(secret), length, Str.toStringz(contentType));
86 
87 		if(p is null)
88 		{
89 			throw new ConstructionException("null returned by new");
90 		}
91 
92 		this(cast(SecretValue*) p);
93 	}
94 
95 	/**
96 	 * Create a #SecretValue for the secret data passed in. The secret data is
97 	 * not copied, and will later be freed with the @destroy function.
98 	 *
99 	 * If the length is less than zero, then @secret is assumed to be
100 	 * null-terminated.
101 	 *
102 	 * Params:
103 	 *     secret = the secret data
104 	 *     length = the length of the data
105 	 *     contentType = the content type of the data
106 	 *     destroy = function to call to free the secret data
107 	 *
108 	 * Returns: the new #SecretValue
109 	 *
110 	 * Throws: ConstructionException GTK+ fails to create the object.
111 	 */
112 	public this(string secret, ptrdiff_t length, string contentType, GDestroyNotify destroy)
113 	{
114 		auto p = secret_value_new_full(Str.toStringz(secret), length, Str.toStringz(contentType), destroy);
115 
116 		if(p is null)
117 		{
118 			throw new ConstructionException("null returned by new_full");
119 		}
120 
121 		this(cast(SecretValue*) p);
122 	}
123 
124 	/**
125 	 * Get the secret data in the #SecretValue. The value is not necessarily
126 	 * null-terminated unless it was created with secret_value_new() or a
127 	 * null-terminated string was passed to secret_value_new_full().
128 	 *
129 	 * Returns: the secret data
130 	 */
131 	public string get()
132 	{
133 		size_t length;
134 
135 		return Str.toString(secret_value_get(secretValue, &length));
136 	}
137 
138 	/**
139 	 * Get the content type of the secret value, such as
140 	 * <literal>text/plain</literal>.
141 	 *
142 	 * Returns: the content type
143 	 */
144 	public string getContentType()
145 	{
146 		return Str.toString(secret_value_get_content_type(secretValue));
147 	}
148 
149 	/**
150 	 * Get the secret data in the #SecretValue if it contains a textual
151 	 * value. The content type must be <literal>text/plain</literal>.
152 	 *
153 	 * Returns: the content type
154 	 */
155 	public string getText()
156 	{
157 		return Str.toString(secret_value_get_text(secretValue));
158 	}
159 
160 	/**
161 	 * Add another reference to the #SecretValue. For each reference
162 	 * secret_value_unref() should be called to unreference the value.
163 	 *
164 	 * Returns: the value
165 	 */
166 	public Value doref()
167 	{
168 		auto p = secret_value_ref(secretValue);
169 
170 		if(p is null)
171 		{
172 			return null;
173 		}
174 
175 		return ObjectG.getDObject!(Value)(cast(SecretValue*) p, true);
176 	}
177 
178 	/**
179 	 * Unreference a #SecretValue. When the last reference is gone, then
180 	 * the value will be freed.
181 	 */
182 	public void unref()
183 	{
184 		secret_value_unref(secretValue);
185 	}
186 }