Merge lp:~larsu/telepathy-indicator/watch-empathy into lp:telepathy-indicator

Proposed by Lars Karlitski
Status: Merged
Approved by: Ted Gould
Approved revision: 73
Merged at revision: 73
Proposed branch: lp:~larsu/telepathy-indicator/watch-empathy
Merge into: lp:telepathy-indicator
Prerequisite: lp:~larsu/telepathy-indicator/gracefully-exit
Diff against target: 169 lines (+49/-28)
1 file modified
src/indicator-approver.c (+49/-28)
To merge this branch: bzr merge lp:~larsu/telepathy-indicator/watch-empathy
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Ken VanDine Pending
Review via email: mp+149432@code.launchpad.net

Commit message

Mark empathy as running only when it is actually running.

Description of the change

Mark empathy as running only when it is actually running.

This doesn't actually work yet due to a bug in indicator-messages. Will fix that shortly.

To post a comment you must log in.
71. By Lars Karlitski on 2013-02-20

Quit when another instance is already running

72. By Lars Karlitski on 2013-02-20

Unref tp_am in the function it was created in

73. By Lars Karlitski on 2013-02-20

Update license header

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ted Gould (ted) :
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 2013-02-20 01:16:27 +0000
3+++ src/indicator-approver.c 2013-02-20 01:16:27 +0000
4@@ -1,5 +1,5 @@
5 /*
6- * Copyright(C) 2011 Canonical Ltd.
7+ * Copyright(C) 2013 Canonical Ltd.
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11@@ -14,7 +14,7 @@
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *
15- * Authored by Ken VaDine <ken.vandine@canonical.com>
16+ * Authored by Ken VanDine <ken.vandine@canonical.com>
17 */
18
19 #include <glib.h>
20@@ -36,6 +36,8 @@
21 static gint n_sources;
22 UnityLauncherEntry *launcher = NULL;
23 GList *conns;
24+TpBaseClient *approver;
25+TpBaseClient *observer;
26
27 static void update_launcher (gint count)
28 {
29@@ -835,8 +837,6 @@
30 static TpBaseClient *
31 approver_setup (TpAccountManager *tp_am, GError **error)
32 {
33- TpBaseClient *approver;
34-
35 g_return_val_if_fail (TP_IS_ACCOUNT_MANAGER (tp_am), NULL);
36
37 approver = tp_simple_approver_new_with_am (tp_am, "IndicatorApprover",
38@@ -856,8 +856,7 @@
39
40 if (!tp_base_client_register (approver, error))
41 {
42- g_object_unref (tp_am);
43- g_object_unref (approver);
44+ g_clear_object (&approver);
45 return NULL;
46 }
47 return approver;
48@@ -866,8 +865,6 @@
49 static TpBaseClient *
50 observer_setup (TpAccountManager *tp_am, GError **error)
51 {
52- TpBaseClient *observer;
53-
54 g_return_val_if_fail (TP_IS_ACCOUNT_MANAGER (tp_am), NULL);
55
56 observer = tp_simple_observer_new_with_am (tp_am, TRUE, "IndicatorObserver",
57@@ -881,8 +878,7 @@
58
59 if (!tp_base_client_register (observer, error))
60 {
61- g_object_unref (tp_am);
62- g_object_unref (observer);
63+ g_clear_object (&observer);
64 return NULL;
65 }
66 return observer;
67@@ -1014,34 +1010,48 @@
68 }
69 }
70
71-
72-int setup ()
73+static void
74+empathy_appeared (GDBusConnection *connection,
75+ const gchar *name,
76+ const gchar *name_owner,
77+ gpointer user_data)
78 {
79+ GMainLoop *loop = user_data;
80+ TpAccountManager *tp_am;
81+ TpBaseClient *approver;
82+ TpBaseClient *observer;
83 TpConnectionPresenceType presence;
84 GError *error = NULL;
85
86- TpBaseClient *approver;
87- TpBaseClient *observer;
88+ g_debug (G_STRFUNC);
89
90- TpAccountManager *tp_am = tp_account_manager_dup ();
91+ tp_am = tp_account_manager_dup ();
92
93 approver = approver_setup (tp_am, &error);
94 if (approver == NULL)
95 {
96 g_warning ("Failed to register the approver: %s", error->message);
97 g_error_free (error);
98- return 1;
99+ g_object_unref (tp_am);
100+ g_main_loop_quit (loop);
101+ return;
102 }
103+
104 observer = observer_setup (tp_am, &error);
105 if (observer == NULL)
106 {
107 g_warning ("Failed to register the observer: %s", error->message);
108 g_error_free (error);
109- return 1;
110+ g_object_unref (tp_am);
111+ g_main_loop_quit (loop);
112+ return;
113 }
114
115 mmapp = messaging_menu_app_new ("empathy.desktop");
116
117+ if (check_enabled_accounts ())
118+ messaging_menu_app_register (mmapp);
119+
120 g_signal_connect (mmapp, "activate-source",
121 G_CALLBACK (message_source_activated), tp_am);
122 g_signal_connect (mmapp, "status-changed",
123@@ -1064,9 +1074,22 @@
124
125 contact_list_setup (tp_am);
126
127- return 0;
128-}
129-
130+ g_object_unref (tp_am);
131+}
132+
133+static void
134+empathy_vanished (GDBusConnection *connection,
135+ const gchar *name,
136+ gpointer user_data)
137+{
138+ g_debug (G_STRFUNC);
139+
140+ g_clear_object (&approver);
141+ g_clear_object (&observer);
142+ g_clear_object (&launcher);
143+ g_clear_pointer (&dispatch_ops, g_hash_table_unref);
144+ g_clear_object (&mmapp);
145+}
146
147 int
148 main (int argc, char **argv)
149@@ -1077,14 +1100,12 @@
150
151 loop = g_main_loop_new (NULL, FALSE);
152
153- ret = setup ();
154- if (ret == 1)
155- return ret;
156-
157- if (check_enabled_accounts ())
158- {
159- messaging_menu_app_register (mmapp);
160- }
161+ g_bus_watch_name (G_BUS_TYPE_SESSION,
162+ "org.gnome.Empathy",
163+ G_BUS_NAME_WATCHER_FLAGS_NONE,
164+ empathy_appeared,
165+ empathy_vanished,
166+ loop, NULL);
167
168 g_debug ("Telepathy Indicator started");
169 g_main_loop_run (loop);

Subscribers

People subscribed via source and target branches

to all changes: