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
|
/***************************************************************************
lmsensorsalarms.cpp - description
-------------------
begin : Wed Nov 14 2001
copyright : (C) 2001 by Miguel Novas
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <stdlib.h>
#include <ntqstring.h>
#include <tdeglobal.h>
#include <kprocess.h>
#include <kaudioplayer.h>
#include "lmsensorsalarms.h"
LMSensorsAlarms::LMSensorsAlarms(LMSensors *sensors, TQObject *parent, const char *name)
: TQObject(parent,name)
{
sensorCount= 0;
soundPlay = "";
connect( sensors, SIGNAL(valueChanged(Sensor *)) , this, SLOT(setValueChanged(Sensor *)) );
}
LMSensorsAlarms::~LMSensorsAlarms()
{
}
//###########################################################################################
void LMSensorsAlarms::runSensorCommand(const char *name,const char *value, const char *cmd)
{
setenv("SENSOR_NAME" , name , 1);
setenv("SENSOR_VALUE", value, 1);
runCommand( cmd );
}
void LMSensorsAlarms::runCommand(const char *str)
{
KShellProcess p;
p << str;
p.start(KShellProcess::DontCare);
p.detach();
}
void LMSensorsAlarms::playSound(const char *sound)
{
KAudioPlayer::play(sound);
}
//###########################################################################################
void LMSensorsAlarms::setValueChanged(Sensor *sensor)
{
if(sensor->getAlarm()) {
if(!sensor->getAlarmPrevious()) {
switch ( readAlarm(sensor->name()) )
{
case acSound:
sensorCount++;
soundPlay= readAlarmSound(sensor->name());
if(sensorCount==1) startTimer(3000);
break;
case acCommand:
runSensorCommand(
(const char *)sensor->getDescription(),
(const char *)TQString::number(sensor->getValue()),
(const char *)readAlarmCommand(sensor->name())
);
break;
}
}
} else {
if(sensor->getAlarmPrevious()) {
if( readAlarm(sensor->name())==acSound ) {
if(--sensorCount==0) killTimers();
}
}
}
}
void LMSensorsAlarms::timerEvent( TQTimerEvent * )
{
KAudioPlayer::play(soundPlay);
}
//##########################################################################
int LMSensorsAlarms::readAlarm(const char *name)
{
TDEGlobal::config()->setGroup(name);
return TDEGlobal::config()->readNumEntry("Alarm",acNothing);
}
void LMSensorsAlarms::writeAlarm(const char *name, int alarm)
{
TDEGlobal::config()->setGroup(name);
TDEGlobal::config()->writeEntry("Alarm",alarm);
}
TQString LMSensorsAlarms::readAlarmCommand(const char *name)
{
TDEGlobal::config()->setGroup(name);
return TDEGlobal::config()->readEntry("AlarmCommand", "");
}
void LMSensorsAlarms::writeAlarmCommand(const char *name, const TQString &cmd)
{
TDEGlobal::config()->setGroup(name);
TDEGlobal::config()->writeEntry("AlarmCommand", cmd);
}
TQString LMSensorsAlarms::readAlarmSound(const char *name)
{
TDEGlobal::config()->setGroup(name);
return TDEGlobal::config()->readEntry("AlarmSound", "ksensors_alert.wav");
}
void LMSensorsAlarms::writeAlarmSound(const char *name, const TQString &cmd)
{
TDEGlobal::config()->setGroup(name);
TDEGlobal::config()->writeEntry("AlarmSound", cmd);
}
#include "lmsensorsalarms.moc"
|