aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@src.gnome.org>2009-01-31 01:07:35 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2009-01-31 01:07:35 +0800
commitd968b3380c661d8c31be352afbd373cac5fcb673 (patch)
tree6c2f00bd75cdf966ce23cd70dc19e3b5bafcf382 /src
parent111068fd8b34e36ffbfd9614001918bb31388e73 (diff)
downloadgsoc2013-empathy-d968b3380c661d8c31be352afbd373cac5fcb673.tar
gsoc2013-empathy-d968b3380c661d8c31be352afbd373cac5fcb673.tar.gz
gsoc2013-empathy-d968b3380c661d8c31be352afbd373cac5fcb673.tar.bz2
gsoc2013-empathy-d968b3380c661d8c31be352afbd373cac5fcb673.tar.lz
gsoc2013-empathy-d968b3380c661d8c31be352afbd373cac5fcb673.tar.xz
gsoc2013-empathy-d968b3380c661d8c31be352afbd373cac5fcb673.tar.zst
gsoc2013-empathy-d968b3380c661d8c31be352afbd373cac5fcb673.zip
W.I.P. for notifications on chat window.
svn path=/trunk/; revision=2285
Diffstat (limited to 'src')
-rw-r--r--src/empathy-chat-window.c85
-rw-r--r--src/empathy-event-manager.c3
-rw-r--r--src/empathy-status-icon.c9
3 files changed, 92 insertions, 5 deletions
diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c
index 0ce90ac4a..2f9d59641 100644
--- a/src/empathy-chat-window.c
+++ b/src/empathy-chat-window.c
@@ -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);
diff --git a/src/empathy-event-manager.c b/src/empathy-event-manager.c
index 253067ff1..f4e774b84 100644
--- a/src/empathy-event-manager.c
+++ b/src/empathy-event-manager.c
@@ -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);
diff --git a/src/empathy-status-icon.c b/src/empathy-status-icon.c
index 9ea211784..4c7964566 100644
--- a/src/empathy-status-icon.c
+++ b/src/empathy-status-icon.c
@@ -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);