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.Schema;
14 
15 private import glib.ConstructionException;
16 private import glib.HashTable;
17 private import glib.Str;
18 private import gobject.ObjectG;
19 private import libsecret.c.functions;
20 public  import libsecret.c.types;
21 
22 
23 /**
24  * Represents a set of attributes that are stored with an item. These schemas
25  * are used for interoperability between various services storing the same types
26  * of items.
27  * 
28  * Each schema has a name like "org.gnome.keyring.NetworkPassword", and defines
29  * a set of attributes, and types (string, integer, boolean) for those attributes.
30  * 
31  * Attributes are stored as strings in the Secret Service, and the attribute
32  * types simply define standard ways to store integer and boolean values as strings.
33  * Attributes are represented in libsecret via a #GHashTable with string keys and
34  * values. Even for values that defined as an integer or boolean in the schema,
35  * the attribute values in the #GHashTable are strings. Boolean values are stored
36  * as the strings 'true' and 'false'. Integer values are stored in decimal, with
37  * a preceding negative sign for negative integers.
38  * 
39  * Schemas are handled entirely on the client side by this library. The name of the
40  * schema is automatically stored as an attribute on the item.
41  * 
42  * Normally when looking up passwords only those with matching schema names are
43  * returned. If the schema @flags contain the %SECRET_SCHEMA_DONT_MATCH_NAME flag,
44  * then lookups will not check that the schema name matches that on the item, only
45  * the schema's attributes are matched. This is useful when you are looking up items
46  * that are not stored by the libsecret library. Other libraries such as libgnome-keyring
47  * don't store the schema name.
48  */
49 public class Schema
50 {
51 	/** the main Gtk struct */
52 	protected SecretSchema* secretSchema;
53 	protected bool ownedRef;
54 
55 	/** Get the main Gtk struct */
56 	public SecretSchema* getSchemaStruct(bool transferOwnership = false)
57 	{
58 		if (transferOwnership)
59 			ownedRef = false;
60 		return secretSchema;
61 	}
62 
63 	/** the main Gtk struct as a void* */
64 	protected void* getStruct()
65 	{
66 		return cast(void*)secretSchema;
67 	}
68 
69 	/**
70 	 * Sets our main struct and passes it to the parent class.
71 	 */
72 	public this (SecretSchema* secretSchema, bool ownedRef = false)
73 	{
74 		this.secretSchema = secretSchema;
75 		this.ownedRef = ownedRef;
76 	}
77 
78 	~this ()
79 	{
80 		if ( ownedRef )
81 			secret_schema_unref(secretSchema);
82 	}
83 
84 
85 	/** */
86 	public static GType getType()
87 	{
88 		return secret_schema_get_type();
89 	}
90 
91 	/**
92 	 * Using this function is not normally necessary from C code. This is useful
93 	 * for constructing #SecretSchema structures in bindings.
94 	 *
95 	 * A schema represents a set of attributes that are stored with an item. These
96 	 * schemas are used for interoperability between various services storing the
97 	 * same types of items.
98 	 *
99 	 * Each schema has an @name like "org.gnome.keyring.NetworkPassword", and
100 	 * defines a set of attributes names, and types (string, integer, boolean) for
101 	 * those attributes.
102 	 *
103 	 * Each key in the @attributes table should be a attribute name strings, and
104 	 * the values in the table should be integers from the #SecretSchemaAttributeType
105 	 * enumeration, representing the attribute type for each attribute name.
106 	 *
107 	 * Normally when looking up passwords only those with matching schema names are
108 	 * returned. If the schema @flags contain the %SECRET_SCHEMA_DONT_MATCH_NAME flag,
109 	 * then lookups will not check that the schema name matches that on the item, only
110 	 * the schema's attributes are matched. This is useful when you are looking up items
111 	 * that are not stored by the libsecret library. Other libraries such as libgnome-keyring
112 	 * don't store the schema name.
113 	 *
114 	 * Params:
115 	 *     name = the dotted name of the schema
116 	 *     flags = the flags for the schema
117 	 *     attributeNamesAndTypes = the attribute names and types of those attributes
118 	 *
119 	 * Returns: the new schema, which should be unreferenced with
120 	 *     secret_schema_unref() when done
121 	 *
122 	 * Throws: ConstructionException GTK+ fails to create the object.
123 	 */
124 	public this(string name, SecretSchemaFlags flags, HashTable attributeNamesAndTypes)
125 	{
126 		auto p = secret_schema_newv(Str.toStringz(name), flags, (attributeNamesAndTypes is null) ? null : attributeNamesAndTypes.getHashTableStruct());
127 
128 		if(p is null)
129 		{
130 			throw new ConstructionException("null returned by newv");
131 		}
132 
133 		this(cast(SecretSchema*) p);
134 	}
135 
136 	/**
137 	 * Adds a reference to the #SecretSchema.
138 	 *
139 	 * It is not normally necessary to call this function from C code, and is
140 	 * mainly present for the sake of bindings. If the @schema was statically
141 	 * allocated, then this function will copy the schema.
142 	 *
143 	 * Returns: the referenced schema, which should be later
144 	 *     unreferenced with secret_schema_unref()
145 	 */
146 	public Schema doref()
147 	{
148 		auto p = secret_schema_ref(secretSchema);
149 
150 		if(p is null)
151 		{
152 			return null;
153 		}
154 
155 		return ObjectG.getDObject!(Schema)(cast(SecretSchema*) p, true);
156 	}
157 
158 	/**
159 	 * Releases a reference to the #SecretSchema. If the last reference is
160 	 * released then the schema will be freed.
161 	 *
162 	 * It is not normally necessary to call this function from C code, and is
163 	 * mainly present for the sake of bindings. It is an error to call this for
164 	 * a @schema that was statically allocated.
165 	 */
166 	public void unref()
167 	{
168 		secret_schema_unref(secretSchema);
169 	}
170 }