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>.
|
2012-02-14 23:07:55 +00:00
|
|
|
|
Portions created by the Initial Developer are Copyright (C) 2009-2012
|
2010-01-26 22:37:48 +00:00
|
|
|
|
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.Drawing;
|
|
|
|
|
using OpenHardwareMonitor.Hardware;
|
|
|
|
|
|
|
|
|
|
namespace OpenHardwareMonitor.GUI {
|
|
|
|
|
public class HardwareNode : Node {
|
|
|
|
|
|
2010-08-08 13:57:26 +00:00
|
|
|
|
private PersistentSettings settings;
|
|
|
|
|
private UnitManager unitManager;
|
2010-01-26 22:37:48 +00:00
|
|
|
|
private IHardware hardware;
|
|
|
|
|
|
|
|
|
|
private List<TypeNode> typeNodes = new List<TypeNode>();
|
|
|
|
|
|
2010-08-08 13:57:26 +00:00
|
|
|
|
public HardwareNode(IHardware hardware, PersistentSettings settings,
|
2011-04-30 16:03:58 +00:00
|
|
|
|
UnitManager unitManager) : base()
|
2010-08-08 13:57:26 +00:00
|
|
|
|
{
|
|
|
|
|
this.settings = settings;
|
|
|
|
|
this.unitManager = unitManager;
|
2010-01-26 22:37:48 +00:00
|
|
|
|
this.hardware = hardware;
|
2010-09-06 19:53:13 +00:00
|
|
|
|
this.Image = HardwareTypeImage.Instance.GetImage(hardware.HardwareType);
|
2010-01-26 22:37:48 +00:00
|
|
|
|
|
2012-02-14 23:07:55 +00:00
|
|
|
|
foreach (SensorType sensorType in Enum.GetValues(typeof(SensorType)))
|
|
|
|
|
typeNodes.Add(new TypeNode(sensorType));
|
2011-07-27 18:27:16 +00:00
|
|
|
|
|
2010-01-26 22:37:48 +00:00
|
|
|
|
foreach (ISensor sensor in hardware.Sensors)
|
|
|
|
|
SensorAdded(sensor);
|
|
|
|
|
|
|
|
|
|
hardware.SensorAdded +=new SensorEventHandler(SensorAdded);
|
|
|
|
|
hardware.SensorRemoved += new SensorEventHandler(SensorRemoved);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-30 16:03:58 +00:00
|
|
|
|
public override string Text {
|
|
|
|
|
get { return hardware.Name; }
|
|
|
|
|
set { hardware.Name = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-26 22:37:48 +00:00
|
|
|
|
public IHardware Hardware {
|
|
|
|
|
get { return hardware; }
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-14 22:30:06 +00:00
|
|
|
|
private void UpdateNode(TypeNode node) {
|
|
|
|
|
if (node.Nodes.Count > 0) {
|
2010-01-26 22:37:48 +00:00
|
|
|
|
if (!Nodes.Contains(node)) {
|
|
|
|
|
int i = 0;
|
|
|
|
|
while (i < Nodes.Count &&
|
|
|
|
|
((TypeNode)Nodes[i]).SensorType < node.SensorType)
|
|
|
|
|
i++;
|
|
|
|
|
Nodes.Insert(i, node);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (Nodes.Contains(node))
|
|
|
|
|
Nodes.Remove(node);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SensorRemoved(ISensor sensor) {
|
2010-05-14 22:30:06 +00:00
|
|
|
|
foreach (TypeNode typeNode in typeNodes)
|
|
|
|
|
if (typeNode.SensorType == sensor.SensorType) {
|
|
|
|
|
SensorNode sensorNode = null;
|
|
|
|
|
foreach (Node node in typeNode.Nodes) {
|
|
|
|
|
SensorNode n = node as SensorNode;
|
|
|
|
|
if (n != null && n.Sensor == sensor)
|
|
|
|
|
sensorNode = n;
|
|
|
|
|
}
|
2012-01-01 17:12:34 +00:00
|
|
|
|
if (sensorNode != null) {
|
|
|
|
|
sensorNode.PlotSelectionChanged -= SensorPlotSelectionChanged;
|
|
|
|
|
typeNode.Nodes.Remove(sensorNode);
|
|
|
|
|
UpdateNode(typeNode);
|
|
|
|
|
}
|
2010-01-26 22:37:48 +00:00
|
|
|
|
}
|
2012-01-01 17:12:34 +00:00
|
|
|
|
if (PlotSelectionChanged != null)
|
|
|
|
|
PlotSelectionChanged(this, null);
|
2010-01-26 22:37:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InsertSorted(Node node, ISensor sensor) {
|
|
|
|
|
int i = 0;
|
|
|
|
|
while (i < node.Nodes.Count &&
|
|
|
|
|
((SensorNode)node.Nodes[i]).Sensor.Index < sensor.Index)
|
|
|
|
|
i++;
|
2010-08-08 13:57:26 +00:00
|
|
|
|
SensorNode sensorNode = new SensorNode(sensor, settings, unitManager);
|
2012-01-01 17:12:34 +00:00
|
|
|
|
sensorNode.PlotSelectionChanged += SensorPlotSelectionChanged;
|
2010-05-14 22:30:06 +00:00
|
|
|
|
node.Nodes.Insert(i, sensorNode);
|
2010-01-26 22:37:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-01 17:12:34 +00:00
|
|
|
|
private void SensorPlotSelectionChanged(object sender, EventArgs e) {
|
|
|
|
|
if (PlotSelectionChanged != null)
|
|
|
|
|
PlotSelectionChanged(this, null);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-26 22:37:48 +00:00
|
|
|
|
private void SensorAdded(ISensor sensor) {
|
2010-05-14 22:30:06 +00:00
|
|
|
|
foreach (TypeNode typeNode in typeNodes)
|
|
|
|
|
if (typeNode.SensorType == sensor.SensorType) {
|
|
|
|
|
InsertSorted(typeNode, sensor);
|
|
|
|
|
UpdateNode(typeNode);
|
2010-01-26 22:37:48 +00:00
|
|
|
|
}
|
2012-01-01 17:12:34 +00:00
|
|
|
|
if (PlotSelectionChanged != null)
|
|
|
|
|
PlotSelectionChanged(this, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public event EventHandler PlotSelectionChanged;
|
2010-01-26 22:37:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|