2014-06-23 19:41:54 +04:00
|
|
|
//
|
|
|
|
// Copyright (C) 2014 Tom Beckmann
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
using Meta;
|
|
|
|
|
|
|
|
namespace Gala.Plugins.Notify
|
|
|
|
{
|
2015-06-03 13:52:33 +03:00
|
|
|
const string APP_BUBBLES_SHOW = "show";
|
|
|
|
const string APP_BUBBLES_HIDE = "hide";
|
|
|
|
const string APP_SOUNDS_ON = "on";
|
|
|
|
const string APP_SOUNDS_OFF = "off";
|
|
|
|
|
|
|
|
const string X_CANONICAL_PRIVATE_SYNCHRONOUS = "x-canonical-private-synchronous";
|
|
|
|
const string X_CANONICAL_PRIVATE_ICON_ONLY = "x-canonical-private-icon-only";
|
|
|
|
|
2014-07-21 06:00:32 +04:00
|
|
|
public enum NotificationUrgency
|
|
|
|
{
|
2014-06-23 19:41:54 +04:00
|
|
|
LOW = 0,
|
|
|
|
NORMAL = 1,
|
|
|
|
CRITICAL = 2
|
|
|
|
}
|
|
|
|
|
2014-07-21 06:00:32 +04:00
|
|
|
public enum NotificationClosedReason
|
|
|
|
{
|
|
|
|
EXPIRED = 1,
|
|
|
|
DISMISSED = 2,
|
|
|
|
CLOSE_NOTIFICATION_CALL = 3,
|
|
|
|
UNDEFINED = 4
|
|
|
|
}
|
|
|
|
|
2014-06-24 03:27:33 +04:00
|
|
|
[DBus (name = "org.freedesktop.DBus")]
|
|
|
|
private interface DBus : Object
|
|
|
|
{
|
|
|
|
[DBus (name = "GetConnectionUnixProcessID")]
|
|
|
|
public abstract uint32 get_connection_unix_process_id (string name) throws Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
[DBus (name = "org.freedesktop.Notifications")]
|
2014-06-23 19:41:54 +04:00
|
|
|
public class NotifyServer : Object
|
|
|
|
{
|
2014-06-28 03:47:13 +04:00
|
|
|
const int DEFAULT_TMEOUT = 4000;
|
2014-06-23 19:41:54 +04:00
|
|
|
const string FALLBACK_ICON = "dialog-information";
|
|
|
|
|
|
|
|
[DBus (visible = false)]
|
2014-07-18 15:12:31 +04:00
|
|
|
public signal void show_notification (Notification notification);
|
2014-06-23 19:41:54 +04:00
|
|
|
|
2014-07-21 06:00:32 +04:00
|
|
|
public signal void notification_closed (uint32 id, uint32 reason);
|
|
|
|
public signal void action_invoked (uint32 id, string action_key);
|
2014-06-23 19:41:54 +04:00
|
|
|
|
2014-07-18 15:12:31 +04:00
|
|
|
[DBus (visible = false)]
|
|
|
|
public NotificationStack stack { get; construct; }
|
|
|
|
|
2014-06-23 19:41:54 +04:00
|
|
|
uint32 id_counter = 0;
|
|
|
|
|
2014-06-24 03:27:33 +04:00
|
|
|
DBus? bus_proxy = null;
|
2014-07-23 21:23:00 +04:00
|
|
|
unowned Canberra.Context? ca_context = null;
|
2014-06-24 03:27:33 +04:00
|
|
|
|
2014-07-18 15:12:31 +04:00
|
|
|
public NotifyServer (NotificationStack stack)
|
2014-06-23 19:41:54 +04:00
|
|
|
{
|
2014-07-23 21:23:00 +04:00
|
|
|
Object (stack: stack);
|
2014-07-19 13:37:14 +04:00
|
|
|
}
|
2014-07-18 15:12:31 +04:00
|
|
|
|
2014-07-19 13:37:14 +04:00
|
|
|
construct
|
|
|
|
{
|
2014-06-24 03:27:33 +04:00
|
|
|
try {
|
|
|
|
bus_proxy = Bus.get_proxy_sync (BusType.SESSION, "org.freedesktop.DBus", "/");
|
|
|
|
} catch (Error e) {
|
|
|
|
warning (e.message);
|
|
|
|
bus_proxy = null;
|
|
|
|
}
|
2014-07-21 19:45:32 +04:00
|
|
|
|
|
|
|
var locale = Intl.setlocale (LocaleCategory.MESSAGES, null);
|
2014-07-23 21:23:00 +04:00
|
|
|
ca_context = CanberraGtk.context_get ();
|
2014-07-21 19:45:32 +04:00
|
|
|
ca_context.change_props (Canberra.PROP_APPLICATION_NAME, "Gala",
|
|
|
|
Canberra.PROP_APPLICATION_ID, "org.pantheon.gala",
|
2014-07-23 21:23:00 +04:00
|
|
|
Canberra.PROP_APPLICATION_NAME, "start-here",
|
|
|
|
Canberra.PROP_APPLICATION_LANGUAGE, locale,
|
|
|
|
null);
|
2014-07-21 19:45:32 +04:00
|
|
|
ca_context.open ();
|
2014-06-23 19:41:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public string [] get_capabilities ()
|
|
|
|
{
|
2014-07-18 15:12:31 +04:00
|
|
|
return {
|
|
|
|
"body",
|
|
|
|
"body-markup",
|
2014-07-21 19:45:32 +04:00
|
|
|
"sound",
|
2014-10-07 21:08:31 +04:00
|
|
|
// even though we don't fully support actions, we still want to receive the default
|
|
|
|
// action. Well written applications will check if the actions capability is available
|
|
|
|
// before settings a default action, so we have to specify it here. Also, not displaying
|
|
|
|
// certain actions even though requested is allowed according to spec, so we should be fine
|
|
|
|
"actions",
|
2015-06-03 13:52:33 +03:00
|
|
|
X_CANONICAL_PRIVATE_SYNCHRONOUS,
|
|
|
|
X_CANONICAL_PRIVATE_ICON_ONLY
|
2014-07-18 15:12:31 +04:00
|
|
|
};
|
2014-06-23 19:41:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void get_server_information (out string name, out string vendor,
|
|
|
|
out string version, out string spec_version)
|
|
|
|
{
|
|
|
|
name = "pantheon-notify";
|
|
|
|
vendor = "elementaryOS";
|
|
|
|
version = "0.1";
|
|
|
|
spec_version = "1.1";
|
|
|
|
}
|
|
|
|
|
2014-07-21 06:00:32 +04:00
|
|
|
/**
|
|
|
|
* Implementation of the CloseNotification DBus method
|
|
|
|
*
|
|
|
|
* @param id The id of the notification to be closed.
|
|
|
|
*/
|
|
|
|
public void close_notification (uint32 id) throws DBusError
|
|
|
|
{
|
|
|
|
foreach (var child in stack.get_children ()) {
|
|
|
|
unowned Notification notification = (Notification) child;
|
2014-07-23 21:23:00 +04:00
|
|
|
if (notification.id != id)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
notification_closed_callback (notification, id,
|
|
|
|
NotificationClosedReason.CLOSE_NOTIFICATION_CALL);
|
|
|
|
notification.close ();
|
|
|
|
|
|
|
|
return;
|
2014-07-21 06:00:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// according to spec, an empty dbus error should be sent if the notification
|
|
|
|
// doesn't exist (anymore)
|
|
|
|
throw new DBusError.FAILED ("");
|
|
|
|
}
|
|
|
|
|
2014-06-23 19:41:54 +04:00
|
|
|
public new uint32 notify (string app_name, uint32 replaces_id, string app_icon, string summary,
|
2014-06-24 03:27:33 +04:00
|
|
|
string body, string[] actions, HashTable<string, Variant> hints, int32 expire_timeout, BusName sender)
|
2014-06-23 19:41:54 +04:00
|
|
|
{
|
2015-06-03 13:52:33 +03:00
|
|
|
unowned Variant? variant;
|
2014-07-21 19:45:40 +04:00
|
|
|
|
2015-06-03 13:52:33 +03:00
|
|
|
var id = (replaces_id != 0 ? replaces_id : ++id_counter);
|
2014-07-21 19:45:40 +04:00
|
|
|
var pixbuf = get_pixbuf (app_name, app_icon, hints);
|
2015-06-03 13:52:33 +03:00
|
|
|
var timeout = (expire_timeout == uint32.MAX ? DEFAULT_TMEOUT : expire_timeout);
|
2014-07-21 19:45:40 +04:00
|
|
|
|
|
|
|
var urgency = NotificationUrgency.NORMAL;
|
|
|
|
if ((variant = hints.lookup ("urgency")) != null)
|
|
|
|
urgency = (NotificationUrgency) variant.get_byte ();
|
2014-06-23 19:41:54 +04:00
|
|
|
|
2015-06-03 13:52:33 +03:00
|
|
|
var icon_only = hints.contains (X_CANONICAL_PRIVATE_ICON_ONLY);
|
|
|
|
var confirmation = hints.contains (X_CANONICAL_PRIVATE_SYNCHRONOUS);
|
2014-07-18 15:12:31 +04:00
|
|
|
var progress = confirmation && hints.contains ("value");
|
|
|
|
|
2015-03-12 17:15:47 +03:00
|
|
|
unowned NotifySettings options = NotifySettings.get_default ();
|
2014-11-12 00:43:35 +03:00
|
|
|
|
2014-11-10 01:27:08 +03:00
|
|
|
// Default values for confirmations
|
2014-11-07 18:11:23 +03:00
|
|
|
var allow_bubble = true;
|
|
|
|
var allow_sound = true;
|
|
|
|
|
2014-11-10 01:27:08 +03:00
|
|
|
if (!confirmation) {
|
|
|
|
var app_found = false;
|
2015-06-03 14:18:23 +03:00
|
|
|
var app_key = app_name.replace (":", "_").down ();
|
2014-11-07 18:11:23 +03:00
|
|
|
|
2015-06-05 21:03:11 +03:00
|
|
|
string[] parameters;
|
2015-06-03 13:52:33 +03:00
|
|
|
unowned string param_bubbles = (options.default_bubbles ? APP_BUBBLES_SHOW : APP_BUBBLES_HIDE);
|
|
|
|
unowned string param_sounds = (options.default_sounds ? APP_SOUNDS_ON : APP_SOUNDS_OFF);
|
2014-11-07 18:11:23 +03:00
|
|
|
|
2015-06-03 13:52:33 +03:00
|
|
|
foreach (unowned string app in options.apps) {
|
|
|
|
var properties = app.split (":");
|
2014-11-09 20:58:38 +03:00
|
|
|
|
2015-06-03 14:18:23 +03:00
|
|
|
if (properties.length == 2 && properties[0].down () == app_key) {
|
2015-06-05 21:03:11 +03:00
|
|
|
parameters = properties[1].split (",");
|
2014-11-10 01:27:08 +03:00
|
|
|
|
2015-06-03 13:52:33 +03:00
|
|
|
if (parameters.length == 2) {
|
|
|
|
param_bubbles = parameters[0];
|
|
|
|
param_sounds = parameters[1];
|
2014-11-15 19:22:06 +03:00
|
|
|
|
2015-06-03 13:52:33 +03:00
|
|
|
app_found = true;
|
2014-11-15 19:22:06 +03:00
|
|
|
|
2015-06-03 13:52:33 +03:00
|
|
|
break;
|
2014-11-09 20:58:38 +03:00
|
|
|
}
|
|
|
|
}
|
2014-11-07 18:11:23 +03:00
|
|
|
}
|
|
|
|
|
2015-06-03 13:52:33 +03:00
|
|
|
// if no matching app was found, add the default values to the list
|
2014-11-10 01:27:08 +03:00
|
|
|
if (!app_found) {
|
2015-06-03 13:52:33 +03:00
|
|
|
var apps_new = options.apps;
|
2015-06-03 14:18:23 +03:00
|
|
|
apps_new += "%s:%s,%s".printf (app_key, param_bubbles, param_sounds);
|
2014-11-12 00:43:35 +03:00
|
|
|
options.apps = apps_new;
|
2014-11-10 01:27:08 +03:00
|
|
|
}
|
2014-11-07 18:11:23 +03:00
|
|
|
|
2015-06-03 13:52:33 +03:00
|
|
|
allow_bubble = (!options.do_not_disturb && param_bubbles == APP_BUBBLES_SHOW);
|
|
|
|
allow_sound = (allow_bubble && param_sounds == APP_SOUNDS_ON);
|
2014-11-10 01:27:08 +03:00
|
|
|
}
|
2014-11-07 18:11:23 +03:00
|
|
|
|
2014-07-22 22:18:54 +04:00
|
|
|
#if 0 // enable to debug notifications
|
2014-07-18 15:12:31 +04:00
|
|
|
print ("Notification from '%s', replaces: %u\n" +
|
|
|
|
"\tapp icon: '%s'\n\tsummary: '%s'\n\tbody: '%s'\n\tn actions: %u\n\texpire: %i\n\tHints:\n",
|
|
|
|
app_name, replaces_id, app_icon, summary, body, actions.length);
|
|
|
|
hints.@foreach ((key, val) => {
|
|
|
|
print ("\t\t%s => %s\n", key, val.is_of_type (VariantType.STRING) ?
|
|
|
|
val.get_string () : "<" + val.get_type ().dup_string () + ">");
|
|
|
|
});
|
2014-10-07 21:08:31 +04:00
|
|
|
print ("\tActions: ");
|
|
|
|
foreach (var action in actions) {
|
|
|
|
print ("%s, ", action);
|
|
|
|
}
|
|
|
|
print ("\n");
|
2014-07-18 15:12:31 +04:00
|
|
|
#endif
|
|
|
|
|
2014-06-24 03:27:33 +04:00
|
|
|
uint32 pid = 0;
|
|
|
|
try {
|
|
|
|
pid = bus_proxy.get_connection_unix_process_id (sender);
|
|
|
|
} catch (Error e) { warning (e.message); }
|
2014-06-23 19:41:54 +04:00
|
|
|
|
2014-11-07 18:11:23 +03:00
|
|
|
if (allow_sound)
|
2014-11-03 14:35:33 +03:00
|
|
|
handle_sounds (hints);
|
2014-07-21 19:45:32 +04:00
|
|
|
|
2014-07-18 15:12:31 +04:00
|
|
|
foreach (var child in stack.get_children ()) {
|
|
|
|
unowned Notification notification = (Notification) child;
|
|
|
|
|
2014-07-19 21:03:17 +04:00
|
|
|
if (notification.being_destroyed)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// we only want a single confirmation notification, so we just take the
|
|
|
|
// first one that can be found, no need to check ids or anything
|
2014-07-21 19:45:40 +04:00
|
|
|
unowned ConfirmationNotification? confirmation_notification = notification as ConfirmationNotification;
|
|
|
|
if (confirmation
|
|
|
|
&& confirmation_notification != null) {
|
2014-08-11 02:30:29 +04:00
|
|
|
|
|
|
|
// value may be -1 for a muted state, but -1 is interpreted as no progress set by the
|
|
|
|
// ConfirmationNotification class, so if we do have a progress, we make sure it's set
|
|
|
|
// to 0 for a muted state.
|
|
|
|
var progress_value = progress ? int.max (hints.@get ("value").get_int32 (), 0) : -1;
|
|
|
|
|
2014-07-19 21:03:17 +04:00
|
|
|
confirmation_notification.update (pixbuf,
|
2014-08-11 02:30:29 +04:00
|
|
|
progress_value,
|
2015-06-03 13:52:33 +03:00
|
|
|
hints.@get (X_CANONICAL_PRIVATE_SYNCHRONOUS).get_string (),
|
2014-07-21 04:53:07 +04:00
|
|
|
icon_only);
|
2014-07-19 21:03:17 +04:00
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2014-07-21 19:45:40 +04:00
|
|
|
unowned NormalNotification? normal_notification = notification as NormalNotification;
|
2014-07-21 05:21:19 +04:00
|
|
|
if (!confirmation
|
|
|
|
&& notification.id == id
|
|
|
|
&& normal_notification != null) {
|
2014-07-18 15:12:31 +04:00
|
|
|
|
2014-07-21 19:45:40 +04:00
|
|
|
normal_notification.update (summary, body, pixbuf, timeout, actions);
|
2014-07-18 15:12:31 +04:00
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-07 18:11:23 +03:00
|
|
|
if (allow_bubble) {
|
2014-11-03 14:35:33 +03:00
|
|
|
Notification notification;
|
|
|
|
if (confirmation)
|
|
|
|
notification = new ConfirmationNotification (id, pixbuf, icon_only,
|
|
|
|
progress ? hints.@get ("value").get_int32 () : -1,
|
2015-06-03 13:52:33 +03:00
|
|
|
hints.@get (X_CANONICAL_PRIVATE_SYNCHRONOUS).get_string ());
|
2014-11-03 14:35:33 +03:00
|
|
|
else
|
|
|
|
notification = new NormalNotification (stack.screen, id, summary, body, pixbuf,
|
|
|
|
urgency, timeout, pid, actions);
|
2014-06-23 19:41:54 +04:00
|
|
|
|
2014-11-03 14:35:33 +03:00
|
|
|
notification.action_invoked.connect (notification_action_invoked_callback);
|
|
|
|
notification.closed.connect (notification_closed_callback);
|
|
|
|
stack.show_notification (notification);
|
|
|
|
}
|
2014-07-18 15:12:31 +04:00
|
|
|
|
2014-08-01 15:25:31 +04:00
|
|
|
#if !VALA_0_26
|
|
|
|
// fixes memleaks as described in https://bugzilla.gnome.org/show_bug.cgi?id=698260
|
|
|
|
// valac >= 0.26 already has this fix
|
|
|
|
hints.@foreach ((key, val) => {
|
|
|
|
g_variant_unref (val);
|
|
|
|
});
|
|
|
|
#endif
|
|
|
|
|
2014-07-18 15:12:31 +04:00
|
|
|
return id;
|
2014-06-23 19:41:54 +04:00
|
|
|
}
|
|
|
|
|
2014-07-21 19:45:40 +04:00
|
|
|
static Gdk.Pixbuf? get_pixbuf (string app_name, string app_icon, HashTable<string, Variant> hints)
|
2014-06-23 19:41:54 +04:00
|
|
|
{
|
|
|
|
// decide on the icon, order:
|
|
|
|
// - image-data
|
|
|
|
// - image-path
|
|
|
|
// - app_icon
|
|
|
|
// - icon_data
|
|
|
|
// - from app name?
|
|
|
|
// - fallback to dialog-information
|
|
|
|
|
|
|
|
Gdk.Pixbuf? pixbuf = null;
|
2014-07-21 19:45:40 +04:00
|
|
|
Variant? variant = null;
|
2014-06-23 19:41:54 +04:00
|
|
|
var size = Notification.ICON_SIZE;
|
2014-07-20 23:01:52 +04:00
|
|
|
var mask_offset = 4;
|
|
|
|
var mask_size_offset = mask_offset * 2;
|
|
|
|
var has_mask = false;
|
|
|
|
|
2014-07-21 19:45:40 +04:00
|
|
|
if ((variant = hints.lookup ("image-data")) != null
|
2014-07-23 21:51:49 +04:00
|
|
|
|| (variant = hints.lookup ("image_data")) != null
|
|
|
|
|| (variant = hints.lookup ("icon_data")) != null) {
|
2014-06-23 19:41:54 +04:00
|
|
|
|
2014-07-20 23:01:52 +04:00
|
|
|
has_mask = true;
|
|
|
|
size = size - mask_size_offset;
|
|
|
|
|
2014-07-21 19:45:40 +04:00
|
|
|
pixbuf = load_from_variant_at_size (variant, size);
|
2014-06-23 19:41:54 +04:00
|
|
|
|
2014-07-21 19:45:40 +04:00
|
|
|
} else if ((variant = hints.lookup ("image-path")) != null
|
|
|
|
|| (variant = hints.lookup ("image_path")) != null) {
|
2014-06-23 19:41:54 +04:00
|
|
|
|
2014-07-21 19:45:40 +04:00
|
|
|
var image_path = variant.get_string ();
|
2014-06-23 19:41:54 +04:00
|
|
|
|
|
|
|
try {
|
2014-06-23 23:21:37 +04:00
|
|
|
if (image_path.has_prefix ("file://") || image_path.has_prefix ("/")) {
|
2014-07-20 23:01:52 +04:00
|
|
|
has_mask = true;
|
|
|
|
size = size - mask_size_offset;
|
|
|
|
|
2014-06-23 23:21:37 +04:00
|
|
|
var file_path = File.new_for_commandline_arg (image_path).get_path ();
|
|
|
|
pixbuf = new Gdk.Pixbuf.from_file_at_scale (file_path, size, size, true);
|
2014-06-23 19:41:54 +04:00
|
|
|
} else {
|
|
|
|
pixbuf = Gtk.IconTheme.get_default ().load_icon (image_path, size, 0);
|
|
|
|
}
|
|
|
|
} catch (Error e) { warning (e.message); }
|
|
|
|
|
2014-07-21 19:45:40 +04:00
|
|
|
} else if (app_icon != "") {
|
2014-06-23 19:41:54 +04:00
|
|
|
|
|
|
|
try {
|
2014-07-21 19:45:40 +04:00
|
|
|
var themed = new ThemedIcon.with_default_fallbacks (app_icon);
|
2014-07-19 04:42:21 +04:00
|
|
|
var info = Gtk.IconTheme.get_default ().lookup_by_gicon (themed, size, 0);
|
2015-05-26 12:43:31 +03:00
|
|
|
if (info != null) {
|
2014-07-19 04:42:21 +04:00
|
|
|
pixbuf = info.load_icon ();
|
2015-05-26 12:43:31 +03:00
|
|
|
|
2015-05-26 14:18:07 +03:00
|
|
|
if (pixbuf.height != size)
|
2015-05-26 12:43:31 +03:00
|
|
|
pixbuf = pixbuf.scale_simple (size, size, Gdk.InterpType.HYPER);
|
|
|
|
|
|
|
|
}
|
2014-06-23 23:21:37 +04:00
|
|
|
} catch (Error e) { warning (e.message); }
|
2014-07-18 15:12:31 +04:00
|
|
|
|
2014-06-23 19:41:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pixbuf == null) {
|
2014-06-23 23:21:37 +04:00
|
|
|
|
2014-06-23 19:41:54 +04:00
|
|
|
try {
|
2014-07-21 19:45:40 +04:00
|
|
|
pixbuf = Gtk.IconTheme.get_default ().load_icon (app_name.down (), size, 0);
|
2014-06-23 19:41:54 +04:00
|
|
|
} catch (Error e) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
pixbuf = Gtk.IconTheme.get_default ().load_icon (FALLBACK_ICON, size, 0);
|
|
|
|
} catch (Error e) { warning (e.message); }
|
|
|
|
}
|
2014-07-20 23:01:52 +04:00
|
|
|
} else if (has_mask) {
|
|
|
|
var mask_size = Notification.ICON_SIZE;
|
|
|
|
var offset_x = mask_offset;
|
|
|
|
var offset_y = mask_offset + 1;
|
|
|
|
|
|
|
|
var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, mask_size, mask_size);
|
|
|
|
var cr = new Cairo.Context (surface);
|
|
|
|
|
|
|
|
Granite.Drawing.Utilities.cairo_rounded_rectangle (cr,
|
|
|
|
offset_x, offset_y, size, size, 4);
|
|
|
|
cr.clip ();
|
|
|
|
|
|
|
|
Gdk.cairo_set_source_pixbuf (cr, pixbuf, offset_x, offset_y);
|
|
|
|
cr.paint ();
|
|
|
|
|
|
|
|
cr.reset_clip ();
|
|
|
|
|
|
|
|
var mask = new Cairo.ImageSurface.from_png (Config.PKGDATADIR + "/image-mask.png");
|
|
|
|
cr.set_source_surface (mask, 0, 0);
|
|
|
|
cr.paint ();
|
|
|
|
|
|
|
|
pixbuf = Gdk.pixbuf_get_from_surface (surface, 0, 0, mask_size, mask_size);
|
2014-06-23 19:41:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return pixbuf;
|
|
|
|
}
|
2014-07-19 23:42:33 +04:00
|
|
|
|
|
|
|
static Gdk.Pixbuf? load_from_variant_at_size (Variant variant, int size)
|
|
|
|
{
|
|
|
|
if (!variant.is_of_type (new VariantType ("(iiibiiay)"))) {
|
|
|
|
critical ("notify icon/image-data format invalid");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
int width, height, rowstride, bits_per_sample, n_channels;
|
|
|
|
bool has_alpha;
|
|
|
|
|
|
|
|
variant.get ("(iiibiiay)", out width, out height, out rowstride,
|
|
|
|
out has_alpha, out bits_per_sample, out n_channels, null);
|
|
|
|
|
|
|
|
var data = variant.get_child_value (6);
|
|
|
|
unowned uint8[] pixel_data = (uint8[]) data.get_data ();
|
|
|
|
|
2014-07-21 19:45:40 +04:00
|
|
|
var pixbuf = new Gdk.Pixbuf.with_unowned_data (pixel_data, Gdk.Colorspace.RGB, has_alpha,
|
|
|
|
bits_per_sample, width, height, rowstride, null);
|
|
|
|
|
2014-07-19 23:42:33 +04:00
|
|
|
return pixbuf.scale_simple (size, size, Gdk.InterpType.BILINEAR);
|
2014-07-21 19:45:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_sounds (HashTable<string,Variant> hints)
|
|
|
|
{
|
2014-07-23 23:38:23 +04:00
|
|
|
if (ca_context == null)
|
|
|
|
return;
|
|
|
|
|
2014-07-23 21:23:00 +04:00
|
|
|
Variant? variant = null;
|
|
|
|
|
2014-07-23 23:38:23 +04:00
|
|
|
// Are we suppose to play a sound at all?
|
|
|
|
if ((variant = hints.lookup ("supress-sound")) != null
|
|
|
|
&& variant.get_boolean ())
|
2014-07-21 19:45:32 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
Canberra.Proplist props;
|
|
|
|
Canberra.Proplist.create (out props);
|
|
|
|
props.sets (Canberra.PROP_CANBERRA_CACHE_CONTROL, "volatile");
|
|
|
|
|
|
|
|
bool play_sound = false;
|
|
|
|
|
2014-07-22 22:06:09 +04:00
|
|
|
// no sounds for confirmation bubbles
|
2015-06-03 13:52:33 +03:00
|
|
|
if ((variant = hints.lookup (X_CANONICAL_PRIVATE_SYNCHRONOUS)) != null) {
|
2014-07-23 21:23:00 +04:00
|
|
|
var confirmation_type = variant.get_string ();
|
2014-07-21 19:45:32 +04:00
|
|
|
|
2014-07-22 22:06:09 +04:00
|
|
|
// the sound indicator is an exception here, it won't emit a sound at all, even though for
|
|
|
|
// consistency it should. So we make it emit the default one.
|
|
|
|
if (confirmation_type != "indicator-sound")
|
2014-07-21 19:45:32 +04:00
|
|
|
return;
|
|
|
|
|
2014-07-22 22:06:09 +04:00
|
|
|
props.sets (Canberra.PROP_EVENT_ID, "audio-volume-change");
|
|
|
|
play_sound = true;
|
2014-07-21 19:45:32 +04:00
|
|
|
}
|
|
|
|
|
2014-07-23 21:23:00 +04:00
|
|
|
if ((variant = hints.lookup ("sound-name")) != null) {
|
2014-07-23 23:38:23 +04:00
|
|
|
props.sets (Canberra.PROP_EVENT_ID, variant.get_string ());
|
2014-07-21 19:45:32 +04:00
|
|
|
play_sound = true;
|
|
|
|
}
|
|
|
|
|
2014-07-23 21:23:00 +04:00
|
|
|
if ((variant = hints.lookup ("sound-file")) != null) {
|
2014-07-23 23:38:23 +04:00
|
|
|
props.sets (Canberra.PROP_MEDIA_FILENAME, variant.get_string ());
|
2014-07-21 19:45:32 +04:00
|
|
|
play_sound = true;
|
|
|
|
}
|
|
|
|
|
2014-07-22 22:06:09 +04:00
|
|
|
// pick a sound according to the category
|
2014-07-21 19:45:32 +04:00
|
|
|
if (!play_sound) {
|
2014-07-23 23:38:23 +04:00
|
|
|
variant = hints.lookup ("category");
|
2015-06-03 13:52:33 +03:00
|
|
|
unowned string? sound_name = null;
|
2014-07-21 19:45:32 +04:00
|
|
|
|
2014-07-23 23:38:23 +04:00
|
|
|
if (variant != null)
|
|
|
|
sound_name = category_to_sound (variant.get_string ());
|
|
|
|
else
|
|
|
|
sound_name = "dialog-information";
|
2014-07-21 19:45:32 +04:00
|
|
|
|
2014-07-23 23:38:23 +04:00
|
|
|
if (sound_name != null) {
|
|
|
|
props.sets (Canberra.PROP_EVENT_ID, sound_name);
|
|
|
|
play_sound = true;
|
2014-07-21 19:45:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (play_sound)
|
|
|
|
ca_context.play_full (0, props);
|
|
|
|
}
|
2014-07-21 06:00:32 +04:00
|
|
|
|
2015-06-03 13:52:33 +03:00
|
|
|
static unowned string? category_to_sound (string category)
|
2014-07-23 23:38:23 +04:00
|
|
|
{
|
2015-06-03 13:52:33 +03:00
|
|
|
unowned string? sound = null;
|
2014-07-23 23:38:23 +04:00
|
|
|
|
|
|
|
switch (category) {
|
|
|
|
case "device.added":
|
|
|
|
sound = "device-added";
|
|
|
|
break;
|
|
|
|
case "device.removed":
|
|
|
|
sound = "device-removed";
|
|
|
|
break;
|
|
|
|
case "im":
|
|
|
|
sound = "message";
|
|
|
|
break;
|
|
|
|
case "im.received":
|
|
|
|
sound = "message-new-instant";
|
|
|
|
break;
|
|
|
|
case "network.connected":
|
|
|
|
sound = "network-connectivity-established";
|
|
|
|
break;
|
|
|
|
case "network.disconnected":
|
|
|
|
sound = "network-connectivity-lost";
|
|
|
|
break;
|
|
|
|
case "presence.online":
|
|
|
|
sound = "service-login";
|
|
|
|
break;
|
|
|
|
case "presence.offline":
|
|
|
|
sound = "service-logout";
|
|
|
|
break;
|
|
|
|
// no sound at all
|
|
|
|
case "x-gnome.music":
|
|
|
|
sound = null;
|
|
|
|
break;
|
|
|
|
// generic errors
|
|
|
|
case "device.error":
|
|
|
|
case "email.bounced":
|
|
|
|
case "im.error":
|
|
|
|
case "network.error":
|
|
|
|
case "transfer.error":
|
|
|
|
sound = "dialog-error";
|
|
|
|
break;
|
|
|
|
// use generic default
|
|
|
|
case "network":
|
|
|
|
case "email":
|
|
|
|
case "email.arrived":
|
|
|
|
case "presence":
|
|
|
|
case "transfer":
|
|
|
|
case "transfer.complete":
|
|
|
|
default:
|
|
|
|
sound = "dialog-information";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sound;
|
|
|
|
}
|
|
|
|
|
2014-07-21 06:00:32 +04:00
|
|
|
void notification_closed_callback (Notification notification, uint32 id, uint32 reason)
|
|
|
|
{
|
2014-10-07 22:10:46 +04:00
|
|
|
notification.action_invoked.disconnect (notification_action_invoked_callback);
|
2014-07-21 06:00:32 +04:00
|
|
|
notification.closed.disconnect (notification_closed_callback);
|
|
|
|
|
|
|
|
notification_closed (id, reason);
|
|
|
|
}
|
2014-10-07 21:08:31 +04:00
|
|
|
|
2014-10-07 22:10:46 +04:00
|
|
|
void notification_action_invoked_callback (Notification notification, uint32 id, string action)
|
2014-10-07 21:08:31 +04:00
|
|
|
{
|
2014-10-07 22:10:46 +04:00
|
|
|
action_invoked (id, action);
|
2014-10-07 21:08:31 +04:00
|
|
|
}
|
2014-06-23 19:41:54 +04:00
|
|
|
}
|
2014-11-12 00:43:35 +03:00
|
|
|
}
|