Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved connect/disconnect from sub to main menu. #25

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion OpenVPN/OpenVPN.csproj
Expand Up @@ -12,7 +12,7 @@
<AssemblyName>OpenVPN</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SignAssembly>true</SignAssembly>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>jochenwierum.pfx</AssemblyOriginatorKeyFile>
<FileUpgradeFlags>
</FileUpgradeFlags>
Expand Down
10 changes: 7 additions & 3 deletions OpenVPNManager.sln
@@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Express 2012 for Windows Desktop
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6E1C959F-F2A8-4686-A223-57C515CA3753}"
ProjectSection(SolutionItems) = preProject
OpenVPNManager.FxCop = OpenVPNManager.FxCop
Expand Down Expand Up @@ -56,12 +58,14 @@ Global
{628FEE46-4538-4286-A827-8EE45BFC3BCD}.Release|Mixed Platforms.Build.0 = Release|x86
{628FEE46-4538-4286-A827-8EE45BFC3BCD}.Release|x86.ActiveCfg = Release|x86
{628FEE46-4538-4286-A827-8EE45BFC3BCD}.Release|x86.Build.0 = Release|x86
{9676859D-F3BE-4A7C-8263-17EA195B0EA6}.Debug|Any CPU.ActiveCfg = Debug|x86
{9676859D-F3BE-4A7C-8263-17EA195B0EA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9676859D-F3BE-4A7C-8263-17EA195B0EA6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9676859D-F3BE-4A7C-8263-17EA195B0EA6}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{9676859D-F3BE-4A7C-8263-17EA195B0EA6}.Debug|Mixed Platforms.Build.0 = Debug|x86
{9676859D-F3BE-4A7C-8263-17EA195B0EA6}.Debug|x86.ActiveCfg = Debug|x86
{9676859D-F3BE-4A7C-8263-17EA195B0EA6}.Debug|x86.Build.0 = Debug|x86
{9676859D-F3BE-4A7C-8263-17EA195B0EA6}.Release|Any CPU.ActiveCfg = Release|x86
{9676859D-F3BE-4A7C-8263-17EA195B0EA6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9676859D-F3BE-4A7C-8263-17EA195B0EA6}.Release|Any CPU.Build.0 = Release|Any CPU
{9676859D-F3BE-4A7C-8263-17EA195B0EA6}.Release|Mixed Platforms.ActiveCfg = Release|x86
{9676859D-F3BE-4A7C-8263-17EA195B0EA6}.Release|Mixed Platforms.Build.0 = Release|x86
{9676859D-F3BE-4A7C-8263-17EA195B0EA6}.Release|x86.ActiveCfg = Release|x86
Expand Down
53 changes: 40 additions & 13 deletions OpenVPNManager/FrmGlobalStatus.cs
Expand Up @@ -6,6 +6,7 @@
using System.Configuration;
using System.Threading;
using OpenVPNUtils;
using System.Reflection;

namespace OpenVPNManager
{
Expand All @@ -17,6 +18,11 @@ public partial class FrmGlobalStatus : Form

#region variables

/// <summary>
/// The "Advanced" submenu.
/// </summary>
private ToolStripMenuItem m_menu_advanced = new ToolStripMenuItem();

/// <summary>
/// Represents a list of available vpn configuration.
/// </summary>
Expand Down Expand Up @@ -51,6 +57,8 @@ public partial class FrmGlobalStatus : Form
public FrmGlobalStatus(string[] commands)
{
InitializeComponent();
this.niIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(this.niIcon_MouseClick);

Helper.UpdateSettings();

// if this is the first start: show settings
Expand Down Expand Up @@ -270,10 +278,12 @@ public void UnloadConfigs()
{
System.Threading.Thread.Sleep(200);
}
contextMenu.Items.Remove(m_configs[0].Menuitem);
contextMenu.Items.Remove(m_configs[0].ToggleConnectionMenuItem);
m_menu_advanced.DropDownItems.Remove(m_configs[0].Menuitem);
m_configs.Remove(m_configs[0]);
}

contextMenu.Items.Remove(m_menu_advanced);
toolStripSeparator2.Visible = false;
}

Expand All @@ -291,24 +301,27 @@ public void ReadConfigs()

// insert configs in context menu and panel
int atIndex = 2;
if (configs != null)
if (configs != null)
{
m_menu_advanced.Text = Program.res.GetString("TRAY_Advanced");
contextMenu.Items.Insert(atIndex, m_menu_advanced);

toolStripSeparator2.Visible = true;

foreach (string cfile in configs)
foreach (string cfile in configs)
{
try
try
{
VPNConfig c = VPNConfig.CreateUserspaceConnection(
Properties.Settings.Default.vpnbin,
cfile, Properties.Settings.Default.debugLevel,
Properties.Settings.Default.smartCardSupport, this);

m_configs.Add(c);
contextMenu.Items.Insert(atIndex++, c.Menuitem);
m_menu_advanced.DropDownItems.Add(c.Menuitem);
pnlStatus.Controls.Add(c.InfoBox);
}
catch (ArgumentException e)
catch (ArgumentException e)
{
RTLMessageBox.Show(this,
Program.res.GetString("BOX_Config_Error") +
Expand All @@ -319,32 +332,37 @@ public void ReadConfigs()
}

configs = UtilsHelper.LocateOpenVPNManagerConfigs(true);
if (Helper.CanUseService())
{
if (Helper.CanUseService()) {
configs.AddRange(Helper.LocateOpenVPNServiceConfigs());
}

toolStripSeparator2.Visible = configs.Count > 0;
foreach (string cfile in configs)
foreach (string cfile in configs)
{
try
try
{
VPNConfig c = VPNConfig.CreateServiceConnection(
cfile, Properties.Settings.Default.debugLevel,
Properties.Settings.Default.smartCardSupport, this);

m_configs.Add(c);
contextMenu.Items.Insert(atIndex++, c.Menuitem);
m_menu_advanced.DropDownItems.Add(c.Menuitem);
pnlStatus.Controls.Add(c.InfoBox);
}
catch (ArgumentException e)
catch (ArgumentException e)
{
RTLMessageBox.Show(this,
Program.res.GetString("BOX_Config_Error") +
Environment.NewLine + cfile + ": " +
e.Message, MessageBoxIcon.Error);
}
}

// insert connection toggles in menu
int toggleConnectionMenuIndex = 2;
foreach (var c in m_configs) {
contextMenu.Items.Insert(toggleConnectionMenuIndex++, c.ToggleConnectionMenuItem);
}
}

/// <summary>
Expand Down Expand Up @@ -437,6 +455,15 @@ private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
ShowSettings(false);
}

// Show the menu on left click, in addition to right click.
private void niIcon_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left) {
MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic);
mi.Invoke(niIcon, null);
}
}

/// <summary>
/// User doubleclicked notify icon: show/hide icon.
/// </summary>
Expand Down