goa: Add missing linker flag (for real).
[platform/upstream/evolution-data-server.git] / libedataserver / e-source-uoa.c
1 /*
2  * e-source-uoa.c
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) version 3.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with the program; if not, see <http://www.gnu.org/licenses/>
16  *
17  */
18
19 /**
20  * SECTION: e-source-uoa
21  * @include: libedataserver/libedataserver.h
22  * @short_description: #ESource extension for Ubuntu Online Accounts
23  *
24  * The #ESourceUoa extension associates an #ESource with an #AgAccount.
25  * This extension is usually found in a top-level #ESource, with various
26  * mail, calendar and address book data sources as children.
27  *
28  * Access the extension as follows:
29  *
30  * |[
31  *   #include <libedataserver/libedataserver.h>
32  *
33  *   ESourceUoa *extension;
34  *
35  *   extension = e_source_get_extension (source, E_SOURCE_EXTENSION_UOA);
36  * ]|
37  **/
38
39 #include "e-source-uoa.h"
40
41 #include <libedataserver/e-data-server-util.h>
42
43 #define E_SOURCE_UOA_GET_PRIVATE(obj) \
44         (G_TYPE_INSTANCE_GET_PRIVATE \
45         ((obj), E_TYPE_SOURCE_UOA, ESourceUoaPrivate))
46
47 struct _ESourceUoaPrivate {
48         guint account_id;
49 };
50
51 enum {
52         PROP_0,
53         PROP_ACCOUNT_ID
54 };
55
56 G_DEFINE_TYPE (
57         ESourceUoa,
58         e_source_uoa,
59         E_TYPE_SOURCE_EXTENSION)
60
61 static void
62 source_uoa_set_property (GObject *object,
63                          guint property_id,
64                          const GValue *value,
65                          GParamSpec *pspec)
66 {
67         switch (property_id) {
68                 case PROP_ACCOUNT_ID:
69                         e_source_uoa_set_account_id (
70                                 E_SOURCE_UOA (object),
71                                 g_value_get_uint (value));
72                         return;
73         }
74
75         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
76 }
77
78 static void
79 source_uoa_get_property (GObject *object,
80                          guint property_id,
81                          GValue *value,
82                          GParamSpec *pspec)
83 {
84         switch (property_id) {
85                 case PROP_ACCOUNT_ID:
86                         g_value_set_uint (
87                                 value,
88                                 e_source_uoa_get_account_id (
89                                 E_SOURCE_UOA (object)));
90                         return;
91         }
92
93         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
94 }
95
96 static void
97 e_source_uoa_class_init (ESourceUoaClass *class)
98 {
99         GObjectClass *object_class;
100         ESourceExtensionClass *extension_class;
101
102         g_type_class_add_private (class, sizeof (ESourceUoaPrivate));
103
104         object_class = G_OBJECT_CLASS (class);
105         object_class->set_property = source_uoa_set_property;
106         object_class->get_property = source_uoa_get_property;
107
108         extension_class = E_SOURCE_EXTENSION_CLASS (class);
109         extension_class->name = E_SOURCE_EXTENSION_UOA;
110
111         g_object_class_install_property (
112                 object_class,
113                 PROP_ACCOUNT_ID,
114                 g_param_spec_uint (
115                         "account-id",
116                         "Account ID",
117                         "Ubuntu Online Account ID",
118                         0, G_MAXUINT, 0,
119                         G_PARAM_READWRITE |
120                         G_PARAM_CONSTRUCT |
121                         G_PARAM_STATIC_STRINGS |
122                         E_SOURCE_PARAM_SETTING));
123 }
124
125 static void
126 e_source_uoa_init (ESourceUoa *extension)
127 {
128         extension->priv = E_SOURCE_UOA_GET_PRIVATE (extension);
129 }
130
131 /**
132  * e_source_uoa_get_account_id:
133  * @extension: an #ESourceUoa
134  *
135  * Returns the numeric identifier of the Ubuntu Online Account associated
136  * with the #ESource to which @extension belongs.
137  *
138  * Returns: the associated Ubuntu Online Account ID
139  *
140  * Since: 3.8
141  **/
142 guint
143 e_source_uoa_get_account_id (ESourceUoa *extension)
144 {
145         g_return_val_if_fail (E_IS_SOURCE_UOA (extension), 0);
146
147         return extension->priv->account_id;
148 }
149
150 /**
151  * e_source_uoa_set_account_id:
152  * @extension: an #ESourceUoa
153  * @account_id: the associated Ubuntu Online Account ID
154  *
155  * Sets the numeric identifier of the Ubuntu Online Account associated
156  * with the #ESource to which @extension belongs.
157  *
158  * Since: 3.8
159  **/
160 void
161 e_source_uoa_set_account_id (ESourceUoa *extension,
162                              guint account_id)
163 {
164         g_return_if_fail (E_IS_SOURCE_UOA (extension));
165
166         if (extension->priv->account_id == account_id)
167                 return;
168
169         extension->priv->account_id = account_id;
170
171         g_object_notify (G_OBJECT (extension), "account-id");
172 }
173