28
28
using Do.Interface;
30
30
namespace Do.Platform.Linux
32
public enum NotificationCapability {
43
positioning, // not an official capability
44
scaling, // not an official capability
33
48
internal class NotificationHelper
35
50
const string DefaultIconName = "gnome-do";
37
const int IconSize = 24;
52
const int IconSize = 48;
38
53
const int LettersPerWord = 7;
39
54
const int MillisecondsPerWord = 350;
40
55
const int MinNotifyShow = 5000;
55
70
return Math.Min (Math.Max (t, MinNotifyShow), MaxNotifyShow);
73
public void Notify (Notification note)
75
Notify (note, Screen.Default, 0, 0);
58
78
public void Notify (Notification note, Screen screen, int x, int y)
60
80
LibNotify.Notification notify = ToNotify (note);
61
81
notify.SetGeometryHints (screen, x, y);
85
public bool SupportsCapability (NotificationCapability capability)
87
// positioning and scaling are not actual capabilities, i just know for a fact most other servers
88
// support geo. hints, and notify-osd is the only that auto scales images
89
if (capability == NotificationCapability.positioning)
90
return LibNotify.Global.ServerInformation.Name != "notify-osd";
91
else if (capability == NotificationCapability.scaling)
92
return LibNotify.Global.ServerInformation.Name == "notify-osd";
94
return Array.IndexOf (LibNotify.Global.Capabilities, Enum.GetName (typeof (NotificationCapability), capability)) > -1;
65
97
LibNotify.Notification ToNotify (Notification note)
67
99
LibNotify.Notification notify = new LibNotify.Notification ();
69
notify.Icon = string.IsNullOrEmpty (note.Icon)
71
: IconProvider.PixbufFromIconName (note.Icon, IconSize);
72
100
notify.Body = GLib.Markup.EscapeText (note.Body);
73
101
notify.Summary = GLib.Markup.EscapeText (note.Title);
102
notify.Closed += (sender, e) => OnNotificationClosed (note);
74
103
notify.Timeout = ReadableDurationForMessage (note.Title, note.Body);
75
notify.Closed += (sender, e) => OnNotificationClosed (note);
105
if (SupportsCapability (NotificationCapability.scaling) && !note.Icon.Contains ("@")) {
106
notify.IconName = string.IsNullOrEmpty (note.Icon)
110
notify.Icon = string.IsNullOrEmpty (note.Icon)
112
: IconProvider.PixbufFromIconName (note.Icon, IconSize);
77
115
if (note is ActionableNotification) {
78
116
ActionableNotification anote = note as ActionableNotification;
86
124
void OnNotificationClosed (Notification note)
88
if (NotificationClosed == null) return;
89
NotificationClosed (this, new NotificationEventArgs (note));
126
if (NotificationClosed != null)
127
NotificationClosed (this, new NotificationEventArgs (note));