Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
notifyiconsystray now more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericrous committed Sep 4, 2015
1 parent e8f9156 commit 076cabd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
Binary file modified LyncLogger.v11.suo
Binary file not shown.
5 changes: 3 additions & 2 deletions LyncLogger/LyncLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.ComponentModel;
using System.Reflection;
using log4net;
using IconSystray;

namespace LyncLogger
{
Expand Down Expand Up @@ -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();
}
};
Expand All @@ -72,7 +73,7 @@ public void run()
{
_log.Info("watch conversation");
conversations.ConversationAdded += conversations_ConversationAdded;
NotifyIconSystray.ChangeLoggerStatus(true);
NotifyIconSystray.ChangeStatus(true);
}
else
{
Expand Down
45 changes: 35 additions & 10 deletions LyncLogger/NotifyIconSystray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,54 @@
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LyncLogger
namespace IconSystray
{
/// <summary>
/// Handles the systray icon
/// </summary>
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;
}

/// <summary>
/// This method allows to change the state of icon and tooltip
/// true = Log Active: the logger detected the client and is active.
/// </summary>
/// <param name="status"></param>
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);
}

/// <summary>
/// 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.
/// </summary>
public static LoggerStatus ChangeLoggerStatus = LoggerStatus_DelegateMethod;
public static Status ChangeStatus = Status_DelegateMethod;

/// <summary>
/// set text and icon for the taskbar
Expand All @@ -65,18 +83,25 @@ public static void setNotifyIcon(string iconName, string text)
/// </summary>
/// <param name="name">name displayed on mouse hover</param>
/// <param name="items">items to add to the context menu</param>
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;
Expand Down
1 change: 1 addition & 0 deletions LyncLogger/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.ComponentModel;
using log4net;
using Microsoft.Win32;
using IconSystray;

namespace LyncLogger
{
Expand Down

0 comments on commit 076cabd

Please sign in to comment.