changes: Bump to 3.8.1
[platform/upstream/evolution-data-server.git] / libedataserver / e-source-mdn.c
1 /*
2  * e-source-mdn.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 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-mdn
20  * @include: libedataserver/libedataserver.h
21  * @short_description: #ESource extension for MDN settings
22  *
23  * The #ESourceMDN extension tracks Message Disposition Notification
24  * settings for a mail account.  See RFC 2298 for more information about
25  * Message Disposition Notification.
26  *
27  * Access the extension as follows:
28  *
29  * |[
30  *   #include <libedataserver/libedataserver.h>
31  *
32  *   ESourceMDN *extension;
33  *
34  *   extension = e_source_get_extension (source, E_SOURCE_EXTENSION_MDN);
35  * ]|
36  **/
37
38 #include "e-source-mdn.h"
39
40 #include <libedataserver/e-source-enumtypes.h>
41
42 #define E_SOURCE_MDN_GET_PRIVATE(obj) \
43         (G_TYPE_INSTANCE_GET_PRIVATE \
44         ((obj), E_TYPE_SOURCE_MDN, ESourceMDNPrivate))
45
46 struct _ESourceMDNPrivate {
47         EMdnResponsePolicy response_policy;
48 };
49
50 enum {
51         PROP_0,
52         PROP_RESPONSE_POLICY
53 };
54
55 G_DEFINE_TYPE (
56         ESourceMDN,
57         e_source_mdn,
58         E_TYPE_SOURCE_EXTENSION)
59
60 static void
61 source_mdn_set_property (GObject *object,
62                          guint property_id,
63                          const GValue *value,
64                          GParamSpec *pspec)
65 {
66         switch (property_id) {
67                 case PROP_RESPONSE_POLICY:
68                         e_source_mdn_set_response_policy (
69                                 E_SOURCE_MDN (object),
70                                 g_value_get_enum (value));
71                         return;
72         }
73
74         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
75 }
76
77 static void
78 source_mdn_get_property (GObject *object,
79                          guint property_id,
80                          GValue *value,
81                          GParamSpec *pspec)
82 {
83         switch (property_id) {
84                 case PROP_RESPONSE_POLICY:
85                         g_value_set_enum (
86                                 value,
87                                 e_source_mdn_get_response_policy (
88                                 E_SOURCE_MDN (object)));
89                         return;
90         }
91
92         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
93 }
94
95 static void
96 e_source_mdn_class_init (ESourceMDNClass *class)
97 {
98         GObjectClass *object_class;
99         ESourceExtensionClass *extension_class;
100
101         g_type_class_add_private (class, sizeof (ESourceMDNPrivate));
102
103         object_class = G_OBJECT_CLASS (class);
104         object_class->set_property = source_mdn_set_property;
105         object_class->get_property = source_mdn_get_property;
106
107         extension_class = E_SOURCE_EXTENSION_CLASS (class);
108         extension_class->name = E_SOURCE_EXTENSION_MDN;
109
110         g_object_class_install_property (
111                 object_class,
112                 PROP_RESPONSE_POLICY,
113                 g_param_spec_enum (
114                         "response-policy",
115                         "Response Policy",
116                         "Policy for responding to MDN requests",
117                         E_TYPE_MDN_RESPONSE_POLICY,
118                         E_MDN_RESPONSE_POLICY_ASK,
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_mdn_init (ESourceMDN *extension)
127 {
128         extension->priv = E_SOURCE_MDN_GET_PRIVATE (extension);
129 }
130
131 /**
132  * e_source_mdn_get_response_policy:
133  * @extension: an #ESourceMDN
134  *
135  * Returns the policy for this mail account on responding to Message
136  * Disposition Notification requests when receiving mail messages.
137  *
138  * Returns: the #EMdnResponsePolicy for this account
139  *
140  * Since: 3.6
141  **/
142 EMdnResponsePolicy
143 e_source_mdn_get_response_policy (ESourceMDN *extension)
144 {
145         g_return_val_if_fail (
146                 E_IS_SOURCE_MDN (extension),
147                 E_MDN_RESPONSE_POLICY_NEVER);
148
149         return extension->priv->response_policy;
150 }
151
152 /**
153  * e_source_mdn_set_response_policy:
154  * @extension: an #ESourceMDN
155  * @response_policy: the #EMdnResponsePolicy
156  *
157  * Sets the policy for this mail account on responding to Message
158  * Disposition Notification requests when receiving mail messages.
159  *
160  * Since: 3.6
161  **/
162 void
163 e_source_mdn_set_response_policy (ESourceMDN *extension,
164                                   EMdnResponsePolicy response_policy)
165 {
166         g_return_if_fail (E_IS_SOURCE_MDN (extension));
167
168         if (extension->priv->response_policy == response_policy)
169                 return;
170
171         extension->priv->response_policy = response_policy;
172
173         g_object_notify (G_OBJECT (extension), "response-policy");
174 }