evolution-3.6.4/modules/cal-config-contacts/e-source-contacts.c

No issues found

  1 /*
  2  * e-source-contacts.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 <webcal://www.gnu.org/licenses/>
 16  *
 17  */
 18 
 19 #include "e-source-contacts.h"
 20 
 21 #define E_SOURCE_CONTACTS_GET_PRIVATE(obj) \
 22 	(G_TYPE_INSTANCE_GET_PRIVATE \
 23 	((obj), E_TYPE_SOURCE_CONTACTS, ESourceContactsPrivate))
 24 
 25 struct _ESourceContactsPrivate {
 26 	gboolean include_me;
 27 };
 28 
 29 enum {
 30 	PROP_0,
 31 	PROP_INCLUDE_ME
 32 };
 33 
 34 G_DEFINE_DYNAMIC_TYPE (
 35 	ESourceContacts,
 36 	e_source_contacts,
 37 	E_TYPE_SOURCE_EXTENSION)
 38 
 39 static void
 40 source_contacts_set_property (GObject *object,
 41                               guint property_id,
 42                               const GValue *value,
 43                               GParamSpec *pspec)
 44 {
 45 	switch (property_id) {
 46 		case PROP_INCLUDE_ME:
 47 			e_source_contacts_set_include_me (
 48 				E_SOURCE_CONTACTS (object),
 49 				g_value_get_boolean (value));
 50 			return;
 51 	}
 52 
 53 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 54 }
 55 
 56 static void
 57 source_contacts_get_property (GObject *object,
 58                               guint property_id,
 59                               GValue *value,
 60                               GParamSpec *pspec)
 61 {
 62 	switch (property_id) {
 63 		case PROP_INCLUDE_ME:
 64 			g_value_set_boolean (
 65 				value,
 66 				e_source_contacts_get_include_me (
 67 				E_SOURCE_CONTACTS (object)));
 68 			return;
 69 	}
 70 
 71 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 72 }
 73 
 74 static void
 75 source_contacts_constructed (GObject *object)
 76 {
 77 	ESource *source;
 78 	ESourceExtension *extension;
 79 	ESourceBackend *backend_extension;
 80 	ESourceContacts *contacts_extension;
 81 	const gchar *backend_name;
 82 	const gchar *extension_name;
 83 	gboolean include_me;
 84 
 85 	/* Chain up to parent's constructed() method. */
 86 	G_OBJECT_CLASS (e_source_contacts_parent_class)->constructed (object);
 87 
 88 	extension = E_SOURCE_EXTENSION (object);
 89 	source = e_source_extension_get_source (extension);
 90 
 91 	extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK;
 92 	backend_extension = e_source_get_extension (source, extension_name);
 93 	backend_name = e_source_backend_get_backend_name (backend_extension);
 94 
 95 	/* Only include local address books by default. */
 96 	include_me = (g_strcmp0 (backend_name, "local") == 0);
 97 
 98 	contacts_extension = E_SOURCE_CONTACTS (extension);
 99 	e_source_contacts_set_include_me (contacts_extension, include_me);
100 }
101 
102 static void
103 e_source_contacts_class_init (ESourceContactsClass *class)
104 {
105 	GObjectClass *object_class;
106 	ESourceExtensionClass *extension_class;
107 
108 	g_type_class_add_private (class, sizeof (ESourceContactsPrivate));
109 
110 	object_class = G_OBJECT_CLASS (class);
111 	object_class->set_property = source_contacts_set_property;
112 	object_class->get_property = source_contacts_get_property;
113 	object_class->constructed = source_contacts_constructed;
114 
115 	extension_class = E_SOURCE_EXTENSION_CLASS (class);
116 	extension_class->name = E_SOURCE_EXTENSION_CONTACTS_BACKEND;
117 
118 	g_object_class_install_property (
119 		object_class,
120 		PROP_INCLUDE_ME,
121 		g_param_spec_boolean (
122 			"include-me",
123 			"Include Me",
124 			"Include this address book in the contacts calendar",
125 			FALSE,  /* see constructed () */
126 			G_PARAM_READWRITE |
127 			E_SOURCE_PARAM_SETTING));
128 }
129 
130 static void
131 e_source_contacts_class_finalize (ESourceContactsClass *class)
132 {
133 }
134 
135 static void
136 e_source_contacts_init (ESourceContacts *extension)
137 {
138 	extension->priv = E_SOURCE_CONTACTS_GET_PRIVATE (extension);
139 }
140 
141 void
142 e_source_contacts_type_register (GTypeModule *type_module)
143 {
144 	/* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
145 	 *     function, so we have to wrap it with a public function in
146 	 *     order to register types from a separate compilation unit. */
147 	e_source_contacts_register_type (type_module);
148 }
149 
150 gboolean
151 e_source_contacts_get_include_me (ESourceContacts *extension)
152 {
153 	g_return_val_if_fail (E_IS_SOURCE_CONTACTS (extension), FALSE);
154 
155 	return extension->priv->include_me;
156 }
157 
158 void
159 e_source_contacts_set_include_me (ESourceContacts *extension,
160                                   gboolean include_me)
161 {
162 	g_return_if_fail (E_IS_SOURCE_CONTACTS (extension));
163 
164 	if (extension->priv->include_me == include_me)
165 		return;
166 
167 	extension->priv->include_me = include_me;
168 
169 	g_object_notify (G_OBJECT (extension), "include-me");
170 }