1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Authors: Xavier Claessens <xclaesse@gmail.com>
30 #include <libtelepathy/tp-helpers.h>
32 #include <libmissioncontrol/mission-control.h>
34 #include <libempathy/gossip-debug.h>
35 #include <libempathy/gossip-utils.h>
37 #include "empathy-status-icon.h"
38 #include "gossip-ui-utils.h"
40 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
41 EMPATHY_TYPE_STATUS_ICON, EmpathyStatusIconPriv))
43 #define DEBUG_DOMAIN "StatusIcon"
45 struct _EmpathyStatusIconPriv {
50 static void empathy_status_icon_class_init (EmpathyStatusIconClass *klass);
51 static void empathy_status_icon_init (EmpathyStatusIcon *icon);
52 static void status_icon_finalize (GObject *object);
53 static void status_icon_presence_changed_cb (MissionControl *mc,
55 EmpathyStatusIcon *icon);
56 static void status_icon_activate_cb (GtkStatusIcon *status_icon,
57 EmpathyStatusIcon *icon);
64 static guint signals[LAST_SIGNAL];
66 G_DEFINE_TYPE (EmpathyStatusIcon, empathy_status_icon, G_TYPE_OBJECT);
69 empathy_status_icon_class_init (EmpathyStatusIconClass *klass)
71 GObjectClass *object_class = G_OBJECT_CLASS (klass);
73 object_class->finalize = status_icon_finalize;
76 g_signal_new ("activate",
77 G_TYPE_FROM_CLASS (klass),
81 g_cclosure_marshal_VOID__VOID,
85 g_type_class_add_private (object_class, sizeof (EmpathyStatusIconPriv));
89 empathy_status_icon_init (EmpathyStatusIcon *icon)
91 EmpathyStatusIconPriv *priv;
94 priv = GET_PRIV (icon);
96 priv->mc = mission_control_new (tp_get_bus ());
97 priv->icon = gtk_status_icon_new ();
99 dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->mc),
100 "PresenceStatusActual",
101 G_CALLBACK (status_icon_presence_changed_cb),
103 g_signal_connect (priv->icon, "activate",
104 G_CALLBACK (status_icon_activate_cb),
107 state = mission_control_get_presence_actual (priv->mc, NULL);
108 status_icon_presence_changed_cb (priv->mc, state, icon);
112 status_icon_finalize (GObject *object)
114 EmpathyStatusIconPriv *priv;
116 priv = GET_PRIV (object);
118 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->mc),
119 "PresenceStatusActual",
120 G_CALLBACK (status_icon_presence_changed_cb),
122 g_signal_handlers_disconnect_by_func (priv->icon,
123 status_icon_activate_cb,
126 g_object_unref (priv->mc);
127 g_object_unref (priv->icon);
131 empathy_status_icon_new (void)
133 return g_object_new (EMPATHY_TYPE_STATUS_ICON, NULL);
137 status_icon_presence_changed_cb (MissionControl *mc,
139 EmpathyStatusIcon *icon)
141 EmpathyStatusIconPriv *priv;
142 const gchar *icon_name;
145 priv = GET_PRIV (icon);
147 icon_name = gossip_icon_name_for_presence_state (state);
148 status = mission_control_get_presence_message_actual (priv->mc, NULL);
149 if (G_STR_EMPTY (status)) {
151 status = g_strdup (gossip_presence_state_get_default_status (state));
154 gtk_status_icon_set_from_icon_name (priv->icon, icon_name);
155 gtk_status_icon_set_tooltip (priv->icon, status);
161 status_icon_activate_cb (GtkStatusIcon *status_icon,
162 EmpathyStatusIcon *icon)
164 g_signal_emit (icon, signals[ACTIVATE], 0);