From 076cabdea7e702883ba808f2c066091b477b5eb0 Mon Sep 17 00:00:00 2001 From: Zougi Date: Fri, 4 Sep 2015 12:38:19 +0200 Subject: [PATCH] notifyiconsystray now more generic --- LyncLogger.v11.suo | Bin 74752 -> 77312 bytes LyncLogger/LyncLogger.cs | 5 ++-- LyncLogger/NotifyIconSystray.cs | 45 +++++++++++++++++++++++++------- LyncLogger/Program.cs | 1 + 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/LyncLogger.v11.suo b/LyncLogger.v11.suo index 0b709dc372ab898229a54e3f3fe6b35d7153c877..1d358e2cff93f071e4f55a4cf6239c77e3f548f3 100755 GIT binary patch delta 4300 zcmd5uvzzYDrU_Md z02Mu@V)hE#Vo?kpn^q2RGdwNgL~m}o*t(t9Vn3LLBUoc_Vv z^P6|yeRuA=@80|Fyp=ly`2*qUNzmXm#7A*l499UiVqkD^5Ic?`lJ=A*@sSO2{+CyL za*UNBM=XG~{91M$dibLPiNioqCcM@w81BIVH6t(~`bTq+LPc6L1!-J_i$jzmA`!6& z5{L-)L~lS^KokXe`e3iaJ_XA4(Ly*s1Qt}P?Bn&YEajQ>KkVkI}$DVvcKA|!Bq#t|o$v}%W=@wU*gJLB5e{@C6x48m( z4LkHN;exvnup>NO^B{SV04Kta6<)xZ&k>gppCK+IXtE3YD~PLzFA&{`9>kZ3uMoY6 zKEyS6!I;!$Dr3Sh96?l3I!H4!*%WwT=2-nyWQ_~54HuF46M}<&!?U-GRXWWo=o>j7 z4)Qr5jap)06m&{_+6)^3J)@55DZX?rh^6~C5_;&1OA;tGAU-}N>JB8xYZP3~wPnt9 zK_jI2%pu~%_!2np%+(T`X6A=PGhLbS#30-kWUdHJHY7}f9XcVIGJXxhfv86~5iW$b zhMFL@T6q7aVgol5d30dO(4EpI#*)DM%R#mayifUbw1ax+duoB+h*We?jNJ>~%|6ot z9G;_6fz97kY+z%N7?050uot{diwz7-9Lx{$pu1^_flI^Dogt}t;B8(E2Q4|Kk;v)_ zX-h2=CWK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Urir}v&N zI9#@*ZBM}kzmf{M=oVv9&aL1_L%;=+_pwKQ?W#yWUGv(3&mLa9zCq2g`I{o4(Jz~! z%@ln6Q8LU=8^~78mmk;UD;@B?S&yIH*CR`X5+PS8rHJpkz7P0yfyupdaNi9tR@}7H zU1_?Q6~&GZ+5kOIjG`E7z1tH{omh*WmOKMbrPxTsGx?4%dKQv!+IQbso|g5vyk&Y| d=lhLz_}c8J*IU*Pr}eu(#iIs2#b0oO_-_GKF=YS% 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 {