diff --git a/LyncLogger.v11.suo b/LyncLogger.v11.suo index 0b709dc..1d358e2 100755 Binary files a/LyncLogger.v11.suo and b/LyncLogger.v11.suo differ diff --git a/LyncLogger/LyncLogger.cs b/LyncLogger/LyncLogger.cs index d299a2c..48dc6c2 100755 --- a/LyncLogger/LyncLogger.cs +++ b/LyncLogger/LyncLogger.cs @@ -10,6 +10,7 @@ using System.ComponentModel; using System.Reflection; using log4net; +using IconSystray; namespace LyncLogger { @@ -55,7 +56,7 @@ public void run() if (e.NewState == ClientState.SignedOut) { _log.Info("User signed out. Watch for signed in event"); - NotifyIconSystray.ChangeLoggerStatus(false); + NotifyIconSystray.ChangeStatus(false); run(); } }; @@ -72,7 +73,7 @@ public void run() { _log.Info("watch conversation"); conversations.ConversationAdded += conversations_ConversationAdded; - NotifyIconSystray.ChangeLoggerStatus(true); + NotifyIconSystray.ChangeStatus(true); } else { diff --git a/LyncLogger/NotifyIconSystray.cs b/LyncLogger/NotifyIconSystray.cs index 8dc1cc3..cda90e7 100755 --- a/LyncLogger/NotifyIconSystray.cs +++ b/LyncLogger/NotifyIconSystray.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; using System.Windows.Forms; -namespace LyncLogger +namespace IconSystray { /// /// Handles the systray icon @@ -17,28 +17,46 @@ namespace LyncLogger static class NotifyIconSystray { private static NotifyIcon notifyIcon; - public delegate void LoggerStatus(bool status); + public delegate void Status(bool status); private static string _name; + public delegate void CallbackQuit(); + public static event CallbackQuit OnQuit; + + private static string _on_text = "on"; + private static string _on_image = "icon.ico"; + public static void setOnIcon(string text, string imageName) + { + _on_text = text; + _on_image = imageName; + } + + private static string _off_text = "off"; + private static string _off_image = "icon_off.ico"; + public static void setOffIcon(string text, string imageName) + { + _off_text = text; + _off_image = imageName; + } /// /// This method allows to change the state of icon and tooltip /// true = Log Active: the logger detected the client and is active. /// /// - public static void LoggerStatus_DelegateMethod(bool status) + public static void Status_DelegateMethod(bool status) { - string text = String.Format("{0}\nstatus: {1}", _name, status ? "on" : "off"); + string text = String.Format("{0}\nstatus: {1}", _name, status ? _on_text : _off_text); - string iconName = status ? "icon.ico" : "icon_off.ico"; + string iconName = status ? _on_image : _off_image; setNotifyIcon(iconName, text); } /// - /// This delegate allows us to call LoggerStatus_DelegateMethod in the backgroundworker + /// This delegate allows us to call Status_DelegateMethod in the backgroundworker /// It changes the indicator that displays the state of the app. /// - public static LoggerStatus ChangeLoggerStatus = LoggerStatus_DelegateMethod; + public static Status ChangeStatus = Status_DelegateMethod; /// /// set text and icon for the taskbar @@ -65,18 +83,25 @@ public static void setNotifyIcon(string iconName, string text) /// /// name displayed on mouse hover /// items to add to the context menu - public static void addNotifyIcon(String name, MenuItem[] items) + public static void addNotifyIcon(String name, MenuItem[] items = null) { _name = name; notifyIcon = new System.Windows.Forms.NotifyIcon(); notifyIcon.Visible = true; - LoggerStatus_DelegateMethod(false); //set name and icon + Status_DelegateMethod(false); //set name and icon ContextMenu contextMenu1 = new ContextMenu(); - contextMenu1.MenuItems.AddRange(items); + if (items != null) + { + contextMenu1.MenuItems.AddRange(items); + } contextMenu1.MenuItems.Add(new MenuItem("Quit", (s, e) => { + if (OnQuit != null) + { + OnQuit(); + } disposeNotifyIcon(); })); notifyIcon.ContextMenu = contextMenu1; diff --git a/LyncLogger/Program.cs b/LyncLogger/Program.cs index 43dabee..fabc3ce 100755 --- a/LyncLogger/Program.cs +++ b/LyncLogger/Program.cs @@ -11,6 +11,7 @@ using System.ComponentModel; using log4net; using Microsoft.Win32; +using IconSystray; namespace LyncLogger {