1 /*
2 * e-source-autocomplete.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-autocomplete
20 * @include: libedataserver/libedataserver.h
21 * @short_description: #ESource extension for autocomplete settings
22 *
23 * The #ESourceAutocomplete extension tracks contact autocompletion
24 * settings for an address book.
25 *
26 * Access the extension as follows:
27 *
28 * |[
29 * #include <libedataserver/libedataserver.h>
30 *
31 * ESourceAutocomplete *extension;
32 *
33 * extension = e_source_get_extension (source, E_SOURCE_EXTENSION_AUTOCOMPLETE);
34 * ]|
35 **/
36
37 #include "e-source-autocomplete.h"
38
39 struct _ESourceAutocompletePrivate {
40 gboolean include_me;
41 };
42
43 enum {
44 PROP_0,
45 PROP_INCLUDE_ME
46 };
47
G_DEFINE_TYPE_WITH_PRIVATE(ESourceAutocomplete,e_source_autocomplete,E_TYPE_SOURCE_EXTENSION)48 G_DEFINE_TYPE_WITH_PRIVATE (
49 ESourceAutocomplete,
50 e_source_autocomplete,
51 E_TYPE_SOURCE_EXTENSION)
52
53 static void
54 source_autocomplete_set_property (GObject *object,
55 guint property_id,
56 const GValue *value,
57 GParamSpec *pspec)
58 {
59 switch (property_id) {
60 case PROP_INCLUDE_ME:
61 e_source_autocomplete_set_include_me (
62 E_SOURCE_AUTOCOMPLETE (object),
63 g_value_get_boolean (value));
64 return;
65 }
66
67 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
68 }
69
70 static void
source_autocomplete_get_property(GObject * object,guint property_id,GValue * value,GParamSpec * pspec)71 source_autocomplete_get_property (GObject *object,
72 guint property_id,
73 GValue *value,
74 GParamSpec *pspec)
75 {
76 switch (property_id) {
77 case PROP_INCLUDE_ME:
78 g_value_set_boolean (
79 value,
80 e_source_autocomplete_get_include_me (
81 E_SOURCE_AUTOCOMPLETE (object)));
82 return;
83 }
84
85 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
86 }
87
88 static void
e_source_autocomplete_class_init(ESourceAutocompleteClass * class)89 e_source_autocomplete_class_init (ESourceAutocompleteClass *class)
90 {
91 GObjectClass *object_class;
92 ESourceExtensionClass *extension_class;
93
94 object_class = G_OBJECT_CLASS (class);
95 object_class->set_property = source_autocomplete_set_property;
96 object_class->get_property = source_autocomplete_get_property;
97
98 extension_class = E_SOURCE_EXTENSION_CLASS (class);
99 extension_class->name = E_SOURCE_EXTENSION_AUTOCOMPLETE;
100
101 g_object_class_install_property (
102 object_class,
103 PROP_INCLUDE_ME,
104 g_param_spec_boolean (
105 "include-me",
106 "IncludeMe",
107 "Include this source when autocompleting",
108 TRUE,
109 G_PARAM_READWRITE |
110 G_PARAM_CONSTRUCT |
111 G_PARAM_EXPLICIT_NOTIFY |
112 G_PARAM_STATIC_STRINGS |
113 E_SOURCE_PARAM_SETTING));
114 }
115
116 static void
e_source_autocomplete_init(ESourceAutocomplete * extension)117 e_source_autocomplete_init (ESourceAutocomplete *extension)
118 {
119 extension->priv = e_source_autocomplete_get_instance_private (extension);
120 }
121
122 /**
123 * e_source_autocomplete_get_include_me:
124 * @extension: an #ESourceAutocomplete
125 *
126 * Returns whether the address book described by the #ESource to which
127 * @extension belongs should be queried when the user inputs a partial
128 * contact name or email address.
129 *
130 * Returns: whether to use the autocomplete feature
131 *
132 * Since: 3.6
133 **/
134 gboolean
e_source_autocomplete_get_include_me(ESourceAutocomplete * extension)135 e_source_autocomplete_get_include_me (ESourceAutocomplete *extension)
136 {
137 g_return_val_if_fail (E_IS_SOURCE_AUTOCOMPLETE (extension), FALSE);
138
139 return extension->priv->include_me;
140 }
141
142 /**
143 * e_source_autocomplete_set_include_me:
144 * @extension: an #ESourceAutocomplete
145 * @include_me: whether to use the autocomplete feature
146 *
147 * Sets whether the address book described by the #ESource to which
148 * @extension belongs should be queried when the user inputs a partial
149 * contact name or email address.
150 *
151 * Since: 3.6
152 **/
153 void
e_source_autocomplete_set_include_me(ESourceAutocomplete * extension,gboolean include_me)154 e_source_autocomplete_set_include_me (ESourceAutocomplete *extension,
155 gboolean include_me)
156 {
157 g_return_if_fail (E_IS_SOURCE_AUTOCOMPLETE (extension));
158
159 if (extension->priv->include_me == include_me)
160 return;
161
162 extension->priv->include_me = include_me;
163
164 g_object_notify (G_OBJECT (extension), "include-me");
165 }
166