[blam/gtk-builder] TrayIcon: basic trayicon support



commit 3ce06fb796cf6d3da062453b35614f6489c9956b
Author: Carlos Martín Nieto <cmn dwim me>
Date:   Wed Oct 9 19:43:44 2013 +0200

    TrayIcon: basic trayicon support

 src/Blam.cs     |   16 +++++++++++++++
 src/TrayIcon.cs |   56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 0 deletions(-)
---
diff --git a/src/Blam.cs b/src/Blam.cs
index bb779c8..b6d5d6c 100644
--- a/src/Blam.cs
+++ b/src/Blam.cs
@@ -18,6 +18,7 @@ namespace Blam
        public class BlamApplication
        {
                Window MainWindow;
+               TrayIcon trayIcon;
                ItemList ItemList;
                FeedList FeedList;
                ItemView ItemView;
@@ -38,8 +39,23 @@ namespace Blam
 
                        MainWindow = bld.GetObject<Window>("main-window");
                        MainWindow.DeleteEvent += OnDelete;
+                       MainWindow.IconName = "blam";
 
                        channels = ChannelCollection.LoadFromFile (Defines.APP_HOMEDIR + "/collection.xml");
+                       trayIcon = new TrayIcon(channels.ObservableChannels, channels.ObservableGroups);
+                       //trayIcon.ButtonPressEvent += TrayIconButtonPressCb;
+                       //trayIcon.RefreshAllEvent += RefreshAllActivated;
+                       //trayIcon.PreferencesEvent += PreferencesActivated;
+                       //trayIcon.AboutEvent += AboutActivated;
+
+                       trayIcon.ObserveQuit.Subscribe(_ => Application.Quit());
+                       trayIcon.ObserveClick.Subscribe(_ => {
+                               if (MainWindow.Visible)
+                                       MainWindow.Hide();
+                               else
+                                       MainWindow.Show();
+                       });
+
                        FeedListSw = bld.GetObject<ScrolledWindow>("feed-list-scroll");
                        FeedList = new FeedList(channels.ObservableChannels, channels.ObservableGroups);
                        FeedList.MainWindow = MainWindow;
diff --git a/src/TrayIcon.cs b/src/TrayIcon.cs
index 15d1541..430ba58 100644
--- a/src/TrayIcon.cs
+++ b/src/TrayIcon.cs
@@ -9,6 +9,62 @@ using Gtk;
 using Mono.Unix;
 using System;
 using System.ComponentModel;
+using System.Collections.ObjectModel;
+using System.Reactive.Subjects;
+using System.Reactive.Linq;
+using System.Reactive;
+using System.Linq;
+
+namespace Blam
+{
+       using Channel = Imendio.Blam.Channel;
+       using IChannel = Imendio.Blam.IChannel;
+       using ChannelGroup = Imendio.Blam.ChannelGroup;
+       using Unit = System.Reactive.Unit;
+
+       public class TrayIcon : Gtk.StatusIcon
+       {
+               //ObservableCollection<Channel> channels;
+               //ObservableCollection<ChannelGroup> groups;
+
+               Subject<Unit> quitSubject = new Subject<Unit>();
+               public IObservable<Unit> ObserveQuit {
+                       get {
+                               return quitSubject;
+                       }
+               }
+
+               Subject<Unit> clickSubject = new Subject<Unit>();
+               public IObservable<Unit> ObserveClick {
+                       get {
+                               return clickSubject;
+                       }
+               }
+
+               public TrayIcon(ObservableCollection<Channel> channels, ObservableCollection<ChannelGroup> 
groups)
+               {
+                       IconName = "blam";
+                       Tooltip = Catalog.GetString("Blam News Reader");
+
+                       var changes = Observable
+                               .Merge(channels.Select(c => 
Observable.FromEventPattern<PropertyChangedEventArgs>(c, "PropertyChanged")))
+                               .Merge(Observable.Merge(groups.Select(grp => 
Observable.FromEventPattern<PropertyChangedEventArgs>(grp, "PropertyChanged"))))
+                               .Select(_ => Unit.Default);
+
+                       changes.Subscribe(_ => {
+                               var unread = channels.Select(c => c.NrOfUnreadItems).Sum() + groups.Select(g 
=> g.NrOfUnreadItems).Sum();
+                               var str = String.Format(Catalog.GetPluralString("{0} unread item", "{0} 
unread items", unread), unread);
+                               Tooltip = str;
+                       });
+               }
+
+               protected override void OnActivate()
+               {
+                       clickSubject.OnNext(Unit.Default);
+                       base.OnActivate();
+               }
+       }
+}
 
 namespace Imendio.Blam {
     public class TrayIcon {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]