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
=== modified file 'Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/NotificationHelper.cs'
--- Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/NotificationHelper.cs 2009-03-11 03:09:33 +0000
+++ Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/NotificationHelper.cs 2009-03-29 19:29:59 +0000
@@ -28,13 +28,28 @@
28using Do.Interface;28using Do.Interface;
2929
30namespace Do.Platform.Linux30namespace Do.Platform.Linux
31{31{
32 public enum NotificationCapability {
33 actions,
34 append,
35 body,
36 body_hyperlinks,
37 body_images,
38 body_markup,
39 icon_multi,
40 icon_static,
41 image_svg,
42 max,
43 positioning, // not an official capability
44 scaling, // not an official capability
45 sound
46 }
32 47
33 internal class NotificationHelper48 internal class NotificationHelper
34 {49 {
35 const string DefaultIconName = "gnome-do";50 const string DefaultIconName = "gnome-do";
3651
37 const int IconSize = 24;52 const int IconSize = 48;
38 const int LettersPerWord = 7;53 const int LettersPerWord = 7;
39 const int MillisecondsPerWord = 350;54 const int MillisecondsPerWord = 350;
40 const int MinNotifyShow = 5000;55 const int MinNotifyShow = 5000;
@@ -55,24 +70,47 @@
55 return Math.Min (Math.Max (t, MinNotifyShow), MaxNotifyShow);70 return Math.Min (Math.Max (t, MinNotifyShow), MaxNotifyShow);
56 }71 }
5772
73 public void Notify (Notification note)
74 {
75 Notify (note, Screen.Default, 0, 0);
76 }
77
58 public void Notify (Notification note, Screen screen, int x, int y)78 public void Notify (Notification note, Screen screen, int x, int y)
59 {79 {
60 LibNotify.Notification notify = ToNotify (note);80 LibNotify.Notification notify = ToNotify (note);
61 notify.SetGeometryHints (screen, x, y);81 notify.SetGeometryHints (screen, x, y);
62 notify.Show ();82 notify.Show ();
63 }83 }
84
85 public bool SupportsCapability (NotificationCapability capability)
86 {
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";
93
94 return Array.IndexOf (LibNotify.Global.Capabilities, Enum.GetName (typeof (NotificationCapability), capability)) > -1;
95 }
6496
65 LibNotify.Notification ToNotify (Notification note)97 LibNotify.Notification ToNotify (Notification note)
66 {98 {
67 LibNotify.Notification notify = new LibNotify.Notification ();99 LibNotify.Notification notify = new LibNotify.Notification ();
68
69 notify.Icon = string.IsNullOrEmpty (note.Icon)
70 ? DefaultIcon
71 : IconProvider.PixbufFromIconName (note.Icon, IconSize);
72 notify.Body = GLib.Markup.EscapeText (note.Body);100 notify.Body = GLib.Markup.EscapeText (note.Body);
73 notify.Summary = GLib.Markup.EscapeText (note.Title);101 notify.Summary = GLib.Markup.EscapeText (note.Title);
102 notify.Closed += (sender, e) => OnNotificationClosed (note);
74 notify.Timeout = ReadableDurationForMessage (note.Title, note.Body);103 notify.Timeout = ReadableDurationForMessage (note.Title, note.Body);
75 notify.Closed += (sender, e) => OnNotificationClosed (note);104
105 if (SupportsCapability (NotificationCapability.scaling)) {
106 notify.IconName = string.IsNullOrEmpty (note.Icon)
107 ? DefaultIconName
108 : note.Icon;
109 } else {
110 notify.Icon = string.IsNullOrEmpty (note.Icon)
111 ? DefaultIcon
112 : IconProvider.PixbufFromIconName (note.Icon, IconSize);
113 }
76114
77 if (note is ActionableNotification) {115 if (note is ActionableNotification) {
78 ActionableNotification anote = note as ActionableNotification;116 ActionableNotification anote = note as ActionableNotification;
@@ -85,10 +123,9 @@
85123
86 void OnNotificationClosed (Notification note)124 void OnNotificationClosed (Notification note)
87 {125 {
88 if (NotificationClosed == null) return;126 if (NotificationClosed != null)
89 NotificationClosed (this, new NotificationEventArgs (note));127 NotificationClosed (this, new NotificationEventArgs (note));
90 }128 }
91
92 }129 }
93
94}130}
131
95\ No newline at end of file132\ No newline at end of file
96133
=== modified file 'Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/TrayIconService.cs'
--- Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/TrayIconService.cs 2009-01-23 21:15:13 +0000
+++ Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/TrayIconService.cs 2009-03-28 21:45:43 +0000
@@ -61,15 +61,16 @@
6161
62 ~TrayIconService ()62 ~TrayIconService ()
63 {63 {
64 status_icon.Activate -= OnActivate;
64 status_icon.PopupMenu -= OnPopupMenu;65 status_icon.PopupMenu -= OnPopupMenu;
65 status_icon.Activate -= OnActivate;
66 }66 }
6767
68 public void Initialize ()68 public void Initialize ()
69 {69 {
70 Preferences = new TrayIconPreferences ();70 Preferences = new TrayIconPreferences ();
71 Preferences.IconVisibleChanged += OnIconVisibleChanged;71 Preferences.IconVisibleChanged += OnIconVisibleChanged;
72 if (!Preferences.IconVisible) Hide ();72 if (!Preferences.IconVisible)
73 Hide ();
7374
74 // Listen for notifications so we can show a libnotify bubble.75 // Listen for notifications so we can show a libnotify bubble.
75 Services.Notifications.Notified += OnNotified;76 Services.Notifications.Notified += OnNotified;
@@ -102,14 +103,19 @@
102 {103 {
103 int x, y;104 int x, y;
104 Screen screen;105 Screen screen;
105106
106 Show ();107 if (notifier.SupportsCapability (NotificationCapability.positioning)) {
107 GetLocationOnScreen (out screen, out x, out y);108 Show ();
108109 GetLocationOnScreen (out screen, out x, out y);
109 // We delay this so that the status icon has time to show.110 // We delay this so that the status icon has time to show.
110 Services.Application.RunOnMainThread (() => {111 Services.Application.RunOnMainThread (() => {
111 notifier.Notify (note, screen, x, y);112 notifier.Notify (note, screen, x, y);
112 }, NotifyDelay);113 }, NotifyDelay);
114 } else {
115 Services.Application.RunOnMainThread (() => {
116 notifier.Notify (note);
117 });
118 }
113 }119 }
114120
115 void Show ()121 void Show ()
@@ -158,6 +164,5 @@
158 else164 else
159 y += area.Height;165 y += area.Height;
160 }166 }
161
162 }167 }
163}168}
164169
=== modified file 'Do.Platform/src/Do.Platform/Notification.cs'
--- Do.Platform/src/Do.Platform/Notification.cs 2008-12-17 01:35:02 +0000
+++ Do.Platform/src/Do.Platform/Notification.cs 2009-03-29 19:25:40 +0000
@@ -46,6 +46,5 @@
46 Body = body;46 Body = body;
47 Icon = icon;47 Icon = icon;
48 }48 }
49
50 }49 }
51}50}
5251
=== modified file 'Do.mds'
--- Do.mds 2009-03-20 20:43:06 +0000
+++ Do.mds 2009-03-28 15:34:37 +0000
@@ -1,9 +1,4 @@
1<Combine fileversion="2.0" outputpath="build/bin/" name="Do">1<Combine fileversion="2.0" outputpath="build/bin/" name="Do">
2 <Policies>
3 <ChangeLogPolicy UpdateMode="Nearest" inheritsSet="Mono">
4 <MessageStyle Header="" Indent="" LineAlign="0" />
5 </ChangeLogPolicy>
6 </Policies>
7 <Configurations active="Debug">2 <Configurations active="Debug">
8 <Configuration name="Debug" ctype="CombineConfiguration">3 <Configuration name="Debug" ctype="CombineConfiguration">
9 <Entry build="True" name="Do" configuration="Debug" />4 <Entry build="True" name="Do" configuration="Debug" />