2014-07-11 16:38:10 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using NetMonitorTray.Properties;
|
|
|
|
|
using BlubbFish.Utils;
|
|
|
|
|
|
|
|
|
|
namespace NetMonitorTray.View
|
|
|
|
|
{
|
|
|
|
|
public class Tray : OwnView
|
|
|
|
|
{
|
|
|
|
|
private NotifyIcon trayi;
|
2015-03-04 23:21:34 +01:00
|
|
|
|
private Dictionary<string, Dictionary<string, Tuple<string, Bitmap, bool, bool>>> menuVpn;
|
|
|
|
|
private Dictionary<string, Dictionary<string, Tuple<string, Bitmap, bool, bool>>> menuNetwork;
|
|
|
|
|
|
|
|
|
|
private Icon[] iconlist = { new Icon(Resources.IconNothing, 40, 40), new Icon(Resources.IconWorking, 40, 40), new Icon(Resources.IconConnected, 40, 40) };
|
2014-07-11 16:38:10 +02:00
|
|
|
|
|
|
|
|
|
public Tray()
|
|
|
|
|
{
|
2015-03-04 23:21:34 +01:00
|
|
|
|
this.init();
|
|
|
|
|
this.Model = Models.Tray.Instance;
|
|
|
|
|
this.Model.setObserver(this);
|
2014-07-11 16:38:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void update()
|
|
|
|
|
{
|
2015-03-04 23:21:34 +01:00
|
|
|
|
this.menuVpn = this.Model.getMenuVpn();
|
|
|
|
|
this.menuNetwork = this.Model.getMenuNetwork();
|
2014-07-11 16:38:10 +02:00
|
|
|
|
this.trayi.ContextMenuStrip = this.genMenu();
|
2015-03-04 23:21:34 +01:00
|
|
|
|
this.trayi.Icon = (this.Model.connectedStatus ? this.iconlist[2] : this.iconlist[0]);
|
2014-07-11 16:38:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-04 23:21:34 +01:00
|
|
|
|
override protected void init()
|
2014-07-11 16:38:10 +02:00
|
|
|
|
{
|
|
|
|
|
this.trayi = new NotifyIcon();
|
|
|
|
|
this.trayi.Visible = true;
|
2015-03-04 23:21:34 +01:00
|
|
|
|
this.trayi.Icon = this.iconlist[0];
|
2014-07-11 16:38:10 +02:00
|
|
|
|
this.trayi.Text = "NetMonitorTray";
|
|
|
|
|
this.trayi.DoubleClick += Controller.Tray.Click_Tray;
|
|
|
|
|
this.trayi.BalloonTipClicked += Controller.Tray.Click_Ballon;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ContextMenuStrip genMenu()
|
|
|
|
|
{
|
|
|
|
|
ContextMenuStrip menu = new ContextMenuStrip();
|
|
|
|
|
ToolStripMenuItem m1 = new ToolStripMenuItem("Öffnen");
|
|
|
|
|
m1.Image = Resources.MenuImagesQuit;
|
|
|
|
|
m1.Click += Controller.Tray.Click_Open;
|
|
|
|
|
m1.Name = "Open";
|
|
|
|
|
menu.Items.Add(m1);
|
|
|
|
|
menu.Items.Add(new ToolStripSeparator());
|
2015-03-04 23:21:34 +01:00
|
|
|
|
foreach (String adapter in this.menuNetwork.Keys)
|
|
|
|
|
{
|
|
|
|
|
menu.Items.AddRange(this.genMenuIt(this.menuNetwork[adapter], Controller.Tray.Click_Network));
|
|
|
|
|
menu.Items.Add(new ToolStripSeparator());
|
|
|
|
|
}
|
|
|
|
|
foreach(String adapter in this.menuVpn.Keys) {
|
|
|
|
|
menu.Items.AddRange(this.genMenuIt(this.menuVpn[adapter], Controller.Tray.Click_Vpn));
|
|
|
|
|
menu.Items.Add(new ToolStripSeparator());
|
|
|
|
|
}
|
2014-07-11 16:38:10 +02:00
|
|
|
|
ToolStripMenuItem m2 = new ToolStripMenuItem("Beenden");
|
|
|
|
|
m2.Image = Resources.MenuImagesQuit;
|
|
|
|
|
m2.Click += Controller.Tray.Click_Quit;
|
|
|
|
|
m2.Name = "Quit";
|
|
|
|
|
menu.Items.Add(m2);
|
|
|
|
|
return menu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ToolStripMenuItem[] genMenuIt(Dictionary<string, Tuple<string, Bitmap, bool, bool>> dictionary, EventHandler ev)
|
|
|
|
|
{
|
|
|
|
|
List<ToolStripMenuItem> l = new List<ToolStripMenuItem>();
|
|
|
|
|
foreach (String key in dictionary.Keys)
|
|
|
|
|
{
|
|
|
|
|
ToolStripMenuItem m = new ToolStripMenuItem(dictionary[key].Item1);
|
|
|
|
|
if (dictionary[key].Item2 != null)
|
|
|
|
|
{
|
|
|
|
|
m.Image = dictionary[key].Item2;
|
|
|
|
|
}
|
|
|
|
|
m.Click += ev;
|
|
|
|
|
m.Name = key;
|
|
|
|
|
m.Enabled = dictionary[key].Item3;
|
|
|
|
|
if (dictionary[key].Item4)
|
|
|
|
|
{
|
|
|
|
|
m.Font = new System.Drawing.Font(m.Font, m.Font.Style | FontStyle.Bold);
|
|
|
|
|
}
|
|
|
|
|
l.Add(m);
|
|
|
|
|
}
|
|
|
|
|
return l.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showBallonTooltip(string text, ToolTipIcon toolTipIcon, string title = "NetMonitor Tray")
|
|
|
|
|
{
|
|
|
|
|
this.trayi.BalloonTipIcon = toolTipIcon;
|
|
|
|
|
this.trayi.BalloonTipText = text;
|
|
|
|
|
this.trayi.BalloonTipTitle = title;
|
|
|
|
|
this.trayi.ShowBalloonTip(100);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-04 23:21:34 +01:00
|
|
|
|
override public void Dispose()
|
2014-07-11 16:38:10 +02:00
|
|
|
|
{
|
|
|
|
|
this.trayi.Visible = false;
|
|
|
|
|
Application.ExitThread();
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-04 23:21:34 +01:00
|
|
|
|
internal void setVpn(bool run, string ip)
|
2014-07-11 16:38:10 +02:00
|
|
|
|
{
|
2015-03-04 23:21:34 +01:00
|
|
|
|
this.showBallonTooltip((run ? "OpenVpn erfolgreich gestartet.\n"+ip : "OpenVpn erfolgreich beendet\n"+ip), ToolTipIcon.Info);
|
|
|
|
|
this.Model.connectedStatus = run;
|
2014-07-11 16:38:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void showError(string text)
|
|
|
|
|
{
|
|
|
|
|
this.showBallonTooltip(text, ToolTipIcon.Error);
|
|
|
|
|
}
|
2015-03-04 23:21:34 +01:00
|
|
|
|
|
|
|
|
|
public Models.Tray Model { get; private set; }
|
|
|
|
|
|
|
|
|
|
internal void setWorkingIcon()
|
|
|
|
|
{
|
|
|
|
|
this.trayi.Icon = this.iconlist[1];
|
|
|
|
|
}
|
2014-07-11 16:38:10 +02:00
|
|
|
|
}
|
|
|
|
|
}
|