summaryrefslogtreecommitdiffstats
path: root/src/sources/i8ksrc.cpp
blob: 314a15aac622f003cbd465f7e05a1ec0cf9247d4 (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
/***************************************************************************
 *   Copyright (C) 2006 by Ken Werner                                      *
 *   [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.                                   *
 *                                                                         *
 *   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.             *
 ***************************************************************************/

#include "i8ksrc.h"
#include <tqtextstream.h> 
#include <tqdir.h>
#include <klocale.h>

I8kSrc::I8kSrc(TQWidget* inParent, const TQFile& inSourceFile, unsigned int inIndex):
		LabelSource(inParent),
		mIndex(inIndex),
		mSourceFile(inSourceFile.name()),
		mTrigger(this){
	mID = I8kSrc::index2Name(inIndex);
	mName = mID;
	mDescription = i18n("This source is provided by i8k kernel module.");
}

I8kSrc::~I8kSrc(){
}

std::list<Source*>I8kSrc::createInstances(TQWidget* inParent){
	std::list<Source*> list;
	TQFile i8kFile("/proc/i8k");
	if(i8kFile.open(IO_ReadOnly)){
		TQTextStream textStream(&i8kFile);
		TQString s = textStream.readLine();
		i8kFile.close();
		TQStringList entries = TQStringList::split(' ', s);
		if(entries.size() && entries[0] == "1.0"){ // support for version 1.0
			// CPU temp
			if(entries.size() >= 4 && !entries[3].startsWith("-"))
				list.push_back(new I8kSrc(inParent, i8kFile, 3));
			// left fan
			if(entries.size() >= 7 && !entries[4].startsWith("-"))
				list.push_back(new I8kSrc(inParent, i8kFile, 6));
			// left fan
			if(entries.size() >= 8 && !entries[5].startsWith("-"))
				list.push_back(new I8kSrc(inParent, i8kFile, 7));
		}
	}
	return list;	
}
TQString I8kSrc::fetchValue(){
	TQString s = "n/a";
	if(mSourceFile.open(IO_ReadOnly)){
		TQTextStream textStream(&mSourceFile);
		s = textStream.readLine();
		mSourceFile.close();
		s = s.section(' ', mIndex, mIndex, TQString::SectionSkipEmpty).stripWhiteSpace();
		switch(mIndex){
		case 3: // CPU temperature (Celsius)
			s = formatTemperature(s);
			break;
		case 6: // left fan rpm
		case 7: // right fan rpm
			if(s.length() > 1)
				s.truncate(s.length() - 1); //s = TQString::number(s.toInt()/10);
			s.append(" rpm");
			break;
		default:
			break;
		}
	}
	return s;
}

TQString I8kSrc::index2Name(unsigned int inIndex){
	switch(inIndex){
	case 0: // /proc/i8k format version
		return "i8k Format Version";
	case 1: // BIOS version
		return "Bios"; 
	case 2: // serial number
		return "Serial";
	case 3: // CPU temperature (Celsius)
		return "CPU";
	case 4: // left fan status
		return "left Fan tqStatus";
	case 5: // right fan status
		return "right Fan tqStatus";
	case 6: // left fan rpm
		return "left Fan";
	case 7: // right fan rpm
		return "right Fan";
	case 8: // ac status
		return "AC tqStatus";
	case 9: // buttons status
		return "Button tqStatus";
	default:
		return "unknown" + TQString().setNum(inIndex);
	}
}