Merge lp:~larsu/telepathy-indicator/lp1302930 into lp:telepathy-indicator

Proposed by Lars Karlitski
Status: Merged
Approved by: Charles Kerr
Approved revision: 80
Merged at revision: 79
Proposed branch: lp:~larsu/telepathy-indicator/lp1302930
Merge into: lp:telepathy-indicator
Diff against target: 146 lines (+61/-15)
1 file modified
src/indicator-approver.c (+61/-15)
To merge this branch: bzr merge lp:~larsu/telepathy-indicator/lp1302930
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Ted Gould (community) Approve
Review via email: mp+215855@code.launchpad.net

Commit message

Remove source when a connection dies

Description of the change

Remove source when a connection dies

Keep a hashtable mapping connections to all sources that are associated with that connection. When the connection dies, remove those sources.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ted Gould (ted) wrote :

Seems like we should be able to call update_launcher() once after removing all the items. Not critical, but seems like it would be better.

Top approve if you want to land as-is.

review: Approve
80. By Lars Karlitski

Don't unnecessarily call update_launcher()

Revision history for this message
Lars Karlitski (larsu) wrote :

Good catch, thanks. Fixed in r80.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Housekeeping: top-approving based on ted's approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/indicator-approver.c'
--- src/indicator-approver.c 2014-04-10 18:15:31 +0000
+++ src/indicator-approver.c 2014-04-17 12:38:28 +0000
@@ -35,7 +35,7 @@
35GHashTable *dispatch_ops;35GHashTable *dispatch_ops;
36static gint n_sources;36static gint n_sources;
37UnityLauncherEntry *launcher = NULL;37UnityLauncherEntry *launcher = NULL;
38GList *conns;38GHashTable *conns; /* connection object -> set of mmapp ids for that connection */
39TpBaseClient *approver;39TpBaseClient *approver;
40TpBaseClient *observer;40TpBaseClient *observer;
4141
@@ -57,30 +57,51 @@
57 }57 }
58}58}
5959
60void
61remember_id_for_connection (TpConnection *con,
62 const gchar *id)
63{
64 GHashTable *ids;
65
66 ids = g_hash_table_lookup (conns, con);
67 if (ids != NULL)
68 g_hash_table_add (ids, g_strdup (id));
69 else
70 g_warning ("%s: never seen chanel '%s' before", G_STRFUNC, id);
71}
72
60static gchar *73static gchar *
61channel_id (TpChannel *channel)74channel_id (TpChannel *channel)
62{75{
63 TpConnection *con;76 TpConnection *con;
77 gchar *id;
6478
65 con = tp_channel_get_connection (channel);79 con = tp_channel_get_connection (channel);
6680 id = g_strconcat ("channel:",
67 return g_strconcat ("channel:",81 tp_proxy_get_object_path (TP_PROXY (con)), ":",
68 tp_proxy_get_object_path (TP_PROXY (con)), ":",82 tp_proxy_get_object_path (TP_PROXY (channel)),
69 tp_proxy_get_object_path (TP_PROXY (channel)),83 NULL);
70 NULL);84
85 remember_id_for_connection (con, id);
86
87 return id;
71}88}
7289
73static gchar *90static gchar *
74contact_id (TpContact *contact)91contact_id (TpContact *contact)
75{92{
76 TpConnection *con;93 TpConnection *con;
94 gchar *id;
7795
78 con = tp_contact_get_connection (contact);96 con = tp_contact_get_connection (contact);
7997 id = g_strconcat ("contact:",
80 return g_strconcat ("contact:",98 tp_proxy_get_object_path (TP_PROXY (con)), ":",
81 tp_proxy_get_object_path (TP_PROXY (con)), ":",99 tp_contact_get_identifier (contact),
82 tp_contact_get_identifier (contact),100 NULL);
83 NULL);101
102 remember_id_for_connection (con, id);
103
104 return id;
84}105}
85106
86static void107static void
@@ -680,8 +701,7 @@
680conn_invalidated_cb (TpConnection *conn, guint domain, gint code, gchar *message, gpointer user_data)701conn_invalidated_cb (TpConnection *conn, guint domain, gint code, gchar *message, gpointer user_data)
681{702{
682 g_debug ("conn_invalidated_cb");703 g_debug ("conn_invalidated_cb");
683 conns = g_list_remove (conns, conn);704 g_hash_table_remove (conns, conn);
684 g_object_unref (conn);
685}705}
686706
687static void707static void
@@ -760,12 +780,13 @@
760 if (connection == NULL)780 if (connection == NULL)
761 return;781 return;
762782
763 if (g_list_find (conns, connection) != NULL)783 if (g_hash_table_contains (conns, connection))
764 return;784 return;
765785
766 g_debug ("account_manager_prepared_cb %s", tp_connection_get_cm_name (connection));786 g_debug ("account_manager_prepared_cb %s", tp_connection_get_cm_name (connection));
767787
768 conns = g_list_prepend (conns, g_object_ref (connection));788 g_hash_table_insert (conns, g_object_ref (connection),
789 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL));
769790
770 tp_g_signal_connect_object (connection, "contact-list-changed",791 tp_g_signal_connect_object (connection, "contact-list-changed",
771 G_CALLBACK (contact_list_changed_cb), manager, 0);792 G_CALLBACK (contact_list_changed_cb), manager, 0);
@@ -1092,6 +1113,29 @@
1092}1113}
10931114
1094static void1115static void
1116free_ids_hash (gpointer data)
1117{
1118 GHashTable *ids = data;
1119
1120 if (mmapp)
1121 {
1122 GHashTableIter iter;
1123 gpointer id;
1124
1125 g_hash_table_iter_init (&iter, ids);
1126 while (g_hash_table_iter_next (&iter, &id, NULL))
1127 {
1128 messaging_menu_app_remove_source (mmapp, id);
1129 --n_sources;
1130 }
1131
1132 update_launcher (n_sources);
1133 }
1134
1135 g_hash_table_unref (ids);
1136}
1137
1138static void
1095empathy_appeared (GDBusConnection *connection,1139empathy_appeared (GDBusConnection *connection,
1096 const gchar *name,1140 const gchar *name,
1097 const gchar *name_owner,1141 const gchar *name_owner,
@@ -1101,6 +1145,7 @@
1101 TpConnectionPresenceType presence;1145 TpConnectionPresenceType presence;
11021146
1103 mmapp = messaging_menu_app_new ("empathy.desktop");1147 mmapp = messaging_menu_app_new ("empathy.desktop");
1148 conns = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, free_ids_hash);
11041149
1105 if (check_enabled_accounts ())1150 if (check_enabled_accounts ())
1106 messaging_menu_app_register (mmapp);1151 messaging_menu_app_register (mmapp);
@@ -1126,6 +1171,7 @@
11261171
1127 g_clear_object (&launcher);1172 g_clear_object (&launcher);
1128 g_clear_object (&mmapp);1173 g_clear_object (&mmapp);
1174 g_clear_pointer (&conns, g_hash_table_unref);
1129}1175}
11301176
1131int1177int

Subscribers

People subscribed via source and target branches

to all changes: