| 1 |
|
| 2 |
|
| 3 |
nc. |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "config.h" |
| 20 |
#include <glib/gi18n-lib.h> |
| 21 |
|
| 22 |
#include "goaewsclient.h" |
| 23 |
#include "goaprovider.h" |
| 24 |
#include "goaproviderdialog.h" |
| 25 |
#include "goaexchangeprovider.h" |
| 26 |
#include "goaobjectskeletonutils.h" |
| 27 |
#include "goautils.h" |
| 28 |
|
| 29 |
struct _GoaExchangeProvider |
| 30 |
{ |
| 31 |
GoaProvider parent_instance; |
| 32 |
}; |
| 33 |
|
| 34 |
G_DEFINE_TYPE_WITH_CODE (GoaExchangeProvider, goa_exchange_provider, GOA_TYPE_PROVIDER, |
| 35 |
goa_provider_ensure_extension_points_registered (); |
| 36 |
g_io_extension_point_implement (GOA_PROVIDER_EXTENSION_POINT_NAME, |
| 37 |
g_define_type_id, |
| 38 |
GOA_EXCHANGE_NAME, |
| 39 |
0)); |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
static const gchar * |
| 44 |
get_provider_type (GoaProvider *provider) |
| 45 |
{ |
| 46 |
return GOA_EXCHANGE_NAME; |
| 47 |
} |
| 48 |
|
| 49 |
static gchar * |
| 50 |
get_provider_name (GoaProvider *provider, GoaObject *object) |
| 51 |
{ |
| 52 |
return g_strdup(_("Microsoft Exchange")); |
| 53 |
} |
| 54 |
|
| 55 |
static GoaProviderGroup |
| 56 |
get_provider_group (GoaProvider *provider) |
| 57 |
{ |
| 58 |
return GOA_PROVIDER_GROUP_BRANDED; |
| 59 |
} |
| 60 |
|
| 61 |
static GoaProviderFeatures |
| 62 |
get_provider_features (GoaProvider *provider) |
| 63 |
{ |
| 64 |
return GOA_PROVIDER_FEATURE_BRANDED | |
| 65 |
GOA_PROVIDER_FEATURE_MAIL | |
| 66 |
GOA_PROVIDER_FEATURE_CALENDAR | |
| 67 |
GOA_PROVIDER_FEATURE_CONTACTS; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
static gboolean on_handle_get_password (GoaPasswordBased *interface, |
| 73 |
GDBusMethodInvocation *invocation, |
| 74 |
const gchar *id, |
| 75 |
gpointer user_data); |
| 76 |
|
| 77 |
static gboolean |
| 78 |
build_object (GoaProvider *provider, |
| 79 |
GoaObjectSkeleton *object, |
| 80 |
GKeyFile *key_file, |
| 81 |
const gchar *group, |
| 82 |
GDBusConnection *connection, |
| 83 |
gboolean just_added, |
| 84 |
GError **error) |
| 85 |
{ |
| 86 |
GoaAccount *account = NULL; |
| 87 |
GoaExchange *exchange = NULL; |
| 88 |
GoaMail *mail = NULL; |
| 89 |
GoaPasswordBased *password_based = NULL; |
| 90 |
GKeyFile *goa_conf; |
| 91 |
const gchar *provider_type; |
| 92 |
gboolean calendar_enabled; |
| 93 |
gboolean contacts_enabled; |
| 94 |
gboolean mail_enabled; |
| 95 |
gboolean ret = FALSE; |
| 96 |
|
| 97 |
|
| 98 |
if (!GOA_PROVIDER_CLASS (goa_exchange_provider_parent_class)->build_object (provider, |
| 99 |
object, |
| 100 |
key_file, |
| 101 |
group, |
| 102 |
connection, |
| 103 |
just_added, |
| 104 |
error)) |
| 105 |
goto out; |
| 106 |
|
| 107 |
password_based = goa_object_get_password_based (GOA_OBJECT (object)); |
| 108 |
if (password_based == NULL) |
| 109 |
{ |
| 110 |
password_based = goa_password_based_skeleton_new (); |
| 111 |
|
| 112 |
g_dbus_interface_skeleton_set_flags (G_DBUS_INTERFACE_SKELETON (password_based), |
| 113 |
G_DBUS_INTERFACE_SKELETON_FLAGS_HANDLE_METHOD_INVOCATIONS_IN_THREAD); |
| 114 |
goa_object_skeleton_set_password_based (object, password_based); |
| 115 |
g_signal_connect (password_based, |
| 116 |
"handle-get-password", |
| 117 |
G_CALLBACK (on_handle_get_password), |
| 118 |
NULL); |
| 119 |
} |
| 120 |
|
| 121 |
provider_type = goa_provider_get_provider_type (provider); |
| 122 |
goa_conf = goa_util_open_goa_conf (); |
| 123 |
account = goa_object_get_account (GOA_OBJECT (object)); |
| 124 |
|
| 125 |
|
| 126 |
mail = goa_object_get_mail (GOA_OBJECT (object)); |
| 127 |
mail_enabled = goa_util_provider_feature_is_enabled (goa_conf, provider_type, GOA_PROVIDER_FEATURE_MAIL) && |
| 128 |
g_key_file_get_boolean (key_file, group, "MailEnabled", NULL); |
| 129 |
if (mail_enabled) |
| 130 |
{ |
| 131 |
if (mail == NULL) |
| 132 |
{ |
| 133 |
const gchar *email_address; |
| 134 |
|
| 135 |
email_address = goa_account_get_presentation_identity (account); |
| 136 |
mail = goa_mail_skeleton_new (); |
| 137 |
g_object_set (G_OBJECT (mail), "email-address", email_address, NULL); |
| 138 |
goa_object_skeleton_set_mail (object, mail); |
| 139 |
} |
| 140 |
} |
| 141 |
else |
| 142 |
{ |
| 143 |
if (mail != NULL) |
| 144 |
goa_object_skeleton_set_mail (object, NULL); |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
calendar_enabled = goa_util_provider_feature_is_enabled (goa_conf, provider_type, GOA_PROVIDER_FEATURE_CALENDAR) && |
| 149 |
g_key_file_get_boolean (key_file, group, "CalendarEnabled", NULL); |
| 150 |
goa_object_skeleton_attach_calendar (object, NULL, calendar_enabled, FALSE); |
| 151 |
|
| 152 |
|
| 153 |
contacts_enabled = goa_util_provider_feature_is_enabled (goa_conf, provider_type, GOA_PROVIDER_FEATURE_CONTACTS) && |
| 154 |
g_key_file_get_boolean (key_file, group, "ContactsEnabled", NULL); |
| 155 |
goa_object_skeleton_attach_contacts (object, NULL, contacts_enabled, FALSE); |
| 156 |
|
| 157 |
g_clear_pointer (&goa_conf, g_key_file_free); |
| 158 |
|
| 159 |
|
| 160 |
exchange = goa_object_get_exchange (GOA_OBJECT (object)); |
| 161 |
if (exchange == NULL) |
| 162 |
{ |
| 163 |
gboolean accept_ssl_errors; |
| 164 |
gchar *host; |
| 165 |
|
| 166 |
accept_ssl_errors = g_key_file_get_boolean (key_file, group, "AcceptSslErrors", NULL); |
| 167 |
host = g_key_file_get_string (key_file, group, "Host", NULL); |
| 168 |
exchange = goa_exchange_skeleton_new (); |
| 169 |
g_object_set (G_OBJECT (exchange), |
| 170 |
"accept-ssl-errors", accept_ssl_errors, |
| 171 |
"host", host, |
| 172 |
NULL); |
| 173 |
goa_object_skeleton_set_exchange (object, exchange); |
| 174 |
g_free (host); |
| 175 |
} |
| 176 |
|
| 177 |
if (just_added) |
| 178 |
{ |
| 179 |
goa_account_set_mail_disabled (account, !mail_enabled); |
| 180 |
goa_account_set_calendar_disabled (account, !calendar_enabled); |
| 181 |
goa_account_set_contacts_disabled (account, !contacts_enabled); |
| 182 |
|
| 183 |
g_signal_connect (account, |
| 184 |
"notify::mail-disabled", |
| 185 |
G_CALLBACK (goa_util_account_notify_property_cb), |
| 186 |
(gpointer) "MailEnabled"); |
| 187 |
g_signal_connect (account, |
| 188 |
"notify::calendar-disabled", |
| 189 |
G_CALLBACK (goa_util_account_notify_property_cb), |
| 190 |
(gpointer) "CalendarEnabled"); |
| 191 |
g_signal_connect (account, |
| 192 |
"notify::contacts-disabled", |
| 193 |
G_CALLBACK (goa_util_account_notify_property_cb), |
| 194 |
(gpointer) "ContactsEnabled"); |
| 195 |
} |
| 196 |
|
| 197 |
ret = TRUE; |
| 198 |
|
| 199 |
out: |
| 200 |
g_clear_object (&exchange); |
| 201 |
g_clear_object (&mail); |
| 202 |
g_clear_object (&password_based); |
| 203 |
return ret; |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
static gboolean |
| 209 |
ensure_credentials_sync (GoaProvider *provider, |
| 210 |
GoaObject *object, |
| 211 |
gint *out_expires_in, |
| 212 |
GCancellable *cancellable, |
| 213 |
GError **error) |
| 214 |
{ |
| 215 |
GoaAccount *account; |
| 216 |
GoaEwsClient *ews_client = NULL; |
| 217 |
GoaExchange *exchange; |
| 218 |
gboolean accept_ssl_errors; |
| 219 |
gboolean ret = FALSE; |
| 220 |
const gchar *email_address; |
| 221 |
const gchar *server; |
| 222 |
gchar *username = NULL; |
| 223 |
gchar *password = NULL; |
| 224 |
|
| 225 |
if (!goa_utils_get_credentials (provider, object, "password", &username, &password, cancellable, error)) |
| 226 |
{ |
| 227 |
if (error != NULL) |
| 228 |
{ |
| 229 |
(*error)->domain = GOA_ERROR; |
| 230 |
(*error)->code = GOA_ERROR_NOT_AUTHORIZED; |
| 231 |
} |
| 232 |
goto out; |
| 233 |
} |
| 234 |
|
| 235 |
account = goa_object_peek_account (object); |
| 236 |
email_address = goa_account_get_presentation_identity (account); |
| 237 |
exchange = goa_object_peek_exchange (object); |
| 238 |
accept_ssl_errors = goa_exchange_get_accept_ssl_errors (exchange); |
| 239 |
server = goa_exchange_get_host (exchange); |
| 240 |
|
| 241 |
ews_client = goa_ews_client_new (); |
| 242 |
if (!goa_ews_client_autodiscover_sync (ews_client, |
| 243 |
email_address, |
| 244 |
password, |
| 245 |
username, |
| 246 |
server, |
| 247 |
accept_ssl_errors, |
| 248 |
cancellable, |
| 249 |
error)) |
| 250 |
{ |
| 251 |
if (error != NULL && g_error_matches (*error, GOA_ERROR, GOA_ERROR_NOT_AUTHORIZED)) |
| 252 |
{ |
| 253 |
g_prefix_error (error, |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
_("Invalid password with username ā%sā (%s, %d): "), |
| 259 |
username, |
| 260 |
g_quark_to_string ((*error)->domain), |
| 261 |
(*error)->code); |
| 262 |
} |
| 263 |
goto out; |
| 264 |
} |
| 265 |
|
| 266 |
if (out_expires_in != NULL) |
| 267 |
*out_expires_in = 0; |
| 268 |
|
| 269 |
ret = TRUE; |
| 270 |
|
| 271 |
out: |
| 272 |
g_clear_object (&ews_client); |
| 273 |
g_free (username); |
| 274 |
g_free (password); |
| 275 |
return ret; |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
typedef struct |
| 281 |
{ |
| 282 |
GoaProviderDialog *dialog; |
| 283 |
GoaClient *client; |
| 284 |
GoaObject *object; |
| 285 |
gboolean accept_ssl_errors; |
| 286 |
|
| 287 |
GtkWidget *email_address; |
| 288 |
GtkWidget *password; |
| 289 |
GtkWidget *username; |
| 290 |
GtkWidget *server; |
| 291 |
} AddAccountData; |
| 292 |
|
| 293 |
static void |
| 294 |
add_account_data_free (gpointer user_data) |
| 295 |
{ |
| 296 |
AddAccountData *data = (AddAccountData *)user_data; |
| 297 |
|
| 298 |
g_clear_object (&data->client); |
| 299 |
g_clear_object (&data->object); |
| 300 |
g_free (data); |
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
static void |
| 306 |
on_username_or_server_changed (GtkEditable *editable, |
| 307 |
AddAccountData *data) |
| 308 |
{ |
| 309 |
GoaDialogState state = GOA_DIALOG_IDLE; |
| 310 |
const char *email = NULL; |
| 311 |
const char *password = NULL; |
| 312 |
const char *server = NULL; |
| 313 |
const char *username = NULL; |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
data->accept_ssl_errors = FALSE; |
| 318 |
|
| 319 |
email = gtk_editable_get_text (GTK_EDITABLE (data->email_address)); |
| 320 |
if (!goa_utils_parse_email_address (email, NULL, NULL)) |
| 321 |
goto out; |
| 322 |
|
| 323 |
password = gtk_editable_get_text (GTK_EDITABLE (data->password)); |
| 324 |
username = gtk_editable_get_text (GTK_EDITABLE (data->username)); |
| 325 |
server = gtk_editable_get_text (GTK_EDITABLE (data->server)); |
| 326 |
if (*password != '\0' && *username != '\0' && *server != '\0') |
| 327 |
state = GOA_DIALOG_READY; |
| 328 |
|
| 329 |
out: |
| 330 |
goa_provider_dialog_set_state (data->dialog, state); |
| 331 |
} |
| 332 |
|
| 333 |
static void |
| 334 |
on_email_or_password_changed (GtkEditable *editable, |
| 335 |
AddAccountData *data) |
| 336 |
{ |
| 337 |
GoaDialogState state = GOA_DIALOG_IDLE; |
| 338 |
const char *email = NULL; |
| 339 |
const char *password = NULL; |
| 340 |
g_autofree char *email_localpart = NULL; |
| 341 |
g_autofree char *email_domain = NULL; |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
data->accept_ssl_errors = FALSE; |
| 346 |
|
| 347 |
email = gtk_editable_get_text (GTK_EDITABLE (data->email_address)); |
| 348 |
if (!goa_utils_parse_email_address (email, &email_localpart, &email_domain)) |
| 349 |
goto out; |
| 350 |
|
| 351 |
|
| 352 |
if (data->username != NULL && data->server != NULL) |
| 353 |
{ |
| 354 |
const char *username = NULL; |
| 355 |
const char *server = NULL; |
| 356 |
|
| 357 |
|
| 358 |
if (GTK_WIDGET (editable) == data->email_address) |
| 359 |
{ |
| 360 |
gtk_editable_set_text (GTK_EDITABLE (data->username), email_localpart); |
| 361 |
gtk_editable_set_text (GTK_EDITABLE (data->server), email_domain); |
| 362 |
return; |
| 363 |
} |
| 364 |
|
| 365 |
username = gtk_editable_get_text (GTK_EDITABLE (data->username)); |
| 366 |
server = gtk_editable_get_text (GTK_EDITABLE (data->server)); |
| 367 |
if (*username == '\0' || *server == '\0') |
| 368 |
goto out; |
| 369 |
} |
| 370 |
|
| 371 |
password = gtk_editable_get_text (GTK_EDITABLE (data->password)); |
| 372 |
if (password != NULL && *password != '\0') |
| 373 |
state = GOA_DIALOG_READY; |
| 374 |
|
| 375 |
out: |
| 376 |
goa_provider_dialog_set_state (data->dialog, state); |
| 377 |
} |
| 378 |
|
| 379 |
static void |
| 380 |
create_setup_page (GoaProvider *provider, |
| 381 |
AddAccountData *data, |
| 382 |
gboolean new_account) |
| 383 |
{ |
| 384 |
GoaProviderDialog *dialog = GOA_PROVIDER_DIALOG (data->dialog); |
| 385 |
GtkWidget *group; |
| 386 |
|
| 387 |
goa_provider_dialog_add_page (dialog, |
| 388 |
NULL, |
| 389 |
_("Connect to a Microsoft Exchange provider to access calendars, contacts and files")); |
| 390 |
|
| 391 |
group = goa_provider_dialog_add_group (dialog, NULL); |
| 392 |
data->email_address = goa_provider_dialog_add_entry (dialog, group, _("_Email")); |
| 393 |
data->password = goa_provider_dialog_add_password_entry (dialog, group, _("_Password")); |
| 394 |
goa_provider_dialog_add_description (dialog, NULL, _("Exchange account details will be auto-detected from your email address when possible")); |
| 395 |
|
| 396 |
g_signal_connect (data->email_address, |
| 397 |
"changed", |
| 398 |
G_CALLBACK (on_email_or_password_changed), |
| 399 |
data); |
| 400 |
g_signal_connect (data->password, |
| 401 |
"changed", |
| 402 |
G_CALLBACK (on_email_or_password_changed), |
| 403 |
data); |
| 404 |
|
| 405 |
group = goa_provider_dialog_add_group (dialog, _("Account Details")); |
| 406 |
data->username = goa_provider_dialog_add_entry (dialog, group, _("User_name")); |
| 407 |
data->server = goa_provider_dialog_add_entry (dialog, group, _("_Domain")); |
| 408 |
goa_provider_dialog_add_description (dialog, data->server, _("Example domain: example.com")); |
| 409 |
|
| 410 |
g_signal_connect (data->username, |
| 411 |
"changed", |
| 412 |
G_CALLBACK (on_username_or_server_changed), |
| 413 |
data); |
| 414 |
g_signal_connect (data->server, |
| 415 |
"changed", |
| 416 |
G_CALLBACK (on_username_or_server_changed), |
| 417 |
data); |
| 418 |
|
| 419 |
gtk_widget_grab_focus ((new_account) ? data->email_address : data->password); |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
static void |
| 425 |
add_account_credentials_cb (GoaManager *manager, |
| 426 |
GAsyncResult *res, |
| 427 |
gpointer user_data) |
| 428 |
{ |
| 429 |
g_autoptr(GTask) task = G_TASK (g_steal_pointer (&user_data)); |
| 430 |
AddAccountData *data = g_task_get_task_data (task); |
| 431 |
GDBusObject *ret = NULL; |
| 432 |
g_autofree char *object_path = NULL; |
| 433 |
GError *error = NULL; |
| 434 |
|
| 435 |
if (!goa_manager_call_add_account_finish (manager, &object_path, res, &error)) |
| 436 |
{ |
| 437 |
goa_provider_task_return_error (task, error); |
| 438 |
return; |
| 439 |
} |
| 440 |
|
| 441 |
ret = g_dbus_object_manager_get_object (goa_client_get_object_manager (data->client), |
| 442 |
object_path); |
| 443 |
goa_provider_task_return_account (task, GOA_OBJECT (ret)); |
| 444 |
} |
| 445 |
|
| 446 |
static void |
| 447 |
add_account_autodiscover_cb (GoaEwsClient *client, |
| 448 |
GAsyncResult *res, |
| 449 |
gpointer user_data) |
| 450 |
{ |
| 451 |
g_autoptr(GTask) task = G_TASK (g_steal_pointer (&user_data)); |
| 452 |
GoaProvider *provider = g_task_get_source_object (task); |
| 453 |
AddAccountData *data = g_task_get_task_data (task); |
| 454 |
GCancellable *cancellable = g_task_get_cancellable (task); |
| 455 |
GVariantBuilder credentials; |
| 456 |
GVariantBuilder details; |
| 457 |
const gchar *email_address; |
| 458 |
const gchar *server; |
| 459 |
const gchar *password; |
| 460 |
const gchar *username; |
| 461 |
g_autoptr(GError) error = NULL; |
| 462 |
|
| 463 |
if (!goa_ews_client_autodiscover_finish (client, res, &error)) |
| 464 |
{ |
| 465 |
data->accept_ssl_errors = (error->code == GOA_ERROR_SSL); |
| 466 |
goa_provider_dialog_report_error (data->dialog, error); |
| 467 |
return; |
| 468 |
} |
| 469 |
|
| 470 |
|
| 471 |
email_address = gtk_editable_get_text (GTK_EDITABLE (data->email_address)); |
| 472 |
password = gtk_editable_get_text (GTK_EDITABLE (data->password)); |
| 473 |
username = gtk_editable_get_text (GTK_EDITABLE (data->username)); |
| 474 |
server = gtk_editable_get_text (GTK_EDITABLE (data->server)); |
| 475 |
|
| 476 |
g_variant_builder_init (&credentials, G_VARIANT_TYPE_VARDICT); |
| 477 |
g_variant_builder_add (&credentials, "{sv}", "password", g_variant_new_string (password)); |
| 478 |
|
| 479 |
g_variant_builder_init (&details, G_VARIANT_TYPE ("a{ss}")); |
| 480 |
g_variant_builder_add (&details, "{ss}", "MailEnabled", "true"); |
| 481 |
g_variant_builder_add (&details, "{ss}", "CalendarEnabled", "true"); |
| 482 |
g_variant_builder_add (&details, "{ss}", "ContactsEnabled", "true"); |
| 483 |
g_variant_builder_add (&details, "{ss}", "Host", server); |
| 484 |
g_variant_builder_add (&details, "{ss}", "AcceptSslErrors", (data->accept_ssl_errors) ? "true" : "false"); |
| 485 |
|
| 486 |
goa_manager_call_add_account (goa_client_get_manager (data->client), |
| 487 |
goa_provider_get_provider_type (provider), |
| 488 |
username, |
| 489 |
email_address, |
| 490 |
g_variant_builder_end (&credentials), |
| 491 |
g_variant_builder_end (&details), |
| 492 |
cancellable, |
| 493 |
(GAsyncReadyCallback) add_account_credentials_cb, |
| 494 |
g_steal_pointer (&task)); |
| 495 |
} |
| 496 |
|
| 497 |
static void |
| 498 |
add_account_action_cb (GoaProviderDialog *dialog, |
| 499 |
GParamSpec *pspec, |
| 500 |
GTask *task) |
| 501 |
{ |
| 502 |
GoaProvider *provider = g_task_get_source_object (task); |
| 503 |
AddAccountData *data = g_task_get_task_data (task); |
| 504 |
GCancellable *cancellable = g_task_get_cancellable (task); |
| 505 |
g_autoptr(GoaEwsClient) ews_client = NULL; |
| 506 |
g_autoptr(GError) error = NULL; |
| 507 |
const char *email_address; |
| 508 |
const char *server; |
| 509 |
const char *password; |
| 510 |
const char *username; |
| 511 |
const char *provider_type; |
| 512 |
|
| 513 |
if (goa_provider_dialog_get_state (data->dialog) != GOA_DIALOG_BUSY) |
| 514 |
return; |
| 515 |
|
| 516 |
email_address = gtk_editable_get_text (GTK_EDITABLE (data->email_address)); |
| 517 |
password = gtk_editable_get_text (GTK_EDITABLE (data->password)); |
| 518 |
username = gtk_editable_get_text (GTK_EDITABLE (data->username)); |
| 519 |
server = gtk_editable_get_text (GTK_EDITABLE (data->server)); |
| 520 |
|
| 521 |
|
| 522 |
provider_type = goa_provider_get_provider_type (provider); |
| 523 |
if (!goa_utils_check_duplicate (data->client, |
| 524 |
username, |
| 525 |
email_address, |
| 526 |
provider_type, |
| 527 |
(GoaPeekInterfaceFunc) goa_object_peek_password_based, |
| 528 |
&error)) |
| 529 |
{ |
| 530 |
goa_provider_task_return_error (task, g_steal_pointer (&error)); |
| 531 |
return; |
| 532 |
} |
| 533 |
|
| 534 |
|
| 535 |
ews_client = goa_ews_client_new (); |
| 536 |
goa_ews_client_autodiscover (ews_client, |
| 537 |
email_address, |
| 538 |
password, |
| 539 |
username, |
| 540 |
server, |
| 541 |
data->accept_ssl_errors, |
| 542 |
cancellable, |
| 543 |
(GAsyncReadyCallback)add_account_autodiscover_cb, |
| 544 |
g_object_ref (task)); |
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
static void |
| 550 |
add_account (GoaProvider *provider, |
| 551 |
GoaClient *client, |
| 552 |
GtkWidget *parent, |
| 553 |
GCancellable *cancellable, |
| 554 |
GAsyncReadyCallback callback, |
| 555 |
gpointer user_data) |
| 556 |
{ |
| 557 |
AddAccountData *data; |
| 558 |
g_autoptr(GTask) task = NULL; |
| 559 |
|
| 560 |
data = g_new0 (AddAccountData, 1); |
| 561 |
data->dialog = goa_provider_dialog_new (provider, client, parent); |
| 562 |
data->client = g_object_ref (client); |
| 563 |
|
| 564 |
task = g_task_new (provider, cancellable, callback, user_data); |
| 565 |
g_task_set_check_cancellable (task, FALSE); |
| 566 |
g_task_set_source_tag (task, add_account); |
| 567 |
g_task_set_task_data (task, data, add_account_data_free); |
| 568 |
|
| 569 |
create_setup_page (provider, data, TRUE); |
| 570 |
g_signal_connect_object (data->dialog, |
| 571 |
"notify::state", |
| 572 |
G_CALLBACK (add_account_action_cb), |
| 573 |
task, |
| 574 |
G_CONNECT_DEFAULT); |
| 575 |
goa_provider_task_run_in_dialog (task, data->dialog); |
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
static void |
| 581 |
refresh_account_credentials_cb (GoaAccount *account, |
| 582 |
GAsyncResult *res, |
| 583 |
gpointer user_data) |
| 584 |
{ |
| 585 |
g_autoptr(GTask) task = G_TASK (g_steal_pointer (&user_data)); |
| 586 |
GError *error = NULL; |
| 587 |
|
| 588 |
if (!goa_account_call_ensure_credentials_finish (account, NULL, res, &error)) |
| 589 |
{ |
| 590 |
goa_provider_task_return_error (task, error); |
| 591 |
return; |
| 592 |
} |
| 593 |
|
| 594 |
g_task_return_boolean (task, TRUE); |
| 595 |
} |
| 596 |
|
| 597 |
static void |
| 598 |
refresh_account_autodiscover_cb (GoaEwsClient *client, |
| 599 |
GAsyncResult *res, |
| 600 |
gpointer user_data) |
| 601 |
{ |
| 602 |
g_autoptr(GTask) task = G_TASK (g_steal_pointer (&user_data)); |
| 603 |
GoaProvider *provider = g_task_get_source_object (task); |
| 604 |
AddAccountData *data = g_task_get_task_data (task); |
| 605 |
GCancellable *cancellable = g_task_get_cancellable (task); |
| 606 |
GVariantBuilder credentials; |
| 607 |
const gchar *password; |
| 608 |
g_autoptr(GError) error = NULL; |
| 609 |
|
| 610 |
if (!goa_ews_client_autodiscover_finish (client, res, &error)) |
| 611 |
{ |
| 612 |
data->accept_ssl_errors = (error->code == GOA_ERROR_SSL); |
| 613 |
goa_provider_dialog_report_error (data->dialog, error); |
| 614 |
return; |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
password = gtk_editable_get_text (GTK_EDITABLE (data->password)); |
| 619 |
|
| 620 |
g_variant_builder_init (&credentials, G_VARIANT_TYPE_VARDICT); |
| 621 |
g_variant_builder_add (&credentials, "{sv}", "password", g_variant_new_string (password)); |
| 622 |
|
| 623 |
|
| 624 |
if (!goa_utils_store_credentials_for_object_sync (provider, |
| 625 |
data->object, |
| 626 |
g_variant_builder_end (&credentials), |
| 627 |
g_task_get_cancellable (task), |
| 628 |
&error)) |
| 629 |
{ |
| 630 |
goa_provider_task_return_error (task, g_steal_pointer (&error)); |
| 631 |
return; |
| 632 |
} |
| 633 |
|
| 634 |
goa_account_call_ensure_credentials (goa_object_peek_account (data->object), |
| 635 |
cancellable, |
| 636 |
(GAsyncReadyCallback) refresh_account_credentials_cb, |
| 637 |
g_steal_pointer (&task)); |
| 638 |
} |
| 639 |
|
| 640 |
static void |
| 641 |
refresh_account_action_cb (GoaProviderDialog *dialog, |
| 642 |
GParamSpec *pspec, |
| 643 |
GTask *task) |
| 644 |
{ |
| 645 |
AddAccountData *data = g_task_get_task_data (task); |
| 646 |
GCancellable *cancellable = g_task_get_cancellable (task); |
| 647 |
GoaAccount *account; |
| 648 |
GoaExchange *exchange; |
| 649 |
g_autoptr(GoaEwsClient) ews_client = NULL; |
| 650 |
const char *email_address; |
| 651 |
const char *server; |
| 652 |
const char *password; |
| 653 |
const char *username; |
| 654 |
gboolean accept_ssl_errors; |
| 655 |
|
| 656 |
if (goa_provider_dialog_get_state (data->dialog) != GOA_DIALOG_BUSY) |
| 657 |
return; |
| 658 |
|
| 659 |
account = goa_object_peek_account (data->object); |
| 660 |
exchange = goa_object_peek_exchange (data->object); |
| 661 |
|
| 662 |
email_address = goa_account_get_presentation_identity (account); |
| 663 |
password = gtk_editable_get_text (GTK_EDITABLE (data->password)); |
| 664 |
username = goa_account_get_identity (account); |
| 665 |
server = goa_exchange_get_host (exchange); |
| 666 |
accept_ssl_errors = goa_exchange_get_accept_ssl_errors (exchange); |
| 667 |
|
| 668 |
gtk_editable_set_editable (GTK_EDITABLE (data->email_address), FALSE); |
| 669 |
gtk_editable_set_text (GTK_EDITABLE (data->email_address), email_address); |
| 670 |
|
| 671 |
|
| 672 |
ews_client = goa_ews_client_new (); |
| 673 |
goa_ews_client_autodiscover (ews_client, |
| 674 |
email_address, |
| 675 |
password, |
| 676 |
username, |
| 677 |
server, |
| 678 |
accept_ssl_errors, |
| 679 |
cancellable, |
| 680 |
(GAsyncReadyCallback) refresh_account_autodiscover_cb, |
| 681 |
g_steal_pointer (&task)); |
| 682 |
} |
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
static void |
| 687 |
refresh_account (GoaProvider *provider, |
| 688 |
GoaClient *client, |
| 689 |
GoaObject *object, |
| 690 |
GtkWidget *parent, |
| 691 |
GCancellable *cancellable, |
| 692 |
GAsyncReadyCallback callback, |
| 693 |
gpointer user_data) |
| 694 |
{ |
| 695 |
AddAccountData *data; |
| 696 |
g_autoptr(GTask) task = NULL; |
| 697 |
|
| 698 |
g_assert (GOA_IS_EXCHANGE_PROVIDER (provider)); |
| 699 |
g_assert (GOA_IS_CLIENT (client)); |
| 700 |
g_assert (GOA_IS_OBJECT (object)); |
| 701 |
g_assert (parent == NULL || GTK_IS_WIDGET (parent)); |
| 702 |
g_assert (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); |
| 703 |
|
| 704 |
data = g_new0 (AddAccountData, 1); |
| 705 |
data->dialog = goa_provider_dialog_new (provider, client, parent); |
| 706 |
data->client = g_object_ref (client); |
| 707 |
data->object = g_object_ref (object); |
| 708 |
|
| 709 |
task = g_task_new (provider, cancellable, callback, user_data); |
| 710 |
g_task_set_check_cancellable (task, FALSE); |
| 711 |
g_task_set_source_tag (task, refresh_account); |
| 712 |
g_task_set_task_data (task, data, add_account_data_free); |
| 713 |
|
| 714 |
create_setup_page (provider, data, FALSE); |
| 715 |
g_signal_connect_object (data->dialog, |
| 716 |
"notify::state", |
| 717 |
G_CALLBACK (refresh_account_action_cb), |
| 718 |
task, |
| 719 |
G_CONNECT_DEFAULT); |
| 720 |
goa_provider_task_run_in_dialog (task, data->dialog); |
| 721 |
} |
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
static void |
| 726 |
goa_exchange_provider_init (GoaExchangeProvider *self) |
| 727 |
{ |
| 728 |
} |
| 729 |
|
| 730 |
static void |
| 731 |
goa_exchange_provider_class_init (GoaExchangeProviderClass *klass) |
| 732 |
{ |
| 733 |
GoaProviderClass *provider_class; |
| 734 |
|
| 735 |
provider_class = GOA_PROVIDER_CLASS (klass); |
| 736 |
provider_class->get_provider_type = get_provider_type; |
| 737 |
provider_class->get_provider_name = get_provider_name; |
| 738 |
provider_class->get_provider_group = get_provider_group; |
| 739 |
provider_class->get_provider_features = get_provider_features; |
| 740 |
provider_class->add_account = add_account; |
| 741 |
provider_class->refresh_account = refresh_account; |
| 742 |
provider_class->build_object = build_object; |
| 743 |
provider_class->ensure_credentials_sync = ensure_credentials_sync; |
| 744 |
} |
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
static gboolean |
| 749 |
on_handle_get_password (GoaPasswordBased *interface, |
| 750 |
GDBusMethodInvocation *invocation, |
| 751 |
const gchar *id, |
| 752 |
gpointer user_data) |
| 753 |
{ |
| 754 |
GoaObject *object; |
| 755 |
GoaAccount *account; |
| 756 |
GoaProvider *provider; |
| 757 |
GError *error; |
| 758 |
const gchar *account_id; |
| 759 |
const gchar *method_name; |
| 760 |
const gchar *provider_type; |
| 761 |
gchar *password = NULL; |
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
object = GOA_OBJECT (g_dbus_interface_get_object (G_DBUS_INTERFACE (interface))); |
| 766 |
account = goa_object_peek_account (object); |
| 767 |
account_id = goa_account_get_id (account); |
| 768 |
provider_type = goa_account_get_provider_type (account); |
| 769 |
method_name = g_dbus_method_invocation_get_method_name (invocation); |
| 770 |
g_debug ("Handling %s for account (%s, %s)", method_name, provider_type, account_id); |
| 771 |
|
| 772 |
provider = goa_provider_get_for_provider_type (provider_type); |
| 773 |
|
| 774 |
error = NULL; |
| 775 |
if (!goa_utils_get_credentials (provider, object, "password", NULL, &password, NULL, &error)) |
| 776 |
{ |
| 777 |
g_dbus_method_invocation_take_error (invocation, error); |
| 778 |
goto out; |
| 779 |
} |
| 780 |
|
| 781 |
goa_password_based_complete_get_password (interface, invocation, password); |
| 782 |
|
| 783 |
out: |
| 784 |
g_free (password); |
| 785 |
g_object_unref (provider); |
| 786 |
return TRUE; |
| 787 |
} |