PageRenderTime 29ms CodeModel.GetById 18ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/SparkleShare/SparkleBubbles.cs

http://github.com/hbons/SparkleShare
C# | 67 lines | 36 code | 14 blank | 17 comment | 4 complexity | 424fc5baa09f20800e8be0cbaed07368 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 Gtk;
21using Notifications;
22
23namespace SparkleShare {
24    
25    public class SparkleBubbles {
26
27        public SparkleBubblesController Controller = new SparkleBubblesController ();
28
29
30        public SparkleBubbles ()
31        {
32            Controller.ShowBubbleEvent += delegate (string title, string subtext, string image_path) {
33                try {
34                    Notification notification = new Notification () {
35                        Summary = title,
36                        Body    = subtext,
37                        Timeout = 5 * 1000,
38                        Urgency = Urgency.Low
39                    };
40    
41                    if (image_path != null)
42                        notification.Icon = new Gdk.Pixbuf (image_path);
43                    else
44                        notification.IconName = "folder-sparkleshare";
45
46                    notification.Closed += delegate {
47                        Application.Invoke (delegate {
48                            if (SparkleUI.EventLog == null)
49                                SparkleUI.EventLog = new SparkleEventLog ();
50
51                            SparkleUI.EventLog.Controller.SelectedFolder = null;
52
53                            SparkleUI.EventLog.ShowAll ();
54                            SparkleUI.EventLog.Present ();
55                        });
56                    };
57
58                    notification.Show ();
59
60                } catch (Exception) {
61                    // Ignore exceptions thrown by libnotify,
62                    // they're not important enough to crash
63                }
64            };
65        }
66    }
67}