2 KSysGuard, the KDE System Guard
4 Copyright (c) 1999, 2000 Chris Schlaeger <cs@kde.org>
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public
8 License version 2 or at your option version 3 as published by
9 the Free Software Foundation.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #ifndef KSG_SENSORBROWSER_H
23 #define KSG_SENSORBROWSER_H
25 #include <QMouseEvent>
26 #include <QTreeWidget>
29 #include <ksgrd/SensorClient.h>
42 class SensorBrowserModel
: public QAbstractItemModel
, private KSGRD::SensorClient
47 ~SensorBrowserModel();
48 virtual int columnCount( const QModelIndex
&) const;
49 virtual QVariant
data( const QModelIndex
& parent
, int role
) const;
50 virtual QVariant
headerData ( int section
, Qt::Orientation orientation
, int role
) const;
51 virtual QModelIndex
index ( int row
, int column
, const QModelIndex
& parent
) const;
52 virtual QModelIndex
parent ( const QModelIndex
& index
) const;
53 virtual int rowCount ( const QModelIndex
& parent
= QModelIndex() ) const;
56 QStringList
listSensors( const QString
&hostName
) const; ///Returns a list of sensors names. E.g. (cpu/0, mem/free, mem/cache, etc)
57 QStringList
listSensors( int parentId
) const; ///Used recursively by listSensor(QString)
58 QStringList
listHosts( ) const; ///Returns a list of host names. E.g. (localhost, 192.168.0.1,...)
59 SensorInfo
*getSensorInfo(QModelIndex index
) const;
60 HostInfo
*getHostInfo(int hostId
) const { return mHostInfoMap
.value(hostId
);}
61 bool hasSensor(int hostId
, const QString
&sensor
) const { return mHostSensorsMap
.value(hostId
).contains(sensor
);}
62 int makeTreeBranch(int parentId
, const QString
&name
);
63 int makeSensor(HostInfo
*hostInfo
, int parentId
, const QString
&sensorName
, const QString
&name
, const QString
&sensorType
);
64 void removeSensor(HostInfo
*hostInfo
, int parentId
, const QString
&sensorName
);
65 void addHost(KSGRD::SensorAgent
*sensorAgent
, const QString
&hostName
);
67 void disconnectHost(uint id
);
68 void disconnectHost(const HostInfo
*hostInfo
);
69 void disconnectHost(const QString
&hostname
);
70 virtual Qt::ItemFlags
flags ( const QModelIndex
& index
) const;
71 virtual QMimeData
* mimeData ( const QModelIndexList
& indexes
) const;
72 void retranslate(); /// Retranslate the model
74 void sensorsAddedToHost(const QModelIndex
&index
);
79 virtual void answerReceived( int id
, const QList
<QByteArray
>& );
80 void removeEmptyParentTreeBranches(int hostId
, int id
, int parentid
);
82 int mIdCount
; ///The lowest id that has not been used yet
83 QMap
<int, HostInfo
*> mHostInfoMap
; ///So each host has a number
84 QHash
<int, QList
<int> > mTreeMap
; ///This describes the structure of the tree. It maps a parent branch number (which can be equal to the hostinfo number if it's a host branch) to a list of children. The children themselves either have branches in the map, or else just relate to a sensor info
85 QHash
<int, int > mParentsTreeMap
; ///
86 QHash
<int, QString
> mTreeNodeNames
; ///Maps the mTreeMap node id's to (translated) names
87 QHash
<int, QHash
<QString
,bool> > mHostSensorsMap
; ///Maps a host id to a hash of sensor names. Let's us quickly check if a sensor is registered for a given host. bool is just ignored
88 QHash
<int, SensorInfo
*> mSensorInfoMap
; ///Each sensor has a unique number as well. This relates to the ID in mTreeMap
93 * The SensorBrowserWidget is the graphical front-end of the SensorManager. It
94 * displays the currently available hosts and their sensors.
96 class SensorBrowserWidget
: public QTreeView
101 SensorBrowserWidget( QWidget
* parent
, KSGRD::SensorManager
* sm
);
102 ~SensorBrowserWidget();
104 QStringList
listHosts() const
105 { return mSensorBrowserModel
.listHosts(); }
106 QStringList
listSensors( const QString
&hostName
) const
107 { return mSensorBrowserModel
.listSensors(hostName
); }
111 void hostReconfigured( const QString
&hostName
);
114 void retranslateUi();
115 void changeEvent( QEvent
* event
);
117 KSGRD::SensorManager
* mSensorManager
;
120 SensorBrowserModel mSensorBrowserModel
;
126 SensorInfo( HostInfo
*hostInfo
, const QString
&name
,
127 const QString
&description
, const QString
&type
);
130 Returns the name of the sensor. e.g. "cpu/free". Not translated.
132 QString
name() const;
135 Returns the description of the sensor. e.g. "free"
137 QString
description() const;
140 Returns the type of the sensor. e.g. "Integer"
142 QString
type() const;
145 Returns the host that this sensor is on.
147 HostInfo
*hostInfo() const;
159 HostInfo( int id
, KSGRD::SensorAgent
*agent
, const QString
&name
) : mId(id
), mSensorAgent(agent
), mHostName(name
) {}
162 Returns the unique id of the host.
164 int id() const {return mId
;}
167 Returns a pointer to the sensor agent of the host.
169 KSGRD::SensorAgent
* sensorAgent() const {return mSensorAgent
;}
172 Returns the name of the host.
174 QString
hostName() const { return mHostName
;}
178 KSGRD::SensorAgent
* mSensorAgent
;
179 const QString mHostName
;