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>
30
#include "ksortfilterproxymodel.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 );
77
void hostAdded(KSGRD::SensorAgent *sensorAgent, const QString &hostName);
79
* Remove host from this model. The proper way this is called is with the signal in SensorManager
80
* (from disengage), otherwise
81
* if this is called directly the SensorManager container will be out of sync with ours. Calling disconnectHost
82
* from this object will also call disengage.
84
void hostRemoved(const QString &hostName);
87
virtual void answerReceived( int id, const QList<QByteArray>& );
88
void removeEmptyParentTreeBranches(int hostId, int id, int parentid);
89
HostInfo* findHostInfoByHostName(const QString &hostName) const;
90
void removeAllSensorUnderBranch(HostInfo* hostInfo, int parentId);
92
int mIdCount; ///The lowest id that has not been used yet
93
QMap<int, HostInfo*> mHostInfoMap; ///So each host has a number
94
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
95
QHash<int, int > mParentsTreeMap; ///
96
QHash<int, QString> mTreeNodeNames; ///Maps the mTreeMap node id's to (translated) names
97
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
98
QHash<int, SensorInfo *> mSensorInfoMap; ///Each sensor has a unique number as well. This relates to the ID in mTreeMap
101
class SensorBrowserTreeWidget : public QTreeView
106
SensorBrowserTreeWidget( QWidget* parent, KSGRD::SensorManager* sm );
107
~SensorBrowserTreeWidget();
109
QStringList listHosts() const
110
{ return mSensorBrowserModel.listHosts(); }
111
QStringList listSensors( const QString &hostName ) const
112
{ return mSensorBrowserModel.listSensors(hostName); }
113
KSortFilterProxyModel & model()
114
{ return mSortFilterProxyModel; }
118
void hostReconfigured( const QString &hostName );
120
void expandItem(const QModelIndex& model_index);
123
void retranslateUi();
124
void changeEvent( QEvent * event );
126
KSGRD::SensorManager* mSensorManager;
129
SensorBrowserModel mSensorBrowserModel;
130
KSortFilterProxyModel mSortFilterProxyModel;
134
* The SensorBrowserWidget is the graphical front-end of the SensorManager. It
135
* displays the currently available hosts and their sensors.
137
class SensorBrowserWidget : public QWidget
141
SensorBrowserWidget( QWidget* parent, KSGRD::SensorManager* sm );
142
~SensorBrowserWidget();
143
QStringList listHosts() const
144
{ return m_treeWidget->listHosts(); }
145
QStringList listSensors( const QString &hostName ) const
146
{ return m_treeWidget->listSensors(hostName); }
149
SensorBrowserTreeWidget *m_treeWidget;
156
SensorInfo( HostInfo *hostInfo, const QString &name,
157
const QString &description, const QString &type );
160
Returns the name of the sensor. e.g. "cpu/free". Not translated.
162
QString name() const;
165
Returns the description of the sensor. e.g. "free"
167
QString description() const;
170
Returns the type of the sensor. e.g. "Integer"
172
QString type() const;
175
Returns the host that this sensor is on.
177
HostInfo *hostInfo() const;
189
HostInfo( int id, KSGRD::SensorAgent *agent, const QString &name) : mId(id), mSensorAgent(agent), mHostName(name) {}
192
Returns the unique id of the host.
194
int id() const {return mId;}
197
Returns a pointer to the sensor agent of the host.
199
KSGRD::SensorAgent* sensorAgent() const {return mSensorAgent;}
202
Returns the name of the host.
204
QString hostName() const { return mHostName;}
208
KSGRD::SensorAgent* mSensorAgent;
209
const QString mHostName;