diff --git a/DeviceUserControl.cs b/DeviceUserControl.cs index ea32181..6466600 100644 --- a/DeviceUserControl.cs +++ b/DeviceUserControl.cs @@ -8,6 +8,13 @@ namespace MeshCentralRouter public NodeClass node; public MainForm parent; public bool present; + private bool xShowDeviceGroupName = true; + + public bool showDeviceGroupName + { + get { return xShowDeviceGroupName; } + set { xShowDeviceGroupName = value; } + } public DeviceUserControl() { @@ -16,7 +23,7 @@ namespace MeshCentralRouter public void UpdateInfo() { - deviceNameLabel.Text = node.name; + if (parent.getShowGroupNames()) { deviceNameLabel.Text = mesh.name + ", " + node.name; } else { deviceNameLabel.Text = node.name; } if (node.conn == 0) { devicePictureBox.Image = disabledDeviceImageList.Images[node.icon - 1]; } else { @@ -25,9 +32,10 @@ namespace MeshCentralRouter string status = ""; if ((node.conn & 1) != 0) { if (status.Length > 0) { status += ", "; } status += "Agent"; } - if ((node.conn & 2) != 0) { if (status.Length > 0) { status += ", "; } status += "AMT"; } - if ((node.conn & 4) != 0) { if (status.Length > 0) { status += ", "; } status += "CIRA"; } - if ((node.conn & 8) != 0) { if (status.Length > 0) { status += ", "; } status += "MQTT"; } + if ((node.conn & 2) != 0) { if (status.Length > 0) { status += ", "; } status += "CIRA"; } + if ((node.conn & 4) != 0) { if (status.Length > 0) { status += ", "; } status += "AMT"; } + if ((node.conn & 8) != 0) { if (status.Length > 0) { status += ", "; } status += "Relay"; } + if ((node.conn & 16) != 0) { if (status.Length > 0) { status += ", "; } status += "MQTT"; } if (status == "") { status = "Offline"; } deviceStatusLabel.Text = status; diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index 22b2c76..a2c3d27 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -50,6 +50,8 @@ this.pictureBox2 = new System.Windows.Forms.PictureBox(); this.tabPage2 = new System.Windows.Forms.TabPage(); this.panel2 = new System.Windows.Forms.Panel(); + this.tokenEmailSentLabel = new System.Windows.Forms.Label(); + this.emailTokenButton = new System.Windows.Forms.Button(); this.label3 = new System.Windows.Forms.Label(); this.tokenTextBox = new System.Windows.Forms.TextBox(); this.pictureBox6 = new System.Windows.Forms.PictureBox(); @@ -93,8 +95,13 @@ this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.emailTokenButton = new System.Windows.Forms.Button(); - this.tokenEmailSentLabel = new System.Windows.Forms.Label(); + this.menuLabel = new System.Windows.Forms.Label(); + this.mainContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); + this.showGroupNamesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.showOfflineDevicesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator(); + this.sortByNameToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.sortByGroupToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.panel5.SuspendLayout(); this.mainPanel.SuspendLayout(); this.mainTabControl.SuspendLayout(); @@ -121,6 +128,7 @@ ((System.ComponentModel.ISupportInitialize)(this.pictureBox7)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.trayIconContextMenuStrip.SuspendLayout(); + this.mainContextMenuStrip.SuspendLayout(); this.SuspendLayout(); // // panel5 @@ -369,6 +377,27 @@ this.panel2.Size = new System.Drawing.Size(478, 316); this.panel2.TabIndex = 7; // + // tokenEmailSentLabel + // + this.tokenEmailSentLabel.AutoSize = true; + this.tokenEmailSentLabel.Location = new System.Drawing.Point(238, 182); + this.tokenEmailSentLabel.Name = "tokenEmailSentLabel"; + this.tokenEmailSentLabel.Size = new System.Drawing.Size(55, 13); + this.tokenEmailSentLabel.TabIndex = 21; + this.tokenEmailSentLabel.Text = "Email sent"; + this.tokenEmailSentLabel.Visible = false; + // + // emailTokenButton + // + this.emailTokenButton.Location = new System.Drawing.Point(241, 177); + this.emailTokenButton.Name = "emailTokenButton"; + this.emailTokenButton.Size = new System.Drawing.Size(75, 23); + this.emailTokenButton.TabIndex = 20; + this.emailTokenButton.Text = "Email"; + this.emailTokenButton.UseVisualStyleBackColor = true; + this.emailTokenButton.Visible = false; + this.emailTokenButton.Click += new System.EventHandler(this.emailTokenButton_Click); + // // label3 // this.label3.AutoSize = true; @@ -567,6 +596,7 @@ // // panel4 // + this.panel4.Controls.Add(this.menuLabel); this.panel4.Controls.Add(this.searchTextBox); this.panel4.Controls.Add(this.devicesTabControl); this.panel4.Controls.Add(this.openWebSiteButton); @@ -582,7 +612,7 @@ // searchTextBox // this.searchTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.searchTextBox.Location = new System.Drawing.Point(330, 5); + this.searchTextBox.Location = new System.Drawing.Point(306, 5); this.searchTextBox.Name = "searchTextBox"; this.searchTextBox.Size = new System.Drawing.Size(146, 20); this.searchTextBox.TabIndex = 9; @@ -845,26 +875,67 @@ this.exitToolStripMenuItem.Text = "E&xit"; this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click_1); // - // emailTokenButton + // menuLabel // - this.emailTokenButton.Location = new System.Drawing.Point(241, 177); - this.emailTokenButton.Name = "emailTokenButton"; - this.emailTokenButton.Size = new System.Drawing.Size(75, 23); - this.emailTokenButton.TabIndex = 20; - this.emailTokenButton.Text = "Email"; - this.emailTokenButton.UseVisualStyleBackColor = true; - this.emailTokenButton.Visible = false; - this.emailTokenButton.Click += new System.EventHandler(this.emailTokenButton_Click); + this.menuLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.menuLabel.AutoSize = true; + this.menuLabel.ContextMenuStrip = this.mainContextMenuStrip; + this.menuLabel.Cursor = System.Windows.Forms.Cursors.Hand; + this.menuLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.menuLabel.Location = new System.Drawing.Point(454, 2); + this.menuLabel.Name = "menuLabel"; + this.menuLabel.Size = new System.Drawing.Size(25, 25); + this.menuLabel.TabIndex = 6; + this.menuLabel.Text = "≡"; + this.menuLabel.Click += new System.EventHandler(this.menuLabel_Click); // - // tokenEmailSentLabel + // mainContextMenuStrip // - this.tokenEmailSentLabel.AutoSize = true; - this.tokenEmailSentLabel.Location = new System.Drawing.Point(238, 182); - this.tokenEmailSentLabel.Name = "tokenEmailSentLabel"; - this.tokenEmailSentLabel.Size = new System.Drawing.Size(55, 13); - this.tokenEmailSentLabel.TabIndex = 21; - this.tokenEmailSentLabel.Text = "Email sent"; - this.tokenEmailSentLabel.Visible = false; + this.mainContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.showGroupNamesToolStripMenuItem, + this.showOfflineDevicesToolStripMenuItem, + this.toolStripMenuItem2, + this.sortByNameToolStripMenuItem, + this.sortByGroupToolStripMenuItem}); + this.mainContextMenuStrip.Name = "mainContextMenuStrip"; + this.mainContextMenuStrip.Size = new System.Drawing.Size(186, 120); + // + // showGroupNamesToolStripMenuItem + // + this.showGroupNamesToolStripMenuItem.Checked = true; + this.showGroupNamesToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; + this.showGroupNamesToolStripMenuItem.Name = "showGroupNamesToolStripMenuItem"; + this.showGroupNamesToolStripMenuItem.Size = new System.Drawing.Size(185, 22); + this.showGroupNamesToolStripMenuItem.Text = "Show &Group Names"; + this.showGroupNamesToolStripMenuItem.Click += new System.EventHandler(this.showGroupNamesToolStripMenuItem_Click); + // + // showOfflineDevicesToolStripMenuItem + // + this.showOfflineDevicesToolStripMenuItem.Name = "showOfflineDevicesToolStripMenuItem"; + this.showOfflineDevicesToolStripMenuItem.Size = new System.Drawing.Size(185, 22); + this.showOfflineDevicesToolStripMenuItem.Text = "Show &Offline Devices"; + this.showOfflineDevicesToolStripMenuItem.Click += new System.EventHandler(this.hideOfflineDevicesToolStripMenuItem_Click); + // + // toolStripMenuItem2 + // + this.toolStripMenuItem2.Name = "toolStripMenuItem2"; + this.toolStripMenuItem2.Size = new System.Drawing.Size(182, 6); + // + // sortByNameToolStripMenuItem + // + this.sortByNameToolStripMenuItem.Checked = true; + this.sortByNameToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; + this.sortByNameToolStripMenuItem.Name = "sortByNameToolStripMenuItem"; + this.sortByNameToolStripMenuItem.Size = new System.Drawing.Size(185, 22); + this.sortByNameToolStripMenuItem.Text = "Sort by &Name"; + this.sortByNameToolStripMenuItem.Click += new System.EventHandler(this.sortByNameToolStripMenuItem_Click); + // + // sortByGroupToolStripMenuItem + // + this.sortByGroupToolStripMenuItem.Name = "sortByGroupToolStripMenuItem"; + this.sortByGroupToolStripMenuItem.Size = new System.Drawing.Size(185, 22); + this.sortByGroupToolStripMenuItem.Text = "Sort by G&roup"; + this.sortByGroupToolStripMenuItem.Click += new System.EventHandler(this.sortByGroupToolStripMenuItem_Click); // // MainForm // @@ -910,6 +981,7 @@ ((System.ComponentModel.ISupportInitialize)(this.pictureBox7)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.trayIconContextMenuStrip.ResumeLayout(false); + this.mainContextMenuStrip.ResumeLayout(false); this.ResumeLayout(false); } @@ -980,6 +1052,13 @@ private System.Windows.Forms.Label noSearchResultsLabel; private System.Windows.Forms.Button emailTokenButton; private System.Windows.Forms.Label tokenEmailSentLabel; + private System.Windows.Forms.Label menuLabel; + private System.Windows.Forms.ContextMenuStrip mainContextMenuStrip; + private System.Windows.Forms.ToolStripMenuItem showGroupNamesToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem showOfflineDevicesToolStripMenuItem; + private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2; + private System.Windows.Forms.ToolStripMenuItem sortByNameToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem sortByGroupToolStripMenuItem; } } diff --git a/MainForm.cs b/MainForm.cs index e2f2496..2790488 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -40,6 +40,9 @@ namespace MeshCentralRouter public bool forceExit = false; public bool sendEmailToken = false; + public void setRegValue(string name, string value) { Registry.SetValue(@"HKEY_CURRENT_USER\SOFTWARE\Open Source\MeshCentral Router", name, value); } + public string getRegValue(string name, string value) { return Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Open Source\MeshCentral Router", name, value).ToString(); } + public class DeviceComparer : IComparer { public int Compare(Object a, Object b) @@ -49,7 +52,16 @@ namespace MeshCentralRouter return bx.CompareTo(ax); } } - + public class DeviceGroupComparer : IComparer + { + public int Compare(Object a, Object b) + { + string ax = ((DeviceUserControl)a).mesh.name.ToLower() + ", " + ((DeviceUserControl)a).node.name.ToLower(); + string bx = ((DeviceUserControl)a).mesh.name.ToLower() + ", " + ((DeviceUserControl)b).node.name.ToLower(); + return bx.CompareTo(ax); + } + } + private const int EM_SETCUEBANNER = 0x1501; [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern Int32 SendMessage(IntPtr hWnd, int msg, int wParam, [MarshalAs(UnmanagedType.LPWStr)]string lParam); @@ -110,6 +122,17 @@ namespace MeshCentralRouter private void MainForm_Load(object sender, EventArgs e) { + // Load registry settings + showGroupNamesToolStripMenuItem.Checked = (getRegValue("Show Group Names", "1") == "1"); + showOfflineDevicesToolStripMenuItem.Checked = (getRegValue("Show Offline Devices", "1") == "1"); + if (getRegValue("Device Sort", "Name") == "Name") { + sortByNameToolStripMenuItem.Checked = true; + sortByGroupToolStripMenuItem.Checked = false; + } else { + sortByNameToolStripMenuItem.Checked = false; + sortByGroupToolStripMenuItem.Checked = true; + } + //Text += " - v" + Application.ProductVersion; //installPathTextBox.Text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Open Source", "MeshCentral"); //serverModeComboBox.SelectedIndex = 0; @@ -278,8 +301,7 @@ namespace MeshCentralRouter } // Clear all untagged devices - foreach (Control c in devicesPanel.Controls) - { + foreach (Control c in devicesPanel.Controls) { if ((c.GetType() == typeof(DeviceUserControl)) && ((DeviceUserControl)c).present == false) { devicesPanel.Controls.Remove(c); c.Dispose(); } @@ -287,12 +309,12 @@ namespace MeshCentralRouter // Filter devices int visibleDevices = 0; - foreach (Control c in devicesPanel.Controls) - { + foreach (Control c in devicesPanel.Controls) { if (c.GetType() == typeof(DeviceUserControl)) { NodeClass n = ((DeviceUserControl)c).node; - if ((search == "") || (n.name.ToLower().IndexOf(search) >= 0)) { - c.Visible = true; + bool connVisible = ((showOfflineDevicesToolStripMenuItem.Checked) || ((n.conn & 1) != 0)); + if ((search == "") || (n.name.ToLower().IndexOf(search) >= 0) || (showGroupNamesToolStripMenuItem.Checked && (((DeviceUserControl)c).mesh.name.ToLower().IndexOf(search) >= 0))) { + c.Visible = connVisible; visibleDevices++; } else { c.Visible = false; @@ -303,8 +325,13 @@ namespace MeshCentralRouter // Sort devices ArrayList sortlist = new ArrayList(); foreach (Control c in devicesPanel.Controls) { if (c.GetType() == typeof(DeviceUserControl)) { sortlist.Add(c); } } - DeviceComparer comp = new DeviceComparer(); - sortlist.Sort(comp); + if (sortByNameToolStripMenuItem.Checked) { + DeviceComparer comp = new DeviceComparer(); + sortlist.Sort(comp); + } else { + DeviceGroupComparer comp = new DeviceGroupComparer(); + sortlist.Sort(comp); + } devicesPanel.Controls.Clear(); devicesPanel.Controls.AddRange((DeviceUserControl[])sortlist.ToArray(typeof(DeviceUserControl))); @@ -313,6 +340,8 @@ namespace MeshCentralRouter noSearchResultsLabel.Visible = ((devicesPanel.Controls.Count > 0) && (visibleDevices == 0)); } + public bool getShowGroupNames() { return showGroupNamesToolStripMenuItem.Checked; } + private void Meshcentral_onStateChanged(int state) { if (meshcentral == null) return; @@ -730,13 +759,13 @@ namespace MeshCentralRouter if (c.GetType() == typeof(DeviceUserControl)) { NodeClass n = ((DeviceUserControl)c).node; - if ((search == "") || (n.name.ToLower().IndexOf(search) >= 0)) + bool connVisible = ((showOfflineDevicesToolStripMenuItem.Checked) || ((n.conn & 1) != 0)); + if ((search == "") || (n.name.ToLower().IndexOf(search) >= 0) || (showGroupNamesToolStripMenuItem.Checked && (((DeviceUserControl)c).mesh.name.ToLower().IndexOf(search) >= 0))) { - c.Visible = true; + //if ((search == "") || (n.name.ToLower().IndexOf(search) >= 0)) { + c.Visible = connVisible; visibleDevices++; - } - else - { + } else { c.Visible = false; } } @@ -748,7 +777,7 @@ namespace MeshCentralRouter private void devicesTabControl_SelectedIndexChanged(object sender, EventArgs e) { - searchTextBox.Visible = (devicesTabControl.SelectedIndex == 0); + menuLabel.Visible = searchTextBox.Visible = (devicesTabControl.SelectedIndex == 0); } private void searchTextBox_KeyPress(object sender, KeyPressEventArgs e) @@ -812,6 +841,41 @@ namespace MeshCentralRouter nextButton2.Enabled = (tokenTextBox.Text.Replace(" ", "") != ""); } + private void menuLabel_Click(object sender, EventArgs e) + { + mainContextMenuStrip.Show(menuLabel, menuLabel.PointToClient(Cursor.Position)); + } + + private void showGroupNamesToolStripMenuItem_Click(object sender, EventArgs e) + { + showGroupNamesToolStripMenuItem.Checked = !showGroupNamesToolStripMenuItem.Checked; + setRegValue("Show Group Names", showGroupNamesToolStripMenuItem.Checked ? "1" : "0"); + updateDeviceList(); + } + + private void hideOfflineDevicesToolStripMenuItem_Click(object sender, EventArgs e) + { + showOfflineDevicesToolStripMenuItem.Checked = !showOfflineDevicesToolStripMenuItem.Checked; + setRegValue("Show Offline Devices", showOfflineDevicesToolStripMenuItem.Checked?"1":"0"); + updateDeviceList(); + } + + private void sortByNameToolStripMenuItem_Click(object sender, EventArgs e) + { + sortByNameToolStripMenuItem.Checked = true; + sortByGroupToolStripMenuItem.Checked = false; + setRegValue("Device Sort", "Name"); + updateDeviceList(); + } + + private void sortByGroupToolStripMenuItem_Click(object sender, EventArgs e) + { + sortByNameToolStripMenuItem.Checked = false; + sortByGroupToolStripMenuItem.Checked = true; + setRegValue("Device Sort", "Group"); + updateDeviceList(); + } + /* private delegate void displayMessageHandler(string msg, int buttons, string extra, int progress); private void displayMessage(string msg, int buttons = 0, string extra = "", int progress = 0) diff --git a/MainForm.resx b/MainForm.resx index fa5c6f6..ef449c8 100644 --- a/MainForm.resx +++ b/MainForm.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 613, 17 + This server presented a un-trusted certificate. This may indicate that this is not the correct server or that the server does not have a valid certificate. It is not recommanded, but you can press the ignore button to continue connection to this server. diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs index be4e4bf..35f5d66 100644 --- a/Properties/Settings.Designer.cs +++ b/Properties/Settings.Designer.cs @@ -22,77 +22,5 @@ namespace MeshCentralRouter.Properties { return defaultInstance; } } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("0")] - public int ViewType { - get { - return ((int)(this["ViewType"])); - } - set { - this["ViewType"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("1")] - public int GraphType { - get { - return ((int)(this["GraphType"])); - } - set { - this["GraphType"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("True")] - public bool ShowHiddenNodes { - get { - return ((bool)(this["ShowHiddenNodes"])); - } - set { - this["ShowHiddenNodes"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("")] - public string ServerCertHash { - get { - return ((string)(this["ServerCertHash"])); - } - set { - this["ServerCertHash"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("False")] - public bool AllowsAgentDownloads { - get { - return ((bool)(this["AllowsAgentDownloads"])); - } - set { - this["AllowsAgentDownloads"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("False")] - public bool AllowsAgentUploads { - get { - return ((bool)(this["AllowsAgentUploads"])); - } - set { - this["AllowsAgentUploads"] = value; - } - } } } diff --git a/Properties/Settings.settings b/Properties/Settings.settings index e6bfb2a..8e615f2 100644 --- a/Properties/Settings.settings +++ b/Properties/Settings.settings @@ -1,24 +1,5 @@  - + - - - 0 - - - 1 - - - True - - - - - - False - - - False - - + \ No newline at end of file