~ubuntu-branches/ubuntu/lucid/kdebase/lucid

« back to all changes in this revision

Viewing changes to ksysguard/gui/SensorDisplayLib/SensorDisplay.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-27 12:09:48 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20080527120948-dottsyd5rcwhzd36
Tags: 4:4.0.80-1ubuntu1
* Merge with Debian
 - remove 97_fix_target_link_libraries.diff
 - Add replaces/conflicts on -kde4 packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    KSysGuard, the KDE System Guard
3
 
   
4
 
    Copyright (c) 1999 - 2001 Chris Schlaeger <cs@kde.org>
5
 
    
6
 
    This program is free software; you can redistribute it and/or
7
 
    modify it under the terms of version 2 of the GNU General Public
8
 
    License as published by the Free Software Foundation.
9
 
 
10
 
    This program is distributed in the hope that it will be useful,
11
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
    GNU General Public License for more details.
14
 
 
15
 
    You should have received a copy of the GNU General Public License
16
 
    along with this program; if not, write to the Free Software
17
 
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
 
 
19
 
    KSysGuard is currently maintained by Chris Schlaeger <cs@kde.org>.
20
 
    Please do not commit any changes without consulting me first. Thanks!
21
 
 
22
 
*/
23
 
 
24
 
#ifndef KSG_SENSORDISPLAY_H
25
 
#define KSG_SENSORDISPLAY_H
26
 
 
27
 
#include <qgroupbox.h>
28
 
#include <qlabel.h>
29
 
#include <qvaluelist.h>
30
 
#include <qwidget.h>
31
 
 
32
 
#include <knotifyclient.h>
33
 
 
34
 
#include <ksgrd/SensorClient.h>
35
 
 
36
 
#define NONE -1
37
 
 
38
 
class QDomDocument;
39
 
class QDomElement;
40
 
 
41
 
