summaryrefslogtreecommitdiffstats
path: root/ksysguard/gui/SensorDisplayLib/SensorDisplay.h
blob: 72f1af5430f48287ec869bc2d37d121b74fdbe08 (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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/*
    KSysGuard, the KDE System Guard
   
    Copyright (c) 1999 - 2001 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_SENSORDISPLAY_H
#define KSG_SENSORDISPLAY_H

#include <tqgroupbox.h>
#include <tqlabel.h>
#include <tqvaluelist.h>
#include <tqwidget.h>

#include <knotifyclient.h>

#include <ksgrd/SensorClient.h>

#define NONE -1

class QDomDocument;
class QDomElement;

namespace KSGRD {

class SensorProperties;

/**
  This class is the base class for all displays for sensors. A
  display is any kind of widget that can display the value of one or
  more sensors in any form. It must be inherited by all displays that
  should be inserted into the work sheet.
 */
class SensorDisplay : public TQWidget, public SensorClient
{
  Q_OBJECT

  public:
    /**
      Constructor.
     */
    SensorDisplay( TQWidget *parent = 0, const char *name = 0, 
                   const TQString& title = 0, bool nf = false, bool isApplet = false );

    /**
      Destructor.
     */
    virtual ~SensorDisplay();

    /**
      Sets the title of the display.
     */
    void setTitle( const TQString &title );

    /**
      Returns the title of the display.
     */
    TQString title() const;

    /**
      Sets the unit of the display.
     */
    void setUnit( const TQString &unit );

    /**
      Returns the unit of the display.
     */
    TQString unit() const;

    /**
      Sets whether the unit string should be displayed at the top
      of the display frame.
     */
    void setShowUnit( bool value );

    /**
      Returns whether the unit string should be displayed at the top
      of the display frame. @see setShowUnit()
     */
    bool showUnit() const;

    /**
      Sets whether the update interval of the work sheet should be
      used instead of the one, set by @ref setUpdateInterval().
     */
    void setUseGlobalUpdateInterval( bool value );

    /**
      Returns whether the update interval of the work sheet should be
      used instead of the one, set by @ref setUpdateInterval().
      see @ref setUseGlobalUpdateInterval()
     */
    bool useGlobalUpdateInterval() const;

    /**
      Sets the update interval of the timer, which triggers the timer
      events. The state of the timer can be set with @ref setTimerOn().
     */
    void setUpdateInterval( uint interval );

    /**
      Returns the update interval.
     */
    uint updateInterval() const;

    /**
      This method appends all hosts of the display to @ref list.
     */
    void hosts( TQStringList& list );

    /**
      Sets the widget on which the error icon can be drawn.
     */
    void setPlotterWidget( TQWidget *plotter );

    /**
      Returns the widget on which the error icon can be drawn.
     */
    TQWidget *plotterWidget() const;

    /**
      Add a sensor to the display.
      
      @param hostName The name of the host, the sensor belongs to.
      @param name The sensor name.
      @param type The type of the sensor.
      @param description A short description of the sensor.
     */
    virtual bool addSensor( const TQString &hostName, const TQString &name,
                            const TQString &type, const TQString &description );

    /**
      Removes the sensor from the display, that is at the position
      @ref pos of the intern sensor list.
     */
    virtual bool removeSensor( uint pos );

    /**
      This function is a wrapper function to SensorManager::sendRequest.
      It should be used by all SensorDisplay functions that need to send
      a request to a sensor since it performs an appropriate error
      handling by removing the display of necessary.
     */
    void sendRequest( const TQString &hostName, const TQString &cmd, int id );

    /**
      Raises the configure dialog to setup the update interval.
     */
    void configureUpdateInterval();

    /**
      Returns whether the display provides a settings dialog.
      This method should be reimplemented in the derived class.
     */
    virtual bool hasSettingsDialog() const;

    /**
      This method is called to raise the settings dialog of the
      display. It should be reimplemented in the derived class.
     */
    virtual void configureSettings();

    /**
      Reimplement this method to setup the display from config data.
     */
    virtual bool restoreSettings( TQDomElement& );

    /**
      Reimplement this method to save the displays config data.
     */
    virtual bool saveSettings( TQDomDocument&, TQDomElement&, bool = true );

    /**
      Reimplement this method to catch error messages from the SensorManager.
      
      @param sensorId The unique id of the sensor.
      @param mode The mode: true = error, false = everthing ok
     */
    virtual void sensorError( int sensorId, bool mode );

    /**
      Normaly you shouldn't reimplement this methode
     */
    virtual void sensorLost( int reqId );

  public slots:
    /**
      If @ref value is true, this method starts the timer that triggers
      timer events. If @ref value is false, the timer is stopped.
     */
    void setTimerOn( bool value );

    /**
      Calling this method emits the @ref showPopupMenu() with this
      display as argument.
     */
    void rmbPressed();

    /**
      Sets whether the display is modified of not.
     */
    void setModified( bool modified );
    
    /**
      This method can be used to apply the new settings. Just connect
      the applyClicked() signal of your configuration dialog with this
      slot and reimplement it.
     */
    virtual void applySettings();

    /**
      This methid is called whenever the global style is changed.
      Reimplement it to apply the new style settings to the display.
     */
    virtual void applyStyle();

		
  signals:
    void showPopupMenu( KSGRD::SensorDisplay *display );
    void modified( bool modified );

  protected:
    virtual bool eventFilter( TQObject*, TQEvent* );
    virtual void resizeEvent( TQResizeEvent* );
    virtual void timerEvent( TQTimerEvent* );

    void registerSensor( SensorProperties *sp );
    void unregisterSensor( uint pos );

    TQColor restoreColor( TQDomElement &element, const TQString &attr,
                         const TQColor& fallback );
    void saveColor( TQDomElement &element, const TQString &attr,
                    const TQColor &color );

    virtual TQString additionalWhatsThis();

    void setSensorOk( bool ok );

    bool modified() const;
    bool timerOn() const;

    TQWidget *frame();

//    void setNoFrame( bool value );
    bool noFrame() const;

    void reorderSensors(const TQValueList<int> &orderOfSensors);
    TQPtrList<SensorProperties> &sensors();

  private:
    void updateWhatsThis();

    bool mShowUnit;
    bool mUseGlobalUpdateInterval;
    bool mModified;
    bool mNoFrame;
    bool mIsApplet;

    int mTimerId;
    int mUpdateInterval;

    // The frame around the other widgets.
    TQGroupBox* mFrame;

    TQPtrList<SensorProperties> mSensors;

    TQString mTitle;
    TQString mUnit;

    TQWidget* mErrorIndicator;
    TQWidget* mPlotterWdg;
};

class SensorProperties
{
  public:
    SensorProperties();
    SensorProperties( const TQString &hostName, const TQString &name,
                      const TQString &type, const TQString &description );
    ~SensorProperties();

    void setHostName( const TQString &hostName );
    TQString hostName() const;

    void setName( const TQString &name );
    TQString name() const;

    void setType( const TQString &type );
    TQString type() const;

    void setDescription( const TQString &description );
    TQString description() const;

    void setUnit( const TQString &unit );
    TQString unit() const;

    void setIsOk( bool value );
    bool isOk() const;

  private:
    TQString mHostName;
    TQString mName;
    TQString mType;
    TQString mDescription;
    TQString mUnit;

    /* This flag indicates whether the communication to the sensor is
     * ok or not. */
    bool mOk;
};

}

#endif