Commit 454d6502 authored by Tristan Matthews's avatar Tristan Matthews

* #9490: gnome: fixed account remove

parent c9ab5d02
......@@ -33,6 +33,7 @@
#include "str_utils.h"
#include "dbus.h"
#include "accountlist.h"
#include "logger.h"
#include "actions.h"
#include "unused.h"
......@@ -229,6 +230,13 @@ const gchar* account_list_get_current_id(void)
return NULL;
}
void account_list_remove(const gchar *accountID)
{
account_t *target = account_list_get_by_id(accountID);
if (target && !g_queue_remove(accountQueue, target))
ERROR("Could not remove account with ID %s", accountID);
}
gchar * account_list_get_ordered_list(void)
{
gchar *order = strdup("");
......
......@@ -195,5 +195,6 @@ void initialize_credential_information(account_t *account);
void account_replace(account_t *account, const gchar *key, const gchar *value);
void account_insert(account_t *account, const gchar *key, const gchar *value);
gpointer account_lookup(const account_t *account, gconstpointer key);
void account_list_remove(const gchar *accountID);
#endif
......@@ -417,7 +417,6 @@ delete_credential_cb(GtkWidget *button UNUSED, gpointer data)
GtkTreePath *path;
path = gtk_tree_model_get_path(model, &iter);
gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
gtk_tree_path_free(path);
}
}
......@@ -1254,15 +1253,18 @@ void update_account_from_dialog(GtkWidget *dialog, account_t *account)
account->credential_information = get_new_credential();
/** @todo Verify if it's the best condition to check */
if (g_strcmp0(account->accountID, "new") == 0)
if (g_strcmp0(account->accountID, "new") == 0) {
dbus_add_account(account);
else
if (account->credential_information)
dbus_set_credentials(account);
} else {
if (account->credential_information)
dbus_set_credentials(account);
dbus_set_account_details(account);
}
// propagate changes to the daemon
codec_list_update_to_daemon(account);
if (account->credential_information)
dbus_set_credentials(account);
g_free(current_protocol);
gtk_widget_destroy(dialog);
......
......@@ -83,10 +83,34 @@ get_selected_accountID(GtkTreeView *tree_view)
return selected_accountID;
}
static void delete_account_cb(gpointer data)
static gboolean
find_account_in_account_store(const gchar *accountID, GtkTreeModel *model,
GtkTreeIter *iter)
{
gboolean valid = gtk_tree_model_get_iter_first(model, iter);
gboolean found = FALSE;
while (valid && !found) {
gchar *id;
gtk_tree_model_get(model, iter, COLUMN_ACCOUNT_ID, &id, -1);
if (g_strcmp0(id, accountID) == 0)
found = TRUE;
else
valid = gtk_tree_model_iter_next(model, iter);
g_free(id);
}
return found;
}
static void delete_account_cb(GtkButton *button UNUSED, gpointer data)
{
gchar *selected_accountID = get_selected_accountID(data);
RETURN_IF_NULL(selected_accountID, "No selected account in delete action");
GtkTreeModel *model = GTK_TREE_MODEL(account_store);
GtkTreeIter iter;
if (find_account_in_account_store(selected_accountID, model, &iter))
gtk_list_store_remove(account_store, &iter);
dbus_remove_account(selected_accountID);
g_free(selected_accountID);
}
......@@ -511,8 +535,8 @@ create_account_list()
delete_button = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
gtk_widget_set_sensitive(delete_button, FALSE);
g_signal_connect_swapped(G_OBJECT(delete_button), "clicked",
G_CALLBACK(delete_account_cb), tree_view);
g_signal_connect(G_OBJECT(delete_button), "clicked",
G_CALLBACK(delete_account_cb), tree_view);
gtk_box_pack_start(GTK_BOX(button_box), delete_button, FALSE, FALSE, 0);
/* help and close buttons */
......@@ -573,21 +597,11 @@ void update_account_list_status_bar(account_t *account)
gtk_statusbar_push(GTK_STATUSBAR(account_list_status_bar),
CONTEXT_ID_REGISTRATION, state_name);
}
GtkTreeModel *model = GTK_TREE_MODEL(account_store);
GtkTreeIter iter;
gboolean looking = gtk_tree_model_get_iter_first(model, &iter);
while (looking) {
gchar *id;
gtk_tree_model_get(model, &iter, COLUMN_ACCOUNT_ID, &id, -1);
if (g_strcmp0(id, account->accountID) == 0) {
gtk_list_store_set(account_store, &iter, COLUMN_ACCOUNT_STATUS,
state_name, -1);
looking = FALSE;
} else {
looking = gtk_tree_model_iter_next(model, &iter);
}
g_free(id);
}
if (find_account_in_account_store(account->accountID, model, &iter))
gtk_list_store_set(account_store, &iter, COLUMN_ACCOUNT_STATUS, state_name, -1);
}
void show_account_list_config_dialog(void)
......
......@@ -1096,6 +1096,7 @@ dbus_remove_account(const gchar *accountID)
{
GError *error = NULL;
org_sflphone_SFLphone_ConfigurationManager_remove_account(config_proxy, accountID, &error);
account_list_remove(accountID);
check_error(error);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment