summaryrefslogtreecommitdiff
path: root/docs/reference/libsecret/libsecret-using.sgml
blob: c531b15de53c0d806c81549e450f46305d5fd157 (plain)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?xml version="1.0"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
               "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
<!ENTITY major SYSTEM "version-major.xml">
]>
<part id="using">
<title>Using libsecret in builds or scripts</title>

<chapter id="using-c">
<title>C: Compiling with libsecret</title>

<para>Like other GNOME libraries, <application>libsecret</application> uses
<application>pkg-config</application> to provide compiler options. The package
name is "<literal>libsecret-&major;</literal>". So in your
<literal>configure.ac</literal> script,you might specify something like:</para>

<informalexample><programlisting>
PKG_CHECK_MODULES(LIBSECRET, [libsecret-&major; >= 1.0])
AC_SUBST(LIBSECRET_CFLAGS)
AC_SUBST(LIBSECRET_LIBS)
</programlisting></informalexample>

<para>
Code using <application>libsecret</application> should include the header like this:
</para>

<informalexample><programlisting>
#include &lt;libsecret/secret.h&gt;
</programlisting></informalexample>

<para>
Including individual headers besides the main header files is not
permitted and will cause an error.
</para>

<para>
Some parts of the <application>libsecret</application> API are not yet stable.
To use them you need use the <literal>libsecret-unstable</literal> package.
The API contained in this package will change from time to time. Here's how
you would do it:
</para>

<informalexample><programlisting>
PKG_CHECK_MODULES(LIBSECRET, [libsecret-unstable >= 1.0])
AC_SUBST(LIBSECRET_CFLAGS)
AC_SUBST(LIBSECRET_LIBS)
</programlisting></informalexample>

</chapter>

<chapter id="using-js">
<title>Javascript: Importing libsecret</title>

<para>
In javascript use the standard introspection import mechanism to get at
<application>libsecret</application>:
</para>

<informalexample><programlisting language="javascript">
const Secret = imports.gi.Secret;

// ... and here's a sample line of code which uses the import
var schema = new Secret.Schema.new("org.mock.Schema",
	Secret.SchemaFlags.NONE, { "name", Secret.SchemaAttributeType.STRING });
</programlisting></informalexample>

<para>
Some parts of the <application>libsecret</application> API are not yet stable.
It is <emphasis>not</emphasis> recommended that you use these unstable parts
from javascript. Your code <emphasis>will break</emphasis> when the unstable API
changes, and due to the lack of a compiler you will have no way of knowing when
it does. If you must use the unstable API, you would do it like this:
</para>

<informalexample><programlisting language="javascript">
// Warning: if you use the unstable API from javascript, your're going to have a bad time
const SecretUnstable = imports.gi.SecretUnstable;

// ... and a here's sample line of code which uses the import
var collection = SecretUnstable.Collection.for_alias(null, "default", null);
</programlisting></informalexample>

</chapter>

<chapter id="using-python">
<title>Python: Importing libsecret</title>

<para>
In python use the standard introspection import mechanism to get at
<application>libsecret</application>:
</para>

<informalexample><programlisting language="py">
from gi.repository import Secret

# ... and a here's sample line of code which uses the import
schema = Secret.Schema.new("org.mock.Schema",
	Secret.SchemaFlags.NONE, { "name", Secret.SchemaAttributeType.STRING })
</programlisting></informalexample>

<para>
Some parts of the <application>libsecret</application> API are not yet stable.
It is <emphasis>not</emphasis> recommended that you use these unstable parts
from python. Your code <emphasis>will break</emphasis> when the unstable API
changes, and due to the lack of a compiler you will have no way of knowing when
it does. If you must use the unstable API, you would do it like this:
</para>

<informalexample><programlisting language="py">
# Warning: if you use the unstable API from python, your're going to have a bad time
from gi.repository import SecretUnstable

# ... and a here's sample line of code which uses the import
collection = SecretUnstable.Collection.for_alias(None, "default", None);
</programlisting></informalexample>

</chapter>

<chapter id="using-vala">
<title>Vala: Compiling with libsecret</title>

<para>
The package name is "<literal>libsecret-&major;</literal>". You can use it like
this in your <literal>Makefile.am</literal> file:
</para>

<informalexample><programlisting>
AM_VALAFLAGS = \
	--pkg=libsecret-&major;
</programlisting></informalexample>

<para>
Some parts of the <application>libsecret</application> API are not yet stable.
To use them you need use the <literal>libsecret-unstable</literal> package.
The API contained in this package will change from time to time. Here's how
you would do it:
</para>

<informalexample><programlisting>
AM_VALAFLAGS = \
	--pkg=libsecret-unstable
</programlisting></informalexample>

</chapter>

</part>