summaryrefslogtreecommitdiffstats
path: root/ksysguard/gui/SensorBrowser.h
blob: 9021166d9ce7409609f1bcc9c55c34900f3f2542 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
    KSysGuard, the KDE System Guard
   
    Copyright (c) 1999, 2000 Chris Schlaeger <cs@kde.org>
    
    This program is free software; you can redistribute it and/or
    modify it under the terms of version 2 of the GNU General Public
    License as published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

    KSysGuard is currently maintained by Chris Schlaeger <cs@kde.org>. Please do
    not commit any changes without consulting me first. Thanks!

*/

#ifndef KSG_SENSORBROWSER_H
#define KSG_SENSORBROWSER_H

#include <qdict.h>

#include <klistview.h>
#include <ksgrd/SensorClient.h>

class QMouseEvent;

namespace KSGRD {
class SensorManager;
class SensorAgent;
}

class SensorInfo;
class HostInfo;

/**
 * The SensorBrowser is the graphical front-end of the SensorManager. It
 * displays the currently available hosts and their sensors.
 */
class SensorBrowser : public KListView, public KSGRD::SensorClient
{
  Q_OBJECT

  public:
    SensorBrowser( QWidget* parent, KSGRD::SensorManager* sm, const char* name = 0 );
    ~SensorBrowser();

    QStringList listHosts();
    QStringList listSensors( const QString &hostName );

  public slots:
    void disconnect();
    void hostReconfigured( const QString &hostName );
    void update();
    void newItemSelected( QListViewItem *item );

  protected:
    virtual void viewportMouseMoveEvent( QMouseEvent* );

  private:
    void answerReceived( int id, const QString& );

    KSGRD::SensorManager* mSensorManager;

    QPtrList<HostInfo> mHostInfoList;
    QString mDragText;

};

/**
 Helper classes
 */
class SensorInfo
{
  public:
    SensorInfo( QListViewItem *lvi, const QString &name, const QString &desc,
                const QString &type );
    ~SensorInfo() {}

    /**
      Returns a pointer to the list view item of the sensor.
     */
    QListViewItem* listViewItem() const;

    /**
      Returns the name of the sensor.
     */
    const QString& name() const;

    /**
      Returns the description of the sensor.
     */
    const QString& description() const;

    /**
      Returns the type of the sensor.
     */
    const QString& type() const;

  private:
    QListViewItem* mLvi;
    QString mName;
    QString mDesc;
    QString mType;
};

class HostInfo
{
  public:
    HostInfo( int id, const KSGRD::SensorAgent *agent, const QString &name,
              QListViewItem *lvi );
    ~HostInfo() { }

    /**
      Returns the unique id of the host.
     */
    int id() const;

    /**
      Returns a pointer to the sensor agent of the host.
     */
    const KSGRD::SensorAgent* sensorAgent() const;

    /**
      Returns the name of the host.
     */
    const QString& hostName() const;

    /**
      Returns the a pointer to the list view item of the host.
     */
    QListViewItem* listViewItem() const;

    /**
      Returns the sensor name of a special list view item.
     */
    const QString& sensorName( const QListViewItem *lvi ) const;

    /**
      Returns all sensor names of the host.
     */
    QStringList allSensorNames() const;

    /**
      Returns the type of a special list view item.
     */
    const QString& sensorType( const QListViewItem *lvi ) const;

    /**
      Returns the description of a special list view item.
     */
    const QString& sensorDescription( const QListViewItem *lvi ) const;

    /**
      Adds a new Sensor to the host.
      
      @param lvi  The list view item.
      @param name The sensor name.
      @param desc A description.
      @param type The type of the sensor.
     */
    void addSensor( QListViewItem *lvi, const QString& name,
                    const QString& desc, const QString& type );

    /**
      Returns whether the sensor with @ref name
      is registered at the host.
     */
    bool isRegistered( const QString& name ) const;

    /**
      Returns whether the sensor with @ref lvi
      is registered at the host.
     */
    bool isRegistered( QListViewItem *lvi ) const;

  private:
    int mId;

    const KSGRD::SensorAgent* mSensorAgent;
    const QString mHostName;
    QListViewItem* mLvi;

    QPtrList<SensorInfo> mSensorList;
};

#endif