~ubuntu-branches/ubuntu/natty/notify-sharp/natty

« back to all changes in this revision

Viewing changes to src/Notification.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2009-03-05 13:57:55 UTC
  • mfrom: (1.1.1 upstream) (2.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090305135755-omziewsx1a94m8pj
Tags: 0.4.0~r3032-1
New upstream SVN snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
                }
51
51
        }
52
52
 
 
53
        public class CloseArgs : EventArgs {
 
54
                private CloseReason reason;
 
55
                public CloseReason Reason {
 
56
                        get { return reason; }
 
57
                }
 
58
 
 
59
                public CloseArgs (CloseReason reason) {
 
60
                        this.reason = reason;
 
61
                }
 
62
        }
 
63
 
53
64
        public delegate void ActionHandler (object o, ActionArgs args);
 
65
        public delegate void CloseHandler (object o, CloseArgs args);
54
66
        
55
67
        public class Notification {
56
68
                private struct IconData {
83
95
                private int timeout = -1;
84
96
                private string summary = String.Empty, body = String.Empty;
85
97
                private string icon = String.Empty;
 
98
                private Gtk.Widget attach_widget = null;
 
99
                private Gtk.StatusIcon status_icon = null;
86
100
                private IDictionary <string, ActionTuple> action_map = new Dictionary<string, ActionTuple> ();
87
101
                private IDictionary <string, object> hints  = new Dictionary<string, object> ();
88
102
 
122
136
                        AttachToWidget (widget);
123
137
                }
124
138
 
 
139
                public Notification (string summary, string body, Pixbuf icon, Gtk.StatusIcon status_icon) : this (summary, body, icon) {
 
140
                        AttachToStatusIcon (status_icon);
 
141
                }
 
142
                
 
143
                public Notification (string summary, string body, string icon, Gtk.StatusIcon status_icon) : this (summary, body, icon) {
 
144
                        AttachToStatusIcon (status_icon);
 
145
                }
 
146
 
 
147
 
125
148
                public string Summary {
126
149
                        set {
127
150
                                summary = value;
189
212
                        }
190
213
                }
191
214
 
 
215
                public uint Id {
 
216
                        get {
 
217
                                return id;
 
218
                        }
 
219
                }
 
220
 
 
221
                public Gtk.Widget AttachWidget {
 
222
                        get {
 
223
                                return attach_widget;
 
224
                        }
 
225
                        set {
 
226
                                AttachToWidget (value);
 
227
                        }
 
228
                }
 
229
 
 
230
                public Gtk.StatusIcon StatusIcon {
 
231
                        get {
 
232
                                return status_icon;
 
233
                        }
 
234
                        set {
 
235
                                AttachToStatusIcon (value);
 
236
                        }
 
237
                }
 
238
 
192
239
                private void SetPixbufHint (Pixbuf pixbuf) {
193
240
                        IconData icon_data = new IconData ();
194
241
                        icon_data.Width = pixbuf.Width;
220
267
                        y += widget.Allocation.Height / 2;
221
268
 
222
269
                        SetGeometryHints (widget.Screen, x, y);
 
270
                        attach_widget = widget;
 
271
                        status_icon = null;
 
272
                }
 
273
 
 
274
                public void AttachToStatusIcon (Gtk.StatusIcon status_icon) {
 
275
                        Gdk.Screen screen;
 
276
                        Gdk.Rectangle rect;
 
277
                        Orientation orientation;
 
278
                        int x, y;
 
279
 
 
280
                        if (!status_icon.GetGeometry (out screen, out rect, out orientation)) {
 
281
                                return;
 
282
                        }
 
283
 
 
284
                        x = rect.X + rect.Width / 2;
 
285
                        y = rect.Y + rect.Height / 2;
 
286
 
 
287
                        SetGeometryHints (screen, x, y);
 
288
 
 
289
                        this.status_icon = status_icon;
 
290
                        attach_widget = null;
223
291
                }
224
292
 
225
293
                public void SetGeometryHints (Screen screen, int x, int y) {
262
330
                        shown = false;
263
331
                }
264
332
 
265
 
                private void OnClosed (uint id) {
 
333
                private void OnClosed (uint id, uint reason) {
266
334
                        if (this.id == id) {
267
335
                                this.id = 0;
268
336
                                shown = false;
269
337
                                if (Closed != null) {
270
 
                                        Closed (this, new EventArgs ());
 
338
                                        Closed (this, new CloseArgs ((CloseReason) reason));
271
339
                                }
272
340
                        }
273
341
                }
274
342
 
275
343
                public void AddAction (string action, string label, ActionHandler handler) {
276
 
                        lock (action_map) {
277
 
                                action_map[action] = new ActionTuple (label, handler);
 
344
                        if (Notifications.Global.Capabilities != null &&
 
345
                            Array.IndexOf (Notifications.Global.Capabilities, "actions") > -1) {
 
346
                                lock (action_map) {
 
347
                                        action_map[action] = new ActionTuple (label, handler);
 
348
                                }
 
349
                                Update ();
278
350
                        }
279
 
                        Update ();
280
351
                }
281
352
 
282
353
                public void RemoveAction (string action) {