| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: (C) 2020 Red Hat (www.redhat.com) |
| 3 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "evolution-ews-config.h" |
| 7 |
|
| 8 |
#include "e-source-m365-deltas.h" |
| 9 |
|
| 10 |
struct _ESourceM365DeltasPrivate { |
| 11 |
gchar *contacts_link; |
| 12 |
}; |
| 13 |
|
| 14 |
enum { |
| 15 |
PROP_0, |
| 16 |
PROP_CONTACTS_LINK |
| 17 |
}; |
| 18 |
|
| 19 |
G_DEFINE_TYPE_WITH_PRIVATE (ESourceM365Deltas, e_source_m365_deltas, E_TYPE_SOURCE_EXTENSION) |
| 20 |
|
| 21 |
static void |
| 22 |
source_m365_deltas_set_property (GObject *object, |
| 23 |
guint property_id, |
| 24 |
const GValue *value, |
| 25 |
GParamSpec *pspec) |
| 26 |
{ |
| 27 |
switch (property_id) { |
| 28 |
case PROP_CONTACTS_LINK: |
| 29 |
e_source_m365_deltas_set_contacts_link ( |
| 30 |
E_SOURCE_M365_DELTAS (object), |
| 31 |
g_value_get_string (value)); |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); |
| 36 |
} |
| 37 |
|
| 38 |
static void |
| 39 |
source_m365_deltas_get_property (GObject *object, |
| 40 |
guint property_id, |
| 41 |
GValue *value, |
| 42 |
GParamSpec *pspec) |
| 43 |
{ |
| 44 |
switch (property_id) { |
| 45 |
case PROP_CONTACTS_LINK: |
| 46 |
g_value_take_string ( |
| 47 |
value, |
| 48 |
e_source_m365_deltas_dup_contacts_link ( |
| 49 |
E_SOURCE_M365_DELTAS (object))); |
| 50 |
return; |
| 51 |
} |
| 52 |
|
| 53 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); |
| 54 |
} |
| 55 |
|
| 56 |
static void |
| 57 |
source_m365_deltas_finalize (GObject *object) |
| 58 |
{ |
| 59 |
ESourceM365Deltas *m365_deltas = E_SOURCE_M365_DELTAS (object); |
| 60 |
|
| 61 |
g_free (m365_deltas->priv->contacts_link); |
| 62 |
|
| 63 |
/* Chain up to parent's method. */ |
| 64 |
G_OBJECT_CLASS (e_source_m365_deltas_parent_class)->finalize (object); |
| 65 |
} |
| 66 |
|
| 67 |
static void |
| 68 |
e_source_m365_deltas_class_init (ESourceM365DeltasClass *class) |
| 69 |
{ |
| 70 |
GObjectClass *object_class; |
| 71 |
ESourceExtensionClass *extension_class; |
| 72 |
|
| 73 |
object_class = G_OBJECT_CLASS (class); |
| 74 |
object_class->set_property = source_m365_deltas_set_property; |
| 75 |
object_class->get_property = source_m365_deltas_get_property; |
| 76 |
object_class->finalize = source_m365_deltas_finalize; |
| 77 |
|
| 78 |
extension_class = E_SOURCE_EXTENSION_CLASS (class); |
| 79 |
extension_class->name = E_SOURCE_EXTENSION_M365_DELTAS; |
| 80 |
|
| 81 |
g_object_class_install_property ( |
| 82 |
object_class, |
| 83 |
PROP_CONTACTS_LINK, |
| 84 |
g_param_spec_string ( |
| 85 |
"contacts-link", |
| 86 |
"Contacts Link", |
| 87 |
"The delta link for contacts", |
| 88 |
NULL, |
| 89 |
G_PARAM_READWRITE | |
| 90 |
G_PARAM_CONSTRUCT | |
| 91 |
G_PARAM_STATIC_STRINGS | |
| 92 |
E_SOURCE_PARAM_SETTING)); |
| 93 |
} |
| 94 |
|
| 95 |
static void |
| 96 |
e_source_m365_deltas_init (ESourceM365Deltas *extension) |
| 97 |
{ |
| 98 |
extension->priv = e_source_m365_deltas_get_instance_private (extension); |
| 99 |
} |
| 100 |
|
| 101 |
void |
| 102 |
e_source_m365_deltas_type_register (GTypeModule *type_module) |
| 103 |
{ |
| 104 |
/* We need to ensure this is registered, because it's looked up |
| 105 |
* by name in e_source_get_extension(). */ |
| 106 |
g_type_ensure (E_TYPE_SOURCE_M365_DELTAS); |
| 107 |
} |
| 108 |
|
| 109 |
const gchar * |
| 110 |
e_source_m365_deltas_get_contacts_link (ESourceM365Deltas *extension) |
| 111 |
{ |
| 112 |
g_return_val_if_fail (E_IS_SOURCE_M365_DELTAS (extension), NULL); |
| 113 |
|
| 114 |
return extension->priv->contacts_link; |
| 115 |
} |
| 116 |
|
| 117 |
gchar * |
| 118 |
e_source_m365_deltas_dup_contacts_link (ESourceM365Deltas *extension) |
| 119 |
{ |
| 120 |
const gchar *protected; |
| 121 |
gchar *duplicate; |
| 122 |
|
| 123 |
g_return_val_if_fail (E_IS_SOURCE_M365_DELTAS (extension), NULL); |
| 124 |
|
| 125 |
e_source_extension_property_lock (E_SOURCE_EXTENSION (extension)); |
| 126 |
|
| 127 |
protected = e_source_m365_deltas_get_contacts_link (extension); |
| 128 |
duplicate = g_strdup (protected); |
| 129 |
|
| 130 |
e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension)); |
| 131 |
|
| 132 |
return duplicate; |
| 133 |
} |
| 134 |
|
| 135 |
void |
| 136 |
e_source_m365_deltas_set_contacts_link (ESourceM365Deltas *extension, |
| 137 |
const gchar *delta_link) |
| 138 |
{ |
| 139 |
g_return_if_fail (E_IS_SOURCE_M365_DELTAS (extension)); |
| 140 |
|
| 141 |
e_source_extension_property_lock (E_SOURCE_EXTENSION (extension)); |
| 142 |
|
| 143 |
if (g_strcmp0 (extension->priv->contacts_link, delta_link) == 0) { |
| 144 |
e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension)); |
| 145 |
return; |
| 146 |
} |
| 147 |
|
| 148 |
g_free (extension->priv->contacts_link); |
| 149 |
extension->priv->contacts_link = e_util_strdup_strip (delta_link); |
| 150 |
|
| 151 |
e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension)); |
| 152 |
|
| 153 |
g_object_notify (G_OBJECT (extension), "contacts-link"); |
| 154 |
} |