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
1=== modified file 'src/indicator-approver.c'
2--- src/indicator-approver.c 2014-04-10 18:15:31 +0000
3+++ src/indicator-approver.c 2014-04-17 12:38:28 +0000
4@@ -35,7 +35,7 @@
5 GHashTable *dispatch_ops;
6 static gint n_sources;
7 UnityLauncherEntry *launcher = NULL;
8-GList *conns;
9+GHashTable *conns; /* connection object -> set of mmapp ids for that connection */
10 TpBaseClient *approver;
11 TpBaseClient *observer;
12
13@@ -57,30 +57,51 @@
14 }
15 }
16
17+void
18+remember_id_for_connection (TpConnection *con,
19+ const gchar *id)
20+{
21+ GHashTable *ids;
22+
23+ ids = g_hash_table_lookup (conns, con);
24+ if (ids != NULL)
25+ g_hash_table_add (ids, g_strdup (id));
26+ else
27+ g_warning ("%s: never seen chanel '%s' before", G_STRFUNC, id);
28+}
29+
30 static gchar *
31 channel_id (TpChannel *channel)
32 {
33 TpConnection *con;
34+ gchar *id;
35
36 con = tp_channel_get_connection (channel);
37-
38- return g_strconcat ("channel:",
39- tp_proxy_get_object_path (TP_PROXY (con)), ":",
40- tp_proxy_get_object_path (TP_PROXY (channel)),
41- NULL);
42+ id = g_strconcat ("channel:",
43+ tp_proxy_get_object_path (TP_PROXY (con)), ":",
44+ tp_proxy_get_object_path (TP_PROXY (channel)),
45+ NULL);
46+
47+ remember_id_for_connection (con, id);
48+
49+ return id;
50 }
51
52 static gchar *
53 contact_id (TpContact *contact)
54 {
55 TpConnection *con;
56+ gchar *id;
57
58 con = tp_contact_get_connection (contact);
59-
60- return g_strconcat ("contact:",
61- tp_proxy_get_object_path (TP_PROXY (con)), ":",
62- tp_contact_get_identifier (contact),
63- NULL);
64+ id = g_strconcat ("contact:",
65+ tp_proxy_get_object_path (TP_PROXY (con)), ":",
66+ tp_contact_get_identifier (contact),
67+ NULL);
68+
69+ remember_id_for_connection (con, id);
70+
71+ return id;
72 }
73
74 static void
75@@ -680,8 +701,7 @@
76 conn_invalidated_cb (TpConnection *conn, guint domain, gint code, gchar *message, gpointer user_data)
77 {
78 g_debug ("conn_invalidated_cb");
79- conns = g_list_remove (conns, conn);
80- g_object_unref (conn);
81+ g_hash_table_remove (conns, conn);
82 }
83
84 static void
85@@ -760,12 +780,13 @@
86 if (connection == NULL)
87 return;
88
89- if (g_list_find (conns, connection) != NULL)
90+ if (g_hash_table_contains (conns, connection))
91 return;
92
93 g_debug ("account_manager_prepared_cb %s", tp_connection_get_cm_name (connection));
94
95- conns = g_list_prepend (conns, g_object_ref (connection));
96+ g_hash_table_insert (conns, g_object_ref (connection),
97+ g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL));
98
99 tp_g_signal_connect_object (connection, "contact-list-changed",
100 G_CALLBACK (contact_list_changed_cb), manager, 0);
101@@ -1092,6 +1113,29 @@
102 }
103
104 static void
105+free_ids_hash (gpointer data)
106+{
107+ GHashTable *ids = data;
108+
109+ if (mmapp)
110+ {
111+ GHashTableIter iter;
112+ gpointer id;
113+
114+ g_hash_table_iter_init (&iter, ids);
115+ while (g_hash_table_iter_next (&iter, &id, NULL))
116+ {
117+ messaging_menu_app_remove_source (mmapp, id);
118+ --n_sources;
119+ }
120+
121+ update_launcher (n_sources);
122+ }
123+
124+ g_hash_table_unref (ids);
125+}
126+
127+static void
128 empathy_appeared (GDBusConnection *connection,
129 const gchar *name,
130 const gchar *name_owner,
131@@ -1101,6 +1145,7 @@
132 TpConnectionPresenceType presence;
133
134 mmapp = messaging_menu_app_new ("empathy.desktop");
135+ conns = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, free_ids_hash);
136
137 if (check_enabled_accounts ())
138 messaging_menu_app_register (mmapp);
139@@ -1126,6 +1171,7 @@
140
141 g_clear_object (&launcher);
142 g_clear_object (&mmapp);
143+ g_clear_pointer (&conns, g_hash_table_unref);
144 }
145
146 int

Subscribers

People subscribed via source and target branches

to all changes: