]> git.0d.be Git - empathy.git/blobdiff - src/empathy-notifications-approver.c
Move should_create_salut_account to local-xmpp-assistant-widget
[empathy.git] / src / empathy-notifications-approver.c
index 4bfe23cf1cb38d36f1c7be1bd8dbe148933f2ca9..ac51459fb76eb8db1a1abd7bf93d1f0137a2162c 100644 (file)
@@ -25,7 +25,9 @@
 #include <libnotify/notify.h>
 #include <telepathy-glib/telepathy-glib.h>
 
-#include <libempathy/empathy-contact-manager.h>
+#include <telepathy-yell/telepathy-yell.h>
+
+#include <libempathy/empathy-tp-streamed-media.h>
 
 #include <libempathy-gtk/empathy-notify-manager.h>
 
@@ -118,6 +120,20 @@ notification_close_helper (EmpathyNotificationsApprover *self)
     }
 }
 
+static void
+notification_approve_no_video_cb (NotifyNotification *notification,
+    gchar *action,
+    EmpathyNotificationsApprover *self)
+{
+  if (self->priv->event)
+    {
+      tpy_call_channel_send_video (
+          TPY_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 +157,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,24 +170,20 @@ 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:
       notify_notification_add_action (notification,
@@ -186,12 +192,27 @@ add_notification_actions (EmpathyNotificationsApprover *self,
       break;
 
     case EMPATHY_EVENT_TYPE_VOIP:
+    case EMPATHY_EVENT_TYPE_CALL:
+      if (self->priv->event->type == EMPATHY_EVENT_TYPE_VOIP)
+        video = empathy_tp_streamed_media_has_initial_video (
+            EMPATHY_TP_STREAMED_MEDIA (self->priv->event->handler_instance));
+      else
+        video = tpy_call_channel_has_initial_video (
+            TPY_CALL_CHANNEL (self->priv->event->handler_instance));
+
       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,6 +237,16 @@ 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;
@@ -231,32 +262,44 @@ notification_is_urgent (EmpathyNotificationsApprover *self,
   switch (self->priv->event->type) {
     case EMPATHY_EVENT_TYPE_CHAT:
     case EMPATHY_EVENT_TYPE_VOIP:
+    case EMPATHY_EVENT_TYPE_CALL:
     case EMPATHY_EVENT_TYPE_TRANSFER:
     case EMPATHY_EVENT_TYPE_INVITATION:
     case EMPATHY_EVENT_TYPE_AUTH:
       return TRUE;
 
     case EMPATHY_EVENT_TYPE_SUBSCRIPTION:
-    case EMPATHY_EVENT_TYPE_PRESENCE:
+    case EMPATHY_EVENT_TYPE_PRESENCE_ONLINE:
+    case EMPATHY_EVENT_TYPE_PRESENCE_OFFLINE:
       return FALSE;
   }
 
   return FALSE;
 }
 
+/* Use x-empathy as prefix for unofficial categories
+ * http://www.galago-project.org/specs/notification/0.9/x211.html */
 static const gchar *
 get_category_for_event_type (EmpathyEventType type)
 {
   switch (type) {
     case EMPATHY_EVENT_TYPE_CHAT:
       return "im.received";
+    case EMPATHY_EVENT_TYPE_PRESENCE_ONLINE:
+      return "presence.online";
+    case EMPATHY_EVENT_TYPE_PRESENCE_OFFLINE:
+      return "presence.offline";
     case EMPATHY_EVENT_TYPE_VOIP:
+    case EMPATHY_EVENT_TYPE_CALL:
+      return "x-empathy.call.incoming";
     case EMPATHY_EVENT_TYPE_TRANSFER:
+      return "x-empathy.transfer.incoming";
     case EMPATHY_EVENT_TYPE_INVITATION:
+      return "x-empathy.im.room-invitation";
     case EMPATHY_EVENT_TYPE_AUTH:
+      return "x-empathy.network.auth-request";
     case EMPATHY_EVENT_TYPE_SUBSCRIPTION:
-    case EMPATHY_EVENT_TYPE_PRESENCE:
-      return NULL;
+      return "x-empathy.im.subscription-request";
   }
 
   return NULL;
@@ -324,8 +367,11 @@ update_notification (EmpathyNotificationsApprover *self)
           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))
@@ -336,8 +382,11 @@ update_notification (EmpathyNotificationsApprover *self)
 
       category = get_category_for_event_type (self->priv->event->type);
       if (category != NULL)
-        notify_notification_set_hint_string (notification,
-            EMPATHY_NOTIFY_MANAGER_CAP_CATEGORY, category);
+        {
+          notify_notification_set_hint (notification,
+              EMPATHY_NOTIFY_MANAGER_CAP_CATEGORY,
+              g_variant_new_string (category));
+        }
     }
 
   pixbuf = empathy_notify_manager_get_pixbuf_for_notification (
@@ -346,7 +395,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);
     }
 
@@ -364,9 +413,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);
@@ -380,9 +426,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);
 
@@ -397,9 +440,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);
 }