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