Merge lp:~ken-vandine/telepathy-indicator/lp_1046360 into lp:telepathy-indicator

Proposed by Ken VanDine on 2012-10-10
Status: Merged
Approved by: Ken VanDine on 2012-10-11
Approved revision: 66
Merged at revision: 62
Proposed branch: lp:~ken-vandine/telepathy-indicator/lp_1046360
Merge into: lp:telepathy-indicator
Diff against target: 148 lines (+91/-12)
1 file modified
src/indicator-approver.c (+91/-12)
To merge this branch: bzr merge lp:~ken-vandine/telepathy-indicator/lp_1046360
Reviewer Review Type Date Requested Status
Lars Karlitski (community) 2012-10-10 Approve on 2012-10-11
Review via email: mp+129039@code.launchpad.net

Description of the change

don't register with messaging menu unless we have enabled IM accounts

To post a comment you must log in.
Lars Karlitski (larsu) wrote :

Works, but has a memory leak in check_enabled_accounts:

tp_account_manager_dup_valid_accounts returns a list of reffed TpAccounts. Instead of using g_list_free, the returned list should be freed with

  g_list_free_full (account_list, g_object_unref)

to unref the contained accounts.

Also, the `g_list_free (account_service_list)` can be removed, it doesn't free anything (account_service_list is NULL after the loop has run through).

Thanks!

review: Needs Fixing
66. By Ken VanDine on 2012-10-11

fixed a leak

Ken VanDine (ken-vandine) wrote :

OK, I've updated the branch per your feedback. Thanks!

Lars Karlitski (larsu) wrote :

Great, thanks!

review: 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 2012-08-27 14:18:16 +0000
3+++ src/indicator-approver.c 2012-10-11 13:21:24 +0000
4@@ -777,6 +777,16 @@
5 g_debug ("account_enabled_cb");
6
7 add_account (account, manager);
8+ if (valid == TRUE)
9+ {
10+ messaging_menu_app_register (mmapp);
11+ return;
12+ }
13+ if (!check_enabled_accounts ())
14+ {
15+ messaging_menu_app_unregister (mmapp);
16+ }
17+
18 }
19
20 static void
21@@ -978,20 +988,64 @@
22 tp_account_manager_set_all_requested_presences (tp_am, status, "", "");
23 }
24
25-int
26-main (int argc, char **argv)
27-{
28- GMainLoop *loop = NULL;
29+gboolean check_enabled_accounts ()
30+{
31+ gboolean r = FALSE;
32+ TpAccountManager* tp_am = tp_account_manager_dup ();
33+ GList* account_service_list = NULL;
34+ GList* account_list = tp_account_manager_dup_valid_accounts (tp_am);
35+
36+ for (account_service_list = account_list; account_service_list != NULL; account_service_list = account_service_list->next) {
37+ TpAccount* account = NULL;
38+ account = (TpAccount*) account_service_list->data;
39+ if (tp_account_is_enabled (account))
40+ {
41+ g_debug ("ENABLED: %s", tp_account_get_cm_name (account));
42+ r = TRUE;
43+ } else
44+ {
45+ g_debug ("DISABLED: %s", tp_account_get_cm_name (account));
46+ }
47+ }
48+
49+ g_list_free_full (account_list, g_object_unref);
50+ g_object_unref(G_OBJECT(tp_am));
51+ return r;
52+}
53+
54+static void on_enabled_event (TpAccountManager* self, TpAccount* account, gpointer user_data)
55+{
56+ g_debug ("on_enabled_event");
57+ messaging_menu_app_register (mmapp);
58+}
59+
60+static void on_disabled_event (TpAccountManager* self, TpAccount* account, gpointer user_data)
61+{
62+ g_debug ("on_disabled_event");
63+ if (!check_enabled_accounts ())
64+ {
65+ messaging_menu_app_unregister (mmapp);
66+ }
67+}
68+
69+
70+static void on_account_removed_event (TpAccountManager* self, TpAccount* account, gpointer user_data)
71+{
72+ g_debug ("on_account_removed_event");
73+ if (!check_enabled_accounts ())
74+ {
75+ messaging_menu_app_unregister (mmapp);
76+ }
77+}
78+
79+
80+int setup ()
81+{
82 TpConnectionPresenceType presence;
83
84- g_type_init ();
85-
86- gtk_init (&argc, &argv);
87 TpBaseClient *approver;
88 TpBaseClient *observer;
89
90- loop = g_main_loop_new (NULL, FALSE);
91-
92 TpAccountManager *tp_am = tp_account_manager_dup ();
93
94 approver = approver_setup (tp_am);
95@@ -1008,7 +1062,6 @@
96 }
97
98 mmapp = messaging_menu_app_new ("empathy.desktop");
99- messaging_menu_app_register (mmapp);
100
101 g_signal_connect (mmapp, "activate-source",
102 G_CALLBACK (message_source_activated), tp_am);
103@@ -1019,17 +1072,43 @@
104 presence_changed (tp_am, presence, "", "", NULL);
105 g_signal_connect(tp_am, "most-available-presence-changed",
106 G_CALLBACK (presence_changed), NULL);
107+ g_signal_connect (tp_am, "account-enabled",
108+ G_CALLBACK (on_enabled_event), NULL);
109+ g_signal_connect (tp_am, "account-disabled",
110+ G_CALLBACK (on_disabled_event), NULL);
111+ g_signal_connect (tp_am, "account-removed",
112+ G_CALLBACK (on_account_removed_event), NULL);
113
114 dispatch_ops = g_hash_table_new_full (g_str_hash, g_str_equal,
115 g_free, g_object_unref);
116-
117 launcher = unity_launcher_entry_get_for_desktop_id ("empathy.desktop");
118
119 contact_list_setup (tp_am);
120+}
121+
122+
123+int
124+main (int argc, char **argv)
125+{
126+ int ret = 0;
127+ GMainLoop *loop = NULL;
128+ g_type_init ();
129+ gtk_init (&argc, &argv);
130+
131+ loop = g_main_loop_new (NULL, FALSE);
132+
133+ ret = setup ();
134+ if (ret == 1)
135+ return ret;
136+
137+ if (check_enabled_accounts ())
138+ {
139+ messaging_menu_app_register (mmapp);
140+ }
141
142 g_debug ("Telepathy Indicator started");
143 g_main_loop_run (loop);
144
145 g_main_loop_unref (loop);
146- return 0;
147+ return ret;
148 }

Subscribers

People subscribed via source and target branches

to all changes: