gboolean goa_utils_check_duplicate (GoaClient *client, const gchar *identity, const gchar *presentation_identity, const gchar *provider_type, GoaPeekInterfaceFunc func, GError **error) { GList *accounts; GList *l; gboolean ret; ret = FALSE; accounts = goa_client_get_accounts (client); for (l = accounts; l != NULL; l = l->next) { GoaObject *object = GOA_OBJECT (l->data); GoaAccount *account; gpointer *interface; const gchar *identity_from_object; const gchar *presentation_identity_from_object; const gchar *provider_type_from_object; account = goa_object_peek_account (object); interface = (*func) (object); if (interface == NULL) continue; provider_type_from_object = goa_account_get_provider_type (account); if (g_strcmp0 (provider_type_from_object, provider_type) != 0) continue; identity_from_object = goa_account_get_identity (account); presentation_identity_from_object = goa_account_get_presentation_identity (account); if (g_strcmp0 (identity_from_object, identity) == 0 && g_strcmp0 (presentation_identity_from_object, presentation_identity) == 0) { const gchar *provider_name; provider_name = goa_account_get_provider_name (account); g_set_error (error, GOA_ERROR, GOA_ERROR_ACCOUNT_EXISTS, _("A %s account already exists for %s"), provider_name, presentation_identity); goto out; } } ret = TRUE; out: g_list_free_full (accounts, g_object_unref); return ret; }
static void sync_provider_widget (ProviderWidget *provider_widget) { gboolean has_account = (provider_widget->displayed_account != NULL); gtk_widget_set_visible (provider_widget->checkmark, has_account); gtk_widget_set_visible (provider_widget->account_label, has_account); gtk_widget_set_sensitive (provider_widget->row, !has_account); if (has_account) { char *markup; markup = g_strdup_printf ("<small><span foreground=\"#555555\">%s</span></small>", goa_account_get_presentation_identity (provider_widget->displayed_account)); gtk_label_set_markup (GTK_LABEL (provider_widget->account_label), markup); g_free (markup); } }
static void set_values (GoaPanelAccountsModel *model, GoaObject *object, GtkTreeIter *iter) { GoaAccount *account; GIcon *icon; gchar *markup; GError *error; account = goa_object_peek_account (object); error = NULL; icon = g_icon_new_for_string (goa_account_get_provider_icon (account), &error); if (icon == NULL) { goa_warning ("Error creating GIcon for account: %s (%s, %d)", error->message, g_quark_to_string (error->domain), error->code); g_error_free (error); } markup = g_strdup_printf ("<b>%s</b>\n<small>%s</small>", goa_account_get_provider_name (account), goa_account_get_presentation_identity (account)); gtk_list_store_set (GTK_LIST_STORE (model), iter, GOA_PANEL_ACCOUNTS_MODEL_COLUMN_SORT_KEY, goa_account_get_id (account), GOA_PANEL_ACCOUNTS_MODEL_COLUMN_OBJECT, object, GOA_PANEL_ACCOUNTS_MODEL_COLUMN_ATTENTION_NEEDED, goa_account_get_attention_needed (account), GOA_PANEL_ACCOUNTS_MODEL_COLUMN_MARKUP, markup, GOA_PANEL_ACCOUNTS_MODEL_COLUMN_ICON, icon, -1); g_free (markup); g_clear_object (&icon); }
static gboolean build_object (GoaProvider *provider, GoaObjectSkeleton *object, GKeyFile *key_file, const gchar *group, GDBusConnection *connection, gboolean just_added, GError **error) { GoaAccount *account; GoaCalendar *calendar; GoaContacts *contacts; GoaExchange *exchange; GoaMail *mail; GoaPasswordBased *password_based; gboolean calendar_enabled; gboolean contacts_enabled; gboolean mail_enabled; gboolean ret; account = NULL; calendar = NULL; contacts = NULL; exchange = NULL; mail = NULL; password_based = NULL; ret = FALSE; /* Chain up */ if (!GOA_PROVIDER_CLASS (goa_exchange_provider_parent_class)->build_object (provider, object, key_file, group, connection, just_added, error)) goto out; password_based = goa_object_get_password_based (GOA_OBJECT (object)); if (password_based == NULL) { password_based = goa_password_based_skeleton_new (); /* Ensure D-Bus method invocations run in their own thread */ g_dbus_interface_skeleton_set_flags (G_DBUS_INTERFACE_SKELETON (password_based), G_DBUS_INTERFACE_SKELETON_FLAGS_HANDLE_METHOD_INVOCATIONS_IN_THREAD); goa_object_skeleton_set_password_based (object, password_based); g_signal_connect (password_based, "handle-get-password", G_CALLBACK (on_handle_get_password), NULL); } account = goa_object_get_account (GOA_OBJECT (object)); /* Email */ mail = goa_object_get_mail (GOA_OBJECT (object)); mail_enabled = g_key_file_get_boolean (key_file, group, "MailEnabled", NULL); if (mail_enabled) { if (mail == NULL) { const gchar *email_address; email_address = goa_account_get_presentation_identity (account); mail = goa_mail_skeleton_new (); g_object_set (G_OBJECT (mail), "email-address", email_address, NULL); goa_object_skeleton_set_mail (object, mail); } } else { if (mail != NULL) goa_object_skeleton_set_mail (object, NULL); } /* Calendar */ calendar = goa_object_get_calendar (GOA_OBJECT (object)); calendar_enabled = g_key_file_get_boolean (key_file, group, "CalendarEnabled", NULL); if (calendar_enabled) { if (calendar == NULL) { calendar = goa_calendar_skeleton_new (); goa_object_skeleton_set_calendar (object, calendar); } } else { if (calendar != NULL) goa_object_skeleton_set_calendar (object, NULL); } /* Contacts */ contacts = goa_object_get_contacts (GOA_OBJECT (object)); contacts_enabled = g_key_file_get_boolean (key_file, group, "ContactsEnabled", NULL); if (contacts_enabled) { if (contacts == NULL) { contacts = goa_contacts_skeleton_new (); goa_object_skeleton_set_contacts (object, contacts); } } else { if (contacts != NULL) goa_object_skeleton_set_contacts (object, NULL); } /* Exchange */ exchange = goa_object_get_exchange (GOA_OBJECT (object)); if (exchange == NULL) { gchar *host; host = g_key_file_get_string (key_file, group, "Host", NULL); exchange = goa_exchange_skeleton_new (); g_object_set (G_OBJECT (exchange), "host", host, NULL); goa_object_skeleton_set_exchange (object, exchange); g_free (host); } if (just_added) { goa_account_set_mail_disabled (account, !mail_enabled); goa_account_set_calendar_disabled (account, !calendar_enabled); goa_account_set_contacts_disabled (account, !contacts_enabled); g_signal_connect (account, "notify::mail-disabled", G_CALLBACK (goa_util_account_notify_property_cb), "MailEnabled"); g_signal_connect (account, "notify::calendar-disabled", G_CALLBACK (goa_util_account_notify_property_cb), "CalendarEnabled"); g_signal_connect (account, "notify::contacts-disabled", G_CALLBACK (goa_util_account_notify_property_cb), "ContactsEnabled"); } ret = TRUE; out: if (exchange != NULL) g_object_unref (exchange); if (contacts != NULL) g_object_unref (contacts); if (calendar != NULL) g_object_unref (calendar); if (mail != NULL) g_object_unref (mail); if (password_based != NULL) g_object_unref (password_based); return ret; }
static gboolean refresh_account (GoaProvider *provider, GoaClient *client, GoaObject *object, GtkWindow *parent, GError **error) { AddAccountData data; GVariantBuilder builder; GoaAccount *account; GoaEwsClient *ews_client; GoaExchange *exchange; GtkWidget *dialog; GtkWidget *vbox; gboolean accept_ssl_errors; gboolean ret; const gchar *email_address; const gchar *server; const gchar *password; const gchar *username; gint response; g_return_val_if_fail (GOA_IS_EXCHANGE_PROVIDER (provider), FALSE); g_return_val_if_fail (GOA_IS_CLIENT (client), FALSE); g_return_val_if_fail (GOA_IS_OBJECT (object), FALSE); g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); ews_client = NULL; ret = FALSE; dialog = gtk_dialog_new_with_buttons (NULL, parent, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); gtk_container_set_border_width (GTK_CONTAINER (dialog), 12); gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); gtk_box_set_spacing (GTK_BOX (vbox), 12); memset (&data, 0, sizeof (AddAccountData)); data.loop = g_main_loop_new (NULL, FALSE); data.dialog = GTK_DIALOG (dialog); data.error = NULL; create_account_details_ui (provider, GTK_DIALOG (dialog), GTK_BOX (vbox), FALSE, &data); account = goa_object_peek_account (object); email_address = goa_account_get_presentation_identity (account); gtk_entry_set_text (GTK_ENTRY (data.email_address), email_address); gtk_editable_set_editable (GTK_EDITABLE (data.email_address), FALSE); gtk_widget_show_all (dialog); ews_client = goa_ews_client_new (); ews_again: response = gtk_dialog_run (GTK_DIALOG (dialog)); if (response != GTK_RESPONSE_OK) { g_set_error (error, GOA_ERROR, GOA_ERROR_DIALOG_DISMISSED, _("Dialog was dismissed")); goto out; } password = gtk_entry_get_text (GTK_ENTRY (data.password)); username = goa_account_get_identity (account); exchange = goa_object_peek_exchange (object); accept_ssl_errors = goa_util_lookup_keyfile_boolean (object, "AcceptSslErrors"); server = goa_exchange_get_host (exchange); goa_ews_client_autodiscover (ews_client, email_address, password, username, server, accept_ssl_errors, NULL, autodiscover_cb, &data); goa_spinner_button_start (GOA_SPINNER_BUTTON (data.spinner_button)); g_main_loop_run (data.loop); if (data.error != NULL) { GtkWidget *button; gchar *markup; markup = g_strdup_printf ("<b>%s:</b> %s", _("Error connecting to Microsoft Exchange server"), data.error->message); g_clear_error (&data.error); gtk_label_set_markup (GTK_LABEL (data.cluebar_label), markup); g_free (markup); button = gtk_dialog_get_widget_for_response (data.dialog, GTK_RESPONSE_OK); gtk_button_set_label (GTK_BUTTON (button), _("_Try Again")); gtk_widget_set_no_show_all (data.cluebar, FALSE); gtk_widget_show_all (data.cluebar); goto ews_again; } /* TODO: run in worker thread */ g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); g_variant_builder_add (&builder, "{sv}", "password", g_variant_new_string (password)); if (!goa_utils_store_credentials_for_object_sync (provider, object, g_variant_builder_end (&builder), NULL, /* GCancellable */ error)) goto out; goa_account_call_ensure_credentials (account, NULL, /* GCancellable */ NULL, NULL); /* callback, user_data */ ret = TRUE; out: gtk_widget_destroy (dialog); if (data.loop != NULL) g_main_loop_unref (data.loop); if (ews_client != NULL) g_object_unref (ews_client); return ret; }
static gboolean ensure_credentials_sync (GoaProvider *provider, GoaObject *object, gint *out_expires_in, GCancellable *cancellable, GError **error) { GVariant *credentials; GoaAccount *account; GoaEwsClient *ews_client; GoaExchange *exchange; gboolean accept_ssl_errors; gboolean ret; const gchar *email_address; const gchar *server; const gchar *username; gchar *password; credentials = NULL; ews_client = NULL; password = NULL; ret = FALSE; credentials = goa_utils_lookup_credentials_sync (provider, object, cancellable, error); if (credentials == NULL) { if (error != NULL) { g_prefix_error (error, _("Credentials not found in keyring (%s, %d): "), g_quark_to_string ((*error)->domain), (*error)->code); (*error)->domain = GOA_ERROR; (*error)->code = GOA_ERROR_NOT_AUTHORIZED; } goto out; } account = goa_object_peek_account (object); email_address = goa_account_get_presentation_identity (account); username = goa_account_get_identity (account); if (!g_variant_lookup (credentials, "password", "s", &password)) { if (error != NULL) { *error = g_error_new (GOA_ERROR, GOA_ERROR_NOT_AUTHORIZED, _("Did not find password with username `%s' in credentials"), username); } goto out; } exchange = goa_object_peek_exchange (object); accept_ssl_errors = goa_util_lookup_keyfile_boolean (object, "AcceptSslErrors"); server = goa_exchange_get_host (exchange); ews_client = goa_ews_client_new (); ret = goa_ews_client_autodiscover_sync (ews_client, email_address, password, username, server, accept_ssl_errors, cancellable, error); if (!ret) { if (error != NULL) { g_prefix_error (error, /* Translators: the first %s is the username * (eg., [email protected] or rishi), and the * (%s, %d) is the error domain and code. */ _("Invalid password with username `%s' (%s, %d): "), username, g_quark_to_string ((*error)->domain), (*error)->code); (*error)->domain = GOA_ERROR; (*error)->code = GOA_ERROR_NOT_AUTHORIZED; } goto out; } if (out_expires_in != NULL) *out_expires_in = 0; out: if (ews_client != NULL) g_object_unref (ews_client); g_free (password); if (credentials != NULL) g_variant_unref (credentials); return ret; }