+typedef struct {
+ EmpathyChatWindow *window;
+ EmpathyChat *chat;
+} NotificationData;
+
+static void
+chat_window_notification_closed_cb (NotifyNotification *notify,
+ NotificationData *cb_data)
+{
+ EmpathyNotificationClosedReason reason = 0;
+ EmpathyChatWindowPriv *priv = GET_PRIV (cb_data->window);
+
+#ifdef notify_notification_get_closed_reason
+ reason = notify_notification_get_closed_reason (notify);
+#endif
+ if (reason == EMPATHY_NOTIFICATION_CLOSED_DISMISSED) {
+ empathy_chat_window_present_chat (cb_data->chat);
+ }
+
+ g_object_unref (notify);
+ priv->notification = NULL;
+ g_object_unref (cb_data->chat);
+ g_slice_free (NotificationData, cb_data);
+}
+
+static void
+chat_window_show_or_update_notification (EmpathyChatWindow *window,
+ EmpathyMessage *message,
+ EmpathyChat *chat)
+{
+ EmpathyContact *sender;
+ const gchar *header;
+ char *escaped;
+ const char *body;
+ GdkPixbuf *pixbuf;
+ NotificationData *cb_data;
+ EmpathyChatWindowPriv *priv = GET_PRIV (window);
+ gboolean res;
+
+ if (!empathy_notification_is_enabled ()) {
+ return;
+ } else {
+ empathy_conf_get_bool (empathy_conf_get (),
+ EMPATHY_PREFS_NOTIFICATIONS_FOCUS, &res);
+ if (!res) {
+ return;
+ }
+ }
+
+ cb_data = g_slice_new0 (NotificationData);
+ cb_data->chat = g_object_ref (chat);
+ cb_data->window = window;
+
+ sender = empathy_message_get_sender (message);
+ header = empathy_contact_get_name (sender);
+ body = empathy_message_get_body (message);
+ escaped = g_markup_escape_text (body, -1);
+
+ pixbuf = empathy_misc_get_pixbuf_for_notification (sender, EMPATHY_IMAGE_NEW_MESSAGE);
+
+ if (priv->notification != NULL) {
+ notify_notification_update (priv->notification,
+ header, escaped, NULL);
+ /* if icon doesn't exist libnotify will crash */
+ if (pixbuf != NULL)
+ notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
+ } else {
+ priv->notification = notify_notification_new (header, escaped, NULL, NULL);
+ notify_notification_set_timeout (priv->notification, NOTIFY_EXPIRES_DEFAULT);
+ /* if icon doesn't exist libnotify will crash */
+ if (pixbuf != NULL)
+ notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
+
+ g_signal_connect (priv->notification, "closed",
+ G_CALLBACK (chat_window_notification_closed_cb), cb_data);
+ }
+
+ notify_notification_show (priv->notification, NULL);
+
+ g_object_unref (pixbuf);
+ g_free (escaped);
+}
+
+static void
+chat_window_set_highlight_room_tab_label (EmpathyChat *chat)
+{
+ gchar *markup;
+ GtkWidget *widget;
+
+ if (empathy_chat_is_room (chat) == FALSE)
+ return;
+
+ markup = g_markup_printf_escaped ("<span color=\"%s\">%s</span>",
+ "red",
+ empathy_chat_get_name (chat));
+
+ widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-label");
+ gtk_label_set_markup (GTK_LABEL (widget), markup);
+ g_free (markup);
+}
+