using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.CompilerServices;
using IReaper.FileData;
namespace IReaper.Notify{
struct NotifyMessage
{
public string Message;
public string Url;
}
/// <summary>
///
/// </summary>
class iReaperNotifyManager
{
//
static NotifyIcon sysIcon;
[ThreadStatic()]
static NotifyMessage nMessage;
static iReaperNotifyManager()
{
nMessage = new NotifyMessage();
Running.CourseFileWorker.OnFileDownloaded += new IReaper.Running.FileDownloadFinishedEventHandler(CourseFileWorker_OnFileDownloaded);
}
private static void CourseFileWorker_OnFileDownloaded(CourseFileData File)
{
iReaperNotifyManager.NotifyMessage(Properties.Resources.DownloadFinishedMessage,File.Owner.Headline, null);
}
/// <summary>
///
/// </summary>
public static NotifyIcon InitSysIcon(IContainer Container)
{
sysIcon = new NotifyIcon(Container);
sysIcon.Visible = true;
sysIcon.Icon = Properties.Resources.LogoIcon;
sysIcon.BalloonTipClicked += new EventHandler(sysIcon_BalloonTipClicked);
sysIcon.BalloonTipClosed += new EventHandler(sysIcon_BalloonTipClosed);
sysIcon.Click += new EventHandler(sysIcon_Click);
sysIcon.ContextMenuStrip = new NotifyIconContextMenu(sysIcon.Container);
sysIcon.Text = "iReaper";
return sysIcon;
}
private static void sysIcon_Click(object sender, EventArgs e)
{
Form main = Core.CoreData[CoreDataType.ApplicationForm] as Form;
if (main == null)
{ return; }
////
main.Visible = true;
main.WindowState = FormWindowState.Maximized;
main.Activate();
}
private static void sysIcon_BalloonTipClosed(object sender, EventArgs e)
{
nMessage.Message = null;
nMessage.Url = null;
}
private static void sysIcon_BalloonTipClicked(object sender, EventArgs e)
{
if (nMessage.Url != null)
{
Browser.BrowserManager.OpenWebsite(nMessage.Url);
}
}
/// <summary>
///
/// </summary>
/// <param name="message"></param>
/// <param name="Url"></param>
[MethodImpl(MethodImplOptions.Synchronized)]
public static void NotifyMessage(string title,string message, string Url)
{
//
if (sysIcon == null)
{ return; }
nMessage.Message = message;
nMessage.Url = Url;
sysIcon.BalloonTipTitle = title;
sysIcon.BalloonTipText = message;
sysIcon.ShowBalloonTip(30);
}
}
}
|