static gboolean on_account_handle_remove (GoaAccount *account, GDBusMethodInvocation *invocation, gpointer user_data) { GoaDaemon *daemon = GOA_DAEMON (user_data); GoaProvider *provider; GKeyFile *key_file; const gchar *provider_type; gchar *path; gchar *group; gchar *data; gsize length; GError *error; provider = NULL; provider_type = NULL; path = NULL; group = NULL; key_file = NULL; data = NULL; /* update key-file - right now we only support removing the account * if the entry is in ~/.config/goa-1.0/accounts.conf */ key_file = g_key_file_new (); path = g_strdup_printf ("%s/goa-1.0/accounts.conf", g_get_user_config_dir ()); error = NULL; if (!g_key_file_load_from_file (key_file, path, G_KEY_FILE_KEEP_COMMENTS, &error)) { g_dbus_method_invocation_return_gerror (invocation, error); g_error_free (error); goto out; } group = g_strdup_printf ("Account %s", goa_account_get_id (account)); error = NULL; if (!g_key_file_remove_group (key_file, group, &error)) { g_dbus_method_invocation_return_gerror (invocation, error); g_error_free (error); goto out; } error = NULL; data = g_key_file_to_data (key_file, &length, &error); if (data == NULL) { g_prefix_error (&error, "Error generating key-value-file: "); g_dbus_method_invocation_return_gerror (invocation, error); goto out; } error = NULL; if (!g_file_set_contents (path, data, length, &error)) { g_prefix_error (&error, "Error writing key-value-file %s: ", path); g_dbus_method_invocation_return_gerror (invocation, error); goto out; } provider_type = goa_account_get_provider_type (account); if (provider_type == NULL) { error = NULL; g_set_error_literal (&error, GOA_ERROR, GOA_ERROR_FAILED, /* TODO: more specific */ _("ProviderType property is not set for account")); g_dbus_method_invocation_return_gerror (invocation, error); goto out; } provider = goa_provider_get_for_provider_type (provider_type); if (provider == NULL) { error = NULL; g_set_error (&error, GOA_ERROR, GOA_ERROR_FAILED, /* TODO: more specific */ _("Failed to find a provider for: %s"), provider_type); g_dbus_method_invocation_return_gerror (invocation, error); goto out; } error = NULL; if (!goa_utils_delete_credentials_sync (provider, account, NULL, &error)) { g_dbus_method_invocation_return_gerror (invocation, error); goto out; } goa_daemon_reload_configuration (daemon); goa_account_complete_remove (account, invocation); out: if (provider != NULL) g_object_unref (provider); g_free (data); if (key_file != NULL) g_key_file_free (key_file); g_free (group); g_free (path); return TRUE; /* invocation was handled */ }
static gboolean on_account_handle_remove (GoaAccount *account, GDBusMethodInvocation *invocation, gpointer user_data) { GoaDaemon *daemon = GOA_DAEMON (user_data); GKeyFile *key_file; gchar *path; gchar *group; gchar *data; gsize length; GError *error; path = NULL; group = NULL; key_file = NULL; data = NULL; /* update key-file - right now we only support removing the account * if the entry is in ~/.config/goa-1.0/accounts.conf */ key_file = g_key_file_new (); path = g_strdup_printf ("%s/goa-1.0/accounts.conf", g_get_user_config_dir ()); error = NULL; if (!g_key_file_load_from_file (key_file, path, G_KEY_FILE_KEEP_COMMENTS, &error)) { g_dbus_method_invocation_return_gerror (invocation, error); g_error_free (error); goto out; } group = g_strdup_printf ("Account %s", goa_account_get_id (account)); error = NULL; if (!g_key_file_remove_group (key_file, group, &error)) { g_dbus_method_invocation_return_gerror (invocation, error); g_error_free (error); goto out; } error = NULL; data = g_key_file_to_data (key_file, &length, &error); if (data == NULL) { g_prefix_error (&error, "Error generating key-value-file: "); g_dbus_method_invocation_return_gerror (invocation, error); goto out; } error = NULL; if (!g_file_set_contents (path, data, length, &error)) { g_prefix_error (&error, "Error writing key-value-file %s: ", path); g_dbus_method_invocation_return_gerror (invocation, error); goto out; } goa_daemon_reload_configuration (daemon); goa_account_complete_remove (account, invocation); out: g_free (data); if (key_file != NULL) g_key_file_free (key_file); g_free (group); g_free (path); return TRUE; /* invocation was handled */ }