]> git.0d.be Git - empathy.git/commitdiff
W.I.P. for notifications on chat window.
authorXavier Claessens <xclaesse@src.gnome.org>
Fri, 30 Jan 2009 17:07:35 +0000 (17:07 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Fri, 30 Jan 2009 17:07:35 +0000 (17:07 +0000)
svn path=/trunk/; revision=2285

libempathy-gtk/empathy-ui-utils.c
libempathy-gtk/empathy-ui-utils.h
src/empathy-chat-window.c
src/empathy-event-manager.c
src/empathy-status-icon.c

index 7b55587ea13300d166532fcaf8d152bf3a3bb803..7c6166839dd0ba8740175a23ec3a235573a444ea 100644 (file)
@@ -1647,7 +1647,7 @@ empathy_sound_play (GtkWidget *widget,
 }
 
 gboolean
-empathy_notification_should_show (void)
+empathy_notification_should_show (gboolean check_focus)
 {
        EmpathyConf *conf;
        gboolean res;
@@ -1670,6 +1670,12 @@ empathy_notification_should_show (void)
                }
        }
 
-       return TRUE;
+       if (check_focus) {
+               empathy_conf_get_bool (conf,
+                                      EMPATHY_PREFS_NOTIFICATIONS_FOCUS, &res);
+               return res;
+       } else {
+               return TRUE;
+       }
 }
 
index b3b26f0bbc7de39394f251eed63ae370f7367748..455ddd7a2e8c885223793d94f665be006b0b8a6b 100644 (file)
@@ -132,7 +132,7 @@ void        empathy_sound_play                          (GtkWidget        *widge
                                                         EmpathySound      sound_id);
 
 /* Notifications */
-gboolean    empathy_notification_should_show            (void);
+gboolean    empathy_notification_should_show            (gboolean          check_focus);
 
 G_END_DECLS
 
index 0ce90ac4aed018d728d8decaf8cbce29d4d67abf..2f9d5964118f5219df8d28ea7da64ab794621130 100644 (file)
@@ -33,6 +33,7 @@
 #include <gdk/gdkkeysyms.h>
 #include <glade/glade.h>
 #include <glib/gi18n.h>
+#include <libnotify/notification.h>
 
 #include <telepathy-glib/util.h>
 #include <libmissioncontrol/mission-control.h>
@@ -70,6 +71,7 @@ typedef struct {
        EmpathyChatroomManager *chatroom_manager;
        GtkWidget   *dialog;
        GtkWidget   *notebook;
+       NotifyNotification *notification;
 
        /* Menu items. */
        GtkWidget   *menu_conv_clear;
@@ -833,6 +835,79 @@ chat_window_set_urgency_hint (EmpathyChatWindow *window,
        gtk_window_set_urgency_hint (GTK_WINDOW (priv->dialog), urgent);
 }
 
+static gboolean
+notification_closed_idle_cb (EmpathyChatWindow *window)
+{
+       EmpathyChatWindowPriv *priv = GET_PRIV (window);
+
+       gtk_widget_grab_focus (priv->dialog);
+
+       return FALSE;
+}
+
+static void
+chat_window_notification_closed_cb (NotifyNotification *notify,
+                                   EmpathyChatWindow *window)
+{
+       EmpathyChatWindowPriv *priv = GET_PRIV (window);
+       int reason;
+
+       reason = notify_notification_get_closed_reason (notify);
+
+       if (priv->notification) {
+               g_object_unref (priv->notification);
+               priv->notification = NULL;
+       }
+
+       if (reason == 2) {
+               g_idle_add ((GSourceFunc) notification_closed_idle_cb, window);
+       }
+}
+
+static void
+show_or_update_notification (EmpathyMessage *message,
+                            EmpathyChatWindow *window)
+{
+       EmpathyContact *sender;
+       char *header;
+       const char *body;
+       GdkPixbuf *pixbuf;
+       EmpathyChatWindowPriv *priv = GET_PRIV (window);
+
+       if (!empathy_notification_should_show (TRUE)) {
+               return;
+       }
+
+       sender = empathy_message_get_sender (message);
+       header = g_strdup_printf (_("New message from %s"),
+                                 empathy_contact_get_name (sender));
+       body = empathy_message_get_body (message);
+       pixbuf = empathy_pixbuf_avatar_from_contact_scaled (sender, 48, 48);
+       if (pixbuf == NULL) {
+               /* we use INVALID here so we fall pack to 48px */
+               pixbuf = empathy_pixbuf_from_icon_name (EMPATHY_IMAGE_NEW_MESSAGE,
+                                                       GTK_ICON_SIZE_INVALID);
+       }
+
+       if (priv->notification != NULL) {
+               notify_notification_update (priv->notification,
+                                           header, body, NULL);
+               notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
+       } else {
+               priv->notification = notify_notification_new (header, body, NULL, priv->dialog);
+               notify_notification_set_timeout (priv->notification, NOTIFY_EXPIRES_DEFAULT);
+               notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
+
+               g_signal_connect (priv->notification, "closed",
+                                 G_CALLBACK (chat_window_notification_closed_cb), window);
+       }
+
+       notify_notification_show (priv->notification, NULL);
+
+       g_object_unref (pixbuf);
+       g_free (header);
+}
+
 static void
 chat_window_new_message_cb (EmpathyChat       *chat,
                            EmpathyMessage    *message,
@@ -866,6 +941,10 @@ chat_window_new_message_cb (EmpathyChat       *chat,
                }
        }
 
+       if (!has_focus) {
+               show_or_update_notification (message, window);
+       }
+
        if (has_focus && priv->current_chat == chat) {
                return;
        }
@@ -1163,6 +1242,12 @@ chat_window_finalize (GObject *object)
                g_source_remove (priv->save_geometry_id);
        }
 
