]> git.0d.be Git - empathy.git/commitdiff
mimic tooltip and icon notifications; unref any outstanding notification
authorXavier Claessens <xclaesse@src.gnome.org>
Fri, 30 Jan 2009 17:06:50 +0000 (17:06 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Fri, 30 Jan 2009 17:06:50 +0000 (17:06 +0000)
on finalize

svn path=/trunk/; revision=2272

src/empathy-status-icon.c

index 254a1b863161f3d558be2754ee39e5b4325241dc..dc1e8ddbcc8e036ec19ffbf14ccd37bda35d65ff 100644 (file)
@@ -59,6 +59,7 @@ typedef struct {
        guint                blink_timeout;
        EmpathyEventManager *event_manager;
        EmpathyEvent        *event;
+       NotifyNotification  *notification;
 
        GtkWindow           *window;
        GtkWidget           *popup_menu;
@@ -94,9 +95,40 @@ status_icon_notification_cb (NotifyNotification *notification,
 
 static void
 status_icon_notification_closed_cb (NotifyNotification *notification,
-                                   gpointer            user_data)
+                                   gpointer            data)
 {
-       g_object_unref (notification);
+       EmpathyStatusIcon *icon = EMPATHY_STATUS_ICON (data);
+       EmpathyStatusIconPriv *priv = GET_PRIV (icon);
+
+       if (priv->notification) {
+               g_object_unref (priv->notification);
+               priv->notification = NULL;
+       }
+}
+
+static void
+status_icon_update_notification (EmpathyStatusIcon *icon)
+{
+       EmpathyStatusIconPriv *priv = GET_PRIV (icon);
+
+       if (priv->event) {
+               priv->notification = notify_notification_new_with_status_icon ("New Event", priv->event->message, priv->event->icon_name, priv->icon);
+               notify_notification_add_action (priv->notification,
+                                               "activate",
+                                               "Activate",
+                                               status_icon_notification_cb,
+                                               icon, NULL);
+               notify_notification_set_timeout (priv->notification,
+                                                NOTIFY_EXPIRES_DEFAULT);
+               g_signal_connect (priv->notification, "closed", G_CALLBACK (status_icon_notification_closed_cb), (gpointer) icon);
+               notify_notification_show (priv->notification, NULL);
+       } else {
+               if (priv->notification) {
+                       notify_notification_close (priv->notification, NULL);
+                       g_object_unref (priv->notification);
+                       priv->notification = NULL;
+               }
+       }
 }
 
 static void
@@ -162,25 +194,13 @@ status_icon_event_added_cb (EmpathyEventManager *manager,
 
        status_icon_update_icon (icon);
        status_icon_update_tooltip (icon);
+       status_icon_update_notification (icon);
 
        if (!priv->blink_timeout) {
                priv->blink_timeout = g_timeout_add (BLINK_TIMEOUT,
                                                     (GSourceFunc) status_icon_blink_timeout_cb,
                                                     icon);
        }
-
-       if (!priv->event)
-               return;
-       NotifyNotification *notification = notify_notification_new_with_status_icon ("Incoming Something", priv->event->message, priv->event->icon_name, priv->icon);
-       notify_notification_add_action (notification,
-                                       "activate",
-                                       "Activate",
-                                       status_icon_notification_cb,
-                                       icon, NULL);
-       notify_notification_set_timeout (notification,
-                                        NOTIFY_EXPIRES_NEVER);
-       g_signal_connect (G_OBJECT (notification), "closed", G_CALLBACK (status_icon_notification_closed_cb), NULL);
-       notify_notification_show (notification, NULL);
 }
 
 static void
@@ -198,6 +218,7 @@ status_icon_event_removed_cb (EmpathyEventManager *manager,
 
        status_icon_update_tooltip (icon);
        status_icon_update_icon (icon);
+       status_icon_update_notification (icon);
 
        if (!priv->event && priv->blink_timeout) {
                g_source_remove (priv->blink_timeout);
@@ -415,6 +436,11 @@ status_icon_finalize (GObject *object)
                                              status_icon_connection_changed_cb,
                                              object);
 
+       if (priv->notification) {
+               notify_notification_close (priv->notification, NULL);
+               g_object_unref (priv->notification);
+       }
+
        g_object_unref (priv->icon);
        g_object_unref (priv->idle);
        g_object_unref (priv->account_manager);