| 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 <glib/gi18n-lib.h> |
| 9 |
|
| 10 |
#include "common/camel-m365-settings.h" |
| 11 |
#include "common/e-m365-connection.h" |
| 12 |
#include "common/e-source-m365-folder.h" |
| 13 |
|
| 14 |
#include "e-book-config-m365.h" |
| 15 |
|
| 16 |
G_DEFINE_DYNAMIC_TYPE (EBookConfigM365, e_book_config_m365, E_TYPE_SOURCE_CONFIG_BACKEND) |
| 17 |
|
| 18 |
static gboolean |
| 19 |
book_config_m365_allow_creation (ESourceConfigBackend *backend) |
| 20 |
{ |
| 21 |
return FALSE; |
| 22 |
} |
| 23 |
|
| 24 |
static void |
| 25 |
book_config_m365_insert_widgets (ESourceConfigBackend *backend, |
| 26 |
ESource *scratch_source) |
| 27 |
{ |
| 28 |
ESourceConfig *config; |
| 29 |
|
| 30 |
if (!scratch_source) |
| 31 |
return; |
| 32 |
|
| 33 |
config = e_source_config_backend_get_config (backend); |
| 34 |
|
| 35 |
if (e_source_has_extension (scratch_source, E_SOURCE_EXTENSION_M365_FOLDER)) { |
| 36 |
ESourceM365Folder *m365_folder_ext; |
| 37 |
const gchar *id; |
| 38 |
|
| 39 |
m365_folder_ext = e_source_get_extension (scratch_source, E_SOURCE_EXTENSION_M365_FOLDER); |
| 40 |
id = e_source_m365_folder_get_id (m365_folder_ext); |
| 41 |
|
| 42 |
if (g_strcmp0 (id, E_M365_ARTIFICIAL_FOLDER_ID_ORG_CONTACTS) == 0 || |
| 43 |
g_strcmp0 (id, E_M365_ARTIFICIAL_FOLDER_ID_USERS) == 0) { |
| 44 |
e_book_source_config_add_offline_toggle (E_BOOK_SOURCE_CONFIG (config), scratch_source); |
| 45 |
} else if (g_strcmp0 (id, E_M365_ARTIFICIAL_FOLDER_ID_PEOPLE) == 0) { |
| 46 |
GtkWidget *widget; |
| 47 |
GtkWidget *container; |
| 48 |
ESourceExtension *extension; |
| 49 |
|
| 50 |
extension = e_source_get_extension (scratch_source, E_SOURCE_EXTENSION_M365_FOLDER); |
| 51 |
|
| 52 |
widget = gtk_alignment_new (0.0, 0.5, 0.0, 0.0); |
| 53 |
e_source_config_insert_widget (config, scratch_source, NULL, widget); |
| 54 |
gtk_widget_show (widget); |
| 55 |
|
| 56 |
container = widget; |
| 57 |
|
| 58 |
widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); |
| 59 |
gtk_container_add (GTK_CONTAINER (container), widget); |
| 60 |
gtk_widget_show (widget); |
| 61 |
|
| 62 |
container = widget; |
| 63 |
|
| 64 |
widget = gtk_label_new (_("Maximum contacts to download")); |
| 65 |
gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); |
| 66 |
gtk_widget_show (widget); |
| 67 |
|
| 68 |
widget = gtk_spin_button_new_with_range (0, G_MAXUINT, 1); |
| 69 |
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (widget), TRUE); |
| 70 |
gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (widget), GTK_UPDATE_IF_VALID); |
| 71 |
gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); |
| 72 |
gtk_widget_show (widget); |
| 73 |
|
| 74 |
e_binding_bind_property ( |
| 75 |
extension, "max-people", |
| 76 |
widget, "value", |
| 77 |
G_BINDING_BIDIRECTIONAL | |
| 78 |
G_BINDING_SYNC_CREATE); |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
e_source_config_add_refresh_interval (config, scratch_source); |
| 83 |
e_source_config_add_refresh_on_metered_network (config, scratch_source); |
| 84 |
} |
| 85 |
|
| 86 |
static void |
| 87 |
e_book_config_m365_class_init (EBookConfigM365Class *class) |
| 88 |
{ |
| 89 |
EExtensionClass *extension_class; |
| 90 |
ESourceConfigBackendClass *backend_class; |
| 91 |
|
| 92 |
extension_class = E_EXTENSION_CLASS (class); |
| 93 |
extension_class->extensible_type = E_TYPE_BOOK_SOURCE_CONFIG; |
| 94 |
|
| 95 |
backend_class = E_SOURCE_CONFIG_BACKEND_CLASS (class); |
| 96 |
backend_class->backend_name = "microsoft365"; |
| 97 |
backend_class->allow_creation = book_config_m365_allow_creation; |
| 98 |
backend_class->insert_widgets = book_config_m365_insert_widgets; |
| 99 |
} |
| 100 |
|
| 101 |
static void |
| 102 |
e_book_config_m365_class_finalize (EBookConfigM365Class *class) |
| 103 |
{ |
| 104 |
} |
| 105 |
|
| 106 |
static void |
| 107 |
e_book_config_m365_init (EBookConfigM365 *backend) |
| 108 |
{ |
| 109 |
} |
| 110 |
|
| 111 |
void |
| 112 |
e_book_config_m365_type_register (GTypeModule *type_module) |
| 113 |
{ |
| 114 |
/* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration |
| 115 |
* function, so we have to wrap it with a public function in |
| 116 |
* order to register types from a separate compilation unit. */ |
| 117 |
e_book_config_m365_register_type (type_module); |
| 118 |
} |