summaryrefslogtreecommitdiffstats
path: root/ksysguard/gui/SensorDisplayLib/SensorLogger.h
blob: 018e36bf9ff811e2b4ad065953c17b71935fd29a (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
/*
    KSysGuard, the KDE System Guard

	Copyright (c) 2001 Tobias Koenig <tokoe@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.

*/

#ifndef _SensorLogger_h
#define _SensorLogger_h

#include <tqdom.h>
#include <tqlabel.h>
#include <tqlineedit.h>
#include <tqlistview.h>
#include <tqpopupmenu.h>
#include <tqspinbox.h>
#include <tqstring.h>

#include <SensorDisplay.h>

#include "SensorLoggerDlg.h"

#define NONE -1

class SensorLoggerSettings;

class SLListViewItem : public QListViewItem
{
public:
	SLListViewItem(TQListView *parent = 0);

	void setTextColor(const TQColor& color) { textColor = color; }

	void paintCell(TQPainter *p, const TQColorGroup &cg, int column, int width, int alignment) {
		TQColorGroup cgroup(cg);
		cgroup.setColor(TQColorGroup::Text, textColor);
		TQListViewItem::paintCell(p, cgroup, column, width, alignment);
	
	}

	void paintFocus(TQPainter *, const TQColorGroup, const TQRect) {}

private:
	TQColor textColor;
};	

class LogSensor : public TQObject, public KSGRD::SensorClient
{
	Q_OBJECT
public:
	LogSensor(TQListView *parent);
	~LogSensor(void);

	void answerReceived(int id, const TQString& answer);

	void setHostName(const TQString& name) { hostName = name; lvi->setText(3, name); }
	void setSensorName(const TQString& name) { sensorName = name; lvi->setText(2, name); }
	void setFileName(const TQString& name)
	{
		fileName = name;
		lvi->setText(4, name);
	}
	void setUpperLimitActive(bool value) { upperLimitActive = value; }
	void setLowerLimitActive(bool value) { lowerLimitActive = value; }
	void setUpperLimit(double value) { upperLimit = value; }
	void setLowerLimit(double value) { lowerLimit = value; }

	void setTimerInterval(int interval) {
		timerInterval = interval;

		if (timerID != NONE)
		{
			timerOff();
			timerOn();
		}

		lvi->setText(1, TQString("%1").arg(interval));
	}

	TQString getSensorName(void) { return sensorName; }
	TQString getHostName(void) { return hostName; }
	TQString getFileName(void) { return fileName; }
	int getTimerInterval(void) { return timerInterval; }
	bool getUpperLimitActive(void) { return upperLimitActive; }
	bool getLowerLimitActive(void) { return lowerLimitActive; }
	double getUpperLimit(void) { return upperLimit; }
	double getLowerLimit(void) { return lowerLimit; }
	TQListViewItem* getListViewItem(void) { return lvi; }

public slots:
	void timerOff()
	{
		killTimer(timerID);
		timerID = NONE;
	}

	void timerOn()
	{
		timerID = startTimer(timerInterval * 1000);
	}

	bool isLogging() { return timerID != NONE; }

	void startLogging(void);
	void stopLogging(void);

protected:
	virtual void timerEvent(TQTimerEvent*);

private:
	TQListView* monitor;
	SLListViewItem* lvi;
	TQPixmap pixmap_running;
	TQPixmap pixmap_waiting;
	TQString sensorName;
	TQString hostName;
	TQString fileName;

	int timerInterval;
	int timerID;

	bool lowerLimitActive;
	bool upperLimitActive;

	double lowerLimit;
	double upperLimit;
};

class SensorLogger : public KSGRD::SensorDisplay
{
	Q_OBJECT
public:
	SensorLogger(TQWidget *parent = 0, const char *name = 0, const TQString& title = 0);
	~SensorLogger(void);

	bool addSensor(const TQString& hostName, const TQString& sensorName, const TQString& sensorType,
				   const TQString& sensorDescr);

	bool editSensor(LogSensor*);

	void answerReceived(int id, const TQString& answer);
	void resizeEvent(TQResizeEvent*);

	bool restoreSettings(TQDomElement& element);
	bool saveSettings(TQDomDocument& doc, TQDomElement& element, bool save = true);

	void configureSettings(void);

	virtual bool hasSettingsDialog() const
	{
		return (true);
	}

public slots:
	void applySettings();
	void applyStyle();
	void RMBClicked(TQListViewItem*, const TQPoint&, int);

protected:
	LogSensor* getLogSensor(TQListViewItem*);

private:
	TQListView* monitor;

	TQPtrList<LogSensor> logSensors;

	SensorLoggerDlg *sld;
	SensorLoggerSettings *sls;
};

#endif // _SensorLogger_h