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
|
/***************************************************************************
cpudisplay.cpp - description
-------------------
begin : Sun Nov 25 2001
copyright : (C) 2001 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 "cpupanel.h"
#include "qlcddraw.h"
#include <ntqcolor.h>
#include <ntqpainter.h>
#include <ntqlcdnumber.h>
#include <string.h>
bool getCpuInfoValue(const char *name,TQString &value)
{
char buffer[128];
char *ptr;
FILE *fp;
bool result;
result= false;
if( (fp= fopen("/proc/cpuinfo","r")) ) {
while( fgets(buffer, 127, fp) ) {
if(!strncmp(name,buffer,strlen(name))) {
ptr= strchr(buffer,':');
if(ptr) {
value= (const char *)(ptr+2);
value = value.stripWhiteSpace();
}
result= true;
break;
}
}
fclose(fp);
}
return result;
}
void adjustString(TQString &str,int maxlen)
{
int i= str.find('(');
str.truncate(maxlen);
if(i>=0) str.truncate(i);
str= str.stripWhiteSpace();
}
CpuPanel::CpuPanel(TQWidget *parent, const char *name) : Panel(parent,name)
{
sCpu= "Unknown";
getCpuInfoValue("model name",sCpu);
adjustString(sCpu,16);
sVendor= "Unknown";
getCpuInfoValue("vendor_id",sVendor);
adjustString(sVendor,16);
sBogomips= "0";
getCpuInfoValue("bogomips",sBogomips);
sBogomips.sprintf("%.0f BMPS",sBogomips.toDouble());
TQString sSpeed= "0";
getCpuInfoValue("cpu MHz",sSpeed);
sSpeed.sprintf("%.0f",sSpeed.toDouble());
speed= new TQLCDNumber(this);
speed->setGeometry(6,20,52,26);
speed->setNumDigits(sSpeed.length());
speed->setSegmentStyle(TQLCDNumber::Filled);
speed->setFrameShape(TQFrame::NoFrame);
speed->display(sSpeed);
TQPalette cg= speed->palette();
cg.setColor( TQColorGroup::Foreground, TQColor( 255, 0, 0) );
cg.setColor( TQColorGroup::Light, TQColor( 255, 0, 0) );
cg.setColor( TQColorGroup::Midlight, TQColor( 231, 232, 246) );
cg.setColor( TQColorGroup::Dark, TQColor( 104, 105, 118) );
cg.setColor( TQColorGroup::Mid, TQColor( 139, 140, 158) );
cg.setColor( TQColorGroup::Background, palette().active().background() );
speed->setPalette(cg);
speed->installEventFilter(this);
}
CpuPanel::~CpuPanel()
{
}
void CpuPanel::updateInfo()
{
getCpuInfoValue("bogomips",sBogomips);
sBogomips.sprintf("%.0f BMPS",sBogomips.toDouble());
getCpuInfoValue("cpu MHz",sSpeed);
sSpeed.sprintf("%.0f",sSpeed.toDouble());
speed->setNumDigits(sSpeed.length());
speed->display(sSpeed);
update();
}
void CpuPanel::drawContents(TQPainter *p)
{
int w= width();
int h= height();
int i2= (h * 4) / 5;
int th= h-i2-h/11;
TQLcd::draw(p, 2,h/10,w-4,th,sCpu.latin1(),TQLcd::alignJustify, &getColorTitle());
TQLcd::draw(p, 2,i2+1,w-4,th,sBogomips.latin1(),TQLcd::alignCenter,&getColorTitle());
}
void CpuPanel::paletteChange( const TQPalette &oldPalette)
{
TQPalette cg= speed->palette();
cg.setColor(TQColorGroup::Background,palette().active().background());
speed->setPalette(cg);
}
void CpuPanel::resizeEvent ( TQResizeEvent *e )
{
int w= width();
int h= height();
int mw= w/10;
speed->setGeometry(mw,h/3,w-mw*2,(h*2)/5);
}
|