empathy r2285 - in trunk: libempathy-gtk src



Author: xclaesse
Date: Fri Jan 30 17:07:35 2009
New Revision: 2285
URL: http://svn.gnome.org/viewvc/empathy?rev=2285&view=rev

Log:
W.I.P. for notifications on chat window.

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

Modified: trunk/libempathy-gtk/empathy-ui-utils.c
==============================================================================
--- trunk/libempathy-gtk/empathy-ui-utils.c	(original)
+++ trunk/libempathy-gtk/empathy-ui-utils.c	Fri Jan 30 17:07:35 2009
@@ -1647,7 +1647,7 @@
 }
 
 gboolean
-empathy_notification_should_show (void)
+empathy_notification_should_show (gboolean check_focus)
 {
 	EmpathyConf *conf;
 	gboolean res;
@@ -1670,6 +1670,12 @@
 		}
 	}
 
-	return TRUE;
+	if (check_focus) {
+		empathy_conf_get_bool (conf,
+				       EMPATHY_PREFS_NOTIFICATIONS_FOCUS, &res);
+		return res;
+	} else {
+		return TRUE;
+	}
 }
 

Modified: trunk/libempathy-gtk/empathy-ui-utils.h
==============================================================================
--- trunk/libempathy-gtk/empathy-ui-utils.h	(original)
+++ trunk/libempathy-gtk/empathy-ui-utils.h	Fri Jan 30 17:07:35 2009
@@ -132,7 +132,7 @@
 							 EmpathySound      sound_id);
 
 /* Notifications */
-gboolean    empathy_notification_should_show            (void);
+gboolean    empathy_notification_should_show            (gboolean          check_focus);
 
 G_END_DECLS
 

Modified: trunk/src/empathy-chat-window.c
==============================================================================
--- trunk/src/empathy-chat-window.c	(original)
+++ trunk/src/empathy-chat-window.c	Fri Jan 30 17:07:35 2009
@@ -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 @@
 	EmpathyChatroomManager *chatroom_manager;
 	GtkWidget   *dialog;
 	GtkWidget   *notebook;
+	NotifyNotification *notification;
 
 	/* Menu items. */
 	GtkWidget   *menu_conv_clear;
@@ -833,6 +835,79 @@
 	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 @@
 		}
 	}
 
+	if (!has_focus) {
+		show_or_update_notification (message, window);
+	}
+
 	if (has_focus && priv->current_chat == chat) {
 		return;
 	}
@@ -1163,6 +1242,12 @@
 		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);
 

Modified: trunk/src/empathy-event-manager.c
==============================================================================
--- trunk/src/empathy-event-manager.c	(original)
+++ trunk/src/empathy-event-manager.c	Fri Jan 30 17:07:35 2009
@@ -230,7 +230,6 @@
 
   /* 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 @@
   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);

Modified: trunk/src/empathy-status-icon.c
==============================================================================
--- trunk/src/empathy-status-icon.c	(original)
+++ trunk/src/empathy-status-icon.c	Fri Jan 30 17:07:35 2009
@@ -140,6 +140,8 @@
 
 			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_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 @@
 		return;
 	}
 
-	if (empathy_notification_should_show ()) {
+	if (empathy_notification_should_show (FALSE)) {
 		status_icon_update_notification (icon);
 	}
 
@@ -340,7 +342,7 @@
 	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 @@
 	if (priv->notification) {
 		notify_notification_close (priv->notification, NULL);
 		g_object_unref (priv->notification);
+		priv->notification = NULL;
 	}
 
 	g_object_unref (priv->icon);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]