diff options
author | Felix Kaser <f.kaser@gmx.net> | 2010-01-09 20:22:55 +0800 |
---|---|---|
committer | Felix Kaser <f.kaser@gmx.net> | 2010-01-11 22:36:34 +0800 |
commit | 9dd268d147b52e7bcb1beaebf3ab5fd13cf5e73a (patch) | |
tree | 3cbc240871fb6aad132278f6a22eb687b03ee4d3 /src | |
parent | a4f5f649d912e3726b568fd7e67ded887f92587b (diff) | |
download | gsoc2013-empathy-9dd268d147b52e7bcb1beaebf3ab5fd13cf5e73a.tar gsoc2013-empathy-9dd268d147b52e7bcb1beaebf3ab5fd13cf5e73a.tar.gz gsoc2013-empathy-9dd268d147b52e7bcb1beaebf3ab5fd13cf5e73a.tar.bz2 gsoc2013-empathy-9dd268d147b52e7bcb1beaebf3ab5fd13cf5e73a.tar.lz gsoc2013-empathy-9dd268d147b52e7bcb1beaebf3ab5fd13cf5e73a.tar.xz gsoc2013-empathy-9dd268d147b52e7bcb1beaebf3ab5fd13cf5e73a.tar.zst gsoc2013-empathy-9dd268d147b52e7bcb1beaebf3ab5fd13cf5e73a.zip |
remember handler ids to prevent double invokation
the handler ids for the status-changed signals are remembered to prevent registration more than once on newly created accounts
Diffstat (limited to 'src')
-rw-r--r-- | src/empathy-main-window.c | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index e77ab9e3e..2f1e077f4 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -113,6 +113,10 @@ typedef struct { guint size_timeout_id; GHashTable *errors; + /* stores a mapping from TpAccount to Handler ID to prevent + * to listen more than once to the status-changed signal */ + GHashTable *status_changed_handlers; + /* Actions that are enabled when there are connected accounts */ GList *actions_connected; } EmpathyMainWindow; @@ -625,6 +629,9 @@ static void main_window_destroy_cb (GtkWidget *widget, EmpathyMainWindow *window) { + GHashTableIter iter; + gpointer key, value; + /* Save user-defined accelerators. */ main_window_accels_save (); @@ -634,6 +641,14 @@ main_window_destroy_cb (GtkWidget *widget, g_object_unref (window->list_store); g_hash_table_destroy (window->errors); + /* disconnect all handlers of status-changed signal */ + g_hash_table_iter_init (&iter, window->status_changed_handlers); + while (g_hash_table_iter_next (&iter, &key, &value)) + g_signal_handler_disconnect (TP_ACCOUNT (key), + GPOINTER_TO_UINT (value)); + + g_hash_table_destroy (window->status_changed_handlers); + g_signal_handlers_disconnect_by_func (window->event_manager, main_window_event_added_cb, window); @@ -1133,9 +1148,19 @@ main_window_account_validity_changed_cb (TpAccountManager *manager, EmpathyMainWindow *window) { if (valid) { - g_signal_connect (account, "status-changed", - G_CALLBACK (main_window_connection_changed_cb), - window); + gulong handler_id; + handler_id = GPOINTER_TO_UINT (g_hash_table_lookup ( + window->status_changed_handlers, account)); + + /* connect signal only if it was not connected yet */ + if (handler_id == 0) { + handler_id = g_signal_connect (account, + "status-changed", + G_CALLBACK (main_window_connection_changed_cb), + window); + g_hash_table_insert (window->status_changed_handlers, + account, GUINT_TO_POINTER (handler_id)); + } } main_window_account_removed_cb (manager, account, window); @@ -1201,10 +1226,13 @@ account_manager_prepared_cb (GObject *source_object, accounts = tp_account_manager_get_valid_accounts (window->account_manager); for (j = accounts; j != NULL; j = j->next) { TpAccount *account = TP_ACCOUNT (j->data); + gulong handler_id; - g_signal_connect (account, "status-changed", + handler_id = g_signal_connect (account, "status-changed", G_CALLBACK (main_window_connection_changed_cb), window); + g_hash_table_insert (window->status_changed_handlers, + account, GUINT_TO_POINTER (handler_id)); } g_signal_connect (manager, "account-validity-changed", @@ -1312,6 +1340,11 @@ empathy_main_window_show (void) g_object_unref, NULL); + window->status_changed_handlers = g_hash_table_new_full (g_direct_hash, + g_direct_equal, + NULL, + NULL); + /* Set up menu */ main_window_favorite_chatroom_menu_setup (window); |