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 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-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 struct _ESourceMDNPrivate {
43 EMdnResponsePolicy response_policy;
44 };
45
46 enum {
47 PROP_0,
48 PROP_RESPONSE_POLICY
49 };
50
G_DEFINE_TYPE_WITH_PRIVATE(ESourceMDN,e_source_mdn,E_TYPE_SOURCE_EXTENSION)51 G_DEFINE_TYPE_WITH_PRIVATE (
52 ESourceMDN,
53 e_source_mdn,
54 E_TYPE_SOURCE_EXTENSION)
55
56 static void
57 source_mdn_set_property (GObject *object,
58 guint property_id,
59 const GValue *value,
60 GParamSpec *pspec)
61 {
62 switch (property_id) {
63 case PROP_RESPONSE_POLICY:
64 e_source_mdn_set_response_policy (
65 E_SOURCE_MDN (object),
66 g_value_get_enum (value));
67 return;
68 }
69
70 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
71 }
72
73 static void
source_mdn_get_property(GObject * object,guint property_id,GValue * value,GParamSpec * pspec)74 source_mdn_get_property (GObject *object,
75 guint property_id,
76 GValue *value,
77 GParamSpec *pspec)
78 {
79 switch (property_id) {
80 case PROP_RESPONSE_POLICY:
81 g_value_set_enum (
82 value,
83 e_source_mdn_get_response_policy (
84 E_SOURCE_MDN (object)));
85 return;
86 }
87
88 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
89 }
90
91 static void
e_source_mdn_class_init(ESourceMDNClass * class)92 e_source_mdn_class_init (ESourceMDNClass *class)
93 {
94 GObjectClass *object_class;
95 ESourceExtensionClass *extension_class;
96
97 object_class = G_OBJECT_CLASS (class);
98 object_class->set_property = source_mdn_set_property;
99 object_class->get_property = source_mdn_get_property;
100
101 extension_class = E_SOURCE_EXTENSION_CLASS (class);
102 extension_class->name = E_SOURCE_EXTENSION_MDN;
103
104 g_object_class_install_property (
105 object_class,
106 PROP_RESPONSE_POLICY,
107 g_param_spec_enum (
108 "response-policy",
109 "Response Policy",
110 "Policy for responding to MDN requests",
111 E_TYPE_MDN_RESPONSE_POLICY,
112 E_MDN_RESPONSE_POLICY_ASK,
113 G_PARAM_READWRITE |
114 G_PARAM_CONSTRUCT |
115 G_PARAM_EXPLICIT_NOTIFY |
116 G_PARAM_STATIC_STRINGS |
117 E_SOURCE_PARAM_SETTING));
118 }
119
120 static void
e_source_mdn_init(ESourceMDN * extension)121 e_source_mdn_init (ESourceMDN *extension)
122 {
123 extension->priv = e_source_mdn_get_instance_private (extension);
124 }
125
126 /**
127 * e_source_mdn_get_response_policy:
128 * @extension: an #ESourceMDN
129 *
130 * Returns the policy for this mail account on responding to Message
131 * Disposition Notification requests when receiving mail messages.
132 *
133 * Returns: the #EMdnResponsePolicy for this account
134 *
135 * Since: 3.6
136 **/
137 EMdnResponsePolicy
e_source_mdn_get_response_policy(ESourceMDN * extension)138 e_source_mdn_get_response_policy (ESourceMDN *extension)
139 {
140 g_return_val_if_fail (
141 E_IS_SOURCE_MDN (extension),
142 E_MDN_RESPONSE_POLICY_NEVER);
143
144 return extension->priv->response_policy;
145 }
146
147 /**
148 * e_source_mdn_set_response_policy:
149 * @extension: an #ESourceMDN
150 * @response_policy: the #EMdnResponsePolicy
151 *
152 * Sets the policy for this mail account on responding to Message
153 * Disposition Notification requests when receiving mail messages.
154 *
155 * Since: 3.6
156 **/
157 void
e_source_mdn_set_response_policy(ESourceMDN * extension,EMdnResponsePolicy response_policy)158 e_source_mdn_set_response_policy (ESourceMDN *extension,
159 EMdnResponsePolicy response_policy)
160 {
161 g_return_if_fail (E_IS_SOURCE_MDN (extension));
162
163 if (extension->priv->response_policy == response_policy)
164 return;
165
166 extension->priv->response_policy = response_policy;
167
168 g_object_notify (G_OBJECT (extension), "response-policy");
169 }
170