]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-status-icon.c
Implement EmpathyAvatarChooser and EmpathyAvatarImage and make use of them
[empathy.git] / libempathy-gtk / empathy-status-icon.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007 Collabora Ltd.
4  *
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.
9  *
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.
14  *
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.
19  * 
20  * Authors: Xavier Claessens <xclaesse@gmail.com>
21  */
22
23 #include <config.h>
24
25 #include <string.h>
26
27 #include <gtk/gtk.h>
28 #include <glade/glade.h>
29 #include <glib/gi18n.h>
30
31 #include <libmissioncontrol/mission-control.h>
32
33 #include <libempathy/empathy-contact-list.h>
34 #include <libempathy/empathy-contact-manager.h>
35 #include <libempathy/empathy-contact.h>
36 #include <libempathy/empathy-tp-chat.h>
37 #include <libempathy/empathy-debug.h>
38 #include <libempathy/empathy-utils.h>
39 #include <libempathy/empathy-conf.h>
40 #include <libempathy/empathy-idle.h>
41 #include <libempathy/empathy-filter.h>
42
43 #include "empathy-status-icon.h"
44 #include "empathy-contact-dialogs.h"
45 #include "empathy-presence-chooser.h"
46 #include "empathy-preferences.h"
47 #include "empathy-ui-utils.h"
48 #include "empathy-accounts-dialog.h"
49 #include "empathy-images.h"
50
51
52 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
53                        EMPATHY_TYPE_STATUS_ICON, EmpathyStatusIconPriv))
54
55 #define DEBUG_DOMAIN "StatusIcon"
56
57 /* Number of ms to wait when blinking */
58 #define BLINK_TIMEOUT 500
59
60 typedef struct _StatusIconEvent StatusIconEvent;
61
62 struct _EmpathyStatusIconPriv {
63         GtkStatusIcon         *icon;
64         EmpathyContactManager *manager;
65         EmpathyFilter         *text_filter;
66         EmpathyIdle           *idle;
67         MissionControl        *mc;
68         GList                 *events;
69         gboolean               showing_event_icon;
70         StatusIconEvent       *flash_state_event;
71         guint                  blink_timeout;
72
73         GtkWindow             *window;
74         GtkWidget             *popup_menu;
75         GtkWidget             *show_window_item;
76         GtkWidget             *message_item;
77         GtkWidget             *status_item;
78 };
79
80 typedef void (*EventActivatedFunc) (StatusIconEvent *event);
81
82 struct _StatusIconEvent {
83         gchar              *icon_name;
84         gchar              *message;
85         EventActivatedFunc  func;
86         gpointer            user_data;
87 };
88
89
90 static void       empathy_status_icon_class_init  (EmpathyStatusIconClass *klass);
91 static void       empathy_status_icon_init        (EmpathyStatusIcon      *icon);
92 static void       status_icon_finalize            (GObject                *object);
93 static void       status_icon_filter_new_channel  (EmpathyFilter          *filter,
94                                                    TpConn                 *tp_conn,
95                                                    TpChan                 *tp_chan,
96                                                    EmpathyStatusIcon      *icon);
97 static void       status_icon_message_received_cb (EmpathyTpChat          *tp_chat,
98                                                    EmpathyMessage         *message,
99                                                    EmpathyStatusIcon      *icon);
100 static void       status_icon_idle_notify_cb      (EmpathyStatusIcon      *icon);
101 static void       status_icon_update_tooltip      (EmpathyStatusIcon      *icon);
102 static void       status_icon_set_from_state      (EmpathyStatusIcon      *icon);
103 static void       status_icon_toggle_visibility   (EmpathyStatusIcon      *icon);
104 static void       status_icon_activate_cb         (GtkStatusIcon          *status_icon,
105                                                    EmpathyStatusIcon      *icon);
106 static gboolean   status_icon_delete_event_cb     (GtkWidget              *widget,
107                                                    GdkEvent               *event,
108                                                    EmpathyStatusIcon      *icon);
109 static void       status_icon_popup_menu_cb       (GtkStatusIcon          *status_icon,
110                                                    guint                   button,
111                                                    guint                   activate_time,
112                                                    EmpathyStatusIcon      *icon);
113 static void       status_icon_create_menu         (EmpathyStatusIcon      *icon);
114 static void       status_icon_new_message_cb      (GtkWidget              *widget,
115                                                    EmpathyStatusIcon      *icon);
116 static void       status_icon_quit_cb             (GtkWidget              *window,
117                                                    EmpathyStatusIcon      *icon);
118 static void       status_icon_show_hide_window_cb (GtkWidget              *widget,
119                                                    EmpathyStatusIcon      *icon);
120 static void       status_icon_pendings_changed_cb (EmpathyContactManager  *manager,
121                                                    EmpathyContact         *contact,
122                                                    EmpathyContact         *actor,
123                                                    guint                   reason,
124                                                    gchar                  *message,
125                                                    gboolean                is_pending,
126                                                    EmpathyStatusIcon      *icon);
127 static void       status_icon_event_subscribe_cb  (StatusIconEvent        *event);
128 static void       status_icon_event_flash_state_cb (StatusIconEvent       *event);
129 static void       status_icon_event_msg_cb        (StatusIconEvent        *event);
130 static StatusIconEvent * status_icon_event_new    (EmpathyStatusIcon      *icon,
131                                                    const gchar            *icon_name,
132                                                    const gchar            *message);
133 static void       status_icon_event_remove        (EmpathyStatusIcon      *icon,
134                                                    StatusIconEvent        *event);
135 static gboolean   status_icon_event_timeout_cb    (EmpathyStatusIcon      *icon);
136 static void       status_icon_event_free          (StatusIconEvent        *event);
137
138 G_DEFINE_TYPE (EmpathyStatusIcon, empathy_status_icon, G_TYPE_OBJECT);
139
140 static void
141 empathy_status_icon_class_init (EmpathyStatusIconClass *klass)
142 {
143         GObjectClass *object_class = G_OBJECT_CLASS (klass);
144
145         object_class->finalize = status_icon_finalize;
146
147         g_type_class_add_private (object_class, sizeof (EmpathyStatusIconPriv));
148 }
149
150 static void
151 empathy_status_icon_init (EmpathyStatusIcon *icon)
152 {
153         EmpathyStatusIconPriv *priv;
154         GList                 *pendings, *l;
155
156         priv = GET_PRIV (icon);
157
158         priv->icon = gtk_status_icon_new ();
159         priv->idle = empathy_idle_new ();
160         empathy_idle_set_auto_away (priv->idle, TRUE);
161         empathy_idle_set_auto_disconnect (priv->idle, TRUE);
162         priv->manager = empathy_contact_manager_new ();
163         priv->mc = empathy_mission_control_new ();
164         priv->text_filter = empathy_filter_new ("org.gnome.Empathy.Chat",
165                                                 "/org/freedesktop/Telepathy/Filter",
166                                                 TP_IFACE_CHANNEL_TYPE_TEXT,
167                                                 MC_FILTER_PRIORITY_DIALOG,
168                                                 MC_FILTER_FLAG_INCOMING);
169
170         status_icon_create_menu (icon);
171         status_icon_idle_notify_cb (icon);
172
173         g_signal_connect (priv->text_filter, "new-channel",
174                           G_CALLBACK (status_icon_filter_new_channel),
175                           icon);
176         g_signal_connect_swapped (priv->idle, "notify",
177                                   G_CALLBACK (status_icon_idle_notify_cb),
178                                   icon);
179         g_signal_connect (priv->icon, "activate",
180                           G_CALLBACK (status_icon_activate_cb),
181                           icon);
182         g_signal_connect (priv->icon, "popup-menu",
183                           G_CALLBACK (status_icon_popup_menu_cb),
184                           icon);
185         g_signal_connect (priv->manager, "pendings-changed",
186                           G_CALLBACK (status_icon_pendings_changed_cb),
187                           icon);
188
189         pendings = empathy_contact_list_get_pendings (EMPATHY_CONTACT_LIST (priv->manager));
190         for (l = pendings; l; l = l->next) {
191                 EmpathyPendingInfo *info;
192
193                 info = l->data;
194                 status_icon_pendings_changed_cb (priv->manager,
195                                                  info->member,
196                                                  info->actor,
197                                                  0,
198                                                  info->message,
199                                                  TRUE,
200                                                  icon);
201                 empathy_pending_info_free (info);
202         }
203         g_list_free (pendings);
204 }
205
206 static void
207 status_icon_finalize (GObject *object)
208 {
209         EmpathyStatusIconPriv *priv;
210
211         priv = GET_PRIV (object);
212
213         g_list_foreach (priv->events, (GFunc) status_icon_event_free, NULL);
214         g_list_free (priv->events);
215
216         if (priv->blink_timeout) {
217                 g_source_remove (priv->blink_timeout);
218         }
219
220         g_object_unref (priv->icon);
221         g_object_unref (priv->window);
222         g_object_unref (priv->idle);
223         g_object_unref (priv->manager);
224         g_object_unref (priv->mc);
225 }
226
227 EmpathyStatusIcon *
228 empathy_status_icon_new (GtkWindow *window)
229 {
230         EmpathyStatusIconPriv *priv;
231         EmpathyStatusIcon     *icon;
232         gboolean               should_hide;
233         gboolean               visible;
234
235         g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
236
237         icon = g_object_new (EMPATHY_TYPE_STATUS_ICON, NULL);
238         priv = GET_PRIV (icon);
239
240         priv->window = g_object_ref (window);
241
242         g_signal_connect (priv->window, "delete-event",
243                           G_CALLBACK (status_icon_delete_event_cb),
244                           icon);
245
246         empathy_conf_get_bool (empathy_conf_get (),
247                               EMPATHY_PREFS_UI_MAIN_WINDOW_HIDDEN,
248                               &should_hide);
249         visible = empathy_window_get_is_visible (window);
250
251         if ((!should_hide && !visible) || (should_hide && visible)) {
252                 status_icon_toggle_visibility (icon);
253         }
254
255         return icon;
256 }
257
258 static void
259 status_icon_filter_new_channel (EmpathyFilter     *filter,
260                                 TpConn            *tp_conn,
261                                 TpChan            *tp_chan,
262                                 EmpathyStatusIcon *icon)
263 {
264         EmpathyStatusIconPriv *priv;
265         McAccount             *account;
266         EmpathyTpChat         *tp_chat;
267         GList                 *messages;
268
269         priv = GET_PRIV (icon);
270
271         account = mission_control_get_account_for_connection (priv->mc, tp_conn, NULL);
272
273         empathy_debug (DEBUG_DOMAIN, "New text channel to be filtered for contact %s",
274                        empathy_inspect_channel (account, tp_chan));
275
276         tp_chat = empathy_tp_chat_new (account, tp_chan);
277         g_object_set_data (G_OBJECT (tp_chat), "filter", filter);
278         g_object_unref (account);
279
280         messages = empathy_tp_chat_get_pendings (tp_chat);
281         if (!messages) {
282                 empathy_debug (DEBUG_DOMAIN, "No pending msg, waiting...");
283                 g_signal_connect (tp_chat, "message-received",
284                                   G_CALLBACK (status_icon_message_received_cb),
285                                   icon);
286                 return;
287         }
288
289         status_icon_message_received_cb (tp_chat, messages->data, icon);
290
291         g_list_foreach (messages, (GFunc) g_object_unref, NULL);
292         g_list_free (messages);
293 }
294
295 static void
296 status_icon_message_received_cb (EmpathyTpChat     *tp_chat,
297                                  EmpathyMessage    *message,
298                                  EmpathyStatusIcon *icon)
299 {
300         EmpathyContact  *sender;
301         gchar           *msg;
302         StatusIconEvent *event;
303
304         empathy_debug (DEBUG_DOMAIN, "Message received, add event");
305
306         g_signal_handlers_disconnect_by_func (tp_chat,
307                                               status_icon_message_received_cb,
308                                               icon);
309
310         sender = empathy_message_get_sender (message);
311         msg = g_strdup_printf (_("New message from %s:\n%s"),
312                                empathy_contact_get_name (sender),
313                                empathy_message_get_body (message));
314
315         event = status_icon_event_new (icon, EMPATHY_IMAGE_NEW_MESSAGE, msg);
316         event->func = status_icon_event_msg_cb;
317         event->user_data = tp_chat;
318 }
319
320 static void
321 status_icon_idle_notify_cb (EmpathyStatusIcon *icon)
322 {
323         EmpathyStatusIconPriv *priv;
324         McPresence             flash_state;
325
326         priv = GET_PRIV (icon);
327
328         flash_state = empathy_idle_get_flash_state (priv->idle);
329         if (flash_state != MC_PRESENCE_UNSET) {
330                 const gchar *icon_name;
331
332                 icon_name = empathy_icon_name_for_presence_state (flash_state);
333                 if (!priv->flash_state_event) {
334                         /* We are now flashing */
335                         priv->flash_state_event = status_icon_event_new (icon, icon_name, NULL);
336                         priv->flash_state_event->user_data = icon;
337                         priv->flash_state_event->func = status_icon_event_flash_state_cb;
338                 } else {
339                         /* We are still flashing but with another state */
340                         g_free (priv->flash_state_event->icon_name);
341                         priv->flash_state_event->icon_name = g_strdup (icon_name);
342                 }
343         }
344         else if (priv->flash_state_event) {
345                 /* We are no more flashing */
346                 status_icon_event_remove (icon, priv->flash_state_event);
347                 priv->flash_state_event = NULL;
348         }
349
350         if (!priv->showing_event_icon) {
351                 status_icon_set_from_state (icon);
352         }
353
354         status_icon_update_tooltip (icon);
355 }
356
357 static void
358 status_icon_update_tooltip (EmpathyStatusIcon *icon)
359 {
360         EmpathyStatusIconPriv *priv;
361         const gchar           *tooltip = NULL;
362
363         priv = GET_PRIV (icon);
364
365         if (priv->events) {
366                 StatusIconEvent *event;
367
368                 event = priv->events->data;
369                 tooltip = event->message;
370         }
371
372         if (!tooltip) {
373                 tooltip = empathy_idle_get_status (priv->idle);
374         }
375
376         gtk_status_icon_set_tooltip (priv->icon, tooltip);      
377 }
378
379 static void
380 status_icon_set_from_state (EmpathyStatusIcon *icon)
381 {
382         EmpathyStatusIconPriv *priv;
383         McPresence             state;
384         const gchar           *icon_name;
385
386         priv = GET_PRIV (icon);
387
388         state = empathy_idle_get_state (priv->idle);
389         icon_name = empathy_icon_name_for_presence_state (state);
390         gtk_status_icon_set_from_icon_name (priv->icon, icon_name);
391 }
392
393 static void
394 status_icon_toggle_visibility (EmpathyStatusIcon *icon)
395 {
396         EmpathyStatusIconPriv *priv;
397         gboolean               visible;
398
399         priv = GET_PRIV (icon);
400
401         visible = gtk_window_has_toplevel_focus (GTK_WINDOW (priv->window));
402
403         if (visible) {
404                 empathy_window_iconify (priv->window, priv->icon);
405                 empathy_conf_set_bool (empathy_conf_get (),
406                                       EMPATHY_PREFS_UI_MAIN_WINDOW_HIDDEN, TRUE);
407         } else {
408                 GList *accounts;
409
410                 empathy_window_present (GTK_WINDOW (priv->window), TRUE);
411                 empathy_conf_set_bool (empathy_conf_get (),
412                                       EMPATHY_PREFS_UI_MAIN_WINDOW_HIDDEN, FALSE);
413         
414                 /* Show the accounts dialog if there is no enabled accounts */
415                 accounts = mc_accounts_list_by_enabled (TRUE);
416                 if (accounts) {
417                         mc_accounts_list_free (accounts);
418                 } else {
419                         empathy_debug (DEBUG_DOMAIN,
420                                       "No enabled account, Showing account dialog");
421                         empathy_accounts_dialog_show (GTK_WINDOW (priv->window));
422                 }
423         }
424 }
425
426 static void
427 status_icon_activate_cb (GtkStatusIcon     *status_icon,
428                          EmpathyStatusIcon *icon)
429 {
430         EmpathyStatusIconPriv *priv;
431
432         priv = GET_PRIV (icon);
433
434         empathy_debug (DEBUG_DOMAIN, "Activated: %s",
435                        priv->events ? "event" : "toggle");
436
437         if (priv->events) {
438                 status_icon_event_remove (icon, priv->events->data);
439         } else {
440                 status_icon_toggle_visibility (icon);
441         }
442 }
443
444 static gboolean
445 status_icon_delete_event_cb (GtkWidget         *widget,
446                              GdkEvent          *event,
447                              EmpathyStatusIcon *icon)
448 {
449         status_icon_toggle_visibility (icon);
450
451         return TRUE;
452 }
453
454 static void
455 status_icon_popup_menu_cb (GtkStatusIcon     *status_icon,
456                            guint              button,
457                            guint              activate_time,
458                            EmpathyStatusIcon *icon)
459 {
460         EmpathyStatusIconPriv *priv;
461         GtkWidget             *submenu;
462         gboolean               show;
463
464         priv = GET_PRIV (icon);
465
466         show = empathy_window_get_is_visible (GTK_WINDOW (priv->window));
467
468         g_signal_handlers_block_by_func (priv->show_window_item,
469                                          status_icon_show_hide_window_cb,
470                                          icon);
471         gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (priv->show_window_item),
472                                         show);
473         g_signal_handlers_unblock_by_func (priv->show_window_item,
474                                            status_icon_show_hide_window_cb,
475                                            icon);
476
477         submenu = empathy_presence_chooser_create_menu ();
478         gtk_menu_item_set_submenu (GTK_MENU_ITEM (priv->status_item),
479                                    submenu);
480
481         gtk_menu_popup (GTK_MENU (priv->popup_menu),
482                         NULL, NULL,
483                         gtk_status_icon_position_menu,
484                         priv->icon,
485                         button,
486                         activate_time);
487 }
488
489 static void
490 status_icon_create_menu (EmpathyStatusIcon *icon)
491 {
492         EmpathyStatusIconPriv *priv;
493         GladeXML              *glade;
494
495         priv = GET_PRIV (icon);
496
497         glade = empathy_glade_get_file ("empathy-status-icon.glade",
498                                        "tray_menu",
499                                        NULL,
500                                        "tray_menu", &priv->popup_menu,
501                                        "tray_show_list", &priv->show_window_item,
502                                        "tray_new_message", &priv->message_item,
503                                        "tray_status", &priv->status_item,
504                                        NULL);
505
506         empathy_glade_connect (glade,
507                               icon,
508                               "tray_new_message", "activate", status_icon_new_message_cb,
509                               "tray_quit", "activate", status_icon_quit_cb,
510                               NULL);
511
512         g_signal_connect (priv->show_window_item, "toggled",
513                           G_CALLBACK (status_icon_show_hide_window_cb),
514                           icon);
515
516         g_object_unref (glade);
517 }
518
519 static void
520 status_icon_new_message_cb (GtkWidget         *widget,
521                             EmpathyStatusIcon *icon)
522 {
523         EmpathyStatusIconPriv *priv;
524
525         priv = GET_PRIV (icon);
526
527         //empathy_new_message_dialog_show (GTK_WINDOW (priv->window));
528 }
529
530 static void
531 status_icon_quit_cb (GtkWidget         *window,
532                      EmpathyStatusIcon *icon)
533 {
534         gtk_main_quit ();
535 }
536
537 static void
538 status_icon_show_hide_window_cb (GtkWidget         *widget,
539                                  EmpathyStatusIcon *icon)
540 {
541         status_icon_toggle_visibility (icon);
542 }
543
544 static void
545 status_icon_pendings_changed_cb (EmpathyContactManager *manager,
546                                  EmpathyContact        *contact,
547                                  EmpathyContact        *actor,
548                                  guint                  reason,
549                                  gchar                 *message,
550                                  gboolean               is_pending,
551                                  EmpathyStatusIcon     *icon)
552 {
553         EmpathyStatusIconPriv *priv;
554         StatusIconEvent       *event;
555         GString               *str;
556         GList                 *l;
557
558         priv = GET_PRIV (icon);
559
560         if (!is_pending) {
561                 /* FIXME: We should remove the event */
562                 return;
563         }
564
565         for (l = priv->events; l; l = l->next) {
566                 if (empathy_contact_equal (contact, ((StatusIconEvent*)l->data)->user_data)) {
567                         return;
568                 }
569         }
570
571         str = g_string_new (NULL);
572         g_string_printf (str, _("Subscription requested by %s"),
573                          empathy_contact_get_name (contact));   
574         if (!G_STR_EMPTY (message)) {
575                 g_string_append_printf (str, _("\nMessage: %s"), message);
576         }
577
578         event = status_icon_event_new (icon, GTK_STOCK_DIALOG_QUESTION, str->str);
579         event->user_data = g_object_ref (contact);
580         event->func = status_icon_event_subscribe_cb;
581
582         g_string_free (str, TRUE);
583 }
584
585 static void
586 status_icon_event_subscribe_cb (StatusIconEvent *event)
587 {
588         EmpathyContact *contact;
589
590         contact = EMPATHY_CONTACT (event->user_data);
591
592         empathy_subscription_dialog_show (contact, NULL);
593
594         g_object_unref (contact);
595 }
596
597 static void
598 status_icon_event_flash_state_cb (StatusIconEvent *event)
599 {
600         EmpathyStatusIconPriv *priv;
601
602         priv = GET_PRIV (event->user_data);
603
604         empathy_idle_set_flash_state (priv->idle, MC_PRESENCE_UNSET);
605 }
606
607 static void
608 status_icon_event_msg_cb (StatusIconEvent *event)
609 {
610         EmpathyFilter *filter;
611         EmpathyTpChat *tp_chat;
612
613         empathy_debug (DEBUG_DOMAIN, "Dispatching text channel");
614
615         tp_chat = event->user_data;
616         filter = g_object_get_data (G_OBJECT (tp_chat), "filter");
617         empathy_filter_process (filter,
618                                 empathy_tp_chat_get_channel (tp_chat),
619                                 TRUE);
620         g_object_unref (tp_chat);
621 }
622
623 static StatusIconEvent *
624 status_icon_event_new (EmpathyStatusIcon *icon,
625                        const gchar       *icon_name,
626                        const gchar       *message)
627 {
628         EmpathyStatusIconPriv *priv;
629         StatusIconEvent       *event;
630
631         priv = GET_PRIV (icon);
632
633         event = g_slice_new0 (StatusIconEvent);
634         event->icon_name = g_strdup (icon_name);        
635         event->message = g_strdup (message);
636
637         priv->events = g_list_append (priv->events, event);
638         if (!priv->blink_timeout) {
639                 priv->showing_event_icon = FALSE;
640                 priv->blink_timeout = g_timeout_add (BLINK_TIMEOUT,
641                                                      (GSourceFunc) status_icon_event_timeout_cb,
642                                                      icon);
643                 status_icon_event_timeout_cb (icon);
644                 status_icon_update_tooltip (icon);
645         }
646
647         return event;
648 }
649
650 static void
651 status_icon_event_remove (EmpathyStatusIcon *icon,
652                           StatusIconEvent   *event)
653 {
654         EmpathyStatusIconPriv *priv;
655
656         priv = GET_PRIV (icon);
657
658         if (event->func) {
659                 event->func (event);
660         }
661         priv->events = g_list_remove (priv->events, event);
662         status_icon_event_free (event);
663         priv->showing_event_icon = FALSE;
664         status_icon_update_tooltip (icon);
665         status_icon_set_from_state (icon);
666
667         if (priv->events) {
668                 return;
669         }
670
671         if (priv->blink_timeout) {
672                 g_source_remove (priv->blink_timeout);
673                 priv->blink_timeout = 0;
674         }
675 }
676
677 static gboolean
678 status_icon_event_timeout_cb (EmpathyStatusIcon *icon)
679 {
680         EmpathyStatusIconPriv *priv;
681
682         priv = GET_PRIV (icon);
683
684         priv->showing_event_icon = !priv->showing_event_icon;
685
686         if (!priv->showing_event_icon) {
687                 status_icon_set_from_state (icon);
688         } else {
689                 StatusIconEvent *event;
690
691                 event = priv->events->data;
692                 gtk_status_icon_set_from_icon_name (priv->icon, event->icon_name);
693         }
694
695         return TRUE;
696 }
697
698 static void
699 status_icon_event_free (StatusIconEvent *event)
700 {
701         g_free (event->icon_name);
702         g_free (event->message);
703         g_slice_free (StatusIconEvent, event);
704 }
705