summaryrefslogtreecommitdiffstats
path: root/src/sensorslist.cpp
blob: 90bcac4d187df6987e49041330c0e4ff128a799a (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
/***************************************************************************
                          sensorslist.cpp  -  description
                             -------------------
    begin                : mié abr 24 2002
    copyright            : (C) 2002 by Miguel Novas
    email                : michaell@teleline.es
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 "sensorslist.h"

#include <tdeglobal.h>

SensorsList::SensorsList(TQObject *parent, const char * name)
                                  : TQObject(parent,name)
{
 tempScale= Sensor::dgCelsius;
 updateInterval= 5000;
}

SensorsList::~SensorsList()
{
}


void SensorsList::setMonitorized(bool enable)
{
 if(monitorized!=enable) {
   monitorized= enable;
   if(enable) startTimer( updateInterval );
   else       killTimers();
 }
}

void SensorsList::setUpdateInterval(int seconds)
{
 seconds= seconds*1000;
 if(updateInterval!=seconds) {
    updateInterval= seconds;
    if(monitorized) {
       setMonitorized(false);
       setMonitorized(true);
    }
 }
}

void SensorsList::setTempScale(Sensor::TempScale scale)
{
 if(tempScale!=scale) {
     tempScale= scale;
     TQObjectList *list= getSensors();
     if(list)
       for(Sensor *sensor=(Sensor*)list->first(); sensor!=0; sensor= (Sensor*)list->next())
         if(sensor->getType()==Sensor::lmTemp)
           emit sensor->configChanged();
 }
}


void SensorsList::readConfig()
{
 TDEConfig *ksConfig= TDEGlobal::config();
 ksConfig->setGroup( name() );
 setUpdateInterval(ksConfig->readNumEntry("UpdateInterval",5));
 TQString str= ksConfig->readEntry("Scale" ,"C");
 Sensor::TempScale tempScale;
 if(str=="F") tempScale= Sensor::dgFahrenheit;
 else if(str=="K") tempScale= Sensor::dgKelvin;
      else             tempScale= Sensor::dgCelsius;
 setTempScale(tempScale);
}


void SensorsList::writeConfig()
{
 TDEConfig *ksConfig= TDEGlobal::config();
 ksConfig->setGroup( name() );
 ksConfig->writeEntry("UpdateInterval",updateInterval/1000);
 TQString str;
 switch(tempScale) {
  case Sensor::dgCelsius   : str='C'; break;
  case Sensor::dgKelvin    : str='K'; break;
  case Sensor::dgFahrenheit: str='F'; break;
 }
 ksConfig->writeEntry("Scale" ,str);
}


//****************************************************************************
// Protected methods
//****************************************************************************

void SensorsList::timerEvent( TQTimerEvent * )
{
 updateSensors();
}

//***************

void SensorsList::childEvent ( TQChildEvent *e )
{
 if(e->inserted()) {
    connect((Sensor *)e->child(),SIGNAL(configChanged()),this,SLOT(slotConfigChanged()));
    connect((Sensor *)e->child(),SIGNAL(valueChanged(double)) ,this,SLOT(slotValueChanged()));
 }
}

//****************************************************************************
// Protected slots
//****************************************************************************


void SensorsList::slotConfigChanged()
{
 emit configChanged( sender()->name() );
}

void SensorsList::slotValueChanged()
{
 emit valueChanged( (Sensor *)sender() );
}


/*********************************************************************************/

#include "sensorslist.moc"