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
|
/***************************************************************************
strength.cpp - description
-------------------
begin : Mon Aug 19 2002
copyright : (C) 2002 by Stefan Winter
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 <tqwidget.h>
#include <tqpainter.h>
#include <tqpixmap.h>
#include <tqlabel.h>
#include <kstandarddirs.h>
#include <klocale.h>
#include <kdebug.h>
#include "strength.h"
#include "interface_wireless.h"
extern bool useAlternateStrengthCalc;
Strength::Strength (TQWidget * parent, Interface_wireless * device):TQWidget (parent,
"strength")
{
this->device = device;
KStandardDirs finder;
tdedir = finder.findResourceDir ("data", "kwifimanager/pics/no_card.png");
tdedir += "kwifimanager/pics/";
NOT_CON_OFFLINE_ADHOC = new TQPixmap (tdedir + "offline.png");
EXCELLENT = new TQPixmap (tdedir + "excellent.png");
GOOD = new TQPixmap (tdedir + "good.png");
MARGINAL = new TQPixmap (tdedir + "marginal.png");
OOR_MINIMUM = new TQPixmap (tdedir + "oor_minimum.png");
OOR_DOWN = new TQPixmap (tdedir + "oor_down.png");
}
TQSize Strength::mySizeHint ()
{
/* make this quite general, just in case someone uses different icons */
TQSize* temp = new TQSize(NOT_CON_OFFLINE_ADHOC->size());
if (EXCELLENT->size().width() > temp->width ()) { temp->setWidth (EXCELLENT->size().width ()); }
if (EXCELLENT->size().height() > temp->height()) { temp->setHeight(EXCELLENT->size().height()); }
if (GOOD->size().width() > temp->width ()) { temp->setWidth (GOOD->size().width ()); }
if (GOOD->size().height() > temp->height()) { temp->setHeight(GOOD->size().height()); }
if (MARGINAL->size().width() > temp->width ()) { temp->setWidth (MARGINAL->size().width ()); }
if (MARGINAL->size().height() > temp->height()) { temp->setHeight(MARGINAL->size().height()); }
if (OOR_MINIMUM->size().width() > temp->width ()) { temp->setWidth (OOR_MINIMUM->size().width ()); }
if (OOR_MINIMUM->size().height() > temp->height()) { temp->setHeight(OOR_MINIMUM->size().height()); }
if (OOR_DOWN->size().width() > temp->width ()) { temp->setWidth (OOR_DOWN->size().width ()); }
if (OOR_DOWN->size().height() > temp->height()) { temp->setHeight(OOR_DOWN->size().height()); }
// add a little more x-space: we need 50 pixels left and 50 pixels right of the icon
temp->setWidth (temp->width() + 100);
// add a little more y-space: we need 10 pixels above and 20 pixels below the icon
temp->setHeight(temp->height() + 30);
// up to now: this is the height required to get a decent logo display
// now determine height of TQLabels to calculate the extra needed height
TQLabel heightTest( "ABC", 0 );
temp->setHeight( temp->height() + 2 * heightTest.sizeHint().height() + 10 );
return *temp;
}
Strength::~Strength ()
{
delete NOT_CON_OFFLINE_ADHOC;
delete GOOD;
delete MARGINAL;
delete OOR_MINIMUM;
delete OOR_DOWN;
}
void
Strength::paintEvent (TQPaintEvent * event)
{
updateInfo (event);
}
void
Strength::updateInfo (TQPaintEvent *)
{
TQPainter *strengthpainter = new TQPainter (this);
TQString sstrength1, sstrength2( i18n("N/A") );
int mode;
double freq;
int sig, noi, strength;
bool validdata = device->get_current_quality (sig, noi, strength);
if (useAlternateStrengthCalc)
strength = sig - noi;
if ( device->get_txpower_disabled() )
{
sstrength1 = i18n("DISABLED");
strengthpainter->drawPixmap (50, 10, *NOT_CON_OFFLINE_ADHOC);
}
else if (!device->get_device_freq (freq))
{
sstrength1 = i18n("NOT CONNECTED");
strengthpainter->drawPixmap (50, 10, *NOT_CON_OFFLINE_ADHOC);
}
else if (device->get_mode(mode) && mode == 1)
{
sstrength1 = i18n("AD-HOC MODE");
strengthpainter->drawPixmap (50, 10, *NOT_CON_OFFLINE_ADHOC);
}
else if (validdata && (strength > 45))
{
sstrength1 = i18n("ULTIMATE");
sstrength2 = TQString::number(strength);
strengthpainter->drawPixmap (50, 10, *EXCELLENT);
}
else if (validdata && (strength > 35))
{
sstrength1 = i18n("TOP");
sstrength2 = TQString::number(strength);
strengthpainter->drawPixmap (50, 10, *EXCELLENT);
}
else if (validdata && (strength > 25))
{
sstrength1 = i18n("EXCELLENT");
sstrength2 = TQString::number(strength);
strengthpainter->drawPixmap (50, 10, *EXCELLENT);
}
else if (validdata && (strength > 15))
{
sstrength1 = i18n("GOOD");
sstrength2 = TQString::number(strength);
strengthpainter->drawPixmap (50, 10, *GOOD);
}
else if (validdata && (strength > 5))
{
sstrength1 = i18n("WEAK");
sstrength2 = TQString::number(strength);
strengthpainter->drawPixmap (50, 10, *MARGINAL);
}
else if (validdata && (strength > 0))
{
sstrength1 = i18n("MINIMUM");
sstrength2 = TQString::number(strength);
strengthpainter->drawPixmap (50, 10, *OOR_MINIMUM);
}
else if (((strength == 0) && (mode == 2)) || (!validdata))
{
sstrength1 = i18n("OUT OF RANGE");
sstrength2 = TQString::fromLatin1("0");
strengthpainter->drawPixmap (50, 10, *OOR_DOWN);
}
else
{
sstrength1 = i18n("N/A");
strengthpainter->drawPixmap (50, 10, *NOT_CON_OFFLINE_ADHOC);
};
sstrength2.prepend( i18n("Signal strength: ") );
strengthpainter->drawText (5, 55, sstrength1);
strengthpainter->drawText (5, 80, sstrength2);
delete strengthpainter;
}
#include "strength.moc"
|