1.1 --- a/GUI/SensorSystemTray.cs Sat Jun 05 11:15:16 2010 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,134 +0,0 @@
1.4 -/*
1.5 -
1.6 - Version: MPL 1.1/GPL 2.0/LGPL 2.1
1.7 -
1.8 - The contents of this file are subject to the Mozilla Public License Version
1.9 - 1.1 (the "License"); you may not use this file except in compliance with
1.10 - the License. You may obtain a copy of the License at
1.11 -
1.12 - http://www.mozilla.org/MPL/
1.13 -
1.14 - Software distributed under the License is distributed on an "AS IS" basis,
1.15 - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
1.16 - for the specific language governing rights and limitations under the License.
1.17 -
1.18 - The Original Code is the Open Hardware Monitor code.
1.19 -
1.20 - The Initial Developer of the Original Code is
1.21 - Michael Möller <m.moeller@gmx.ch>.
1.22 - Portions created by the Initial Developer are Copyright (C) 2009-2010
1.23 - the Initial Developer. All Rights Reserved.
1.24 -
1.25 - Contributor(s):
1.26 -
1.27 - Alternatively, the contents of this file may be used under the terms of
1.28 - either the GNU General Public License Version 2 or later (the "GPL"), or
1.29 - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
1.30 - in which case the provisions of the GPL or the LGPL are applicable instead
1.31 - of those above. If you wish to allow use of your version of this file only
1.32 - under the terms of either the GPL or the LGPL, and not to allow others to
1.33 - use your version of this file under the terms of the MPL, indicate your
1.34 - decision by deleting the provisions above and replace them with the notice
1.35 - and other provisions required by the GPL or the LGPL. If you do not delete
1.36 - the provisions above, a recipient may use your version of this file under
1.37 - the terms of any one of the MPL, the GPL or the LGPL.
1.38 -
1.39 -*/
1.40 -
1.41 -using System;
1.42 -using System.Collections.Generic;
1.43 -using System.Drawing;
1.44 -using System.Text;
1.45 -using System.Windows.Forms;
1.46 -using OpenHardwareMonitor.Hardware;
1.47 -using OpenHardwareMonitor.Utilities;
1.48 -
1.49 -namespace OpenHardwareMonitor.GUI {
1.50 - public class SensorSystemTray : IDisposable {
1.51 - private IComputer computer;
1.52 - private List<SensorNotifyIcon> list = new List<SensorNotifyIcon>();
1.53 -
1.54 - public SensorSystemTray(IComputer computer) {
1.55 - this.computer = computer;
1.56 - computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
1.57 - computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
1.58 - }
1.59 -
1.60 - private void HardwareRemoved(IHardware hardware) {
1.61 - hardware.SensorAdded -= new SensorEventHandler(SensorAdded);
1.62 - hardware.SensorRemoved -= new SensorEventHandler(SensorRemoved);
1.63 - foreach (ISensor sensor in hardware.Sensors)
1.64 - SensorRemoved(sensor);
1.65 - foreach (IHardware subHardware in hardware.SubHardware)
1.66 - HardwareRemoved(subHardware);
1.67 - }
1.68 -
1.69 - private void HardwareAdded(IHardware hardware) {
1.70 - foreach (ISensor sensor in hardware.Sensors)
1.71 - SensorAdded(sensor);
1.72 - hardware.SensorAdded += new SensorEventHandler(SensorAdded);
1.73 - hardware.SensorRemoved += new SensorEventHandler(SensorRemoved);
1.74 - foreach (IHardware subHardware in hardware.SubHardware)
1.75 - HardwareAdded(subHardware);
1.76 - }
1.77 -
1.78 - private void SensorAdded(ISensor sensor) {
1.79 - if (Config.Get(new Identifier(sensor.Identifier,
1.80 - "tray").ToString(), false))
1.81 - Add(sensor, false);
1.82 - }
1.83 -
1.84 - private void SensorRemoved(ISensor sensor) {
1.85 - if (Contains(sensor))
1.86 - Remove(sensor, false);
1.87 - }
1.88 -
1.89 - public void Dispose() {
1.90 - foreach (SensorNotifyIcon icon in list)
1.91 - icon.Dispose();
1.92 - }
1.93 -
1.94 - public void Redraw() {
1.95 - foreach (SensorNotifyIcon icon in list)
1.96 - icon.Update();
1.97 - }
1.98 -
1.99 - public bool Contains(ISensor sensor) {
1.100 - foreach (SensorNotifyIcon icon in list)
1.101 - if (icon.Sensor == sensor)
1.102 - return true;
1.103 - return false;
1.104 - }
1.105 -
1.106 - public void Add(ISensor sensor, bool balloonTip) {
1.107 - if (Contains(sensor)) {
1.108 - return;
1.109 - } else {
1.110 - list.Add(new SensorNotifyIcon(this, sensor, balloonTip));
1.111 - Config.Set(new Identifier(sensor.Identifier, "tray").ToString(), true);
1.112 - }
1.113 - }
1.114 -
1.115 - public void Remove(ISensor sensor) {
1.116 - Remove(sensor, true);
1.117 - }
1.118 -
1.119 - private void Remove(ISensor sensor, bool deleteConfig) {
1.120 - if (deleteConfig) {
1.121 - Config.Remove(
1.122 - new Identifier(sensor.Identifier, "tray").ToString());
1.123 - Config.Remove(
1.124 - new Identifier(sensor.Identifier, "traycolor").ToString());
1.125 - }
1.126 - SensorNotifyIcon instance = null;
1.127 - foreach (SensorNotifyIcon icon in list)
1.128 - if (icon.Sensor == sensor)
1.129 - instance = icon;
1.130 - if (instance != null) {
1.131 - list.Remove(instance);
1.132 - instance.Dispose();
1.133 - }
1.134 - }
1.135 -
1.136 - }
1.137 -}