PageRenderTime 11ms CodeModel.GetById 2ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/SparkleShare/Mac/SparkleBubbles.cs

http://github.com/hbons/SparkleShare
C# | 54 lines | 26 code | 12 blank | 16 comment | 1 complexity | 7906da7b4594dc0b41cbc77bcfb5df8e MD5 | raw file
 1//   SparkleShare, a collaboration and sharing tool.
 2//   Copyright (C) 2010  Hylke Bons <hylkebons@gmail.com>
 3//
 4//   This program is free software: you can redistribute it and/or modify
 5//   it under the terms of the GNU General Public License as published by
 6//   the Free Software Foundation, either version 3 of the License, or
 7//   (at your option) any later version.
 8//
 9//   This program is distributed in the hope that it will be useful,
10//   but WITHOUT ANY WARRANTY; without even the implied warranty of
11//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12//   GNU General Public License for more details.
13//
14//   You should have received a copy of the GNU General Public License
15//   along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
18using System;
19
20using MonoMac.AppKit;
21using MonoMac.Foundation;
22
23namespace SparkleShare {
24    
25    public class SparkleBubbles : NSObject {
26
27        public SparkleBubblesController Controller = new SparkleBubblesController ();
28
29
30        public SparkleBubbles ()
31        {
32            // The notification center was introduced in Mountain Lion
33            if (Environment.OSVersion.Version.Major >= 12)
34                Controller.ShowBubbleEvent += ShowBubbleEvent;
35        }
36
37
38        private void ShowBubbleEvent (string title, string subtext, string image_path) {
39            InvokeOnMainThread (() => {
40                NSUserNotification notification = new NSUserNotification () {
41                    Title           = title,
42                    InformativeText = subtext,
43                    DeliveryDate    = DateTime.Now
44                };
45
46                NSUserNotificationCenter center  = NSUserNotificationCenter.DefaultUserNotificationCenter;
47                center.ShouldPresentNotification = delegate { return true; };
48                center.DidActivateNotification  += delegate { Controller.BubbleClicked (); };
49
50                center.ScheduleNotification (notification);
51            });
52        }
53    }
54}