* 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"
}
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,
{
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
{
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);
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,
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))
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))
{
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);
{
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;
}
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,
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
{
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",