summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2004-04-07 10:32:54 (UTC)
committer mickeyl <mickeyl>2004-04-07 10:32:54 (UTC)
commit364971c08f3d761102daab01889b9fab394f8f08 (patch) (unidiff)
tree1004de1b8fa1dc8d96f9a559f6e30d7bac32849a
parent9b1f8d08db8d533ac59975a8badd25e587c2239c (diff)
downloadopie-364971c08f3d761102daab01889b9fab394f8f08.zip
opie-364971c08f3d761102daab01889b9fab394f8f08.tar.gz
opie-364971c08f3d761102daab01889b9fab394f8f08.tar.bz2
remove bogus '(const char*)' in debug statements
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/zkbapplet/zkbwidget.cpp2
-rw-r--r--noncore/apps/keyz-cfg/zkb.cpp2
-rw-r--r--noncore/apps/keyz-cfg/zkbcfg.cpp4
-rw-r--r--noncore/net/wellenreiter/gui/configwindow.cpp8
-rw-r--r--noncore/net/wellenreiter/gui/mainwindow.cpp18
-rw-r--r--noncore/net/wellenreiter/gui/scanlist.cpp24
-rw-r--r--noncore/net/wellenreiter/gui/wellenreiter.cpp58
-rw-r--r--noncore/settings/networksettings/wlan/wlanimp2.cpp4
-rw-r--r--noncore/settings/sysinfo/benchmarkinfo.cpp2
9 files changed, 61 insertions, 61 deletions
diff --git a/noncore/applets/zkbapplet/zkbwidget.cpp b/noncore/applets/zkbapplet/zkbwidget.cpp
index 13d554c..38bfba9 100644
--- a/noncore/applets/zkbapplet/zkbwidget.cpp
+++ b/noncore/applets/zkbapplet/zkbwidget.cpp
@@ -1,161 +1,161 @@
1#include <opie2/otaskbarapplet.h> 1#include <opie2/otaskbarapplet.h>
2#include <qpe/qcopenvelope_qws.h> 2#include <qpe/qcopenvelope_qws.h>
3#include <qpe/applnk.h> 3#include <qpe/applnk.h>
4#include <qpe/qpeapplication.h> 4#include <qpe/qpeapplication.h>
5#include <qpe/resource.h> 5#include <qpe/resource.h>
6#include <stdio.h> 6#include <stdio.h>
7#include <unistd.h> 7#include <unistd.h>
8#include "zkbwidget.h" 8#include "zkbwidget.h"
9#include "zkbcfg.h" 9#include "zkbcfg.h"
10 10
11using namespace Opie::Ui; 11using namespace Opie::Ui;
12ZkbWidget::ZkbWidget(QWidget* parent):QLabel(parent),keymap(0), 12ZkbWidget::ZkbWidget(QWidget* parent):QLabel(parent),keymap(0),
13 disabled(Resource::loadPixmap("zkb-disabled")) { 13 disabled(Resource::loadPixmap("zkb-disabled")) {
14 14
15 labels = new QPopupMenu(); 15 labels = new QPopupMenu();
16 connect(labels, SIGNAL(activated(int)), this, 16 connect(labels, SIGNAL(activated(int)), this,
17 SLOT(labelChanged(int))); 17 SLOT(labelChanged(int)));
18 18
19 loadKeymap(); 19 loadKeymap();
20 20
21 channel = new QCopChannel("QPE/zkb", this); 21 channel = new QCopChannel("QPE/zkb", this);
22 connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), 22 connect(channel, SIGNAL(received(const QCString&,const QByteArray&)),
23 this, SLOT(signalReceived(const QCString&,const QByteArray&))); 23 this, SLOT(signalReceived(const QCString&,const QByteArray&)));
24 setFixedWidth ( AppLnk::smallIconSize() ); 24 setFixedWidth ( AppLnk::smallIconSize() );
25 setFixedHeight ( AppLnk::smallIconSize() ); 25 setFixedHeight ( AppLnk::smallIconSize() );
26} 26}
27 27
28ZkbWidget::~ZkbWidget() { 28ZkbWidget::~ZkbWidget() {
29} 29}
30 30
31int ZkbWidget::position() 31int ZkbWidget::position()
32{ 32{
33 return 8; 33 return 8;
34} 34}
35 35
36bool ZkbWidget::loadKeymap() { 36bool ZkbWidget::loadKeymap() {
37 ZkbConfig c(QPEApplication::qpeDir()+"/share/zkb"); 37 ZkbConfig c(QPEApplication::qpeDir()+"/share/zkb");
38 QFontMetrics fm(font()); 38 QFontMetrics fm(font());
39 39
40 if (keymap != 0) { 40 if (keymap != 0) {
41 delete keymap; 41 delete keymap;
42 keymap = 0; 42 keymap = 0;
43 } 43 }
44 44
45 Keymap* km = new Keymap(); 45 Keymap* km = new Keymap();
46 46
47 if (!c.load("zkb.xml", *km, "")) { 47 if (!c.load("zkb.xml", *km, "")) {
48 delete km; 48 delete km;
49 setPixmap(disabled); 49 setPixmap(disabled);
50 return false; 50 return false;
51 } 51 }
52 52
53 connect(km, SIGNAL(stateChanged(const QString&)), 53 connect(km, SIGNAL(stateChanged(const QString&)),
54 this, SLOT(stateChanged(const QString&))); 54 this, SLOT(stateChanged(const QString&)));
55 55
56 qwsServer->setKeyboardFilter(km); 56 qwsServer->setKeyboardFilter(km);
57 57
58 Keymap* oldkm = keymap; 58 Keymap* oldkm = keymap;
59 keymap = km; 59 keymap = km;
60 60
61 if (oldkm != 0) { 61 if (oldkm != 0) {
62 delete oldkm; 62 delete oldkm;
63 } 63 }
64 64
65 setText(keymap->getCurrentLabel()); 65 setText(keymap->getCurrentLabel());
66 66
67 labels->clear(); 67 labels->clear();
68 QStringList l = keymap->listLabels(); 68 QStringList l = keymap->listLabels();
69 labels->insertItem(disabled, 0, 0); 69 labels->insertItem(disabled, 0, 0);
70 int n = 1; 70 int n = 1;
71 w = 0; 71 w = 0;
72 for(QStringList::Iterator it = l.begin(); it != l.end(); 72 for(QStringList::Iterator it = l.begin(); it != l.end();
73 ++it, n++) { 73 ++it, n++) {
74 74
75 // printf("label: %s\n", (const char*) (*it).utf8()); 75 // printf("label: %s\n", (const char*) (*it).utf8());
76 76
77 labels->insertItem(*it, n, n); 77 labels->insertItem(*it, n, n);
78 int lw = fm.width(*it); 78 int lw = fm.width(*it);
79 if (lw > w) { 79 if (lw > w) {
80 w = lw; 80 w = lw;
81 } 81 }
82 } 82 }
83 83
84 if (w == 0) { 84 if (w == 0) {
85 hide(); 85 hide();
86 } else { 86 } else {
87 show(); 87 show();
88 } 88 }
89 return true; 89 return true;
90} 90}
91 91
92QSize ZkbWidget::sizeHint() const { 92QSize ZkbWidget::sizeHint() const {
93 return QSize(AppLnk::smallIconSize(),AppLnk::smallIconSize()); 93 return QSize(AppLnk::smallIconSize(),AppLnk::smallIconSize());
94} 94}
95 95
96void ZkbWidget::stateChanged(const QString& s) { 96void ZkbWidget::stateChanged(const QString& s) {
97 //odebug << "stateChanged: " << (const char*) s.utf8() << "\n" << oendl; 97 //odebug << "stateChanged: " << s.utf8() << "\n" << oendl;
98 setText(s); 98 setText(s);
99} 99}
100 100
101void ZkbWidget::labelChanged(int id) { 101void ZkbWidget::labelChanged(int id) {
102 if (id == 0) { 102 if (id == 0) {
103 keymap->disable(); 103 keymap->disable();
104 setPixmap(disabled); 104 setPixmap(disabled);
105 return; 105 return;
106 } 106 }
107 107
108 keymap->enable(); 108 keymap->enable();
109 109
110 QStringList l = keymap->listLabels(); 110 QStringList l = keymap->listLabels();
111 QString lbl = l[id-1]; 111 QString lbl = l[id-1];
112 112
113 //printf("labelChanged: %s\n", (const char*) lbl.utf8()); 113 //printf("labelChanged: %s\n", (const char*) lbl.utf8());
114 State* state = keymap->getStateByLabel(lbl); 114 State* state = keymap->getStateByLabel(lbl);
115 if (state != 0) { 115 if (state != 0) {
116 keymap->setCurrentState(state); 116 keymap->setCurrentState(state);
117 setText(lbl); 117 setText(lbl);
118 } 118 }
119} 119}
120 120
121void ZkbWidget::mouseReleaseEvent(QMouseEvent*) { 121void ZkbWidget::mouseReleaseEvent(QMouseEvent*) {
122 QSize sh = labels->sizeHint(); 122 QSize sh = labels->sizeHint();
123 QPoint p = mapToGlobal(QPoint((width()-sh.width())/2,-sh.height())); 123 QPoint p = mapToGlobal(QPoint((width()-sh.width())/2,-sh.height()));
124 labels->exec(p); 124 labels->exec(p);
125} 125}
126 126
127void ZkbWidget::signalReceived(const QCString& msg, const QByteArray& data) { 127void ZkbWidget::signalReceived(const QCString& msg, const QByteArray& data) {
128 QDataStream stream(data, IO_ReadOnly); 128 QDataStream stream(data, IO_ReadOnly);
129 129
130 if (msg == "enable()") { 130 if (msg == "enable()") {
131 keymap->enable(); 131 keymap->enable();
132 } else if (msg == "disable()") { 132 } else if (msg == "disable()") {
133 keymap->disable(); 133 keymap->disable();
134 } else if (msg == "reload()") { 134 } else if (msg == "reload()") {
135 QCopEnvelope("QPE/System", "busy()"); 135 QCopEnvelope("QPE/System", "busy()");
136 QTimer::singleShot(0, this, SLOT(reload())); 136 QTimer::singleShot(0, this, SLOT(reload()));
137 } else if (msg == "switch(QString)") { 137 } else if (msg == "switch(QString)") {
138 QString lbl; 138 QString lbl;
139 stream >> lbl; 139 stream >> lbl;
140 140
141 if (keymap != 0) { 141 if (keymap != 0) {
142 State* state = keymap->getStateByLabel(lbl); 142 State* state = keymap->getStateByLabel(lbl);
143 if (state != 0) { 143 if (state != 0) {
144 keymap->setCurrentState(state); 144 keymap->setCurrentState(state);
145 setText(lbl); 145 setText(lbl);
146 } 146 }
147 } 147 }
148 } else if (msg == "debug(QString)") { 148 } else if (msg == "debug(QString)") {
149 QString flag; 149 QString flag;
150 stream >> flag; 150 stream >> flag;
151 } 151 }
152} 152}
153 153
154void ZkbWidget::reload() { 154void ZkbWidget::reload() {
155 loadKeymap(); 155 loadKeymap();
156 QCopEnvelope("QPE/System", "notBusy()"); 156 QCopEnvelope("QPE/System", "notBusy()");
157} 157}
158 158
159EXPORT_OPIE_APPLET_v1( ZkbWidget ) 159EXPORT_OPIE_APPLET_v1( ZkbWidget )
160 160
161 161
diff --git a/noncore/apps/keyz-cfg/zkb.cpp b/noncore/apps/keyz-cfg/zkb.cpp
index 8382615..58bde2a 100644
--- a/noncore/apps/keyz-cfg/zkb.cpp
+++ b/noncore/apps/keyz-cfg/zkb.cpp
@@ -1,589 +1,589 @@
1#include "zkb.h" 1#include "zkb.h"
2#include <stdio.h> 2#include <stdio.h>
3 3
4// Implementation of Action class 4// Implementation of Action class
5Action::Action():state(0), keycode(0), unicode(0), flags(0) { 5Action::Action():state(0), keycode(0), unicode(0), flags(0) {
6} 6}
7 7
8Action::Action(State* s, ushort kc, ushort uni, int f): 8Action::Action(State* s, ushort kc, ushort uni, int f):
9 state(s), keycode(kc), unicode(uni), flags(f) { 9 state(s), keycode(kc), unicode(uni), flags(f) {
10} 10}
11 11
12Action::~Action() { 12Action::~Action() {
13} 13}
14 14
15State* Action::getState() const { 15State* Action::getState() const {
16 return state; 16 return state;
17} 17}
18 18
19void Action::setState(State* s) { 19void Action::setState(State* s) {
20 state = s; 20 state = s;
21 setDefined(true); 21 setDefined(true);
22} 22}
23 23
24bool Action::hasEvent() const { 24bool Action::hasEvent() const {
25 return flags & Event; 25 return flags & Event;
26} 26}
27 27
28void Action::setEvent(bool e) { 28void Action::setEvent(bool e) {
29 flags = (flags & ~Event) | ((e) ? Event : 0); 29 flags = (flags & ~Event) | ((e) ? Event : 0);
30 30
31 if (e) { 31 if (e) {
32 setDefined(true); 32 setDefined(true);
33 } else { 33 } else {
34 if (state == 0) { 34 if (state == 0) {
35 setDefined(false); 35 setDefined(false);
36 } 36 }
37 } 37 }
38} 38}
39 39
40bool Action::isDefined() const { 40bool Action::isDefined() const {
41 return flags & Defined; 41 return flags & Defined;
42} 42}
43 43
44void Action::setDefined(bool d) { 44void Action::setDefined(bool d) {
45 flags = (flags & ~Defined) | ((d) ? Defined : 0); 45 flags = (flags & ~Defined) | ((d) ? Defined : 0);
46} 46}
47 47
48int Action::getKeycode() const { 48int Action::getKeycode() const {
49 return keycode; 49 return keycode;
50} 50}
51 51
52void Action::setKeycode(int c) { 52void Action::setKeycode(int c) {
53 keycode = (ushort) c; 53 keycode = (ushort) c;
54 setEvent(true); 54 setEvent(true);
55} 55}
56 56
57int Action::getUnicode() const { 57int Action::getUnicode() const {
58 return unicode; 58 return unicode;
59} 59}
60 60
61void Action::setUnicode(int u) { 61void Action::setUnicode(int u) {
62 unicode = (ushort) u; 62 unicode = (ushort) u;
63 setEvent(true); 63 setEvent(true);
64} 64}
65 65
66int Action::getModifiers() const { 66int Action::getModifiers() const {
67 int ret = 0; 67 int ret = 0;
68 if (flags & Shift_Mod) { 68 if (flags & Shift_Mod) {
69 ret |= Qt::ShiftButton; 69 ret |= Qt::ShiftButton;
70 } 70 }
71 71
72 if (flags & Ctrl_Mod) { 72 if (flags & Ctrl_Mod) {
73 ret |= Qt::ControlButton; 73 ret |= Qt::ControlButton;
74 } 74 }
75 75
76 if (flags & Alt_Mod) { 76 if (flags & Alt_Mod) {
77 ret |= Qt::AltButton; 77 ret |= Qt::AltButton;
78 } 78 }
79 79
80 if (flags & Keypad_Mod) { 80 if (flags & Keypad_Mod) {
81 ret |= Qt::Keypad; 81 ret |= Qt::Keypad;
82 } 82 }
83 83
84 return ret; 84 return ret;
85} 85}
86 86
87void Action::setModifiers(int m) { 87void Action::setModifiers(int m) {
88 int n = 0; 88 int n = 0;
89 89
90 if (m & Qt::ShiftButton) { 90 if (m & Qt::ShiftButton) {
91 n |= Shift_Mod; 91 n |= Shift_Mod;
92 } 92 }
93 93
94 if (m & Qt::ControlButton) { 94 if (m & Qt::ControlButton) {
95 n |= Ctrl_Mod; 95 n |= Ctrl_Mod;
96 } 96 }
97 97
98 if (m & Qt::AltButton) { 98 if (m & Qt::AltButton) {
99 n |= Alt_Mod; 99 n |= Alt_Mod;
100 } 100 }
101 101
102 if (m & Qt::Keypad) { 102 if (m & Qt::Keypad) {
103 n |= Keypad_Mod; 103 n |= Keypad_Mod;
104 } 104 }
105 105
106 flags = flags & ~Mod_Bits | n; 106 flags = flags & ~Mod_Bits | n;
107 setEvent(true); 107 setEvent(true);
108} 108}
109 109
110bool Action::isPressed() const { 110bool Action::isPressed() const {
111 return (flags & Press) != 0; 111 return (flags & Press) != 0;
112} 112}
113 113
114void Action::setPressed(bool p) { 114void Action::setPressed(bool p) {
115 flags = (flags & ~Press) | ((p) ? Press : 0); 115 flags = (flags & ~Press) | ((p) ? Press : 0);
116 setEvent(true); 116 setEvent(true);
117} 117}
118 118
119bool Action::isAutorepeat() const { 119bool Action::isAutorepeat() const {
120 return (flags & Autorepeat) != 0; 120 return (flags & Autorepeat) != 0;
121} 121}
122 122
123void Action::setAutorepeat(bool p) { 123void Action::setAutorepeat(bool p) {
124 flags = (flags & ~Autorepeat) | ((p) ? Autorepeat : 0); 124 flags = (flags & ~Autorepeat) | ((p) ? Autorepeat : 0);
125 setEvent(true); 125 setEvent(true);
126} 126}
127 127
128// Implementation of State class 128// Implementation of State class
129const short State::x1[] = { /* from 0x20 to 0x5f */ 129const short State::x1[] = { /* from 0x20 to 0x5f */
130 31, 0, 28, 3, 5, 6, 9, 28, /* 0x20 - 0x27 */ 130 31, 0, 28, 3, 5, 6, 9, 28, /* 0x20 - 0x27 */
131 11, 26, 10, 13, 26, 1, 29, 27, /* 0x28 - 0x2f */ 131 11, 26, 10, 13, 26, 1, 29, 27, /* 0x28 - 0x2f */
132 15, 16, 22, 4, 17, 19, 24, 20, /* 0x30 - 0x37 */ 132 15, 16, 22, 4, 17, 19, 24, 20, /* 0x30 - 0x37 */
133 8, 14, 29, 26, 29, 12, 32, 27, /* 0x38 - 0x3f */ 133 8, 14, 29, 26, 29, 12, 32, 27, /* 0x38 - 0x3f */
134 18, 0, 1, 2, 3, 4, 5, 6, /* 0x40 - 0x47 */ 134 18, 0, 1, 2, 3, 4, 5, 6, /* 0x40 - 0x47 */
135 7, 8, 9, 10, 11, 12, 13, 14, /* 0x48 - 0x4f */ 135 7, 8, 9, 10, 11, 12, 13, 14, /* 0x48 - 0x4f */
136 15, 16, 17, 18, 19, 20, 21, 22, /* 0x50 - 0x57 */ 136 15, 16, 17, 18, 19, 20, 21, 22, /* 0x50 - 0x57 */
137 23, 24, 25, 30, -1, 26, 28, 7, /* 0x58 - 0x5f */ 137 23, 24, 25, 30, -1, 26, 28, 7, /* 0x58 - 0x5f */
138 31, -1, -1, -1, -1, -1, -1, -1, /* 0x60 - 0x67 */ 138 31, -1, -1, -1, -1, -1, -1, -1, /* 0x60 - 0x67 */
139 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x68 - 0x6f */ 139 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x68 - 0x6f */
140 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70 - 0x77 */ 140 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70 - 0x77 */
141 -1, -1, -1, 29, 31, 32, 32, 28, /* 0x78 - 0x7f */ 141 -1, -1, -1, 29, 31, 32, 32, 28, /* 0x78 - 0x7f */
142}; 142};
143 143
144const short State::x2[] = { /* from 0x1000 to 0x1057*/ 144const short State::x2[] = { /* from 0x1000 to 0x1057*/
145 42, 36, -1, 30, 32, -1, -1, -1, /* 0x1000 - 0x1007 */ 145 42, 36, -1, 30, 32, -1, -1, -1, /* 0x1000 - 0x1007 */
146 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1008 - 0x100f */ 146 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1008 - 0x100f */
147 -1, -1, 44, 45, 46, 47, -1, -1, /* 0x1010 - 0x1017 */ 147 -1, -1, 44, 45, 46, 47, -1, -1, /* 0x1010 - 0x1017 */
148 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1018 - 0x101f */ 148 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1018 - 0x101f */
149 33, 35, 34, -1, 36, 27, -1, -1, /* 0x1020 - 0x1027 */ 149 33, 35, 34, -1, 36, 27, -1, -1, /* 0x1020 - 0x1027 */
150 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1028 - 0x102f */ 150 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1028 - 0x102f */
151 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1030 - 0x1037 */ 151 -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1030 - 0x1037 */
152 37, 38, 40, 39, 41, -1, -1, -1, /* 0x1038 - 0x103f */ 152 37, 38, 40, 39, 41, -1, -1, -1, /* 0x1038 - 0x103f */
153 -1, -1, -1, -1, -1, 35, -1, -1, /* 0x1040 - 0x1047 */ 153 -1, -1, -1, -1, -1, 35, -1, -1, /* 0x1040 - 0x1047 */
154 -1, -1, -1, -1, -1, 48, -1, -1, /* 0x1048 - 0x104f */ 154 -1, -1, -1, -1, -1, 48, -1, -1, /* 0x1048 - 0x104f */
155 43, 49, 50, -1, -1, -1, -1, -1, /* 0x1050 - 0x1057 */ 155 43, 49, 50, -1, -1, -1, -1, -1, /* 0x1050 - 0x1057 */
156}; 156};
157 157
158State::State(State* p):parent(p), keys(0) { 158State::State(State* p):parent(p), keys(0) {
159 keys = new Action[Key_Max * 2 + 1]; 159 keys = new Action[Key_Max * 2 + 1];
160} 160}
161 161
162State::State(const State& s) { 162State::State(const State& s) {
163 parent = s.parent; 163 parent = s.parent;
164 keys = new Action[Key_Max * 2 + 1]; 164 keys = new Action[Key_Max * 2 + 1];
165 memcpy(keys, s.keys, sizeof(Action) * (Key_Max * 2 + 1)); 165 memcpy(keys, s.keys, sizeof(Action) * (Key_Max * 2 + 1));
166} 166}
167 167
168State::~State() { 168State::~State() {
169 if (keys!=0) { 169 if (keys!=0) {
170 delete [] keys; 170 delete [] keys;
171 } 171 }
172} 172}
173 173
174Action* State::get(int keycode, bool pressed, bool follow) const { 174Action* State::get(int keycode, bool pressed, bool follow) const {
175 Action* ret = 0; 175 Action* ret = 0;
176 int n = translateKeycode(keycode); 176 int n = translateKeycode(keycode);
177 177
178 if (n != -1 && keys != 0) { 178 if (n != -1 && keys != 0) {
179 if (pressed) { 179 if (pressed) {
180 n += Key_Max; 180 n += Key_Max;
181 } 181 }
182 ret = &keys[n]; 182 ret = &keys[n];
183 } 183 }
184 184
185 if (ret==0 || !ret->isDefined()) { 185 if (ret==0 || !ret->isDefined()) {
186 if (follow && parent!=0) { 186 if (follow && parent!=0) {
187 ret = parent->get(keycode, pressed, follow); 187 ret = parent->get(keycode, pressed, follow);
188 } 188 }
189 } 189 }
190 190
191 return ret; 191 return ret;
192} 192}
193 193
194bool State::set(int keycode, bool pressed, Action& action) { 194bool State::set(int keycode, bool pressed, Action& action) {
195 int n = translateKeycode(keycode); 195 int n = translateKeycode(keycode);
196 196
197 if (n==-1 || keys==0) { 197 if (n==-1 || keys==0) {
198 return false; 198 return false;
199 } 199 }
200 200
201 if (pressed) { 201 if (pressed) {
202 n += Key_Max + 1; 202 n += Key_Max + 1;
203 } 203 }
204 204
205 keys[n] = action; 205 keys[n] = action;
206 return true; 206 return true;
207} 207}
208 208
209State* State::getParent() const { 209State* State::getParent() const {
210 return parent; 210 return parent;
211} 211}
212 212
213void State::setParent(State* s) { 213void State::setParent(State* s) {
214 parent = s; 214 parent = s;
215} 215}
216 216
217int State::translateKeycode(int keycode) const { 217int State::translateKeycode(int keycode) const {
218 if (keycode < 0x20) { 218 if (keycode < 0x20) {
219 return -1; 219 return -1;
220 } 220 }
221 221
222 if (keycode < 0x80) { 222 if (keycode < 0x80) {
223 return x1[keycode - 0x20]; 223 return x1[keycode - 0x20];
224 } 224 }
225 225
226 if (keycode < 0x1000) { 226 if (keycode < 0x1000) {
227 return -1; 227 return -1;
228 } 228 }
229 229
230 if (keycode < 0x1057) { 230 if (keycode < 0x1057) {
231 return x2[keycode - 0x1000]; 231 return x2[keycode - 0x1000];
232 } 232 }
233 233
234 return -1; 234 return -1;
235} 235}
236 236
237// Implementation of Keymap class 237// Implementation of Keymap class
238Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) { 238Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) {
239 repeatDelay=400; 239 repeatDelay=400;
240 repeatPeriod=80; 240 repeatPeriod=80;
241 connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat())); 241 connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat()));
242} 242}
243 243
244Keymap::~Keymap() { 244Keymap::~Keymap() {
245 QMap<QString, State*>::Iterator it; 245 QMap<QString, State*>::Iterator it;
246 for(it = states.begin(); it != states.end(); ++it) { 246 for(it = states.begin(); it != states.end(); ++it) {
247 delete it.data(); 247 delete it.data();
248 } 248 }
249 states.clear(); 249 states.clear();
250} 250}
251 251
252bool Keymap::filter(int unicode, int keycode, int modifiers, 252bool Keymap::filter(int unicode, int keycode, int modifiers,
253 bool isPress, bool autoRepeat) { 253 bool isPress, bool autoRepeat) {
254 254
255 qDebug("filter: >>> unicode=%x, keycode=%x, modifiers=%x, " 255 qDebug("filter: >>> unicode=%x, keycode=%x, modifiers=%x, "
256 "ispressed=%x\n", unicode, keycode, modifiers, isPress); 256 "ispressed=%x\n", unicode, keycode, modifiers, isPress);
257 257
258 if (!enabled) { 258 if (!enabled) {
259 return false; 259 return false;
260 } 260 }
261 261
262 // the second check is workaround to make suspend work if 262 // the second check is workaround to make suspend work if
263 // the user pressed it right after he did resume. for some 263 // the user pressed it right after he did resume. for some
264 // reason the event sent by qt has autoRepeat true in this 264 // reason the event sent by qt has autoRepeat true in this
265 // case 265 // case
266 if (autoRepeat && keycode != 4177) { 266 if (autoRepeat && keycode != 4177) {
267 return true; 267 return true;
268 } 268 }
269 269
270 (void) unicode; (void) modifiers; 270 (void) unicode; (void) modifiers;
271 271
272 Action* action = currentState->get(keycode, isPress, true); 272 Action* action = currentState->get(keycode, isPress, true);
273 if (action==0 || !action->isDefined()) { 273 if (action==0 || !action->isDefined()) {
274 return true; 274 return true;
275 } 275 }
276 276
277 if (action->hasEvent()) { 277 if (action->hasEvent()) {
278 qDebug("filter:<<< unicode=%x, keycode=%x, modifiers=%x, " 278 qDebug("filter:<<< unicode=%x, keycode=%x, modifiers=%x, "
279 "ispressed=%x\n", action->getUnicode(), 279 "ispressed=%x\n", action->getUnicode(),
280 action->getKeycode(), action->getModifiers(), 280 action->getKeycode(), action->getModifiers(),
281 action->isPressed()); 281 action->isPressed());
282 282
283 QWSServer::sendKeyEvent(action->getUnicode(), 283 QWSServer::sendKeyEvent(action->getUnicode(),
284 action->getKeycode(), action->getModifiers(), 284 action->getKeycode(), action->getModifiers(),
285 action->isPressed(), false); 285 action->isPressed(), false);
286 } 286 }
287 287
288 if (action->isAutorepeat()) { 288 if (action->isAutorepeat()) {
289 autoRepeatAction = action; 289 autoRepeatAction = action;
290 repeater.start(repeatDelay, TRUE); 290 repeater.start(repeatDelay, TRUE);
291 } else { 291 } else {
292 autoRepeatAction = 0; 292 autoRepeatAction = 0;
293 } 293 }
294 294
295 State* nstate = action->getState(); 295 State* nstate = action->getState();
296 if (nstate != 0) { 296 if (nstate != 0) {
297 setCurrentState(nstate); 297 setCurrentState(nstate);
298 QString lbl = getCurrentLabel(); 298 QString lbl = getCurrentLabel();
299 if (!lbl.isEmpty()) { 299 if (!lbl.isEmpty()) {
300 emit stateChanged(lbl); 300 emit stateChanged(lbl);
301 } 301 }
302 } 302 }
303 303
304 304
305 return true; 305 return true;
306} 306}
307 307
308void Keymap::enable() { 308void Keymap::enable() {
309 enabled = true; 309 enabled = true;
310} 310}
311 311
312void Keymap::disable() { 312void Keymap::disable() {
313 enabled = false; 313 enabled = false;
314} 314}
315 315
316QStringList Keymap::listStates() { 316QStringList Keymap::listStates() {
317 QStringList ret; 317 QStringList ret;
318 318
319 QMap<QString, State*>::Iterator it; 319 QMap<QString, State*>::Iterator it;
320 for(it = states.begin(); it != states.end(); ++it) { 320 for(it = states.begin(); it != states.end(); ++it) {
321 ret.append(it.key()); 321 ret.append(it.key());
322 } 322 }
323 323
324 return ret; 324 return ret;
325} 325}
326 326
327State* Keymap::getStateByName(const QString& name) { 327State* Keymap::getStateByName(const QString& name) {
328 QMap<QString, State*>::Iterator it = states.find(name); 328 QMap<QString, State*>::Iterator it = states.find(name);
329 329
330 if (it == states.end()) { 330 if (it == states.end()) {
331 return 0; 331 return 0;
332 } 332 }
333 333
334 return it.data(); 334 return it.data();
335} 335}
336 336
337QStringList Keymap::listLabels() { 337QStringList Keymap::listLabels() {
338 QStringList ret; 338 QStringList ret;
339 339
340 for(uint i = 0; i < labelList.count(); i++) { 340 for(uint i = 0; i < labelList.count(); i++) {
341 ret.append(*labelList.at(i)); 341 ret.append(*labelList.at(i));
342 } 342 }
343 343
344 return ret; 344 return ret;
345} 345}
346 346
347State* Keymap::getStateByLabel(const QString& label) { 347State* Keymap::getStateByLabel(const QString& label) {
348 QMap<QString, QString>::Iterator lit = labels.find(label); 348 QMap<QString, QString>::Iterator lit = labels.find(label);
349 State* state = 0; 349 State* state = 0;
350 350
351 if (lit == labels.end()) { 351 if (lit == labels.end()) {
352 return 0; 352 return 0;
353 } 353 }
354 354
355 QString name = lit.data(); 355 QString name = lit.data();
356 356
357 int n = name.find(":*"); 357 int n = name.find(":*");
358 if (n>=0 && n==(int)(name.length()-2)) { 358 if (n>=0 && n==(int)(name.length()-2)) {
359 name=name.left(name.length() - 1); 359 name=name.left(name.length() - 1);
360 360
361 n = currentStateName.findRev(":"); 361 n = currentStateName.findRev(":");
362 if (n >= 0) { 362 if (n >= 0) {
363 name += currentStateName.mid(n+1); 363 name += currentStateName.mid(n+1);
364 } 364 }
365 } 365 }
366 366
367 //odebug << "look for: " << (const char*) name.utf8() << "\n" << oendl; 367 //odebug << "look for: " << name.utf8() << "\n" << oendl;
368 QMap<QString, State*>::Iterator sit = states.find(name); 368 QMap<QString, State*>::Iterator sit = states.find(name);
369 if (sit != states.end()) { 369 if (sit != states.end()) {
370 state = sit.data(); 370 state = sit.data();
371 } 371 }
372 372
373 return state; 373 return state;
374} 374}
375 375
376bool Keymap::addState(const QString& name, State* state) { 376bool Keymap::addState(const QString& name, State* state) {
377 if (states.find(name) != states.end()) { 377 if (states.find(name) != states.end()) {
378 return false; 378 return false;
379 } 379 }
380 380
381 states.insert(name, state); 381 states.insert(name, state);
382 lsmapInSync = false; 382 lsmapInSync = false;
383 383
384 if (currentState == 0) { 384 if (currentState == 0) {
385 setCurrentState(state); 385 setCurrentState(state);
386 } 386 }
387 387
388 return true; 388 return true;
389} 389}
390 390
391State* Keymap::getCurrentState() const { 391State* Keymap::getCurrentState() const {
392 return currentState; 392 return currentState;
393} 393}
394 394
395QString Keymap::getCurrentLabel() { 395QString Keymap::getCurrentLabel() {
396 return currentLabel; 396 return currentLabel;
397} 397}
398 398
399bool Keymap::setCurrentState(State* state) { 399bool Keymap::setCurrentState(State* state) {
400 QMap<QString, State*>::Iterator it; 400 QMap<QString, State*>::Iterator it;
401 for(it = states.begin(); it != states.end(); ++it) { 401 for(it = states.begin(); it != states.end(); ++it) {
402 State* s = it.data(); 402 State* s = it.data();
403 if (s == state) { 403 if (s == state) {
404 currentState = s; 404 currentState = s;
405 currentStateName = it.key(); 405 currentStateName = it.key();
406 406
407 qDebug("state changed: %s\n", (const char*) 407 qDebug("state changed: %s\n", (const char*)
408 currentStateName.utf8()); 408 currentStateName.utf8());
409 409
410 if (!lsmapInSync) { 410 if (!lsmapInSync) {
411 generateLabelStateMaps(); 411 generateLabelStateMaps();
412 } 412 }
413 413
414 QMap<State*, QString>::Iterator tit; 414 QMap<State*, QString>::Iterator tit;
415 tit = stateLabelMap.find(state); 415 tit = stateLabelMap.find(state);
416 if (tit != stateLabelMap.end()) { 416 if (tit != stateLabelMap.end()) {
417 currentLabel = tit.data(); 417 currentLabel = tit.data();
418 } else { 418 } else {
419 // odebug << "no label for: " + currentStateName + "\n" << oendl; 419 // odebug << "no label for: " + currentStateName + "\n" << oendl;
420 currentLabel = ""; 420 currentLabel = "";
421 } 421 }
422 422
423 return true; 423 return true;
424 } 424 }
425 } 425 }
426 426
427 return false; 427 return false;
428} 428}
429 429
430bool Keymap::removeState(const QString& name, bool force) { 430bool Keymap::removeState(const QString& name, bool force) {
431 QMap<QString, State*>::Iterator it = states.find(name); 431 QMap<QString, State*>::Iterator it = states.find(name);
432 432
433 if (it == states.end()) { 433 if (it == states.end()) {
434 return false; 434 return false;
435 } 435 }
436 436
437 State* state = it.data(); 437 State* state = it.data();
438 QList<Action> acts = findStateUsage(state); 438 QList<Action> acts = findStateUsage(state);
439 439
440 if (!acts.isEmpty()) { 440 if (!acts.isEmpty()) {
441 if (!force) { 441 if (!force) {
442 return false; 442 return false;
443 } else { 443 } else {
444 for(Action* a = acts.first(); a != 0; a = acts.next()) { 444 for(Action* a = acts.first(); a != 0; a = acts.next()) {
445 a->setState(0); 445 a->setState(0);
446 } 446 }
447 } 447 }
448 } 448 }
449 449
450 if (state == currentState) { 450 if (state == currentState) {
451 if (states.begin() != states.end()) { 451 if (states.begin() != states.end()) {
452 setCurrentState(states.begin().data()); 452 setCurrentState(states.begin().data());
453 } 453 }
454 } 454 }
455 455
456 states.remove(it); 456 states.remove(it);
457 delete state; 457 delete state;
458 458
459 lsmapInSync = false; 459 lsmapInSync = false;
460 460
461 return true; 461 return true;
462} 462}
463 463
464void Keymap::autoRepeat() { 464void Keymap::autoRepeat() {
465 if (autoRepeatAction != 0) { 465 if (autoRepeatAction != 0) {
466 qDebug("filter:<<< unicode=%x, keycode=%x, modifiers=%x, " 466 qDebug("filter:<<< unicode=%x, keycode=%x, modifiers=%x, "
467 "ispressed=%x\n", autoRepeatAction->getUnicode(), 467 "ispressed=%x\n", autoRepeatAction->getUnicode(),
468 autoRepeatAction->getKeycode(), 468 autoRepeatAction->getKeycode(),
469 autoRepeatAction->getModifiers(), 469 autoRepeatAction->getModifiers(),
470 autoRepeatAction->isPressed()); 470 autoRepeatAction->isPressed());
471 471
472 QWSServer::sendKeyEvent(autoRepeatAction->getUnicode(), 472 QWSServer::sendKeyEvent(autoRepeatAction->getUnicode(),
473 autoRepeatAction->getKeycode(), 473 autoRepeatAction->getKeycode(),
474 autoRepeatAction->getModifiers(), 474 autoRepeatAction->getModifiers(),
475 autoRepeatAction->isPressed(), true); 475 autoRepeatAction->isPressed(), true);
476 } 476 }
477 477
478 repeater.start(repeatPeriod, TRUE); 478 repeater.start(repeatPeriod, TRUE);
479} 479}
480 480
481bool Keymap::addLabel(const QString& label, const QString& state, int index) { 481bool Keymap::addLabel(const QString& label, const QString& state, int index) {
482 if (labels.find(label) != labels.end()) { 482 if (labels.find(label) != labels.end()) {
483 return false; 483 return false;
484 } 484 }
485 485
486 labels.insert(label, state); 486 labels.insert(label, state);
487 const QString& l = labels.find(label).key(); 487 const QString& l = labels.find(label).key();
488 if (index == -1) { 488 if (index == -1) {
489 labelList.append(l); 489 labelList.append(l);
490 } else { 490 } else {
491 labelList.insert(labelList.at(index), l); 491 labelList.insert(labelList.at(index), l);
492 } 492 }
493 493
494 lsmapInSync = false; 494 lsmapInSync = false;
495 495
496 return true; 496 return true;
497} 497}
498 498
499bool Keymap::removeLabel(const QString& label) { 499bool Keymap::removeLabel(const QString& label) {
500 500
501 if (labels.find(label) == labels.end()) { 501 if (labels.find(label) == labels.end()) {
502 return false; 502 return false;
503 } 503 }
504 504
505 labels.remove(label); 505 labels.remove(label);
506 labelList.remove(label); 506 labelList.remove(label);
507 lsmapInSync = false; 507 lsmapInSync = false;
508 508
509 if (label == currentLabel) { 509 if (label == currentLabel) {
510 currentLabel = ""; 510 currentLabel = "";
511 } 511 }
512 512
513 return true; 513 return true;
514} 514}
515 515
516int Keymap::getAutorepeatDelay() const { 516int Keymap::getAutorepeatDelay() const {
517 return repeatDelay; 517 return repeatDelay;
518} 518}
519 519
520void Keymap::setAutorepeatDelay(int n) { 520void Keymap::setAutorepeatDelay(int n) {
521 repeatDelay = n; 521 repeatDelay = n;
522} 522}
523 523
524int Keymap::getAutorepeatPeriod() const { 524int Keymap::getAutorepeatPeriod() const {
525 return repeatPeriod; 525 return repeatPeriod;
526} 526}
527 527
528void Keymap::setAutorepeatPeriod(int n) { 528void Keymap::setAutorepeatPeriod(int n) {
529 repeatPeriod = n; 529 repeatPeriod = n;
530} 530}
531 531
532QList<Action> Keymap::findStateUsage(State* s) { 532QList<Action> Keymap::findStateUsage(State* s) {
533 QList<Action> ret; 533 QList<Action> ret;
534 534
535 QMap<QString, State*>::Iterator it; 535 QMap<QString, State*>::Iterator it;
536 for(it = states.begin(); it != states.end(); ++it) { 536 for(it = states.begin(); it != states.end(); ++it) {
537 State* state = it.data(); 537 State* state = it.data();
538 538
539 for(int i = 0; i < 0x1100; i++) { 539 for(int i = 0; i < 0x1100; i++) {
540 Action* action = state->get(i, false); 540 Action* action = state->get(i, false);
541 if (action!=0 && action->getState()==s) { 541 if (action!=0 && action->getState()==s) {
542 ret.append(action); 542 ret.append(action);
543 } 543 }
544 544
545 action = state->get(i, true); 545 action = state->get(i, true);
546 if (action!=0 && action->getState()==s) { 546 if (action!=0 && action->getState()==s) {
547 ret.append(action); 547 ret.append(action);
548 } 548 }
549 } 549 }
550 } 550 }
551 551
552 return ret; 552 return ret;
553} 553}
554 554
555void Keymap::generateLabelStateMaps() { 555void Keymap::generateLabelStateMaps() {
556 stateLabelMap.clear(); 556 stateLabelMap.clear();
557 557
558 QMap<QString, QString>::Iterator lit; 558 QMap<QString, QString>::Iterator lit;
559 for(lit = labels.begin(); lit != labels.end(); ++lit) { 559 for(lit = labels.begin(); lit != labels.end(); ++lit) {
560 QString label = lit.key(); 560 QString label = lit.key();
561 QString name = lit.data(); 561 QString name = lit.data();
562 562
563 bool wc = false; 563 bool wc = false;
564 int n = name.find("*"); 564 int n = name.find("*");
565 if (n>=0 && n==(int)(name.length()-1)) { 565 if (n>=0 && n==(int)(name.length()-1)) {
566 name=name.left(name.length() - 1); 566 name=name.left(name.length() - 1);
567 wc = true; 567 wc = true;
568 } 568 }
569 569
570 QMap<QString, State*>::Iterator sit; 570 QMap<QString, State*>::Iterator sit;
571 for(sit = states.begin(); sit != states.end(); ++sit) { 571 for(sit = states.begin(); sit != states.end(); ++sit) {
572 QString sname = sit.key(); 572 QString sname = sit.key();
573 State* state = sit.data(); 573 State* state = sit.data();
574 574
575 if (sname.length() < name.length()) { 575 if (sname.length() < name.length()) {
576 continue; 576 continue;
577 } 577 }
578 578
579 if (sname.left(name.length()) == name) { 579 if (sname.left(name.length()) == name) {
580 if (wc || sname.length()==name.length()) { 580 if (wc || sname.length()==name.length()) {
581 stateLabelMap.insert(state, label); 581 stateLabelMap.insert(state, label);
582 } 582 }
583 583
584 } 584 }
585 } 585 }
586 } 586 }
587 587
588 lsmapInSync = true; 588 lsmapInSync = true;
589} 589}
diff --git a/noncore/apps/keyz-cfg/zkbcfg.cpp b/noncore/apps/keyz-cfg/zkbcfg.cpp
index f1d53ba..24bd897 100644
--- a/noncore/apps/keyz-cfg/zkbcfg.cpp
+++ b/noncore/apps/keyz-cfg/zkbcfg.cpp
@@ -1,231 +1,231 @@
1#include "zkbcfg.h" 1#include "zkbcfg.h"
2 2
3/* OPIE */ 3/* OPIE */
4#include <opie2/odebug.h> 4#include <opie2/odebug.h>
5using namespace Opie::Core; 5using namespace Opie::Core;
6 6
7/* QT */ 7/* QT */
8#include <qfileinfo.h> 8#include <qfileinfo.h>
9 9
10// Implementation of XkbConfig class 10// Implementation of XkbConfig class
11ZkbConfig::ZkbConfig(const QString& dir):path(dir) { 11ZkbConfig::ZkbConfig(const QString& dir):path(dir) {
12} 12}
13 13
14ZkbConfig::~ZkbConfig() { 14ZkbConfig::~ZkbConfig() {
15} 15}
16 16
17bool ZkbConfig::load(const QString& file, Keymap& keymap, const QString& prefix) { 17bool ZkbConfig::load(const QString& file, Keymap& keymap, const QString& prefix) {
18 bool ret; 18 bool ret;
19 QFile f(path+"/"+file); 19 QFile f(path+"/"+file);
20 QFileInfo fi(f); 20 QFileInfo fi(f);
21 21
22 odebug << "start loading file=" << (const char*) file.utf8() << "\n" << oendl; 22 odebug << "start loading file=" << file.utf8() << "\n" << oendl;
23 if (includedFiles.find(fi.absFilePath()) != includedFiles.end()) { 23 if (includedFiles.find(fi.absFilePath()) != includedFiles.end()) {
24 return false; 24 return false;
25 } 25 }
26 26
27 includedFiles.insert(fi.absFilePath(), 1); 27 includedFiles.insert(fi.absFilePath(), 1);
28 QXmlInputSource is(f); 28 QXmlInputSource is(f);
29 QXmlSimpleReader reader; 29 QXmlSimpleReader reader;
30 ZkbHandler h(*this, keymap, prefix); 30 ZkbHandler h(*this, keymap, prefix);
31 31
32 reader.setContentHandler(&h); 32 reader.setContentHandler(&h);
33 reader.setErrorHandler(this); 33 reader.setErrorHandler(this);
34 ret = reader.parse(is); 34 ret = reader.parse(is);
35 includedFiles.remove(fi.absFilePath()); 35 includedFiles.remove(fi.absFilePath());
36 36
37 odebug << "end loading file=" << file.utf8() << ": status=" << err.utf8() << oendl; 37 odebug << "end loading file=" << file.utf8() << ": status=" << err.utf8() << oendl;
38 return ret; 38 return ret;
39} 39}
40 40
41bool ZkbConfig::warning(const QXmlParseException& e) { 41bool ZkbConfig::warning(const QXmlParseException& e) {
42 QString tmp; 42 QString tmp;
43 43
44 tmp.sprintf("%d: warning: %s\n", e.lineNumber(), 44 tmp.sprintf("%d: warning: %s\n", e.lineNumber(),
45 (const char*) e.message().utf8()); 45 (const char*) e.message().utf8());
46 46
47 err += tmp; 47 err += tmp;
48 48
49 return true; 49 return true;
50} 50}
51 51
52bool ZkbConfig::error(const QXmlParseException& e) { 52bool ZkbConfig::error(const QXmlParseException& e) {
53 QString tmp; 53 QString tmp;
54 54
55 tmp.sprintf("%d: error: %s\n", e.lineNumber(), 55 tmp.sprintf("%d: error: %s\n", e.lineNumber(),
56 (const char*) e.message().utf8()); 56 (const char*) e.message().utf8());
57 57
58 err += tmp; 58 err += tmp;
59 59
60 return true; 60 return true;
61} 61}
62 62
63bool ZkbConfig::fatalError(const QXmlParseException& e) { 63bool ZkbConfig::fatalError(const QXmlParseException& e) {
64 QString tmp; 64 QString tmp;
65 65
66 tmp.sprintf("%d: fatal error: %s\n", e.lineNumber(), 66 tmp.sprintf("%d: fatal error: %s\n", e.lineNumber(),
67 (const char*) e.message().utf8()); 67 (const char*) e.message().utf8());
68 68
69 err += tmp; 69 err += tmp;
70 70
71 return false; 71 return false;
72} 72}
73 73
74QString ZkbConfig::errorString() { 74QString ZkbConfig::errorString() {
75 return err; 75 return err;
76} 76}
77 77
78// Implementation of ZkbHandler 78// Implementation of ZkbHandler
79ZkbHandler::ZkbHandler(ZkbConfig& z, Keymap& k, const QString& p):zkc(z), keymap(k), 79ZkbHandler::ZkbHandler(ZkbConfig& z, Keymap& k, const QString& p):zkc(z), keymap(k),
80 prefix(p), ardelay(-1), arperiod(-1), currentState(0), currentAction(0) { 80 prefix(p), ardelay(-1), arperiod(-1), currentState(0), currentAction(0) {
81} 81}
82 82
83ZkbHandler::~ZkbHandler() { 83ZkbHandler::~ZkbHandler() {
84} 84}
85 85
86bool ZkbHandler::startKeymapElement(int ard, int arp, const QString&) { 86bool ZkbHandler::startKeymapElement(int ard, int arp, const QString&) {
87 ardelay = ard; 87 ardelay = ard;
88 arperiod = arp; 88 arperiod = arp;
89 89
90 return true; 90 return true;
91} 91}
92 92
93bool ZkbHandler::startIncludeElement(const QString& file, 93bool ZkbHandler::startIncludeElement(const QString& file,
94 const QString& pref) { 94 const QString& pref) {
95 95
96 QString p = prefix; 96 QString p = prefix;
97 97
98 if (!pref.isNull()) { 98 if (!pref.isNull()) {
99 p += pref + ":"; 99 p += pref + ":";
100 } 100 }
101 101
102 102
103 bool ret = zkc.load(file, keymap, p); 103 bool ret = zkc.load(file, keymap, p);
104 if (!ret) { 104 if (!ret) {
105 setError("Error including file: " + file); 105 setError("Error including file: " + file);
106 } 106 }
107 107
108 return ret; 108 return ret;
109} 109}
110 110
111bool ZkbHandler::startLabelElement(const QString& label, 111bool ZkbHandler::startLabelElement(const QString& label,
112 const QString& state) { 112 const QString& state) {
113 113
114 if (!keymap.addLabel(label, prefix + state)) { 114 if (!keymap.addLabel(label, prefix + state)) {
115 err = "label " + label + " already defined"; 115 err = "label " + label + " already defined";
116 return false; 116 return false;
117 } 117 }
118 118
119 return true; 119 return true;
120} 120}
121 121
122bool ZkbHandler::startStateElement(const QString& name, 122bool ZkbHandler::startStateElement(const QString& name,
123 const QString& parentName, bool dflt) { 123 const QString& parentName, bool dflt) {
124 124
125 currentStateName = prefix + name; 125 currentStateName = prefix + name;
126 currentState = keymap.getStateByName(currentStateName); 126 currentState = keymap.getStateByName(currentStateName);
127 127
128 //odebug << "state name=" << (const char*) currentStateName.utf8() << "\n" << oendl; 128 //odebug << "state name=" << currentStateName.utf8() << "\n" << oendl;
129 129
130 State* parent = 0; 130 State* parent = 0;
131 if (!parentName.isEmpty()) { 131 if (!parentName.isEmpty()) {
132 QString pn = prefix + parentName; 132 QString pn = prefix + parentName;
133 parent = keymap.getStateByName(pn); 133 parent = keymap.getStateByName(pn);
134 if (parent == 0) { 134 if (parent == 0) {
135 err = currentStateName + 135 err = currentStateName +
136 ": undefined parent state: " + pn; 136 ": undefined parent state: " + pn;
137 return false; 137 return false;
138 } 138 }
139 } 139 }
140 140
141 if (currentState == 0) { 141 if (currentState == 0) {
142 currentState = new State(parent); 142 currentState = new State(parent);
143 keymap.addState(currentStateName, currentState); 143 keymap.addState(currentStateName, currentState);
144 } else { 144 } else {
145 if (parent!=0) { 145 if (parent!=0) {
146 currentState->setParent(parent); 146 currentState->setParent(parent);
147 } 147 }
148 } 148 }
149 149
150 if (dflt) { 150 if (dflt) {
151 keymap.setCurrentState(currentState); 151 keymap.setCurrentState(currentState);
152 } 152 }
153 153
154 return true; 154 return true;
155} 155}
156 156
157bool ZkbHandler::startMapElement(int keycode, bool pressed) { 157bool ZkbHandler::startMapElement(int keycode, bool pressed) {
158 currentAction = currentState->get(keycode, pressed); 158 currentAction = currentState->get(keycode, pressed);
159 if (currentAction == 0) { 159 if (currentAction == 0) {
160 setError("keycode " + QString::number(keycode) + " not supported"); 160 setError("keycode " + QString::number(keycode) + " not supported");
161 return false; 161 return false;
162 } 162 }
163 163
164 currentAction->setEvent(false); 164 currentAction->setEvent(false);
165 currentAction->setState(0); 165 currentAction->setState(0);
166 166
167 return true; 167 return true;
168} 168}
169 169
170bool ZkbHandler::startEventElement(int keycode, int unicode, int modifiers, 170bool ZkbHandler::startEventElement(int keycode, int unicode, int modifiers,
171 bool pressed, bool autorepeat) { 171 bool pressed, bool autorepeat) {
172 172
173 currentAction->setEvent(true); 173 currentAction->setEvent(true);
174 currentAction->setKeycode(keycode); 174 currentAction->setKeycode(keycode);
175 currentAction->setUnicode(unicode); 175 currentAction->setUnicode(unicode);
176 currentAction->setModifiers(modifiers); 176 currentAction->setModifiers(modifiers);
177 currentAction->setPressed(pressed); 177 currentAction->setPressed(pressed);
178 currentAction->setAutorepeat(autorepeat); 178 currentAction->setAutorepeat(autorepeat);
179 179
180 return true; 180 return true;
181} 181}
182 182
183bool ZkbHandler::startNextStateElement(const QString& state) { 183bool ZkbHandler::startNextStateElement(const QString& state) {
184 State* s = keymap.getStateByName(prefix + state); 184 State* s = keymap.getStateByName(prefix + state);
185 if (s == 0) { 185 if (s == 0) {
186 setError("undefine state: " + prefix + state); 186 setError("undefine state: " + prefix + state);
187 return false; 187 return false;
188 } 188 }
189 189
190 currentAction->setState(s); 190 currentAction->setState(s);
191 return true; 191 return true;
192} 192}
193 193
194 194
195bool ZkbHandler::endKeymapElement() { 195bool ZkbHandler::endKeymapElement() {
196 if (ardelay > 0) { 196 if (ardelay > 0) {
197 keymap.setAutorepeatDelay(ardelay); 197 keymap.setAutorepeatDelay(ardelay);
198 } 198 }
199 199
200 if (arperiod > 0) { 200 if (arperiod > 0) {
201 keymap.setAutorepeatPeriod(arperiod); 201 keymap.setAutorepeatPeriod(arperiod);
202 } 202 }
203 203
204 return true; 204 return true;
205} 205}
206 206
207bool ZkbHandler::endIncludeElement() { 207bool ZkbHandler::endIncludeElement() {
208 return true; 208 return true;
209} 209}
210 210
211bool ZkbHandler::endLabelElement() { 211bool ZkbHandler::endLabelElement() {
212 return true; 212 return true;
213} 213}
214 214
215bool ZkbHandler::endStateElement() { 215bool ZkbHandler::endStateElement() {
216 currentState = 0; 216 currentState = 0;
217 return true; 217 return true;
218} 218}
219 219
220bool ZkbHandler::endMapElement() { 220bool ZkbHandler::endMapElement() {
221 currentAction = 0; 221 currentAction = 0;
222 return true; 222 return true;
223} 223}
224 224
225bool ZkbHandler::endEventElement() { 225bool ZkbHandler::endEventElement() {
226 return true; 226 return true;
227} 227}
228 228
229bool ZkbHandler::endNextStateElement() { 229bool ZkbHandler::endNextStateElement() {
230 return true; 230 return true;
231} 231}
diff --git a/noncore/net/wellenreiter/gui/configwindow.cpp b/noncore/net/wellenreiter/gui/configwindow.cpp
index bfdb20a..279b39c 100644
--- a/noncore/net/wellenreiter/gui/configwindow.cpp
+++ b/noncore/net/wellenreiter/gui/configwindow.cpp
@@ -1,476 +1,476 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved. 2** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved.
3** 3**
4** This file is part of Wellenreiter II. 4** This file is part of Wellenreiter II.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14**********************************************************************/ 14**********************************************************************/
15 15
16/* LOCAL */ 16/* LOCAL */
17#include "configwindow.h" 17#include "configwindow.h"
18#include "mainwindow.h" 18#include "mainwindow.h"
19 19
20/* OPIE */ 20/* OPIE */
21#include <opie2/onetwork.h> 21#include <opie2/onetwork.h>
22#ifdef QWS 22#ifdef QWS
23#include <opie2/oapplication.h> 23#include <opie2/oapplication.h>
24#include <opie2/oconfig.h> 24#include <opie2/oconfig.h>
25#include <opie2/odevice.h> 25#include <opie2/odevice.h>
26#include <opie2/odebug.h> 26#include <opie2/odebug.h>
27using namespace Opie::Core; 27using namespace Opie::Core;
28using namespace Opie::Net; 28using namespace Opie::Net;
29#endif 29#endif
30 30
31/* QT */ 31/* QT */
32#include <qapplication.h> 32#include <qapplication.h>
33#include <qcheckbox.h> 33#include <qcheckbox.h>
34#include <qcombobox.h> 34#include <qcombobox.h>
35#include <qfile.h> 35#include <qfile.h>
36#include <qlineedit.h> 36#include <qlineedit.h>
37#include <qlayout.h> 37#include <qlayout.h>
38#include <qmap.h> 38#include <qmap.h>
39#include <qpushbutton.h> 39#include <qpushbutton.h>
40#include <qtabwidget.h> 40#include <qtabwidget.h>
41#include <qtoolbutton.h> 41#include <qtoolbutton.h>
42#include <qspinbox.h> 42#include <qspinbox.h>
43#include <qtextstream.h> 43#include <qtextstream.h>
44 44
45/* STD */ 45/* STD */
46#include <assert.h> 46#include <assert.h>
47 47
48WellenreiterConfigWindow* WellenreiterConfigWindow::_instance = 0; 48WellenreiterConfigWindow* WellenreiterConfigWindow::_instance = 0;
49 49
50WellenreiterConfigWindow::WellenreiterConfigWindow( QWidget * parent, const char * name, WFlags f ) 50WellenreiterConfigWindow::WellenreiterConfigWindow( QWidget * parent, const char * name, WFlags f )
51 :WellenreiterConfigBase( parent, name, true, f ) 51 :WellenreiterConfigBase( parent, name, true, f )
52{ 52{
53 _devicetype[ "cisco" ] = DEVTYPE_CISCO; 53 _devicetype[ "cisco" ] = DEVTYPE_CISCO;
54 _devicetype[ "wlan-ng" ] = DEVTYPE_WLAN_NG; 54 _devicetype[ "wlan-ng" ] = DEVTYPE_WLAN_NG;
55 _devicetype[ "hostap" ] = DEVTYPE_HOSTAP; 55 _devicetype[ "hostap" ] = DEVTYPE_HOSTAP;
56 _devicetype[ "orinoco" ] = DEVTYPE_ORINOCO; 56 _devicetype[ "orinoco" ] = DEVTYPE_ORINOCO;
57 _devicetype[ "<manual>" ] = DEVTYPE_MANUAL; 57 _devicetype[ "<manual>" ] = DEVTYPE_MANUAL;
58 _devicetype[ "<file>" ] = DEVTYPE_FILE; 58 _devicetype[ "<file>" ] = DEVTYPE_FILE;
59 59
60 // gather possible interface names from ONetwork 60 // gather possible interface names from ONetwork
61 ONetwork* net = ONetwork::instance(); 61 ONetwork* net = ONetwork::instance();
62 ONetwork::InterfaceIterator it = net->iterator(); 62 ONetwork::InterfaceIterator it = net->iterator();
63 while ( it.current() ) 63 while ( it.current() )
64 { 64 {
65 if ( it.current()->isWireless() ) 65 if ( it.current()->isWireless() )
66 interfaceName->insertItem( it.current()->name() ); 66 interfaceName->insertItem( it.current()->name() );
67 ++it; 67 ++it;
68 } 68 }
69 69
70 load(); 70 load();
71 71
72 #ifdef Q_WS_X11 // We're on X11: adding an Ok-Button for the Dialog here 72 #ifdef Q_WS_X11 // We're on X11: adding an Ok-Button for the Dialog here
73 QPushButton* okButton = new QPushButton( "ok", this ); 73 QPushButton* okButton = new QPushButton( "ok", this );
74 okButton->show(); 74 okButton->show();
75 WellenreiterConfigBaseLayout->addWidget( okButton, 0, 3 ); //FIXME: rename this in configbase.ui 75 WellenreiterConfigBaseLayout->addWidget( okButton, 0, 3 ); //FIXME: rename this in configbase.ui
76 connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); 76 connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
77 #endif 77 #endif
78 78
79 WellenreiterConfigWindow::_instance = this; 79 WellenreiterConfigWindow::_instance = this;
80 80
81 connect( deviceType, SIGNAL( activated(int) ), this, SLOT( changedDeviceType(int) ) ); 81 connect( deviceType, SIGNAL( activated(int) ), this, SLOT( changedDeviceType(int) ) );
82 connect( newNetworkAction, SIGNAL( activated(int) ), this, SLOT( changedNetworkAction(int) ) ); 82 connect( newNetworkAction, SIGNAL( activated(int) ), this, SLOT( changedNetworkAction(int) ) );
83 connect( newClientAction, SIGNAL( activated(int) ), this, SLOT( changedClientAction(int) ) ); 83 connect( newClientAction, SIGNAL( activated(int) ), this, SLOT( changedClientAction(int) ) );
84 connect( newStationAction, SIGNAL( activated(int) ), this, SLOT( changedStationAction(int) ) ); 84 connect( newStationAction, SIGNAL( activated(int) ), this, SLOT( changedStationAction(int) ) );
85 connect( getCaptureFileName, SIGNAL( clicked() ), this, SLOT( getCaptureFileNameClicked() ) ); 85 connect( getCaptureFileName, SIGNAL( clicked() ), this, SLOT( getCaptureFileNameClicked() ) );
86 86
87 // make the checkbox 'channelAll' control all other channels 87 // make the checkbox 'channelAll' control all other channels
88 connect( channelAll, SIGNAL( stateChanged(int) ), this, SLOT( channelAllClicked(int) ) ); 88 connect( channelAll, SIGNAL( stateChanged(int) ), this, SLOT( channelAllClicked(int) ) );
89 89
90 connect( autodetect, SIGNAL( clicked() ), this, SLOT( performAutodetection() ) ); 90 connect( autodetect, SIGNAL( clicked() ), this, SLOT( performAutodetection() ) );
91 91
92 // hide tab4 (parse) until Wellenreiter 1.2 92 // hide tab4 (parse) until Wellenreiter 1.2
93 tab->removePage( tab_4 ); 93 tab->removePage( tab_4 );
94}; 94};
95 95
96 96
97void WellenreiterConfigWindow::accept() 97void WellenreiterConfigWindow::accept()
98{ 98{
99 save(); 99 save();
100 QDialog::accept(); 100 QDialog::accept();
101} 101}
102 102
103 103
104WellenreiterConfigWindow::~WellenreiterConfigWindow() 104WellenreiterConfigWindow::~WellenreiterConfigWindow()
105{ 105{
106} 106}
107 107
108 108
109void WellenreiterConfigWindow::performAutodetection() 109void WellenreiterConfigWindow::performAutodetection()
110{ 110{
111 //TODO: insert modal splash screen here 111 //TODO: insert modal splash screen here
112 // and sleep a second, so that it looks 112 // and sleep a second, so that it looks
113 // like we're actually doing something fancy... ;-) 113 // like we're actually doing something fancy... ;-)
114 114
115 odebug << "WellenreiterConfigWindow::performAutodetection()" << oendl; 115 odebug << "WellenreiterConfigWindow::performAutodetection()" << oendl;
116 116
117 // try to guess device type 117 // try to guess device type
118 QFile m( "/proc/modules" ); 118 QFile m( "/proc/modules" );
119 if ( m.open( IO_ReadOnly ) ) 119 if ( m.open( IO_ReadOnly ) )
120 { 120 {
121 int devicetype(0); 121 int devicetype(0);
122 QString line; 122 QString line;
123 QTextStream modules( &m ); 123 QTextStream modules( &m );
124 while( !modules.atEnd() && !devicetype ) 124 while( !modules.atEnd() && !devicetype )
125 { 125 {
126 modules >> line; 126 modules >> line;
127 if ( line.contains( "cisco" ) ) devicetype = DEVTYPE_CISCO; 127 if ( line.contains( "cisco" ) ) devicetype = DEVTYPE_CISCO;
128 else if ( line.contains( "hostap" ) ) devicetype = DEVTYPE_HOSTAP; 128 else if ( line.contains( "hostap" ) ) devicetype = DEVTYPE_HOSTAP;
129 else if ( line.contains( "prism" ) ) devicetype = DEVTYPE_WLAN_NG; 129 else if ( line.contains( "prism" ) ) devicetype = DEVTYPE_WLAN_NG;
130 else if ( line.contains( "orinoco" ) ) devicetype = DEVTYPE_ORINOCO; 130 else if ( line.contains( "orinoco" ) ) devicetype = DEVTYPE_ORINOCO;
131 } 131 }
132 if ( devicetype ) 132 if ( devicetype )
133 { 133 {
134 deviceType->setCurrentItem( devicetype ); 134 deviceType->setCurrentItem( devicetype );
135 _guess = devicetype; 135 _guess = devicetype;
136 odebug << "Wellenreiter: guessed device type to be #" << devicetype << "" << oendl; 136 odebug << "Wellenreiter: guessed device type to be #" << devicetype << "" << oendl;
137 } 137 }
138 } 138 }
139} 139}
140 140
141 141
142int WellenreiterConfigWindow::driverType() const 142int WellenreiterConfigWindow::driverType() const
143{ 143{
144 QString name = deviceType->currentText(); 144 QString name = deviceType->currentText();
145 if ( _devicetype.contains( name ) ) 145 if ( _devicetype.contains( name ) )
146 { 146 {
147 return _devicetype[name]; 147 return _devicetype[name];
148 } 148 }
149 else 149 else
150 { 150 {
151 return 0; 151 return 0;
152 } 152 }
153}; 153};
154 154
155 155
156int WellenreiterConfigWindow::hoppingInterval() const 156int WellenreiterConfigWindow::hoppingInterval() const
157{ 157{
158 return hopInterval->cleanText().toInt(); 158 return hopInterval->cleanText().toInt();
159} 159}
160 160
161 161
162bool WellenreiterConfigWindow::usePrismHeader() const 162bool WellenreiterConfigWindow::usePrismHeader() const
163{ 163{
164 return prismHeader->isChecked(); 164 return prismHeader->isChecked();
165} 165}
166 166
167 167
168bool WellenreiterConfigWindow::isChannelChecked( int channel ) const 168bool WellenreiterConfigWindow::isChannelChecked( int channel ) const
169{ 169{
170 switch ( channel ) 170 switch ( channel )
171 { 171 {
172 case 1: return channel1->isOn(); 172 case 1: return channel1->isOn();
173 case 2: return channel2->isOn(); 173 case 2: return channel2->isOn();
174 case 3: return channel3->isOn(); 174 case 3: return channel3->isOn();
175 case 4: return channel4->isOn(); 175 case 4: return channel4->isOn();
176 case 5: return channel5->isOn(); 176 case 5: return channel5->isOn();
177 case 6: return channel6->isOn(); 177 case 6: return channel6->isOn();
178 case 7: return channel7->isOn(); 178 case 7: return channel7->isOn();
179 case 8: return channel8->isOn(); 179 case 8: return channel8->isOn();
180 case 9: return channel9->isOn(); 180 case 9: return channel9->isOn();
181 case 10: return channel10->isOn(); 181 case 10: return channel10->isOn();
182 case 11: return channel11->isOn(); 182 case 11: return channel11->isOn();
183 case 12: return channel12->isOn(); 183 case 12: return channel12->isOn();
184 case 13: return channel13->isOn(); 184 case 13: return channel13->isOn();
185 case 14: return channel14->isOn(); 185 case 14: return channel14->isOn();
186 } 186 }
187} 187}
188 188
189 189
190void WellenreiterConfigWindow::changedDeviceType(int t) 190void WellenreiterConfigWindow::changedDeviceType(int t)
191{ 191{
192 if ( t != DEVTYPE_FILE ) return; 192 if ( t != DEVTYPE_FILE ) return;
193 QString name = ( (WellenreiterMainWindow*) qApp->mainWidget() )->getFileName(false); 193 QString name = ( (WellenreiterMainWindow*) qApp->mainWidget() )->getFileName(false);
194 if ( !name.isEmpty() && QFile::exists( name ) ) 194 if ( !name.isEmpty() && QFile::exists( name ) )
195 { 195 {
196 interfaceName->insertItem( name ); 196 interfaceName->insertItem( name );
197 interfaceName->setCurrentItem( interfaceName->count()-1 ); 197 interfaceName->setCurrentItem( interfaceName->count()-1 );
198 } 198 }
199 else 199 else
200 { 200 {
201 deviceType->setCurrentItem( _guess ); 201 deviceType->setCurrentItem( _guess );
202 } 202 }
203 203
204} 204}
205 205
206 206
207void WellenreiterConfigWindow::synchronizeActionsAndScripts() 207void WellenreiterConfigWindow::synchronizeActionsAndScripts()
208{ 208{
209 if ( newNetworkAction->currentItem() == 4 ) newNetworkScript->show(); else newNetworkScript->hide(); 209 if ( newNetworkAction->currentItem() == 4 ) newNetworkScript->show(); else newNetworkScript->hide();
210 if ( newClientAction->currentItem() == 4 ) newClientScript->show(); else newClientScript->hide(); 210 if ( newClientAction->currentItem() == 4 ) newClientScript->show(); else newClientScript->hide();
211 if ( newStationAction->currentItem() == 4 ) newStationScript->show(); else newStationScript->hide(); 211 if ( newStationAction->currentItem() == 4 ) newStationScript->show(); else newStationScript->hide();
212 212
213 //newNetworkScript->setEnabled( newNetworkAction->currentItem() == 4 ); 213 //newNetworkScript->setEnabled( newNetworkAction->currentItem() == 4 );
214 //newClientScript->setEnabled( newClientAction->currentItem() == 4 ); 214 //newClientScript->setEnabled( newClientAction->currentItem() == 4 );
215 //newStationScript->setEnabled( newStationAction->currentItem() == 4 ); 215 //newStationScript->setEnabled( newStationAction->currentItem() == 4 );
216} 216}
217 217
218 218
219void WellenreiterConfigWindow::changedNetworkAction(int t) 219void WellenreiterConfigWindow::changedNetworkAction(int t)
220{ 220{
221 synchronizeActionsAndScripts(); 221 synchronizeActionsAndScripts();
222} 222}
223 223
224 224
225void WellenreiterConfigWindow::changedClientAction(int t) 225void WellenreiterConfigWindow::changedClientAction(int t)
226{ 226{
227 synchronizeActionsAndScripts(); 227 synchronizeActionsAndScripts();
228} 228}
229 229
230 230
231void WellenreiterConfigWindow::changedStationAction(int t) 231void WellenreiterConfigWindow::changedStationAction(int t)
232{ 232{
233 synchronizeActionsAndScripts(); 233 synchronizeActionsAndScripts();
234} 234}
235 235
236 236
237void WellenreiterConfigWindow::getCaptureFileNameClicked() 237void WellenreiterConfigWindow::getCaptureFileNameClicked()
238{ 238{
239 QString name = ( (WellenreiterMainWindow*) qApp->mainWidget() )->getFileName(true); 239 QString name = ( (WellenreiterMainWindow*) qApp->mainWidget() )->getFileName(true);
240 odebug << "name = " << (const char*) name << "" << oendl; 240 odebug << "name = " << name << "" << oendl;
241 if ( !name.isEmpty() ) 241 if ( !name.isEmpty() )
242 { 242 {
243 captureFileName->setText( name ); 243 captureFileName->setText( name );
244 } 244 }
245} 245}
246 246
247 247
248void WellenreiterConfigWindow::channelAllClicked(int state) 248void WellenreiterConfigWindow::channelAllClicked(int state)
249{ 249{
250 bool b = state; 250 bool b = state;
251 channel1->setChecked( b ); 251 channel1->setChecked( b );
252 channel2->setChecked( b ); 252 channel2->setChecked( b );
253 channel3->setChecked( b ); 253 channel3->setChecked( b );
254 channel4->setChecked( b ); 254 channel4->setChecked( b );
255 channel5->setChecked( b ); 255 channel5->setChecked( b );
256 channel6->setChecked( b ); 256 channel6->setChecked( b );
257 channel7->setChecked( b ); 257 channel7->setChecked( b );
258 channel8->setChecked( b ); 258 channel8->setChecked( b );
259 channel9->setChecked( b ); 259 channel9->setChecked( b );
260 channel10->setChecked( b ); 260 channel10->setChecked( b );
261 channel11->setChecked( b ); 261 channel11->setChecked( b );
262 channel12->setChecked( b ); 262 channel12->setChecked( b );
263 channel13->setChecked( b ); 263 channel13->setChecked( b );
264 channel14->setChecked( b ); 264 channel14->setChecked( b );
265} 265}
266 266
267 267
268bool WellenreiterConfigWindow::useGPS() const 268bool WellenreiterConfigWindow::useGPS() const
269{ 269{
270 return enableGPS->isChecked(); 270 return enableGPS->isChecked();
271} 271}
272 272
273 273
274const QString WellenreiterConfigWindow::gpsHost() const 274const QString WellenreiterConfigWindow::gpsHost() const
275{ 275{
276 return useGPS() ? gpsdHost->currentText() : QString::null; 276 return useGPS() ? gpsdHost->currentText() : QString::null;
277} 277}
278 278
279 279
280int WellenreiterConfigWindow::gpsPort() const 280int WellenreiterConfigWindow::gpsPort() const
281{ 281{
282 bool ok; 282 bool ok;
283 return useGPS() ? gpsdPort->value() : -1; 283 return useGPS() ? gpsdPort->value() : -1;
284} 284}
285 285
286 286
287void WellenreiterConfigWindow::performAction( const QString& type, 287void WellenreiterConfigWindow::performAction( const QString& type,
288 const QString& essid, 288 const QString& essid,
289 const QString& mac, 289 const QString& mac,
290 bool wep, 290 bool wep,
291 int channel, 291 int channel,
292 int signal 292 int signal
293 /* , const GpsLocation& loc */ ) 293 /* , const GpsLocation& loc */ )
294{ 294{
295 int action; 295 int action;
296 QString script; 296 QString script;
297 297
298 if ( type == "network" ) 298 if ( type == "network" )
299 { 299 {
300 action = newNetworkAction->currentItem(); 300 action = newNetworkAction->currentItem();
301 script = newNetworkScript->text(); 301 script = newNetworkScript->text();
302 } 302 }
303 else if ( type == "managed" || type == "adhoc" ) 303 else if ( type == "managed" || type == "adhoc" )
304 { 304 {
305 action = newClientAction->currentItem(); 305 action = newClientAction->currentItem();
306 script = newClientScript->text(); 306 script = newClientScript->text();
307 } 307 }
308 else if ( type == "station" ) 308 else if ( type == "station" )
309 { 309 {
310 action = newStationAction->currentItem(); 310 action = newStationAction->currentItem();
311 script = newStationScript->text(); 311 script = newStationScript->text();
312 } 312 }
313 else 313 else
314 { 314 {
315 owarn << "WellenreiterConfigWindow::performAction(): unknown type '" << (const char*) type << "'" << oendl; 315 owarn << "WellenreiterConfigWindow::performAction(): unknown type '" << type << "'" << oendl;
316 return; 316 return;
317 } 317 }
318 318
319 odebug << "for event '" << (const char*) type << "' I'm going to perform action " << action << " (script='" << (const char*) script << "')" << oendl; 319 odebug << "for event '" << (const char*) type << "' I'm going to perform action " << action << " (script='" << script << "')" << oendl;
320 320
321 switch( action ) 321 switch( action )
322 { 322 {
323 case 0: /* Ignore */ return; 323 case 0: /* Ignore */ return;
324 case 1: /* Play Alarm */ ODevice::inst()->playAlarmSound(); return; 324 case 1: /* Play Alarm */ ODevice::inst()->playAlarmSound(); return;
325 case 2: /* Play Click */ ODevice::inst()->playTouchSound(); return; 325 case 2: /* Play Click */ ODevice::inst()->playTouchSound(); return;
326 case 3: /* Blink LED */ break; //FIXME: Implement this 326 case 3: /* Blink LED */ break; //FIXME: Implement this
327 case 4: /* Run Script */ 327 case 4: /* Run Script */
328 { 328 {
329 /** 329 /**
330 * 330 *
331 * Script Substitution Information: 331 * Script Substitution Information:
332 * 332 *
333 * $SSID = SSID 333 * $SSID = SSID
334 * $MAC = MAC 334 * $MAC = MAC
335 * $WEP = Wep 335 * $WEP = Wep
336 * $CHAN = Channel 336 * $CHAN = Channel
337 * 337 *
338 **/ 338 **/
339 script = script.replace( QRegExp( "$SSID" ), essid ); 339 script = script.replace( QRegExp( "$SSID" ), essid );
340 script = script.replace( QRegExp( "$MAC" ), mac ); 340 script = script.replace( QRegExp( "$MAC" ), mac );
341 script = script.replace( QRegExp( "$WEP" ), wep ? QString( "true" ) : QString( "false" ) ); 341 script = script.replace( QRegExp( "$WEP" ), wep ? QString( "true" ) : QString( "false" ) );
342 script = script.replace( QRegExp( "$CHAN" ), QString::number( channel ) ); 342 script = script.replace( QRegExp( "$CHAN" ), QString::number( channel ) );
343 343
344 odebug << "going to call script '" << (const char*) script << "'" << oendl; 344 odebug << "going to call script '" << script << "'" << oendl;
345 ::system( script ); 345 ::system( script );
346 odebug << "script returned." << oendl; 346 odebug << "script returned." << oendl;
347 return; 347 return;
348 } 348 }
349 default: assert( false ); 349 default: assert( false );
350 } 350 }
351} 351}
352 352
353 353
354void WellenreiterConfigWindow::load() 354void WellenreiterConfigWindow::load()
355{ 355{
356#ifdef Q_WS_X11 356#ifdef Q_WS_X11
357 #warning Persistent Configuration not yet implemented for standalone X11 build 357 #warning Persistent Configuration not yet implemented for standalone X11 build
358 performAutodetection(); 358 performAutodetection();
359#else 359#else
360 odebug << "loading configuration settings..." << oendl; 360 odebug << "loading configuration settings..." << oendl;
361 361
362 /* This is dumb monkey typing stuff... We _need_ to do this automatically! */ 362 /* This is dumb monkey typing stuff... We _need_ to do this automatically! */
363 363
364 OConfig* c = oApp->config(); 364 OConfig* c = oApp->config();
365 365
366 c->setGroup( "Interface" ); 366 c->setGroup( "Interface" );
367 367
368 QString interface = c->readEntry( "name", "<none>" ); 368 QString interface = c->readEntry( "name", "<none>" );
369 if ( interface != "<none>" ) 369 if ( interface != "<none>" )
370 { 370 {
371#if QT_VERSION < 300 371#if QT_VERSION < 300
372 interfaceName->insertItem( interface, 0 ); 372 interfaceName->insertItem( interface, 0 );
373 interfaceName->setCurrentItem( 0 ); 373 interfaceName->setCurrentItem( 0 );
374#else 374#else
375 interfaceName->setCurrentText( interface ); 375 interfaceName->setCurrentText( interface );
376#endif 376#endif
377 377
378 QString device = c->readEntry( "type", "<select>" ); 378 QString device = c->readEntry( "type", "<select>" );
379#if QT_VERSION < 300 379#if QT_VERSION < 300
380 for ( int i = 0; i < deviceType->count(); ++i ) 380 for ( int i = 0; i < deviceType->count(); ++i )
381 { 381 {
382 if ( deviceType->text( i ) == device ) 382 if ( deviceType->text( i ) == device )
383 { 383 {
384 deviceType->setCurrentItem( i ); 384 deviceType->setCurrentItem( i );
385 break; 385 break;
386 } 386 }
387 } 387 }
388#else 388#else
389 deviceType->setCurrentText( device ); 389 deviceType->setCurrentText( device );
390#endif 390#endif
391 } 391 }
392 else 392 else
393 { 393 {
394 performAutodetection(); 394 performAutodetection();
395 } 395 }
396 396
397 prismHeader->setChecked( c->readBoolEntry( "prism", false ) ); 397 prismHeader->setChecked( c->readBoolEntry( "prism", false ) );
398 hopChannels->setChecked( c->readBoolEntry( "hop", true ) ); 398 hopChannels->setChecked( c->readBoolEntry( "hop", true ) );
399 hopInterval->setValue( c->readNumEntry( "interval", 250 ) ); 399 hopInterval->setValue( c->readNumEntry( "interval", 250 ) );
400 adaptiveHopping->setChecked( c->readBoolEntry( "adaptive", true ) ); 400 adaptiveHopping->setChecked( c->readBoolEntry( "adaptive", true ) );
401 401
402 c->setGroup( "Capture" ); 402 c->setGroup( "Capture" );
403 captureFileName->setText( c->readEntry( "filename", "/tmp/capture" ) ); 403 captureFileName->setText( c->readEntry( "filename", "/tmp/capture" ) );
404 404
405 c->setGroup( "UI" ); 405 c->setGroup( "UI" );
406 lookupVendor->setChecked( c->readBoolEntry( "lookupVendor", true ) ); 406 lookupVendor->setChecked( c->readBoolEntry( "lookupVendor", true ) );
407 openTree->setChecked( c->readBoolEntry( "openTree", true ) ); 407 openTree->setChecked( c->readBoolEntry( "openTree", true ) );
408 disablePM->setChecked( c->readBoolEntry( "disablePM", true ) ); 408 disablePM->setChecked( c->readBoolEntry( "disablePM", true ) );
409 newNetworkAction->setCurrentItem( c->readNumEntry( "newNetworkAction", 1 ) ); // Default: Play Alarm 409 newNetworkAction->setCurrentItem( c->readNumEntry( "newNetworkAction", 1 ) ); // Default: Play Alarm
410 newNetworkScript->setText( c->readEntry( "newNetworkScript", "" ) ); 410 newNetworkScript->setText( c->readEntry( "newNetworkScript", "" ) );
411 newClientAction->setCurrentItem( c->readNumEntry( "newClientAction", 2 ) ); // Default: Play Click 411 newClientAction->setCurrentItem( c->readNumEntry( "newClientAction", 2 ) ); // Default: Play Click
412 newClientScript->setText( c->readEntry( "newClientScript", "" ) ); 412 newClientScript->setText( c->readEntry( "newClientScript", "" ) );
413 newStationAction->setCurrentItem( c->readNumEntry( "newStationAction", 2 ) ); // Default: Play Click 413 newStationAction->setCurrentItem( c->readNumEntry( "newStationAction", 2 ) ); // Default: Play Click
414 newStationScript->setText( c->readEntry( "newStationScript", "" ) ); 414 newStationScript->setText( c->readEntry( "newStationScript", "" ) );
415 synchronizeActionsAndScripts(); // needed for showing/hiding the script QLineEdit on demand 415 synchronizeActionsAndScripts(); // needed for showing/hiding the script QLineEdit on demand
416 416
417 c->setGroup( "GPS" ); 417 c->setGroup( "GPS" );
418 enableGPS->setChecked( c->readBoolEntry( "use", false ) ); 418 enableGPS->setChecked( c->readBoolEntry( "use", false ) );
419#if QT_VERSION < 300 419#if QT_VERSION < 300
420 gpsdHost->insertItem( c->readEntry( "host", "localhost" ), 0 ); 420 gpsdHost->insertItem( c->readEntry( "host", "localhost" ), 0 );
421 gpsdHost->setCurrentItem( 0 ); 421 gpsdHost->setCurrentItem( 0 );
422#else 422#else
423 gpsdHost->setCurrentText( c->readEntry( "host", "localhost" ) ); 423 gpsdHost->setCurrentText( c->readEntry( "host", "localhost" ) );
424#endif 424#endif
425 gpsdPort->setValue( c->readNumEntry( "port", 2947 ) ); 425 gpsdPort->setValue( c->readNumEntry( "port", 2947 ) );
426 startGPS->setChecked( c->readBoolEntry( "start", false ) ); 426 startGPS->setChecked( c->readBoolEntry( "start", false ) );
427 commandGPS->setText( c->readEntry( "command", "gpsd -p /dev/ttyS3 -s 57600" ) ); 427 commandGPS->setText( c->readEntry( "command", "gpsd -p /dev/ttyS3 -s 57600" ) );
428 428
429#endif 429#endif
430} 430}
431 431
432 432
433void WellenreiterConfigWindow::save() 433void WellenreiterConfigWindow::save()
434{ 434{
435#ifdef Q_WS_X11 435#ifdef Q_WS_X11
436 #warning Persistent Configuration not yet implemented for standalone X11 build 436 #warning Persistent Configuration not yet implemented for standalone X11 build
437#else 437#else
438 odebug << "saving configuration settings..." << oendl; 438 odebug << "saving configuration settings..." << oendl;
439 439
440 /* This is dumb monkey typing stuff... We _need_ to do this automatically! */ 440 /* This is dumb monkey typing stuff... We _need_ to do this automatically! */
441 441
442 OConfig* c = oApp->config(); 442 OConfig* c = oApp->config();
443 443
444 c->setGroup( "Interface" ); 444 c->setGroup( "Interface" );
445 c->writeEntry( "name", interfaceName->currentText() ); 445 c->writeEntry( "name", interfaceName->currentText() );
446 c->writeEntry( "type", deviceType->currentText() ); 446 c->writeEntry( "type", deviceType->currentText() );
447 c->writeEntry( "prism", prismHeader->isChecked() ); 447 c->writeEntry( "prism", prismHeader->isChecked() );
448 c->writeEntry( "hop", hopChannels->isChecked() ); 448 c->writeEntry( "hop", hopChannels->isChecked() );
449 c->writeEntry( "interval", hopInterval->value() ); 449 c->writeEntry( "interval", hopInterval->value() );
450 c->writeEntry( "adaptive", adaptiveHopping->isChecked() ); 450 c->writeEntry( "adaptive", adaptiveHopping->isChecked() );
451 451
452 c->setGroup( "Capture" ); 452 c->setGroup( "Capture" );
453 c->writeEntry( "filename", captureFileName->text() ); 453 c->writeEntry( "filename", captureFileName->text() );
454 454
455 c->setGroup( "UI" ); 455 c->setGroup( "UI" );
456 c->writeEntry( "lookupVendor", lookupVendor->isChecked() ); 456 c->writeEntry( "lookupVendor", lookupVendor->isChecked() );
457 c->writeEntry( "openTree", openTree->isChecked() ); 457 c->writeEntry( "openTree", openTree->isChecked() );
458 c->writeEntry( "disablePM", disablePM->isChecked() ); 458 c->writeEntry( "disablePM", disablePM->isChecked() );
459 c->writeEntry( "newNetworkAction", newNetworkAction->currentItem() ); 459 c->writeEntry( "newNetworkAction", newNetworkAction->currentItem() );
460 c->writeEntry( "newNetworkScript", newNetworkScript->text() ); 460 c->writeEntry( "newNetworkScript", newNetworkScript->text() );
461 c->writeEntry( "newClientAction", newClientAction->currentItem() ); 461 c->writeEntry( "newClientAction", newClientAction->currentItem() );
462 c->writeEntry( "newClientScript", newClientScript->text() ); 462 c->writeEntry( "newClientScript", newClientScript->text() );
463 c->writeEntry( "newStationAction", newStationAction->currentItem() ); 463 c->writeEntry( "newStationAction", newStationAction->currentItem() );
464 c->writeEntry( "newStationScript", newStationScript->text() ); 464 c->writeEntry( "newStationScript", newStationScript->text() );
465 465
466 c->setGroup( "GPS" ); 466 c->setGroup( "GPS" );
467 c->writeEntry( "use", enableGPS->isChecked() ); 467 c->writeEntry( "use", enableGPS->isChecked() );
468 c->writeEntry( "host", gpsdHost->currentText() ); 468 c->writeEntry( "host", gpsdHost->currentText() );
469 c->writeEntry( "port", gpsdPort->value() ); 469 c->writeEntry( "port", gpsdPort->value() );
470 c->writeEntry( "start", startGPS->isChecked() ); 470 c->writeEntry( "start", startGPS->isChecked() );
471 c->writeEntry( "command", commandGPS->text() ); 471 c->writeEntry( "command", commandGPS->text() );
472 472
473 c->write(); 473 c->write();
474 474
475#endif 475#endif
476} 476}
diff --git a/noncore/net/wellenreiter/gui/mainwindow.cpp b/noncore/net/wellenreiter/gui/mainwindow.cpp
index a4b8839..8525109 100644
--- a/noncore/net/wellenreiter/gui/mainwindow.cpp
+++ b/noncore/net/wellenreiter/gui/mainwindow.cpp
@@ -1,582 +1,582 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved. 2** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved.
3** 3**
4** This file is part of Wellenreiter II. 4** This file is part of Wellenreiter II.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14**********************************************************************/ 14**********************************************************************/
15 15
16#include "configwindow.h" 16#include "configwindow.h"
17#include "gps.h" 17#include "gps.h"
18#include "logwindow.h" 18#include "logwindow.h"
19#include "packetview.h" 19#include "packetview.h"
20#include "mainwindow.h" 20#include "mainwindow.h"
21#include "wellenreiter.h" 21#include "wellenreiter.h"
22#include "scanlist.h" 22#include "scanlist.h"
23 23
24/* OPIE */ 24/* OPIE */
25#ifdef QWS 25#ifdef QWS
26#include <qpe/resource.h> 26#include <qpe/resource.h>
27#include <opie2/odebug.h> 27#include <opie2/odebug.h>
28#include <opie2/ofiledialog.h> 28#include <opie2/ofiledialog.h>
29#else 29#else
30#include "resource.h" 30#include "resource.h"
31#include <qapplication.h> 31#include <qapplication.h>
32#include <qfiledialog.h> 32#include <qfiledialog.h>
33#endif 33#endif
34using namespace Opie::Core; 34using namespace Opie::Core;
35using namespace Opie::Net; 35using namespace Opie::Net;
36using namespace Opie::Ui; 36using namespace Opie::Ui;
37 37
38/* QT */ 38/* QT */
39#include <qcombobox.h> 39#include <qcombobox.h>
40#include <qdatastream.h> 40#include <qdatastream.h>
41#include <qfile.h> 41#include <qfile.h>
42#include <qfileinfo.h> 42#include <qfileinfo.h>
43#include <qlabel.h> 43#include <qlabel.h>
44#include <qlayout.h> 44#include <qlayout.h>
45#include <qlineedit.h> 45#include <qlineedit.h>
46#include <qiconset.h> 46#include <qiconset.h>
47#include <qmenubar.h> 47#include <qmenubar.h>
48#include <qmessagebox.h> 48#include <qmessagebox.h>
49#include <qpopupmenu.h> 49#include <qpopupmenu.h>
50#include <qpushbutton.h> 50#include <qpushbutton.h>
51#include <qstatusbar.h> 51#include <qstatusbar.h>
52#include <qspinbox.h> 52#include <qspinbox.h>
53#include <qtextstream.h> 53#include <qtextstream.h>
54#include <qtoolbutton.h> 54#include <qtoolbutton.h>
55#include <qwhatsthis.h> 55#include <qwhatsthis.h>
56 56
57/* STD */ 57/* STD */
58#include <unistd.h> 58#include <unistd.h>
59 59
60WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * name, WFlags f ) 60WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * name, WFlags f )
61 :QMainWindow( parent, name, f ) 61 :QMainWindow( parent, name, f )
62{ 62{
63 cw = new WellenreiterConfigWindow( this ); 63 cw = new WellenreiterConfigWindow( this );
64 mw = new Wellenreiter( this ); 64 mw = new Wellenreiter( this );
65 mw->setConfigWindow( cw ); 65 mw->setConfigWindow( cw );
66 setCentralWidget( mw ); 66 setCentralWidget( mw );
67 67
68 // setup application icon 68 // setup application icon
69 69
70 setIcon( Resource::loadPixmap( "wellenreiter/appicon-trans" ) ); 70 setIcon( Resource::loadPixmap( "wellenreiter/appicon-trans" ) );
71 #ifndef QWS 71 #ifndef QWS
72 setIconText( "Wellenreiter/X11" ); 72 setIconText( "Wellenreiter/X11" );
73 #endif 73 #endif
74 74
75 // setup tool buttons 75 // setup tool buttons
76 76
77 startButton = new QToolButton( 0 ); 77 startButton = new QToolButton( 0 );
78 QWhatsThis::add( startButton, tr( "Click here to start scanning." ) ); 78 QWhatsThis::add( startButton, tr( "Click here to start scanning." ) );
79 #ifdef QWS 79 #ifdef QWS
80 startButton->setAutoRaise( true ); 80 startButton->setAutoRaise( true );
81 #endif 81 #endif
82 startButton->setIconSet( Resource::loadIconSet( "wellenreiter/SearchIcon" ) ); 82 startButton->setIconSet( Resource::loadIconSet( "wellenreiter/SearchIcon" ) );
83 startButton->setEnabled( false ); 83 startButton->setEnabled( false );
84 connect( startButton, SIGNAL( clicked() ), mw, SLOT( startClicked() ) ); 84 connect( startButton, SIGNAL( clicked() ), mw, SLOT( startClicked() ) );
85 85
86 stopButton = new QToolButton( 0 ); 86 stopButton = new QToolButton( 0 );
87 QWhatsThis::add( stopButton, tr( "Click here to stop scanning." ) ); 87 QWhatsThis::add( stopButton, tr( "Click here to stop scanning." ) );
88 #ifdef QWS 88 #ifdef QWS
89 stopButton->setAutoRaise( true ); 89 stopButton->setAutoRaise( true );
90 #endif 90 #endif
91 stopButton->setIconSet( Resource::loadIconSet( "wellenreiter/CancelIcon" ) ); 91 stopButton->setIconSet( Resource::loadIconSet( "wellenreiter/CancelIcon" ) );
92 stopButton->setEnabled( false ); 92 stopButton->setEnabled( false );
93 connect( stopButton, SIGNAL( clicked() ), mw, SLOT( stopClicked() ) ); 93 connect( stopButton, SIGNAL( clicked() ), mw, SLOT( stopClicked() ) );
94 94
95 QToolButton* d = new QToolButton( 0 ); 95 QToolButton* d = new QToolButton( 0 );
96 QWhatsThis::add( d, tr( "Click here to open the configure dialog." ) ), 96 QWhatsThis::add( d, tr( "Click here to open the configure dialog." ) ),
97 #ifdef QWS 97 #ifdef QWS
98 d->setAutoRaise( true ); 98 d->setAutoRaise( true );
99 #endif 99 #endif
100 d->setIconSet( Resource::loadIconSet( "wellenreiter/SettingsIcon" ) ); 100 d->setIconSet( Resource::loadIconSet( "wellenreiter/SettingsIcon" ) );
101 connect( d, SIGNAL( clicked() ), this, SLOT( showConfigure() ) ); 101 connect( d, SIGNAL( clicked() ), this, SLOT( showConfigure() ) );
102 102
103 uploadButton = new QToolButton( 0 ); 103 uploadButton = new QToolButton( 0 );
104 QWhatsThis::add( uploadButton, tr( "Click here to upload a capture session." ) ); 104 QWhatsThis::add( uploadButton, tr( "Click here to upload a capture session." ) );
105 #ifdef QWS 105 #ifdef QWS
106 uploadButton->setAutoRaise( true ); 106 uploadButton->setAutoRaise( true );
107 #endif 107 #endif
108 uploadButton->setIconSet( Resource::loadIconSet( "up" ) ); 108 uploadButton->setIconSet( Resource::loadIconSet( "up" ) );
109 uploadButton->setEnabled( false ); 109 uploadButton->setEnabled( false );
110 //uploadButton->setEnabled( true ); // DEBUGGING 110 //uploadButton->setEnabled( true ); // DEBUGGING
111 connect( uploadButton, SIGNAL( clicked() ), this, SLOT( uploadSession() ) ); 111 connect( uploadButton, SIGNAL( clicked() ), this, SLOT( uploadSession() ) );
112 112
113 // setup menu bar 113 // setup menu bar
114 114
115 int id; 115 int id;
116 116
117 QMenuBar* mb = menuBar(); 117 QMenuBar* mb = menuBar();
118 118
119 QPopupMenu* fileSave = new QPopupMenu( mb ); 119 QPopupMenu* fileSave = new QPopupMenu( mb );
120 fileSave->insertItem( tr( "&Session..." ), this, SLOT( fileSaveSession() ) ); 120 fileSave->insertItem( tr( "&Session..." ), this, SLOT( fileSaveSession() ) );
121 fileSave->insertItem( tr( "&Text Log..." ), this, SLOT( fileSaveLog() ) ); 121 fileSave->insertItem( tr( "&Text Log..." ), this, SLOT( fileSaveLog() ) );
122 fileSave->insertItem( tr( "&Hex Log..." ), this, SLOT( fileSaveHex() ) ); 122 fileSave->insertItem( tr( "&Hex Log..." ), this, SLOT( fileSaveHex() ) );
123 123
124 QPopupMenu* fileLoad = new QPopupMenu( mb ); 124 QPopupMenu* fileLoad = new QPopupMenu( mb );
125 fileLoad->insertItem( tr( "&Session..." ), this, SLOT( fileLoadSession() ) ); 125 fileLoad->insertItem( tr( "&Session..." ), this, SLOT( fileLoadSession() ) );
126 //fileLoad->insertItem( "&Log", this, SLOT( fileLoadLog() ) ); 126 //fileLoad->insertItem( "&Log", this, SLOT( fileLoadLog() ) );
127 127
128 QPopupMenu* file = new QPopupMenu( mb ); 128 QPopupMenu* file = new QPopupMenu( mb );
129 file->insertItem( tr( "&New" ), this, SLOT( fileNew() ) ); 129 file->insertItem( tr( "&New" ), this, SLOT( fileNew() ) );
130 id = file->insertItem( tr( "&Load" ), fileLoad ); 130 id = file->insertItem( tr( "&Load" ), fileLoad );
131 file->insertItem( tr( "&Save" ), fileSave ); 131 file->insertItem( tr( "&Save" ), fileSave );
132 file->insertSeparator(); 132 file->insertSeparator();
133 uploadID = file->insertItem( tr( "&Upload Session" ), this, SLOT( uploadSession() ) ); 133 uploadID = file->insertItem( tr( "&Upload Session" ), this, SLOT( uploadSession() ) );
134 file->insertSeparator(); 134 file->insertSeparator();
135 file->insertItem( tr( "&Exit" ), qApp, SLOT( quit() ) ); 135 file->insertItem( tr( "&Exit" ), qApp, SLOT( quit() ) );
136 136
137 QPopupMenu* sniffer = new QPopupMenu( mb ); 137 QPopupMenu* sniffer = new QPopupMenu( mb );
138 sniffer->insertItem( tr( "&Configure..." ), this, SLOT( showConfigure() ) ); 138 sniffer->insertItem( tr( "&Configure..." ), this, SLOT( showConfigure() ) );
139 sniffer->insertSeparator(); 139 sniffer->insertSeparator();
140 startID = sniffer->insertItem( tr( "&Start" ), mw, SLOT( startClicked() ) ); 140 startID = sniffer->insertItem( tr( "&Start" ), mw, SLOT( startClicked() ) );
141 sniffer->setItemEnabled( startID, false ); 141 sniffer->setItemEnabled( startID, false );
142 stopID = sniffer->insertItem( tr( "Sto&p" ), mw, SLOT( stopClicked() ) ); 142 stopID = sniffer->insertItem( tr( "Sto&p" ), mw, SLOT( stopClicked() ) );
143 sniffer->setItemEnabled( stopID, false ); 143 sniffer->setItemEnabled( stopID, false );
144 144
145 QPopupMenu* view = new QPopupMenu( mb ); 145 QPopupMenu* view = new QPopupMenu( mb );
146 view->insertItem( tr( "&Expand All" ), this, SLOT( viewExpandAll() ) ); 146 view->insertItem( tr( "&Expand All" ), this, SLOT( viewExpandAll() ) );
147 view->insertItem( tr( "&Collapse All" ), this, SLOT( viewCollapseAll() ) ); 147 view->insertItem( tr( "&Collapse All" ), this, SLOT( viewCollapseAll() ) );
148 148
149 QPopupMenu* demo = new QPopupMenu( mb ); 149 QPopupMenu* demo = new QPopupMenu( mb );
150 demo->insertItem( tr( "&Add something" ), this, SLOT( demoAddStations() ) ); 150 demo->insertItem( tr( "&Add something" ), this, SLOT( demoAddStations() ) );
151 //demo->insertItem( tr( "&Read from GPSd" ), this, SLOT( demoReadFromGps() ) ); 151 //demo->insertItem( tr( "&Read from GPSd" ), this, SLOT( demoReadFromGps() ) );
152 152
153 id = mb->insertItem( tr( "&File" ), file ); 153 id = mb->insertItem( tr( "&File" ), file );
154 154
155 id = mb->insertItem( tr( "&View" ), view ); 155 id = mb->insertItem( tr( "&View" ), view );
156 //mb->setItemEnabled( id, false ); 156 //mb->setItemEnabled( id, false );
157 157
158 id = mb->insertItem( tr( "&Sniffer" ), sniffer ); 158 id = mb->insertItem( tr( "&Sniffer" ), sniffer );
159 159
160 id = mb->insertItem( tr( "&Demo" ), demo ); 160 id = mb->insertItem( tr( "&Demo" ), demo );
161 mb->setItemEnabled( id, true ); 161 mb->setItemEnabled( id, true );
162 mb->setItemEnabled( uploadID, false ); 162 mb->setItemEnabled( uploadID, false );
163 163
164 #ifdef QWS 164 #ifdef QWS
165 mb->insertItem( startButton ); 165 mb->insertItem( startButton );
166 mb->insertItem( stopButton ); 166 mb->insertItem( stopButton );
167 mb->insertItem( uploadButton ); 167 mb->insertItem( uploadButton );
168 mb->insertItem( d ); 168 mb->insertItem( d );
169 #else // Qt3 changed the insertion order. It's now totally random :( 169 #else // Qt3 changed the insertion order. It's now totally random :(
170 mb->insertItem( d ); 170 mb->insertItem( d );
171 mb->insertItem( uploadButton ); 171 mb->insertItem( uploadButton );
172 mb->insertItem( stopButton ); 172 mb->insertItem( stopButton );
173 mb->insertItem( startButton ); 173 mb->insertItem( startButton );
174 #endif 174 #endif
175 175
176 updateToolButtonState(); 176 updateToolButtonState();
177 177
178 // setup status bar (for now only on X11) 178 // setup status bar (for now only on X11)
179 179
180 #ifndef QWS 180 #ifndef QWS
181 statusBar()->message( tr( "Ready." ) ); 181 statusBar()->message( tr( "Ready." ) );
182 #endif 182 #endif
183 183
184 connect( mw, SIGNAL( startedSniffing() ), this, SLOT( changedSniffingState() ) ); 184 connect( mw, SIGNAL( startedSniffing() ), this, SLOT( changedSniffingState() ) );
185 connect( mw, SIGNAL( stoppedSniffing() ), this, SLOT( changedSniffingState() ) ); 185 connect( mw, SIGNAL( stoppedSniffing() ), this, SLOT( changedSniffingState() ) );
186}; 186};
187 187
188 188
189 189
190void WellenreiterMainWindow::showConfigure() 190void WellenreiterMainWindow::showConfigure()
191{ 191{
192 odebug << "show configure..." << oendl; 192 odebug << "show configure..." << oendl;
193 cw->setCaption( tr( "Configure" ) ); 193 cw->setCaption( tr( "Configure" ) );
194 int result = QPEApplication::execDialog( cw ); 194 int result = QPEApplication::execDialog( cw );
195 195
196 if ( result ) updateToolButtonState(); 196 if ( result ) updateToolButtonState();
197} 197}
198 198
199 199
200void WellenreiterMainWindow::updateToolButtonState() 200void WellenreiterMainWindow::updateToolButtonState()
201{ 201{
202 const QString& interface = cw->interfaceName->currentText(); 202 const QString& interface = cw->interfaceName->currentText();
203 const int cardtype = cw->driverType(); 203 const int cardtype = cw->driverType();
204 204
205 if ( ( interface != "<select>" ) && ( cardtype != 0 ) ) 205 if ( ( interface != "<select>" ) && ( cardtype != 0 ) )
206 { 206 {
207 startButton->setEnabled( true ); 207 startButton->setEnabled( true );
208 menuBar()->setItemEnabled( startID, true ); 208 menuBar()->setItemEnabled( startID, true );
209 } 209 }
210 else 210 else
211 { 211 {
212 startButton->setEnabled( false ); 212 startButton->setEnabled( false );
213 menuBar()->setItemEnabled( startID, false ); 213 menuBar()->setItemEnabled( startID, false );
214 } 214 }
215} 215}
216 216
217 217
218void WellenreiterMainWindow::changedSniffingState() 218void WellenreiterMainWindow::changedSniffingState()
219{ 219{
220 startButton->setEnabled( !mw->sniffing ); 220 startButton->setEnabled( !mw->sniffing );
221 menuBar()->setItemEnabled( startID, !mw->sniffing ); 221 menuBar()->setItemEnabled( startID, !mw->sniffing );
222 stopButton->setEnabled( mw->sniffing ); 222 stopButton->setEnabled( mw->sniffing );
223 menuBar()->setItemEnabled( stopID, mw->sniffing ); 223 menuBar()->setItemEnabled( stopID, mw->sniffing );
224 224
225 if ( !mw->sniffing ) 225 if ( !mw->sniffing )
226 { 226 {
227 menuBar()->setItemEnabled( uploadID, true ); 227 menuBar()->setItemEnabled( uploadID, true );
228 uploadButton->setEnabled( true ); 228 uploadButton->setEnabled( true );
229 } 229 }
230} 230}
231 231
232 232
233WellenreiterMainWindow::~WellenreiterMainWindow() 233WellenreiterMainWindow::~WellenreiterMainWindow()
234{ 234{
235 odebug << "Wellenreiter: bye." << oendl; 235 odebug << "Wellenreiter: bye." << oendl;
236}; 236};
237 237
238 238
239void WellenreiterMainWindow::demoAddStations() 239void WellenreiterMainWindow::demoAddStations()
240{ 240{
241 //mw = 0; // test SIGSEGV handling 241 //mw = 0; // test SIGSEGV handling
242 242
243 mw->netView()->addNewItem( "managed", "Vanille", OMacAddress::fromString("00:00:20:EF:A6:43"), true, 6, 80, GpsLocation( 39.8794, -94.0936) ); 243 mw->netView()->addNewItem( "managed", "Vanille", OMacAddress::fromString("00:00:20:EF:A6:43"), true, 6, 80, GpsLocation( 39.8794, -94.0936) );
244 mw->netView()->addNewItem( "managed", "Vanille", OMacAddress::fromString("00:30:6D:EF:A6:23"), true, 11, 10, GpsLocation( 0.0, 0.0 ) ); 244 mw->netView()->addNewItem( "managed", "Vanille", OMacAddress::fromString("00:30:6D:EF:A6:23"), true, 11, 10, GpsLocation( 0.0, 0.0 ) );
245 mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:03:F8:E7:16:22"), false, 3, 10, GpsLocation( 5.5, 2.3 ) ); 245 mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:03:F8:E7:16:22"), false, 3, 10, GpsLocation( 5.5, 2.3 ) );
246 mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:04:01:E7:56:62"), false, 3, 15, GpsLocation( 2.3, 5.5 ) ); 246 mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:04:01:E7:56:62"), false, 3, 15, GpsLocation( 2.3, 5.5 ) );
247 mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:05:8E:E7:56:E2"), false, 3, 20, GpsLocation( -10.0, -20.5 ) ); 247 mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:05:8E:E7:56:E2"), false, 3, 20, GpsLocation( -10.0, -20.5 ) );
248} 248}
249 249
250 250
251void WellenreiterMainWindow::demoReadFromGps() 251void WellenreiterMainWindow::demoReadFromGps()
252{ 252{
253 WellenreiterConfigWindow* configwindow = WellenreiterConfigWindow::instance(); 253 WellenreiterConfigWindow* configwindow = WellenreiterConfigWindow::instance();
254 GPS* gps = new GPS( this ); 254 GPS* gps = new GPS( this );
255 odebug << "Wellenreiter::demoReadFromGps(): url=gps://" << (const char*) configwindow->gpsdHost->currentText() << ":" << configwindow->gpsdPort->value() << "/" << oendl; 255 odebug << "Wellenreiter::demoReadFromGps(): url=gps://" << configwindow->gpsdHost->currentText() << ":" << configwindow->gpsdPort->value() << "/" << oendl;
256 gps->open( configwindow->gpsdHost->currentText(), configwindow->gpsdPort->value() ); 256 gps->open( configwindow->gpsdHost->currentText(), configwindow->gpsdPort->value() );
257 GpsLocation loc = gps->position(); 257 GpsLocation loc = gps->position();
258 QMessageBox::information( this, "Wellenreiter/Opie", tr( "GPS said:\n%1" ).arg( loc.dmsPosition() ) ); 258 QMessageBox::information( this, "Wellenreiter/Opie", tr( "GPS said:\n%1" ).arg( loc.dmsPosition() ) );
259 delete gps; 259 delete gps;
260} 260}
261 261
262 262
263QString WellenreiterMainWindow::getFileName( bool save ) 263QString WellenreiterMainWindow::getFileName( bool save )
264{ 264{
265 QMap<QString, QStringList> map; 265 QMap<QString, QStringList> map;
266 map.insert( tr("All"), QStringList() ); 266 map.insert( tr("All"), QStringList() );
267 QStringList text; 267 QStringList text;
268 text << "text/*"; 268 text << "text/*";
269 map.insert( tr("Text"), text ); 269 map.insert( tr("Text"), text );
270 text << "*"; 270 text << "*";
271 map.insert( tr("All"), text ); 271 map.insert( tr("All"), text );
272 272
273 QString str; 273 QString str;
274 if ( save ) 274 if ( save )
275 { 275 {
276 #ifdef QWS 276 #ifdef QWS
277 str = OFileDialog::getSaveFileName( 2, "/", QString::null, map ); 277 str = OFileDialog::getSaveFileName( 2, "/", QString::null, map );
278 #else 278 #else
279 str = QFileDialog::getSaveFileName(); 279 str = QFileDialog::getSaveFileName();
280 #endif 280 #endif
281 if ( str.isEmpty() /*|| QFileInfo(str).isDir()*/ ) 281 if ( str.isEmpty() /*|| QFileInfo(str).isDir()*/ )
282 return ""; 282 return "";
283 } 283 }
284 else 284 else
285 { 285 {
286 #ifdef QWS 286 #ifdef QWS
287 str = OFileDialog::getOpenFileName( 2, "/", QString::null, map ); 287 str = OFileDialog::getOpenFileName( 2, "/", QString::null, map );
288 #else 288 #else
289 str = QFileDialog::getOpenFileName(); 289 str = QFileDialog::getOpenFileName();
290 #endif 290 #endif
291 if ( str.isEmpty() || !QFile(str).exists() || QFileInfo(str).isDir() ) 291 if ( str.isEmpty() || !QFile(str).exists() || QFileInfo(str).isDir() )
292 return ""; 292 return "";
293 } 293 }
294 return str; 294 return str;
295} 295}
296 296
297 297
298void WellenreiterMainWindow::fileSaveLog() 298void WellenreiterMainWindow::fileSaveLog()
299{ 299{
300 QString fname = getFileName( true ); 300 QString fname = getFileName( true );
301 if ( !fname.isEmpty() ) 301 if ( !fname.isEmpty() )
302 { 302 {
303 QFile f( fname ); 303 QFile f( fname );
304 if ( f.open(IO_WriteOnly) ) 304 if ( f.open(IO_WriteOnly) )
305 { 305 {
306 QTextStream t( &f ); 306 QTextStream t( &f );
307 t << mw->logWindow()->getLog(); 307 t << mw->logWindow()->getLog();
308 f.close(); 308 f.close();
309 odebug << "Saved log to file '" << (const char*) fname << "'" << oendl; 309 odebug << "Saved log to file '" << fname << "'" << oendl;
310 } 310 }
311 else 311 else
312 { 312 {
313 odebug << "Problem saving log to file '" << (const char*) fname << "'" << oendl; 313 odebug << "Problem saving log to file '" << fname << "'" << oendl;
314 } 314 }
315 } 315 }
316} 316}
317 317
318void WellenreiterMainWindow::fileSaveSession() 318void WellenreiterMainWindow::fileSaveSession()
319{ 319{
320 QString fname = getFileName( true ); 320 QString fname = getFileName( true );
321 if ( !fname.isEmpty() ) 321 if ( !fname.isEmpty() )
322 { 322 {
323 323
324 QFile f( fname ); 324 QFile f( fname );
325 if ( f.open(IO_WriteOnly) ) 325 if ( f.open(IO_WriteOnly) )
326 { 326 {
327 QDataStream t( &f ); 327 QDataStream t( &f );
328 t << *mw->netView(); 328 t << *mw->netView();
329 f.close(); 329 f.close();
330 odebug << "Saved session to file '" << (const char*) fname << "'" << oendl; 330 odebug << "Saved session to file '" << fname << "'" << oendl;
331 } 331 }
332 else 332 else
333 { 333 {
334 odebug << "Problem saving session to file '" << (const char*) fname << "'" << oendl; 334 odebug << "Problem saving session to file '" << fname << "'" << oendl;
335 } 335 }
336 } 336 }
337} 337}
338 338
339void WellenreiterMainWindow::fileSaveHex() 339void WellenreiterMainWindow::fileSaveHex()
340{ 340{
341 #warning DOES NOT WORK AT THE MOMENT 341 #warning DOES NOT WORK AT THE MOMENT
342 /* 342 /*
343 QString fname = getFileName( true ); 343 QString fname = getFileName( true );
344 if ( !fname.isEmpty() ) 344 if ( !fname.isEmpty() )
345 { 345 {
346 QFile f( fname ); 346 QFile f( fname );
347 if ( f.open(IO_WriteOnly) ) 347 if ( f.open(IO_WriteOnly) )
348 { 348 {
349 QTextStream t( &f ); 349 QTextStream t( &f );
350 t << mw->hexWindow()->getLog(); 350 t << mw->hexWindow()->getLog();
351 f.close(); 351 f.close();
352 odebug << "Saved hex log to file '" << (const char*) fname << "'" << oendl; 352 odebug << "Saved hex log to file '" << fname << "'" << oendl;
353 } 353 }
354 else 354 else
355 { 355 {
356 odebug << "Problem saving hex log to file '" << (const char*) fname << "'" << oendl; 356 odebug << "Problem saving hex log to file '" << fname << "'" << oendl;
357 } 357 }
358 } 358 }
359 */ 359 */
360} 360}
361 361
362void WellenreiterMainWindow::fileLoadSession() 362void WellenreiterMainWindow::fileLoadSession()
363{ 363{
364 QString fname = getFileName( false ); 364 QString fname = getFileName( false );
365 if ( !fname.isEmpty() ) 365 if ( !fname.isEmpty() )
366 { 366 {
367 QFile f( fname ); 367 QFile f( fname );
368 if ( f.open(IO_ReadOnly) ) 368 if ( f.open(IO_ReadOnly) )
369 { 369 {
370 QDataStream t( &f ); 370 QDataStream t( &f );
371 t >> *mw->netView(); 371 t >> *mw->netView();
372 f.close(); 372 f.close();
373 odebug << "Loaded session from file '" << (const char*) fname << "'" << oendl; 373 odebug << "Loaded session from file '" << fname << "'" << oendl;
374 } 374 }
375 else 375 else
376 { 376 {
377 odebug << "Problem loading session from file '" << (const char*) fname << "'" << oendl; 377 odebug << "Problem loading session from file '" << fname << "'" << oendl;
378 } 378 }
379 } 379 }
380} 380}
381 381
382 382
383void WellenreiterMainWindow::fileNew() 383void WellenreiterMainWindow::fileNew()
384{ 384{
385 mw->netView()->clear(); 385 mw->netView()->clear();
386 mw->logWindow()->clear(); 386 mw->logWindow()->clear();
387 mw->hexWindow()->clear(); 387 mw->hexWindow()->clear();
388} 388}
389 389
390 390
391void WellenreiterMainWindow::closeEvent( QCloseEvent* e ) 391void WellenreiterMainWindow::closeEvent( QCloseEvent* e )
392{ 392{
393 if ( mw->isDaemonRunning() ) 393 if ( mw->isDaemonRunning() )
394 { 394 {
395 QMessageBox::warning( this, "Wellenreiter/Opie", 395 QMessageBox::warning( this, "Wellenreiter/Opie",
396 tr( "Sniffing in progress!\nPlease stop sniffing before closing." ) ); 396 tr( "Sniffing in progress!\nPlease stop sniffing before closing." ) );
397 e->ignore(); 397 e->ignore();
398 } 398 }
399 else 399 else
400 { 400 {
401 QMainWindow::closeEvent( e ); 401 QMainWindow::closeEvent( e );
402 } 402 }
403} 403}
404 404
405static const char* CAP_hostname = "www.vanille.de"; 405static const char* CAP_hostname = "www.vanille.de";
406 406
407#include <netdb.h> 407#include <netdb.h>
408#include <unistd.h> 408#include <unistd.h>
409#include <sys/types.h> 409#include <sys/types.h>
410#include <sys/socket.h> 410#include <sys/socket.h>
411 411
412void WellenreiterMainWindow::uploadSession() 412void WellenreiterMainWindow::uploadSession()
413{ 413{
414 QLineEdit* from; 414 QLineEdit* from;
415 QLineEdit* location; 415 QLineEdit* location;
416 QLineEdit* comments; 416 QLineEdit* comments;
417 QPushButton* accept; 417 QPushButton* accept;
418 QPushButton* reject; 418 QPushButton* reject;
419 419
420 QDialog* d = new QDialog( 0, "session upload", true ); 420 QDialog* d = new QDialog( 0, "session upload", true );
421 d->setCaption( tr( "Upload Session" ) ); 421 d->setCaption( tr( "Upload Session" ) );
422 QGridLayout* g = new QGridLayout( d, 4, 2, 3 ); 422 QGridLayout* g = new QGridLayout( d, 4, 2, 3 );
423 g->addWidget( new QLabel( tr( "From: " ), d ), 0, 0 ); 423 g->addWidget( new QLabel( tr( "From: " ), d ), 0, 0 );
424 g->addWidget( from = new QLineEdit( d ), 0, 1 ); 424 g->addWidget( from = new QLineEdit( d ), 0, 1 );
425 g->addWidget( new QLabel( tr( "Location: " ), d ), 1, 0 ); 425 g->addWidget( new QLabel( tr( "Location: " ), d ), 1, 0 );
426 g->addWidget( location = new QLineEdit( d ), 1, 1 ); 426 g->addWidget( location = new QLineEdit( d ), 1, 1 );
427 g->addWidget( new QLabel( tr( "Comments: " ), d ), 2, 0 ); 427 g->addWidget( new QLabel( tr( "Comments: " ), d ), 2, 0 );
428 g->addWidget( comments = new QLineEdit( d ), 2, 1 ); 428 g->addWidget( comments = new QLineEdit( d ), 2, 1 );
429 g->addWidget( accept = new QPushButton( tr( "&Ok" ), d ), 3, 0 ); 429 g->addWidget( accept = new QPushButton( tr( "&Ok" ), d ), 3, 0 );
430 g->addWidget( reject = new QPushButton( tr( "&Cancel" ), d ), 3, 1 ); 430 g->addWidget( reject = new QPushButton( tr( "&Cancel" ), d ), 3, 1 );
431 accept->setDefault( true ); 431 accept->setDefault( true );
432 accept->setAutoDefault( true ); 432 accept->setAutoDefault( true );
433 from->setText( "WL II User" ); 433 from->setText( "WL II User" );
434 location->setText( "WL II Location" ); 434 location->setText( "WL II Location" );
435 comments->setText( "No Comments." ); 435 comments->setText( "No Comments." );
436 connect( accept, SIGNAL( clicked() ), d, SLOT( accept() ) ); 436 connect( accept, SIGNAL( clicked() ), d, SLOT( accept() ) );
437 connect( reject, SIGNAL( clicked() ), d, SLOT( reject() ) ); 437 connect( reject, SIGNAL( clicked() ), d, SLOT( reject() ) );
438 int result = d->exec(); 438 int result = d->exec();
439 439
440 if ( !result ) 440 if ( !result )
441 { 441 {
442 odebug << "Session upload cancelled :(" << oendl; 442 odebug << "Session upload cancelled :(" << oendl;
443 return; 443 return;
444 } 444 }
445 445
446 odebug << "Starting upload..." << oendl; 446 odebug << "Starting upload..." << oendl;
447 447
448 struct sockaddr_in raddr; 448 struct sockaddr_in raddr;
449 struct hostent *rhost_info; 449 struct hostent *rhost_info;
450 int sock = -1; 450 int sock = -1;
451 bool ok = false; 451 bool ok = false;
452 452
453 rhost_info = (struct hostent *) ::gethostbyname( CAP_hostname ); 453 rhost_info = (struct hostent *) ::gethostbyname( CAP_hostname );
454 if ( rhost_info ) 454 if ( rhost_info )
455 { 455 {
456 456
457 457
458 if ( !QFile::exists( mw->captureFileName() ) ) 458 if ( !QFile::exists( mw->captureFileName() ) )
459 { 459 {
460 QMessageBox::warning( 0, tr( "Error" ), tr( "<p>Logfile '%1' doesn't exist</p>").arg( mw->captureFileName() ) ); 460 QMessageBox::warning( 0, tr( "Error" ), tr( "<p>Logfile '%1' doesn't exist</p>").arg( mw->captureFileName() ) );
461 return; 461 return;
462 } 462 }
463 463
464 QFile f( mw->captureFileName() ); 464 QFile f( mw->captureFileName() );
465 if ( !f.open( IO_ReadOnly ) ) 465 if ( !f.open( IO_ReadOnly ) )
466 { 466 {
467 QMessageBox::warning( 0, tr( "Error" ), tr( "<p>Can't open Logfile '%1'</p>").arg( mw->captureFileName() ) ); 467 QMessageBox::warning( 0, tr( "Error" ), tr( "<p>Can't open Logfile '%1'</p>").arg( mw->captureFileName() ) );
468 return; 468 return;
469 } 469 }
470 470
471 int content_length = f.size(); 471 int content_length = f.size();
472 472
473 ::memset( &raddr, 0, sizeof (struct sockaddr_in) ); 473 ::memset( &raddr, 0, sizeof (struct sockaddr_in) );
474 ::memcpy( &raddr. sin_addr, rhost_info-> h_addr, rhost_info-> h_length ); 474 ::memcpy( &raddr. sin_addr, rhost_info-> h_addr, rhost_info-> h_length );
475 raddr.sin_family = rhost_info-> h_addrtype; 475 raddr.sin_family = rhost_info-> h_addrtype;
476 raddr.sin_port = htons ( 80 ); 476 raddr.sin_port = htons ( 80 );
477 477
478 sock = ::socket( AF_INET, SOCK_STREAM, 0 ); 478 sock = ::socket( AF_INET, SOCK_STREAM, 0 );
479 479
480 if ( sock >= 0 ) 480 if ( sock >= 0 )
481 { 481 {
482 if ( ::connect ( sock, (struct sockaddr *) & raddr, sizeof (struct sockaddr)) >= 0 ) 482 if ( ::connect ( sock, (struct sockaddr *) & raddr, sizeof (struct sockaddr)) >= 0 )
483 { 483 {
484 QString header; 484 QString header;
485 QString content; 485 QString content;
486 QString preambel; 486 QString preambel;
487 487
488 header = "" 488 header = ""
489 "POST /projects/capturedump.spy HTTP/1.1\r\n" 489 "POST /projects/capturedump.spy HTTP/1.1\r\n"
490 "Host: www.vanille.de\r\n" 490 "Host: www.vanille.de\r\n"
491 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031010 Galeon/1.3.10\r\n" 491 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031010 Galeon/1.3.10\r\n"
492 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1\r\n" 492 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1\r\n"
493 "Accept-Language: en\r\n" 493 "Accept-Language: en\r\n"
494 "Accept-Encoding: gzip, deflate, compress;q=0.9\r\n" 494 "Accept-Encoding: gzip, deflate, compress;q=0.9\r\n"
495 "Accept-Charset: us-ascii,utf-8;q=0.7,*;q=0.7\r\n" 495 "Accept-Charset: us-ascii,utf-8;q=0.7,*;q=0.7\r\n"
496 "Keep-Alive: 300\r\n" 496 "Keep-Alive: 300\r\n"
497 "Connection: keep-alive\r\n" 497 "Connection: keep-alive\r\n"
498 "Referer: http://www.vanille.de/projects/capturedump.spy\r\n" 498 "Referer: http://www.vanille.de/projects/capturedump.spy\r\n"
499 "Content-Type: multipart/form-data; boundary=---------------------------97267758015830030481215568065\r\n" 499 "Content-Type: multipart/form-data; boundary=---------------------------97267758015830030481215568065\r\n"
500 "Content-Length: %1\r\n" 500 "Content-Length: %1\r\n"
501 "\r\n"; 501 "\r\n";
502 502
503 content = "" 503 content = ""
504 "-----------------------------97267758015830030481215568065\r\n" 504 "-----------------------------97267758015830030481215568065\r\n"
505 "Content-Disposition: form-data; name=\"Name\"\r\n" 505 "Content-Disposition: form-data; name=\"Name\"\r\n"
506 "\r\n" 506 "\r\n"
507 "%1\r\n" 507 "%1\r\n"
508 "-----------------------------97267758015830030481215568065\r\n" 508 "-----------------------------97267758015830030481215568065\r\n"
509 "Content-Disposition: form-data; name=\"Location\"\r\n" 509 "Content-Disposition: form-data; name=\"Location\"\r\n"
510 "\r\n" 510 "\r\n"
511 "%2\r\n" 511 "%2\r\n"
512 "-----------------------------97267758015830030481215568065\r\n" 512 "-----------------------------97267758015830030481215568065\r\n"
513 "Content-Disposition: form-data; name=\"Comments\"\r\n" 513 "Content-Disposition: form-data; name=\"Comments\"\r\n"
514 "\r\n" 514 "\r\n"
515 "%3\r\n" 515 "%3\r\n"
516 "-----------------------------97267758015830030481215568065\r\n" 516 "-----------------------------97267758015830030481215568065\r\n"
517 "Content-Disposition: form-data; name=\"upfile\"; filename=\"%4\"\r\n" 517 "Content-Disposition: form-data; name=\"upfile\"; filename=\"%4\"\r\n"
518 "Content-Type: application/octet-stream\r\n" 518 "Content-Type: application/octet-stream\r\n"
519 "\r\n"; 519 "\r\n";
520 520
521 preambel = "" 521 preambel = ""
522 "\r\n-----------------------------97267758015830030481215568065--\r\n"; 522 "\r\n-----------------------------97267758015830030481215568065--\r\n";
523 523
524 content = content.arg( from->text().isEmpty() ? QString( "Anonymous Wellenreiter II User" ) : from->text() ); 524 content = content.arg( from->text().isEmpty() ? QString( "Anonymous Wellenreiter II User" ) : from->text() );
525 content = content.arg( location->text().isEmpty() ? QString( "Anonymous Wellenreiter II Location" ) : location->text() ); 525 content = content.arg( location->text().isEmpty() ? QString( "Anonymous Wellenreiter II Location" ) : location->text() );
526 content = content.arg( comments->text().isEmpty() ? QString( "Anonymous Wellenreiter II Comments" ) : comments->text() ); 526 content = content.arg( comments->text().isEmpty() ? QString( "Anonymous Wellenreiter II Comments" ) : comments->text() );
527 content = content.arg( mw->captureFileName() ); 527 content = content.arg( mw->captureFileName() );
528 528
529 header = header.arg( QString::number( content.length() + f.size() + preambel.length() ) ); 529 header = header.arg( QString::number( content.length() + f.size() + preambel.length() ) );
530 530
531 // write header 531 // write header
532 532
533 const char* ascii = header.latin1(); 533 const char* ascii = header.latin1();
534 uint ascii_len = ::strlen( ascii ); 534 uint ascii_len = ::strlen( ascii );
535 ::write ( sock, ascii, ascii_len ); 535 ::write ( sock, ascii, ascii_len );
536 536
537 // write fixed content 537 // write fixed content
538 538
539 ascii = content.latin1(); 539 ascii = content.latin1();
540 ascii_len = ::strlen( ascii ); 540 ascii_len = ::strlen( ascii );
541 ::write ( sock, ascii, ascii_len ); 541 ::write ( sock, ascii, ascii_len );
542 542
543 // write variable content 543 // write variable content
544 544
545 char ch; 545 char ch;
546 while ( !f.atEnd() ) 546 while ( !f.atEnd() )
547 { 547 {
548 f.readBlock( &ch, 1 ); 548 f.readBlock( &ch, 1 );
549 ::write ( sock, &ch, 1 ); 549 ::write ( sock, &ch, 1 );
550 } 550 }
551 551
552 // write preambel 552 // write preambel
553 553
554 ascii = preambel.latin1(); 554 ascii = preambel.latin1();
555 ascii_len = ::strlen( ascii ); 555 ascii_len = ::strlen( ascii );
556 ::write ( sock, ascii, ascii_len ); 556 ::write ( sock, ascii, ascii_len );
557 557
558 // done! 558 // done!
559 559
560 ok = true; 560 ok = true;
561 } 561 }
562 } 562 }
563 ::close ( sock ); 563 ::close ( sock );
564 } 564 }
565 if ( ok ) 565 if ( ok )
566 QMessageBox::information( 0, tr( "Success" ), 566 QMessageBox::information( 0, tr( "Success" ),
567 QString ( "<p>%1</p>" ).arg( tr( "Capture Dump was uploaded to %1" ) ).arg( CAP_hostname ) ); 567 QString ( "<p>%1</p>" ).arg( tr( "Capture Dump was uploaded to %1" ) ).arg( CAP_hostname ) );
568 else 568 else
569 QMessageBox::warning( 0, tr( "Error" ), 569 QMessageBox::warning( 0, tr( "Error" ),
570 QString ( "<p>%1</p>" ).arg ( tr( "Connection to %1 failed" ) ).arg( CAP_hostname ) ); 570 QString ( "<p>%1</p>" ).arg ( tr( "Connection to %1 failed" ) ).arg( CAP_hostname ) );
571} 571}
572 572
573 573
574void WellenreiterMainWindow::viewExpandAll() 574void WellenreiterMainWindow::viewExpandAll()
575{ 575{
576 mw->netView()->expand(); 576 mw->netView()->expand();
577} 577}
578 578
579void WellenreiterMainWindow::viewCollapseAll() 579void WellenreiterMainWindow::viewCollapseAll()
580{ 580{
581 mw->netView()->collapse(); 581 mw->netView()->collapse();
582} 582}
diff --git a/noncore/net/wellenreiter/gui/scanlist.cpp b/noncore/net/wellenreiter/gui/scanlist.cpp
index a2be782..ed9ec14 100644
--- a/noncore/net/wellenreiter/gui/scanlist.cpp
+++ b/noncore/net/wellenreiter/gui/scanlist.cpp
@@ -1,567 +1,567 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved. 2** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved.
3** 3**
4** This file is part of Wellenreiter II. 4** This file is part of Wellenreiter II.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14**********************************************************************/ 14**********************************************************************/
15 15
16#include "scanlist.h" 16#include "scanlist.h"
17#include "configwindow.h" 17#include "configwindow.h"
18#include "logwindow.h" 18#include "logwindow.h"
19 19
20/* OPIE */ 20/* OPIE */
21#ifdef QWS 21#ifdef QWS
22#include <opie2/odebug.h> 22#include <opie2/odebug.h>
23#include <qpe/qpeapplication.h> 23#include <qpe/qpeapplication.h>
24#include <qpe/resource.h> 24#include <qpe/resource.h>
25#else 25#else
26#include "resource.h" 26#include "resource.h"
27#endif 27#endif
28using namespace Opie::Core; 28using namespace Opie::Core;
29using namespace Opie::Ui; 29using namespace Opie::Ui;
30using namespace Opie::Net; 30using namespace Opie::Net;
31 31
32/* QT */ 32/* QT */
33#include <qcursor.h> 33#include <qcursor.h>
34#include <qdatetime.h> 34#include <qdatetime.h>
35#include <qpopupmenu.h> 35#include <qpopupmenu.h>
36#include <qcheckbox.h> 36#include <qcheckbox.h>
37 37
38/* STD */ 38/* STD */
39#include <assert.h> 39#include <assert.h>
40 40
41const int col_type = 0; 41const int col_type = 0;
42const int col_essid = 0; 42const int col_essid = 0;
43const int col_sig = 1; 43const int col_sig = 1;
44const int col_ap = 2; 44const int col_ap = 2;
45const int col_channel = 3; 45const int col_channel = 3;
46const int col_wep = 4; 46const int col_wep = 4;
47const int col_traffic = 5; 47const int col_traffic = 5;
48const int col_ip = 6; 48const int col_ip = 6;
49const int col_manuf = 7; 49const int col_manuf = 7;
50const int col_firstseen = 8; 50const int col_firstseen = 8;
51const int col_lastseen = 9; 51const int col_lastseen = 9;
52const int col_location = 10; 52const int col_location = 10;
53 53
54MScanListView::MScanListView( QWidget* parent, const char* name ) 54MScanListView::MScanListView( QWidget* parent, const char* name )
55 :OListView( parent, name ) 55 :OListView( parent, name )
56{ 56{
57 setFrameShape( QListView::StyledPanel ); 57 setFrameShape( QListView::StyledPanel );
58 setFrameShadow( QListView::Sunken ); 58 setFrameShadow( QListView::Sunken );
59 59
60 addColumn( tr( "Net/Station" ) ); 60 addColumn( tr( "Net/Station" ) );
61 setColumnAlignment( col_essid, AlignLeft || AlignVCenter ); 61 setColumnAlignment( col_essid, AlignLeft || AlignVCenter );
62 addColumn( tr( "#" ) ); 62 addColumn( tr( "#" ) );
63 setColumnAlignment( col_sig, AlignCenter ); 63 setColumnAlignment( col_sig, AlignCenter );
64 addColumn( tr( "MAC" ) ); 64 addColumn( tr( "MAC" ) );
65 setColumnAlignment( col_ap, AlignCenter ); 65 setColumnAlignment( col_ap, AlignCenter );
66 addColumn( tr( "Chn" ) ); 66 addColumn( tr( "Chn" ) );
67 setColumnAlignment( col_channel, AlignCenter ); 67 setColumnAlignment( col_channel, AlignCenter );
68 addColumn( tr( "W" ) ); 68 addColumn( tr( "W" ) );
69 setColumnAlignment( col_wep, AlignCenter ); 69 setColumnAlignment( col_wep, AlignCenter );
70 addColumn( tr( "T" ) ); 70 addColumn( tr( "T" ) );
71 setColumnAlignment( col_traffic, AlignCenter ); 71 setColumnAlignment( col_traffic, AlignCenter );
72 addColumn( tr( "IP" ) ); 72 addColumn( tr( "IP" ) );
73 setColumnAlignment( col_ip, AlignCenter ); 73 setColumnAlignment( col_ip, AlignCenter );
74 addColumn( tr( "Manufacturer" ) ); 74 addColumn( tr( "Manufacturer" ) );
75 setColumnAlignment( col_manuf, AlignCenter ); 75 setColumnAlignment( col_manuf, AlignCenter );
76 addColumn( tr( "First Seen" ) ); 76 addColumn( tr( "First Seen" ) );
77 setColumnAlignment( col_firstseen, AlignCenter ); 77 setColumnAlignment( col_firstseen, AlignCenter );
78 addColumn( tr( "Last Seen" ) ); 78 addColumn( tr( "Last Seen" ) );
79 setColumnAlignment( col_lastseen, AlignCenter ); 79 setColumnAlignment( col_lastseen, AlignCenter );
80 addColumn( tr( "Location" ) ); 80 addColumn( tr( "Location" ) );
81 setColumnAlignment( col_location, AlignCenter ); 81 setColumnAlignment( col_location, AlignCenter );
82 setRootIsDecorated( true ); 82 setRootIsDecorated( true );
83 setAllColumnsShowFocus( true ); 83 setAllColumnsShowFocus( true );
84 84
85 connect( this, SIGNAL( rightButtonClicked(QListViewItem*,const QPoint&,int) ), 85 connect( this, SIGNAL( rightButtonClicked(QListViewItem*,const QPoint&,int) ),
86 this, SLOT( contextMenuRequested(QListViewItem*,const QPoint&,int) ) ); 86 this, SLOT( contextMenuRequested(QListViewItem*,const QPoint&,int) ) );
87 87
88 #ifdef QWS 88 #ifdef QWS
89 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); 89 QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
90 #endif 90 #endif
91 91
92}; 92};
93 93
94 94
95MScanListView::~MScanListView() 95MScanListView::~MScanListView()
96{ 96{
97}; 97};
98 98
99 99
100OListViewItem* MScanListView::childFactory() 100OListViewItem* MScanListView::childFactory()
101{ 101{
102 return new MScanListItem( this ); 102 return new MScanListItem( this );
103} 103}
104 104
105 105
106void MScanListView::serializeTo( QDataStream& s) const 106void MScanListView::serializeTo( QDataStream& s) const
107{ 107{
108 odebug << "serializing MScanListView" << oendl; 108 odebug << "serializing MScanListView" << oendl;
109 OListView::serializeTo( s ); 109 OListView::serializeTo( s );
110} 110}
111 111
112 112
113void MScanListView::serializeFrom( QDataStream& s) 113void MScanListView::serializeFrom( QDataStream& s)
114{ 114{
115 odebug << "serializing MScanListView" << oendl; 115 odebug << "serializing MScanListView" << oendl;
116 OListView::serializeFrom( s ); 116 OListView::serializeFrom( s );
117} 117}
118 118
119 119
120void MScanListView::addNewItem( const QString& type, 120void MScanListView::addNewItem( const QString& type,
121 const QString& essid, 121 const QString& essid,
122 const OMacAddress& mac, 122 const OMacAddress& mac,
123 bool wep, 123 bool wep,
124 int channel, 124 int channel,
125 int signal, 125 int signal,
126 const GpsLocation& loc, 126 const GpsLocation& loc,
127 bool probe ) 127 bool probe )
128{ 128{
129 QString macaddr = mac.toString(true); 129 QString macaddr = mac.toString(true);
130 130
131 #ifdef DEBUG 131 #ifdef DEBUG
132 qDebug( "MScanList::addNewItem( %s / %s / %s [%d]", (const char*) type, 132 qDebug( "MScanList::addNewItem( %s / %s / %s [%d]", (const char*) type,
133 (const char*) essid, (const char*) macaddr, channel ); 133 (const char*) essid, (const char*) macaddr, channel );
134 #endif 134 #endif
135 135
136 // search, if we already have seen this net 136 // search, if we already have seen this net
137 137
138 QString s; 138 QString s;
139 MScanListItem* network; 139 MScanListItem* network;
140 MScanListItem* item = static_cast<MScanListItem*> ( firstChild() ); 140 MScanListItem* item = static_cast<MScanListItem*> ( firstChild() );
141 141
142 while ( item && ( item->text( col_essid ) != essid ) ) 142 while ( item && ( item->text( col_essid ) != essid ) )
143 { 143 {
144 #ifdef DEBUG 144 #ifdef DEBUG
145 odebug << "itemtext: " << (const char*) item->text( col_essid ) << "" << oendl; 145 odebug << "itemtext: " << item->text( col_essid ) << "" << oendl;
146 #endif 146 #endif
147 item = static_cast<MScanListItem*> ( item->nextSibling() ); 147 item = static_cast<MScanListItem*> ( item->nextSibling() );
148 } 148 }
149 if ( item ) 149 if ( item )
150 { 150 {
151 // we have already seen this net, check all childs if MAC exists 151 // we have already seen this net, check all childs if MAC exists
152 152
153 network = item; 153 network = item;
154 154
155 item = static_cast<MScanListItem*> ( item->firstChild() ); 155 item = static_cast<MScanListItem*> ( item->firstChild() );
156 assert( item ); // this shouldn't fail 156 assert( item ); // this shouldn't fail
157 157
158 while ( item && ( item->text( col_ap ) != macaddr ) ) 158 while ( item && ( item->text( col_ap ) != macaddr ) )
159 { 159 {
160 #ifdef DEBUG 160 #ifdef DEBUG
161 odebug << "subitemtext: " << (const char*) item->text( col_ap ) << "" << oendl; 161 odebug << "subitemtext: " << item->text( col_ap ) << "" << oendl;
162 #endif 162 #endif
163 item = static_cast<MScanListItem*> ( item->nextSibling() ); 163 item = static_cast<MScanListItem*> ( item->nextSibling() );
164 } 164 }
165 165
166 if ( item ) 166 if ( item )
167 { 167 {
168 // we have already seen this item, it's a dupe 168 // we have already seen this item, it's a dupe
169 #ifdef DEBUG 169 #ifdef DEBUG
170 odebug << "" << (const char*) macaddr << " is a dupe - ignoring..." << oendl; 170 odebug << "" << macaddr << " is a dupe - ignoring..." << oendl;
171 #endif 171 #endif
172 item->receivedBeacon(); 172 item->receivedBeacon();
173 return; 173 return;
174 } 174 }
175 } 175 }
176 else 176 else
177 { 177 {
178 s.sprintf( "(i) New network: ESSID '%s'", (const char*) essid ); 178 s.sprintf( "(i) New network: ESSID '%s'", (const char*) essid );
179 MLogWindow::logwindow()->log( s ); 179 MLogWindow::logwindow()->log( s );
180 network = new MScanListItem( this, "network", essid, QString::null, 0, 0, 0, probe ); 180 network = new MScanListItem( this, "network", essid, QString::null, 0, 0, 0, probe );
181 } 181 }
182 182
183 183
184 // insert new station as child from network 184 // insert new station as child from network
185 // no essid to reduce clutter, maybe later we have a nick or stationname to display!? 185 // no essid to reduce clutter, maybe later we have a nick or stationname to display!?
186 186
187 #ifdef DEBUG 187 #ifdef DEBUG
188 odebug << "inserting new station " << (const char*) macaddr << "" << oendl; 188 odebug << "inserting new station " << macaddr << "" << oendl;
189 #endif 189 #endif
190 190
191 MScanListItem* station = new MScanListItem( network, type, "", macaddr, wep, channel, signal ); 191 MScanListItem* station = new MScanListItem( network, type, "", macaddr, wep, channel, signal );
192 station->setManufacturer( mac.manufacturer() ); 192 station->setManufacturer( mac.manufacturer() );
193 station->setLocation( loc.dmsPosition() ); 193 station->setLocation( loc.dmsPosition() );
194 194
195 if ( type == "managed" ) 195 if ( type == "managed" )
196 { 196 {
197 s.sprintf( "(i) New Access Point in '%s' [%d]", (const char*) essid, channel ); 197 s.sprintf( "(i) New Access Point in '%s' [%d]", (const char*) essid, channel );
198 } 198 }
199 else 199 else
200 { 200 {
201 s.sprintf( "(i) New AdHoc station in '%s' [%d]", (const char*) essid, channel ); 201 s.sprintf( "(i) New AdHoc station in '%s' [%d]", (const char*) essid, channel );
202 } 202 }
203 MLogWindow::logwindow()->log( s ); 203 MLogWindow::logwindow()->log( s );
204} 204}
205 205
206 206
207void MScanListView::addIfNotExisting( MScanListItem* network, const OMacAddress& addr, const QString& type ) 207void MScanListView::addIfNotExisting( MScanListItem* network, const OMacAddress& addr, const QString& type )
208{ 208{
209 MScanListItem* subitem = static_cast<MScanListItem*>( network->firstChild() ); 209 MScanListItem* subitem = static_cast<MScanListItem*>( network->firstChild() );
210 210
211 while ( subitem && ( subitem->text( col_ap ) != addr.toString(true) ) ) 211 while ( subitem && ( subitem->text( col_ap ) != addr.toString(true) ) )
212 { 212 {
213 #ifdef DEBUG 213 #ifdef DEBUG
214 odebug << "subitemtext: " << (const char*) subitem->text( col_ap ) << "" << oendl; 214 odebug << "subitemtext: " << subitem->text( col_ap ) << "" << oendl;
215 #endif 215 #endif
216 subitem = static_cast<MScanListItem*> ( subitem->nextSibling() ); 216 subitem = static_cast<MScanListItem*> ( subitem->nextSibling() );
217 } 217 }
218 218
219 if ( subitem ) 219 if ( subitem )
220 { 220 {
221 // we have already seen this item, it's a dupe 221 // we have already seen this item, it's a dupe
222 #ifdef DEBUG 222 #ifdef DEBUG
223 odebug << "" << (const char*) addr.toString(true) << " is a dupe - ignoring..." << oendl; 223 odebug << "" << addr.toString(true) << " is a dupe - ignoring..." << oendl;
224 #endif 224 #endif
225 subitem->receivedBeacon(); //FIXME: sent data bit 225 subitem->receivedBeacon(); //FIXME: sent data bit
226 return; 226 return;
227 } 227 }
228 228
229 // Hey, it seems to be a new item :-D 229 // Hey, it seems to be a new item :-D
230 MScanListItem* station = new MScanListItem( network, type, /* network->text( col_essid ) */ "", addr.toString(true), false, -1, -1 ); 230 MScanListItem* station = new MScanListItem( network, type, /* network->text( col_essid ) */ "", addr.toString(true), false, -1, -1 );
231 station->setManufacturer( addr.manufacturer() ); 231 station->setManufacturer( addr.manufacturer() );
232 232
233 QString s; 233 QString s;
234 if ( type == "station" ) 234 if ( type == "station" )
235 { 235 {
236 s.sprintf( "(i) New Station in '%s' [xx]", (const char*) network->text( col_essid ) ); 236 s.sprintf( "(i) New Station in '%s' [xx]", (const char*) network->text( col_essid ) );
237 } 237 }
238 else 238 else
239 { 239 {
240 s.sprintf( "(i) New Wireless Station in '%s' [xx]", (const char*) network->text( col_essid ) ); 240 s.sprintf( "(i) New Wireless Station in '%s' [xx]", (const char*) network->text( col_essid ) );
241 } 241 }
242 MLogWindow::logwindow()->log( s ); 242 MLogWindow::logwindow()->log( s );
243} 243}
244 244
245 245
246void MScanListView::WDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& viaFrom, const OMacAddress& viaTo ) 246void MScanListView::WDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& viaFrom, const OMacAddress& viaTo )
247{ 247{
248 odebug << "WDSTraffic: " << (const char*) viaFrom.toString() << " and " << (const char*) viaTo.toString() << " seem to form a WDS" << oendl; 248 odebug << "WDSTraffic: " << (const char*) viaFrom.toString() << " and " << viaTo.toString() << " seem to form a WDS" << oendl;
249 QString s; 249 QString s;
250 MScanListItem* network; 250 MScanListItem* network;
251 251
252 QListViewItemIterator it( this ); 252 QListViewItemIterator it( this );
253 while ( it.current() && 253 while ( it.current() &&
254 it.current()->text( col_ap ) != viaFrom.toString(true) && 254 it.current()->text( col_ap ) != viaFrom.toString(true) &&
255 it.current()->text( col_ap ) != viaTo.toString(true) ) ++it; 255 it.current()->text( col_ap ) != viaTo.toString(true) ) ++it;
256 256
257 MScanListItem* item = static_cast<MScanListItem*>( it.current() ); 257 MScanListItem* item = static_cast<MScanListItem*>( it.current() );
258 258
259 if ( item ) // Either viaFrom or viaTo AP has shown up yet, so just add our two new stations 259 if ( item ) // Either viaFrom or viaTo AP has shown up yet, so just add our two new stations
260 { 260 {
261 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from ); 261 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from );
262 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), to ); 262 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), to );
263 } 263 }
264 else 264 else
265 { 265 {
266 odebug << "D'Oh! Stations without AP... ignoring for now... will handle this in 1.1 version :-D" << oendl; 266 odebug << "D'Oh! Stations without AP... ignoring for now... will handle this in 1.1 version :-D" << oendl;
267 MLogWindow::logwindow()->log( "WARNING: Unhandled WSD traffic!" ); 267 MLogWindow::logwindow()->log( "WARNING: Unhandled WSD traffic!" );
268 } 268 }
269} 269}
270 270
271 271
272void MScanListView::toDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via ) 272void MScanListView::toDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via )
273{ 273{
274 QString s; 274 QString s;
275 MScanListItem* network; 275 MScanListItem* network;
276 276
277 QListViewItemIterator it( this ); 277 QListViewItemIterator it( this );
278 while ( it.current() && it.current()->text( col_ap ) != via.toString(true) ) ++it; 278 while ( it.current() && it.current()->text( col_ap ) != via.toString(true) ) ++it;
279 279
280 MScanListItem* item = static_cast<MScanListItem*>( it.current() ); 280 MScanListItem* item = static_cast<MScanListItem*>( it.current() );
281 281
282 if ( item ) // AP has shown up yet, so just add our new "from" - station 282 if ( item ) // AP has shown up yet, so just add our new "from" - station
283 { 283 {
284 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from, "adhoc" ); 284 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from, "adhoc" );
285 } 285 }
286 else 286 else
287 { 287 {
288 odebug << "D'Oh! Station without AP... ignoring for now... will handle this in 1.1 :-D" << oendl; 288 odebug << "D'Oh! Station without AP... ignoring for now... will handle this in 1.1 :-D" << oendl;
289 MLogWindow::logwindow()->log( "WARNING: Unhandled toDS traffic!" ); 289 MLogWindow::logwindow()->log( "WARNING: Unhandled toDS traffic!" );
290 290
291 } 291 }
292} 292}
293 293
294 294
295void MScanListView::fromDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via ) 295void MScanListView::fromDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via )
296{ 296{
297 QString s; 297 QString s;
298 MScanListItem* network; 298 MScanListItem* network;
299 299
300 QListViewItemIterator it( this ); 300 QListViewItemIterator it( this );
301 while ( it.current() && it.current()->text( col_ap ) != via.toString(true) ) ++it; 301 while ( it.current() && it.current()->text( col_ap ) != via.toString(true) ) ++it;
302 302
303 MScanListItem* item = static_cast<MScanListItem*>( it.current() ); 303 MScanListItem* item = static_cast<MScanListItem*>( it.current() );
304 304
305 if ( item ) // AP has shown up yet, so just add our new "from" - station 305 if ( item ) // AP has shown up yet, so just add our new "from" - station
306 { 306 {
307 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from, "station" ); 307 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from, "station" );
308 } 308 }
309 else 309 else
310 { 310 {
311 odebug << "D'Oh! Station without AP... ignoring for now... will handle this in 1.1 :-D" << oendl; 311 odebug << "D'Oh! Station without AP... ignoring for now... will handle this in 1.1 :-D" << oendl;
312 MLogWindow::logwindow()->log( "WARNING: Unhandled fromDS traffic!" ); 312 MLogWindow::logwindow()->log( "WARNING: Unhandled fromDS traffic!" );
313 } 313 }
314} 314}
315 315
316 316
317void MScanListView::IBSStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via ) 317void MScanListView::IBSStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via )
318{ 318{
319 owarn << "D'oh! Not yet implemented..." << oendl; 319 owarn << "D'oh! Not yet implemented..." << oendl;
320 MLogWindow::logwindow()->log( "WARNING: Unhandled IBSS traffic!" ); 320 MLogWindow::logwindow()->log( "WARNING: Unhandled IBSS traffic!" );
321} 321}
322 322
323 323
324void MScanListView::identify( const OMacAddress& macaddr, const QString& ip ) 324void MScanListView::identify( const OMacAddress& macaddr, const QString& ip )
325{ 325{
326 odebug << "identify " << (const char*) macaddr.toString() << " = " << (const char*) ip << "" << oendl; 326 odebug << "identify " << (const char*) macaddr.toString() << " = " << ip << "" << oendl;
327 327
328 QListViewItemIterator it( this ); 328 QListViewItemIterator it( this );
329 for ( ; it.current(); ++it ) 329 for ( ; it.current(); ++it )
330 { 330 {
331 if ( it.current()->text( col_ap ) == macaddr.toString(true) ) 331 if ( it.current()->text( col_ap ) == macaddr.toString(true) )
332 { 332 {
333 it.current()->setText( col_ip, ip ); 333 it.current()->setText( col_ip, ip );
334 return; 334 return;
335 } 335 }
336 } 336 }
337 odebug << "D'oh! Received identification, but item not yet in list... ==> Handle this!" << oendl; 337 odebug << "D'oh! Received identification, but item not yet in list... ==> Handle this!" << oendl;
338 MLogWindow::logwindow()->log( QString().sprintf( "WARNING: Unhandled identification %s = %s!", 338 MLogWindow::logwindow()->log( QString().sprintf( "WARNING: Unhandled identification %s = %s!",
339 (const char*) macaddr.toString(), (const char*) ip ) ); 339 (const char*) macaddr.toString(), (const char*) ip ) );
340} 340}
341 341
342 342
343void MScanListView::addService( const QString& name, const OMacAddress& macaddr, const QString& ip ) 343void MScanListView::addService( const QString& name, const OMacAddress& macaddr, const QString& ip )
344{ 344{
345 odebug << "addService '" << (const char*) name << "', Server = " << (const char*) macaddr.toString() << " = " << (const char*) ip << "" << oendl; 345 odebug << "addService '" << (const char*) name << "', Server = " << (const char*) macaddr.toString() << " = " << ip << "" << oendl;
346 346
347 //TODO: Refactor that out, we need it all over the place. 347 //TODO: Refactor that out, we need it all over the place.
348 // Best to do it in a more comfortable abstraction in OListView 348 // Best to do it in a more comfortable abstraction in OListView
349 // (Hmm, didn't I already start something in this direction?) 349 // (Hmm, didn't I already start something in this direction?)
350 350
351 QListViewItemIterator it( this ); 351 QListViewItemIterator it( this );
352 for ( ; it.current(); ++it ) 352 for ( ; it.current(); ++it )
353 { 353 {
354 if ( it.current()->text( col_ap ) == macaddr.toString(true) ) 354 if ( it.current()->text( col_ap ) == macaddr.toString(true) )
355 { 355 {
356 356
357 MScanListItem* subitem = static_cast<MScanListItem*>( it.current()->firstChild() ); 357 MScanListItem* subitem = static_cast<MScanListItem*>( it.current()->firstChild() );
358 358
359 while ( subitem && ( subitem->text( col_essid ) != name ) ) 359 while ( subitem && ( subitem->text( col_essid ) != name ) )
360 { 360 {
361 #ifdef DEBUG 361 #ifdef DEBUG
362 odebug << "subitemtext: " << (const char*) subitem->text( col_essid ) << "" << oendl; 362 odebug << "subitemtext: " << subitem->text( col_essid ) << "" << oendl;
363 #endif 363 #endif
364 subitem = static_cast<MScanListItem*> ( subitem->nextSibling() ); 364 subitem = static_cast<MScanListItem*> ( subitem->nextSibling() );
365 } 365 }
366 366
367 if ( subitem ) 367 if ( subitem )
368 { 368 {
369 // we have already seen this item, it's a dupe 369 // we have already seen this item, it's a dupe
370 #ifdef DEBUG 370 #ifdef DEBUG
371 odebug << "" << (const char*) name << " is a dupe - ignoring..." << oendl; 371 odebug << "" << name << " is a dupe - ignoring..." << oendl;
372 #endif 372 #endif
373 subitem->receivedBeacon(); //FIXME: sent data bit 373 subitem->receivedBeacon(); //FIXME: sent data bit
374 return; 374 return;
375 } 375 }
376 376
377 // never seen that - add new item 377 // never seen that - add new item
378 378
379 MScanListItem* item = new MScanListItem( it.current(), "service", "N/A", " ", false, -1, -1 ); 379 MScanListItem* item = new MScanListItem( it.current(), "service", "N/A", " ", false, -1, -1 );
380 item->setText( col_essid, name ); 380 item->setText( col_essid, name );
381 381
382 return; 382 return;
383 } 383 }
384 } 384 }
385 odebug << "D'oh! Received identification, but item not yet in list... ==> Handle this!" << oendl; 385 odebug << "D'oh! Received identification, but item not yet in list... ==> Handle this!" << oendl;
386 MLogWindow::logwindow()->log( QString().sprintf( "WARNING: Unhandled service addition %s = %s!", 386 MLogWindow::logwindow()->log( QString().sprintf( "WARNING: Unhandled service addition %s = %s!",
387 (const char*) macaddr.toString(), (const char*) ip ) ); 387 (const char*) macaddr.toString(), (const char*) ip ) );
388} 388}
389 389
390 390
391void MScanListView::contextMenuRequested( QListViewItem* item, const QPoint&, int col ) 391void MScanListView::contextMenuRequested( QListViewItem* item, const QPoint&, int col )
392{ 392{
393 if ( !item ) return; 393 if ( !item ) return;
394 394
395 MScanListItem* itm = static_cast<MScanListItem*>( item ); 395 MScanListItem* itm = static_cast<MScanListItem*>( item );
396 396
397 qDebug( "contextMenuRequested on item '%s' (%s) in column: '%d'", 397 qDebug( "contextMenuRequested on item '%s' (%s) in column: '%d'",
398 (const char*) itm->text(0), (const char*) itm->type, col ); 398 (const char*) itm->text(0), (const char*) itm->type, col );
399 399
400 if ( itm->type == "adhoc" || itm->type == "managed" ) 400 if ( itm->type == "adhoc" || itm->type == "managed" )
401 { 401 {
402 QString entry = QString().sprintf( "&Join %s Net '%s'...", (const char*) itm->type, (const char*) itm->essid() ); 402 QString entry = QString().sprintf( "&Join %s Net '%s'...", (const char*) itm->type, (const char*) itm->essid() );
403 403
404 QPopupMenu m( this ); 404 QPopupMenu m( this );
405 m.insertItem( entry, 37773, 0 ); 405 m.insertItem( entry, 37773, 0 );
406 int result = m.exec( QCursor::pos() ); 406 int result = m.exec( QCursor::pos() );
407 if ( result == 37773 ) 407 if ( result == 37773 )
408 emit joinNetwork( itm->type, itm->essid(), itm->channel(), itm->macaddr() ); 408 emit joinNetwork( itm->type, itm->essid(), itm->channel(), itm->macaddr() );
409 } 409 }
410} 410}
411 411
412//============================================================ 412//============================================================
413// MScanListItem 413// MScanListItem
414//============================================================ 414//============================================================
415 415
416MScanListItem::MScanListItem( QListView* parent, const QString& type, const QString& essid, const QString& macaddr, 416MScanListItem::MScanListItem( QListView* parent, const QString& type, const QString& essid, const QString& macaddr,
417 bool wep, int channel, int signal, bool probed ) 417 bool wep, int channel, int signal, bool probed )
418 :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null ), 418 :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null ),
419 _type( type ), _essid( essid ), _macaddr( macaddr ), _wep( wep ), 419 _type( type ), _essid( essid ), _macaddr( macaddr ), _wep( wep ),
420 _channel( channel ), _signal( signal ), _beacons( 1 ) 420 _channel( channel ), _signal( signal ), _beacons( 1 )
421{ 421{
422 #ifdef DEBUG 422 #ifdef DEBUG
423 odebug << "creating scanlist item" << oendl; 423 odebug << "creating scanlist item" << oendl;
424 #endif 424 #endif
425 425
426 if ( WellenreiterConfigWindow::instance() ) 426 if ( WellenreiterConfigWindow::instance() )
427 WellenreiterConfigWindow::instance()->performAction( type, essid, macaddr, wep, channel, signal ); // better use signal/slot combination here 427 WellenreiterConfigWindow::instance()->performAction( type, essid, macaddr, wep, channel, signal ); // better use signal/slot combination here
428 428
429 decorateItem( type, essid, macaddr, wep, channel, signal, probed ); 429 decorateItem( type, essid, macaddr, wep, channel, signal, probed );
430} 430}
431 431
432MScanListItem::MScanListItem( QListViewItem* parent, const QString& type, const QString& essid, const QString& macaddr, 432MScanListItem::MScanListItem( QListViewItem* parent, const QString& type, const QString& essid, const QString& macaddr,
433 bool wep, int channel, int signal ) 433 bool wep, int channel, int signal )
434 :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null ) 434 :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null )
435{ 435{
436 #ifdef DEBUG 436 #ifdef DEBUG
437 odebug << "creating scanlist item" << oendl; 437 odebug << "creating scanlist item" << oendl;
438 #endif 438 #endif
439 if ( WellenreiterConfigWindow::instance() ) 439 if ( WellenreiterConfigWindow::instance() )
440 WellenreiterConfigWindow::instance()->performAction( type, essid, macaddr, wep, channel, signal ); // better use signal/slot combination here 440 WellenreiterConfigWindow::instance()->performAction( type, essid, macaddr, wep, channel, signal ); // better use signal/slot combination here
441 441
442 decorateItem( type, essid, macaddr, wep, channel, signal, false ); 442 decorateItem( type, essid, macaddr, wep, channel, signal, false );
443} 443}
444 444
445const QString& MScanListItem::essid() const 445const QString& MScanListItem::essid() const
446{ 446{
447 if ( type == "network" ) 447 if ( type == "network" )
448 return _essid; 448 return _essid;
449 else 449 else
450 return ( (MScanListItem*) parent() )->essid(); 450 return ( (MScanListItem*) parent() )->essid();
451} 451}
452 452
453OListViewItem* MScanListItem::childFactory() 453OListViewItem* MScanListItem::childFactory()
454{ 454{
455 return new MScanListItem( this ); 455 return new MScanListItem( this );
456} 456}
457 457
458void MScanListItem::serializeTo( QDataStream& s ) const 458void MScanListItem::serializeTo( QDataStream& s ) const
459{ 459{
460 #ifdef DEBUG 460 #ifdef DEBUG
461 odebug << "serializing MScanListItem" << oendl; 461 odebug << "serializing MScanListItem" << oendl;
462 #endif 462 #endif
463 OListViewItem::serializeTo( s ); 463 OListViewItem::serializeTo( s );
464 464
465 s << _type; 465 s << _type;
466 s << (Q_UINT8) ( _wep ? 'y' : 'n' ); 466 s << (Q_UINT8) ( _wep ? 'y' : 'n' );
467} 467}
468 468
469void MScanListItem::serializeFrom( QDataStream& s ) 469void MScanListItem::serializeFrom( QDataStream& s )
470{ 470{
471 #ifdef DEBUG 471 #ifdef DEBUG
472 odebug << "serializing MScanListItem" << oendl; 472 odebug << "serializing MScanListItem" << oendl;
473 #endif 473 #endif
474 OListViewItem::serializeFrom( s ); 474 OListViewItem::serializeFrom( s );
475 475
476 char wep; 476 char wep;
477 s >> _type; 477 s >> _type;
478 s >> (Q_UINT8) wep; 478 s >> (Q_UINT8) wep;
479 _wep = (wep == 'y'); 479 _wep = (wep == 'y');
480 480
481 QString name; 481 QString name;
482 name.sprintf( "wellenreiter/%s", (const char*) _type ); 482 name.sprintf( "wellenreiter/%s", (const char*) _type );
483 setPixmap( col_type, Resource::loadPixmap( name ) ); 483 setPixmap( col_type, Resource::loadPixmap( name ) );
484 if ( _wep ) 484 if ( _wep )
485 setPixmap( col_wep, Resource::loadPixmap( "wellenreiter/cracked" ) ); //FIXME: rename the pixmap! 485 setPixmap( col_wep, Resource::loadPixmap( "wellenreiter/cracked" ) ); //FIXME: rename the pixmap!
486 listView()->triggerUpdate(); 486 listView()->triggerUpdate();
487} 487}
488 488
489void MScanListItem::decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal, bool probed ) 489void MScanListItem::decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal, bool probed )
490{ 490{
491 #ifdef DEBUG 491 #ifdef DEBUG
492 qDebug( "decorating scanlist item %s / %s / %s [%d]", 492 qDebug( "decorating scanlist item %s / %s / %s [%d]",
493 (const char*) type, 493 (const char*) type,
494 (const char*) essid, 494 (const char*) essid,
495 (const char*) macaddr, 495 (const char*) macaddr,
496 channel ); 496 channel );
497 #endif 497 #endif
498 498
499 // set icon for managed or adhoc mode 499 // set icon for managed or adhoc mode
500 QString name; 500 QString name;
501 name.sprintf( "wellenreiter/%s", (const char*) type ); 501 name.sprintf( "wellenreiter/%s", (const char*) type );
502 setPixmap( col_type, Resource::loadPixmap( name ) ); 502 setPixmap( col_type, Resource::loadPixmap( name ) );
503 503
504 // special case for probed networks FIXME: This is ugly at present 504 // special case for probed networks FIXME: This is ugly at present
505 if ( type == "network" && probed ) 505 if ( type == "network" && probed )
506 { 506 {
507 setPixmap( col_type, Resource::loadPixmap( "wellenreiter/network-probed.png" ) ); 507 setPixmap( col_type, Resource::loadPixmap( "wellenreiter/network-probed.png" ) );
508 } 508 }
509 509
510 // set icon for wep (wireless encryption protocol) 510 // set icon for wep (wireless encryption protocol)
511 if ( wep ) 511 if ( wep )
512 setPixmap( col_wep, Resource::loadPixmap( "wellenreiter/cracked" ) ); //FIXME: rename the pixmap! 512 setPixmap( col_wep, Resource::loadPixmap( "wellenreiter/cracked" ) ); //FIXME: rename the pixmap!
513 513
514 // set channel and signal text 514 // set channel and signal text
515 515
516 if ( signal != -1 ) 516 if ( signal != -1 )
517 setText( col_sig, QString::number( signal ) ); 517 setText( col_sig, QString::number( signal ) );
518 if ( channel != -1 ) 518 if ( channel != -1 )
519 setText( col_channel, QString::number( channel ) ); 519 setText( col_channel, QString::number( channel ) );
520 520
521 setText( col_firstseen, QTime::currentTime().toString() ); 521 setText( col_firstseen, QTime::currentTime().toString() );
522 //setText( col_lastseen, QTime::currentTime().toString() ); 522 //setText( col_lastseen, QTime::currentTime().toString() );
523 523
524 listView()->triggerUpdate(); 524 listView()->triggerUpdate();
525 525
526 this->type = type; 526 this->type = type;
527 _type = type; 527 _type = type;
528 _essid = essid; 528 _essid = essid;
529 _macaddr = macaddr; 529 _macaddr = macaddr;
530 _channel = channel; 530 _channel = channel;
531 _beacons = 1; 531 _beacons = 1;
532 _signal = 0; 532 _signal = 0;
533 533
534 if ( WellenreiterConfigWindow::instance()->openTree->isChecked() ) 534 if ( WellenreiterConfigWindow::instance()->openTree->isChecked() )
535 { 535 {
536 listView()->ensureItemVisible( this ); 536 listView()->ensureItemVisible( this );
537 } 537 }
538 538
539} 539}
540 540
541 541
542void MScanListItem::setManufacturer( const QString& manufacturer ) 542void MScanListItem::setManufacturer( const QString& manufacturer )
543{ 543{
544 setText( col_manuf, manufacturer ); 544 setText( col_manuf, manufacturer );
545} 545}
546 546
547 547
548void MScanListItem::setLocation( const QString& location ) 548void MScanListItem::setLocation( const QString& location )
549{ 549{
550 setText( col_location, location ); 550 setText( col_location, location );
551} 551}
552 552
553 553
554void MScanListItem::receivedBeacon() 554void MScanListItem::receivedBeacon()
555{ 555{
556 _beacons++; 556 _beacons++;
557 #ifdef DEBUG 557 #ifdef DEBUG
558 odebug << "MScanListItem " << (const char*) _macaddr << ": received beacon #" << _beacons << "" << oendl; 558 odebug << "MScanListItem " << _macaddr << ": received beacon #" << _beacons << "" << oendl;
559 #endif 559 #endif
560 setText( col_sig, QString::number( _beacons ) ); 560 setText( col_sig, QString::number( _beacons ) );
561 setText( col_lastseen, QTime::currentTime().toString() ); 561 setText( col_lastseen, QTime::currentTime().toString() );
562 562
563 MScanListItem* p = (MScanListItem*) parent(); 563 MScanListItem* p = (MScanListItem*) parent();
564 if ( p ) p->receivedBeacon(); 564 if ( p ) p->receivedBeacon();
565 565
566} 566}
567 567
diff --git a/noncore/net/wellenreiter/gui/wellenreiter.cpp b/noncore/net/wellenreiter/gui/wellenreiter.cpp
index fad6efd..822bde8 100644
--- a/noncore/net/wellenreiter/gui/wellenreiter.cpp
+++ b/noncore/net/wellenreiter/gui/wellenreiter.cpp
@@ -1,725 +1,725 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved. 2** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved.
3** 3**
4** This file may be distributed and/or modified under the terms of the 4** This file may be distributed and/or modified under the terms of the
5** GNU General Public License version 2 as published by the Free Software 5** GNU General Public License version 2 as published by the Free Software
6** Foundation and appearing in the file LICENSE.GPL included in the 6** Foundation and appearing in the file LICENSE.GPL included in the
7** packaging of this file. 7** packaging of this file.
8** 8**
9** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 9** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 10** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11** 11**
12***********************************************************************/ 12***********************************************************************/
13 13
14#include "gps.h" 14#include "gps.h"
15#include "wellenreiter.h" 15#include "wellenreiter.h"
16#include "scanlist.h" 16#include "scanlist.h"
17#include "logwindow.h" 17#include "logwindow.h"
18#include "packetview.h" 18#include "packetview.h"
19#include "configwindow.h" 19#include "configwindow.h"
20#include "statwindow.h" 20#include "statwindow.h"
21#include "graphwindow.h" 21#include "graphwindow.h"
22#include "protolistview.h" 22#include "protolistview.h"
23 23
24/* OPIE */ 24/* OPIE */
25#ifdef QWS 25#ifdef QWS
26#include <opie2/oapplication.h> 26#include <opie2/oapplication.h>
27#include <opie2/odebug.h> 27#include <opie2/odebug.h>
28#include <opie2/odevice.h> 28#include <opie2/odevice.h>
29#else 29#else
30#include <qapplication.h> 30#include <qapplication.h>
31#endif 31#endif
32#include <opie2/omanufacturerdb.h> 32#include <opie2/omanufacturerdb.h>
33#include <opie2/onetwork.h> 33#include <opie2/onetwork.h>
34#include <opie2/opcap.h> 34#include <opie2/opcap.h>
35#include <qpe/qcopenvelope_qws.h> 35#include <qpe/qcopenvelope_qws.h>
36using namespace Opie::Core; 36using namespace Opie::Core;
37using namespace Opie::Net; 37using namespace Opie::Net;
38using namespace Opie::Ui; 38using namespace Opie::Ui;
39 39
40/* QT */ 40/* QT */
41#include <qcheckbox.h> 41#include <qcheckbox.h>
42#include <qcombobox.h> 42#include <qcombobox.h>
43#include <qdatetime.h> 43#include <qdatetime.h>
44#include <qpushbutton.h> 44#include <qpushbutton.h>
45#include <qlineedit.h> 45#include <qlineedit.h>
46#include <qmessagebox.h> 46#include <qmessagebox.h>
47#include <qobjectlist.h> 47#include <qobjectlist.h>
48#include <qregexp.h> 48#include <qregexp.h>
49#include <qspinbox.h> 49#include <qspinbox.h>
50#include <qtimer.h> 50#include <qtimer.h>
51#include <qtoolbutton.h> 51#include <qtoolbutton.h>
52#include <qmainwindow.h> 52#include <qmainwindow.h>
53 53
54/* STD */ 54/* STD */
55#include <assert.h> 55#include <assert.h>
56#include <errno.h> 56#include <errno.h>
57#include <unistd.h> 57#include <unistd.h>
58#include <string.h> 58#include <string.h>
59#include <sys/types.h> 59#include <sys/types.h>
60#include <stdlib.h> 60#include <stdlib.h>
61 61
62Wellenreiter::Wellenreiter( QWidget* parent ) 62Wellenreiter::Wellenreiter( QWidget* parent )
63 : WellenreiterBase( parent, 0, 0 ), 63 : WellenreiterBase( parent, 0, 0 ),
64 sniffing( false ), iface( 0 ), configwindow( 0 ) 64 sniffing( false ), iface( 0 ), configwindow( 0 )
65{ 65{
66 66
67 logwindow->log( "(i) Wellenreiter has been started." ); 67 logwindow->log( "(i) Wellenreiter has been started." );
68 68
69 // 69 //
70 // detect operating system 70 // detect operating system
71 // 71 //
72 72
73 #ifdef QWS 73 #ifdef QWS
74 QString sys; 74 QString sys;
75 sys.sprintf( "(i) Running on '%s'.", (const char*) ODevice::inst()->systemString() ); 75 sys.sprintf( "(i) Running on '%s'.", (const char*) ODevice::inst()->systemString() );
76 _system = ODevice::inst()->system(); 76 _system = ODevice::inst()->system();
77 logwindow->log( sys ); 77 logwindow->log( sys );
78 #endif 78 #endif
79 79
80 netview->setColumnWidthMode( 1, QListView::Manual ); 80 netview->setColumnWidthMode( 1, QListView::Manual );
81 connect( netview, SIGNAL( joinNetwork(const QString&,const QString&,int,const QString&) ), 81 connect( netview, SIGNAL( joinNetwork(const QString&,const QString&,int,const QString&) ),
82 this, SLOT( joinNetwork(const QString&,const QString&,int,const QString&) ) ); 82 this, SLOT( joinNetwork(const QString&,const QString&,int,const QString&) ) );
83 pcap = new OPacketCapturer(); 83 pcap = new OPacketCapturer();
84 pcap->setAutoDelete( false ); 84 pcap->setAutoDelete( false );
85 85
86 gps = new GPS( this ); 86 gps = new GPS( this );
87 87
88 QTimer::singleShot( 1000, this, SLOT( initialTimer() ) ); 88 QTimer::singleShot( 1000, this, SLOT( initialTimer() ) );
89 89
90} 90}
91 91
92 92
93Wellenreiter::~Wellenreiter() 93Wellenreiter::~Wellenreiter()
94{ 94{
95 delete pcap; 95 delete pcap;
96} 96}
97 97
98 98
99void Wellenreiter::initialTimer() 99void Wellenreiter::initialTimer()
100{ 100{
101 odebug << "Wellenreiter::preloading manufacturer database..." << oendl; 101 odebug << "Wellenreiter::preloading manufacturer database..." << oendl;
102 OManufacturerDB::instance(); 102 OManufacturerDB::instance();
103} 103}
104 104
105 105
106void Wellenreiter::setConfigWindow( WellenreiterConfigWindow* cw ) 106void Wellenreiter::setConfigWindow( WellenreiterConfigWindow* cw )
107{ 107{
108 configwindow = cw; 108 configwindow = cw;
109} 109}
110 110
111 111
112void Wellenreiter::channelHopped(int c) 112void Wellenreiter::channelHopped(int c)
113{ 113{
114 QString title = "Wellenreiter II -scan- ["; 114 QString title = "Wellenreiter II -scan- [";
115 QString left; 115 QString left;
116 if ( c > 1 ) left.fill( '.', c-1 ); 116 if ( c > 1 ) left.fill( '.', c-1 );
117 title.append( left ); 117 title.append( left );
118 title.append( '|' ); 118 title.append( '|' );
119 if ( c < iface->channels() ) 119 if ( c < iface->channels() )
120 { 120 {
121 QString right; 121 QString right;
122 right.fill( '.', iface->channels()-c ); 122 right.fill( '.', iface->channels()-c );
123 title.append( right ); 123 title.append( right );
124 } 124 }
125 title.append( "]" ); 125 title.append( "]" );
126 //title.append( QString().sprintf( " %02d", c ) ); 126 //title.append( QString().sprintf( " %02d", c ) );
127 assert( parent() ); 127 assert( parent() );
128 ( (QMainWindow*) parent() )->setCaption( title ); 128 ( (QMainWindow*) parent() )->setCaption( title );
129} 129}
130 130
131 131
132void Wellenreiter::handleNotification( OPacket* p ) 132void Wellenreiter::handleNotification( OPacket* p )
133{ 133{
134 QObjectList* l = p->queryList(); 134 QObjectList* l = p->queryList();
135 QObjectListIt it( *l ); 135 QObjectListIt it( *l );
136 QObject* o; 136 QObject* o;
137 137
138 while ( (o = it.current()) != 0 ) 138 while ( (o = it.current()) != 0 )
139 { 139 {
140 QString name = it.current()->name(); 140 QString name = it.current()->name();
141 if ( configwindow->parsePackets->isProtocolChecked( name ) ) 141 if ( configwindow->parsePackets->isProtocolChecked( name ) )
142 { 142 {
143 QString action = configwindow->parsePackets->protocolAction( name ); 143 QString action = configwindow->parsePackets->protocolAction( name );
144 odebug << "parsePacket-action for '" << (const char*) name << "' seems to be '" << (const char*) action << "'" << oendl; 144 odebug << "parsePacket-action for '" << (const char*) name << "' seems to be '" << action << "'" << oendl;
145 doAction( action, name, p ); 145 doAction( action, name, p );
146 } 146 }
147 else 147 else
148 { 148 {
149 odebug << "protocol '" << (const char*) name << "' not checked in parsePackets." << oendl; 149 odebug << "protocol '" << name << "' not checked in parsePackets." << oendl;
150 } 150 }
151 ++it; 151 ++it;
152 } 152 }
153} 153}
154 154
155 155
156void Wellenreiter::handleManagementFrame( OPacket* p, OWaveLanManagementPacket* manage ) 156void Wellenreiter::handleManagementFrame( OPacket* p, OWaveLanManagementPacket* manage )
157{ 157{
158 if ( manage->managementType() == "Beacon" ) handleManagementFrameBeacon( p, manage ); 158 if ( manage->managementType() == "Beacon" ) handleManagementFrameBeacon( p, manage );
159 else if ( manage->managementType() == "ProbeRequest" ) handleManagementFrameProbeRequest( p, manage ); 159 else if ( manage->managementType() == "ProbeRequest" ) handleManagementFrameProbeRequest( p, manage );
160 else if ( manage->managementType() == "ProbeResponse" ) handleManagementFrameProbeResponse( p, manage ); 160 else if ( manage->managementType() == "ProbeResponse" ) handleManagementFrameProbeResponse( p, manage );
161 else owarn << "Wellenreiter::handleManagementFrame(): '" << (const char*) manage->managementType() << "' - please handle me!" << oendl; 161 else owarn << "Wellenreiter::handleManagementFrame(): '" << manage->managementType() << "' - please handle me!" << oendl;
162} 162}
163 163
164 164
165void Wellenreiter::handleManagementFrameProbeRequest( OPacket* p, OWaveLanManagementPacket* request ) 165void Wellenreiter::handleManagementFrameProbeRequest( OPacket* p, OWaveLanManagementPacket* request )
166{ 166{
167 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); 167 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) );
168 QString essid = ssid ? ssid->ID( true /* decloak */ ) : QString("<unknown>"); 168 QString essid = ssid ? ssid->ID( true /* decloak */ ) : QString("<unknown>");
169 OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) ); 169 OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) );
170 int channel = ds ? ds->channel() : -1; 170 int channel = ds ? ds->channel() : -1;
171 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) ); 171 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) );
172 172
173 GpsLocation loc( -111, -111 ); 173 GpsLocation loc( -111, -111 );
174 if ( configwindow->enableGPS->isChecked() ) 174 if ( configwindow->enableGPS->isChecked() )
175 { 175 {
176 // TODO: add check if GPS is working!? 176 // TODO: add check if GPS is working!?
177 odebug << "Wellenreiter::gathering GPS data..." << oendl; 177 odebug << "Wellenreiter::gathering GPS data..." << oendl;
178 loc = gps->position(); 178 loc = gps->position();
179 odebug << "Wellenreiter::GPS data received is ( " << loc.latitude() << " , " << loc.longitude() << " ) - dms string = '" << loc.dmsPosition().latin1() << "'" << oendl; 179 odebug << "Wellenreiter::GPS data received is ( " << loc.latitude() << " , " << loc.longitude() << " ) - dms string = '" << loc.dmsPosition().latin1() << "'" << oendl;
180 } 180 }
181 181
182 if ( essid.length() ) 182 if ( essid.length() )
183 netView()->addNewItem( "adhoc", essid, header->macAddress2(), false /* should check FrameControl field */, -1, 0, loc, true /* only probed */ ); 183 netView()->addNewItem( "adhoc", essid, header->macAddress2(), false /* should check FrameControl field */, -1, 0, loc, true /* only probed */ );
184 odebug << "Wellenreiter::invalid frame [possibly noise] detected!" << oendl; 184 odebug << "Wellenreiter::invalid frame [possibly noise] detected!" << oendl;
185} 185}
186 186
187 187
188void Wellenreiter::handleManagementFrameProbeResponse( OPacket* p, OWaveLanManagementPacket* response ) 188void Wellenreiter::handleManagementFrameProbeResponse( OPacket* p, OWaveLanManagementPacket* response )
189{ 189{
190} 190}
191 191
192 192
193void Wellenreiter::handleManagementFrameBeacon( OPacket* p, OWaveLanManagementPacket* beacon ) 193void Wellenreiter::handleManagementFrameBeacon( OPacket* p, OWaveLanManagementPacket* beacon )
194{ 194{
195 QString type; 195 QString type;
196 if ( beacon->canIBSS() ) 196 if ( beacon->canIBSS() )
197 { 197 {
198 type = "adhoc"; 198 type = "adhoc";
199 } 199 }
200 else if ( beacon->canESS() ) 200 else if ( beacon->canESS() )
201 { 201 {
202 type = "managed"; 202 type = "managed";
203 } 203 }
204 else 204 else
205 { 205 {
206 owarn << "Wellenreiter::invalid frame [possibly noise] detected!" << oendl; 206 owarn << "Wellenreiter::invalid frame [possibly noise] detected!" << oendl;
207 return; 207 return;
208 } 208 }
209 209
210 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); 210 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) );
211 QString essid = ssid ? ssid->ID( true /* decloak */ ) : QString("<unknown>"); 211 QString essid = ssid ? ssid->ID( true /* decloak */ ) : QString("<unknown>");
212 OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) ); 212 OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) );
213 int channel = ds ? ds->channel() : -1; 213 int channel = ds ? ds->channel() : -1;
214 214
215 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) ); 215 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) );
216 216
217 GpsLocation loc( -111, -111 ); 217 GpsLocation loc( -111, -111 );
218 if ( configwindow->enableGPS->isChecked() ) 218 if ( configwindow->enableGPS->isChecked() )
219 { 219 {
220 // TODO: add check if GPS is working!? 220 // TODO: add check if GPS is working!?
221 odebug << "Wellenreiter::gathering GPS data..." << oendl; 221 odebug << "Wellenreiter::gathering GPS data..." << oendl;
222 loc = gps->position(); 222 loc = gps->position();
223 odebug << "Wellenreiter::GPS data received is ( " << loc.latitude() << " , " << loc.longitude() << " ) - dms string = '" << loc.dmsPosition().latin1() << "'" << oendl; 223 odebug << "Wellenreiter::GPS data received is ( " << loc.latitude() << " , " << loc.longitude() << " ) - dms string = '" << loc.dmsPosition().latin1() << "'" << oendl;
224 } 224 }
225 225
226 netView()->addNewItem( type, essid, header->macAddress2(), beacon->canPrivacy(), channel, 0, loc ); 226 netView()->addNewItem( type, essid, header->macAddress2(), beacon->canPrivacy(), channel, 0, loc );
227 227
228 // update graph window 228 // update graph window
229 if ( ds ) 229 if ( ds )
230 { 230 {
231 OPrismHeaderPacket* prism = static_cast<OPrismHeaderPacket*>( p->child( "Prism" ) ); 231 OPrismHeaderPacket* prism = static_cast<OPrismHeaderPacket*>( p->child( "Prism" ) );
232 if ( prism ) 232 if ( prism )
233 graphwindow->traffic( ds->channel(), prism->signalStrength() ); 233 graphwindow->traffic( ds->channel(), prism->signalStrength() );
234 else 234 else
235 graphwindow->traffic( ds->channel(), 95 ); 235 graphwindow->traffic( ds->channel(), 95 );
236 } 236 }
237} 237}
238 238
239 239
240void Wellenreiter::handleControlFrame( OPacket* p, OWaveLanControlPacket* control ) 240void Wellenreiter::handleControlFrame( OPacket* p, OWaveLanControlPacket* control )
241{ 241{
242 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) ); 242 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) );
243 243
244 if ( control->controlType() == "Acknowledge" ) 244 if ( control->controlType() == "Acknowledge" )
245 { 245 {
246 netView()->addNewItem( "adhoc", "<unknown>", header->macAddress1(), false, -1, 0, GpsLocation( -111, -111 ) ); 246 netView()->addNewItem( "adhoc", "<unknown>", header->macAddress1(), false, -1, 0, GpsLocation( -111, -111 ) );
247 } 247 }
248 else 248 else
249 { 249 {
250 odebug << "Wellenreiter::handleControlFrame - please handle " << (const char*) control->controlType() << " in a future version! :D" << oendl; 250 odebug << "Wellenreiter::handleControlFrame - please handle " << control->controlType() << " in a future version! :D" << oendl;
251 } 251 }
252} 252}
253 253
254 254
255void Wellenreiter::handleWlanData( OPacket* p, OWaveLanDataPacket* data, OMacAddress& from, OMacAddress& to ) 255void Wellenreiter::handleWlanData( OPacket* p, OWaveLanDataPacket* data, OMacAddress& from, OMacAddress& to )
256{ 256{
257 OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" ); 257 OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" );
258 if ( wlan->fromDS() && !wlan->toDS() ) 258 if ( wlan->fromDS() && !wlan->toDS() )
259 { 259 {
260 netView()->fromDStraffic( wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() ); 260 netView()->fromDStraffic( wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() );
261 from = wlan->macAddress3(); 261 from = wlan->macAddress3();
262 to = wlan->macAddress2(); 262 to = wlan->macAddress2();
263 } 263 }
264 else if ( !wlan->fromDS() && wlan->toDS() ) 264 else if ( !wlan->fromDS() && wlan->toDS() )
265 { 265 {
266 netView()->toDStraffic( wlan->macAddress2(), wlan->macAddress3(), wlan->macAddress1() ); 266 netView()->toDStraffic( wlan->macAddress2(), wlan->macAddress3(), wlan->macAddress1() );
267 from = wlan->macAddress2(); 267 from = wlan->macAddress2();
268 to = wlan->macAddress3(); 268 to = wlan->macAddress3();
269 } 269 }
270 else if ( wlan->fromDS() && wlan->toDS() ) 270 else if ( wlan->fromDS() && wlan->toDS() )
271 { 271 {
272 netView()->WDStraffic( wlan->macAddress4(), wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() ); 272 netView()->WDStraffic( wlan->macAddress4(), wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() );
273 from = wlan->macAddress4(); 273 from = wlan->macAddress4();
274 to = wlan->macAddress3(); 274 to = wlan->macAddress3();
275 } 275 }
276 else 276 else
277 { 277 {
278 netView()->IBSStraffic( wlan->macAddress2(), wlan->macAddress1(), wlan->macAddress3() ); 278 netView()->IBSStraffic( wlan->macAddress2(), wlan->macAddress1(), wlan->macAddress3() );
279 from = wlan->macAddress2(); 279 from = wlan->macAddress2();
280 to = wlan->macAddress1(); 280 to = wlan->macAddress1();
281 } 281 }
282} 282}
283 283
284 284
285void Wellenreiter::handleEthernetData( OPacket* p, OEthernetPacket* data, OMacAddress& from, OMacAddress& to ) 285void Wellenreiter::handleEthernetData( OPacket* p, OEthernetPacket* data, OMacAddress& from, OMacAddress& to )
286{ 286{
287 from = data->sourceAddress(); 287 from = data->sourceAddress();
288 to = data->destinationAddress(); 288 to = data->destinationAddress();
289 289
290 netView()->addNewItem( "station", "<wired>", from, false, -1, 0, GpsLocation( -111, -111 ) ); 290 netView()->addNewItem( "station", "<wired>", from, false, -1, 0, GpsLocation( -111, -111 ) );
291} 291}
292 292
293 293
294void Wellenreiter::handleARPData( OPacket* p, OARPPacket*, OMacAddress& source, OMacAddress& dest ) 294void Wellenreiter::handleARPData( OPacket* p, OARPPacket*, OMacAddress& source, OMacAddress& dest )
295{ 295{
296 OARPPacket* arp = (OARPPacket*) p->child( "ARP" ); 296 OARPPacket* arp = (OARPPacket*) p->child( "ARP" );
297 if ( arp ) 297 if ( arp )
298 { 298 {
299 odebug << "Received ARP traffic (type '" << (const char*) arp->type() << "'): " << oendl; 299 odebug << "Received ARP traffic (type '" << arp->type() << "'): " << oendl;
300 if ( arp->type() == "REQUEST" ) 300 if ( arp->type() == "REQUEST" )
301 { 301 {
302 netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() ); 302 netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() );
303 } 303 }
304 else if ( arp->type() == "REPLY" ) 304 else if ( arp->type() == "REPLY" )
305 { 305 {
306 netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() ); 306 netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() );
307 netView()->identify( arp->targetMacAddress(), arp->targetIPV4Address().toString() ); 307 netView()->identify( arp->targetMacAddress(), arp->targetIPV4Address().toString() );
308 } 308 }
309 } 309 }
310} 310}
311 311
312 312
313void Wellenreiter::handleIPData( OPacket* p, OIPPacket* ip, OMacAddress& source, OMacAddress& dest ) 313void Wellenreiter::handleIPData( OPacket* p, OIPPacket* ip, OMacAddress& source, OMacAddress& dest )
314{ 314{
315 //TODO: Implement more IP based protocols 315 //TODO: Implement more IP based protocols
316 316
317 ODHCPPacket* dhcp = (ODHCPPacket*) p->child( "DHCP" ); 317 ODHCPPacket* dhcp = (ODHCPPacket*) p->child( "DHCP" );
318 if ( dhcp ) 318 if ( dhcp )
319 { 319 {
320 odebug << "Received DHCP '" << (const char*) dhcp->type() << "' packet" << oendl; 320 odebug << "Received DHCP '" << dhcp->type() << "' packet" << oendl;
321 if ( dhcp->type() == "OFFER" ) 321 if ( dhcp->type() == "OFFER" )
322 { 322 {
323 odebug << "DHCP: '" << (const char*) source.toString() << "' ('" << (const char*) dhcp->serverAddress().toString() << "') seems to be a DHCP server." << oendl; 323 odebug << "DHCP: '" << (const char*) source.toString() << "' ('" << dhcp->serverAddress().toString() << "') seems to be a DHCP server." << oendl;
324 netView()->identify( source, dhcp->serverAddress().toString() ); 324 netView()->identify( source, dhcp->serverAddress().toString() );
325 netView()->addService( "DHCP", source, dhcp->serverAddress().toString() ); 325 netView()->addService( "DHCP", source, dhcp->serverAddress().toString() );
326 } 326 }
327 else if ( dhcp->type() == "ACK" ) 327 else if ( dhcp->type() == "ACK" )
328 { 328 {
329 odebug << "DHCP: '" << (const char*) dhcp->clientMacAddress().toString() << "' ('" << (const char*) dhcp->yourAddress().toString() << "') accepted the offered DHCP address." << oendl; 329 odebug << "DHCP: '" << (const char*) dhcp->clientMacAddress().toString() << "' ('" << dhcp->yourAddress().toString() << "') accepted the offered DHCP address." << oendl;
330 netView()->identify( dhcp->clientMacAddress(), dhcp->yourAddress().toString() ); 330 netView()->identify( dhcp->clientMacAddress(), dhcp->yourAddress().toString() );
331 } 331 }
332 } 332 }
333} 333}
334 334
335 335
336QObject* Wellenreiter::childIfToParse( OPacket* p, const QString& protocol ) 336QObject* Wellenreiter::childIfToParse( OPacket* p, const QString& protocol )
337{ 337{
338 if ( configwindow->parsePackets->isProtocolChecked( protocol ) ) 338 if ( configwindow->parsePackets->isProtocolChecked( protocol ) )
339 if ( configwindow->parsePackets->protocolAction( protocol ) == "Discard!" ) 339 if ( configwindow->parsePackets->protocolAction( protocol ) == "Discard!" )
340 return 0; 340 return 0;
341 341
342 return p->child( protocol ); 342 return p->child( protocol );
343} 343}
344 344
345 345
346bool Wellenreiter::checkDumpPacket( OPacket* p ) 346bool Wellenreiter::checkDumpPacket( OPacket* p )
347{ 347{
348 // go through all child packets and see if one is inside the child hierarchy for p 348 // go through all child packets and see if one is inside the child hierarchy for p
349 // if so, do what the user requested (protocolAction), e.g. pass or discard 349 // if so, do what the user requested (protocolAction), e.g. pass or discard
350 if ( !configwindow->writeCaptureFile->isChecked() ) 350 if ( !configwindow->writeCaptureFile->isChecked() )
351 return true; // semantic change - we're logging anyway now to /tmp/wellenreiter 351 return true; // semantic change - we're logging anyway now to /tmp/wellenreiter
352 352
353 QObjectList* l = p->queryList(); 353 QObjectList* l = p->queryList();
354 QObjectListIt it( *l ); 354 QObjectListIt it( *l );
355 QObject* o; 355 QObject* o;
356 356
357 while ( (o = it.current()) != 0 ) 357 while ( (o = it.current()) != 0 )
358 { 358 {
359 QString name = it.current()->name(); 359 QString name = it.current()->name();
360 if ( configwindow->capturePackets->isProtocolChecked( name ) ) 360 if ( configwindow->capturePackets->isProtocolChecked( name ) )
361 { 361 {
362 QString action = configwindow->capturePackets->protocolAction( name ); 362 QString action = configwindow->capturePackets->protocolAction( name );
363 odebug << "capturePackets-action for '" << (const char*) name << "' seems to be '" << (const char*) action << "'" << oendl; 363 odebug << "capturePackets-action for '" << (const char*) name << "' seems to be '" << action << "'" << oendl;
364 if ( action == "Discard" ) 364 if ( action == "Discard" )
365 { 365 {
366 logwindow->log( QString().sprintf( "(i) dump-discarding of '%s' packet requested.", (const char*) name ) ); 366 logwindow->log( QString().sprintf( "(i) dump-discarding of '%s' packet requested.", (const char*) name ) );
367 return false; 367 return false;
368 } 368 }
369 } 369 }
370 else 370 else
371 { 371 {
372 odebug << "protocol '" << (const char*) name << "' not checked in capturePackets." << oendl; 372 odebug << "protocol '" << name << "' not checked in capturePackets." << oendl;
373 } 373 }
374 ++it; 374 ++it;
375 } 375 }
376 return true; 376 return true;
377} 377}
378 378
379 379
380void Wellenreiter::receivePacket( OPacket* p ) 380void Wellenreiter::receivePacket( OPacket* p )
381{ 381{
382 hexWindow()->add( p ); 382 hexWindow()->add( p );
383 383
384 if ( checkDumpPacket( p ) ) 384 if ( checkDumpPacket( p ) )
385 { 385 {
386 pcap->dump( p ); 386 pcap->dump( p );
387 } 387 }
388 388
389 // check for a management frame 389 // check for a management frame
390 OWaveLanManagementPacket* manage = static_cast<OWaveLanManagementPacket*>( childIfToParse( p, "802.11 Management" ) ); 390 OWaveLanManagementPacket* manage = static_cast<OWaveLanManagementPacket*>( childIfToParse( p, "802.11 Management" ) );
391 if ( manage ) 391 if ( manage )
392 { 392 {
393 handleManagementFrame( p, manage ); 393 handleManagementFrame( p, manage );
394 return; 394 return;
395 } 395 }
396 396
397 // check for a control frame 397 // check for a control frame
398 OWaveLanControlPacket* control = static_cast<OWaveLanControlPacket*>( childIfToParse( p, "802.11 Control" ) ); 398 OWaveLanControlPacket* control = static_cast<OWaveLanControlPacket*>( childIfToParse( p, "802.11 Control" ) );
399 if ( control ) 399 if ( control )
400 { 400 {
401 handleControlFrame( p, control ); 401 handleControlFrame( p, control );
402 return; 402 return;
403 } 403 }
404 404
405 OMacAddress source; 405 OMacAddress source;
406 OMacAddress dest; 406 OMacAddress dest;
407 407
408 //TODO: WEP check here 408 //TODO: WEP check here
409 409
410 // check for a wireless data frame 410 // check for a wireless data frame
411 OWaveLanDataPacket* wlan = static_cast<OWaveLanDataPacket*>( childIfToParse( p, "802.11 Data" ) ); 411 OWaveLanDataPacket* wlan = static_cast<OWaveLanDataPacket*>( childIfToParse( p, "802.11 Data" ) );
412 if ( wlan ) 412 if ( wlan )
413 { 413 {
414 handleWlanData( p, wlan, source, dest ); 414 handleWlanData( p, wlan, source, dest );
415 } 415 }
416 416
417 // check for a wired data frame 417 // check for a wired data frame
418 OEthernetPacket* eth = static_cast<OEthernetPacket*>( childIfToParse( p, "Ethernet" ) ); 418 OEthernetPacket* eth = static_cast<OEthernetPacket*>( childIfToParse( p, "Ethernet" ) );
419 if ( eth ) 419 if ( eth )
420 { 420 {
421 handleEthernetData( p, eth, source, dest ); 421 handleEthernetData( p, eth, source, dest );
422 } 422 }
423 423
424 // check for an arp frame since arp frames come in two flavours: 424 // check for an arp frame since arp frames come in two flavours:
425 // 802.11 encapsulates ARP data within IP packets while wired ethernet doesn't. 425 // 802.11 encapsulates ARP data within IP packets while wired ethernet doesn't.
426 OARPPacket* arp = static_cast<OARPPacket*>( childIfToParse( p, "ARP" ) ); 426 OARPPacket* arp = static_cast<OARPPacket*>( childIfToParse( p, "ARP" ) );
427 if ( arp ) 427 if ( arp )
428 { 428 {
429 handleARPData( p, arp, source, dest ); 429 handleARPData( p, arp, source, dest );
430 } 430 }
431 431
432 // check for a ip frame 432 // check for a ip frame
433 OIPPacket* ip = static_cast<OIPPacket*>( childIfToParse( p, "IP" ) ); 433 OIPPacket* ip = static_cast<OIPPacket*>( childIfToParse( p, "IP" ) );
434 if ( ip ) 434 if ( ip )
435 { 435 {
436 handleIPData( p, ip, source, dest ); 436 handleIPData( p, ip, source, dest );
437 } 437 }
438 438
439 //handleNotification( p ); 439 //handleNotification( p );
440 440
441} 441}
442 442
443 443
444void Wellenreiter::stopClicked() 444void Wellenreiter::stopClicked()
445{ 445{
446 if ( iface ) 446 if ( iface )
447 { 447 {
448 disconnect( SIGNAL( receivedPacket(Opie::Net::OPacket*) ), this, SLOT( receivePacket(Opie::Net::OPacket*) ) ); 448 disconnect( SIGNAL( receivedPacket(Opie::Net::OPacket*) ), this, SLOT( receivePacket(Opie::Net::OPacket*) ) );
449 disconnect( SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) ); 449 disconnect( SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) );
450 iface->setChannelHopping(); // stop hopping channels 450 iface->setChannelHopping(); // stop hopping channels
451 } 451 }
452 else 452 else
453 killTimers(); 453 killTimers();
454 454
455 pcap->close(); 455 pcap->close();
456 sniffing = false; 456 sniffing = false;
457 457
458 if ( iface ) 458 if ( iface )
459 { 459 {
460 // switch off monitor mode 460 // switch off monitor mode
461 iface->setMode( "managed" ); 461 iface->setMode( "managed" );
462 // switch off promisc flag 462 // switch off promisc flag
463 iface->setPromiscuousMode( false ); 463 iface->setPromiscuousMode( false );
464 464
465 system( "cardctl reset; sleep 1" ); //FIXME: Use OProcess 465 system( "cardctl reset; sleep 1" ); //FIXME: Use OProcess
466 } 466 }
467 467
468 logwindow->log( "(i) Stopped Scanning." ); 468 logwindow->log( "(i) Stopped Scanning." );
469 assert( parent() ); 469 assert( parent() );
470 ( (QMainWindow*) parent() )->setCaption( "Wellenreiter II" ); 470 ( (QMainWindow*) parent() )->setCaption( "Wellenreiter II" );
471 471
472 // message the user 472 // message the user
473 QMessageBox::information( this, "Wellenreiter II", 473 QMessageBox::information( this, "Wellenreiter II",
474 tr( "Your wireless card\nshould now be usable again." ) ); 474 tr( "Your wireless card\nshould now be usable again." ) );
475 475
476 sniffing = false; 476 sniffing = false;
477 emit( stoppedSniffing() ); 477 emit( stoppedSniffing() );
478 478
479 #ifdef QWS 479 #ifdef QWS
480 if ( WellenreiterConfigWindow::instance()->disablePM->isChecked() ) 480 if ( WellenreiterConfigWindow::instance()->disablePM->isChecked() )
481 { 481 {
482 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 482 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
483 } 483 }
484 #else 484 #else
485 #warning FIXME: setScreenSaverMode is not operational on the X11 build 485 #warning FIXME: setScreenSaverMode is not operational on the X11 build
486 #endif 486 #endif
487 487
488 // print out statistics 488 // print out statistics
489 for( QMap<QString,int>::ConstIterator it = pcap->statistics().begin(); it != pcap->statistics().end(); ++it ) 489 for( QMap<QString,int>::ConstIterator it = pcap->statistics().begin(); it != pcap->statistics().end(); ++it )
490 statwindow->updateCounter( it.key(), it.data() ); 490 statwindow->updateCounter( it.key(), it.data() );
491} 491}
492 492
493 493
494void Wellenreiter::startClicked() 494void Wellenreiter::startClicked()
495{ 495{
496 // get configuration from config window 496 // get configuration from config window
497 497
498 const QString& interface = configwindow->interfaceName->currentText(); 498 const QString& interface = configwindow->interfaceName->currentText();
499 const int cardtype = configwindow->driverType(); 499 const int cardtype = configwindow->driverType();
500 const int interval = configwindow->hoppingInterval(); 500 const int interval = configwindow->hoppingInterval();
501 501
502 if ( ( interface == "" ) || ( cardtype == 0 ) ) 502 if ( ( interface == "" ) || ( cardtype == 0 ) )
503 { 503 {
504 QMessageBox::information( this, "Wellenreiter II", 504 QMessageBox::information( this, "Wellenreiter II",
505 tr( "Your device is not\nproperly configured. Please reconfigure!" ) ); 505 tr( "Your device is not\nproperly configured. Please reconfigure!" ) );
506 return; 506 return;
507 } 507 }
508 508
509 // configure device 509 // configure device
510 ONetwork* net = ONetwork::instance(); 510 ONetwork* net = ONetwork::instance();
511 511
512 // TODO: check if interface is wireless and support sniffing for non-wireless interfaces 512 // TODO: check if interface is wireless and support sniffing for non-wireless interfaces
513 513
514 if ( cardtype != DEVTYPE_FILE ) 514 if ( cardtype != DEVTYPE_FILE )
515 { 515 {
516 516
517 if ( !net->isPresent( interface ) ) 517 if ( !net->isPresent( interface ) )
518 { 518 {
519 QMessageBox::information( this, "Wellenreiter II", 519 QMessageBox::information( this, "Wellenreiter II",
520 tr( "The configured device (%1)\nis not available on this system\n. Please reconfigure!" ).arg( interface ) ); 520 tr( "The configured device (%1)\nis not available on this system\n. Please reconfigure!" ).arg( interface ) );
521 return; 521 return;
522 } 522 }
523 523
524 iface = static_cast<OWirelessNetworkInterface*>(net->interface( interface )); // fails if network is not wireless! 524 iface = static_cast<OWirelessNetworkInterface*>(net->interface( interface )); // fails if network is not wireless!
525 assert( iface ); 525 assert( iface );
526 526
527 // bring device UP 527 // bring device UP
528 iface->setUp( true ); 528 iface->setUp( true );
529 if ( !iface->isUp() ) 529 if ( !iface->isUp() )
530 { 530 {
531 QMessageBox::warning( this, "Wellenreiter II", 531 QMessageBox::warning( this, "Wellenreiter II",
532 tr( "Can't bring interface '%1' up:\n" ).arg( iface->name() ) + strerror( errno ) ); 532 tr( "Can't bring interface '%1' up:\n" ).arg( iface->name() ) + strerror( errno ) );
533 return; 533 return;
534 } 534 }
535 } 535 }
536 // set monitor mode 536 // set monitor mode
537 bool usePrism = configwindow->usePrismHeader(); 537 bool usePrism = configwindow->usePrismHeader();
538 538
539 switch ( cardtype ) 539 switch ( cardtype )
540 { 540 {
541 case DEVTYPE_CISCO: iface->setMonitoring( new OCiscoMonitoringInterface( iface, usePrism ) ); break; 541 case DEVTYPE_CISCO: iface->setMonitoring( new OCiscoMonitoringInterface( iface, usePrism ) ); break;
542 case DEVTYPE_WLAN_NG: iface->setMonitoring( new OWlanNGMonitoringInterface( iface, usePrism ) ); break; 542 case DEVTYPE_WLAN_NG: iface->setMonitoring( new OWlanNGMonitoringInterface( iface, usePrism ) ); break;
543 case DEVTYPE_HOSTAP: iface->setMonitoring( new OHostAPMonitoringInterface( iface, usePrism ) ); break; 543 case DEVTYPE_HOSTAP: iface->setMonitoring( new OHostAPMonitoringInterface( iface, usePrism ) ); break;
544 case DEVTYPE_ORINOCO: iface->setMonitoring( new OOrinocoMonitoringInterface( iface, usePrism ) ); break; 544 case DEVTYPE_ORINOCO: iface->setMonitoring( new OOrinocoMonitoringInterface( iface, usePrism ) ); break;
545 case DEVTYPE_MANUAL: QMessageBox::information( this, "Wellenreiter II", tr( "Bring your device into\nmonitor mode now." ) ); break; 545 case DEVTYPE_MANUAL: QMessageBox::information( this, "Wellenreiter II", tr( "Bring your device into\nmonitor mode now." ) ); break;
546 case DEVTYPE_FILE: odebug << "Wellenreiter: Capturing from file '" << (const char*) interface << "'" << oendl; break; 546 case DEVTYPE_FILE: odebug << "Wellenreiter: Capturing from file '" << interface << "'" << oendl; break;
547 default: assert( 0 ); // shouldn't reach this 547 default: assert( 0 ); // shouldn't reach this
548 } 548 }
549 549
550 // switch device into monitor mode 550 // switch device into monitor mode
551 if ( cardtype < DEVTYPE_FILE ) 551 if ( cardtype < DEVTYPE_FILE )
552 { 552 {
553 if ( cardtype != DEVTYPE_MANUAL ) 553 if ( cardtype != DEVTYPE_MANUAL )
554 iface->setMode( "monitor" ); 554 iface->setMode( "monitor" );
555 if ( iface->mode() != "monitor" ) 555 if ( iface->mode() != "monitor" )
556 { 556 {
557 if ( QMessageBox::warning( this, "Wellenreiter II", 557 if ( QMessageBox::warning( this, "Wellenreiter II",
558 tr( "Can't set interface '%1'\ninto monitor mode:\n" ).arg( iface->name() ) + strerror( errno ) + 558 tr( "Can't set interface '%1'\ninto monitor mode:\n" ).arg( iface->name() ) + strerror( errno ) +
559 tr( "\nContinue with limited functionality?" ), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No ) 559 tr( "\nContinue with limited functionality?" ), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No )
560 return; 560 return;
561 } 561 }
562 } 562 }
563 563
564 // open GPS device 564 // open GPS device
565 if ( configwindow->enableGPS->isChecked() ) 565 if ( configwindow->enableGPS->isChecked() )
566 { 566 {
567 odebug << "Wellenreiter:GPS enabled @ " << (const char*) configwindow->gpsdHost->currentText() << ":" << configwindow->gpsdPort->value() << "" << oendl; 567 odebug << "Wellenreiter:GPS enabled @ " << configwindow->gpsdHost->currentText() << ":" << configwindow->gpsdPort->value() << "" << oendl;
568 gps->open( configwindow->gpsdHost->currentText(), configwindow->gpsdPort->value() ); 568 gps->open( configwindow->gpsdHost->currentText(), configwindow->gpsdPort->value() );
569 } 569 }
570 570
571 // open pcap and start sniffing 571 // open pcap and start sniffing
572 572
573 if ( configwindow->writeCaptureFile->isChecked() ) // write to a user specified capture file? 573 if ( configwindow->writeCaptureFile->isChecked() ) // write to a user specified capture file?
574 { 574 {
575 dumpname = configwindow->captureFileName->text(); 575 dumpname = configwindow->captureFileName->text();
576 if ( dumpname.isEmpty() ) dumpname = "captureFile"; 576 if ( dumpname.isEmpty() ) dumpname = "captureFile";
577 dumpname.append( '-' ); 577 dumpname.append( '-' );
578 dumpname.append( QTime::currentTime().toString().replace( QRegExp( ":" ), "-" ) ); 578 dumpname.append( QTime::currentTime().toString().replace( QRegExp( ":" ), "-" ) );
579 dumpname.append( ".wellenreiter" ); 579 dumpname.append( ".wellenreiter" );
580 } 580 }
581 else // write it anyway ;) 581 else // write it anyway ;)
582 { 582 {
583 dumpname = "/var/log/dump.wellenreiter"; 583 dumpname = "/var/log/dump.wellenreiter";
584 } 584 }
585 585
586 if ( cardtype != DEVTYPE_FILE ) 586 if ( cardtype != DEVTYPE_FILE )
587 pcap->open( interface ); 587 pcap->open( interface );
588 else 588 else
589 pcap->open( QFile( interface ) ); 589 pcap->open( QFile( interface ) );
590 590
591 odebug << "Wellenreiter:: dumping to " << (const char*) dumpname << "" << oendl; 591 odebug << "Wellenreiter:: dumping to " << dumpname << "" << oendl;
592 pcap->openDumpFile( dumpname ); 592 pcap->openDumpFile( dumpname );
593 593
594 if ( !pcap->isOpen() ) 594 if ( !pcap->isOpen() )
595 { 595 {
596 QMessageBox::warning( this, "Wellenreiter II", tr( "Can't open packet capturer for\n'%1':\n" ).arg( 596 QMessageBox::warning( this, "Wellenreiter II", tr( "Can't open packet capturer for\n'%1':\n" ).arg(
597 cardtype == DEVTYPE_FILE ? (const char*) interface : iface->name() ) + QString(strerror( errno ) )); 597 cardtype == DEVTYPE_FILE ? (const char*) interface : iface->name() ) + QString(strerror( errno ) ));
598 return; 598 return;
599 } 599 }
600 600
601 // set capturer to non-blocking mode 601 // set capturer to non-blocking mode
602 pcap->setBlocking( false ); 602 pcap->setBlocking( false );
603 603
604 // start channel hopper 604 // start channel hopper
605 if ( cardtype != DEVTYPE_FILE ) 605 if ( cardtype != DEVTYPE_FILE )
606 { 606 {
607 logwindow->log( QString().sprintf( "(i) Starting channel hopper (d=%d ms)", configwindow->hopInterval->value() ) ); 607 logwindow->log( QString().sprintf( "(i) Starting channel hopper (d=%d ms)", configwindow->hopInterval->value() ) );
608 iface->setChannelHopping( configwindow->hopInterval->value() ); //use interval from config window 608 iface->setChannelHopping( configwindow->hopInterval->value() ); //use interval from config window
609 } 609 }
610 610
611 if ( cardtype != DEVTYPE_FILE ) 611 if ( cardtype != DEVTYPE_FILE )
612 { 612 {
613 // connect socket notifier and start channel hopper 613 // connect socket notifier and start channel hopper
614 connect( pcap, SIGNAL( receivedPacket(Opie::Net::OPacket*) ), this, SLOT( receivePacket(Opie::Net::OPacket*) ) ); 614 connect( pcap, SIGNAL( receivedPacket(Opie::Net::OPacket*) ), this, SLOT( receivePacket(Opie::Net::OPacket*) ) );
615 connect( iface->channelHopper(), SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) ); 615 connect( iface->channelHopper(), SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) );
616 } 616 }
617 else 617 else
618 { 618 {
619 // start timer for reading packets 619 // start timer for reading packets
620 startTimer( 100 ); 620 startTimer( 100 );
621 } 621 }
622 622
623 logwindow->log( "(i) Started Scanning." ); 623 logwindow->log( "(i) Started Scanning." );
624 sniffing = true; 624 sniffing = true;
625 625
626 #ifdef QWS 626 #ifdef QWS
627 if ( WellenreiterConfigWindow::instance()->disablePM->isChecked() ) 627 if ( WellenreiterConfigWindow::instance()->disablePM->isChecked() )
628 { 628 {
629 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; 629 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable;
630 } 630 }
631 #else 631 #else
632 #warning FIXME: setScreenSaverMode is not operational on the X11 build 632 #warning FIXME: setScreenSaverMode is not operational on the X11 build
633 #endif 633 #endif
634 634
635 emit( startedSniffing() ); 635 emit( startedSniffing() );
636 if ( cardtype != DEVTYPE_FILE ) channelHopped( 6 ); // set title 636 if ( cardtype != DEVTYPE_FILE ) channelHopped( 6 ); // set title
637 else 637 else
638 { 638 {
639 assert( parent() ); 639 assert( parent() );
640 ( (QMainWindow*) parent() )->setCaption( tr( "Wellenreiter II - replaying capture file..." ) ); 640 ( (QMainWindow*) parent() )->setCaption( tr( "Wellenreiter II - replaying capture file..." ) );
641 } 641 }
642} 642}
643 643
644 644
645void Wellenreiter::timerEvent( QTimerEvent* ) 645void Wellenreiter::timerEvent( QTimerEvent* )
646{ 646{
647 odebug << "Wellenreiter::timerEvent()" << oendl; 647 odebug << "Wellenreiter::timerEvent()" << oendl;
648 OPacket* p = pcap->next(); 648 OPacket* p = pcap->next();
649 if ( !p ) // no more packets available 649 if ( !p ) // no more packets available
650 { 650 {
651 stopClicked(); 651 stopClicked();
652 } 652 }
653 else 653 else
654 { 654 {
655 receivePacket( p ); 655 receivePacket( p );
656 // We no longer delete packets here. Ownership of the packets is 656 // We no longer delete packets here. Ownership of the packets is
657 // transferred to the PacketView. 657 // transferred to the PacketView.
658 //delete p; 658 //delete p;
659 } 659 }
660} 660}
661 661
662 662
663void Wellenreiter::doAction( const QString& action, const QString& protocol, OPacket* p ) 663void Wellenreiter::doAction( const QString& action, const QString& protocol, OPacket* p )
664{ 664{
665 #ifdef QWS 665 #ifdef QWS
666 if ( action == "TouchSound" ) 666 if ( action == "TouchSound" )
667 ODevice::inst()->playTouchSound(); 667 ODevice::inst()->playTouchSound();
668 else if ( action == "AlarmSound" ) 668 else if ( action == "AlarmSound" )
669 ODevice::inst()->playAlarmSound(); 669 ODevice::inst()->playAlarmSound();
670 else if ( action == "KeySound" ) 670 else if ( action == "KeySound" )
671 ODevice::inst()->playKeySound(); 671 ODevice::inst()->playKeySound();
672 else if ( action == "LedOn" ) 672 else if ( action == "LedOn" )
673 ODevice::inst()->setLedState( Led_Mail, Led_On ); 673 ODevice::inst()->setLedState( Led_Mail, Led_On );
674 else if ( action == "LedOff" ) 674 else if ( action == "LedOff" )
675 ODevice::inst()->setLedState( Led_Mail, Led_Off ); 675 ODevice::inst()->setLedState( Led_Mail, Led_Off );
676 else if ( action == "LogMessage" ) 676 else if ( action == "LogMessage" )
677 logwindow->log( QString().sprintf( "Got packet with protocol '%s'", (const char*) protocol ) ); 677 logwindow->log( QString().sprintf( "Got packet with protocol '%s'", (const char*) protocol ) );
678 else if ( action == "MessageBox" ) 678 else if ( action == "MessageBox" )
679 QMessageBox::information( this, "Notification!", 679 QMessageBox::information( this, "Notification!",
680 QString().sprintf( "Got packet with protocol '%s'", (const char*) protocol ) ); 680 QString().sprintf( "Got packet with protocol '%s'", (const char*) protocol ) );
681 #else 681 #else
682 #warning Actions do not work with Qt/X11 yet 682 #warning Actions do not work with Qt/X11 yet
683 #endif 683 #endif
684} 684}
685 685
686void Wellenreiter::joinNetwork(const QString& type, const QString& essid, int channel, const QString& macaddr) 686void Wellenreiter::joinNetwork(const QString& type, const QString& essid, int channel, const QString& macaddr)
687{ 687{
688 #ifdef QWS 688 #ifdef QWS
689 if ( !iface ) 689 if ( !iface )
690 { 690 {
691 QMessageBox::warning( this, tr( "Can't do that!" ), tr( "No wireless\ninterface available." ) ); 691 QMessageBox::warning( this, tr( "Can't do that!" ), tr( "No wireless\ninterface available." ) );
692 return; 692 return;
693 } 693 }
694 694
695 if ( sniffing ) 695 if ( sniffing )
696 { 696 {
697 QMessageBox::warning( this, tr( "Can't do that!" ), tr( "Stop sniffing before\njoining a net." ) ); 697 QMessageBox::warning( this, tr( "Can't do that!" ), tr( "Stop sniffing before\njoining a net." ) );
698 return; 698 return;
699 } 699 }
700 700
701 qDebug( "joinNetwork() with Interface %s: %s, %s, %d, %s", 701 qDebug( "joinNetwork() with Interface %s: %s, %s, %d, %s",
702 (const char*) iface->name(), 702 (const char*) iface->name(),
703 (const char*) type, 703 (const char*) type,
704 (const char*) essid, 704 (const char*) essid,
705 channel, 705 channel,
706 (const char*) macaddr ); 706 (const char*) macaddr );
707 707
708 QCopEnvelope msg( "QPE/Application/networksettings", "wlan(QString,QString,QString)" ); 708 QCopEnvelope msg( "QPE/Application/networksettings", "wlan(QString,QString,QString)" );
709 int count = 3; 709 int count = 3;
710 odebug << "sending " << count << " messages" << oendl; 710 odebug << "sending " << count << " messages" << oendl;
711 msg << QString("count") << QString::number(count); 711 msg << QString("count") << QString::number(count);
712 odebug << "msg >" << iface->name() << "< Mode >" << type.latin1() << "<" << oendl; 712 odebug << "msg >" << iface->name() << "< Mode >" << type.latin1() << "<" << oendl;
713 msg << QString(iface->name()) << QString("Mode") << type; 713 msg << QString(iface->name()) << QString("Mode") << type;
714 odebug << "msg >" << iface->name() << "< essid >" << essid.latin1() << "<" << oendl; 714 odebug << "msg >" << iface->name() << "< essid >" << essid.latin1() << "<" << oendl;
715 msg << QString(iface->name()) << QString("ESSID") << essid; 715 msg << QString(iface->name()) << QString("ESSID") << essid;
716 odebug << "msg >" << iface->name() << "< channel >" << channel << "<" << oendl; 716 odebug << "msg >" << iface->name() << "< channel >" << channel << "<" << oendl;
717 msg << QString(iface->name()) << QString("Channel") << channel; 717 msg << QString(iface->name()) << QString("Channel") << channel;
718// odebug << "msg >" << iface->name() << "< mac >" << macaddr << "<" << oendl; 718// odebug << "msg >" << iface->name() << "< mac >" << macaddr << "<" << oendl;
719// msg << QString(iface->name()) << QString("MacAddr") << macaddr; 719// msg << QString(iface->name()) << QString("MacAddr") << macaddr;
720 #else 720 #else
721 QMessageBox::warning( this, tr( "Can't do that!" ), tr( "Function only available on Embedded build" ) ); 721 QMessageBox::warning( this, tr( "Can't do that!" ), tr( "Function only available on Embedded build" ) );
722 #endif 722 #endif
723 723
724} 724}
725 725
diff --git a/noncore/settings/networksettings/wlan/wlanimp2.cpp b/noncore/settings/networksettings/wlan/wlanimp2.cpp
index e483efe..e4aa2f9 100644
--- a/noncore/settings/networksettings/wlan/wlanimp2.cpp
+++ b/noncore/settings/networksettings/wlan/wlanimp2.cpp
@@ -1,492 +1,492 @@
1#include "wlanimp2.h" 1#include "wlanimp2.h"
2#include "keyedit.h" 2#include "keyedit.h"
3#include "interfacesetupimp.h" 3#include "interfacesetupimp.h"
4 4
5#include "../interfaces/interface.h" 5#include "../interfaces/interface.h"
6 6
7#include <assert.h> 7#include <assert.h>
8#include <errno.h> 8#include <errno.h>
9#include <string.h> 9#include <string.h>
10 10
11#include <qapplication.h> 11#include <qapplication.h>
12#include <qfile.h> 12#include <qfile.h>
13#include <qdir.h> 13#include <qdir.h>
14#include <qdialog.h> 14#include <qdialog.h>
15#include <qtextstream.h> 15#include <qtextstream.h>
16#include <qmessagebox.h> 16#include <qmessagebox.h>
17#include <qlineedit.h> 17#include <qlineedit.h>
18#include <qlabel.h> 18#include <qlabel.h>
19#include <qspinbox.h> 19#include <qspinbox.h>
20#include <qradiobutton.h> 20#include <qradiobutton.h>
21#include <qpushbutton.h> 21#include <qpushbutton.h>
22#include <qcheckbox.h> 22#include <qcheckbox.h>
23#include <qtabwidget.h> 23#include <qtabwidget.h>
24#include <qcombobox.h> 24#include <qcombobox.h>
25#include <qlistview.h> 25#include <qlistview.h>
26#include <qvbox.h> 26#include <qvbox.h>
27#include <qprogressbar.h> 27#include <qprogressbar.h>
28 28
29#ifdef QWS 29#ifdef QWS
30 #include <qpe/resource.h> 30 #include <qpe/resource.h>
31 #include <opie2/oprocess.h> 31 #include <opie2/oprocess.h>
32 #include <opie2/onetwork.h> 32 #include <opie2/onetwork.h>
33 #include <opie2/opcap.h> 33 #include <opie2/opcap.h>
34#else 34#else
35 #define OProcess KProcess 35 #define OProcess KProcess
36 #include <kprocess.h> 36 #include <kprocess.h>
37#endif 37#endif
38 38
39#define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" 39#define WIRELESS_OPTS "/etc/pcmcia/wireless.opts"
40#define PREUP "/etc/network/if-pre-up.d/wireless-tools" 40#define PREUP "/etc/network/if-pre-up.d/wireless-tools"
41 41
42/** 42/**
43 * Constructor, read in the wireless.opts file for parsing later. 43 * Constructor, read in the wireless.opts file for parsing later.
44 */ 44 */
45using namespace Opie::Net; 45using namespace Opie::Net;
46using namespace Opie::Core; 46using namespace Opie::Core;
47WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : WLAN(parent, name, modal, fl), interface(i), currentProfile("*") { 47WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : WLAN(parent, name, modal, fl), interface(i), currentProfile("*") {
48 interfaces = new Interfaces(); 48 interfaces = new Interfaces();
49 interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, interfaces); 49 interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, interfaces);
50 tabWidget->insertTab(interfaceSetup, "TCP/IP"); 50 tabWidget->insertTab(interfaceSetup, "TCP/IP");
51 51
52 // Check sanity - the existance of the wireless-tools if-pre-up script 52 // Check sanity - the existance of the wireless-tools if-pre-up script
53 QFile file(QString(PREUP)); 53 QFile file(QString(PREUP));
54 if (file.exists()) { 54 if (file.exists()) {
55 owarn << QString("WLANImp: Unable to open /etc/network/if-pre-up.d/wireless-tools") << oendl; 55 owarn << QString("WLANImp: Unable to open /etc/network/if-pre-up.d/wireless-tools") << oendl;
56 } 56 }
57 57
58 connect( rescanButton, SIGNAL( clicked() ), this, SLOT( rescanNeighbourhood() ) ); 58 connect( rescanButton, SIGNAL( clicked() ), this, SLOT( rescanNeighbourhood() ) );
59 connect( netView, SIGNAL( clicked(QListViewItem*) ), this, SLOT( selectNetwork(QListViewItem*) ) ); 59 connect( netView, SIGNAL( clicked(QListViewItem*) ), this, SLOT( selectNetwork(QListViewItem*) ) );
60 netView->setColumnAlignment( col_chn, AlignCenter ); 60 netView->setColumnAlignment( col_chn, AlignCenter );
61 netView->setItemMargin( 3 ); 61 netView->setItemMargin( 3 );
62 netView->setAllColumnsShowFocus( true ); 62 netView->setAllColumnsShowFocus( true );
63 63
64} 64}
65 65
66WLANImp::~WLANImp() { 66WLANImp::~WLANImp() {
67//FIXME: delete interfaces; 67//FIXME: delete interfaces;
68} 68}
69 69
70/** 70/**
71 * Change the profile for both wireless settings and network settings. 71 * Change the profile for both wireless settings and network settings.
72 */ 72 */
73void WLANImp::setProfile(const QString &profile){ 73void WLANImp::setProfile(const QString &profile){
74 interfaceSetup->setProfile(profile); 74 interfaceSetup->setProfile(profile);
75 parseOpts(); 75 parseOpts();
76} 76}
77 77
78void WLANImp::parseOpts() { 78void WLANImp::parseOpts() {
79 bool error; 79 bool error;
80 QString opt; 80 QString opt;
81 81
82 if (! interfaces->isInterfaceSet()) 82 if (! interfaces->isInterfaceSet())
83 return; 83 return;
84 84
85 85
86 opt = interfaces->getInterfaceOption("wireless_essid", error); 86 opt = interfaces->getInterfaceOption("wireless_essid", error);
87 if(opt == "any" || opt == "off" || opt.isNull()){ 87 if(opt == "any" || opt == "off" || opt.isNull()){
88 essid->setEditText("any"); 88 essid->setEditText("any");
89 } else { 89 } else {
90 essid->setEditText(opt); 90 essid->setEditText(opt);
91 } 91 }
92 92
93 opt = interfaces->getInterfaceOption("wireless_mode", error).simplifyWhiteSpace(); 93 opt = interfaces->getInterfaceOption("wireless_mode", error).simplifyWhiteSpace();
94 94
95 for ( int i = 0; i < mode->count(); i++) 95 for ( int i = 0; i < mode->count(); i++)
96 if ( mode->text( i ) == opt ) mode->setCurrentItem( i ); 96 if ( mode->text( i ) == opt ) mode->setCurrentItem( i );
97 97
98 opt = interfaces->getInterfaceOption("wireless_ap", error).simplifyWhiteSpace(); 98 opt = interfaces->getInterfaceOption("wireless_ap", error).simplifyWhiteSpace();
99 if (! opt.isNull()) { 99 if (! opt.isNull()) {
100 specifyAp->setChecked(true); 100 specifyAp->setChecked(true);
101 macEdit->setText(opt); 101 macEdit->setText(opt);
102 } 102 }
103 103
104 opt = interfaces->getInterfaceOption("wireless_channel", error).simplifyWhiteSpace(); 104 opt = interfaces->getInterfaceOption("wireless_channel", error).simplifyWhiteSpace();
105 if (! opt.isNull()) { 105 if (! opt.isNull()) {
106 specifyChan->setChecked(true); 106 specifyChan->setChecked(true);
107 networkChannel->setValue(opt.toInt()); 107 networkChannel->setValue(opt.toInt());
108 } 108 }
109 109
110 opt = interfaces->getInterfaceOption("wireless_key", error).simplifyWhiteSpace(); 110 opt = interfaces->getInterfaceOption("wireless_key", error).simplifyWhiteSpace();
111 if (opt.isNull()) 111 if (opt.isNull())
112 opt = interfaces->getInterfaceOption("wireless_enc", error).simplifyWhiteSpace(); 112 opt = interfaces->getInterfaceOption("wireless_enc", error).simplifyWhiteSpace();
113 parseKeyStr(opt); 113 parseKeyStr(opt);
114} 114}
115 115
116void WLANImp::parseKeyStr(QString keystr) { 116void WLANImp::parseKeyStr(QString keystr) {
117 int loc = 0; 117 int loc = 0;
118 int index = 1; 118 int index = 1;
119 QString key; 119 QString key;
120 QStringList keys = QStringList::split(QRegExp("\\s+"), keystr); 120 QStringList keys = QStringList::split(QRegExp("\\s+"), keystr);
121 int enc = -1; // encryption state 121 int enc = -1; // encryption state
122 122
123 for (QStringList::Iterator it = keys.begin(); it != keys.end(); ++it) { 123 for (QStringList::Iterator it = keys.begin(); it != keys.end(); ++it) {
124 if ((*it).left(3) == "off") { 124 if ((*it).left(3) == "off") {
125 // encryption disabled 125 // encryption disabled
126 enc = 0; 126 enc = 0;
127 } else if ((*it).left(2) == "on") { 127 } else if ((*it).left(2) == "on") {
128 // encryption enabled 128 // encryption enabled
129 enc = 1; 129 enc = 1;
130 } else if ((*it).left(4) == "open") { 130 } else if ((*it).left(4) == "open") {
131 // open mode, accept non encrypted packets 131 // open mode, accept non encrypted packets
132 acceptNonEnc->setChecked(true); 132 acceptNonEnc->setChecked(true);
133 } else if ((*it).left(10) == "restricted") { 133 } else if ((*it).left(10) == "restricted") {
134 // restricted mode, only accept encrypted packets 134 // restricted mode, only accept encrypted packets
135 rejectNonEnc->setChecked(true); 135 rejectNonEnc->setChecked(true);
136 } else if ((*it).left(3) == "key") { 136 } else if ((*it).left(3) == "key") {
137 // new set of options 137 // new set of options
138 } else if ((*it).left(1) == "[") { 138 } else if ((*it).left(1) == "[") {
139 index = (*it).mid(1, 1).toInt(); 139 index = (*it).mid(1, 1).toInt();
140 // switch current key to index 140 // switch current key to index
141 switch (index) { 141 switch (index) {
142 case 1: 142 case 1:
143 keyRadio0->setChecked(true); 143 keyRadio0->setChecked(true);
144 break; 144 break;
145 case 2: 145 case 2:
146 keyRadio1->setChecked(true); 146 keyRadio1->setChecked(true);
147 break; 147 break;
148 case 3: 148 case 3:
149 keyRadio2->setChecked(true); 149 keyRadio2->setChecked(true);
150 break; 150 break;
151 case 4: 151 case 4:
152 keyRadio3->setChecked(true); 152 keyRadio3->setChecked(true);
153 break; 153 break;
154 } 154 }
155 } else { 155 } else {
156 // key 156 // key
157 key = (*it); 157 key = (*it);
158 } 158 }
159 if (! key.isNull()) { 159 if (! key.isNull()) {
160 if (enc == -1) 160 if (enc == -1)
161 enc = 1; 161 enc = 1;
162 QStringList::Iterator next = ++it; 162 QStringList::Iterator next = ++it;
163 if (it == keys.end()) { 163 if (it == keys.end()) {
164 break; 164 break;
165 } 165 }
166 if ((*(next)).left(1) == "[") { 166 if ((*(next)).left(1) == "[") {
167 // set key at index 167 // set key at index
168 index = (*(next)).mid(1, 1).toInt(); 168 index = (*(next)).mid(1, 1).toInt();
169 } else { 169 } else {
170 index = 1; 170 index = 1;
171 } 171 }
172 switch (index) { 172 switch (index) {
173 case 1: 173 case 1:
174 keyLineEdit0->setText(key); 174 keyLineEdit0->setText(key);
175 break; 175 break;
176 case 2: 176 case 2:
177 keyLineEdit1->setText(key); 177 keyLineEdit1->setText(key);
178 break; 178 break;
179 case 3: 179 case 3:
180 keyLineEdit2->setText(key); 180 keyLineEdit2->setText(key);
181 break; 181 break;
182 case 4: 182 case 4:
183 keyLineEdit3->setText(key); 183 keyLineEdit3->setText(key);
184 break; 184 break;
185 } 185 }
186 key = QString::null; 186 key = QString::null;
187 } 187 }
188 } 188 }
189 if (enc == 1) { 189 if (enc == 1) {
190 wepEnabled->setChecked(true); 190 wepEnabled->setChecked(true);
191 } else { 191 } else {
192 wepEnabled->setChecked(false); 192 wepEnabled->setChecked(false);
193 } 193 }
194} 194}
195 195
196/** 196/**
197 * Check to see if the current config is valid 197 * Check to see if the current config is valid
198 * Save interfaces 198 * Save interfaces
199 */ 199 */
200void WLANImp::accept() { 200void WLANImp::accept() {
201 if (wepEnabled->isChecked()) { 201 if (wepEnabled->isChecked()) {
202 if ((keyRadio0->isChecked() && keyLineEdit0->text().isEmpty()) || 202 if ((keyRadio0->isChecked() && keyLineEdit0->text().isEmpty()) ||
203 (keyRadio1->isChecked() && keyLineEdit1->text().isEmpty()) || 203 (keyRadio1->isChecked() && keyLineEdit1->text().isEmpty()) ||
204 (keyRadio2->isChecked() && keyLineEdit2->text().isEmpty()) || 204 (keyRadio2->isChecked() && keyLineEdit2->text().isEmpty()) ||
205 (keyRadio3->isChecked() && keyLineEdit3->text().isEmpty())) { 205 (keyRadio3->isChecked() && keyLineEdit3->text().isEmpty())) {
206 QMessageBox::information(this, "Error", "Please enter a WEP key.", QMessageBox::Ok); 206 QMessageBox::information(this, "Error", "Please enter a WEP key.", QMessageBox::Ok);
207 return; 207 return;
208 } 208 }
209 } 209 }
210 210
211 if (essid->currentText().isEmpty()) { 211 if (essid->currentText().isEmpty()) {
212 QMessageBox::information(this, "Error", "Please select/enter an ESSID.", QMessageBox::Ok); 212 QMessageBox::information(this, "Error", "Please select/enter an ESSID.", QMessageBox::Ok);
213 return; 213 return;
214 } 214 }
215 215
216 if (specifyAp->isChecked() && macEdit->text().isEmpty()) { 216 if (specifyAp->isChecked() && macEdit->text().isEmpty()) {
217 QMessageBox::information(this, "Error", "Please enter the MAC address of the Access Point.", QMessageBox::Ok); 217 QMessageBox::information(this, "Error", "Please enter the MAC address of the Access Point.", QMessageBox::Ok);
218 return; 218 return;
219 } 219 }
220 220
221 // Try to save the interfaces settings. 221 // Try to save the interfaces settings.
222 writeOpts(); 222 writeOpts();
223 223
224 // Close out the dialog 224 // Close out the dialog
225// FIXME: QDialog::accept(); 225// FIXME: QDialog::accept();
226} 226}
227 227
228void WLANImp::writeOpts() { 228void WLANImp::writeOpts() {
229 // eh can't really do anything about it other then return. :-D 229 // eh can't really do anything about it other then return. :-D
230 if(!interfaces->isInterfaceSet()){ 230 if(!interfaces->isInterfaceSet()){
231 QMessageBox::warning(0,"Inface not set","should not happen!!!"); 231 QMessageBox::warning(0,"Inface not set","should not happen!!!");
232 return; 232 return;
233 } 233 }
234 bool error = false; 234 bool error = false;
235 235
236 odebug << "setting wlan interface " << interfaces->getInterfaceName( error ).latin1() << "" << oendl; 236 odebug << "setting wlan interface " << interfaces->getInterfaceName( error ).latin1() << "" << oendl;
237 237
238 if (error) QMessageBox::warning(0,"Inface not set","should not happen!!!"); 238 if (error) QMessageBox::warning(0,"Inface not set","should not happen!!!");
239 239
240 interfaces->setInterfaceOption(QString("wireless_mode"), mode->currentText()); 240 interfaces->setInterfaceOption(QString("wireless_mode"), mode->currentText());
241 interfaces->setInterfaceOption(QString("wireless_essid"), essid->currentText()); 241 interfaces->setInterfaceOption(QString("wireless_essid"), essid->currentText());
242 242
243 if (specifyAp->isChecked()) { 243 if (specifyAp->isChecked()) {
244 interfaces->setInterfaceOption(QString("wireless_ap"), macEdit->text()); 244 interfaces->setInterfaceOption(QString("wireless_ap"), macEdit->text());
245 } else { 245 } else {
246 interfaces->removeInterfaceOption(QString("wireless_ap")); 246 interfaces->removeInterfaceOption(QString("wireless_ap"));
247 } 247 }
248 248
249 if (specifyChan->isChecked()) { 249 if (specifyChan->isChecked()) {
250 interfaces->setInterfaceOption(QString("wireless_channel"), networkChannel->text()); 250 interfaces->setInterfaceOption(QString("wireless_channel"), networkChannel->text());
251 } else { 251 } else {
252 interfaces->removeInterfaceOption(QString("wireless_channel")); 252 interfaces->removeInterfaceOption(QString("wireless_channel"));
253 } 253 }
254 254
255 if (wepEnabled->isChecked()) { 255 if (wepEnabled->isChecked()) {
256 QStringList keyList; 256 QStringList keyList;
257 257
258 if (! keyLineEdit0->text().isNull()) { 258 if (! keyLineEdit0->text().isNull()) {
259 keyList += keyLineEdit0->text(); 259 keyList += keyLineEdit0->text();
260 keyList += "[1]"; 260 keyList += "[1]";
261 } //else 261 } //else
262 if (! keyLineEdit1->text().isNull()) { 262 if (! keyLineEdit1->text().isNull()) {
263 keyList += keyLineEdit1->text(); 263 keyList += keyLineEdit1->text();
264 keyList += "[2]"; 264 keyList += "[2]";
265 } //else 265 } //else
266 if (! keyLineEdit2->text().isNull()) { 266 if (! keyLineEdit2->text().isNull()) {
267 keyList += keyLineEdit2->text(); 267 keyList += keyLineEdit2->text();
268 keyList += "[3]"; 268 keyList += "[3]";
269 } //else 269 } //else
270 if (! keyLineEdit3->text().isNull()) { 270 if (! keyLineEdit3->text().isNull()) {
271 keyList += keyLineEdit3->text(); 271 keyList += keyLineEdit3->text();
272 keyList += "[4]"; 272 keyList += "[4]";
273 } 273 }
274 if (acceptNonEnc->isChecked()) { 274 if (acceptNonEnc->isChecked()) {
275 keyList += "open"; 275 keyList += "open";
276 } else { 276 } else {
277 keyList += "restricted"; 277 keyList += "restricted";
278 } 278 }
279 279
280 keyList += "key"; 280 keyList += "key";
281 if (keyRadio0->isChecked()) { 281 if (keyRadio0->isChecked()) {
282 keyList += "[1]"; 282 keyList += "[1]";
283 } else if (keyRadio1->isChecked()) { 283 } else if (keyRadio1->isChecked()) {
284 keyList += "[2]"; 284 keyList += "[2]";
285 } else if (keyRadio2->isChecked()) { 285 } else if (keyRadio2->isChecked()) {
286 keyList += "[3]"; 286 keyList += "[3]";
287 } else if (keyRadio3->isChecked()) { 287 } else if (keyRadio3->isChecked()) {
288 keyList += "[4]"; 288 keyList += "[4]";
289 } 289 }
290 interfaces->setInterfaceOption(QString("wireless_key"), keyList.join(QString(" "))); 290 interfaces->setInterfaceOption(QString("wireless_key"), keyList.join(QString(" ")));
291 } else { 291 } else {
292 interfaces->removeInterfaceOption(QString("wireless_key")); 292 interfaces->removeInterfaceOption(QString("wireless_key"));
293 } 293 }
294 interfaces->removeInterfaceOption(QString("wireless_enc")); 294 interfaces->removeInterfaceOption(QString("wireless_enc"));
295 295
296 if(!interfaceSetup->saveChanges()) 296 if(!interfaceSetup->saveChanges())
297 return; 297 return;
298 298
299 QDialog::accept(); 299 QDialog::accept();
300} 300}
301 301
302/* 302/*
303 * Scan for possible wireless networks around... 303 * Scan for possible wireless networks around...
304 * ... powered by Wellenreiter II technology (C) Michael 'Mickey' Lauer <mickeyl@handhelds.org> 304 * ... powered by Wellenreiter II technology (C) Michael 'Mickey' Lauer <mickeyl@handhelds.org>
305 */ 305 */
306 306
307void WLANImp::rescanNeighbourhood() 307void WLANImp::rescanNeighbourhood()
308{ 308{
309 QString name = interface->getInterfaceName(); 309 QString name = interface->getInterfaceName();
310 odebug << "rescanNeighbourhood via '" << (const char*) name << "'" << oendl; 310 odebug << "rescanNeighbourhood via '" << name << "'" << oendl;
311 311
312 OWirelessNetworkInterface* wiface = static_cast<OWirelessNetworkInterface*>( ONetwork::instance()->interface( name ) ); 312 OWirelessNetworkInterface* wiface = static_cast<OWirelessNetworkInterface*>( ONetwork::instance()->interface( name ) );
313 assert( wiface ); 313 assert( wiface );
314 314
315 // try to guess device type 315 // try to guess device type
316 QString devicetype; 316 QString devicetype;
317 QFile m( "/proc/modules" ); 317 QFile m( "/proc/modules" );
318 if ( m.open( IO_ReadOnly ) ) 318 if ( m.open( IO_ReadOnly ) )
319 { 319 {
320 QString line; 320 QString line;
321 QTextStream modules( &m ); 321 QTextStream modules( &m );
322 while( !modules.atEnd() && !devicetype ) 322 while( !modules.atEnd() && !devicetype )
323 { 323 {
324 modules >> line; 324 modules >> line;
325 if ( line.contains( "cisco" ) ) devicetype = "cisco"; 325 if ( line.contains( "cisco" ) ) devicetype = "cisco";
326 else if ( line.contains( "hostap" ) ) devicetype = "hostap"; 326 else if ( line.contains( "hostap" ) ) devicetype = "hostap";
327 else if ( line.contains( "prism" ) ) devicetype = "wlan-ng"; /* puke */ 327 else if ( line.contains( "prism" ) ) devicetype = "wlan-ng"; /* puke */
328 else if ( line.contains( "orinoco" ) ) devicetype = "orinoco"; 328 else if ( line.contains( "orinoco" ) ) devicetype = "orinoco";
329 } 329 }
330 } 330 }
331 if ( devicetype.isEmpty() ) 331 if ( devicetype.isEmpty() )
332 { 332 {
333 owarn << "rescanNeighbourhood(): couldn't guess device type :(" << oendl; 333 owarn << "rescanNeighbourhood(): couldn't guess device type :(" << oendl;
334 return; 334 return;
335 } 335 }
336 else 336 else
337 { 337 {
338 odebug << "rescanNeighbourhood(): device type seems to be '" << (const char*) devicetype << "'" << oendl; 338 odebug << "rescanNeighbourhood(): device type seems to be '" << devicetype << "'" << oendl;
339 } 339 }
340 340
341 // configure interface to receive 802.11 management frames 341 // configure interface to receive 802.11 management frames
342 342
343 wiface->setUp( true ); 343 wiface->setUp( true );
344 wiface->setPromiscuousMode( true ); 344 wiface->setPromiscuousMode( true );
345 345
346 if ( devicetype == "cisco" ) wiface->setMonitoring( new OCiscoMonitoringInterface( wiface, false ) ); 346 if ( devicetype == "cisco" ) wiface->setMonitoring( new OCiscoMonitoringInterface( wiface, false ) );
347 else if ( devicetype == "hostap" ) wiface->setMonitoring( new OHostAPMonitoringInterface( wiface, false ) ); 347 else if ( devicetype == "hostap" ) wiface->setMonitoring( new OHostAPMonitoringInterface( wiface, false ) );
348 else if ( devicetype == "wlan-ng" ) wiface->setMonitoring( new OWlanNGMonitoringInterface( wiface, false ) ); 348 else if ( devicetype == "wlan-ng" ) wiface->setMonitoring( new OWlanNGMonitoringInterface( wiface, false ) );
349 else if ( devicetype == "orinoco" ) wiface->setMonitoring( new OOrinocoMonitoringInterface( wiface, false ) ); 349 else if ( devicetype == "orinoco" ) wiface->setMonitoring( new OOrinocoMonitoringInterface( wiface, false ) );
350 else 350 else
351 { 351 {
352 odebug << "rescanNeighbourhood(): unsupported device type for monitoring :(" << oendl; 352 odebug << "rescanNeighbourhood(): unsupported device type for monitoring :(" << oendl;
353 return; 353 return;
354 } 354 }
355 355
356 wiface->setMode( "monitor" ); 356 wiface->setMode( "monitor" );
357 if ( wiface->mode() != "monitor" ) 357 if ( wiface->mode() != "monitor" )
358 { 358 {
359 owarn << "rescanNeighbourhood(): Unable to bring device into monitor mode (" << strerror( errno ) << ")." << oendl; 359 owarn << "rescanNeighbourhood(): Unable to bring device into monitor mode (" << strerror( errno ) << ")." << oendl;
360 return; 360 return;
361 } 361 }
362 362
363 // open a packet capturer 363 // open a packet capturer
364 OPacketCapturer* cap = new OPacketCapturer(); 364 OPacketCapturer* cap = new OPacketCapturer();
365 cap->open( name ); 365 cap->open( name );
366 if ( !cap->isOpen() ) 366 if ( !cap->isOpen() )
367 { 367 {
368 owarn << "rescanNeighbourhood(): Unable to open libpcap (" << strerror( errno ) << ")." << oendl; 368 owarn << "rescanNeighbourhood(): Unable to open libpcap (" << strerror( errno ) << ")." << oendl;
369 return; 369 return;
370 } 370 }
371 371
372 // display splash screen 372 // display splash screen
373 QFrame* splash = new QFrame( this, "splash", false, WStyle_StaysOnTop | WStyle_DialogBorder | WStyle_Customize ); 373 QFrame* splash = new QFrame( this, "splash", false, WStyle_StaysOnTop | WStyle_DialogBorder | WStyle_Customize );
374 splash->setLineWidth( 2 ); 374 splash->setLineWidth( 2 );
375 splash->setFrameStyle( QFrame::Panel | QFrame::Raised ); 375 splash->setFrameStyle( QFrame::Panel | QFrame::Raised );
376 QVBoxLayout* vbox = new QVBoxLayout( splash, 4, 4 ); 376 QVBoxLayout* vbox = new QVBoxLayout( splash, 4, 4 );
377 QLabel* lab = new QLabel( "<center><b>Scanning...</b><br>Please Wait...</center>", splash ); 377 QLabel* lab = new QLabel( "<center><b>Scanning...</b><br>Please Wait...</center>", splash );
378 QProgressBar* pb = new QProgressBar( wiface->channels(), splash ); 378 QProgressBar* pb = new QProgressBar( wiface->channels(), splash );
379 vbox->addWidget( lab ); 379 vbox->addWidget( lab );
380 vbox->addWidget( pb ); 380 vbox->addWidget( pb );
381 pb->setCenterIndicator( true ); 381 pb->setCenterIndicator( true );
382 pb->setFixedHeight( pb->sizeHint().height() ); 382 pb->setFixedHeight( pb->sizeHint().height() );
383 QWidget* widgetDesktop = qApp->desktop(); 383 QWidget* widgetDesktop = qApp->desktop();
384 int dw = widgetDesktop->width(); 384 int dw = widgetDesktop->width();
385 int dh = widgetDesktop->height(); 385 int dh = widgetDesktop->height();
386 int pw = vbox->sizeHint().width(); 386 int pw = vbox->sizeHint().width();
387 int ph = vbox->sizeHint().height(); 387 int ph = vbox->sizeHint().height();
388 splash->setGeometry((dw-pw)/2,(dh-ph)/2,pw,ph); 388 splash->setGeometry((dw-pw)/2,(dh-ph)/2,pw,ph);
389 splash->show(); 389 splash->show();
390 splash->raise(); 390 splash->raise();
391 qApp->processEvents(); 391 qApp->processEvents();
392 392
393 // set capturer to non-blocking mode 393 // set capturer to non-blocking mode
394 cap->setBlocking( false ); 394 cap->setBlocking( false );
395 395
396 for ( int i = 1; i <= wiface->channels(); ++i ) 396 for ( int i = 1; i <= wiface->channels(); ++i )
397 { 397 {
398 wiface->setChannel( i ); 398 wiface->setChannel( i );
399 pb->setProgress( i ); 399 pb->setProgress( i );
400 qApp->processEvents(); 400 qApp->processEvents();
401 odebug << "rescanNeighbourhood(): listening on channel " << i << "..." << oendl; 401 odebug << "rescanNeighbourhood(): listening on channel " << i << "..." << oendl;
402 OPacket* p = cap->next( 1000 ); 402 OPacket* p = cap->next( 1000 );
403 if ( !p ) 403 if ( !p )
404 { 404 {
405 odebug << "rescanNeighbourhood(): nothing received on channel " << i << "" << oendl; 405 odebug << "rescanNeighbourhood(): nothing received on channel " << i << "" << oendl;
406 } 406 }
407 else 407 else
408 { 408 {
409 odebug << "rescanNeighbourhood(): TADAA - something came in on channel " << i << "" << oendl; 409 odebug << "rescanNeighbourhood(): TADAA - something came in on channel " << i << "" << oendl;
410 handlePacket( p ); 410 handlePacket( p );
411 } 411 }
412 } 412 }
413 413
414 cap->close(); 414 cap->close();
415 wiface->setMode( "managed" ); // TODO: use previous mode 415 wiface->setMode( "managed" ); // TODO: use previous mode
416 wiface->setPromiscuousMode( false ); 416 wiface->setPromiscuousMode( false );
417 417
418 splash->hide(); 418 splash->hide();
419 delete splash; 419 delete splash;
420 420
421} 421}
422 422
423void WLANImp::handlePacket( OPacket* p ) 423void WLANImp::handlePacket( OPacket* p )
424{ 424{
425 425
426 // check if we received a beacon frame 426 // check if we received a beacon frame
427 OWaveLanManagementPacket* beacon = static_cast<OWaveLanManagementPacket*>( p->child( "802.11 Management" ) ); 427 OWaveLanManagementPacket* beacon = static_cast<OWaveLanManagementPacket*>( p->child( "802.11 Management" ) );
428 if ( beacon && beacon->managementType() == "Beacon" ) 428 if ( beacon && beacon->managementType() == "Beacon" )
429 { 429 {
430 430
431 QString type; 431 QString type;
432 if ( beacon->canIBSS() ) 432 if ( beacon->canIBSS() )
433 { 433 {
434 type = "adhoc"; 434 type = "adhoc";
435 } 435 }
436 else if ( beacon->canESS() ) 436 else if ( beacon->canESS() )
437 { 437 {
438 type = "managed"; 438 type = "managed";
439 } 439 }
440 else 440 else
441 { 441 {
442 owarn << "handlePacket(): invalid frame [possibly noise] detected!" << oendl; 442 owarn << "handlePacket(): invalid frame [possibly noise] detected!" << oendl;
443 return; 443 return;
444 } 444 }
445 445
446 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); 446 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) );
447 QString essid = ssid ? ssid->ID() : QString("<unknown>"); 447 QString essid = ssid ? ssid->ID() : QString("<unknown>");
448 OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) ); 448 OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) );
449 int channel = ds ? ds->channel() : -1; 449 int channel = ds ? ds->channel() : -1;
450 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) ); 450 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) );
451 displayFoundNetwork( type, channel, essid, header->macAddress2() ); 451 displayFoundNetwork( type, channel, essid, header->macAddress2() );
452 } 452 }
453} 453}
454 454
455 455
456void WLANImp::displayFoundNetwork( const QString& mode, int channel, const QString& ssid, const OMacAddress& mac ) 456void WLANImp::displayFoundNetwork( const QString& mode, int channel, const QString& ssid, const OMacAddress& mac )
457{ 457{
458 458
459 qDebug( "found network: <%s>, chn %d, ssid '%s', mac '%s'", (const char*) mode, channel, 459 qDebug( "found network: <%s>, chn %d, ssid '%s', mac '%s'", (const char*) mode, channel,
460 (const char*) ssid, 460 (const char*) ssid,
461 (const char*) mac.toString() ); 461 (const char*) mac.toString() );
462 462
463 QListViewItemIterator it( netView ); 463 QListViewItemIterator it( netView );
464 while ( it.current() && it.current()->text( col_ssid ) != ssid ) ++it; 464 while ( it.current() && it.current()->text( col_ssid ) != ssid ) ++it;
465 if ( !it.current() ) // ssid didn't show up yet 465 if ( !it.current() ) // ssid didn't show up yet
466 { 466 {
467 QListViewItem* item = new QListViewItem( netView, mode.left( 1 ).upper(), ssid, QString::number( channel ), mac.toString() ); 467 QListViewItem* item = new QListViewItem( netView, mode.left( 1 ).upper(), ssid, QString::number( channel ), mac.toString() );
468 QString name; 468 QString name;
469 name.sprintf( "networksettings/%s", (const char*) mode ); 469 name.sprintf( "networksettings/%s", (const char*) mode );
470 item->setPixmap( col_mode, Resource::loadPixmap( name ) ); 470 item->setPixmap( col_mode, Resource::loadPixmap( name ) );
471 qApp->processEvents(); 471 qApp->processEvents();
472 } 472 }
473 473
474} 474}
475 475
476 476
477void WLANImp::selectNetwork( QListViewItem* item ) 477void WLANImp::selectNetwork( QListViewItem* item )
478{ 478{
479 bool ok; 479 bool ok;
480 if ( item ) 480 if ( item )
481 { 481 {
482 specifyAp->setChecked(true); 482 specifyAp->setChecked(true);
483 macEdit->setText( item->text( col_mac ) ); 483 macEdit->setText( item->text( col_mac ) );
484 specifyChan->setChecked( item->text( col_mode ) == "A" ); 484 specifyChan->setChecked( item->text( col_mode ) == "A" );
485 networkChannel->setValue( item->text( col_chn ).toInt( &ok ) ); 485 networkChannel->setValue( item->text( col_chn ).toInt( &ok ) );
486 essid->setEditText( item->text( col_ssid ) ); 486 essid->setEditText( item->text( col_ssid ) );
487 if ( item->text( col_mode ) == "A" ) 487 if ( item->text( col_mode ) == "A" )
488 mode->setCurrentItem( 3 ); 488 mode->setCurrentItem( 3 );
489 else 489 else
490 mode->setCurrentItem( 2 ); 490 mode->setCurrentItem( 2 );
491 } 491 }
492} 492}
diff --git a/noncore/settings/sysinfo/benchmarkinfo.cpp b/noncore/settings/sysinfo/benchmarkinfo.cpp
index 4163fb2..53d4897 100644
--- a/noncore/settings/sysinfo/benchmarkinfo.cpp
+++ b/noncore/settings/sysinfo/benchmarkinfo.cpp
@@ -1,480 +1,480 @@
1/********************************************************************** 1/**********************************************************************
2** BenchmarkInfo 2** BenchmarkInfo
3** 3**
4** A benchmark for Qt/Embedded 4** A benchmark for Qt/Embedded
5** 5**
6** Copyright (C) 2004 Michael Lauer <mickey@vanille.de> 6** Copyright (C) 2004 Michael Lauer <mickey@vanille.de>
7** Inspired by ZBench (C) 2002 Satoshi <af230533@im07.alpha-net.ne.jp> 7** Inspired by ZBench (C) 2002 Satoshi <af230533@im07.alpha-net.ne.jp>
8** 8**
9** This file may be distributed and/or modified under the terms of the 9** This file may be distributed and/or modified under the terms of the
10** GNU General Public License version 2 as published by the Free Software 10** GNU General Public License version 2 as published by the Free Software
11** Foundation and appearing in the file LICENSE.GPL included in the 11** Foundation and appearing in the file LICENSE.GPL included in the
12** packaging of this file. 12** packaging of this file.
13** 13**
14** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 14** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
15** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 15** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16** 16**
17**********************************************************************/ 17**********************************************************************/
18 18
19#include "benchmarkinfo.h" 19#include "benchmarkinfo.h"
20 20
21/* OPIE */ 21/* OPIE */
22#include <opie2/odebug.h> 22#include <opie2/odebug.h>
23#include <opie2/ostorageinfo.h> 23#include <opie2/ostorageinfo.h>
24#include <opie2/olistview.h> 24#include <opie2/olistview.h>
25#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
26#include <qpe/qcopenvelope_qws.h> 26#include <qpe/qcopenvelope_qws.h>
27#include <qpe/qpedecoration_qws.h> 27#include <qpe/qpedecoration_qws.h>
28#include <qpe/resource.h> 28#include <qpe/resource.h>
29#include <qpe/config.h> 29#include <qpe/config.h>
30using namespace Opie::Core; 30using namespace Opie::Core;
31using namespace Opie::Ui; 31using namespace Opie::Ui;
32 32
33/* QT */ 33/* QT */
34#include <qclipboard.h> 34#include <qclipboard.h>
35#include <qcolor.h> 35#include <qcolor.h>
36#include <qcombobox.h> 36#include <qcombobox.h>
37#include <qdirectpainter_qws.h> 37#include <qdirectpainter_qws.h>
38#include <qfile.h> 38#include <qfile.h>
39#include <qtextstream.h> 39#include <qtextstream.h>
40#include <qfiledialog.h> 40#include <qfiledialog.h>
41#include <qlabel.h> 41#include <qlabel.h>
42#include <qlayout.h> 42#include <qlayout.h>
43#include <qpainter.h> 43#include <qpainter.h>
44#include <qpushbutton.h> 44#include <qpushbutton.h>
45#include <qtimer.h> 45#include <qtimer.h>
46#include <qwhatsthis.h> 46#include <qwhatsthis.h>
47 47
48/* STD */ 48/* STD */
49#include <time.h> 49#include <time.h>
50#include <stdio.h> 50#include <stdio.h>
51#include <stdlib.h> 51#include <stdlib.h>
52#include <math.h> 52#include <math.h>
53#if defined (__GNUC__) && (__GNUC__ < 3) 53#if defined (__GNUC__) && (__GNUC__ < 3)
54#define round qRound 54#define round qRound
55#endif 55#endif
56 56
57extern "C" 57extern "C"
58{ 58{
59 void BenchFFT( void ); 59 void BenchFFT( void );
60 double dhry_main( int ); 60 double dhry_main( int );
61} 61}
62 62
63#define DHRYSTONE_RUNS 20000000 63#define DHRYSTONE_RUNS 20000000
64#define TEST_DURATION 3 64#define TEST_DURATION 3
65 65
66#define BUFF_SIZE 8192 66#define BUFF_SIZE 8192
67#define FILE_SIZE 1024 * 1024 // 1Mb 67#define FILE_SIZE 1024 * 1024 // 1Mb
68 68
69//=========================================================================== 69//===========================================================================
70 70
71class BenchmarkPaintWidget : public QWidget 71class BenchmarkPaintWidget : public QWidget
72{ 72{
73 public: 73 public:
74 BenchmarkPaintWidget() : QWidget( 0, "Benchmark Paint Widget", WStyle_Customize|WStyle_StaysOnTop|WPaintUnclipped|WPaintClever ) 74 BenchmarkPaintWidget() : QWidget( 0, "Benchmark Paint Widget", WStyle_Customize|WStyle_StaysOnTop|WPaintUnclipped|WPaintClever )
75 { 75 {
76 resize( QApplication::desktop()->size() ); 76 resize( QApplication::desktop()->size() );
77 show(); 77 show();
78 p.begin( this ); 78 p.begin( this );
79 }; 79 };
80 80
81 ~BenchmarkPaintWidget() 81 ~BenchmarkPaintWidget()
82 { 82 {
83 p.end(); 83 p.end();
84 hide(); 84 hide();
85 }; 85 };
86 86
87 QPainter p; 87 QPainter p;
88}; 88};
89 89
90//=========================================================================== 90//===========================================================================
91 91
92BenchmarkInfo::BenchmarkInfo( QWidget *parent, const char *name, int wFlags ) 92BenchmarkInfo::BenchmarkInfo( QWidget *parent, const char *name, int wFlags )
93 : QWidget( parent, name, wFlags ) 93 : QWidget( parent, name, wFlags )
94{ 94{
95 95
96 setMinimumSize( 200, 150 ); 96 setMinimumSize( 200, 150 );
97 97
98 QVBoxLayout* vb = new QVBoxLayout( this ); 98 QVBoxLayout* vb = new QVBoxLayout( this );
99 vb->setSpacing( 4 ); 99 vb->setSpacing( 4 );
100 vb->setMargin( 4 ); 100 vb->setMargin( 4 );
101 101
102 tests = new OListView( this ); 102 tests = new OListView( this );
103 QWhatsThis::add( tests->viewport(), tr( "This area shows the available tests, the results for which the tests " 103 QWhatsThis::add( tests->viewport(), tr( "This area shows the available tests, the results for which the tests "
104 "have been performed, and comparison values for one selected device. " 104 "have been performed, and comparison values for one selected device. "
105 "Use the checkboxes to define which tests you want to perform." ) ); 105 "Use the checkboxes to define which tests you want to perform." ) );
106 tests->setMargin( 0 ); 106 tests->setMargin( 0 );
107 tests->addColumn( tr( "Tests" ) ); 107 tests->addColumn( tr( "Tests" ) );
108 tests->addColumn( tr( "Results" ) ); 108 tests->addColumn( tr( "Results" ) );
109 tests->addColumn( tr( "Comparison" ) ); 109 tests->addColumn( tr( "Comparison" ) );
110 tests->setShowSortIndicator( true ); 110 tests->setShowSortIndicator( true );
111 111
112 test_alu = new OCheckListItem( tests, tr( "1. Integer Arithmetic " ), OCheckListItem::CheckBox ); 112 test_alu = new OCheckListItem( tests, tr( "1. Integer Arithmetic " ), OCheckListItem::CheckBox );
113 test_fpu = new OCheckListItem( tests, tr( "2. Floating Point Unit " ), OCheckListItem::CheckBox ); 113 test_fpu = new OCheckListItem( tests, tr( "2. Floating Point Unit " ), OCheckListItem::CheckBox );
114 test_txt = new OCheckListItem( tests, tr( "3. Text Rendering " ), OCheckListItem::CheckBox ); 114 test_txt = new OCheckListItem( tests, tr( "3. Text Rendering " ), OCheckListItem::CheckBox );
115 test_gfx = new OCheckListItem( tests, tr( "4. Gfx Rendering " ), OCheckListItem::CheckBox ); 115 test_gfx = new OCheckListItem( tests, tr( "4. Gfx Rendering " ), OCheckListItem::CheckBox );
116 test_ram = new OCheckListItem( tests, tr( "5. RAM Performance " ), OCheckListItem::CheckBox ); 116 test_ram = new OCheckListItem( tests, tr( "5. RAM Performance " ), OCheckListItem::CheckBox );
117 test_sd = new OCheckListItem( tests, tr( "6. SD Card Performance " ), OCheckListItem::CheckBox ); 117 test_sd = new OCheckListItem( tests, tr( "6. SD Card Performance " ), OCheckListItem::CheckBox );
118 test_cf = new OCheckListItem( tests, tr( "7. CF Card Performance " ), OCheckListItem::CheckBox ); 118 test_cf = new OCheckListItem( tests, tr( "7. CF Card Performance " ), OCheckListItem::CheckBox );
119 119
120 test_alu->setText( 1, "n/a" ); 120 test_alu->setText( 1, "n/a" );
121 test_fpu->setText( 1, "n/a" ); 121 test_fpu->setText( 1, "n/a" );
122 test_txt->setText( 1, "n/a" ); 122 test_txt->setText( 1, "n/a" );
123 test_gfx->setText( 1, "n/a" ); 123 test_gfx->setText( 1, "n/a" );
124 test_ram->setText( 1, "n/a" ); 124 test_ram->setText( 1, "n/a" );
125 test_sd->setText( 1, "n/a" ); 125 test_sd->setText( 1, "n/a" );
126 test_cf->setText( 1, "n/a" ); 126 test_cf->setText( 1, "n/a" );
127 127
128 test_alu->setText( 2, "n/a" ); 128 test_alu->setText( 2, "n/a" );
129 test_fpu->setText( 2, "n/a" ); 129 test_fpu->setText( 2, "n/a" );
130 test_txt->setText( 2, "n/a" ); 130 test_txt->setText( 2, "n/a" );
131 test_gfx->setText( 2, "n/a" ); 131 test_gfx->setText( 2, "n/a" );
132 test_ram->setText( 2, "n/a" ); 132 test_ram->setText( 2, "n/a" );
133 test_sd->setText( 2, "n/a" ); 133 test_sd->setText( 2, "n/a" );
134 test_cf->setText( 2, "n/a" ); 134 test_cf->setText( 2, "n/a" );
135 135
136 startButton = new QPushButton( tr( "&Start Tests!" ), this ); 136 startButton = new QPushButton( tr( "&Start Tests!" ), this );
137 QWhatsThis::add( startButton, tr( "Click here to perform the selected tests." ) ); 137 QWhatsThis::add( startButton, tr( "Click here to perform the selected tests." ) );
138 connect( startButton, SIGNAL( clicked() ), this, SLOT( run() ) ); 138 connect( startButton, SIGNAL( clicked() ), this, SLOT( run() ) );
139 vb->addWidget( tests, 2 ); 139 vb->addWidget( tests, 2 );
140 140
141 QFile f( QPEApplication::qpeDir() + "/share/sysinfo/results" ); 141 QFile f( QPEApplication::qpeDir() + "/share/sysinfo/results" );
142 if ( f.open( IO_ReadOnly ) ) 142 if ( f.open( IO_ReadOnly ) )
143 { 143 {
144 machineCombo = new QComboBox( this ); 144 machineCombo = new QComboBox( this );
145 QWhatsThis::add( machineCombo, tr( "Choose a model to compare your results with." ) ); 145 QWhatsThis::add( machineCombo, tr( "Choose a model to compare your results with." ) );
146 146
147 QTextStream ts( &f ); 147 QTextStream ts( &f );
148 while( !ts.eof() ) 148 while( !ts.eof() )
149 { 149 {
150 QString machline = ts.readLine(); 150 QString machline = ts.readLine();
151 odebug << "sysinfo: parsing benchmark results for '" << (const char*) machline << "'" << oendl; 151 odebug << "sysinfo: parsing benchmark results for '" << machline << "'" << oendl;
152 QString resline = ts.readLine(); 152 QString resline = ts.readLine();
153 machines.insert( machline, new QStringList( QStringList::split( ",", resline ) ) ); 153 machines.insert( machline, new QStringList( QStringList::split( ",", resline ) ) );
154 machineCombo->insertItem( machline ); 154 machineCombo->insertItem( machline );
155 } 155 }
156 156
157 QHBoxLayout* hb = new QHBoxLayout( vb ); 157 QHBoxLayout* hb = new QHBoxLayout( vb );
158 hb->addWidget( new QLabel( tr( "Compare To:" ), this ) ); 158 hb->addWidget( new QLabel( tr( "Compare To:" ), this ) );
159 hb->addWidget( machineCombo, 2 ); 159 hb->addWidget( machineCombo, 2 );
160 connect( machineCombo, SIGNAL( activated(int) ), this, SLOT( machineActivated(int) ) ); 160 connect( machineCombo, SIGNAL( activated(int) ), this, SLOT( machineActivated(int) ) );
161 } 161 }
162 162
163 vb->addWidget( startButton, 2 ); 163 vb->addWidget( startButton, 2 );
164} 164}
165 165
166 166
167BenchmarkInfo::~BenchmarkInfo() 167BenchmarkInfo::~BenchmarkInfo()
168{} 168{}
169 169
170 170
171void BenchmarkInfo::machineActivated( int index ) 171void BenchmarkInfo::machineActivated( int index )
172{ 172{
173 QStringList* results = machines[ machineCombo->text( index ) ]; 173 QStringList* results = machines[ machineCombo->text( index ) ];
174 if ( !results ) 174 if ( !results )
175 { 175 {
176 odebug << "sysinfo: no results available." << oendl; 176 odebug << "sysinfo: no results available." << oendl;
177 return; 177 return;
178 } 178 }
179 QStringList::Iterator it = results->begin(); 179 QStringList::Iterator it = results->begin();
180 test_alu->setText( 2, *(it++) ); 180 test_alu->setText( 2, *(it++) );
181 test_fpu->setText( 2, *(it++) ); 181 test_fpu->setText( 2, *(it++) );
182 test_txt->setText( 2, *(it++) ); 182 test_txt->setText( 2, *(it++) );
183 test_gfx->setText( 2, *(it++) ); 183 test_gfx->setText( 2, *(it++) );
184 test_ram->setText( 2, *(it++) ); 184 test_ram->setText( 2, *(it++) );
185 test_sd->setText( 2, *(it++) ); 185 test_sd->setText( 2, *(it++) );
186 test_cf->setText( 2, *(it++) ); 186 test_cf->setText( 2, *(it++) );
187} 187}
188 188
189 189
190void BenchmarkInfo::run() 190void BenchmarkInfo::run()
191{ 191{
192 startButton->setText( "> Don't touch! Running Tests! Don't touch! <" ); 192 startButton->setText( "> Don't touch! Running Tests! Don't touch! <" );
193 qApp->processEvents(); 193 qApp->processEvents();
194 QTime t; 194 QTime t;
195 195
196 if ( test_alu->isOn() ) 196 if ( test_alu->isOn() )
197 { 197 {
198 int d = round( dhry_main( DHRYSTONE_RUNS ) ); 198 int d = round( dhry_main( DHRYSTONE_RUNS ) );
199 test_alu->setText( 1, QString( "%1 dhrys" ).arg( QString::number( d ) ) ); 199 test_alu->setText( 1, QString( "%1 dhrys" ).arg( QString::number( d ) ) );
200 test_alu->setOn( false ); 200 test_alu->setOn( false );
201 } 201 }
202 202
203 if ( test_fpu->isOn() ) 203 if ( test_fpu->isOn() )
204 { 204 {
205 t.start(); 205 t.start();
206 BenchFFT(); 206 BenchFFT();
207 test_fpu->setText( 1, QString( "%1 secs" ).arg( QString::number( t.elapsed() / 1000.0 ) ) ); 207 test_fpu->setText( 1, QString( "%1 secs" ).arg( QString::number( t.elapsed() / 1000.0 ) ) );
208 test_fpu->setOn( false ); 208 test_fpu->setOn( false );
209 } 209 }
210 210
211 if ( test_txt->isOn() ) 211 if ( test_txt->isOn() )
212 { 212 {
213 int value = textRendering( TEST_DURATION ); 213 int value = textRendering( TEST_DURATION );
214 test_txt->setText( 1, QString( "%1 chars/sec" ).arg( QString::number( value / TEST_DURATION ) ) ); 214 test_txt->setText( 1, QString( "%1 chars/sec" ).arg( QString::number( value / TEST_DURATION ) ) );
215 test_txt->setOn( false ); 215 test_txt->setOn( false );
216 } 216 }
217 217
218 if ( test_gfx->isOn() ) 218 if ( test_gfx->isOn() )
219 { 219 {
220 int value = gfxRendering( TEST_DURATION ); 220 int value = gfxRendering( TEST_DURATION );
221 test_gfx->setText( 1, QString( "%1 gops/sec" ).arg( QString::number( value / 4 / TEST_DURATION ) ) ); // 4 tests 221 test_gfx->setText( 1, QString( "%1 gops/sec" ).arg( QString::number( value / 4 / TEST_DURATION ) ) ); // 4 tests
222 test_gfx->setOn( false ); 222 test_gfx->setOn( false );
223 } 223 }
224 224
225 if ( test_ram->isOn() ) // /tmp is supposed to be in RAM on a PDA 225 if ( test_ram->isOn() ) // /tmp is supposed to be in RAM on a PDA
226 { 226 {
227 performFileTest( "/tmp/benchmarkFile.dat", test_ram ); 227 performFileTest( "/tmp/benchmarkFile.dat", test_ram );
228 } 228 }
229 229
230 if ( test_cf->isOn() ) 230 if ( test_cf->isOn() )
231 { 231 {
232 OStorageInfo storage; 232 OStorageInfo storage;
233 performFileTest( storage.cfPath() + "/benchmarkFile.dat", test_cf ); 233 performFileTest( storage.cfPath() + "/benchmarkFile.dat", test_cf );
234 } 234 }
235 235
236 if ( test_sd->isOn() ) 236 if ( test_sd->isOn() )
237 { 237 {
238 OStorageInfo storage; 238 OStorageInfo storage;
239 performFileTest( storage.sdPath() + "/benchmarkFile.dat", test_sd ); 239 performFileTest( storage.sdPath() + "/benchmarkFile.dat", test_sd );
240 } 240 }
241 241
242 startButton->setText( tr( "&Start Tests!" ) ); 242 startButton->setText( tr( "&Start Tests!" ) );
243} 243}
244 244
245 245
246int BenchmarkInfo::textRendering( int seconds ) 246int BenchmarkInfo::textRendering( int seconds )
247{ 247{
248 QTime t; 248 QTime t;
249 t.start(); 249 t.start();
250 int stop = t.elapsed() + seconds * 1000; 250 int stop = t.elapsed() + seconds * 1000;
251 251
252 int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 }; 252 int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 };
253 int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 }; 253 int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 };
254 int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 }; 254 int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 };
255 const QString text( "Opie Benchmark Test" ); 255 const QString text( "Opie Benchmark Test" );
256 256
257 int w = QApplication::desktop()->width(); 257 int w = QApplication::desktop()->width();
258 int h = QApplication::desktop()->height(); 258 int h = QApplication::desktop()->height();
259 259
260 srand( time( NULL ) ); 260 srand( time( NULL ) );
261 261
262 BenchmarkPaintWidget bpw; 262 BenchmarkPaintWidget bpw;
263 263
264 int loops = 0; 264 int loops = 0;
265 265
266 while ( t.elapsed() < stop ) 266 while ( t.elapsed() < stop )
267 { 267 {
268 int k = rand() % 9; 268 int k = rand() % 9;
269 int s = rand() % 100; 269 int s = rand() % 100;
270 bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); 270 bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) );
271 bpw.p.setFont( QFont( "Vera", s ) ); 271 bpw.p.setFont( QFont( "Vera", s ) );
272 bpw.p.drawText( rand() % w, rand() % h, text, text.length() ); 272 bpw.p.drawText( rand() % w, rand() % h, text, text.length() );
273 ++loops; 273 ++loops;
274 } 274 }
275 275
276 return loops * text.length(); 276 return loops * text.length();
277} 277}
278 278
279int BenchmarkInfo::gfxRendering( int seconds ) 279int BenchmarkInfo::gfxRendering( int seconds )
280{ 280{
281 int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 }; 281 int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 };
282 int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 }; 282 int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 };
283 int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 }; 283 int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 };
284 284
285 int w = QApplication::desktop()->width(); 285 int w = QApplication::desktop()->width();
286 int h = QApplication::desktop()->height(); 286 int h = QApplication::desktop()->height();
287 287
288 srand( time( NULL ) ); 288 srand( time( NULL ) );
289 289
290 BenchmarkPaintWidget bpw; 290 BenchmarkPaintWidget bpw;
291 291
292 QTime t; 292 QTime t;
293 t.start(); 293 t.start();
294 int stop = t.elapsed() + seconds*1000; 294 int stop = t.elapsed() + seconds*1000;
295 int loops = 0; 295 int loops = 0;
296 296
297 while ( t.elapsed() < stop ) 297 while ( t.elapsed() < stop )
298 { 298 {
299 int k = rand() % 9; 299 int k = rand() % 9;
300 bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); 300 bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) );
301 bpw.p.drawLine( rand()%w, rand()%h, rand()%w, rand()%h ); 301 bpw.p.drawLine( rand()%w, rand()%h, rand()%w, rand()%h );
302 ++loops; 302 ++loops;
303 } 303 }
304 304
305 t.restart(); 305 t.restart();
306 stop = t.elapsed() + seconds*1000; 306 stop = t.elapsed() + seconds*1000;
307 307
308 while ( t.elapsed() < stop ) 308 while ( t.elapsed() < stop )
309 { 309 {
310 int k = rand() % 9; 310 int k = rand() % 9;
311 bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); 311 bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) );
312 bpw.p.drawArc( rand()%w, rand()%h, rand()%w, rand()%h, 360 * 16, 360 * 16 ); 312 bpw.p.drawArc( rand()%w, rand()%h, rand()%w, rand()%h, 360 * 16, 360 * 16 );
313 ++loops; 313 ++loops;
314 } 314 }
315 315
316 QBrush br1; 316 QBrush br1;
317 br1.setStyle( SolidPattern ); 317 br1.setStyle( SolidPattern );
318 t.restart(); 318 t.restart();
319 stop = t.elapsed() + seconds*1000; 319 stop = t.elapsed() + seconds*1000;
320 320
321 while ( t.elapsed() < stop ) 321 while ( t.elapsed() < stop )
322 { 322 {
323 int k = rand() % 9; 323 int k = rand() % 9;
324 br1.setColor( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); 324 br1.setColor( QColor( rr[ k ], gg[ k ], bb[ k ] ) );
325 bpw.p.fillRect( rand()%w, rand()%h, rand()%w, rand()%h, br1 ); 325 bpw.p.fillRect( rand()%w, rand()%h, rand()%w, rand()%h, br1 );
326 ++loops; 326 ++loops;
327 } 327 }
328 328
329 QPixmap p = Resource::loadPixmap( "sysinfo/pattern" ); 329 QPixmap p = Resource::loadPixmap( "sysinfo/pattern" );
330 t.restart(); 330 t.restart();
331 stop = t.elapsed() + seconds*1000; 331 stop = t.elapsed() + seconds*1000;
332 332
333 while ( t.elapsed() < stop ) 333 while ( t.elapsed() < stop )
334 { 334 {
335 bpw.p.drawPixmap( rand()%w, rand()%h, p ); 335 bpw.p.drawPixmap( rand()%w, rand()%h, p );
336 ++loops; 336 ++loops;
337 } 337 }
338 338
339 return loops; 339 return loops;
340 340
341} 341}
342 342
343void BenchmarkInfo::performFileTest( const QString& fname, OCheckListItem* item ) 343void BenchmarkInfo::performFileTest( const QString& fname, OCheckListItem* item )
344{ 344{
345 QTime time; 345 QTime time;
346 time.start(); 346 time.start();
347 if ( writeFile( fname ) && 347 if ( writeFile( fname ) &&
348 readFile( fname ) ) 348 readFile( fname ) )
349 { 349 {
350 QFile::remove( fname ); 350 QFile::remove( fname );
351 item->setText( 1, QString( "%1 kb/sec" ).arg( QString::number( 1024.0 / ( time.elapsed() / 1000.0 ) ) ) ); 351 item->setText( 1, QString( "%1 kb/sec" ).arg( QString::number( 1024.0 / ( time.elapsed() / 1000.0 ) ) ) );
352 item->setOn( false ); 352 item->setOn( false );
353 } 353 }
354 else 354 else
355 { 355 {
356 item->setText( 1, tr( "error" ) ); 356 item->setText( 1, tr( "error" ) );
357 } 357 }
358} 358}
359 359
360char FileBuf[ BUFF_SIZE + 1 ]; 360char FileBuf[ BUFF_SIZE + 1 ];
361 361
362bool BenchmarkInfo::writeFile( const QString& w_path ) 362bool BenchmarkInfo::writeFile( const QString& w_path )
363{ 363{
364 int i; 364 int i;
365 int k; 365 int k;
366 int n; 366 int n;
367 int pos; 367 int pos;
368 int len; 368 int len;
369 char *data = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; // 62 369 char *data = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; // 62
370 370
371 371
372 // /*------------------------------------ 372 // /*------------------------------------
373 int w_len; 373 int w_len;
374 374
375 QFile writeFile( w_path ); 375 QFile writeFile( w_path );
376 srand( time( NULL ) ); 376 srand( time( NULL ) );
377 377
378 for ( n = 0 ; n < 20 ; n++ ) 378 for ( n = 0 ; n < 20 ; n++ )
379 { 379 {
380 if ( ! writeFile.open( IO_WriteOnly ) ) 380 if ( ! writeFile.open( IO_WriteOnly ) )
381 { 381 {
382 writeFile.close(); 382 writeFile.close();
383 writeFile.remove(); 383 writeFile.remove();
384 return ( false ); 384 return ( false );
385 } 385 }
386 // ------------------------------------------ sequential write 386 // ------------------------------------------ sequential write
387 for ( k = 0 ; k < 256 ; k++ ) 387 for ( k = 0 ; k < 256 ; k++ )
388 { 388 {
389 n = rand() % 30; 389 n = rand() % 30;
390 memcpy( &FileBuf[ k * 32 ], &data[ n ], 32 ); 390 memcpy( &FileBuf[ k * 32 ], &data[ n ], 32 );
391 } 391 }
392 392
393 for ( i = 0 ; i < FILE_SIZE / BUFF_SIZE ; i++ ) 393 for ( i = 0 ; i < FILE_SIZE / BUFF_SIZE ; i++ )
394 { 394 {
395 w_len = writeFile.writeBlock( FileBuf, BUFF_SIZE ); 395 w_len = writeFile.writeBlock( FileBuf, BUFF_SIZE );
396 if ( w_len != BUFF_SIZE ) 396 if ( w_len != BUFF_SIZE )
397 { 397 {
398 writeFile.close(); 398 writeFile.close();
399 writeFile.remove(); 399 writeFile.remove();
400 return ( false ); 400 return ( false );
401 } 401 }
402 writeFile.flush(); 402 writeFile.flush();
403 } 403 }
404 // ------------------------------------------ random write 404 // ------------------------------------------ random write
405 for ( i = 0 ; i < 400 ; i++ ) 405 for ( i = 0 ; i < 400 ; i++ )
406 { 406 {
407 len = rand() % 90 + 4000; 407 len = rand() % 90 + 4000;
408 for ( k = 0 ; k < 128 ; k++ ) 408 for ( k = 0 ; k < 128 ; k++ )
409 { 409 {
410 n = rand() % 30; 410 n = rand() % 30;
411 memcpy( &FileBuf[ k * 8 ], &data[ n ], 32 ); 411 memcpy( &FileBuf[ k * 8 ], &data[ n ], 32 );
412 } 412 }
413 pos = rand() % ( FILE_SIZE - BUFF_SIZE ); 413 pos = rand() % ( FILE_SIZE - BUFF_SIZE );
414 414
415 writeFile.at( pos ); 415 writeFile.at( pos );
416 w_len = writeFile.writeBlock( FileBuf, len ); 416 w_len = writeFile.writeBlock( FileBuf, len );
417 if ( w_len != len ) 417 if ( w_len != len )
418 { 418 {
419 writeFile.close(); 419 writeFile.close();
420 writeFile.remove(); 420 writeFile.remove();
421 return ( false ); 421 return ( false );
422 } 422 }
423 writeFile.flush(); 423 writeFile.flush();
424 } 424 }
425 writeFile.close(); 425 writeFile.close();
426 } 426 }
427 return ( true ); 427 return ( true );
428 428
429} 429}
430 430
431 431
432bool BenchmarkInfo::readFile( const QString& r_path ) 432bool BenchmarkInfo::readFile( const QString& r_path )
433{ 433{
434 int i; 434 int i;
435 int k; 435 int k;
436 int len; 436 int len;
437 int pos; 437 int pos;
438 int r_len; 438 int r_len;
439 439
440 QFile readFile( r_path ); 440 QFile readFile( r_path );
441 srand( time( NULL ) ); 441 srand( time( NULL ) );
442 442
443 for ( k = 0 ; k < 200 ; k++ ) 443 for ( k = 0 ; k < 200 ; k++ )
444 { 444 {
445 if ( ! readFile.open( IO_ReadOnly ) ) 445 if ( ! readFile.open( IO_ReadOnly ) )
446 { 446 {
447 readFile.remove(); 447 readFile.remove();
448 return ( false ); 448 return ( false );
449 } 449 }
450 // ------------------------------------------ sequential read 450 // ------------------------------------------ sequential read
451 readFile.at( 0 ); 451 readFile.at( 0 );
452 for ( i = 0 ; i < FILE_SIZE / BUFF_SIZE ; i++ ) 452 for ( i = 0 ; i < FILE_SIZE / BUFF_SIZE ; i++ )
453 { 453 {
454 readFile.at( i * BUFF_SIZE ); 454 readFile.at( i * BUFF_SIZE );
455 r_len = readFile.readBlock( FileBuf, BUFF_SIZE ); 455 r_len = readFile.readBlock( FileBuf, BUFF_SIZE );
456 if ( r_len != BUFF_SIZE ) 456 if ( r_len != BUFF_SIZE )
457 { 457 {
458 readFile.close(); 458 readFile.close();
459 readFile.remove(); 459 readFile.remove();
460 return ( false ); 460 return ( false );
461 } 461 }
462 } 462 }
463 // ------------------------------------------ random read 463 // ------------------------------------------ random read
464 for ( i = 0 ; i < 1000 ; i++ ) 464 for ( i = 0 ; i < 1000 ; i++ )
465 { 465 {
466 len = rand() % 120 + 8; 466 len = rand() % 120 + 8;
467 pos = rand() % ( FILE_SIZE / BUFF_SIZE - BUFF_SIZE ); 467 pos = rand() % ( FILE_SIZE / BUFF_SIZE - BUFF_SIZE );
468 readFile.at( pos ); 468 readFile.at( pos );
469 r_len = readFile.readBlock( FileBuf, len ); 469 r_len = readFile.readBlock( FileBuf, len );
470 if ( r_len != len ) 470 if ( r_len != len )
471 { 471 {
472 readFile.close(); 472 readFile.close();
473 readFile.remove(); 473 readFile.remove();
474 return ( false ); 474 return ( false );
475 } 475 }
476 } 476 }
477 readFile.close(); 477 readFile.close();
478 } 478 }
479 return ( true ); 479 return ( true );
480} 480}