namespace KSGRD {
42
 
 
43
 
class SensorProperties;
44
 
 
45
 
/**
46
 
  This class is the base class for all displays for sensors. A
47
 
  display is any kind of widget that can display the value of one or
48
 
  more sensors in any form. It must be inherited by all displays that
49
 
  should be inserted into the work sheet.
50
 
 */
51
 
class SensorDisplay : public QWidget, public SensorClient
52
 
{
53
 
  Q_OBJECT
54
 
 
55
 
  public:
56
 
    /**
57
 
      Constructor.
58
 
     */
59
 
    SensorDisplay( QWidget *parent = 0, const char *name = 0, 
60
 
                   const QString& title = 0, bool nf = false, bool isApplet = false );
61
 
 
62
 
    /**
63
 
      Destructor.
64
 
     */
65
 
    virtual ~SensorDisplay();
66
 
 
67
 
    /**
68
 
      Sets the title of the display.
69
 
     */
70
 
    void setTitle( const QString &title );
71
 
 
72
 
    /**
73
 
      Returns the title of the display.
74
 
     */
75
 
    QString title() const;
76
 
 
77
 
    /**
78
 
      Sets the unit of the display.
79
 
     */
80
 
    void setUnit( const QString &unit );
81
 
 
82
 
    /**
83
 
      Returns the unit of the display.
84
 
     */
85
 
    QString unit() const;
86
 
 
87
 
    /**
88
 
      Sets whether the unit string should be displayed at the top
89
 
      of the display frame.
90
 
     */
91
 
    void setShowUnit( bool value );
92
 
 
93
 
    /**
94
 
      Returns whether the unit string should be displayed at the top
95
 
      of the display frame. @see setShowUnit()
96
 
     */
97
 
    bool showUnit() const;
98
 
 
99
 
    /**
100
 
      Sets whether the update interval of the work sheet should be
101
 
      used instead of the one, set by @ref setUpdateInterval().
102
 
     */
103
 
    void setUseGlobalUpdateInterval( bool value );
104
 
 
105
 
    /**
106
 
      Returns whether the update interval of the work sheet should be
107
 
      used instead of the one, set by @ref setUpdateInterval().
108
 
      see @ref setUseGlobalUpdateInterval()
109
 
     */
110
 
    bool useGlobalUpdateInterval() const;
111
 
 
112
 
    /**
113
 
      Sets the update interval of the timer, which triggers the timer
114
 
      events. The state of the timer can be set with @ref setTimerOn().
115
 
     */
116
 
    void setUpdateInterval( uint interval );
117
 
 
118
 
    /**
119
 
      Returns the update interval.
120
 
     */
121
 
    uint updateInterval() const;
122
 
 
123
 
    /**
124
 
      This method appends all hosts of the display to @ref list.
125
 
     */
126
 
    void hosts( QStringList& list );
127
 
 
128
 
    /**
129
 
      Sets the widget on which the error icon can be drawn.
130
 
     */
131
 
    void setPlotterWidget( QWidget *plotter );
132
 
 
133
 
    /**
134
 
      Returns the widget on which the error icon can be drawn.
135
 
     */
136
 
    QWidget *plotterWidget() const;
137
 
 
138
 
    /**
139
 
      Add a sensor to the display.
140
 
      
141
 
      @param hostName The name of the host, the sensor belongs to.
142
 
      @param name The sensor name.
143
 
      @param type The type of the sensor.
144
 
      @param description A short description of the sensor.
145
 
     */
146
 
    virtual bool addSensor( const QString &hostName, const QString &name,
147
 
                            const QString &type, const QString &description );
148
 
 
149
 
    /**
150
 
      Removes the sensor from the display, that is at the position
151
 
      @ref pos of the intern sensor list.
152
 
     */
153
 
    virtual bool removeSensor( uint pos );
154
 
 
155
 
    /**
156
 
      This function is a wrapper function to SensorManager::sendRequest.
157
 
      It should be used by all SensorDisplay functions that need to send
158
 
      a request to a sensor since it performs an appropriate error
159
 
      handling by removing the display of necessary.
160
 
     */
161
 
    void sendRequest( const QString &hostName, const QString &cmd, int id );
162
 
 
163
 
    /**
164
 
      Raises the configure dialog to setup the update interval.
165
 
     */
166
 
    void configureUpdateInterval();
167
 
 
168
 
    /**
169
 
      Returns whether the display provides a settings dialog.
170
 
      This method should be reimplemented in the derived class.
171
 
     */
172
 
    virtual bool hasSettingsDialog() const;
173
 
 
174
 
    /**
175
 
      This method is called to raise the settings dialog of the
176
 
      display. It should be reimplemented in the derived class.
177
 
     */
178
 
    virtual void configureSettings();
179
 
 
180
 
    /**
181
 
      Reimplement this method to setup the display from config data.
182
 
     */
183
 
    virtual bool restoreSettings( QDomElement& );
184
 
 
185
 
    /**
186
 
      Reimplement this method to save the displays config data.
187
 
     */
188
 
    virtual bool saveSettings( QDomDocument&, QDomElement&, bool = true );
189
 
 
190
 
    /**
191
 
      Reimplement this method to catch error messages from the SensorManager.
192
 
      
193
 
      @param sensorId The unique id of the sensor.
194
 
      @param mode The mode: true = error, false = everthing ok
195
 
     */
196
 
    virtual void sensorError( int sensorId, bool mode );
197
 
 
198
 
    /**
199
 
      Normaly you shouldn't reimplement this methode
200
 
     */
201
 
    virtual void sensorLost( int reqId );
202
 
 
203
 
  public slots:
204
 
    /**
205
 
      If @ref value is true, this method starts the timer that triggers
206
 
      timer events. If @ref value is false, the timer is stopped.
207
 
     */
208
 
    void setTimerOn( bool value );
209
 
 
210
 
    /**
211
 
      Calling this method emits the @ref showPopupMenu() with this
212
 
      display as argument.
213
 
     */
214
 
    void rmbPressed();
215
 
 
216
 
    /**
217
 
      Sets whether the display is modified of not.
218
 
     */
219
 
    void setModified( bool modified );
220
 
    
221
 
    /**
222
 
      This method can be used to apply the new settings. Just connect
223
 
      the applyClicked() signal of your configuration dialog with this
224
 
      slot and reimplement it.
225
 
     */
226
 
    virtual void applySettings();
227
 
 
228
 
    /**
229
 
      This methid is called whenever the global style is changed.
230
 
      Reimplement it to apply the new style settings to the display.
231
 
     */
232
 
    virtual void applyStyle();
233
 
 
234
 
                
235
 
  signals:
236
 
    void showPopupMenu( KSGRD::SensorDisplay *display );
237
 
    void modified( bool modified );
238
 
 
239
 
  protected:
240
 
    virtual bool eventFilter( QObject*, QEvent* );
241
 
    virtual void resizeEvent( QResizeEvent* );
242
 
    virtual void timerEvent( QTimerEvent* );
243
 
 
244
 
    void registerSensor( SensorProperties *sp );
245
 
    void unregisterSensor( uint pos );
246
 
 
247
 
    QColor restoreColor( QDomElement &element, const QString &attr,
248
 
                         const QColor& fallback );
249
 
    void saveColor( QDomElement &element, const QString &attr,
250
 
                    const QColor &color );
251
 
 
252
 
    virtual QString additionalWhatsThis();
253
 
 
254
 
    void setSensorOk( bool ok );
255
 
 
256
 
    bool modified() const;
257
 
    bool timerOn() const;
258
 
 
259
 
    QWidget *frame();
260
 
 
261
 
//    void setNoFrame( bool value );
262
 
    bool noFrame() const;
263
 
 
264
 
    void reorderSensors(const QValueList<int> &orderOfSensors);
265
 
    QPtrList<SensorProperties> &sensors();
266
 
 
267
 
  private:
268
 
    void updateWhatsThis();
269
 
 
270
 
    bool mShowUnit;
271
 
    bool mUseGlobalUpdateInterval;
272
 
    bool mModified;
273
 
    bool mNoFrame;
274
 
    bool mIsApplet;
275
 
 
276
 
    int mTimerId;
277
 
    int mUpdateInterval;
278
 
 
279
 
    // The frame around the other widgets.
280
 
    QGroupBox* mFrame;
281
 
 
282
 
    QPtrList<SensorProperties> mSensors;
283
 
 
284
 
    QString mTitle;
285
 
    QString mUnit;
286
 
 
287
 
    QWidget* mErrorIndicator;
288
 
    QWidget* mPlotterWdg;
289
 
};
290
 
 
291
 
class SensorProperties
292
 
{
293
 
  public:
294
 
    SensorProperties();
295
 
    SensorProperties( const QString &hostName, const QString &name,
296
 
                      const QString &type, const QString &description );
297
 
    ~SensorProperties();
298
 
 
299
 
    void setHostName( const QString &hostName );
300
 
    QString hostName() const;
301
 
 
302
 
    void setName( const QString &name );
303
 
    QString name() const;
304
 
 
305
 
    void setType( const QString &type );
306
 
    QString type() const;
307
 
 
308
 
    void setDescription( const QString &description );
309
 
    QString description() const;
310
 
 
311
 
    void setUnit( const QString &unit );
312
 
    QString unit() const;
313
 
 
314
 
    void setIsOk( bool value );
315
 
    bool isOk() const;
316
 
 
317
 
  private:
318
 
    QString mHostName;
319
 
    QString mName;
320
 
    QString mType;
321
 
    QString mDescription;
322
 
    QString mUnit;
323
 
 
324
 
    /* This flag indicates whether the communication to the sensor is
325
 
     * ok or not. */
326
 
    bool mOk;
327
 
};
328
 
 
329
 
}
330
 
 
331
 
#endif