| 1 |
/* |
|---|
| 2 |
* Copyright (c) 2006-2007 Sebastian Dröge <slomo@circular-chaos.org> |
|---|
| 3 |
* |
|---|
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|---|
| 5 |
* of this software and associated documentation files (the "Software"), to deal |
|---|
| 6 |
* in the Software without restriction, including without limitation the rights |
|---|
| 7 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|---|
| 8 |
* copies of the Software, and to permit persons to whom the Software is |
|---|
| 9 |
* furnished to do so, subject to the following conditions: |
|---|
| 10 |
* |
|---|
| 11 |
* The above copyright notice and this permission notice shall be included in |
|---|
| 12 |
* all copies or substantial portions of the Software. |
|---|
| 13 |
* |
|---|
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|---|
| 15 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|---|
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|---|
| 17 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|---|
| 18 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|---|
| 19 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|---|
| 20 |
* THE SOFTWARE. |
|---|
| 21 |
*/ |
|---|
| 22 |
|
|---|
| 23 |
using System; |
|---|
| 24 |
using System.Reflection; |
|---|
| 25 |
using System.Collections.Generic; |
|---|
| 26 |
|
|---|
| 27 |
using NDesk.DBus; |
|---|
| 28 |
using org.freedesktop; |
|---|
| 29 |
using org.freedesktop.DBus; |
|---|
| 30 |
|
|---|
| 31 |
namespace Notifications { |
|---|
| 32 |
[Interface ("org.freedesktop.Notifications")] |
|---|
| 33 |
internal interface INotifications : Introspectable, Properties { |
|---|
| 34 |
ServerInformation ServerInformation { get; } |
|---|
| 35 |
string[] Capabilities { get; } |
|---|
| 36 |
void CloseNotification (uint id); |
|---|
| 37 |
uint Notify (string app_name, uint id, string icon, string summary, string body, |
|---|
| 38 |
string[] actions, IDictionary<string, object> hints, int timeout); |
|---|
| 39 |
event NotificationClosedHandler NotificationClosed; |
|---|
| 40 |
event ActionInvokedHandler ActionInvoked; |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
public enum CloseReason : uint { |
|---|
| 44 |
Expired = 1, |
|---|
| 45 |
User = 2, |
|---|
| 46 |
API = 3, |
|---|
| 47 |
Reserved = 4 |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
internal delegate void NotificationClosedHandler (uint id, uint reason); |
|---|
| 51 |
internal delegate void ActionInvokedHandler (uint id, string action); |
|---|
| 52 |
|
|---|
| 53 |
public struct ServerInformation { |
|---|
| 54 |
public string Name; |
|---|
| 55 |
public string Vendor; |
|---|
| 56 |
public string Version; |
|---|
| 57 |
public string SpecVersion; |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
public static class Global { |
|---|
| 61 |
private const string interface_name = "org.freedesktop.Notifications"; |
|---|
| 62 |
private const string object_path = "/org/freedesktop/Notifications"; |
|---|
| 63 |
|
|---|
| 64 |
private static INotifications dbus_object = null; |
|---|
| 65 |
private static object dbus_object_lock = new object (); |
|---|
| 66 |
|
|---|
| 67 |
internal static INotifications DBusObject { |
|---|
| 68 |
get { |
|---|
| 69 |
if (dbus_object != null) |
|---|
| 70 |
return dbus_object; |
|---|
| 71 |
|
|---|
| 72 |
lock (dbus_object_lock) { |
|---|
| 73 |
if (! Bus.Session.NameHasOwner (interface_name)) |
|---|
| 74 |
Bus.Session.StartServiceByName (interface_name); |
|---|
| 75 |
|
|---|
| 76 |
dbus_object = Bus.Session.GetObject<INotifications> |
|---|
| 77 |
(interface_name, new ObjectPath (object_path)); |
|---|
| 78 |
return dbus_object; |
|---|
| 79 |
} |
|---|
| 80 |
} |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
public static string[] Capabilities { |
|---|
| 84 |
get { |
|---|
| 85 |
return DBusObject.Capabilities; |
|---|
| 86 |
} |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
public static ServerInformation ServerInformation { |
|---|
| 90 |
get { |
|---|
| 91 |
return DBusObject.ServerInformation; |
|---|
| 92 |
} |
|---|
| 93 |
} |
|---|
| 94 |
} |
|---|
| 95 |
} |
|---|