Debian Codegraph @

src/EWS/evolution/e-book-config-ews.c

raw
1 /*
2 * SPDX-FileCopyrightText: (C) 2012 Red Hat, Inc. (www.redhat.com)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6 #include "evolution-ews-config.h"
7
8 #include <glib/gi18n-lib.h>
9
10 #include "common/camel-ews-settings.h"
11 #include "common/e-source-ews-folder.h"
12
13 #include "e-book-config-ews.h"
14
15 G_DEFINE_DYNAMIC_TYPE (
16 EBookConfigEws,
17 e_book_config_ews,
18 E_TYPE_SOURCE_CONFIG_BACKEND)
19
20 static CamelEwsSettings *
21 book_config_ews_get_ews_settings (ESourceConfigBackend *backend,
22 ESource *source)
23 {
24 ESource *collection;
25 ESourceCamel *extension;
26 ESourceRegistry *registry;
27 CamelSettings *settings;
28 const gchar *extension_name;
29
30 if (!source)
31 return NULL;
32
33 registry = e_source_config_get_registry (e_source_config_backend_get_config (backend));
34
35 extension_name = e_source_camel_get_extension_name ("ews");
36 e_source_camel_generate_subtype ("ews", CAMEL_TYPE_EWS_SETTINGS);
37
38 /* The collection settings live in our parent data source. */
39 collection = e_source_registry_find_extension (registry, source, extension_name);
40 if (!collection)
41 return NULL;
42
43 extension = e_source_get_extension (collection, extension_name);
44 settings = e_source_camel_get_settings (extension);
45
46 g_object_unref (collection);
47
48 return CAMEL_EWS_SETTINGS (settings);
49 }
50
51 static gboolean
52 book_config_ews_allow_creation (ESourceConfigBackend *backend)
53 {
54 return TRUE;
55 }
56
57 static void
58 book_config_ews_maybe_insert_gal_options (ESourceConfigBackend *backend,
59 ESource *scratch_source)
60 {
61 CamelEwsSettings *ews_settings;
62 ESource *source;
63 gchar *gal_uid;
64 gboolean is_gal;
65
66 if (!scratch_source || !e_source_has_extension (scratch_source, E_SOURCE_EXTENSION_EWS_FOLDER))
67 return;
68
69 source = e_source_config_get_original_source (e_source_config_backend_get_config (backend));
70 if (!source)
71 return;
72
73 ews_settings = book_config_ews_get_ews_settings (backend, source);
74 if (!ews_settings)
75 return;
76
77 gal_uid = camel_ews_settings_dup_gal_uid (ews_settings);
78 is_gal = g_strcmp0 (e_source_get_uid (source), gal_uid) == 0;
79 g_free (gal_uid);
80
81 if (is_gal) {
82 ESourceEwsFolder *ews_folder;
83 GtkWidget *checkbox;
84
85 ews_folder = e_source_get_extension (scratch_source, E_SOURCE_EXTENSION_EWS_FOLDER);
86
87 checkbox = gtk_check_button_new_with_mnemonic (_("Use only _primary contact email address"));
88 gtk_widget_set_tooltip_text (checkbox, _("When checked, the contacts looked up in the online Global Address List will contain only the primary email address"));
89 gtk_widget_show (checkbox);
90
91 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), e_source_ews_folder_get_use_primary_address (ews_folder));
92
93 e_binding_bind_property (
94 checkbox, "active",
95 ews_folder, "use-primary-address",
96 G_BINDING_DEFAULT);
97
98 e_source_config_insert_widget (e_source_config_backend_get_config (backend), scratch_source, NULL, checkbox);
99
100 checkbox = gtk_check_button_new_with_mnemonic (_("_Fetch contact photos"));
101 gtk_widget_set_tooltip_text (checkbox, _("Tries to look up for user photo"));
102 gtk_widget_show (checkbox);
103
104 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), e_source_ews_folder_get_fetch_gal_photos (ews_folder));
105
106 e_binding_bind_property (
107 checkbox, "active",
108 ews_folder, "fetch-gal-photos",
109 G_BINDING_DEFAULT);
110
111 e_source_config_insert_widget (e_source_config_backend_get_config (backend), scratch_source, NULL, checkbox);
112 }
113 }
114
115 static void
116 book_config_ews_insert_widgets (ESourceConfigBackend *backend,
117 ESource *scratch_source)
118 {
119 ESourceConfig *config;
120
121 if (!scratch_source)
122 return;
123
124 book_config_ews_maybe_insert_gal_options (backend, scratch_source);
125
126 config = e_source_config_backend_get_config (backend);
127
128 e_source_config_add_refresh_interval (config, scratch_source);
129 e_source_config_add_refresh_on_metered_network (config, scratch_source);
130 }
131
132 static void
133 e_book_config_ews_class_init (EBookConfigEwsClass *class)
134 {
135 EExtensionClass *extension_class;
136 ESourceConfigBackendClass *backend_class;
137
138 extension_class = E_EXTENSION_CLASS (class);
139 extension_class->extensible_type = E_TYPE_BOOK_SOURCE_CONFIG;
140
141 backend_class = E_SOURCE_CONFIG_BACKEND_CLASS (class);
142 backend_class->backend_name = "ews";
143 backend_class->allow_creation = book_config_ews_allow_creation;
144 backend_class->insert_widgets = book_config_ews_insert_widgets;
145 }
146
147 static void
148 e_book_config_ews_class_finalize (EBookConfigEwsClass *class)
149 {
150 }
151
152 static void
153 e_book_config_ews_init (EBookConfigEws *backend)
154 {
155 }
156
157 void
158 e_book_config_ews_type_register (GTypeModule *type_module)
159 {
160 /* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
161 * function, so we have to wrap it with a public function in
162 * order to register types from a separate compilation unit. */
163 e_book_config_ews_register_type (type_module);
164 }
165