From 37292c9b2ed55e51f6f7923db0b3aec93e51b89c Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tristan.matthews@savoirfairelinux.com> Date: Mon, 26 Mar 2012 18:20:55 -0400 Subject: [PATCH] * #9490: store accountID, not account pointer in tree store. Only the accountlist should be storing account_t pointers. --- gnome/src/accountlist.c | 11 ++- gnome/src/actions.c | 11 +-- gnome/src/codeclist.c | 6 +- gnome/src/config/accountconfigdialog.c | 54 ++++++----- gnome/src/config/accountconfigdialog.h | 4 + gnome/src/config/accountlistconfigdialog.c | 102 +++++++++++---------- gnome/src/config/accountlistconfigdialog.h | 4 +- gnome/src/dbus/dbus.c | 5 +- gnome/src/logger.h | 9 +- 9 files changed, 108 insertions(+), 98 deletions(-) diff --git a/gnome/src/accountlist.c b/gnome/src/accountlist.c index 44c79b011b..62df3498b2 100644 --- a/gnome/src/accountlist.c +++ b/gnome/src/accountlist.c @@ -75,6 +75,8 @@ static gint get_state_struct(gconstpointer a, gconstpointer b) void account_list_init() { + if (accountQueue) + account_list_free(); accountQueue = g_queue_new(); } @@ -199,6 +201,7 @@ void account_list_free() { g_queue_foreach(accountQueue, account_list_free_elm, NULL); g_queue_free(accountQueue); + accountQueue = NULL; } void @@ -225,7 +228,7 @@ account_list_get_registered_accounts(void) guint res = 0; for (guint i = 0; i < account_list_get_size(); i++) - if (account_list_get_nth(i) -> state == (ACCOUNT_STATE_REGISTERED)) + if (account_list_get_nth(i)->state == (ACCOUNT_STATE_REGISTERED)) res++; return res; @@ -321,7 +324,7 @@ account_t *create_default_account() { account_t *account = g_new0(account_t, 1); account->properties = dbus_get_account_details(NULL); - account->accountID = g_strdup("new"); //FIXME : replace with NULL for new accounts + account->accountID = g_strdup("new"); // FIXME: maybe replace with NULL? account->credential_information = NULL; sflphone_fill_codec_list_per_account(account); return account; @@ -341,16 +344,18 @@ void initialize_credential_information(account_t *account) void account_replace(account_t *account, const gchar *key, const gchar *value) { + g_assert(account && account->properties); g_hash_table_replace(account->properties, g_strdup(key), g_strdup(value)); } void account_insert(account_t *account, const gchar *key, const gchar *value) { + g_assert(account && account->properties); g_hash_table_insert(account->properties, g_strdup(key), g_strdup(value)); } gpointer account_lookup(const account_t *account, gconstpointer key) { - g_assert(account->properties); + g_assert(account && account->properties); return g_hash_table_lookup(account->properties, key); } diff --git a/gnome/src/actions.c b/gnome/src/actions.c index fb385e924b..f0dd5a0218 100644 --- a/gnome/src/actions.c +++ b/gnome/src/actions.c @@ -57,6 +57,7 @@ #include "actions.h" #include "dbus/dbus.h" #include "logger.h" +#include "config/accountlistconfigdialog.h" #include "contacts/calltab.h" #include "contacts/searchbar.h" #include "contacts/addrbookfactory.h" @@ -202,12 +203,8 @@ sflphone_hung_up(callable_obj_t * c) statusbar_update_clock(""); } -/** Internal to actions: Fill account list */ void sflphone_fill_account_list(void) { - int count = current_account_get_message_number(); - - account_list_free(); account_list_init(); gchar **array = dbus_account_list(); @@ -224,7 +221,7 @@ void sflphone_fill_account_list(void) } for (unsigned i = 0; i < account_list_get_size(); i++) { - account_t * a = account_list_get_nth(i); + account_t *a = account_list_get_nth(i); if (a == NULL) { ERROR("SFLphone: Error: Could not find account %d in list", i); @@ -278,9 +275,10 @@ void sflphone_fill_account_list(void) } // Set the current account message number - current_account_set_message_number(count); + current_account_set_message_number(current_account_get_message_number()); sflphone_fill_codec_list(); + account_store_fill(); } gboolean sflphone_init(GError **error) @@ -297,7 +295,6 @@ gboolean sflphone_init(GError **error) contacts_tab = calltab_init(TRUE, CONTACTS); history_tab = calltab_init(TRUE, HISTORY); - account_list_init(); codec_capabilities_load(); conferencelist_init(current_calls_tab); diff --git a/gnome/src/codeclist.c b/gnome/src/codeclist.c index 9a83e5f42d..6662cfe018 100644 --- a/gnome/src/codeclist.c +++ b/gnome/src/codeclist.c @@ -217,7 +217,7 @@ void codec_list_update_to_daemon(const account_t *acc) int c = 0; int i; - for (i = 0; i < length; i++) { + for (i = 0; i < length; ++i) { codec_t* currentCodec = codec_list_get_nth(i, acc->codecs); if (currentCodec) { @@ -240,14 +240,14 @@ void codec_list_update_to_daemon(const account_t *acc) // Allocate NULL array at the end for Dbus codecList = (void*) g_realloc(codecList, (c + 1) * sizeof(void*)); - *(codecList+c) = NULL; + *(codecList + c) = NULL; // call dbus function with array of strings dbus_set_active_audio_codec_list(codecList, acc->accountID); // Delete memory for (i = 0; i < c; i++) - g_free((gchar*) *(codecList+i)); + g_free((gchar*) *(codecList + i) ); g_free(codecList); } diff --git a/gnome/src/config/accountconfigdialog.c b/gnome/src/config/accountconfigdialog.c index 8acc9c5d8c..703d24f9fe 100644 --- a/gnome/src/config/accountconfigdialog.c +++ b/gnome/src/config/accountconfigdialog.c @@ -206,7 +206,7 @@ static GtkWidget* create_basic_tab(const account_t *account) password = g_hash_table_lookup(element, ACCOUNT_PASSWORD); } } else - password = g_hash_table_lookup(account->properties, ACCOUNT_PASSWORD); + password = account_lookup(account, ACCOUNT_PASSWORD); GtkWidget *frame = gnome_main_section_new(_("Account Parameters")); gtk_widget_show(frame); @@ -214,7 +214,7 @@ static GtkWidget* create_basic_tab(const account_t *account) GtkWidget *table = NULL; if (account_is_SIP(account)) - table = gtk_table_new(9, 2, FALSE/* homogeneous */); + table = gtk_table_new(9, 2, FALSE /* homogeneous */); else if (account_is_IAX(account)) table = gtk_table_new(8, 2, FALSE); else { @@ -234,7 +234,7 @@ static GtkWidget* create_basic_tab(const account_t *account) gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); entry_alias = gtk_entry_new(); gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry_alias); - gchar *alias = g_hash_table_lookup(account->properties, ACCOUNT_ALIAS); + gchar *alias = account_lookup(account, ACCOUNT_ALIAS); gtk_entry_set_text(GTK_ENTRY(entry_alias), alias); gtk_table_attach(GTK_TABLE(table), entry_alias, 1, 2, row, row + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); @@ -276,8 +276,7 @@ static GtkWidget* create_basic_tab(const account_t *account) gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); entry_hostname = gtk_entry_new(); gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry_hostname); - const gchar *hostname = g_hash_table_lookup(account->properties, - ACCOUNT_HOSTNAME); + const gchar *hostname = account_lookup(account, ACCOUNT_HOSTNAME); gtk_entry_set_text(GTK_ENTRY(entry_hostname), hostname); gtk_table_attach(GTK_TABLE(table), entry_hostname, 1, 2, row, row + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); @@ -293,7 +292,7 @@ static GtkWidget* create_basic_tab(const account_t *account) GTK_ENTRY_ICON_PRIMARY, gdk_pixbuf_new_from_file(PERSON_IMG, NULL)); gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry_username); - gchar *username = g_hash_table_lookup(account->properties, ACCOUNT_USERNAME); + gchar *username = account_lookup(account, ACCOUNT_USERNAME); gtk_entry_set_text(GTK_ENTRY(entry_username), username); gtk_table_attach(GTK_TABLE(table), entry_username, 1, 2, row, row + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); @@ -337,7 +336,7 @@ static GtkWidget* create_basic_tab(const account_t *account) gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); entry_route_set = gtk_entry_new(); gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry_route_set); - gchar *route_set = g_hash_table_lookup(account->properties, ACCOUNT_ROUTE); + gchar *route_set = account_lookup(account, ACCOUNT_ROUTE); gtk_entry_set_text(GTK_ENTRY(entry_route_set), route_set); gtk_table_attach(GTK_TABLE(table), entry_route_set, 1, 2, row, row+1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); @@ -347,7 +346,7 @@ static GtkWidget* create_basic_tab(const account_t *account) gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); entry_mailbox = gtk_entry_new(); gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry_mailbox); - gchar *mailbox = g_hash_table_lookup(account->properties, ACCOUNT_MAILBOX); + gchar *mailbox = account_lookup(account, ACCOUNT_MAILBOX); mailbox = mailbox ? mailbox : ""; gtk_entry_set_text(GTK_ENTRY(entry_mailbox), mailbox); gtk_table_attach(GTK_TABLE(table), entry_mailbox, 1, 2, row, row+1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); @@ -358,7 +357,7 @@ static GtkWidget* create_basic_tab(const account_t *account) gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); entry_user_agent = gtk_entry_new(); gtk_label_set_mnemonic_widget(GTK_LABEL(label), entry_user_agent); - gchar *user_agent = g_hash_table_lookup(account->properties, ACCOUNT_USERAGENT); + gchar *user_agent = account_lookup(account, ACCOUNT_USERAGENT); gtk_entry_set_text(GTK_ENTRY(entry_user_agent), user_agent); gtk_table_attach(GTK_TABLE(table), entry_user_agent, 1, 2, row, row+1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); @@ -726,17 +725,16 @@ create_security_widget(const account_t *account) // Load from SIP/IAX/Unknown ? if (account && account->properties) { - curKeyExchange = g_hash_table_lookup(account->properties, - ACCOUNT_KEY_EXCHANGE); + curKeyExchange = account_lookup(account, ACCOUNT_KEY_EXCHANGE); if (curKeyExchange == NULL) curKeyExchange = "none"; - curSRTPEnabled = g_hash_table_lookup(account->properties, ACCOUNT_SRTP_ENABLED); + curSRTPEnabled = account_lookup(account, ACCOUNT_SRTP_ENABLED); if (curSRTPEnabled == NULL) curSRTPEnabled = "false"; - curTLSEnabled = g_hash_table_lookup(account->properties, TLS_ENABLE); + curTLSEnabled = account_lookup(account, TLS_ENABLE); if (curTLSEnabled == NULL) curTLSEnabled = "false"; @@ -854,8 +852,8 @@ create_network(const account_t *account) gchar *local_port = NULL; if (account) { - local_interface = g_hash_table_lookup(account->properties, LOCAL_INTERFACE); - local_port = g_hash_table_lookup(account->properties, LOCAL_PORT); + local_interface = account_lookup(account, LOCAL_INTERFACE); + local_port = account_lookup(account, LOCAL_PORT); } GtkWidget *table, *frame; @@ -922,20 +920,20 @@ GtkWidget* create_published_address(const account_t *account) // Get the user configuration if (account) { - use_tls = g_hash_table_lookup(account->properties, TLS_ENABLE); - published_sameas_local = g_hash_table_lookup(account->properties, PUBLISHED_SAMEAS_LOCAL); + use_tls = account_lookup(account, TLS_ENABLE); + published_sameas_local = account_lookup(account, PUBLISHED_SAMEAS_LOCAL); if (utf8_case_equal(published_sameas_local, "true")) { - published_address = dbus_get_address_from_interface_name(g_hash_table_lookup(account->properties, LOCAL_INTERFACE)); - published_port = g_hash_table_lookup(account->properties, LOCAL_PORT); + published_address = dbus_get_address_from_interface_name(account_lookup(account, LOCAL_INTERFACE)); + published_port = account_lookup(account, LOCAL_PORT); } else { - published_address = g_hash_table_lookup(account->properties, PUBLISHED_ADDRESS); - published_port = g_hash_table_lookup(account->properties, PUBLISHED_PORT); + published_address = account_lookup(account, PUBLISHED_ADDRESS); + published_port = account_lookup(account, PUBLISHED_PORT); } - stun_enable = g_hash_table_lookup(account->properties, ACCOUNT_SIP_STUN_ENABLED); - stun_server = g_hash_table_lookup(account->properties, ACCOUNT_SIP_STUN_SERVER); - published_sameas_local = g_hash_table_lookup(account->properties, PUBLISHED_SAMEAS_LOCAL); + stun_enable = account_lookup(account, ACCOUNT_SIP_STUN_ENABLED); + stun_server = account_lookup(account, ACCOUNT_SIP_STUN_SERVER); + published_sameas_local = account_lookup(account, PUBLISHED_SAMEAS_LOCAL); } gnome_main_section_new_with_table(_("Published address"), &frame, &table, 2, 3); @@ -1061,7 +1059,7 @@ create_audiocodecs_configuration(const account_t *account) gtk_widget_show(dtmf); overrtp = gtk_radio_button_new_with_label(NULL, _("RTP")); - const gchar * const dtmf_type = g_hash_table_lookup(account->properties, ACCOUNT_DTMF_TYPE); + const gchar * const dtmf_type = account_lookup(account, ACCOUNT_DTMF_TYPE); const gboolean dtmf_are_rtp = utf8_case_equal(dtmf_type, OVERRTP); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(overrtp), dtmf_are_rtp); gtk_table_attach(GTK_TABLE(table), overrtp, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); @@ -1079,7 +1077,7 @@ create_audiocodecs_configuration(const account_t *account) file_chooser = gtk_file_chooser_button_new(_("Choose a ringtone"), GTK_FILE_CHOOSER_ACTION_OPEN); - gpointer ptr = g_hash_table_lookup(account->properties, CONFIG_RINGTONE_ENABLED); + gpointer ptr = account_lookup(account, CONFIG_RINGTONE_ENABLED); enable_tone = gtk_check_button_new_with_mnemonic(_("_Enable ringtones")); const gboolean ringtone_enabled = g_strcmp0(ptr, "true") == 0; gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enable_tone), ringtone_enabled); @@ -1088,7 +1086,7 @@ create_audiocodecs_configuration(const account_t *account) // file chooser button gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_chooser) , g_get_home_dir()); - ptr = g_hash_table_lookup(account->properties, CONFIG_RINGTONE_PATH); + ptr = account_lookup(account, CONFIG_RINGTONE_PATH); gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(file_chooser) , ptr); gtk_widget_set_sensitive(file_chooser, ringtone_enabled); @@ -1315,7 +1313,7 @@ void show_account_window(account_t *account) update_account_from_basic_tab(account); /** @todo Verify if it's the best condition to check */ - if (utf8_case_equal(account->accountID, "new")) + if (g_strcmp0(account->accountID, "new")) dbus_add_account(account); else dbus_set_account_details(account); diff --git a/gnome/src/config/accountconfigdialog.h b/gnome/src/config/accountconfigdialog.h index 1683b269c2..0b4611525f 100644 --- a/gnome/src/config/accountconfigdialog.h +++ b/gnome/src/config/accountconfigdialog.h @@ -43,4 +43,8 @@ */ void show_account_window(account_t *a); +/** + * Resets local cache of account pointers */ +void reset_account_store(); + #endif diff --git a/gnome/src/config/accountlistconfigdialog.c b/gnome/src/config/accountlistconfigdialog.c index 31de47d48c..0953b51fee 100644 --- a/gnome/src/config/accountlistconfigdialog.c +++ b/gnome/src/config/accountlistconfigdialog.c @@ -52,7 +52,7 @@ static GtkWidget *move_up_button; static GtkWidget *status_bar; static GtkListStore *account_store; static GtkDialog *account_list_dialog; -static account_t *selected_account; +static gchar *selected_accountID; // Account properties enum { @@ -60,15 +60,16 @@ enum { COLUMN_ACCOUNT_TYPE, COLUMN_ACCOUNT_STATUS, COLUMN_ACCOUNT_ACTIVE, - COLUMN_ACCOUNT_DATA, + COLUMN_ACCOUNT_ID, COLUMN_ACCOUNT_COUNT }; static void delete_account_cb(void) { - RETURN_IF_NULL(selected_account, "No selected account in delete action"); - dbus_remove_account(selected_account->accountID); - selected_account = NULL; + RETURN_IF_NULL(selected_accountID, "No selected account in delete action"); + dbus_remove_account(selected_accountID); + g_free(selected_accountID); + selected_accountID = NULL; } static void row_activated_cb(GtkTreeView *view UNUSED, @@ -76,16 +77,16 @@ static void row_activated_cb(GtkTreeView *view UNUSED, GtkTreeViewColumn *col UNUSED, gpointer user_data UNUSED) { - RETURN_IF_NULL(selected_account, "No selected account in edit action"); - DEBUG("%s: accountID=%s\n", __PRETTY_FUNCTION__, selected_account->accountID); - show_account_window(selected_account); + RETURN_IF_NULL(selected_accountID, "No selected account in edit action"); + DEBUG("%s: Selected accountID=%s\n", __PRETTY_FUNCTION__, selected_accountID); + show_account_window(account_list_get_by_id(selected_accountID)); } static void edit_account_cb(GtkButton *button UNUSED, gpointer data UNUSED) { - RETURN_IF_NULL(selected_account, "No selected account in edit action"); - DEBUG("%s: accountID=%s\n", __PRETTY_FUNCTION__, selected_account->accountID); - show_account_window(selected_account); + RETURN_IF_NULL(selected_accountID, "No selected account in edit action"); + DEBUG("%s: Selected accountID=%s\n", __PRETTY_FUNCTION__, selected_accountID); + show_account_window(account_list_get_by_id(selected_accountID)); } static void add_account_cb(void) @@ -94,38 +95,46 @@ static void add_account_cb(void) show_account_window(new_account); } -static void account_store_fill(GtkTreeIter *iter, account_t *a) +static void account_store_add(GtkTreeIter *iter, account_t *account) { - const gchar *enabled = g_hash_table_lookup(a->properties, ACCOUNT_ENABLED); - const gchar *type = g_hash_table_lookup(a->properties, ACCOUNT_TYPE); - DEBUG("Config: Filling accounts: Account is enabled :%s", enabled); + const gchar *enabled = account_lookup(account, ACCOUNT_ENABLED); + const gchar *type = account_lookup(account, ACCOUNT_TYPE); + DEBUG("Config: Adding account: Account is enabled :%s", enabled); gtk_list_store_set(account_store, iter, COLUMN_ACCOUNT_ALIAS, - g_hash_table_lookup(a->properties, ACCOUNT_ALIAS), + account_lookup(account, ACCOUNT_ALIAS), COLUMN_ACCOUNT_TYPE, type, - COLUMN_ACCOUNT_STATUS, account_state_name(a->state), + COLUMN_ACCOUNT_STATUS, account_state_name(account->state), COLUMN_ACCOUNT_ACTIVE, utf8_case_equal(enabled, "true"), - COLUMN_ACCOUNT_DATA, a, -1); + COLUMN_ACCOUNT_ID, account->accountID, -1); +} + +static void +invalidate_selected_accountID() +{ + if (selected_accountID) { + g_free(selected_accountID); + selected_accountID = NULL; + } } /** * Fills the treelist with accounts */ -void account_list_config_dialog_fill() +void account_store_fill() { + invalidate_selected_accountID(); RETURN_IF_NULL(account_list_dialog, "No account dialog"); - gtk_list_store_clear(account_store); // IP2IP account must be first - account_t *ip2ip = account_list_get_by_id("IP2IP"); - + account_t *ip2ip = account_list_get_by_id(IP2IP_PROFILE); RETURN_IF_NULL(ip2ip, "Could not find IP2IP account"); GtkTreeIter iter; gtk_list_store_append(account_store, &iter); - account_store_fill(&iter, ip2ip); + account_store_add(&iter, ip2ip); for (size_t i = 0; i < account_list_get_size(); ++i) { account_t *a = account_list_get_nth(i); @@ -134,7 +143,7 @@ void account_list_config_dialog_fill() // we don't want to process the IP2IP twice if (a != ip2ip) { gtk_list_store_append(account_store, &iter); - account_store_fill(&iter, a); + account_store_add(&iter, a); } } } @@ -147,7 +156,7 @@ select_account_cb(GtkTreeSelection *selection, GtkTreeModel *model) { GtkTreeIter iter; if (!gtk_tree_selection_get_selected(selection, &model, &iter)) { - selected_account = NULL; + invalidate_selected_accountID(); gtk_widget_set_sensitive(move_up_button, FALSE); gtk_widget_set_sensitive(move_down_button, FALSE); gtk_widget_set_sensitive(edit_button, FALSE); @@ -158,13 +167,14 @@ select_account_cb(GtkTreeSelection *selection, GtkTreeModel *model) // The Gvalue will be initialized in the following function GValue val; memset(&val, 0, sizeof(val)); - gtk_tree_model_get_value(model, &iter, COLUMN_ACCOUNT_DATA, &val); + gtk_tree_model_get_value(model, &iter, COLUMN_ACCOUNT_ID, &val); - selected_account = (account_t*) g_value_get_pointer(&val); + selected_accountID = g_strdup(g_value_get_string(&val)); g_value_unset(&val); + DEBUG("Selected account has accountID %s", selected_accountID); + account_t *selected_account = account_list_get_by_id(selected_accountID); RETURN_IF_NULL(selected_account, "Selected account is NULL"); - DEBUG("Selected account has accountID %s", selected_account->accountID); gtk_widget_set_sensitive(edit_button, TRUE); @@ -208,7 +218,7 @@ enable_account_cb(GtkCellRendererToggle *rend UNUSED, gchar* path, gpointer data) { // The IP2IP profile can't be disabled - if (utf8_case_equal(path, "0")) + if (g_strcmp0(path, "0") == 0) return; // Get pointer on object @@ -217,9 +227,11 @@ enable_account_cb(GtkCellRendererToggle *rend UNUSED, gchar* path, GtkTreeIter iter; gtk_tree_model_get_iter(model, &iter, tree_path); gboolean enable; - account_t* acc; + gchar * id; gtk_tree_model_get(model, &iter, COLUMN_ACCOUNT_ACTIVE, &enable, - COLUMN_ACCOUNT_DATA, &acc, -1); + COLUMN_ACCOUNT_ID, &id, -1); + account_t *account = account_list_get_by_id(id); + g_assert(account); enable = !enable; DEBUG("Account is %d enabled", enable); @@ -228,13 +240,11 @@ enable_account_cb(GtkCellRendererToggle *rend UNUSED, gchar* path, enable, -1); // Modify account state - gchar * registration_state = enable ? g_strdup("true") : g_strdup("false"); + const gchar * registration_state = enable ? "true" : "false"; DEBUG("Replacing registration state with %s", registration_state); - g_hash_table_replace(acc->properties, g_strdup(ACCOUNT_ENABLED), - registration_state); - - dbus_send_register(acc->accountID, enable); + account_replace(account, ACCOUNT_ENABLED, registration_state); + dbus_send_register(account->accountID, enable); } /** @@ -259,7 +269,7 @@ account_move(gboolean move_up, gpointer data) // The first real account in the list can't move up because of the IP2IP account // It can still move down though - if (utf8_case_equal(path, "1") && move_up) + if (g_strcmp0(path, "1") == 0 && move_up) return; GtkTreePath *tree_path = gtk_tree_path_new_from_string(path); @@ -343,13 +353,12 @@ highlight_ip_profile(GtkTreeViewColumn *col UNUSED, GtkCellRenderer *rend, { GValue val; memset(&val, 0, sizeof(val)); - gtk_tree_model_get_value(tree_model, iter, COLUMN_ACCOUNT_DATA, &val); - account_t *current = (account_t*) g_value_get_pointer(&val); - + gtk_tree_model_get_value(tree_model, iter, COLUMN_ACCOUNT_ID, &val); + account_t *current = account_list_get_by_id(g_value_get_string(&val)); g_value_unset(&val); - if (current != NULL) { - // Make the first line appear differently + // Make the IP2IP account appear differently + if (current) { if (account_is_IP2IP(current)) { g_object_set(G_OBJECT(rend), "weight", PANGO_WEIGHT_THIN, "style", PANGO_STYLE_ITALIC, "stretch", @@ -381,8 +390,8 @@ highlight_registration(GtkTreeViewColumn *col UNUSED, GtkCellRenderer *rend, { GValue val; memset(&val, 0, sizeof(val)); - gtk_tree_model_get_value(tree_model, iter, COLUMN_ACCOUNT_DATA, &val); - account_t *current = (account_t*) g_value_get_pointer(&val); + gtk_tree_model_get_value(tree_model, iter, COLUMN_ACCOUNT_ID, &val); + account_t *current = account_list_get_by_id(g_value_get_string(&val)); g_value_unset(&val); if (current) @@ -395,7 +404,6 @@ highlight_registration(GtkTreeViewColumn *col UNUSED, GtkCellRenderer *rend, static GtkWidget* create_account_list() { - selected_account = NULL; GtkWidget *table = gtk_table_new(1, 2, FALSE /* homogeneous */); gtk_table_set_col_spacings(GTK_TABLE(table), 10); gtk_container_set_border_width(GTK_CONTAINER(table), 10); @@ -413,10 +421,10 @@ create_account_list() G_TYPE_STRING, // Protocol G_TYPE_STRING, // Status G_TYPE_BOOLEAN, // Enabled / Disabled - G_TYPE_POINTER // Pointer to the Object + G_TYPE_STRING // AccountID ); - account_list_config_dialog_fill(); + account_store_fill(); GtkTreeView * tree_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(account_store))); GtkTreeSelection *tree_selection = gtk_tree_view_get_selection(tree_view); diff --git a/gnome/src/config/accountlistconfigdialog.h b/gnome/src/config/accountlistconfigdialog.h index 40e58526db..8e206054ed 100644 --- a/gnome/src/config/accountlistconfigdialog.h +++ b/gnome/src/config/accountlistconfigdialog.h @@ -32,9 +32,7 @@ #ifndef __SFL_ACCOUNTLISTDIALOG_H__ #define __SFL_ACCOUNTLISTDIALOG_H__ -#include <sflphone_const.h> - void show_account_list_config_dialog(void); -void account_list_config_dialog_fill(void); +void account_store_fill(void); #endif diff --git a/gnome/src/dbus/dbus.c b/gnome/src/dbus/dbus.c index e68d445591..c3ee84d693 100644 --- a/gnome/src/dbus/dbus.c +++ b/gnome/src/dbus/dbus.c @@ -38,7 +38,6 @@ #include "configurationmanager-glue.h" #include "instance-glue.h" #include "preferencesdialog.h" -#include "accountlistconfigdialog.h" #include "mainwindow.h" #include "marshaller.h" #include "sliders.h" @@ -427,7 +426,6 @@ accounts_changed_cb(DBusGProxy *proxy UNUSED, void *foo UNUSED) { sflphone_fill_account_list(); sflphone_fill_ip2ip_profile(); - account_list_config_dialog_fill(); status_bar_display_account(); statusicon_set_tooltip(); } @@ -1096,7 +1094,8 @@ dbus_add_account(account_t *a) g_assert(a->properties); DEBUG("Adding %s account", a->accountID); GError *error = NULL; - g_free(a->accountID); + if (a->accountID) + g_free(a->accountID); a->accountID = NULL; org_sflphone_SFLphone_ConfigurationManager_add_account(config_proxy, a->properties, &a->accountID, &error); diff --git a/gnome/src/logger.h b/gnome/src/logger.h index a5020c8228..330503be82 100644 --- a/gnome/src/logger.h +++ b/gnome/src/logger.h @@ -28,8 +28,8 @@ * as that of the covered work. */ -#ifndef __LOGGER_H -#define __LOGGER_H +#ifndef LOGGER_H_ +#define LOGGER_H_ void internal_log (const int level, const char* format, ...); void set_log_level (const int level); @@ -44,7 +44,8 @@ void set_log_level (const int level); #define INFO(...) internal_log(LOG_INFO, __VA_ARGS__) #define DEBUG(...) internal_log(LOG_DEBUG, __VA_ARGS__) +/* Prints an error message and returns if the pointer A is NULL */ #define RETURN_IF_NULL(A, M, ...) \ - if ((A) == NULL) { ERROR(M, ##__VA_ARGS__); return; } + if (!(A)) { ERROR(M, ##__VA_ARGS__); return; } -#endif +#endif // LOGGER_H_ -- GitLab