]> git.0d.be Git - empathy.git/blobdiff - src/empathy-notifications-approver.c
Use double quotes for all internal headers
[empathy.git] / src / empathy-notifications-approver.c
index e0d540cdcda0eaad185a6b125ccd9ce2b7ef3268..b4f77eebbfed3a21835c3d61398244a597d416a9 100644 (file)
  * Authors: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
  */
 
-#include <config.h>
-#include <string.h>
+#include "config.h"
 
 #include <glib/gi18n.h>
-#include <libnotify/notification.h>
-#include <libnotify/notify.h>
-#include <telepathy-glib/telepathy-glib.h>
 
-#include <libempathy/empathy-contact-manager.h>
-
-#include <libempathy-gtk/empathy-notify-manager.h>
+#include "libempathy-gtk/empathy-notify-manager.h"
+#include "libempathy-gtk/empathy-call-utils.h"
 
 #include "empathy-event-manager.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
-#include <libempathy/empathy-debug.h>
+#include "libempathy/empathy-debug.h"
 
 #include "empathy-notifications-approver.h"
 
@@ -118,6 +113,20 @@ notification_close_helper (EmpathyNotificationsApprover *self)
     }
 }
 
+static void
+notification_approve_no_video_cb (NotifyNotification *notification,
+    gchar *action,
+    EmpathyNotificationsApprover *self)
+{
+  if (self->priv->event)
+    {
+      empathy_call_channel_send_video (
+          TP_CALL_CHANNEL (self->priv->event->handler_instance),
+          FALSE);
+      empathy_event_approve (self->priv->event);
+    }
+}
+
 static void
 notification_approve_cb (NotifyNotification *notification,
     gchar *action,
@@ -141,18 +150,12 @@ notification_decline_subscription_cb (NotifyNotification *notification,
     gchar *action,
     EmpathyNotificationsApprover *self)
 {
-  EmpathyContactManager *manager;
-
   if (self->priv->event == NULL)
     return;
 
-  manager = empathy_contact_manager_dup_singleton ();
-  empathy_contact_list_remove (EMPATHY_CONTACT_LIST (manager),
-      self->priv->event->contact, "");
+  empathy_contact_remove_from_contact_list (self->priv->event->contact);
 
   empathy_event_remove (self->priv->event);
-
-  g_object_unref (manager);
 }
 
 static void
@@ -160,38 +163,45 @@ notification_accept_subscription_cb (NotifyNotification *notification,
     gchar *action,
     EmpathyNotificationsApprover *self)
 {
-  EmpathyContactManager *manager;
-
   if (self->priv->event == NULL)
     return;
 
-  manager = empathy_contact_manager_dup_singleton ();
-  empathy_contact_list_add (EMPATHY_CONTACT_LIST (manager),
-      self->priv->event->contact, "");
+  empathy_contact_add_to_contact_list (self->priv->event->contact, "");
 
   empathy_event_remove (self->priv->event);
-
-  g_object_unref (manager);
 }
 
 static void
 add_notification_actions (EmpathyNotificationsApprover *self,
     NotifyNotification *notification)
 {
+  gboolean video;
+
   switch (self->priv->event->type) {
     case EMPATHY_EVENT_TYPE_CHAT:
+    case EMPATHY_EVENT_TYPE_MENTIONED:
       notify_notification_add_action (notification,
         "respond", _("Respond"), (NotifyActionCallback) notification_approve_cb,
           self, NULL);
       break;
 
-    case EMPATHY_EVENT_TYPE_VOIP:
+    case EMPATHY_EVENT_TYPE_CALL:
+        video = tp_call_channel_has_initial_video (
+            TP_CALL_CHANNEL (self->priv->event->handler_instance), NULL);
+
       notify_notification_add_action (notification,
         "reject", _("Reject"), (NotifyActionCallback) notification_decline_cb,
           self, NULL);
 
+      if (video && self->priv->event->type == EMPATHY_EVENT_TYPE_CALL)
+          notify_notification_add_action (notification,
+          "answer-no-video", _("Answer"),
+          (NotifyActionCallback) notification_approve_no_video_cb,
+          self, NULL);
+
       notify_notification_add_action (notification,
-        "answer", _("Answer"), (NotifyActionCallback) notification_approve_cb,
+          "answer", video ? _("Answer with video") : _("Answer"),
+          (NotifyActionCallback) notification_approve_cb,
           self, NULL);
       break;
 
@@ -216,12 +226,68 @@ add_notification_actions (EmpathyNotificationsApprover *self,
         "accept", _("Accept"),
           (NotifyActionCallback) notification_accept_subscription_cb,
           self, NULL);
+      break;
+
+    case EMPATHY_EVENT_TYPE_AUTH:
+      notify_notification_add_action (notification,
+        /* translators: the 'Provide' button is displayed in a notification
+         * bubble when Empathy is asking for an account password; clicking on it
+         * brings the password popup. */
+        "provide", _("Provide"), (NotifyActionCallback) notification_approve_cb,
+          self, NULL);
+      break;
 
     default:
       break;
   }
 }
 
+static gboolean
+notification_is_urgent (EmpathyNotificationsApprover *self,
+    NotifyNotification *notification)
+{
+  /* Mark as urgent all the notifications with which user should
+   * interact ASAP */
+  switch (self->priv->event->type) {
+    case EMPATHY_EVENT_TYPE_CHAT:
+    case EMPATHY_EVENT_TYPE_CALL:
+    case EMPATHY_EVENT_TYPE_TRANSFER:
+    case EMPATHY_EVENT_TYPE_INVITATION:
+    case EMPATHY_EVENT_TYPE_AUTH:
+    case EMPATHY_EVENT_TYPE_MENTIONED:
+      return TRUE;
+
+    case EMPATHY_EVENT_TYPE_SUBSCRIPTION:
+    case EMPATHY_EVENT_TYPE_PRESENCE_ONLINE:
+    case EMPATHY_EVENT_TYPE_PRESENCE_OFFLINE:
+      return FALSE;
+  }
+
+  return FALSE;
+}
+
+static const gchar *
+get_category_for_event_type (EmpathyEventType type)
+{
+#define CASE(x) \
+    case EMPATHY_EVENT_TYPE_##x: \
+      return EMPATHY_NOTIFICATION_CATEGORY_##x;
+  switch (type) {
+    CASE(CHAT)
+    CASE(PRESENCE_ONLINE)
+    CASE(PRESENCE_OFFLINE)
+    CASE(CALL)
+    CASE(TRANSFER)
+    CASE(INVITATION)
+    CASE(AUTH)
+    CASE(SUBSCRIPTION)
+    CASE(MENTIONED)
+  }
+#undef CASE
+
+  return NULL;
+}
+
 static void
 update_notification (EmpathyNotificationsApprover *self)
 {
@@ -261,14 +327,16 @@ update_notification (EmpathyNotificationsApprover *self)
     }
   else
     {
+      const gchar *category;
+
       /* if the notification server supports x-canonical-append,
        * the hint will be added, so that the message from the
        * just created notification will be automatically appended
        * to an existing notification with the same title.
        * In this way the previous message will not be lost: the new
        * message will appear below it, in the same notification */
-      notification = notify_notification_new (self->priv->event->header,
-           message_esc, NULL);
+      notification = empathy_notify_manager_create_notification (
+          self->priv->event->header, message_esc, NULL);
 
       if (self->priv->notification == NULL)
         {
@@ -278,16 +346,27 @@ update_notification (EmpathyNotificationsApprover *self)
               G_CALLBACK (notification_closed_cb), self);
         }
 
-      notify_notification_set_timeout (notification,
-          NOTIFY_EXPIRES_DEFAULT);
-
       if (has_x_canonical_append)
-        notify_notification_set_hint_string (notification,
-            EMPATHY_NOTIFY_MANAGER_CAP_X_CANONICAL_APPEND, "");
+        {
+          notify_notification_set_hint (notification,
+              EMPATHY_NOTIFY_MANAGER_CAP_X_CANONICAL_APPEND,
+              g_variant_new_boolean (TRUE));
+        }
 
       if (empathy_notify_manager_has_capability (self->priv->notify_mgr,
             EMPATHY_NOTIFY_MANAGER_CAP_ACTIONS))
         add_notification_actions (self, notification);
+
+      if (notification_is_urgent (self, notification))
+        notify_notification_set_urgency (notification, NOTIFY_URGENCY_CRITICAL);
+
+      category = get_category_for_event_type (self->priv->event->type);
+      if (category != NULL)
+        {
+          notify_notification_set_hint (notification,
+              EMPATHY_NOTIFY_MANAGER_CAP_CATEGORY,
+              g_variant_new_string (category));
+        }
     }
 
   pixbuf = empathy_notify_manager_get_pixbuf_for_notification (
@@ -296,7 +375,7 @@ update_notification (EmpathyNotificationsApprover *self)
 
   if (pixbuf != NULL)
     {
-      notify_notification_set_icon_from_pixbuf (notification, pixbuf);
+      notify_notification_set_image_from_pixbuf (notification, pixbuf);
       g_object_unref (pixbuf);
     }
 
@@ -314,9 +393,6 @@ event_added_cb (EmpathyEventManager *manager,
   if (self->priv->event != NULL)
     return;
 
-  if (event->type == EMPATHY_EVENT_TYPE_AUTH)
-    return;
-
   self->priv->event = event;
 
   update_notification (self);
@@ -330,9 +406,6 @@ event_removed_cb (EmpathyEventManager *manager,
   if (event != self->priv->event)
     return;
 
-  if (event->type == EMPATHY_EVENT_TYPE_AUTH)
-    return;
-
   self->priv->event = empathy_event_manager_get_top_event (
       self->priv->event_mgr);
 
@@ -347,9 +420,6 @@ event_updated_cb (EmpathyEventManager *manager,
   if (event != self->priv->event)
     return;
 
-  if (event->type == EMPATHY_EVENT_TYPE_AUTH)
-    return;
-
   if (empathy_notify_manager_notification_is_enabled (self->priv->notify_mgr))
     update_notification (self);
 }