/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. using System;
  17. using Gtk;
  18. using Notifications;
  19. namespace SparkleShare {
  20. public class SparkleBubbles {
  21. public SparkleBubblesController Controller = new SparkleBubblesController ();
  22. public SparkleBubbles ()
  23. {
  24. Controller.ShowBubbleEvent += delegate (string title, string subtext, string image_path) {
  25. try {
  26. Notification notification = new Notification () {
  27. Summary = title,
  28. Body = subtext,
  29. Timeout = 5 * 1000,
  30. Urgency = Urgency.Low
  31. };
  32. if (image_path != null)
  33. notification.Icon = new Gdk.Pixbuf (image_path);
  34. else
  35. notification.IconName = "folder-sparkleshare";
  36. notification.Closed += delegate {
  37. Application.Invoke (delegate {
  38. if (SparkleUI.EventLog == null)
  39. SparkleUI.EventLog = new SparkleEventLog ();
  40. SparkleUI.EventLog.Controller.SelectedFolder = null;
  41. SparkleUI.EventLog.ShowAll ();
  42. SparkleUI.EventLog.Present ();
  43. });
  44. };
  45. notification.Show ();
  46. } catch (Exception) {
  47. // Ignore exceptions thrown by libnotify,
  48. // they're not important enough to crash
  49. }
  50. };
  51. }
  52. }
  53. }