[kdbus] KDBUS_ITEM_PAYLOAD_OFF items are (once again) relative to msg header
[platform/upstream/glib.git] / gio / gfdonotificationbackend.c
index ad665be..1603f6e 100644 (file)
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
  *
  * Authors: Lars Uebernickel <lars@uebernic.de>
  */
 
+#include "config.h"
+
 #include "gnotificationbackend.h"
 
 #include "gapplication.h"
 #include "giomodule-priv.h"
 #include "gnotification-private.h"
 #include "gdbusconnection.h"
+#include "gactiongroup.h"
 #include "gaction.h"
 #include "gfileicon.h"
 #include "gfile.h"
@@ -107,6 +108,24 @@ g_fdo_notification_backend_find_notification_by_notify_id (GFdoNotificationBacke
 }
 
 static void
+activate_action (GFdoNotificationBackend *backend,
+                 const gchar             *name,
+                 GVariant                *parameter)
+{
+  GNotificationBackend *g_backend = G_NOTIFICATION_BACKEND (backend);
+
+  if (name)
+    {
+      if (g_str_has_prefix (name, "app."))
+        g_action_group_activate_action (G_ACTION_GROUP (g_backend->application), name + 4, parameter);
+    }
+  else
+    {
+      g_application_activate (g_backend->application);
+    }
+}
+
+static void
 notify_signal (GDBusConnection *connection,
                const gchar     *sender_name,
                const gchar     *object_path,
@@ -141,9 +160,7 @@ notify_signal (GDBusConnection *connection,
     {
       if (g_str_equal (action, "default"))
         {
-          g_notification_backend_activate_action (G_NOTIFICATION_BACKEND (backend),
-                                                  n->default_action,
-                                                  n->default_action_target);
+          activate_action (backend, n->default_action, n->default_action_target);
         }
       else
         {
@@ -152,7 +169,7 @@ notify_signal (GDBusConnection *connection,
 
           if (g_action_parse_detailed_name (action, &name, &target, NULL))
             {
-              g_notification_backend_activate_action (G_NOTIFICATION_BACKEND (backend), name, target);
+              activate_action (backend, name, target);
               g_free (name);
               if (target)
                 g_variant_unref (target);
@@ -164,6 +181,27 @@ notify_signal (GDBusConnection *connection,
   freedesktop_notification_free (n);
 }
 
+/* Converts a GNotificationPriority to an urgency level as defined by
+ * the freedesktop spec (0: low, 1: normal, 2: critical).
+ */
+static guchar
+urgency_from_priority (GNotificationPriority priority)
+{
+  switch (priority)
+    {
+    case G_NOTIFICATION_PRIORITY_LOW:
+      return 0;
+
+    default:
+    case G_NOTIFICATION_PRIORITY_NORMAL:
+      return 1;
+
+    case G_NOTIFICATION_PRIORITY_HIGH:
+    case G_NOTIFICATION_PRIORITY_URGENT:
+      return 2;
+    }
+}
+
 static void
 call_notify (GDBusConnection     *con,
              GApplication        *app,
@@ -179,6 +217,7 @@ call_notify (GDBusConnection     *con,
   GIcon *icon;
   GVariant *parameters;
   const gchar *body;
+  guchar urgency;
 
   g_variant_builder_init (&action_builder, G_VARIANT_TYPE_STRING_ARRAY);
   if (g_notification_get_default_action (notification, NULL, NULL))
@@ -220,8 +259,8 @@ call_notify (GDBusConnection     *con,
   g_variant_builder_init (&hints_builder, G_VARIANT_TYPE ("a{sv}"));
   g_variant_builder_add (&hints_builder, "{sv}", "desktop-entry",
                          g_variant_new_string (g_application_get_application_id (app)));
-  if (g_notification_get_urgent (notification))
-    g_variant_builder_add (&hints_builder, "{sv}", "urgency", g_variant_new_byte (2));
+  urgency = urgency_from_priority (g_notification_get_priority (notification));
+  g_variant_builder_add (&hints_builder, "{sv}", "urgency", g_variant_new_byte (urgency));
   icon = g_notification_get_icon (notification);
   if (icon != NULL && G_IS_FILE_ICON (icon))
     {
@@ -229,7 +268,7 @@ call_notify (GDBusConnection     *con,
 
       file = g_file_icon_get_file (G_FILE_ICON (icon));
       g_variant_builder_add (&hints_builder, "{sv}", "image-path",
-                             g_variant_new_take_string (g_file_get_uri (file)));
+                             g_variant_new_take_string (g_file_get_path (file)));
     }
 
   body = g_notification_get_body (notification);
@@ -292,7 +331,7 @@ g_fdo_notification_backend_dispose (GObject *object)
     {
       GDBusConnection *session_bus;
 
-      session_bus = g_notification_backend_get_dbus_connection (G_NOTIFICATION_BACKEND (backend));
+      session_bus = G_NOTIFICATION_BACKEND (backend)->dbus_connection;
       g_dbus_connection_signal_unsubscribe (session_bus, backend->notify_subscription);
       backend->notify_subscription = 0;
     }
@@ -328,7 +367,7 @@ g_fdo_notification_backend_send_notification (GNotificationBackend *backend,
   if (self->notify_subscription == 0)
     {
       self->notify_subscription =
-        g_dbus_connection_signal_subscribe (g_notification_backend_get_dbus_connection (backend),
+        g_dbus_connection_signal_subscribe (backend->dbus_connection,
                                             "org.freedesktop.Notifications",
                                             "org.freedesktop.Notifications", NULL,
                                             "/org/freedesktop/Notifications", NULL,
@@ -355,9 +394,7 @@ g_fdo_notification_backend_send_notification (GNotificationBackend *backend,
 
   g_notification_get_default_action (notification, &n->default_action, &n->default_action_target);
 
-  call_notify (g_notification_backend_get_dbus_connection (backend),
-               g_notification_backend_get_application (backend),
-               n->notify_id, notification, notification_sent, n);
+  call_notify (backend->dbus_connection, backend->application, n->notify_id, notification, notification_sent, n);
 }
 
 static void
@@ -372,7 +409,7 @@ g_fdo_notification_backend_withdraw_notification (GNotificationBackend *backend,
     {
       if (n->notify_id > 0)
         {
-          g_dbus_connection_call (g_notification_backend_get_dbus_connection (backend),
+          g_dbus_connection_call (backend->dbus_connection,
                                   "org.freedesktop.Notifications",
                                   "/org/freedesktop/Notifications",
                                   "org.freedesktop.Notifications", "CloseNotification",