~ubuntu-branches/ubuntu/natty/gnome-do/natty

« back to all changes in this revision

Viewing changes to Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/NotificationHelper.cs

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers
  • Date: 2009-06-27 10:40:45 UTC
  • mfrom: (1.1.8 upstream) (0.1.5 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090627104045-7st10y1cqr6dpz37
Tags: 0.8.2+dfsg-1
* New upstream release
  + No longer uses a plugin repository.  Fixes many plugin-
    related issues. (LP: #343096, LP: #330025, LP #345001)
  + No longer blocks on "About Do" (LP: #361679)
  + Reacts correctly when a Composite manager is enabled/
    disabled at runtime. (LP: #346347, LP: #390150)
  + Fixes for space reserved by Docky blocking drag and 
    drop operations. (LP: #354729, LP: #347052, LP: #382843)
  + Properly sets "Hidden" key on autostart files in response to 
    "Start on login" option.  (Closes: #526023) (LP: #369988)
* debian/patches/10_application_search_path:
  + Drop; included upstream
* debian/patches/10_sk_translation_update:
  + Import sk translation update from Debian BTS.
    (Closes: #531779)
* debian/patches/11_fix_autostart_when_directory_does_not_exist:
  + Patch from upstream.  Fixes the "Start on login" option when the 
    ~/.config/autostart directory does not exist. (LP: #393729)
* debian/control:
  + Update standards version to 3.8.2; no changes required.
  + Add libtool to Build-Depends; required for autoreconf.
  + Add Recommends: on new gnome-do-docklets package.
* debian/gnome-do.1
  + Fix spelling: GNOME-Do => GNOME Do.
  + Miscelaneous lintian fixes; NAME section, escaping minus signs with \-
* debian/copyright:
  + Update for new copyright holders.
  + Minor update to DEP-5 format

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
using Do.Interface;
29
29
 
30
30
namespace 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
48
        internal class NotificationHelper
34
49
        {
35
50
                const string DefaultIconName = "gnome-do";
36
 
 
37
 
                const int IconSize = 24;
 
51
                
 
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);
56
71
                }
57
72
 
 
73
                public void Notify (Notification note)
 
74
                {
 
75
                        Notify (note, Screen.Default, 0, 0);
 
76
                }
 
77
                
58
78
                public void Notify (Notification note, Screen screen, int x, int y)
59
79
                {
60
80
                        LibNotify.Notification notify = ToNotify (note);
61
81
                        notify.SetGeometryHints (screen, x, y);
62
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
                }
64
96
 
65
97
                LibNotify.Notification ToNotify (Notification note)
66
98
                {
67
99
                        LibNotify.Notification notify = new LibNotify.Notification ();
68
 
                        
69
 
                        notify.Icon = string.IsNullOrEmpty (note.Icon)
70
 
                                ? DefaultIcon
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);
 
104
                        
 
105
                        if (SupportsCapability (NotificationCapability.scaling) && !note.Icon.Contains ("@")) {
 
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
                        }
76
114
 
77
115
                        if (note is ActionableNotification) {
78
116
                                ActionableNotification anote = note as ActionableNotification;
85
123
 
86
124
                void OnNotificationClosed (Notification note)
87
125
                {
88
 
                        if (NotificationClosed == null) return;
89
 
                        NotificationClosed (this, new NotificationEventArgs (note));
 
126
                        if (NotificationClosed != null)
 
127
                                NotificationClosed (this, new NotificationEventArgs (note));
90
128
                }
91
 
                
92
129
        }
93
 
 
94
130
}
 
131