2010-01-26 22:37:48 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
|
|
|
|
The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.mozilla.org/MPL/
|
|
|
|
|
|
|
|
Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
for the specific language governing rights and limitations under the License.
|
|
|
|
|
|
|
|
The Original Code is the Open Hardware Monitor code.
|
|
|
|
|
|
|
|
The Initial Developer of the Original Code is
|
|
|
|
Michael Möller <m.moeller@gmx.ch>.
|
|
|
|
Portions created by the Initial Developer are Copyright (C) 2009-2010
|
|
|
|
the Initial Developer. All Rights Reserved.
|
|
|
|
|
|
|
|
Contributor(s):
|
|
|
|
|
|
|
|
Alternatively, the contents of this file may be used under the terms of
|
|
|
|
either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
of those above. If you wish to allow use of your version of this file only
|
|
|
|
under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
use your version of this file under the terms of the MPL, indicate your
|
|
|
|
decision by deleting the provisions above and replace them with the notice
|
|
|
|
and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
the provisions above, a recipient may use your version of this file under
|
|
|
|
the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Configuration;
|
|
|
|
using System.Drawing;
|
|
|
|
using System.Text;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using Aga.Controls.Tree;
|
|
|
|
using Aga.Controls.Tree.NodeControls;
|
|
|
|
using OpenHardwareMonitor.Hardware;
|
2010-02-07 16:37:15 +00:00
|
|
|
using OpenHardwareMonitor.Utilities;
|
2010-01-26 22:37:48 +00:00
|
|
|
|
|
|
|
namespace OpenHardwareMonitor.GUI {
|
|
|
|
public partial class MainForm : Form {
|
|
|
|
|
2010-02-07 16:37:15 +00:00
|
|
|
private Computer computer = new Computer();
|
2010-01-26 22:37:48 +00:00
|
|
|
private Node root;
|
|
|
|
private TreeModel treeModel;
|
|
|
|
private IDictionary<ISensor, Color> sensorPlotColors =
|
|
|
|
new Dictionary<ISensor, Color>();
|
|
|
|
private Color[] plotColorPalette;
|
|
|
|
|
2010-02-07 16:37:15 +00:00
|
|
|
public MainForm() {
|
2010-01-26 22:37:48 +00:00
|
|
|
InitializeComponent();
|
|
|
|
this.Font = SystemFonts.MessageBoxFont;
|
|
|
|
treeView.Font = SystemFonts.MessageBoxFont;
|
|
|
|
plotPanel.Font = SystemFonts.MessageBoxFont;
|
|
|
|
|
|
|
|
nodeCheckBox.IsVisibleValueNeeded +=
|
|
|
|
new EventHandler<NodeControlValueEventArgs>(
|
|
|
|
nodeCheckBox_IsVisibleValueNeeded);
|
|
|
|
nodeCheckBox.CheckStateChanged +=
|
|
|
|
new EventHandler<TreePathEventArgs>(UpdatePlotSelection);
|
|
|
|
nodeTextBoxText.DrawText +=
|
|
|
|
new EventHandler<DrawEventArgs>(nodeTextBoxText_DrawText);
|
|
|
|
nodeTextBoxValue.DrawText +=
|
|
|
|
new EventHandler<DrawEventArgs>(nodeTextBoxText_DrawText);
|
|
|
|
nodeTextBoxMin.DrawText +=
|
|
|
|
new EventHandler<DrawEventArgs>(nodeTextBoxText_DrawText);
|
|
|
|
nodeTextBoxMax.DrawText +=
|
|
|
|
new EventHandler<DrawEventArgs>(nodeTextBoxText_DrawText);
|
|
|
|
nodeTextBoxLimit.DrawText +=
|
|
|
|
new EventHandler<DrawEventArgs>(nodeTextBoxLimit_DrawText);
|
|
|
|
|
|
|
|
if (Utilities.Config.Contains("mainForm.Location.X")) {
|
|
|
|
int x = Utilities.Config.Get("mainForm.Location.X", Location.X);
|
|
|
|
x = x < 0 ? 0 : x;
|
|
|
|
int y = Utilities.Config.Get("mainForm.Location.Y", Location.Y);
|
|
|
|
y = y < 0 ? 0 : y;
|
|
|
|
this.Location = new Point(x, y);
|
|
|
|
} else {
|
|
|
|
StartPosition = FormStartPosition.CenterScreen;
|
|
|
|
}
|
|
|
|
|
|
|
|
Width = Utilities.Config.Get("mainForm.Width", Width);
|
|
|
|
Height = Utilities.Config.Get("mainForm.Height", Height);
|
|
|
|
|
|
|
|
treeModel = new TreeModel();
|
|
|
|
root = new Node(System.Environment.MachineName);
|
|
|
|
root.Image = Utilities.EmbeddedResources.GetImage("computer.png");
|
|
|
|
|
|
|
|
treeModel.Nodes.Add(root);
|
|
|
|
treeView.Model = treeModel;
|
|
|
|
|
2010-02-07 16:37:15 +00:00
|
|
|
computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
|
|
|
|
computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
|
|
|
|
computer.Open();
|
|
|
|
|
2010-01-26 22:37:48 +00:00
|
|
|
plotColorPalette = new Color[14];
|
|
|
|
plotColorPalette[0] = Color.Blue;
|
|
|
|
plotColorPalette[1] = Color.OrangeRed;
|
|
|
|
plotColorPalette[2] = Color.Green;
|
|
|
|
plotColorPalette[3] = Color.LightSeaGreen;
|
|
|
|
plotColorPalette[4] = Color.Goldenrod;
|
|
|
|
plotColorPalette[5] = Color.DarkViolet;
|
|
|
|
plotColorPalette[6] = Color.YellowGreen;
|
|
|
|
plotColorPalette[7] = Color.SaddleBrown;
|
|
|
|
plotColorPalette[8] = Color.Gray;
|
|
|
|
plotColorPalette[9] = Color.RoyalBlue;
|
|
|
|
plotColorPalette[10] = Color.DeepPink;
|
|
|
|
plotColorPalette[11] = Color.MediumSeaGreen;
|
|
|
|
plotColorPalette[12] = Color.Olive;
|
|
|
|
plotColorPalette[13] = Color.Firebrick;
|
|
|
|
|
2010-02-07 16:37:15 +00:00
|
|
|
plotMenuItem.Checked = Config.Get(plotMenuItem.Name, false);
|
|
|
|
minMenuItem.Checked = Config.Get(minMenuItem.Name, false);
|
|
|
|
maxMenuItem.Checked = Config.Get(maxMenuItem.Name, true);
|
|
|
|
limitMenuItem.Checked = Config.Get(limitMenuItem.Name, false);
|
|
|
|
|
|
|
|
minTrayMenuItem.Checked = Config.Get(minTrayMenuItem.Name, true);
|
|
|
|
hddMenuItem.Checked = Config.Get(hddMenuItem.Name, true);
|
|
|
|
|
|
|
|
voltMenuItem.Checked = Config.Get(voltMenuItem.Name, true);
|
|
|
|
clocksMenuItem.Checked = Config.Get(clocksMenuItem.Name, true);
|
|
|
|
loadMenuItem.Checked = Config.Get(loadMenuItem.Name, true);
|
|
|
|
tempMenuItem.Checked = Config.Get(tempMenuItem.Name, true);
|
|
|
|
fansMenuItem.Checked = Config.Get(fansMenuItem.Name, true);
|
|
|
|
|
|
|
|
timer.Enabled = true;
|
2010-01-26 22:37:48 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 16:37:15 +00:00
|
|
|
private void HardwareAdded(IHardware hardware) {
|
|
|
|
root.Nodes.Add(new HardwareNode(hardware));
|
2010-01-26 22:37:48 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 16:37:15 +00:00
|
|
|
private void HardwareRemoved(IHardware hardware) {
|
2010-01-26 22:37:48 +00:00
|
|
|
List<Node> nodesToRemove = new List<Node>();
|
2010-02-07 16:37:15 +00:00
|
|
|
foreach (Node node in root.Nodes) {
|
|
|
|
HardwareNode hardwareNode = node as HardwareNode;
|
|
|
|
if (hardwareNode != null && hardwareNode.Hardware == hardware)
|
|
|
|
nodesToRemove.Add(node);
|
|
|
|
}
|
2010-01-26 22:37:48 +00:00
|
|
|
foreach (Node node in nodesToRemove)
|
|
|
|
root.Nodes.Remove(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void nodeTextBoxLimit_DrawText(object sender, DrawEventArgs e) {
|
|
|
|
SensorNode sensorNode = e.Node.Tag as SensorNode;
|
|
|
|
if (sensorNode != null)
|
|
|
|
e.Text = sensorNode.ValueToString(sensorNode.Sensor.Limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void nodeTextBoxText_DrawText(object sender, DrawEventArgs e) {
|
|
|
|
if (!plotMenuItem.Checked)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SensorNode sensorNode = e.Node.Tag as SensorNode;
|
|
|
|
if (sensorNode != null) {
|
|
|
|
Color color;
|
|
|
|
if (sensorPlotColors.TryGetValue(sensorNode.Sensor, out color))
|
|
|
|
e.TextColor = color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdatePlotSelection(object sender,
|
|
|
|
TreePathEventArgs e)
|
|
|
|
{
|
|
|
|
List<ISensor> selected = new List<ISensor>();
|
|
|
|
IDictionary<ISensor, Color> colors = new Dictionary<ISensor, Color>();
|
|
|
|
int colorIndex = 0;
|
|
|
|
foreach (TreeNodeAdv node in treeView.AllNodes) {
|
|
|
|
SensorNode sensorNode = node.Tag as SensorNode;
|
|
|
|
if (sensorNode != null &&
|
|
|
|
sensorNode.Sensor.SensorType == SensorType.Temperature) {
|
|
|
|
if (sensorNode.Plot) {
|
|
|
|
colors.Add(sensorNode.Sensor,
|
|
|
|
plotColorPalette[colorIndex % plotColorPalette.Length]);
|
|
|
|
selected.Add(sensorNode.Sensor);
|
|
|
|
}
|
|
|
|
colorIndex++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sensorPlotColors = colors;
|
|
|
|
plotPanel.SetSensors(selected, colors);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void nodeCheckBox_IsVisibleValueNeeded(object sender,
|
|
|
|
NodeControlValueEventArgs e) {
|
|
|
|
SensorNode node = e.Node.Tag as SensorNode;
|
|
|
|
e.Value = (node != null) &&
|
|
|
|
(node.Sensor.SensorType == SensorType.Temperature) &&
|
|
|
|
plotMenuItem.Checked;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void timer_Tick(object sender, EventArgs e) {
|
|
|
|
|
|
|
|
#if !DEBUG
|
|
|
|
try {
|
|
|
|
#endif
|
2010-02-07 16:37:15 +00:00
|
|
|
computer.Update();
|
2010-01-26 22:37:48 +00:00
|
|
|
#if !DEBUG
|
|
|
|
} catch (Exception exception) {
|
2010-02-07 16:37:15 +00:00
|
|
|
CrashReport.Save(exception);
|
2010-01-26 22:37:48 +00:00
|
|
|
Close();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
treeView.Invalidate();
|
|
|
|
plotPanel.Invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
|
2010-02-07 16:37:15 +00:00
|
|
|
|
|
|
|
Config.Set(plotMenuItem.Name, plotMenuItem.Checked);
|
|
|
|
Config.Set(minMenuItem.Name, minMenuItem.Checked);
|
|
|
|
Config.Set(maxMenuItem.Name, maxMenuItem.Checked);
|
|
|
|
Config.Set(limitMenuItem.Name, limitMenuItem.Checked);
|
|
|
|
|
|
|
|
Config.Set(minTrayMenuItem.Name, minTrayMenuItem.Checked);
|
|
|
|
Config.Set(hddMenuItem.Name, hddMenuItem.Checked);
|
|
|
|
|
|
|
|
Config.Set(voltMenuItem.Name, voltMenuItem.Checked);
|
|
|
|
Config.Set(clocksMenuItem.Name, clocksMenuItem.Checked);
|
|
|
|
Config.Set(loadMenuItem.Name, loadMenuItem.Checked);
|
|
|
|
Config.Set(tempMenuItem.Name, tempMenuItem.Checked);
|
|
|
|
Config.Set(fansMenuItem.Name, fansMenuItem.Checked);
|
2010-01-26 22:37:48 +00:00
|
|
|
|
2010-01-31 20:57:18 +00:00
|
|
|
if (WindowState != FormWindowState.Minimized) {
|
2010-02-07 16:37:15 +00:00
|
|
|
Config.Set("mainForm.Location.X", Location.X);
|
|
|
|
Config.Set("mainForm.Location.Y", Location.Y);
|
|
|
|
Config.Set("mainForm.Width", Width);
|
|
|
|
Config.Set("mainForm.Height", Height);
|
2010-01-31 20:57:18 +00:00
|
|
|
}
|
2010-01-26 22:37:48 +00:00
|
|
|
|
2010-02-07 16:37:15 +00:00
|
|
|
computer.Close();
|
2010-01-26 22:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void aboutToolStripMenuItem_Click(object sender, EventArgs e) {
|
|
|
|
new AboutBox().ShowDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void plotToolStripMenuItem_CheckedChanged(object sender,
|
|
|
|
EventArgs e)
|
|
|
|
{
|
|
|
|
splitContainer.Panel2Collapsed = !plotMenuItem.Checked;
|
|
|
|
treeView.Invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void valueToolStripMenuItem_CheckedChanged(object sender,
|
|
|
|
EventArgs e)
|
|
|
|
{
|
|
|
|
treeView.Columns[1].IsVisible = valueToolStripMenuItem.Checked;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void minToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
treeView.Columns[2].IsVisible = minMenuItem.Checked;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void maxToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
treeView.Columns[3].IsVisible = maxMenuItem.Checked;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void limitToolStripMenuItem_CheckedChanged(object sender,
|
|
|
|
EventArgs e) {
|
|
|
|
treeView.Columns[4].IsVisible = limitMenuItem.Checked;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void treeView_Click(object sender, EventArgs e) {
|
|
|
|
|
|
|
|
MouseEventArgs m = e as MouseEventArgs;
|
|
|
|
if (m == null || m.Button != MouseButtons.Right)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NodeControlInfo info = treeView.GetNodeControlInfoAt(new Point(m.X, m.Y));
|
2010-02-07 16:37:15 +00:00
|
|
|
if (info.Control == null) {
|
2010-01-26 22:37:48 +00:00
|
|
|
columnsContextMenuStrip.Show(treeView, m.X, m.Y);
|
2010-02-07 16:37:15 +00:00
|
|
|
}
|
2010-01-26 22:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void saveReportToolStripMenuItem_Click(object sender, EventArgs e) {
|
2010-02-07 16:37:15 +00:00
|
|
|
computer.SaveReport(new Version(Application.ProductVersion));
|
2010-01-26 22:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void hddsensorsToolStripMenuItem_CheckedChanged(object sender,
|
|
|
|
EventArgs e)
|
|
|
|
{
|
2010-02-07 16:37:15 +00:00
|
|
|
computer.HDDEnabled = hddMenuItem.Checked;
|
|
|
|
UpdateSensorTypeChecked(null, null);
|
|
|
|
UpdatePlotSelection(null, null);
|
2010-01-26 22:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateSensorTypeChecked(object sender, EventArgs e) {
|
|
|
|
foreach (HardwareNode node in root.Nodes) {
|
|
|
|
node.SetVisible(SensorType.Voltage, voltMenuItem.Checked);
|
|
|
|
node.SetVisible(SensorType.Clock, clocksMenuItem.Checked);
|
2010-02-03 20:35:10 +00:00
|
|
|
node.SetVisible(SensorType.Load, loadMenuItem.Checked);
|
2010-01-26 22:37:48 +00:00
|
|
|
node.SetVisible(SensorType.Temperature, tempMenuItem.Checked);
|
|
|
|
node.SetVisible(SensorType.Fan, fansMenuItem.Checked);
|
|
|
|
}
|
2010-02-05 22:45:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void ToggleSysTray() {
|
|
|
|
if (Visible) {
|
|
|
|
notifyIcon.Visible = true;
|
|
|
|
Visible = false;
|
|
|
|
} else {
|
|
|
|
Visible = true;
|
|
|
|
notifyIcon.Visible = false;
|
2010-02-07 16:37:15 +00:00
|
|
|
BringToFront();
|
2010-02-05 22:45:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void WndProc(ref Message m) {
|
|
|
|
const int WM_SYSCOMMAND = 0x112;
|
|
|
|
const int SC_MINIMIZE = 0xF020;
|
2010-02-07 16:37:15 +00:00
|
|
|
if (minTrayMenuItem.Checked &&
|
|
|
|
m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_MINIMIZE) {
|
2010-02-05 22:45:15 +00:00
|
|
|
ToggleSysTray();
|
|
|
|
} else {
|
|
|
|
base.WndProc(ref m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-07 16:37:15 +00:00
|
|
|
private void restoreClick(object sender, EventArgs e) {
|
|
|
|
ToggleSysTray();
|
2010-02-05 22:45:15 +00:00
|
|
|
}
|
|
|
|
|
2010-01-26 22:37:48 +00:00
|
|
|
}
|
|
|
|
}
|