Added support for T-Balancer sensorhub and miniNG. Added a Flow sensor-type.
3 Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 The contents of this file are subject to the Mozilla Public License Version
6 1.1 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.mozilla.org/MPL/
11 Software distributed under the License is distributed on an "AS IS" basis,
12 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 for the specific language governing rights and limitations under the License.
15 The Original Code is the Open Hardware Monitor code.
17 The Initial Developer of the Original Code is
18 Michael Möller <m.moeller@gmx.ch>.
19 Portions created by the Initial Developer are Copyright (C) 2009-2010
20 the Initial Developer. All Rights Reserved.
24 Alternatively, the contents of this file may be used under the terms of
25 either the GNU General Public License Version 2 or later (the "GPL"), or
26 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 in which case the provisions of the GPL or the LGPL are applicable instead
28 of those above. If you wish to allow use of your version of this file only
29 under the terms of either the GPL or the LGPL, and not to allow others to
30 use your version of this file under the terms of the MPL, indicate your
31 decision by deleting the provisions above and replace them with the notice
32 and other provisions required by the GPL or the LGPL. If you do not delete
33 the provisions above, a recipient may use your version of this file under
34 the terms of any one of the MPL, the GPL or the LGPL.
39 using System.Collections.Generic;
40 using System.ComponentModel;
41 using System.Configuration;
44 using System.Windows.Forms;
45 using Aga.Controls.Tree;
46 using Aga.Controls.Tree.NodeControls;
47 using OpenHardwareMonitor.Hardware;
48 using OpenHardwareMonitor.Utilities;
50 namespace OpenHardwareMonitor.GUI {
51 public partial class MainForm : Form {
53 private Computer computer = new Computer();
55 private TreeModel treeModel;
56 private IDictionary<ISensor, Color> sensorPlotColors =
57 new Dictionary<ISensor, Color>();
58 private Color[] plotColorPalette;
59 private SensorSystemTray sensorSystemTray;
60 private NotifyIcon notifyIcon;
63 InitializeComponent();
64 this.Font = SystemFonts.MessageBoxFont;
65 treeView.Font = SystemFonts.MessageBoxFont;
66 plotPanel.Font = SystemFonts.MessageBoxFont;
68 nodeCheckBox.IsVisibleValueNeeded +=
69 new EventHandler<NodeControlValueEventArgs>(
70 nodeCheckBox_IsVisibleValueNeeded);
71 nodeCheckBox.CheckStateChanged +=
72 new EventHandler<TreePathEventArgs>(UpdatePlotSelection);
73 nodeTextBoxText.DrawText +=
74 new EventHandler<DrawEventArgs>(nodeTextBoxText_DrawText);
75 nodeTextBoxValue.DrawText +=
76 new EventHandler<DrawEventArgs>(nodeTextBoxText_DrawText);
77 nodeTextBoxMin.DrawText +=
78 new EventHandler<DrawEventArgs>(nodeTextBoxText_DrawText);
79 nodeTextBoxMax.DrawText +=
80 new EventHandler<DrawEventArgs>(nodeTextBoxText_DrawText);
81 nodeTextBoxLimit.DrawText +=
82 new EventHandler<DrawEventArgs>(nodeTextBoxLimit_DrawText);
84 if (Utilities.Config.Contains("mainForm.Location.X")) {
85 int x = Utilities.Config.Get("mainForm.Location.X", Location.X);
87 int y = Utilities.Config.Get("mainForm.Location.Y", Location.Y);
89 this.Location = new Point(x, y);
91 StartPosition = FormStartPosition.CenterScreen;
94 Width = Utilities.Config.Get("mainForm.Width", Width);
95 Height = Utilities.Config.Get("mainForm.Height", Height);
97 treeModel = new TreeModel();
98 root = new Node(System.Environment.MachineName);
99 root.Image = Utilities.EmbeddedResources.GetImage("computer.png");
101 treeModel.Nodes.Add(root);
102 treeView.Model = treeModel;
104 notifyIcon = new NotifyIcon();
105 notifyIcon.ContextMenuStrip = this.notifyContextMenuStrip;
106 notifyIcon.Icon = EmbeddedResources.GetIcon("smallicon.ico");
107 notifyIcon.Text = "Open Hardware Monitor";
108 notifyIcon.DoubleClick += new EventHandler(this.restoreClick);
110 sensorSystemTray = new SensorSystemTray(computer);
112 computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
113 computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
116 plotColorPalette = new Color[14];
117 plotColorPalette[0] = Color.Blue;
118 plotColorPalette[1] = Color.OrangeRed;
119 plotColorPalette[2] = Color.Green;
120 plotColorPalette[3] = Color.LightSeaGreen;
121 plotColorPalette[4] = Color.Goldenrod;
122 plotColorPalette[5] = Color.DarkViolet;
123 plotColorPalette[6] = Color.YellowGreen;
124 plotColorPalette[7] = Color.SaddleBrown;
125 plotColorPalette[8] = Color.Gray;
126 plotColorPalette[9] = Color.RoyalBlue;
127 plotColorPalette[10] = Color.DeepPink;
128 plotColorPalette[11] = Color.MediumSeaGreen;
129 plotColorPalette[12] = Color.Olive;
130 plotColorPalette[13] = Color.Firebrick;
132 plotMenuItem.Checked = Config.Get(plotMenuItem.Name, false);
133 minMenuItem.Checked = Config.Get(minMenuItem.Name, false);
134 maxMenuItem.Checked = Config.Get(maxMenuItem.Name, true);
135 limitMenuItem.Checked = Config.Get(limitMenuItem.Name, false);
137 startMinMenuItem.Checked = Config.Get(startMinMenuItem.Name, false);
138 minTrayMenuItem.Checked = Config.Get(minTrayMenuItem.Name, true);
139 hddMenuItem.Checked = Config.Get(hddMenuItem.Name, true);
141 voltMenuItem.Checked = Config.Get(voltMenuItem.Name, true);
142 clocksMenuItem.Checked = Config.Get(clocksMenuItem.Name, true);
143 loadMenuItem.Checked = Config.Get(loadMenuItem.Name, true);
144 tempMenuItem.Checked = Config.Get(tempMenuItem.Name, true);
145 fansMenuItem.Checked = Config.Get(fansMenuItem.Name, true);
146 flowsMenuItem.Checked = Config.Get(flowsMenuItem.Name, true);
148 timer.Enabled = true;
150 if (startMinMenuItem.Checked) {
151 if (minTrayMenuItem.Checked) {
152 notifyIcon.Visible = true;
154 WindowState = FormWindowState.Minimized;
162 private void HardwareAdded(IHardware hardware) {
163 root.Nodes.Add(new HardwareNode(hardware));
166 private void HardwareRemoved(IHardware hardware) {
167 List<Node> nodesToRemove = new List<Node>();
168 foreach (Node node in root.Nodes) {
169 HardwareNode hardwareNode = node as HardwareNode;
170 if (hardwareNode != null && hardwareNode.Hardware == hardware)
171 nodesToRemove.Add(node);
173 foreach (Node node in nodesToRemove)
174 root.Nodes.Remove(node);
177 private void nodeTextBoxLimit_DrawText(object sender, DrawEventArgs e) {
178 SensorNode sensorNode = e.Node.Tag as SensorNode;
179 if (sensorNode != null)
180 e.Text = sensorNode.ValueToString(sensorNode.Sensor.Limit);
183 private void nodeTextBoxText_DrawText(object sender, DrawEventArgs e) {
184 if (!plotMenuItem.Checked)
187 SensorNode sensorNode = e.Node.Tag as SensorNode;
188 if (sensorNode != null) {
190 if (sensorPlotColors.TryGetValue(sensorNode.Sensor, out color))
195 private void UpdatePlotSelection(object sender,
198 List<ISensor> selected = new List<ISensor>();
199 IDictionary<ISensor, Color> colors = new Dictionary<ISensor, Color>();
201 foreach (TreeNodeAdv node in treeView.AllNodes) {
202 SensorNode sensorNode = node.Tag as SensorNode;
203 if (sensorNode != null &&
204 sensorNode.Sensor.SensorType == SensorType.Temperature) {
205 if (sensorNode.Plot) {
206 colors.Add(sensorNode.Sensor,
207 plotColorPalette[colorIndex % plotColorPalette.Length]);
208 selected.Add(sensorNode.Sensor);
213 sensorPlotColors = colors;
214 plotPanel.SetSensors(selected, colors);
217 private void nodeCheckBox_IsVisibleValueNeeded(object sender,
218 NodeControlValueEventArgs e) {
219 SensorNode node = e.Node.Tag as SensorNode;
220 e.Value = (node != null) &&
221 (node.Sensor.SensorType == SensorType.Temperature) &&
222 plotMenuItem.Checked;
225 private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
229 private void timer_Tick(object sender, EventArgs e) {
236 } catch (Exception exception) {
237 CrashReport.Save(exception);
242 treeView.Invalidate();
243 plotPanel.Invalidate();
244 sensorSystemTray.Redraw();
247 private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
249 Config.Set(plotMenuItem.Name, plotMenuItem.Checked);
250 Config.Set(minMenuItem.Name, minMenuItem.Checked);
251 Config.Set(maxMenuItem.Name, maxMenuItem.Checked);
252 Config.Set(limitMenuItem.Name, limitMenuItem.Checked);
254 Config.Set(startMinMenuItem.Name, startMinMenuItem.Checked);
255 Config.Set(minTrayMenuItem.Name, minTrayMenuItem.Checked);
256 Config.Set(hddMenuItem.Name, hddMenuItem.Checked);
258 Config.Set(voltMenuItem.Name, voltMenuItem.Checked);
259 Config.Set(clocksMenuItem.Name, clocksMenuItem.Checked);
260 Config.Set(loadMenuItem.Name, loadMenuItem.Checked);
261 Config.Set(tempMenuItem.Name, tempMenuItem.Checked);
262 Config.Set(fansMenuItem.Name, fansMenuItem.Checked);
263 Config.Set(flowsMenuItem.Name, flowsMenuItem.Checked);
265 if (WindowState != FormWindowState.Minimized) {
266 Config.Set("mainForm.Location.X", Location.X);
267 Config.Set("mainForm.Location.Y", Location.Y);
268 Config.Set("mainForm.Width", Width);
269 Config.Set("mainForm.Height", Height);
272 sensorSystemTray.Dispose();
273 notifyIcon.Dispose();
277 private void aboutToolStripMenuItem_Click(object sender, EventArgs e) {
278 new AboutBox().ShowDialog();
281 private void plotToolStripMenuItem_CheckedChanged(object sender,
284 splitContainer.Panel2Collapsed = !plotMenuItem.Checked;
285 treeView.Invalidate();
288 private void valueToolStripMenuItem_CheckedChanged(object sender,
291 treeView.Columns[1].IsVisible = valueToolStripMenuItem.Checked;
294 private void minToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
296 treeView.Columns[2].IsVisible = minMenuItem.Checked;
299 private void maxToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
301 treeView.Columns[3].IsVisible = maxMenuItem.Checked;
304 private void limitToolStripMenuItem_CheckedChanged(object sender,
306 treeView.Columns[4].IsVisible = limitMenuItem.Checked;
309 private void treeView_Click(object sender, EventArgs e) {
311 MouseEventArgs m = e as MouseEventArgs;
312 if (m == null || m.Button != MouseButtons.Right)
315 NodeControlInfo info = treeView.GetNodeControlInfoAt(new Point(m.X, m.Y));
316 if (info.Control == null) {
317 columnsContextMenuStrip.Show(treeView, m.X, m.Y);
319 SensorNode node = info.Node.Tag as SensorNode;
320 if (node != null && node.Sensor != null) {
322 sensorContextMenuStrip.Items.Clear();
323 if (sensorSystemTray.Contains(node.Sensor)) {
324 ToolStripMenuItem item = new ToolStripMenuItem("Remove From Tray");
325 item.Click += delegate(object obj, EventArgs args) {
326 sensorSystemTray.Remove(node.Sensor);
328 sensorContextMenuStrip.Items.Add(item);
330 ToolStripMenuItem item = new ToolStripMenuItem("Add To Tray");
331 item.Click += delegate(object obj, EventArgs args) {
332 sensorSystemTray.Add(node.Sensor, true);
334 sensorContextMenuStrip.Items.Add(item);
336 sensorContextMenuStrip.Show(treeView, m.X, m.Y);
341 private void saveReportToolStripMenuItem_Click(object sender, EventArgs e) {
342 computer.SaveReport(new Version(Application.ProductVersion));
345 private void hddsensorsToolStripMenuItem_CheckedChanged(object sender,
348 computer.HDDEnabled = hddMenuItem.Checked;
349 UpdateSensorTypeChecked(null, null);
350 UpdatePlotSelection(null, null);
353 private void UpdateSensorTypeChecked(object sender, EventArgs e) {
354 foreach (HardwareNode node in root.Nodes) {
355 node.SetVisible(SensorType.Voltage, voltMenuItem.Checked);
356 node.SetVisible(SensorType.Clock, clocksMenuItem.Checked);
357 node.SetVisible(SensorType.Load, loadMenuItem.Checked);
358 node.SetVisible(SensorType.Temperature, tempMenuItem.Checked);
359 node.SetVisible(SensorType.Fan, fansMenuItem.Checked);
360 node.SetVisible(SensorType.Flow, flowsMenuItem.Checked);
364 private void ToggleSysTray() {
365 if (notifyIcon.Visible) {
367 notifyIcon.Visible = false;
370 notifyIcon.Visible = true;
375 protected override void WndProc(ref Message m) {
376 const int WM_SYSCOMMAND = 0x112;
377 const int SC_MINIMIZE = 0xF020;
378 if (minTrayMenuItem.Checked &&
379 m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_MINIMIZE) {
386 private void restoreClick(object sender, EventArgs e) {
390 private void removeToolStripMenuItem_Click(object sender, EventArgs e) {
391 ToolStripMenuItem item = sender as ToolStripMenuItem;
395 ISensor sensor = item.Owner.Tag as ISensor;
399 sensorSystemTray.Remove(sensor);