+       if (priv->notification != NULL) {
+               notify_notification_close (priv->notification, NULL);
+               g_object_unref (priv->notification);
+               priv->notification = NULL;
+       }
+
        chat_windows = g_list_remove (chat_windows, window);
        gtk_widget_destroy (priv->dialog);
 
index 253067ff13b82259682bb63d212e80280839e42f..f4e774b8400502cee29232c5e9ec0afc5bddb640 100644 (file)
@@ -230,7 +230,6 @@ event_manager_chat_message_received_cb (EmpathyTpChat *tp_chat,
 
   /* try to update the event if it's referring to a chat which is already in the
    * queue. */
-
   event = event_lookup_by_approval (approval->manager, approval);
 
   if (event != NULL && event->inhibit)
@@ -248,7 +247,7 @@ event_manager_chat_message_received_cb (EmpathyTpChat *tp_chat,
   channel = empathy_tp_chat_get_channel (tp_chat);
 
   if (event != NULL)
-      event_update (approval->manager, event, EMPATHY_IMAGE_NEW_MESSAGE, header, msg);
+    event_update (approval->manager, event, EMPATHY_IMAGE_NEW_MESSAGE, header, msg);
   else
     event_manager_add (approval->manager, sender, EMPATHY_IMAGE_NEW_MESSAGE, header,
       msg, approval, event_channel_process_func, NULL);
index 9ea211784c58f9fa8e4d96dc738bd6b6afb58139..4c796456665d91e29542f4ac19e4c367b771590a 100644 (file)
@@ -140,6 +140,8 @@ status_icon_update_notification (EmpathyStatusIcon *icon)
 
                        g_signal_connect (priv->notification, "closed",
                                          G_CALLBACK (status_icon_notification_closed_cb), icon);
+
+                       g_object_unref (pixbuf);
                }
 
                notify_notification_show (priv->notification, NULL);
@@ -223,7 +225,7 @@ status_icon_event_added_cb (EmpathyEventManager *manager,
        status_icon_update_icon (icon);
        status_icon_update_tooltip (icon);
 
-       if (empathy_notification_should_show ()) {
+       if (empathy_notification_should_show (FALSE)) {
                status_icon_update_notification (icon);
        }
 
@@ -272,7 +274,7 @@ status_icon_event_updated_cb (EmpathyEventManager *manager,
                return;
        }
 
-       if (empathy_notification_should_show ()) {
+       if (empathy_notification_should_show (FALSE)) {
                status_icon_update_notification (icon);
        }
 
@@ -340,7 +342,7 @@ status_icon_idle_notify_cb (EmpathyStatusIcon *icon)
        status_icon_update_icon (icon);
        status_icon_update_tooltip (icon);
 
-       if (!empathy_notification_should_show ()) {
+       if (!empathy_notification_should_show (FALSE)) {
                /* dismiss the outstanding notification if present */
 
                if (priv->notification) {
@@ -504,6 +506,7 @@ status_icon_finalize (GObject *object)
        if (priv->notification) {
                notify_notification_close (priv->notification, NULL);
                g_object_unref (priv->notification);
+               priv->notification = NULL;
        }
 
        g_object_unref (priv->icon);