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