Do

Merge lp:~alexlauni/do/notify-osd into lp:do

Proposed by Alex Launi
Status: Merged
Merged at revision: not available
Proposed branch: lp:~alexlauni/do/notify-osd
Merge into: lp:do
Diff against target: None lines
To merge this branch: bzr merge lp:~alexlauni/do/notify-osd
Reviewer Review Type Date Requested Status
Jason Smith (community) Approve
Review via email: mp+5016@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Alex Launi (alexlauni) wrote :

Applies a number of fixes to make Do behave better with the new Ubuntu notification system. Preserves compatibility with notification-daemon for other distros, and older Ubuntu releases.

Revision history for this message
Jason Smith (jassmith) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/NotificationHelper.cs'
2--- Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/NotificationHelper.cs 2009-03-11 03:09:33 +0000
3+++ Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/NotificationHelper.cs 2009-03-29 19:29:59 +0000
4@@ -28,13 +28,28 @@
5 using Do.Interface;
6
7 namespace Do.Platform.Linux
8-{
9+{
10+ public enum NotificationCapability {
11+ actions,
12+ append,
13+ body,
14+ body_hyperlinks,
15+ body_images,
16+ body_markup,
17+ icon_multi,
18+ icon_static,
19+ image_svg,
20+ max,
21+ positioning, // not an official capability
22+ scaling, // not an official capability
23+ sound
24+ }
25
26 internal class NotificationHelper
27 {
28 const string DefaultIconName = "gnome-do";
29-
30- const int IconSize = 24;
31+
32+ const int IconSize = 48;
33 const int LettersPerWord = 7;
34 const int MillisecondsPerWord = 350;
35 const int MinNotifyShow = 5000;
36@@ -55,24 +70,47 @@
37 return Math.Min (Math.Max (t, MinNotifyShow), MaxNotifyShow);
38 }
39
40+ public void Notify (Notification note)
41+ {
42+ Notify (note, Screen.Default, 0, 0);
43+ }
44+
45 public void Notify (Notification note, Screen screen, int x, int y)
46 {
47 LibNotify.Notification notify = ToNotify (note);
48 notify.SetGeometryHints (screen, x, y);
49 notify.Show ();
50 }
51+
52+ public bool SupportsCapability (NotificationCapability capability)
53+ {
54+ // positioning and scaling are not actual capabilities, i just know for a fact most other servers
55+ // support geo. hints, and notify-osd is the only that auto scales images
56+ if (capability == NotificationCapability.positioning)
57+ return LibNotify.Global.ServerInformation.Name != "notify-osd";
58+ else if (capability == NotificationCapability.scaling)
59+ return LibNotify.Global.ServerInformation.Name == "notify-osd";
60+
61+ return Array.IndexOf (LibNotify.Global.Capabilities, Enum.GetName (typeof (NotificationCapability), capability)) > -1;
62+ }
63
64 LibNotify.Notification ToNotify (Notification note)
65 {
66 LibNotify.Notification notify = new LibNotify.Notification ();
67-
68- notify.Icon = string.IsNullOrEmpty (note.Icon)
69- ? DefaultIcon
70- : IconProvider.PixbufFromIconName (note.Icon, IconSize);
71 notify.Body = GLib.Markup.EscapeText (note.Body);
72 notify.Summary = GLib.Markup.EscapeText (note.Title);
73+ notify.Closed += (sender, e) => OnNotificationClosed (note);
74 notify.Timeout = ReadableDurationForMessage (note.Title, note.Body);
75- notify.Closed += (sender, e) => OnNotificationClosed (note);
76+
77+ if (SupportsCapability (NotificationCapability.scaling)) {
78+ notify.IconName = string.IsNullOrEmpty (note.Icon)
79+ ? DefaultIconName
80+ : note.Icon;
81+ } else {
82+ notify.Icon = string.IsNullOrEmpty (note.Icon)
83+ ? DefaultIcon
84+ : IconProvider.PixbufFromIconName (note.Icon, IconSize);
85+ }
86
87 if (note is ActionableNotification) {
88 ActionableNotification anote = note as ActionableNotification;
89@@ -85,10 +123,9 @@
90
91 void OnNotificationClosed (Notification note)
92 {
93- if (NotificationClosed == null) return;
94- NotificationClosed (this, new NotificationEventArgs (note));
95+ if (NotificationClosed != null)
96+ NotificationClosed (this, new NotificationEventArgs (note));
97 }
98-
99 }
100-
101 }
102+
103\ No newline at end of file
104
105=== modified file 'Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/TrayIconService.cs'
106--- Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/TrayIconService.cs 2009-01-23 21:15:13 +0000
107+++ Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/TrayIconService.cs 2009-03-28 21:45:43 +0000
108@@ -61,15 +61,16 @@
109
110 ~TrayIconService ()
111 {
112+ status_icon.Activate -= OnActivate;
113 status_icon.PopupMenu -= OnPopupMenu;
114- status_icon.Activate -= OnActivate;
115 }
116
117 public void Initialize ()
118 {
119 Preferences = new TrayIconPreferences ();
120 Preferences.IconVisibleChanged += OnIconVisibleChanged;
121- if (!Preferences.IconVisible) Hide ();
122+ if (!Preferences.IconVisible)
123+ Hide ();
124
125 // Listen for notifications so we can show a libnotify bubble.
126 Services.Notifications.Notified += OnNotified;
127@@ -102,14 +103,19 @@
128 {
129 int x, y;
130 Screen screen;
131-
132- Show ();
133- GetLocationOnScreen (out screen, out x, out y);
134-
135- // We delay this so that the status icon has time to show.
136- Services.Application.RunOnMainThread (() => {
137- notifier.Notify (note, screen, x, y);
138- }, NotifyDelay);
139+
140+ if (notifier.SupportsCapability (NotificationCapability.positioning)) {
141+ Show ();
142+ GetLocationOnScreen (out screen, out x, out y);
143+ // We delay this so that the status icon has time to show.
144+ Services.Application.RunOnMainThread (() => {
145+ notifier.Notify (note, screen, x, y);
146+ }, NotifyDelay);
147+ } else {
148+ Services.Application.RunOnMainThread (() => {
149+ notifier.Notify (note);
150+ });
151+ }
152 }
153
154 void Show ()
155@@ -158,6 +164,5 @@
156 else
157 y += area.Height;
158 }
159-
160 }
161 }
162
163=== modified file 'Do.Platform/src/Do.Platform/Notification.cs'
164--- Do.Platform/src/Do.Platform/Notification.cs 2008-12-17 01:35:02 +0000
165+++ Do.Platform/src/Do.Platform/Notification.cs 2009-03-29 19:25:40 +0000
166@@ -46,6 +46,5 @@
167 Body = body;
168 Icon = icon;
169 }
170-
171 }
172 }
173
174=== modified file 'Do.mds'
175--- Do.mds 2009-03-20 20:43:06 +0000
176+++ Do.mds 2009-03-28 15:34:37 +0000
177@@ -1,9 +1,4 @@
178 <Combine fileversion="2.0" outputpath="build/bin/" name="Do">
179- <Policies>
180- <ChangeLogPolicy UpdateMode="Nearest" inheritsSet="Mono">
181- <MessageStyle Header="" Indent="" LineAlign="0" />
182- </ChangeLogPolicy>
183- </Policies>
184 <Configurations active="Debug">
185 <Configuration name="Debug" ctype="CombineConfiguration">
186 <Entry build="True" name="Do" configuration="Debug" />