author | mickeyl <mickeyl> | 2004-04-07 10:32:54 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-04-07 10:32:54 (UTC) |
commit | 364971c08f3d761102daab01889b9fab394f8f08 (patch) (side-by-side diff) | |
tree | 1004de1b8fa1dc8d96f9a559f6e30d7bac32849a | |
parent | 9b1f8d08db8d533ac59975a8badd25e587c2239c (diff) | |
download | opie-364971c08f3d761102daab01889b9fab394f8f08.zip opie-364971c08f3d761102daab01889b9fab394f8f08.tar.gz opie-364971c08f3d761102daab01889b9fab394f8f08.tar.bz2 |
remove bogus '(const char*)' in debug statements
-rw-r--r-- | noncore/applets/zkbapplet/zkbwidget.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/keyz-cfg/zkb.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/keyz-cfg/zkbcfg.cpp | 4 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/configwindow.cpp | 8 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/mainwindow.cpp | 18 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/scanlist.cpp | 24 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/wellenreiter.cpp | 58 | ||||
-rw-r--r-- | noncore/settings/networksettings/wlan/wlanimp2.cpp | 4 | ||||
-rw-r--r-- | noncore/settings/sysinfo/benchmarkinfo.cpp | 2 |
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 @@ #include <opie2/otaskbarapplet.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/applnk.h> #include <qpe/qpeapplication.h> #include <qpe/resource.h> #include <stdio.h> #include <unistd.h> #include "zkbwidget.h" #include "zkbcfg.h" using namespace Opie::Ui; ZkbWidget::ZkbWidget(QWidget* parent):QLabel(parent),keymap(0), disabled(Resource::loadPixmap("zkb-disabled")) { labels = new QPopupMenu(); connect(labels, SIGNAL(activated(int)), this, SLOT(labelChanged(int))); loadKeymap(); channel = new QCopChannel("QPE/zkb", this); connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), this, SLOT(signalReceived(const QCString&,const QByteArray&))); setFixedWidth ( AppLnk::smallIconSize() ); setFixedHeight ( AppLnk::smallIconSize() ); } ZkbWidget::~ZkbWidget() { } int ZkbWidget::position() { return 8; } bool ZkbWidget::loadKeymap() { ZkbConfig c(QPEApplication::qpeDir()+"/share/zkb"); QFontMetrics fm(font()); if (keymap != 0) { delete keymap; keymap = 0; } Keymap* km = new Keymap(); if (!c.load("zkb.xml", *km, "")) { delete km; setPixmap(disabled); return false; } connect(km, SIGNAL(stateChanged(const QString&)), this, SLOT(stateChanged(const QString&))); qwsServer->setKeyboardFilter(km); Keymap* oldkm = keymap; keymap = km; if (oldkm != 0) { delete oldkm; } setText(keymap->getCurrentLabel()); labels->clear(); QStringList l = keymap->listLabels(); labels->insertItem(disabled, 0, 0); int n = 1; w = 0; for(QStringList::Iterator it = l.begin(); it != l.end(); ++it, n++) { // printf("label: %s\n", (const char*) (*it).utf8()); labels->insertItem(*it, n, n); int lw = fm.width(*it); if (lw > w) { w = lw; } } if (w == 0) { hide(); } else { show(); } return true; } QSize ZkbWidget::sizeHint() const { return QSize(AppLnk::smallIconSize(),AppLnk::smallIconSize()); } void ZkbWidget::stateChanged(const QString& s) { -// odebug << "stateChanged: " << (const char*) s.utf8() << "\n" << oendl; +// odebug << "stateChanged: " << s.utf8() << "\n" << oendl; setText(s); } void ZkbWidget::labelChanged(int id) { if (id == 0) { keymap->disable(); setPixmap(disabled); return; } keymap->enable(); QStringList l = keymap->listLabels(); QString lbl = l[id-1]; // printf("labelChanged: %s\n", (const char*) lbl.utf8()); State* state = keymap->getStateByLabel(lbl); if (state != 0) { keymap->setCurrentState(state); setText(lbl); } } void ZkbWidget::mouseReleaseEvent(QMouseEvent*) { QSize sh = labels->sizeHint(); QPoint p = mapToGlobal(QPoint((width()-sh.width())/2,-sh.height())); labels->exec(p); } void ZkbWidget::signalReceived(const QCString& msg, const QByteArray& data) { QDataStream stream(data, IO_ReadOnly); if (msg == "enable()") { keymap->enable(); } else if (msg == "disable()") { keymap->disable(); } else if (msg == "reload()") { QCopEnvelope("QPE/System", "busy()"); QTimer::singleShot(0, this, SLOT(reload())); } else if (msg == "switch(QString)") { QString lbl; stream >> lbl; if (keymap != 0) { State* state = keymap->getStateByLabel(lbl); if (state != 0) { keymap->setCurrentState(state); setText(lbl); } } } else if (msg == "debug(QString)") { QString flag; stream >> flag; } } void ZkbWidget::reload() { loadKeymap(); QCopEnvelope("QPE/System", "notBusy()"); } EXPORT_OPIE_APPLET_v1( ZkbWidget ) 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 @@ #include "zkb.h" #include <stdio.h> // Implementation of Action class Action::Action():state(0), keycode(0), unicode(0), flags(0) { } Action::Action(State* s, ushort kc, ushort uni, int f): state(s), keycode(kc), unicode(uni), flags(f) { } Action::~Action() { } State* Action::getState() const { return state; } void Action::setState(State* s) { state = s; setDefined(true); } bool Action::hasEvent() const { return flags & Event; } void Action::setEvent(bool e) { flags = (flags & ~Event) | ((e) ? Event : 0); if (e) { setDefined(true); } else { if (state == 0) { setDefined(false); } } } bool Action::isDefined() const { return flags & Defined; } void Action::setDefined(bool d) { flags = (flags & ~Defined) | ((d) ? Defined : 0); } int Action::getKeycode() const { return keycode; } void Action::setKeycode(int c) { keycode = (ushort) c; setEvent(true); } int Action::getUnicode() const { return unicode; } void Action::setUnicode(int u) { unicode = (ushort) u; setEvent(true); } int Action::getModifiers() const { int ret = 0; if (flags & Shift_Mod) { ret |= Qt::ShiftButton; } if (flags & Ctrl_Mod) { ret |= Qt::ControlButton; } if (flags & Alt_Mod) { ret |= Qt::AltButton; } if (flags & Keypad_Mod) { ret |= Qt::Keypad; } return ret; } void Action::setModifiers(int m) { int n = 0; if (m & Qt::ShiftButton) { n |= Shift_Mod; } if (m & Qt::ControlButton) { n |= Ctrl_Mod; } if (m & Qt::AltButton) { n |= Alt_Mod; } if (m & Qt::Keypad) { n |= Keypad_Mod; } flags = flags & ~Mod_Bits | n; setEvent(true); } bool Action::isPressed() const { return (flags & Press) != 0; } void Action::setPressed(bool p) { flags = (flags & ~Press) | ((p) ? Press : 0); setEvent(true); } bool Action::isAutorepeat() const { return (flags & Autorepeat) != 0; } void Action::setAutorepeat(bool p) { flags = (flags & ~Autorepeat) | ((p) ? Autorepeat : 0); setEvent(true); } // Implementation of State class const short State::x1[] = { /* from 0x20 to 0x5f */ 31, 0, 28, 3, 5, 6, 9, 28, /* 0x20 - 0x27 */ 11, 26, 10, 13, 26, 1, 29, 27, /* 0x28 - 0x2f */ 15, 16, 22, 4, 17, 19, 24, 20, /* 0x30 - 0x37 */ 8, 14, 29, 26, 29, 12, 32, 27, /* 0x38 - 0x3f */ 18, 0, 1, 2, 3, 4, 5, 6, /* 0x40 - 0x47 */ 7, 8, 9, 10, 11, 12, 13, 14, /* 0x48 - 0x4f */ 15, 16, 17, 18, 19, 20, 21, 22, /* 0x50 - 0x57 */ 23, 24, 25, 30, -1, 26, 28, 7, /* 0x58 - 0x5f */ 31, -1, -1, -1, -1, -1, -1, -1, /* 0x60 - 0x67 */ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x68 - 0x6f */ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70 - 0x77 */ -1, -1, -1, 29, 31, 32, 32, 28, /* 0x78 - 0x7f */ }; const short State::x2[] = { /* from 0x1000 to 0x1057*/ 42, 36, -1, 30, 32, -1, -1, -1, /* 0x1000 - 0x1007 */ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1008 - 0x100f */ -1, -1, 44, 45, 46, 47, -1, -1, /* 0x1010 - 0x1017 */ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1018 - 0x101f */ 33, 35, 34, -1, 36, 27, -1, -1, /* 0x1020 - 0x1027 */ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1028 - 0x102f */ -1, -1, -1, -1, -1, -1, -1, -1, /* 0x1030 - 0x1037 */ 37, 38, 40, 39, 41, -1, -1, -1, /* 0x1038 - 0x103f */ -1, -1, -1, -1, -1, 35, -1, -1, /* 0x1040 - 0x1047 */ -1, -1, -1, -1, -1, 48, -1, -1, /* 0x1048 - 0x104f */ 43, 49, 50, -1, -1, -1, -1, -1, /* 0x1050 - 0x1057 */ }; State::State(State* p):parent(p), keys(0) { keys = new Action[Key_Max * 2 + 1]; } State::State(const State& s) { parent = s.parent; keys = new Action[Key_Max * 2 + 1]; memcpy(keys, s.keys, sizeof(Action) * (Key_Max * 2 + 1)); } State::~State() { if (keys!=0) { delete [] keys; } } Action* State::get(int keycode, bool pressed, bool follow) const { Action* ret = 0; int n = translateKeycode(keycode); if (n != -1 && keys != 0) { if (pressed) { n += Key_Max; } ret = &keys[n]; } if (ret==0 || !ret->isDefined()) { if (follow && parent!=0) { ret = parent->get(keycode, pressed, follow); } } return ret; } bool State::set(int keycode, bool pressed, Action& action) { int n = translateKeycode(keycode); if (n==-1 || keys==0) { return false; } if (pressed) { n += Key_Max + 1; } keys[n] = action; return true; } State* State::getParent() const { return parent; } void State::setParent(State* s) { parent = s; } int State::translateKeycode(int keycode) const { if (keycode < 0x20) { return -1; } if (keycode < 0x80) { return x1[keycode - 0x20]; } if (keycode < 0x1000) { return -1; } if (keycode < 0x1057) { return x2[keycode - 0x1000]; } return -1; } // Implementation of Keymap class Keymap::Keymap():enabled(true), currentState(0), autoRepeatAction(0), repeater(this) { repeatDelay=400; repeatPeriod=80; connect(&repeater, SIGNAL(timeout()), this, SLOT(autoRepeat())); } Keymap::~Keymap() { QMap<QString, State*>::Iterator it; for(it = states.begin(); it != states.end(); ++it) { delete it.data(); } states.clear(); } bool Keymap::filter(int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat) { qDebug("filter: >>> unicode=%x, keycode=%x, modifiers=%x, " "ispressed=%x\n", unicode, keycode, modifiers, isPress); if (!enabled) { return false; } // the second check is workaround to make suspend work if // the user pressed it right after he did resume. for some // reason the event sent by qt has autoRepeat true in this // case if (autoRepeat && keycode != 4177) { return true; } (void) unicode; (void) modifiers; Action* action = currentState->get(keycode, isPress, true); if (action==0 || !action->isDefined()) { return true; } if (action->hasEvent()) { qDebug("filter:<<< unicode=%x, keycode=%x, modifiers=%x, " "ispressed=%x\n", action->getUnicode(), action->getKeycode(), action->getModifiers(), action->isPressed()); QWSServer::sendKeyEvent(action->getUnicode(), action->getKeycode(), action->getModifiers(), action->isPressed(), false); } if (action->isAutorepeat()) { autoRepeatAction = action; repeater.start(repeatDelay, TRUE); } else { autoRepeatAction = 0; } State* nstate = action->getState(); if (nstate != 0) { setCurrentState(nstate); QString lbl = getCurrentLabel(); if (!lbl.isEmpty()) { emit stateChanged(lbl); } } return true; } void Keymap::enable() { enabled = true; } void Keymap::disable() { enabled = false; } QStringList Keymap::listStates() { QStringList ret; QMap<QString, State*>::Iterator it; for(it = states.begin(); it != states.end(); ++it) { ret.append(it.key()); } return ret; } State* Keymap::getStateByName(const QString& name) { QMap<QString, State*>::Iterator it = states.find(name); if (it == states.end()) { return 0; } return it.data(); } QStringList Keymap::listLabels() { QStringList ret; for(uint i = 0; i < labelList.count(); i++) { ret.append(*labelList.at(i)); } return ret; } State* Keymap::getStateByLabel(const QString& label) { QMap<QString, QString>::Iterator lit = labels.find(label); State* state = 0; if (lit == labels.end()) { return 0; } QString name = lit.data(); int n = name.find(":*"); if (n>=0 && n==(int)(name.length()-2)) { name=name.left(name.length() - 1); n = currentStateName.findRev(":"); if (n >= 0) { name += currentStateName.mid(n+1); } } -// odebug << "look for: " << (const char*) name.utf8() << "\n" << oendl; +// odebug << "look for: " << name.utf8() << "\n" << oendl; QMap<QString, State*>::Iterator sit = states.find(name); if (sit != states.end()) { state = sit.data(); } return state; } bool Keymap::addState(const QString& name, State* state) { if (states.find(name) != states.end()) { return false; } states.insert(name, state); lsmapInSync = false; if (currentState == 0) { setCurrentState(state); } return true; } State* Keymap::getCurrentState() const { return currentState; } QString Keymap::getCurrentLabel() { return currentLabel; } bool Keymap::setCurrentState(State* state) { QMap<QString, State*>::Iterator it; for(it = states.begin(); it != states.end(); ++it) { State* s = it.data(); if (s == state) { currentState = s; currentStateName = it.key(); qDebug("state changed: %s\n", (const char*) currentStateName.utf8()); if (!lsmapInSync) { generateLabelStateMaps(); } QMap<State*, QString>::Iterator tit; tit = stateLabelMap.find(state); if (tit != stateLabelMap.end()) { currentLabel = tit.data(); } else { // odebug << "no label for: " + currentStateName + "\n" << oendl; currentLabel = ""; } return true; } } return false; } bool Keymap::removeState(const QString& name, bool force) { QMap<QString, State*>::Iterator it = states.find(name); if (it == states.end()) { return false; } State* state = it.data(); QList<Action> acts = findStateUsage(state); if (!acts.isEmpty()) { if (!force) { return false; } else { for(Action* a = acts.first(); a != 0; a = acts.next()) { a->setState(0); } } } if (state == currentState) { if (states.begin() != states.end()) { setCurrentState(states.begin().data()); } } states.remove(it); delete state; lsmapInSync = false; return true; } void Keymap::autoRepeat() { if (autoRepeatAction != 0) { qDebug("filter:<<< unicode=%x, keycode=%x, modifiers=%x, " "ispressed=%x\n", autoRepeatAction->getUnicode(), autoRepeatAction->getKeycode(), autoRepeatAction->getModifiers(), autoRepeatAction->isPressed()); QWSServer::sendKeyEvent(autoRepeatAction->getUnicode(), autoRepeatAction->getKeycode(), autoRepeatAction->getModifiers(), autoRepeatAction->isPressed(), true); } repeater.start(repeatPeriod, TRUE); } bool Keymap::addLabel(const QString& label, const QString& state, int index) { if (labels.find(label) != labels.end()) { return false; } labels.insert(label, state); const QString& l = labels.find(label).key(); if (index == -1) { labelList.append(l); } else { labelList.insert(labelList.at(index), l); } lsmapInSync = false; return true; } bool Keymap::removeLabel(const QString& label) { if (labels.find(label) == labels.end()) { return false; } labels.remove(label); labelList.remove(label); lsmapInSync = false; if (label == currentLabel) { currentLabel = ""; } return true; } int Keymap::getAutorepeatDelay() const { return repeatDelay; } void Keymap::setAutorepeatDelay(int n) { repeatDelay = n; } int Keymap::getAutorepeatPeriod() const { return repeatPeriod; } void Keymap::setAutorepeatPeriod(int n) { repeatPeriod = n; } QList<Action> Keymap::findStateUsage(State* s) { QList<Action> ret; QMap<QString, State*>::Iterator it; for(it = states.begin(); it != states.end(); ++it) { State* state = it.data(); for(int i = 0; i < 0x1100; i++) { Action* action = state->get(i, false); if (action!=0 && action->getState()==s) { ret.append(action); } action = state->get(i, true); if (action!=0 && action->getState()==s) { ret.append(action); } } } return ret; } void Keymap::generateLabelStateMaps() { stateLabelMap.clear(); QMap<QString, QString>::Iterator lit; for(lit = labels.begin(); lit != labels.end(); ++lit) { QString label = lit.key(); QString name = lit.data(); bool wc = false; int n = name.find("*"); if (n>=0 && n==(int)(name.length()-1)) { name=name.left(name.length() - 1); wc = true; } QMap<QString, State*>::Iterator sit; for(sit = states.begin(); sit != states.end(); ++sit) { QString sname = sit.key(); State* state = sit.data(); if (sname.length() < name.length()) { continue; } if (sname.left(name.length()) == name) { if (wc || sname.length()==name.length()) { stateLabelMap.insert(state, label); } } } } lsmapInSync = true; } 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 @@ #include "zkbcfg.h" /* OPIE */ #include <opie2/odebug.h> using namespace Opie::Core; /* QT */ #include <qfileinfo.h> // Implementation of XkbConfig class ZkbConfig::ZkbConfig(const QString& dir):path(dir) { } ZkbConfig::~ZkbConfig() { } bool ZkbConfig::load(const QString& file, Keymap& keymap, const QString& prefix) { bool ret; QFile f(path+"/"+file); QFileInfo fi(f); - odebug << "start loading file=" << (const char*) file.utf8() << "\n" << oendl; + odebug << "start loading file=" << file.utf8() << "\n" << oendl; if (includedFiles.find(fi.absFilePath()) != includedFiles.end()) { return false; } includedFiles.insert(fi.absFilePath(), 1); QXmlInputSource is(f); QXmlSimpleReader reader; ZkbHandler h(*this, keymap, prefix); reader.setContentHandler(&h); reader.setErrorHandler(this); ret = reader.parse(is); includedFiles.remove(fi.absFilePath()); odebug << "end loading file=" << file.utf8() << ": status=" << err.utf8() << oendl; return ret; } bool ZkbConfig::warning(const QXmlParseException& e) { QString tmp; tmp.sprintf("%d: warning: %s\n", e.lineNumber(), (const char*) e.message().utf8()); err += tmp; return true; } bool ZkbConfig::error(const QXmlParseException& e) { QString tmp; tmp.sprintf("%d: error: %s\n", e.lineNumber(), (const char*) e.message().utf8()); err += tmp; return true; } bool ZkbConfig::fatalError(const QXmlParseException& e) { QString tmp; tmp.sprintf("%d: fatal error: %s\n", e.lineNumber(), (const char*) e.message().utf8()); err += tmp; return false; } QString ZkbConfig::errorString() { return err; } // Implementation of ZkbHandler ZkbHandler::ZkbHandler(ZkbConfig& z, Keymap& k, const QString& p):zkc(z), keymap(k), prefix(p), ardelay(-1), arperiod(-1), currentState(0), currentAction(0) { } ZkbHandler::~ZkbHandler() { } bool ZkbHandler::startKeymapElement(int ard, int arp, const QString&) { ardelay = ard; arperiod = arp; return true; } bool ZkbHandler::startIncludeElement(const QString& file, const QString& pref) { QString p = prefix; if (!pref.isNull()) { p += pref + ":"; } bool ret = zkc.load(file, keymap, p); if (!ret) { setError("Error including file: " + file); } return ret; } bool ZkbHandler::startLabelElement(const QString& label, const QString& state) { if (!keymap.addLabel(label, prefix + state)) { err = "label " + label + " already defined"; return false; } return true; } bool ZkbHandler::startStateElement(const QString& name, const QString& parentName, bool dflt) { currentStateName = prefix + name; currentState = keymap.getStateByName(currentStateName); -// odebug << "state name=" << (const char*) currentStateName.utf8() << "\n" << oendl; +// odebug << "state name=" << currentStateName.utf8() << "\n" << oendl; State* parent = 0; if (!parentName.isEmpty()) { QString pn = prefix + parentName; parent = keymap.getStateByName(pn); if (parent == 0) { err = currentStateName + ": undefined parent state: " + pn; return false; } } if (currentState == 0) { currentState = new State(parent); keymap.addState(currentStateName, currentState); } else { if (parent!=0) { currentState->setParent(parent); } } if (dflt) { keymap.setCurrentState(currentState); } return true; } bool ZkbHandler::startMapElement(int keycode, bool pressed) { currentAction = currentState->get(keycode, pressed); if (currentAction == 0) { setError("keycode " + QString::number(keycode) + " not supported"); return false; } currentAction->setEvent(false); currentAction->setState(0); return true; } bool ZkbHandler::startEventElement(int keycode, int unicode, int modifiers, bool pressed, bool autorepeat) { currentAction->setEvent(true); currentAction->setKeycode(keycode); currentAction->setUnicode(unicode); currentAction->setModifiers(modifiers); currentAction->setPressed(pressed); currentAction->setAutorepeat(autorepeat); return true; } bool ZkbHandler::startNextStateElement(const QString& state) { State* s = keymap.getStateByName(prefix + state); if (s == 0) { setError("undefine state: " + prefix + state); return false; } currentAction->setState(s); return true; } bool ZkbHandler::endKeymapElement() { if (ardelay > 0) { keymap.setAutorepeatDelay(ardelay); } if (arperiod > 0) { keymap.setAutorepeatPeriod(arperiod); } return true; } bool ZkbHandler::endIncludeElement() { return true; } bool ZkbHandler::endLabelElement() { return true; } bool ZkbHandler::endStateElement() { currentState = 0; return true; } bool ZkbHandler::endMapElement() { currentAction = 0; return true; } bool ZkbHandler::endEventElement() { return true; } bool ZkbHandler::endNextStateElement() { return true; } 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 @@ /********************************************************************** ** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved. ** ** This file is part of Wellenreiter II. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** **********************************************************************/ /* LOCAL */ #include "configwindow.h" #include "mainwindow.h" /* OPIE */ #include <opie2/onetwork.h> #ifdef QWS #include <opie2/oapplication.h> #include <opie2/oconfig.h> #include <opie2/odevice.h> #include <opie2/odebug.h> using namespace Opie::Core; using namespace Opie::Net; #endif /* QT */ #include <qapplication.h> #include <qcheckbox.h> #include <qcombobox.h> #include <qfile.h> #include <qlineedit.h> #include <qlayout.h> #include <qmap.h> #include <qpushbutton.h> #include <qtabwidget.h> #include <qtoolbutton.h> #include <qspinbox.h> #include <qtextstream.h> /* STD */ #include <assert.h> WellenreiterConfigWindow* WellenreiterConfigWindow::_instance = 0; WellenreiterConfigWindow::WellenreiterConfigWindow( QWidget * parent, const char * name, WFlags f ) :WellenreiterConfigBase( parent, name, true, f ) { _devicetype[ "cisco" ] = DEVTYPE_CISCO; _devicetype[ "wlan-ng" ] = DEVTYPE_WLAN_NG; _devicetype[ "hostap" ] = DEVTYPE_HOSTAP; _devicetype[ "orinoco" ] = DEVTYPE_ORINOCO; _devicetype[ "<manual>" ] = DEVTYPE_MANUAL; _devicetype[ "<file>" ] = DEVTYPE_FILE; // gather possible interface names from ONetwork ONetwork* net = ONetwork::instance(); ONetwork::InterfaceIterator it = net->iterator(); while ( it.current() ) { if ( it.current()->isWireless() ) interfaceName->insertItem( it.current()->name() ); ++it; } load(); #ifdef Q_WS_X11 // We're on X11: adding an Ok-Button for the Dialog here QPushButton* okButton = new QPushButton( "ok", this ); okButton->show(); WellenreiterConfigBaseLayout->addWidget( okButton, 0, 3 ); //FIXME: rename this in configbase.ui connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); #endif WellenreiterConfigWindow::_instance = this; connect( deviceType, SIGNAL( activated(int) ), this, SLOT( changedDeviceType(int) ) ); connect( newNetworkAction, SIGNAL( activated(int) ), this, SLOT( changedNetworkAction(int) ) ); connect( newClientAction, SIGNAL( activated(int) ), this, SLOT( changedClientAction(int) ) ); connect( newStationAction, SIGNAL( activated(int) ), this, SLOT( changedStationAction(int) ) ); connect( getCaptureFileName, SIGNAL( clicked() ), this, SLOT( getCaptureFileNameClicked() ) ); // make the checkbox 'channelAll' control all other channels connect( channelAll, SIGNAL( stateChanged(int) ), this, SLOT( channelAllClicked(int) ) ); connect( autodetect, SIGNAL( clicked() ), this, SLOT( performAutodetection() ) ); // hide tab4 (parse) until Wellenreiter 1.2 tab->removePage( tab_4 ); }; void WellenreiterConfigWindow::accept() { save(); QDialog::accept(); } WellenreiterConfigWindow::~WellenreiterConfigWindow() { } void WellenreiterConfigWindow::performAutodetection() { //TODO: insert modal splash screen here // and sleep a second, so that it looks // like we're actually doing something fancy... ;-) odebug << "WellenreiterConfigWindow::performAutodetection()" << oendl; // try to guess device type QFile m( "/proc/modules" ); if ( m.open( IO_ReadOnly ) ) { int devicetype(0); QString line; QTextStream modules( &m ); while( !modules.atEnd() && !devicetype ) { modules >> line; if ( line.contains( "cisco" ) ) devicetype = DEVTYPE_CISCO; else if ( line.contains( "hostap" ) ) devicetype = DEVTYPE_HOSTAP; else if ( line.contains( "prism" ) ) devicetype = DEVTYPE_WLAN_NG; else if ( line.contains( "orinoco" ) ) devicetype = DEVTYPE_ORINOCO; } if ( devicetype ) { deviceType->setCurrentItem( devicetype ); _guess = devicetype; odebug << "Wellenreiter: guessed device type to be #" << devicetype << "" << oendl; } } } int WellenreiterConfigWindow::driverType() const { QString name = deviceType->currentText(); if ( _devicetype.contains( name ) ) { return _devicetype[name]; } else { return 0; } }; int WellenreiterConfigWindow::hoppingInterval() const { return hopInterval->cleanText().toInt(); } bool WellenreiterConfigWindow::usePrismHeader() const { return prismHeader->isChecked(); } bool WellenreiterConfigWindow::isChannelChecked( int channel ) const { switch ( channel ) { case 1: return channel1->isOn(); case 2: return channel2->isOn(); case 3: return channel3->isOn(); case 4: return channel4->isOn(); case 5: return channel5->isOn(); case 6: return channel6->isOn(); case 7: return channel7->isOn(); case 8: return channel8->isOn(); case 9: return channel9->isOn(); case 10: return channel10->isOn(); case 11: return channel11->isOn(); case 12: return channel12->isOn(); case 13: return channel13->isOn(); case 14: return channel14->isOn(); } } void WellenreiterConfigWindow::changedDeviceType(int t) { if ( t != DEVTYPE_FILE ) return; QString name = ( (WellenreiterMainWindow*) qApp->mainWidget() )->getFileName(false); if ( !name.isEmpty() && QFile::exists( name ) ) { interfaceName->insertItem( name ); interfaceName->setCurrentItem( interfaceName->count()-1 ); } else { deviceType->setCurrentItem( _guess ); } } void WellenreiterConfigWindow::synchronizeActionsAndScripts() { if ( newNetworkAction->currentItem() == 4 ) newNetworkScript->show(); else newNetworkScript->hide(); if ( newClientAction->currentItem() == 4 ) newClientScript->show(); else newClientScript->hide(); if ( newStationAction->currentItem() == 4 ) newStationScript->show(); else newStationScript->hide(); //newNetworkScript->setEnabled( newNetworkAction->currentItem() == 4 ); //newClientScript->setEnabled( newClientAction->currentItem() == 4 ); //newStationScript->setEnabled( newStationAction->currentItem() == 4 ); } void WellenreiterConfigWindow::changedNetworkAction(int t) { synchronizeActionsAndScripts(); } void WellenreiterConfigWindow::changedClientAction(int t) { synchronizeActionsAndScripts(); } void WellenreiterConfigWindow::changedStationAction(int t) { synchronizeActionsAndScripts(); } void WellenreiterConfigWindow::getCaptureFileNameClicked() { QString name = ( (WellenreiterMainWindow*) qApp->mainWidget() )->getFileName(true); - odebug << "name = " << (const char*) name << "" << oendl; + odebug << "name = " << name << "" << oendl; if ( !name.isEmpty() ) { captureFileName->setText( name ); } } void WellenreiterConfigWindow::channelAllClicked(int state) { bool b = state; channel1->setChecked( b ); channel2->setChecked( b ); channel3->setChecked( b ); channel4->setChecked( b ); channel5->setChecked( b ); channel6->setChecked( b ); channel7->setChecked( b ); channel8->setChecked( b ); channel9->setChecked( b ); channel10->setChecked( b ); channel11->setChecked( b ); channel12->setChecked( b ); channel13->setChecked( b ); channel14->setChecked( b ); } bool WellenreiterConfigWindow::useGPS() const { return enableGPS->isChecked(); } const QString WellenreiterConfigWindow::gpsHost() const { return useGPS() ? gpsdHost->currentText() : QString::null; } int WellenreiterConfigWindow::gpsPort() const { bool ok; return useGPS() ? gpsdPort->value() : -1; } void WellenreiterConfigWindow::performAction( const QString& type, const QString& essid, const QString& mac, bool wep, int channel, int signal /* , const GpsLocation& loc */ ) { int action; QString script; if ( type == "network" ) { action = newNetworkAction->currentItem(); script = newNetworkScript->text(); } else if ( type == "managed" || type == "adhoc" ) { action = newClientAction->currentItem(); script = newClientScript->text(); } else if ( type == "station" ) { action = newStationAction->currentItem(); script = newStationScript->text(); } else { - owarn << "WellenreiterConfigWindow::performAction(): unknown type '" << (const char*) type << "'" << oendl; + owarn << "WellenreiterConfigWindow::performAction(): unknown type '" << type << "'" << oendl; return; } - odebug << "for event '" << (const char*) type << "' I'm going to perform action " << action << " (script='" << (const char*) script << "')" << oendl; + odebug << "for event '" << (const char*) type << "' I'm going to perform action " << action << " (script='" << script << "')" << oendl; switch( action ) { case 0: /* Ignore */ return; case 1: /* Play Alarm */ ODevice::inst()->playAlarmSound(); return; case 2: /* Play Click */ ODevice::inst()->playTouchSound(); return; case 3: /* Blink LED */ break; //FIXME: Implement this case 4: /* Run Script */ { /** * * Script Substitution Information: * * $SSID = SSID * $MAC = MAC * $WEP = Wep * $CHAN = Channel * **/ script = script.replace( QRegExp( "$SSID" ), essid ); script = script.replace( QRegExp( "$MAC" ), mac ); script = script.replace( QRegExp( "$WEP" ), wep ? QString( "true" ) : QString( "false" ) ); script = script.replace( QRegExp( "$CHAN" ), QString::number( channel ) ); - odebug << "going to call script '" << (const char*) script << "'" << oendl; + odebug << "going to call script '" << script << "'" << oendl; ::system( script ); odebug << "script returned." << oendl; return; } default: assert( false ); } } void WellenreiterConfigWindow::load() { #ifdef Q_WS_X11 #warning Persistent Configuration not yet implemented for standalone X11 build performAutodetection(); #else odebug << "loading configuration settings..." << oendl; /* This is dumb monkey typing stuff... We _need_ to do this automatically! */ OConfig* c = oApp->config(); c->setGroup( "Interface" ); QString interface = c->readEntry( "name", "<none>" ); if ( interface != "<none>" ) { #if QT_VERSION < 300 interfaceName->insertItem( interface, 0 ); interfaceName->setCurrentItem( 0 ); #else interfaceName->setCurrentText( interface ); #endif QString device = c->readEntry( "type", "<select>" ); #if QT_VERSION < 300 for ( int i = 0; i < deviceType->count(); ++i ) { if ( deviceType->text( i ) == device ) { deviceType->setCurrentItem( i ); break; } } #else deviceType->setCurrentText( device ); #endif } else { performAutodetection(); } prismHeader->setChecked( c->readBoolEntry( "prism", false ) ); hopChannels->setChecked( c->readBoolEntry( "hop", true ) ); hopInterval->setValue( c->readNumEntry( "interval", 250 ) ); adaptiveHopping->setChecked( c->readBoolEntry( "adaptive", true ) ); c->setGroup( "Capture" ); captureFileName->setText( c->readEntry( "filename", "/tmp/capture" ) ); c->setGroup( "UI" ); lookupVendor->setChecked( c->readBoolEntry( "lookupVendor", true ) ); openTree->setChecked( c->readBoolEntry( "openTree", true ) ); disablePM->setChecked( c->readBoolEntry( "disablePM", true ) ); newNetworkAction->setCurrentItem( c->readNumEntry( "newNetworkAction", 1 ) ); // Default: Play Alarm newNetworkScript->setText( c->readEntry( "newNetworkScript", "" ) ); newClientAction->setCurrentItem( c->readNumEntry( "newClientAction", 2 ) ); // Default: Play Click newClientScript->setText( c->readEntry( "newClientScript", "" ) ); newStationAction->setCurrentItem( c->readNumEntry( "newStationAction", 2 ) ); // Default: Play Click newStationScript->setText( c->readEntry( "newStationScript", "" ) ); synchronizeActionsAndScripts(); // needed for showing/hiding the script QLineEdit on demand c->setGroup( "GPS" ); enableGPS->setChecked( c->readBoolEntry( "use", false ) ); #if QT_VERSION < 300 gpsdHost->insertItem( c->readEntry( "host", "localhost" ), 0 ); gpsdHost->setCurrentItem( 0 ); #else gpsdHost->setCurrentText( c->readEntry( "host", "localhost" ) ); #endif gpsdPort->setValue( c->readNumEntry( "port", 2947 ) ); startGPS->setChecked( c->readBoolEntry( "start", false ) ); commandGPS->setText( c->readEntry( "command", "gpsd -p /dev/ttyS3 -s 57600" ) ); #endif } void WellenreiterConfigWindow::save() { #ifdef Q_WS_X11 #warning Persistent Configuration not yet implemented for standalone X11 build #else odebug << "saving configuration settings..." << oendl; /* This is dumb monkey typing stuff... We _need_ to do this automatically! */ OConfig* c = oApp->config(); c->setGroup( "Interface" ); c->writeEntry( "name", interfaceName->currentText() ); c->writeEntry( "type", deviceType->currentText() ); c->writeEntry( "prism", prismHeader->isChecked() ); c->writeEntry( "hop", hopChannels->isChecked() ); c->writeEntry( "interval", hopInterval->value() ); c->writeEntry( "adaptive", adaptiveHopping->isChecked() ); c->setGroup( "Capture" ); c->writeEntry( "filename", captureFileName->text() ); c->setGroup( "UI" ); c->writeEntry( "lookupVendor", lookupVendor->isChecked() ); c->writeEntry( "openTree", openTree->isChecked() ); c->writeEntry( "disablePM", disablePM->isChecked() ); c->writeEntry( "newNetworkAction", newNetworkAction->currentItem() ); c->writeEntry( "newNetworkScript", newNetworkScript->text() ); c->writeEntry( "newClientAction", newClientAction->currentItem() ); c->writeEntry( "newClientScript", newClientScript->text() ); c->writeEntry( "newStationAction", newStationAction->currentItem() ); c->writeEntry( "newStationScript", newStationScript->text() ); c->setGroup( "GPS" ); c->writeEntry( "use", enableGPS->isChecked() ); c->writeEntry( "host", gpsdHost->currentText() ); c->writeEntry( "port", gpsdPort->value() ); c->writeEntry( "start", startGPS->isChecked() ); c->writeEntry( "command", commandGPS->text() ); c->write(); #endif } 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 @@ /********************************************************************** ** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved. ** ** This file is part of Wellenreiter II. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** **********************************************************************/ #include "configwindow.h" #include "gps.h" #include "logwindow.h" #include "packetview.h" #include "mainwindow.h" #include "wellenreiter.h" #include "scanlist.h" /* OPIE */ #ifdef QWS #include <qpe/resource.h> #include <opie2/odebug.h> #include <opie2/ofiledialog.h> #else #include "resource.h" #include <qapplication.h> #include <qfiledialog.h> #endif using namespace Opie::Core; using namespace Opie::Net; using namespace Opie::Ui; /* QT */ #include <qcombobox.h> #include <qdatastream.h> #include <qfile.h> #include <qfileinfo.h> #include <qlabel.h> #include <qlayout.h> #include <qlineedit.h> #include <qiconset.h> #include <qmenubar.h> #include <qmessagebox.h> #include <qpopupmenu.h> #include <qpushbutton.h> #include <qstatusbar.h> #include <qspinbox.h> #include <qtextstream.h> #include <qtoolbutton.h> #include <qwhatsthis.h> /* STD */ #include <unistd.h> WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * name, WFlags f ) :QMainWindow( parent, name, f ) { cw = new WellenreiterConfigWindow( this ); mw = new Wellenreiter( this ); mw->setConfigWindow( cw ); setCentralWidget( mw ); // setup application icon setIcon( Resource::loadPixmap( "wellenreiter/appicon-trans" ) ); #ifndef QWS setIconText( "Wellenreiter/X11" ); #endif // setup tool buttons startButton = new QToolButton( 0 ); QWhatsThis::add( startButton, tr( "Click here to start scanning." ) ); #ifdef QWS startButton->setAutoRaise( true ); #endif startButton->setIconSet( Resource::loadIconSet( "wellenreiter/SearchIcon" ) ); startButton->setEnabled( false ); connect( startButton, SIGNAL( clicked() ), mw, SLOT( startClicked() ) ); stopButton = new QToolButton( 0 ); QWhatsThis::add( stopButton, tr( "Click here to stop scanning." ) ); #ifdef QWS stopButton->setAutoRaise( true ); #endif stopButton->setIconSet( Resource::loadIconSet( "wellenreiter/CancelIcon" ) ); stopButton->setEnabled( false ); connect( stopButton, SIGNAL( clicked() ), mw, SLOT( stopClicked() ) ); QToolButton* d = new QToolButton( 0 ); QWhatsThis::add( d, tr( "Click here to open the configure dialog." ) ), #ifdef QWS d->setAutoRaise( true ); #endif d->setIconSet( Resource::loadIconSet( "wellenreiter/SettingsIcon" ) ); connect( d, SIGNAL( clicked() ), this, SLOT( showConfigure() ) ); uploadButton = new QToolButton( 0 ); QWhatsThis::add( uploadButton, tr( "Click here to upload a capture session." ) ); #ifdef QWS uploadButton->setAutoRaise( true ); #endif uploadButton->setIconSet( Resource::loadIconSet( "up" ) ); uploadButton->setEnabled( false ); //uploadButton->setEnabled( true ); // DEBUGGING connect( uploadButton, SIGNAL( clicked() ), this, SLOT( uploadSession() ) ); // setup menu bar int id; QMenuBar* mb = menuBar(); QPopupMenu* fileSave = new QPopupMenu( mb ); fileSave->insertItem( tr( "&Session..." ), this, SLOT( fileSaveSession() ) ); fileSave->insertItem( tr( "&Text Log..." ), this, SLOT( fileSaveLog() ) ); fileSave->insertItem( tr( "&Hex Log..." ), this, SLOT( fileSaveHex() ) ); QPopupMenu* fileLoad = new QPopupMenu( mb ); fileLoad->insertItem( tr( "&Session..." ), this, SLOT( fileLoadSession() ) ); //fileLoad->insertItem( "&Log", this, SLOT( fileLoadLog() ) ); QPopupMenu* file = new QPopupMenu( mb ); file->insertItem( tr( "&New" ), this, SLOT( fileNew() ) ); id = file->insertItem( tr( "&Load" ), fileLoad ); file->insertItem( tr( "&Save" ), fileSave ); file->insertSeparator(); uploadID = file->insertItem( tr( "&Upload Session" ), this, SLOT( uploadSession() ) ); file->insertSeparator(); file->insertItem( tr( "&Exit" ), qApp, SLOT( quit() ) ); QPopupMenu* sniffer = new QPopupMenu( mb ); sniffer->insertItem( tr( "&Configure..." ), this, SLOT( showConfigure() ) ); sniffer->insertSeparator(); startID = sniffer->insertItem( tr( "&Start" ), mw, SLOT( startClicked() ) ); sniffer->setItemEnabled( startID, false ); stopID = sniffer->insertItem( tr( "Sto&p" ), mw, SLOT( stopClicked() ) ); sniffer->setItemEnabled( stopID, false ); QPopupMenu* view = new QPopupMenu( mb ); view->insertItem( tr( "&Expand All" ), this, SLOT( viewExpandAll() ) ); view->insertItem( tr( "&Collapse All" ), this, SLOT( viewCollapseAll() ) ); QPopupMenu* demo = new QPopupMenu( mb ); demo->insertItem( tr( "&Add something" ), this, SLOT( demoAddStations() ) ); //demo->insertItem( tr( "&Read from GPSd" ), this, SLOT( demoReadFromGps() ) ); id = mb->insertItem( tr( "&File" ), file ); id = mb->insertItem( tr( "&View" ), view ); //mb->setItemEnabled( id, false ); id = mb->insertItem( tr( "&Sniffer" ), sniffer ); id = mb->insertItem( tr( "&Demo" ), demo ); mb->setItemEnabled( id, true ); mb->setItemEnabled( uploadID, false ); #ifdef QWS mb->insertItem( startButton ); mb->insertItem( stopButton ); mb->insertItem( uploadButton ); mb->insertItem( d ); #else // Qt3 changed the insertion order. It's now totally random :( mb->insertItem( d ); mb->insertItem( uploadButton ); mb->insertItem( stopButton ); mb->insertItem( startButton ); #endif updateToolButtonState(); // setup status bar (for now only on X11) #ifndef QWS statusBar()->message( tr( "Ready." ) ); #endif connect( mw, SIGNAL( startedSniffing() ), this, SLOT( changedSniffingState() ) ); connect( mw, SIGNAL( stoppedSniffing() ), this, SLOT( changedSniffingState() ) ); }; void WellenreiterMainWindow::showConfigure() { odebug << "show configure..." << oendl; cw->setCaption( tr( "Configure" ) ); int result = QPEApplication::execDialog( cw ); if ( result ) updateToolButtonState(); } void WellenreiterMainWindow::updateToolButtonState() { const QString& interface = cw->interfaceName->currentText(); const int cardtype = cw->driverType(); if ( ( interface != "<select>" ) && ( cardtype != 0 ) ) { startButton->setEnabled( true ); menuBar()->setItemEnabled( startID, true ); } else { startButton->setEnabled( false ); menuBar()->setItemEnabled( startID, false ); } } void WellenreiterMainWindow::changedSniffingState() { startButton->setEnabled( !mw->sniffing ); menuBar()->setItemEnabled( startID, !mw->sniffing ); stopButton->setEnabled( mw->sniffing ); menuBar()->setItemEnabled( stopID, mw->sniffing ); if ( !mw->sniffing ) { menuBar()->setItemEnabled( uploadID, true ); uploadButton->setEnabled( true ); } } WellenreiterMainWindow::~WellenreiterMainWindow() { odebug << "Wellenreiter: bye." << oendl; }; void WellenreiterMainWindow::demoAddStations() { //mw = 0; // test SIGSEGV handling mw->netView()->addNewItem( "managed", "Vanille", OMacAddress::fromString("00:00:20:EF:A6:43"), true, 6, 80, GpsLocation( 39.8794, -94.0936) ); mw->netView()->addNewItem( "managed", "Vanille", OMacAddress::fromString("00:30:6D:EF:A6:23"), true, 11, 10, GpsLocation( 0.0, 0.0 ) ); mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:03:F8:E7:16:22"), false, 3, 10, GpsLocation( 5.5, 2.3 ) ); mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:04:01:E7:56:62"), false, 3, 15, GpsLocation( 2.3, 5.5 ) ); mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:05:8E:E7:56:E2"), false, 3, 20, GpsLocation( -10.0, -20.5 ) ); } void WellenreiterMainWindow::demoReadFromGps() { WellenreiterConfigWindow* configwindow = WellenreiterConfigWindow::instance(); GPS* gps = new GPS( this ); - odebug << "Wellenreiter::demoReadFromGps(): url=gps://" << (const char*) configwindow->gpsdHost->currentText() << ":" << configwindow->gpsdPort->value() << "/" << oendl; + odebug << "Wellenreiter::demoReadFromGps(): url=gps://" << configwindow->gpsdHost->currentText() << ":" << configwindow->gpsdPort->value() << "/" << oendl; gps->open( configwindow->gpsdHost->currentText(), configwindow->gpsdPort->value() ); GpsLocation loc = gps->position(); QMessageBox::information( this, "Wellenreiter/Opie", tr( "GPS said:\n%1" ).arg( loc.dmsPosition() ) ); delete gps; } QString WellenreiterMainWindow::getFileName( bool save ) { QMap<QString, QStringList> map; map.insert( tr("All"), QStringList() ); QStringList text; text << "text/*"; map.insert( tr("Text"), text ); text << "*"; map.insert( tr("All"), text ); QString str; if ( save ) { #ifdef QWS str = OFileDialog::getSaveFileName( 2, "/", QString::null, map ); #else str = QFileDialog::getSaveFileName(); #endif if ( str.isEmpty() /*|| QFileInfo(str).isDir()*/ ) return ""; } else { #ifdef QWS str = OFileDialog::getOpenFileName( 2, "/", QString::null, map ); #else str = QFileDialog::getOpenFileName(); #endif if ( str.isEmpty() || !QFile(str).exists() || QFileInfo(str).isDir() ) return ""; } return str; } void WellenreiterMainWindow::fileSaveLog() { QString fname = getFileName( true ); if ( !fname.isEmpty() ) { QFile f( fname ); if ( f.open(IO_WriteOnly) ) { QTextStream t( &f ); t << mw->logWindow()->getLog(); f.close(); - odebug << "Saved log to file '" << (const char*) fname << "'" << oendl; + odebug << "Saved log to file '" << fname << "'" << oendl; } else { - odebug << "Problem saving log to file '" << (const char*) fname << "'" << oendl; + odebug << "Problem saving log to file '" << fname << "'" << oendl; } } } void WellenreiterMainWindow::fileSaveSession() { QString fname = getFileName( true ); if ( !fname.isEmpty() ) { QFile f( fname ); if ( f.open(IO_WriteOnly) ) { QDataStream t( &f ); t << *mw->netView(); f.close(); - odebug << "Saved session to file '" << (const char*) fname << "'" << oendl; + odebug << "Saved session to file '" << fname << "'" << oendl; } else { - odebug << "Problem saving session to file '" << (const char*) fname << "'" << oendl; + odebug << "Problem saving session to file '" << fname << "'" << oendl; } } } void WellenreiterMainWindow::fileSaveHex() { #warning DOES NOT WORK AT THE MOMENT /* QString fname = getFileName( true ); if ( !fname.isEmpty() ) { QFile f( fname ); if ( f.open(IO_WriteOnly) ) { QTextStream t( &f ); t << mw->hexWindow()->getLog(); f.close(); - odebug << "Saved hex log to file '" << (const char*) fname << "'" << oendl; + odebug << "Saved hex log to file '" << fname << "'" << oendl; } else { - odebug << "Problem saving hex log to file '" << (const char*) fname << "'" << oendl; + odebug << "Problem saving hex log to file '" << fname << "'" << oendl; } } */ } void WellenreiterMainWindow::fileLoadSession() { QString fname = getFileName( false ); if ( !fname.isEmpty() ) { QFile f( fname ); if ( f.open(IO_ReadOnly) ) { QDataStream t( &f ); t >> *mw->netView(); f.close(); - odebug << "Loaded session from file '" << (const char*) fname << "'" << oendl; + odebug << "Loaded session from file '" << fname << "'" << oendl; } else { - odebug << "Problem loading session from file '" << (const char*) fname << "'" << oendl; + odebug << "Problem loading session from file '" << fname << "'" << oendl; } } } void WellenreiterMainWindow::fileNew() { mw->netView()->clear(); mw->logWindow()->clear(); mw->hexWindow()->clear(); } void WellenreiterMainWindow::closeEvent( QCloseEvent* e ) { if ( mw->isDaemonRunning() ) { QMessageBox::warning( this, "Wellenreiter/Opie", tr( "Sniffing in progress!\nPlease stop sniffing before closing." ) ); e->ignore(); } else { QMainWindow::closeEvent( e ); } } static const char* CAP_hostname = "www.vanille.de"; #include <netdb.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> void WellenreiterMainWindow::uploadSession() { QLineEdit* from; QLineEdit* location; QLineEdit* comments; QPushButton* accept; QPushButton* reject; QDialog* d = new QDialog( 0, "session upload", true ); d->setCaption( tr( "Upload Session" ) ); QGridLayout* g = new QGridLayout( d, 4, 2, 3 ); g->addWidget( new QLabel( tr( "From: " ), d ), 0, 0 ); g->addWidget( from = new QLineEdit( d ), 0, 1 ); g->addWidget( new QLabel( tr( "Location: " ), d ), 1, 0 ); g->addWidget( location = new QLineEdit( d ), 1, 1 ); g->addWidget( new QLabel( tr( "Comments: " ), d ), 2, 0 ); g->addWidget( comments = new QLineEdit( d ), 2, 1 ); g->addWidget( accept = new QPushButton( tr( "&Ok" ), d ), 3, 0 ); g->addWidget( reject = new QPushButton( tr( "&Cancel" ), d ), 3, 1 ); accept->setDefault( true ); accept->setAutoDefault( true ); from->setText( "WL II User" ); location->setText( "WL II Location" ); comments->setText( "No Comments." ); connect( accept, SIGNAL( clicked() ), d, SLOT( accept() ) ); connect( reject, SIGNAL( clicked() ), d, SLOT( reject() ) ); int result = d->exec(); if ( !result ) { odebug << "Session upload cancelled :(" << oendl; return; } odebug << "Starting upload..." << oendl; struct sockaddr_in raddr; struct hostent *rhost_info; int sock = -1; bool ok = false; rhost_info = (struct hostent *) ::gethostbyname( CAP_hostname ); if ( rhost_info ) { if ( !QFile::exists( mw->captureFileName() ) ) { QMessageBox::warning( 0, tr( "Error" ), tr( "<p>Logfile '%1' doesn't exist</p>").arg( mw->captureFileName() ) ); return; } QFile f( mw->captureFileName() ); if ( !f.open( IO_ReadOnly ) ) { QMessageBox::warning( 0, tr( "Error" ), tr( "<p>Can't open Logfile '%1'</p>").arg( mw->captureFileName() ) ); return; } int content_length = f.size(); ::memset( &raddr, 0, sizeof (struct sockaddr_in) ); ::memcpy( &raddr. sin_addr, rhost_info-> h_addr, rhost_info-> h_length ); raddr.sin_family = rhost_info-> h_addrtype; raddr.sin_port = htons ( 80 ); sock = ::socket( AF_INET, SOCK_STREAM, 0 ); if ( sock >= 0 ) { if ( ::connect ( sock, (struct sockaddr *) & raddr, sizeof (struct sockaddr)) >= 0 ) { QString header; QString content; QString preambel; header = "" "POST /projects/capturedump.spy HTTP/1.1\r\n" "Host: www.vanille.de\r\n" "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031010 Galeon/1.3.10\r\n" "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" "Accept-Language: en\r\n" "Accept-Encoding: gzip, deflate, compress;q=0.9\r\n" "Accept-Charset: us-ascii,utf-8;q=0.7,*;q=0.7\r\n" "Keep-Alive: 300\r\n" "Connection: keep-alive\r\n" "Referer: http://www.vanille.de/projects/capturedump.spy\r\n" "Content-Type: multipart/form-data; boundary=---------------------------97267758015830030481215568065\r\n" "Content-Length: %1\r\n" "\r\n"; content = "" "-----------------------------97267758015830030481215568065\r\n" "Content-Disposition: form-data; name=\"Name\"\r\n" "\r\n" "%1\r\n" "-----------------------------97267758015830030481215568065\r\n" "Content-Disposition: form-data; name=\"Location\"\r\n" "\r\n" "%2\r\n" "-----------------------------97267758015830030481215568065\r\n" "Content-Disposition: form-data; name=\"Comments\"\r\n" "\r\n" "%3\r\n" "-----------------------------97267758015830030481215568065\r\n" "Content-Disposition: form-data; name=\"upfile\"; filename=\"%4\"\r\n" "Content-Type: application/octet-stream\r\n" "\r\n"; preambel = "" "\r\n-----------------------------97267758015830030481215568065--\r\n"; content = content.arg( from->text().isEmpty() ? QString( "Anonymous Wellenreiter II User" ) : from->text() ); content = content.arg( location->text().isEmpty() ? QString( "Anonymous Wellenreiter II Location" ) : location->text() ); content = content.arg( comments->text().isEmpty() ? QString( "Anonymous Wellenreiter II Comments" ) : comments->text() ); content = content.arg( mw->captureFileName() ); header = header.arg( QString::number( content.length() + f.size() + preambel.length() ) ); // write header const char* ascii = header.latin1(); uint ascii_len = ::strlen( ascii ); ::write ( sock, ascii, ascii_len ); // write fixed content ascii = content.latin1(); ascii_len = ::strlen( ascii ); ::write ( sock, ascii, ascii_len ); // write variable content char ch; while ( !f.atEnd() ) { f.readBlock( &ch, 1 ); ::write ( sock, &ch, 1 ); } // write preambel ascii = preambel.latin1(); ascii_len = ::strlen( ascii ); ::write ( sock, ascii, ascii_len ); // done! ok = true; } } ::close ( sock ); } if ( ok ) QMessageBox::information( 0, tr( "Success" ), QString ( "<p>%1</p>" ).arg( tr( "Capture Dump was uploaded to %1" ) ).arg( CAP_hostname ) ); else QMessageBox::warning( 0, tr( "Error" ), QString ( "<p>%1</p>" ).arg ( tr( "Connection to %1 failed" ) ).arg( CAP_hostname ) ); } void WellenreiterMainWindow::viewExpandAll() { mw->netView()->expand(); } void WellenreiterMainWindow::viewCollapseAll() { mw->netView()->collapse(); } 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 @@ /********************************************************************** ** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved. ** ** This file is part of Wellenreiter II. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** **********************************************************************/ #include "scanlist.h" #include "configwindow.h" #include "logwindow.h" /* OPIE */ #ifdef QWS #include <opie2/odebug.h> #include <qpe/qpeapplication.h> #include <qpe/resource.h> #else #include "resource.h" #endif using namespace Opie::Core; using namespace Opie::Ui; using namespace Opie::Net; /* QT */ #include <qcursor.h> #include <qdatetime.h> #include <qpopupmenu.h> #include <qcheckbox.h> /* STD */ #include <assert.h> const int col_type = 0; const int col_essid = 0; const int col_sig = 1; const int col_ap = 2; const int col_channel = 3; const int col_wep = 4; const int col_traffic = 5; const int col_ip = 6; const int col_manuf = 7; const int col_firstseen = 8; const int col_lastseen = 9; const int col_location = 10; MScanListView::MScanListView( QWidget* parent, const char* name ) :OListView( parent, name ) { setFrameShape( QListView::StyledPanel ); setFrameShadow( QListView::Sunken ); addColumn( tr( "Net/Station" ) ); setColumnAlignment( col_essid, AlignLeft || AlignVCenter ); addColumn( tr( "#" ) ); setColumnAlignment( col_sig, AlignCenter ); addColumn( tr( "MAC" ) ); setColumnAlignment( col_ap, AlignCenter ); addColumn( tr( "Chn" ) ); setColumnAlignment( col_channel, AlignCenter ); addColumn( tr( "W" ) ); setColumnAlignment( col_wep, AlignCenter ); addColumn( tr( "T" ) ); setColumnAlignment( col_traffic, AlignCenter ); addColumn( tr( "IP" ) ); setColumnAlignment( col_ip, AlignCenter ); addColumn( tr( "Manufacturer" ) ); setColumnAlignment( col_manuf, AlignCenter ); addColumn( tr( "First Seen" ) ); setColumnAlignment( col_firstseen, AlignCenter ); addColumn( tr( "Last Seen" ) ); setColumnAlignment( col_lastseen, AlignCenter ); addColumn( tr( "Location" ) ); setColumnAlignment( col_location, AlignCenter ); setRootIsDecorated( true ); setAllColumnsShowFocus( true ); connect( this, SIGNAL( rightButtonClicked(QListViewItem*,const QPoint&,int) ), this, SLOT( contextMenuRequested(QListViewItem*,const QPoint&,int) ) ); #ifdef QWS QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); #endif }; MScanListView::~MScanListView() { }; OListViewItem* MScanListView::childFactory() { return new MScanListItem( this ); } void MScanListView::serializeTo( QDataStream& s) const { odebug << "serializing MScanListView" << oendl; OListView::serializeTo( s ); } void MScanListView::serializeFrom( QDataStream& s) { odebug << "serializing MScanListView" << oendl; OListView::serializeFrom( s ); } void MScanListView::addNewItem( const QString& type, const QString& essid, const OMacAddress& mac, bool wep, int channel, int signal, const GpsLocation& loc, bool probe ) { QString macaddr = mac.toString(true); #ifdef DEBUG qDebug( "MScanList::addNewItem( %s / %s / %s [%d]", (const char*) type, (const char*) essid, (const char*) macaddr, channel ); #endif // search, if we already have seen this net QString s; MScanListItem* network; MScanListItem* item = static_cast<MScanListItem*> ( firstChild() ); while ( item && ( item->text( col_essid ) != essid ) ) { #ifdef DEBUG - odebug << "itemtext: " << (const char*) item->text( col_essid ) << "" << oendl; + odebug << "itemtext: " << item->text( col_essid ) << "" << oendl; #endif item = static_cast<MScanListItem*> ( item->nextSibling() ); } if ( item ) { // we have already seen this net, check all childs if MAC exists network = item; item = static_cast<MScanListItem*> ( item->firstChild() ); assert( item ); // this shouldn't fail while ( item && ( item->text( col_ap ) != macaddr ) ) { #ifdef DEBUG - odebug << "subitemtext: " << (const char*) item->text( col_ap ) << "" << oendl; + odebug << "subitemtext: " << item->text( col_ap ) << "" << oendl; #endif item = static_cast<MScanListItem*> ( item->nextSibling() ); } if ( item ) { // we have already seen this item, it's a dupe #ifdef DEBUG - odebug << "" << (const char*) macaddr << " is a dupe - ignoring..." << oendl; + odebug << "" << macaddr << " is a dupe - ignoring..." << oendl; #endif item->receivedBeacon(); return; } } else { s.sprintf( "(i) New network: ESSID '%s'", (const char*) essid ); MLogWindow::logwindow()->log( s ); network = new MScanListItem( this, "network", essid, QString::null, 0, 0, 0, probe ); } // insert new station as child from network // no essid to reduce clutter, maybe later we have a nick or stationname to display!? #ifdef DEBUG - odebug << "inserting new station " << (const char*) macaddr << "" << oendl; + odebug << "inserting new station " << macaddr << "" << oendl; #endif MScanListItem* station = new MScanListItem( network, type, "", macaddr, wep, channel, signal ); station->setManufacturer( mac.manufacturer() ); station->setLocation( loc.dmsPosition() ); if ( type == "managed" ) { s.sprintf( "(i) New Access Point in '%s' [%d]", (const char*) essid, channel ); } else { s.sprintf( "(i) New AdHoc station in '%s' [%d]", (const char*) essid, channel ); } MLogWindow::logwindow()->log( s ); } void MScanListView::addIfNotExisting( MScanListItem* network, const OMacAddress& addr, const QString& type ) { MScanListItem* subitem = static_cast<MScanListItem*>( network->firstChild() ); while ( subitem && ( subitem->text( col_ap ) != addr.toString(true) ) ) { #ifdef DEBUG - odebug << "subitemtext: " << (const char*) subitem->text( col_ap ) << "" << oendl; + odebug << "subitemtext: " << subitem->text( col_ap ) << "" << oendl; #endif subitem = static_cast<MScanListItem*> ( subitem->nextSibling() ); } if ( subitem ) { // we have already seen this item, it's a dupe #ifdef DEBUG - odebug << "" << (const char*) addr.toString(true) << " is a dupe - ignoring..." << oendl; + odebug << "" << addr.toString(true) << " is a dupe - ignoring..." << oendl; #endif subitem->receivedBeacon(); //FIXME: sent data bit return; } // Hey, it seems to be a new item :-D MScanListItem* station = new MScanListItem( network, type, /* network->text( col_essid ) */ "", addr.toString(true), false, -1, -1 ); station->setManufacturer( addr.manufacturer() ); QString s; if ( type == "station" ) { s.sprintf( "(i) New Station in '%s' [xx]", (const char*) network->text( col_essid ) ); } else { s.sprintf( "(i) New Wireless Station in '%s' [xx]", (const char*) network->text( col_essid ) ); } MLogWindow::logwindow()->log( s ); } void MScanListView::WDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& viaFrom, const OMacAddress& viaTo ) { - odebug << "WDSTraffic: " << (const char*) viaFrom.toString() << " and " << (const char*) viaTo.toString() << " seem to form a WDS" << oendl; + odebug << "WDSTraffic: " << (const char*) viaFrom.toString() << " and " << viaTo.toString() << " seem to form a WDS" << oendl; QString s; MScanListItem* network; QListViewItemIterator it( this ); while ( it.current() && it.current()->text( col_ap ) != viaFrom.toString(true) && it.current()->text( col_ap ) != viaTo.toString(true) ) ++it; MScanListItem* item = static_cast<MScanListItem*>( it.current() ); if ( item ) // Either viaFrom or viaTo AP has shown up yet, so just add our two new stations { addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from ); addIfNotExisting( static_cast<MScanListItem*>(item->parent()), to ); } else { odebug << "D'Oh! Stations without AP... ignoring for now... will handle this in 1.1 version :-D" << oendl; MLogWindow::logwindow()->log( "WARNING: Unhandled WSD traffic!" ); } } void MScanListView::toDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via ) { QString s; MScanListItem* network; QListViewItemIterator it( this ); while ( it.current() && it.current()->text( col_ap ) != via.toString(true) ) ++it; MScanListItem* item = static_cast<MScanListItem*>( it.current() ); if ( item ) // AP has shown up yet, so just add our new "from" - station { addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from, "adhoc" ); } else { odebug << "D'Oh! Station without AP... ignoring for now... will handle this in 1.1 :-D" << oendl; MLogWindow::logwindow()->log( "WARNING: Unhandled toDS traffic!" ); } } void MScanListView::fromDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via ) { QString s; MScanListItem* network; QListViewItemIterator it( this ); while ( it.current() && it.current()->text( col_ap ) != via.toString(true) ) ++it; MScanListItem* item = static_cast<MScanListItem*>( it.current() ); if ( item ) // AP has shown up yet, so just add our new "from" - station { addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from, "station" ); } else { odebug << "D'Oh! Station without AP... ignoring for now... will handle this in 1.1 :-D" << oendl; MLogWindow::logwindow()->log( "WARNING: Unhandled fromDS traffic!" ); } } void MScanListView::IBSStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via ) { owarn << "D'oh! Not yet implemented..." << oendl; MLogWindow::logwindow()->log( "WARNING: Unhandled IBSS traffic!" ); } void MScanListView::identify( const OMacAddress& macaddr, const QString& ip ) { - odebug << "identify " << (const char*) macaddr.toString() << " = " << (const char*) ip << "" << oendl; + odebug << "identify " << (const char*) macaddr.toString() << " = " << ip << "" << oendl; QListViewItemIterator it( this ); for ( ; it.current(); ++it ) { if ( it.current()->text( col_ap ) == macaddr.toString(true) ) { it.current()->setText( col_ip, ip ); return; } } odebug << "D'oh! Received identification, but item not yet in list... ==> Handle this!" << oendl; MLogWindow::logwindow()->log( QString().sprintf( "WARNING: Unhandled identification %s = %s!", (const char*) macaddr.toString(), (const char*) ip ) ); } void MScanListView::addService( const QString& name, const OMacAddress& macaddr, const QString& ip ) { - odebug << "addService '" << (const char*) name << "', Server = " << (const char*) macaddr.toString() << " = " << (const char*) ip << "" << oendl; + odebug << "addService '" << (const char*) name << "', Server = " << (const char*) macaddr.toString() << " = " << ip << "" << oendl; //TODO: Refactor that out, we need it all over the place. // Best to do it in a more comfortable abstraction in OListView // (Hmm, didn't I already start something in this direction?) QListViewItemIterator it( this ); for ( ; it.current(); ++it ) { if ( it.current()->text( col_ap ) == macaddr.toString(true) ) { MScanListItem* subitem = static_cast<MScanListItem*>( it.current()->firstChild() ); while ( subitem && ( subitem->text( col_essid ) != name ) ) { #ifdef DEBUG - odebug << "subitemtext: " << (const char*) subitem->text( col_essid ) << "" << oendl; + odebug << "subitemtext: " << subitem->text( col_essid ) << "" << oendl; #endif subitem = static_cast<MScanListItem*> ( subitem->nextSibling() ); } if ( subitem ) { // we have already seen this item, it's a dupe #ifdef DEBUG - odebug << "" << (const char*) name << " is a dupe - ignoring..." << oendl; + odebug << "" << name << " is a dupe - ignoring..." << oendl; #endif subitem->receivedBeacon(); //FIXME: sent data bit return; } // never seen that - add new item MScanListItem* item = new MScanListItem( it.current(), "service", "N/A", " ", false, -1, -1 ); item->setText( col_essid, name ); return; } } odebug << "D'oh! Received identification, but item not yet in list... ==> Handle this!" << oendl; MLogWindow::logwindow()->log( QString().sprintf( "WARNING: Unhandled service addition %s = %s!", (const char*) macaddr.toString(), (const char*) ip ) ); } void MScanListView::contextMenuRequested( QListViewItem* item, const QPoint&, int col ) { if ( !item ) return; MScanListItem* itm = static_cast<MScanListItem*>( item ); qDebug( "contextMenuRequested on item '%s' (%s) in column: '%d'", (const char*) itm->text(0), (const char*) itm->type, col ); if ( itm->type == "adhoc" || itm->type == "managed" ) { QString entry = QString().sprintf( "&Join %s Net '%s'...", (const char*) itm->type, (const char*) itm->essid() ); QPopupMenu m( this ); m.insertItem( entry, 37773, 0 ); int result = m.exec( QCursor::pos() ); if ( result == 37773 ) emit joinNetwork( itm->type, itm->essid(), itm->channel(), itm->macaddr() ); } } //============================================================ // MScanListItem //============================================================ MScanListItem::MScanListItem( QListView* parent, const QString& type, const QString& essid, const QString& macaddr, bool wep, int channel, int signal, bool probed ) :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null ), _type( type ), _essid( essid ), _macaddr( macaddr ), _wep( wep ), _channel( channel ), _signal( signal ), _beacons( 1 ) { #ifdef DEBUG odebug << "creating scanlist item" << oendl; #endif if ( WellenreiterConfigWindow::instance() ) WellenreiterConfigWindow::instance()->performAction( type, essid, macaddr, wep, channel, signal ); // better use signal/slot combination here decorateItem( type, essid, macaddr, wep, channel, signal, probed ); } MScanListItem::MScanListItem( QListViewItem* parent, const QString& type, const QString& essid, const QString& macaddr, bool wep, int channel, int signal ) :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null ) { #ifdef DEBUG odebug << "creating scanlist item" << oendl; #endif if ( WellenreiterConfigWindow::instance() ) WellenreiterConfigWindow::instance()->performAction( type, essid, macaddr, wep, channel, signal ); // better use signal/slot combination here decorateItem( type, essid, macaddr, wep, channel, signal, false ); } const QString& MScanListItem::essid() const { if ( type == "network" ) return _essid; else return ( (MScanListItem*) parent() )->essid(); } OListViewItem* MScanListItem::childFactory() { return new MScanListItem( this ); } void MScanListItem::serializeTo( QDataStream& s ) const { #ifdef DEBUG odebug << "serializing MScanListItem" << oendl; #endif OListViewItem::serializeTo( s ); s << _type; s << (Q_UINT8) ( _wep ? 'y' : 'n' ); } void MScanListItem::serializeFrom( QDataStream& s ) { #ifdef DEBUG odebug << "serializing MScanListItem" << oendl; #endif OListViewItem::serializeFrom( s ); char wep; s >> _type; s >> (Q_UINT8) wep; _wep = (wep == 'y'); QString name; name.sprintf( "wellenreiter/%s", (const char*) _type ); setPixmap( col_type, Resource::loadPixmap( name ) ); if ( _wep ) setPixmap( col_wep, Resource::loadPixmap( "wellenreiter/cracked" ) ); //FIXME: rename the pixmap! listView()->triggerUpdate(); } void MScanListItem::decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal, bool probed ) { #ifdef DEBUG qDebug( "decorating scanlist item %s / %s / %s [%d]", (const char*) type, (const char*) essid, (const char*) macaddr, channel ); #endif // set icon for managed or adhoc mode QString name; name.sprintf( "wellenreiter/%s", (const char*) type ); setPixmap( col_type, Resource::loadPixmap( name ) ); // special case for probed networks FIXME: This is ugly at present if ( type == "network" && probed ) { setPixmap( col_type, Resource::loadPixmap( "wellenreiter/network-probed.png" ) ); } // set icon for wep (wireless encryption protocol) if ( wep ) setPixmap( col_wep, Resource::loadPixmap( "wellenreiter/cracked" ) ); //FIXME: rename the pixmap! // set channel and signal text if ( signal != -1 ) setText( col_sig, QString::number( signal ) ); if ( channel != -1 ) setText( col_channel, QString::number( channel ) ); setText( col_firstseen, QTime::currentTime().toString() ); //setText( col_lastseen, QTime::currentTime().toString() ); listView()->triggerUpdate(); this->type = type; _type = type; _essid = essid; _macaddr = macaddr; _channel = channel; _beacons = 1; _signal = 0; if ( WellenreiterConfigWindow::instance()->openTree->isChecked() ) { listView()->ensureItemVisible( this ); } } void MScanListItem::setManufacturer( const QString& manufacturer ) { setText( col_manuf, manufacturer ); } void MScanListItem::setLocation( const QString& location ) { setText( col_location, location ); } void MScanListItem::receivedBeacon() { _beacons++; #ifdef DEBUG - odebug << "MScanListItem " << (const char*) _macaddr << ": received beacon #" << _beacons << "" << oendl; + odebug << "MScanListItem " << _macaddr << ": received beacon #" << _beacons << "" << oendl; #endif setText( col_sig, QString::number( _beacons ) ); setText( col_lastseen, QTime::currentTime().toString() ); MScanListItem* p = (MScanListItem*) parent(); if ( p ) p->receivedBeacon(); } 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 @@ /********************************************************************** ** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ***********************************************************************/ #include "gps.h" #include "wellenreiter.h" #include "scanlist.h" #include "logwindow.h" #include "packetview.h" #include "configwindow.h" #include "statwindow.h" #include "graphwindow.h" #include "protolistview.h" /* OPIE */ #ifdef QWS #include <opie2/oapplication.h> #include <opie2/odebug.h> #include <opie2/odevice.h> #else #include <qapplication.h> #endif #include <opie2/omanufacturerdb.h> #include <opie2/onetwork.h> #include <opie2/opcap.h> #include <qpe/qcopenvelope_qws.h> using namespace Opie::Core; using namespace Opie::Net; using namespace Opie::Ui; /* QT */ #include <qcheckbox.h> #include <qcombobox.h> #include <qdatetime.h> #include <qpushbutton.h> #include <qlineedit.h> #include <qmessagebox.h> #include <qobjectlist.h> #include <qregexp.h> #include <qspinbox.h> #include <qtimer.h> #include <qtoolbutton.h> #include <qmainwindow.h> /* STD */ #include <assert.h> #include <errno.h> #include <unistd.h> #include <string.h> #include <sys/types.h> #include <stdlib.h> Wellenreiter::Wellenreiter( QWidget* parent ) : WellenreiterBase( parent, 0, 0 ), sniffing( false ), iface( 0 ), configwindow( 0 ) { logwindow->log( "(i) Wellenreiter has been started." ); // // detect operating system // #ifdef QWS QString sys; sys.sprintf( "(i) Running on '%s'.", (const char*) ODevice::inst()->systemString() ); _system = ODevice::inst()->system(); logwindow->log( sys ); #endif netview->setColumnWidthMode( 1, QListView::Manual ); connect( netview, SIGNAL( joinNetwork(const QString&,const QString&,int,const QString&) ), this, SLOT( joinNetwork(const QString&,const QString&,int,const QString&) ) ); pcap = new OPacketCapturer(); pcap->setAutoDelete( false ); gps = new GPS( this ); QTimer::singleShot( 1000, this, SLOT( initialTimer() ) ); } Wellenreiter::~Wellenreiter() { delete pcap; } void Wellenreiter::initialTimer() { - odebug << "Wellenreiter::preloading manufacturer database..." << oendl; + odebug << "Wellenreiter::preloading manufacturer database..." << oendl; OManufacturerDB::instance(); } void Wellenreiter::setConfigWindow( WellenreiterConfigWindow* cw ) { configwindow = cw; } void Wellenreiter::channelHopped(int c) { QString title = "Wellenreiter II -scan- ["; QString left; if ( c > 1 ) left.fill( '.', c-1 ); title.append( left ); title.append( '|' ); if ( c < iface->channels() ) { QString right; right.fill( '.', iface->channels()-c ); title.append( right ); } title.append( "]" ); //title.append( QString().sprintf( " %02d", c ) ); assert( parent() ); ( (QMainWindow*) parent() )->setCaption( title ); } void Wellenreiter::handleNotification( OPacket* p ) { QObjectList* l = p->queryList(); QObjectListIt it( *l ); QObject* o; while ( (o = it.current()) != 0 ) { QString name = it.current()->name(); if ( configwindow->parsePackets->isProtocolChecked( name ) ) { QString action = configwindow->parsePackets->protocolAction( name ); - odebug << "parsePacket-action for '" << (const char*) name << "' seems to be '" << (const char*) action << "'" << oendl; + odebug << "parsePacket-action for '" << (const char*) name << "' seems to be '" << action << "'" << oendl; doAction( action, name, p ); } else { - odebug << "protocol '" << (const char*) name << "' not checked in parsePackets." << oendl; + odebug << "protocol '" << name << "' not checked in parsePackets." << oendl; } ++it; } } void Wellenreiter::handleManagementFrame( OPacket* p, OWaveLanManagementPacket* manage ) { if ( manage->managementType() == "Beacon" ) handleManagementFrameBeacon( p, manage ); else if ( manage->managementType() == "ProbeRequest" ) handleManagementFrameProbeRequest( p, manage ); else if ( manage->managementType() == "ProbeResponse" ) handleManagementFrameProbeResponse( p, manage ); - else owarn << "Wellenreiter::handleManagementFrame(): '" << (const char*) manage->managementType() << "' - please handle me!" << oendl; + else owarn << "Wellenreiter::handleManagementFrame(): '" << manage->managementType() << "' - please handle me!" << oendl; } void Wellenreiter::handleManagementFrameProbeRequest( OPacket* p, OWaveLanManagementPacket* request ) { OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); QString essid = ssid ? ssid->ID( true /* decloak */ ) : QString("<unknown>"); OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) ); int channel = ds ? ds->channel() : -1; OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) ); GpsLocation loc( -111, -111 ); if ( configwindow->enableGPS->isChecked() ) { // TODO: add check if GPS is working!? - odebug << "Wellenreiter::gathering GPS data..." << oendl; + odebug << "Wellenreiter::gathering GPS data..." << oendl; loc = gps->position(); - odebug << "Wellenreiter::GPS data received is ( " << loc.latitude() << " , " << loc.longitude() << " ) - dms string = '" << loc.dmsPosition().latin1() << "'" << oendl; + odebug << "Wellenreiter::GPS data received is ( " << loc.latitude() << " , " << loc.longitude() << " ) - dms string = '" << loc.dmsPosition().latin1() << "'" << oendl; } if ( essid.length() ) netView()->addNewItem( "adhoc", essid, header->macAddress2(), false /* should check FrameControl field */, -1, 0, loc, true /* only probed */ ); - odebug << "Wellenreiter::invalid frame [possibly noise] detected!" << oendl; + odebug << "Wellenreiter::invalid frame [possibly noise] detected!" << oendl; } void Wellenreiter::handleManagementFrameProbeResponse( OPacket* p, OWaveLanManagementPacket* response ) { } void Wellenreiter::handleManagementFrameBeacon( OPacket* p, OWaveLanManagementPacket* beacon ) { QString type; if ( beacon->canIBSS() ) { type = "adhoc"; } else if ( beacon->canESS() ) { type = "managed"; } else { - owarn << "Wellenreiter::invalid frame [possibly noise] detected!" << oendl; + owarn << "Wellenreiter::invalid frame [possibly noise] detected!" << oendl; return; } OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); QString essid = ssid ? ssid->ID( true /* decloak */ ) : QString("<unknown>"); OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) ); int channel = ds ? ds->channel() : -1; OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) ); GpsLocation loc( -111, -111 ); if ( configwindow->enableGPS->isChecked() ) { // TODO: add check if GPS is working!? - odebug << "Wellenreiter::gathering GPS data..." << oendl; + odebug << "Wellenreiter::gathering GPS data..." << oendl; loc = gps->position(); - odebug << "Wellenreiter::GPS data received is ( " << loc.latitude() << " , " << loc.longitude() << " ) - dms string = '" << loc.dmsPosition().latin1() << "'" << oendl; + odebug << "Wellenreiter::GPS data received is ( " << loc.latitude() << " , " << loc.longitude() << " ) - dms string = '" << loc.dmsPosition().latin1() << "'" << oendl; } netView()->addNewItem( type, essid, header->macAddress2(), beacon->canPrivacy(), channel, 0, loc ); // update graph window if ( ds ) { OPrismHeaderPacket* prism = static_cast<OPrismHeaderPacket*>( p->child( "Prism" ) ); if ( prism ) graphwindow->traffic( ds->channel(), prism->signalStrength() ); else graphwindow->traffic( ds->channel(), 95 ); } } void Wellenreiter::handleControlFrame( OPacket* p, OWaveLanControlPacket* control ) { OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) ); if ( control->controlType() == "Acknowledge" ) { netView()->addNewItem( "adhoc", "<unknown>", header->macAddress1(), false, -1, 0, GpsLocation( -111, -111 ) ); } else { - odebug << "Wellenreiter::handleControlFrame - please handle " << (const char*) control->controlType() << " in a future version! :D" << oendl; + odebug << "Wellenreiter::handleControlFrame - please handle " << control->controlType() << " in a future version! :D" << oendl; } } void Wellenreiter::handleWlanData( OPacket* p, OWaveLanDataPacket* data, OMacAddress& from, OMacAddress& to ) { OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" ); if ( wlan->fromDS() && !wlan->toDS() ) { netView()->fromDStraffic( wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() ); from = wlan->macAddress3(); to = wlan->macAddress2(); } else if ( !wlan->fromDS() && wlan->toDS() ) { netView()->toDStraffic( wlan->macAddress2(), wlan->macAddress3(), wlan->macAddress1() ); from = wlan->macAddress2(); to = wlan->macAddress3(); } else if ( wlan->fromDS() && wlan->toDS() ) { netView()->WDStraffic( wlan->macAddress4(), wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() ); from = wlan->macAddress4(); to = wlan->macAddress3(); } else { netView()->IBSStraffic( wlan->macAddress2(), wlan->macAddress1(), wlan->macAddress3() ); from = wlan->macAddress2(); to = wlan->macAddress1(); } } void Wellenreiter::handleEthernetData( OPacket* p, OEthernetPacket* data, OMacAddress& from, OMacAddress& to ) { from = data->sourceAddress(); to = data->destinationAddress(); netView()->addNewItem( "station", "<wired>", from, false, -1, 0, GpsLocation( -111, -111 ) ); } void Wellenreiter::handleARPData( OPacket* p, OARPPacket*, OMacAddress& source, OMacAddress& dest ) { OARPPacket* arp = (OARPPacket*) p->child( "ARP" ); if ( arp ) { - odebug << "Received ARP traffic (type '" << (const char*) arp->type() << "'): " << oendl; + odebug << "Received ARP traffic (type '" << arp->type() << "'): " << oendl; if ( arp->type() == "REQUEST" ) { netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() ); } else if ( arp->type() == "REPLY" ) { netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() ); netView()->identify( arp->targetMacAddress(), arp->targetIPV4Address().toString() ); } } } void Wellenreiter::handleIPData( OPacket* p, OIPPacket* ip, OMacAddress& source, OMacAddress& dest ) { //TODO: Implement more IP based protocols ODHCPPacket* dhcp = (ODHCPPacket*) p->child( "DHCP" ); if ( dhcp ) { - odebug << "Received DHCP '" << (const char*) dhcp->type() << "' packet" << oendl; + odebug << "Received DHCP '" << dhcp->type() << "' packet" << oendl; if ( dhcp->type() == "OFFER" ) { - odebug << "DHCP: '" << (const char*) source.toString() << "' ('" << (const char*) dhcp->serverAddress().toString() << "') seems to be a DHCP server." << oendl; + odebug << "DHCP: '" << (const char*) source.toString() << "' ('" << dhcp->serverAddress().toString() << "') seems to be a DHCP server." << oendl; netView()->identify( source, dhcp->serverAddress().toString() ); netView()->addService( "DHCP", source, dhcp->serverAddress().toString() ); } else if ( dhcp->type() == "ACK" ) { - odebug << "DHCP: '" << (const char*) dhcp->clientMacAddress().toString() << "' ('" << (const char*) dhcp->yourAddress().toString() << "') accepted the offered DHCP address." << oendl; + odebug << "DHCP: '" << (const char*) dhcp->clientMacAddress().toString() << "' ('" << dhcp->yourAddress().toString() << "') accepted the offered DHCP address." << oendl; netView()->identify( dhcp->clientMacAddress(), dhcp->yourAddress().toString() ); } } } QObject* Wellenreiter::childIfToParse( OPacket* p, const QString& protocol ) { if ( configwindow->parsePackets->isProtocolChecked( protocol ) ) if ( configwindow->parsePackets->protocolAction( protocol ) == "Discard!" ) return 0; return p->child( protocol ); } bool Wellenreiter::checkDumpPacket( OPacket* p ) { // go through all child packets and see if one is inside the child hierarchy for p // if so, do what the user requested (protocolAction), e.g. pass or discard if ( !configwindow->writeCaptureFile->isChecked() ) return true; // semantic change - we're logging anyway now to /tmp/wellenreiter QObjectList* l = p->queryList(); QObjectListIt it( *l ); QObject* o; while ( (o = it.current()) != 0 ) { QString name = it.current()->name(); if ( configwindow->capturePackets->isProtocolChecked( name ) ) { QString action = configwindow->capturePackets->protocolAction( name ); - odebug << "capturePackets-action for '" << (const char*) name << "' seems to be '" << (const char*) action << "'" << oendl; + odebug << "capturePackets-action for '" << (const char*) name << "' seems to be '" << action << "'" << oendl; if ( action == "Discard" ) { logwindow->log( QString().sprintf( "(i) dump-discarding of '%s' packet requested.", (const char*) name ) ); return false; } } else { - odebug << "protocol '" << (const char*) name << "' not checked in capturePackets." << oendl; + odebug << "protocol '" << name << "' not checked in capturePackets." << oendl; } ++it; } return true; } void Wellenreiter::receivePacket( OPacket* p ) { hexWindow()->add( p ); if ( checkDumpPacket( p ) ) { pcap->dump( p ); } // check for a management frame OWaveLanManagementPacket* manage = static_cast<OWaveLanManagementPacket*>( childIfToParse( p, "802.11 Management" ) ); if ( manage ) { handleManagementFrame( p, manage ); return; } // check for a control frame OWaveLanControlPacket* control = static_cast<OWaveLanControlPacket*>( childIfToParse( p, "802.11 Control" ) ); if ( control ) { handleControlFrame( p, control ); return; } OMacAddress source; OMacAddress dest; //TODO: WEP check here // check for a wireless data frame OWaveLanDataPacket* wlan = static_cast<OWaveLanDataPacket*>( childIfToParse( p, "802.11 Data" ) ); if ( wlan ) { handleWlanData( p, wlan, source, dest ); } // check for a wired data frame OEthernetPacket* eth = static_cast<OEthernetPacket*>( childIfToParse( p, "Ethernet" ) ); if ( eth ) { handleEthernetData( p, eth, source, dest ); } // check for an arp frame since arp frames come in two flavours: // 802.11 encapsulates ARP data within IP packets while wired ethernet doesn't. OARPPacket* arp = static_cast<OARPPacket*>( childIfToParse( p, "ARP" ) ); if ( arp ) { handleARPData( p, arp, source, dest ); } // check for a ip frame OIPPacket* ip = static_cast<OIPPacket*>( childIfToParse( p, "IP" ) ); if ( ip ) { handleIPData( p, ip, source, dest ); } //handleNotification( p ); } void Wellenreiter::stopClicked() { if ( iface ) { disconnect( SIGNAL( receivedPacket(Opie::Net::OPacket*) ), this, SLOT( receivePacket(Opie::Net::OPacket*) ) ); disconnect( SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) ); iface->setChannelHopping(); // stop hopping channels } else killTimers(); pcap->close(); sniffing = false; if ( iface ) { // switch off monitor mode iface->setMode( "managed" ); // switch off promisc flag iface->setPromiscuousMode( false ); system( "cardctl reset; sleep 1" ); //FIXME: Use OProcess } logwindow->log( "(i) Stopped Scanning." ); assert( parent() ); ( (QMainWindow*) parent() )->setCaption( "Wellenreiter II" ); // message the user QMessageBox::information( this, "Wellenreiter II", tr( "Your wireless card\nshould now be usable again." ) ); sniffing = false; emit( stoppedSniffing() ); #ifdef QWS if ( WellenreiterConfigWindow::instance()->disablePM->isChecked() ) { QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; } #else #warning FIXME: setScreenSaverMode is not operational on the X11 build #endif // print out statistics for( QMap<QString,int>::ConstIterator it = pcap->statistics().begin(); it != pcap->statistics().end(); ++it ) statwindow->updateCounter( it.key(), it.data() ); } void Wellenreiter::startClicked() { // get configuration from config window const QString& interface = configwindow->interfaceName->currentText(); const int cardtype = configwindow->driverType(); const int interval = configwindow->hoppingInterval(); if ( ( interface == "" ) || ( cardtype == 0 ) ) { QMessageBox::information( this, "Wellenreiter II", tr( "Your device is not\nproperly configured. Please reconfigure!" ) ); return; } // configure device ONetwork* net = ONetwork::instance(); // TODO: check if interface is wireless and support sniffing for non-wireless interfaces if ( cardtype != DEVTYPE_FILE ) { - + if ( !net->isPresent( interface ) ) { QMessageBox::information( this, "Wellenreiter II", tr( "The configured device (%1)\nis not available on this system\n. Please reconfigure!" ).arg( interface ) ); return; } - + iface = static_cast<OWirelessNetworkInterface*>(net->interface( interface )); // fails if network is not wireless! assert( iface ); // bring device UP iface->setUp( true ); if ( !iface->isUp() ) { QMessageBox::warning( this, "Wellenreiter II", tr( "Can't bring interface '%1' up:\n" ).arg( iface->name() ) + strerror( errno ) ); return; } } // set monitor mode bool usePrism = configwindow->usePrismHeader(); switch ( cardtype ) { case DEVTYPE_CISCO: iface->setMonitoring( new OCiscoMonitoringInterface( iface, usePrism ) ); break; case DEVTYPE_WLAN_NG: iface->setMonitoring( new OWlanNGMonitoringInterface( iface, usePrism ) ); break; case DEVTYPE_HOSTAP: iface->setMonitoring( new OHostAPMonitoringInterface( iface, usePrism ) ); break; case DEVTYPE_ORINOCO: iface->setMonitoring( new OOrinocoMonitoringInterface( iface, usePrism ) ); break; case DEVTYPE_MANUAL: QMessageBox::information( this, "Wellenreiter II", tr( "Bring your device into\nmonitor mode now." ) ); break; - case DEVTYPE_FILE: odebug << "Wellenreiter: Capturing from file '" << (const char*) interface << "'" << oendl; break; + case DEVTYPE_FILE: odebug << "Wellenreiter: Capturing from file '" << interface << "'" << oendl; break; default: assert( 0 ); // shouldn't reach this } // switch device into monitor mode if ( cardtype < DEVTYPE_FILE ) { if ( cardtype != DEVTYPE_MANUAL ) iface->setMode( "monitor" ); if ( iface->mode() != "monitor" ) { if ( QMessageBox::warning( this, "Wellenreiter II", tr( "Can't set interface '%1'\ninto monitor mode:\n" ).arg( iface->name() ) + strerror( errno ) + tr( "\nContinue with limited functionality?" ), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No ) return; } } // open GPS device if ( configwindow->enableGPS->isChecked() ) { - odebug << "Wellenreiter:GPS enabled @ " << (const char*) configwindow->gpsdHost->currentText() << ":" << configwindow->gpsdPort->value() << "" << oendl; + odebug << "Wellenreiter:GPS enabled @ " << configwindow->gpsdHost->currentText() << ":" << configwindow->gpsdPort->value() << "" << oendl; gps->open( configwindow->gpsdHost->currentText(), configwindow->gpsdPort->value() ); } // open pcap and start sniffing if ( configwindow->writeCaptureFile->isChecked() ) // write to a user specified capture file? { dumpname = configwindow->captureFileName->text(); if ( dumpname.isEmpty() ) dumpname = "captureFile"; dumpname.append( '-' ); dumpname.append( QTime::currentTime().toString().replace( QRegExp( ":" ), "-" ) ); dumpname.append( ".wellenreiter" ); } else // write it anyway ;) { dumpname = "/var/log/dump.wellenreiter"; } if ( cardtype != DEVTYPE_FILE ) pcap->open( interface ); else pcap->open( QFile( interface ) ); - odebug << "Wellenreiter:: dumping to " << (const char*) dumpname << "" << oendl; + odebug << "Wellenreiter:: dumping to " << dumpname << "" << oendl; pcap->openDumpFile( dumpname ); if ( !pcap->isOpen() ) { QMessageBox::warning( this, "Wellenreiter II", tr( "Can't open packet capturer for\n'%1':\n" ).arg( cardtype == DEVTYPE_FILE ? (const char*) interface : iface->name() ) + QString(strerror( errno ) )); return; } // set capturer to non-blocking mode pcap->setBlocking( false ); // start channel hopper if ( cardtype != DEVTYPE_FILE ) { logwindow->log( QString().sprintf( "(i) Starting channel hopper (d=%d ms)", configwindow->hopInterval->value() ) ); iface->setChannelHopping( configwindow->hopInterval->value() ); //use interval from config window } if ( cardtype != DEVTYPE_FILE ) { // connect socket notifier and start channel hopper connect( pcap, SIGNAL( receivedPacket(Opie::Net::OPacket*) ), this, SLOT( receivePacket(Opie::Net::OPacket*) ) ); connect( iface->channelHopper(), SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) ); } else { // start timer for reading packets startTimer( 100 ); } logwindow->log( "(i) Started Scanning." ); sniffing = true; #ifdef QWS if ( WellenreiterConfigWindow::instance()->disablePM->isChecked() ) { QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; } #else #warning FIXME: setScreenSaverMode is not operational on the X11 build #endif emit( startedSniffing() ); if ( cardtype != DEVTYPE_FILE ) channelHopped( 6 ); // set title else { assert( parent() ); ( (QMainWindow*) parent() )->setCaption( tr( "Wellenreiter II - replaying capture file..." ) ); - } + } } void Wellenreiter::timerEvent( QTimerEvent* ) { - odebug << "Wellenreiter::timerEvent()" << oendl; + odebug << "Wellenreiter::timerEvent()" << oendl; OPacket* p = pcap->next(); if ( !p ) // no more packets available { stopClicked(); } else { receivePacket( p ); // We no longer delete packets here. Ownership of the packets is // transferred to the PacketView. //delete p; } } void Wellenreiter::doAction( const QString& action, const QString& protocol, OPacket* p ) { #ifdef QWS if ( action == "TouchSound" ) ODevice::inst()->playTouchSound(); else if ( action == "AlarmSound" ) ODevice::inst()->playAlarmSound(); else if ( action == "KeySound" ) ODevice::inst()->playKeySound(); else if ( action == "LedOn" ) ODevice::inst()->setLedState( Led_Mail, Led_On ); else if ( action == "LedOff" ) ODevice::inst()->setLedState( Led_Mail, Led_Off ); else if ( action == "LogMessage" ) logwindow->log( QString().sprintf( "Got packet with protocol '%s'", (const char*) protocol ) ); else if ( action == "MessageBox" ) QMessageBox::information( this, "Notification!", QString().sprintf( "Got packet with protocol '%s'", (const char*) protocol ) ); #else #warning Actions do not work with Qt/X11 yet #endif } void Wellenreiter::joinNetwork(const QString& type, const QString& essid, int channel, const QString& macaddr) { #ifdef QWS if ( !iface ) { QMessageBox::warning( this, tr( "Can't do that!" ), tr( "No wireless\ninterface available." ) ); return; } if ( sniffing ) { QMessageBox::warning( this, tr( "Can't do that!" ), tr( "Stop sniffing before\njoining a net." ) ); return; } qDebug( "joinNetwork() with Interface %s: %s, %s, %d, %s", (const char*) iface->name(), (const char*) type, (const char*) essid, channel, (const char*) macaddr ); QCopEnvelope msg( "QPE/Application/networksettings", "wlan(QString,QString,QString)" ); int count = 3; - odebug << "sending " << count << " messages" << oendl; + odebug << "sending " << count << " messages" << oendl; msg << QString("count") << QString::number(count); - odebug << "msg >" << iface->name() << "< Mode >" << type.latin1() << "<" << oendl; + odebug << "msg >" << iface->name() << "< Mode >" << type.latin1() << "<" << oendl; msg << QString(iface->name()) << QString("Mode") << type; - odebug << "msg >" << iface->name() << "< essid >" << essid.latin1() << "<" << oendl; + odebug << "msg >" << iface->name() << "< essid >" << essid.latin1() << "<" << oendl; msg << QString(iface->name()) << QString("ESSID") << essid; - odebug << "msg >" << iface->name() << "< channel >" << channel << "<" << oendl; + odebug << "msg >" << iface->name() << "< channel >" << channel << "<" << oendl; msg << QString(iface->name()) << QString("Channel") << channel; -// odebug << "msg >" << iface->name() << "< mac >" << macaddr << "<" << oendl; +// odebug << "msg >" << iface->name() << "< mac >" << macaddr << "<" << oendl; // msg << QString(iface->name()) << QString("MacAddr") << macaddr; #else QMessageBox::warning( this, tr( "Can't do that!" ), tr( "Function only available on Embedded build" ) ); #endif } 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 @@ #include "wlanimp2.h" #include "keyedit.h" #include "interfacesetupimp.h" #include "../interfaces/interface.h" #include <assert.h> #include <errno.h> #include <string.h> #include <qapplication.h> #include <qfile.h> #include <qdir.h> #include <qdialog.h> #include <qtextstream.h> #include <qmessagebox.h> #include <qlineedit.h> #include <qlabel.h> #include <qspinbox.h> #include <qradiobutton.h> #include <qpushbutton.h> #include <qcheckbox.h> #include <qtabwidget.h> #include <qcombobox.h> #include <qlistview.h> #include <qvbox.h> #include <qprogressbar.h> #ifdef QWS #include <qpe/resource.h> #include <opie2/oprocess.h> #include <opie2/onetwork.h> #include <opie2/opcap.h> #else #define OProcess KProcess #include <kprocess.h> #endif #define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" #define PREUP "/etc/network/if-pre-up.d/wireless-tools" /** * Constructor, read in the wireless.opts file for parsing later. */ using namespace Opie::Net; using namespace Opie::Core; WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : WLAN(parent, name, modal, fl), interface(i), currentProfile("*") { interfaces = new Interfaces(); interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, interfaces); tabWidget->insertTab(interfaceSetup, "TCP/IP"); // Check sanity - the existance of the wireless-tools if-pre-up script QFile file(QString(PREUP)); if (file.exists()) { owarn << QString("WLANImp: Unable to open /etc/network/if-pre-up.d/wireless-tools") << oendl; } connect( rescanButton, SIGNAL( clicked() ), this, SLOT( rescanNeighbourhood() ) ); connect( netView, SIGNAL( clicked(QListViewItem*) ), this, SLOT( selectNetwork(QListViewItem*) ) ); netView->setColumnAlignment( col_chn, AlignCenter ); netView->setItemMargin( 3 ); netView->setAllColumnsShowFocus( true ); } WLANImp::~WLANImp() { //FIXME: delete interfaces; } /** * Change the profile for both wireless settings and network settings. */ void WLANImp::setProfile(const QString &profile){ interfaceSetup->setProfile(profile); parseOpts(); } void WLANImp::parseOpts() { bool error; QString opt; if (! interfaces->isInterfaceSet()) return; opt = interfaces->getInterfaceOption("wireless_essid", error); if(opt == "any" || opt == "off" || opt.isNull()){ essid->setEditText("any"); } else { essid->setEditText(opt); } opt = interfaces->getInterfaceOption("wireless_mode", error).simplifyWhiteSpace(); for ( int i = 0; i < mode->count(); i++) if ( mode->text( i ) == opt ) mode->setCurrentItem( i ); opt = interfaces->getInterfaceOption("wireless_ap", error).simplifyWhiteSpace(); if (! opt.isNull()) { specifyAp->setChecked(true); macEdit->setText(opt); } opt = interfaces->getInterfaceOption("wireless_channel", error).simplifyWhiteSpace(); if (! opt.isNull()) { specifyChan->setChecked(true); networkChannel->setValue(opt.toInt()); } opt = interfaces->getInterfaceOption("wireless_key", error).simplifyWhiteSpace(); if (opt.isNull()) opt = interfaces->getInterfaceOption("wireless_enc", error).simplifyWhiteSpace(); parseKeyStr(opt); } void WLANImp::parseKeyStr(QString keystr) { int loc = 0; int index = 1; QString key; QStringList keys = QStringList::split(QRegExp("\\s+"), keystr); int enc = -1; // encryption state for (QStringList::Iterator it = keys.begin(); it != keys.end(); ++it) { if ((*it).left(3) == "off") { // encryption disabled enc = 0; } else if ((*it).left(2) == "on") { // encryption enabled enc = 1; } else if ((*it).left(4) == "open") { // open mode, accept non encrypted packets acceptNonEnc->setChecked(true); } else if ((*it).left(10) == "restricted") { // restricted mode, only accept encrypted packets rejectNonEnc->setChecked(true); } else if ((*it).left(3) == "key") { // new set of options } else if ((*it).left(1) == "[") { index = (*it).mid(1, 1).toInt(); // switch current key to index switch (index) { case 1: keyRadio0->setChecked(true); break; case 2: keyRadio1->setChecked(true); break; case 3: keyRadio2->setChecked(true); break; case 4: keyRadio3->setChecked(true); break; } } else { // key key = (*it); } if (! key.isNull()) { if (enc == -1) enc = 1; QStringList::Iterator next = ++it; if (it == keys.end()) { break; } if ((*(next)).left(1) == "[") { // set key at index index = (*(next)).mid(1, 1).toInt(); } else { index = 1; } switch (index) { case 1: keyLineEdit0->setText(key); break; case 2: keyLineEdit1->setText(key); break; case 3: keyLineEdit2->setText(key); break; case 4: keyLineEdit3->setText(key); break; } key = QString::null; } } if (enc == 1) { wepEnabled->setChecked(true); } else { wepEnabled->setChecked(false); } } /** * Check to see if the current config is valid * Save interfaces */ void WLANImp::accept() { if (wepEnabled->isChecked()) { if ((keyRadio0->isChecked() && keyLineEdit0->text().isEmpty()) || (keyRadio1->isChecked() && keyLineEdit1->text().isEmpty()) || (keyRadio2->isChecked() && keyLineEdit2->text().isEmpty()) || (keyRadio3->isChecked() && keyLineEdit3->text().isEmpty())) { QMessageBox::information(this, "Error", "Please enter a WEP key.", QMessageBox::Ok); return; } } if (essid->currentText().isEmpty()) { QMessageBox::information(this, "Error", "Please select/enter an ESSID.", QMessageBox::Ok); return; } if (specifyAp->isChecked() && macEdit->text().isEmpty()) { QMessageBox::information(this, "Error", "Please enter the MAC address of the Access Point.", QMessageBox::Ok); return; } // Try to save the interfaces settings. writeOpts(); // Close out the dialog // FIXME: QDialog::accept(); } void WLANImp::writeOpts() { // eh can't really do anything about it other then return. :-D if(!interfaces->isInterfaceSet()){ QMessageBox::warning(0,"Inface not set","should not happen!!!"); return; } bool error = false; odebug << "setting wlan interface " << interfaces->getInterfaceName( error ).latin1() << "" << oendl; if (error) QMessageBox::warning(0,"Inface not set","should not happen!!!"); interfaces->setInterfaceOption(QString("wireless_mode"), mode->currentText()); interfaces->setInterfaceOption(QString("wireless_essid"), essid->currentText()); if (specifyAp->isChecked()) { interfaces->setInterfaceOption(QString("wireless_ap"), macEdit->text()); } else { interfaces->removeInterfaceOption(QString("wireless_ap")); } if (specifyChan->isChecked()) { interfaces->setInterfaceOption(QString("wireless_channel"), networkChannel->text()); } else { interfaces->removeInterfaceOption(QString("wireless_channel")); } if (wepEnabled->isChecked()) { QStringList keyList; if (! keyLineEdit0->text().isNull()) { keyList += keyLineEdit0->text(); keyList += "[1]"; } //else if (! keyLineEdit1->text().isNull()) { keyList += keyLineEdit1->text(); keyList += "[2]"; } //else if (! keyLineEdit2->text().isNull()) { keyList += keyLineEdit2->text(); keyList += "[3]"; } //else if (! keyLineEdit3->text().isNull()) { keyList += keyLineEdit3->text(); keyList += "[4]"; } if (acceptNonEnc->isChecked()) { keyList += "open"; } else { keyList += "restricted"; } keyList += "key"; if (keyRadio0->isChecked()) { keyList += "[1]"; } else if (keyRadio1->isChecked()) { keyList += "[2]"; } else if (keyRadio2->isChecked()) { keyList += "[3]"; } else if (keyRadio3->isChecked()) { keyList += "[4]"; } interfaces->setInterfaceOption(QString("wireless_key"), keyList.join(QString(" "))); } else { interfaces->removeInterfaceOption(QString("wireless_key")); } interfaces->removeInterfaceOption(QString("wireless_enc")); if(!interfaceSetup->saveChanges()) return; QDialog::accept(); } /* * Scan for possible wireless networks around... * ... powered by Wellenreiter II technology (C) Michael 'Mickey' Lauer <mickeyl@handhelds.org> */ void WLANImp::rescanNeighbourhood() { QString name = interface->getInterfaceName(); - odebug << "rescanNeighbourhood via '" << (const char*) name << "'" << oendl; + odebug << "rescanNeighbourhood via '" << name << "'" << oendl; OWirelessNetworkInterface* wiface = static_cast<OWirelessNetworkInterface*>( ONetwork::instance()->interface( name ) ); assert( wiface ); // try to guess device type QString devicetype; QFile m( "/proc/modules" ); if ( m.open( IO_ReadOnly ) ) { QString line; QTextStream modules( &m ); while( !modules.atEnd() && !devicetype ) { modules >> line; if ( line.contains( "cisco" ) ) devicetype = "cisco"; else if ( line.contains( "hostap" ) ) devicetype = "hostap"; else if ( line.contains( "prism" ) ) devicetype = "wlan-ng"; /* puke */ else if ( line.contains( "orinoco" ) ) devicetype = "orinoco"; } } if ( devicetype.isEmpty() ) { owarn << "rescanNeighbourhood(): couldn't guess device type :(" << oendl; return; } else { - odebug << "rescanNeighbourhood(): device type seems to be '" << (const char*) devicetype << "'" << oendl; + odebug << "rescanNeighbourhood(): device type seems to be '" << devicetype << "'" << oendl; } // configure interface to receive 802.11 management frames wiface->setUp( true ); wiface->setPromiscuousMode( true ); if ( devicetype == "cisco" ) wiface->setMonitoring( new OCiscoMonitoringInterface( wiface, false ) ); else if ( devicetype == "hostap" ) wiface->setMonitoring( new OHostAPMonitoringInterface( wiface, false ) ); else if ( devicetype == "wlan-ng" ) wiface->setMonitoring( new OWlanNGMonitoringInterface( wiface, false ) ); else if ( devicetype == "orinoco" ) wiface->setMonitoring( new OOrinocoMonitoringInterface( wiface, false ) ); else { odebug << "rescanNeighbourhood(): unsupported device type for monitoring :(" << oendl; return; } wiface->setMode( "monitor" ); if ( wiface->mode() != "monitor" ) { owarn << "rescanNeighbourhood(): Unable to bring device into monitor mode (" << strerror( errno ) << ")." << oendl; return; } // open a packet capturer OPacketCapturer* cap = new OPacketCapturer(); cap->open( name ); if ( !cap->isOpen() ) { owarn << "rescanNeighbourhood(): Unable to open libpcap (" << strerror( errno ) << ")." << oendl; return; } // display splash screen QFrame* splash = new QFrame( this, "splash", false, WStyle_StaysOnTop | WStyle_DialogBorder | WStyle_Customize ); splash->setLineWidth( 2 ); splash->setFrameStyle( QFrame::Panel | QFrame::Raised ); QVBoxLayout* vbox = new QVBoxLayout( splash, 4, 4 ); QLabel* lab = new QLabel( "<center><b>Scanning...</b><br>Please Wait...</center>", splash ); QProgressBar* pb = new QProgressBar( wiface->channels(), splash ); vbox->addWidget( lab ); vbox->addWidget( pb ); pb->setCenterIndicator( true ); pb->setFixedHeight( pb->sizeHint().height() ); QWidget* widgetDesktop = qApp->desktop(); int dw = widgetDesktop->width(); int dh = widgetDesktop->height(); int pw = vbox->sizeHint().width(); int ph = vbox->sizeHint().height(); splash->setGeometry((dw-pw)/2,(dh-ph)/2,pw,ph); splash->show(); splash->raise(); qApp->processEvents(); // set capturer to non-blocking mode cap->setBlocking( false ); for ( int i = 1; i <= wiface->channels(); ++i ) { wiface->setChannel( i ); pb->setProgress( i ); qApp->processEvents(); odebug << "rescanNeighbourhood(): listening on channel " << i << "..." << oendl; OPacket* p = cap->next( 1000 ); if ( !p ) { odebug << "rescanNeighbourhood(): nothing received on channel " << i << "" << oendl; } else { odebug << "rescanNeighbourhood(): TADAA - something came in on channel " << i << "" << oendl; handlePacket( p ); } } cap->close(); wiface->setMode( "managed" ); // TODO: use previous mode wiface->setPromiscuousMode( false ); splash->hide(); delete splash; } void WLANImp::handlePacket( OPacket* p ) { // check if we received a beacon frame OWaveLanManagementPacket* beacon = static_cast<OWaveLanManagementPacket*>( p->child( "802.11 Management" ) ); if ( beacon && beacon->managementType() == "Beacon" ) { QString type; if ( beacon->canIBSS() ) { type = "adhoc"; } else if ( beacon->canESS() ) { type = "managed"; } else { owarn << "handlePacket(): invalid frame [possibly noise] detected!" << oendl; return; } OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); QString essid = ssid ? ssid->ID() : QString("<unknown>"); OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) ); int channel = ds ? ds->channel() : -1; OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) ); displayFoundNetwork( type, channel, essid, header->macAddress2() ); } } void WLANImp::displayFoundNetwork( const QString& mode, int channel, const QString& ssid, const OMacAddress& mac ) { qDebug( "found network: <%s>, chn %d, ssid '%s', mac '%s'", (const char*) mode, channel, (const char*) ssid, (const char*) mac.toString() ); QListViewItemIterator it( netView ); while ( it.current() && it.current()->text( col_ssid ) != ssid ) ++it; if ( !it.current() ) // ssid didn't show up yet { QListViewItem* item = new QListViewItem( netView, mode.left( 1 ).upper(), ssid, QString::number( channel ), mac.toString() ); QString name; name.sprintf( "networksettings/%s", (const char*) mode ); item->setPixmap( col_mode, Resource::loadPixmap( name ) ); qApp->processEvents(); } } void WLANImp::selectNetwork( QListViewItem* item ) { bool ok; if ( item ) { specifyAp->setChecked(true); macEdit->setText( item->text( col_mac ) ); specifyChan->setChecked( item->text( col_mode ) == "A" ); networkChannel->setValue( item->text( col_chn ).toInt( &ok ) ); essid->setEditText( item->text( col_ssid ) ); if ( item->text( col_mode ) == "A" ) mode->setCurrentItem( 3 ); else mode->setCurrentItem( 2 ); } } 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 @@ /********************************************************************** ** BenchmarkInfo ** ** A benchmark for Qt/Embedded ** ** Copyright (C) 2004 Michael Lauer <mickey@vanille.de> ** Inspired by ZBench (C) 2002 Satoshi <af230533@im07.alpha-net.ne.jp> ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** **********************************************************************/ #include "benchmarkinfo.h" /* OPIE */ #include <opie2/odebug.h> #include <opie2/ostorageinfo.h> #include <opie2/olistview.h> #include <qpe/qpeapplication.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/qpedecoration_qws.h> #include <qpe/resource.h> #include <qpe/config.h> using namespace Opie::Core; using namespace Opie::Ui; /* QT */ #include <qclipboard.h> #include <qcolor.h> #include <qcombobox.h> #include <qdirectpainter_qws.h> #include <qfile.h> #include <qtextstream.h> #include <qfiledialog.h> #include <qlabel.h> #include <qlayout.h> #include <qpainter.h> #include <qpushbutton.h> #include <qtimer.h> #include <qwhatsthis.h> /* STD */ #include <time.h> #include <stdio.h> #include <stdlib.h> #include <math.h> #if defined (__GNUC__) && (__GNUC__ < 3) #define round qRound #endif extern "C" { void BenchFFT( void ); double dhry_main( int ); } #define DHRYSTONE_RUNS 20000000 #define TEST_DURATION 3 #define BUFF_SIZE 8192 #define FILE_SIZE 1024 * 1024 // 1Mb //=========================================================================== class BenchmarkPaintWidget : public QWidget { public: BenchmarkPaintWidget() : QWidget( 0, "Benchmark Paint Widget", WStyle_Customize|WStyle_StaysOnTop|WPaintUnclipped|WPaintClever ) { resize( QApplication::desktop()->size() ); show(); p.begin( this ); }; ~BenchmarkPaintWidget() { p.end(); hide(); }; QPainter p; }; //=========================================================================== BenchmarkInfo::BenchmarkInfo( QWidget *parent, const char *name, int wFlags ) : QWidget( parent, name, wFlags ) { setMinimumSize( 200, 150 ); QVBoxLayout* vb = new QVBoxLayout( this ); vb->setSpacing( 4 ); vb->setMargin( 4 ); tests = new OListView( this ); QWhatsThis::add( tests->viewport(), tr( "This area shows the available tests, the results for which the tests " "have been performed, and comparison values for one selected device. " "Use the checkboxes to define which tests you want to perform." ) ); tests->setMargin( 0 ); tests->addColumn( tr( "Tests" ) ); tests->addColumn( tr( "Results" ) ); tests->addColumn( tr( "Comparison" ) ); tests->setShowSortIndicator( true ); test_alu = new OCheckListItem( tests, tr( "1. Integer Arithmetic " ), OCheckListItem::CheckBox ); test_fpu = new OCheckListItem( tests, tr( "2. Floating Point Unit " ), OCheckListItem::CheckBox ); test_txt = new OCheckListItem( tests, tr( "3. Text Rendering " ), OCheckListItem::CheckBox ); test_gfx = new OCheckListItem( tests, tr( "4. Gfx Rendering " ), OCheckListItem::CheckBox ); test_ram = new OCheckListItem( tests, tr( "5. RAM Performance " ), OCheckListItem::CheckBox ); test_sd = new OCheckListItem( tests, tr( "6. SD Card Performance " ), OCheckListItem::CheckBox ); test_cf = new OCheckListItem( tests, tr( "7. CF Card Performance " ), OCheckListItem::CheckBox ); test_alu->setText( 1, "n/a" ); test_fpu->setText( 1, "n/a" ); test_txt->setText( 1, "n/a" ); test_gfx->setText( 1, "n/a" ); test_ram->setText( 1, "n/a" ); test_sd->setText( 1, "n/a" ); test_cf->setText( 1, "n/a" ); test_alu->setText( 2, "n/a" ); test_fpu->setText( 2, "n/a" ); test_txt->setText( 2, "n/a" ); test_gfx->setText( 2, "n/a" ); test_ram->setText( 2, "n/a" ); test_sd->setText( 2, "n/a" ); test_cf->setText( 2, "n/a" ); startButton = new QPushButton( tr( "&Start Tests!" ), this ); QWhatsThis::add( startButton, tr( "Click here to perform the selected tests." ) ); connect( startButton, SIGNAL( clicked() ), this, SLOT( run() ) ); vb->addWidget( tests, 2 ); QFile f( QPEApplication::qpeDir() + "/share/sysinfo/results" ); if ( f.open( IO_ReadOnly ) ) { machineCombo = new QComboBox( this ); QWhatsThis::add( machineCombo, tr( "Choose a model to compare your results with." ) ); QTextStream ts( &f ); while( !ts.eof() ) { QString machline = ts.readLine(); - odebug << "sysinfo: parsing benchmark results for '" << (const char*) machline << "'" << oendl; + odebug << "sysinfo: parsing benchmark results for '" << machline << "'" << oendl; QString resline = ts.readLine(); machines.insert( machline, new QStringList( QStringList::split( ",", resline ) ) ); machineCombo->insertItem( machline ); } QHBoxLayout* hb = new QHBoxLayout( vb ); hb->addWidget( new QLabel( tr( "Compare To:" ), this ) ); hb->addWidget( machineCombo, 2 ); connect( machineCombo, SIGNAL( activated(int) ), this, SLOT( machineActivated(int) ) ); } vb->addWidget( startButton, 2 ); } BenchmarkInfo::~BenchmarkInfo() {} void BenchmarkInfo::machineActivated( int index ) { QStringList* results = machines[ machineCombo->text( index ) ]; if ( !results ) { odebug << "sysinfo: no results available." << oendl; return; } QStringList::Iterator it = results->begin(); test_alu->setText( 2, *(it++) ); test_fpu->setText( 2, *(it++) ); test_txt->setText( 2, *(it++) ); test_gfx->setText( 2, *(it++) ); test_ram->setText( 2, *(it++) ); test_sd->setText( 2, *(it++) ); test_cf->setText( 2, *(it++) ); } void BenchmarkInfo::run() { startButton->setText( "> Don't touch! Running Tests! Don't touch! <" ); qApp->processEvents(); QTime t; if ( test_alu->isOn() ) { int d = round( dhry_main( DHRYSTONE_RUNS ) ); test_alu->setText( 1, QString( "%1 dhrys" ).arg( QString::number( d ) ) ); test_alu->setOn( false ); } if ( test_fpu->isOn() ) { t.start(); BenchFFT(); test_fpu->setText( 1, QString( "%1 secs" ).arg( QString::number( t.elapsed() / 1000.0 ) ) ); test_fpu->setOn( false ); } if ( test_txt->isOn() ) { int value = textRendering( TEST_DURATION ); test_txt->setText( 1, QString( "%1 chars/sec" ).arg( QString::number( value / TEST_DURATION ) ) ); test_txt->setOn( false ); } if ( test_gfx->isOn() ) { int value = gfxRendering( TEST_DURATION ); test_gfx->setText( 1, QString( "%1 gops/sec" ).arg( QString::number( value / 4 / TEST_DURATION ) ) ); // 4 tests test_gfx->setOn( false ); } if ( test_ram->isOn() ) // /tmp is supposed to be in RAM on a PDA { performFileTest( "/tmp/benchmarkFile.dat", test_ram ); } if ( test_cf->isOn() ) { OStorageInfo storage; performFileTest( storage.cfPath() + "/benchmarkFile.dat", test_cf ); } if ( test_sd->isOn() ) { OStorageInfo storage; performFileTest( storage.sdPath() + "/benchmarkFile.dat", test_sd ); } startButton->setText( tr( "&Start Tests!" ) ); } int BenchmarkInfo::textRendering( int seconds ) { QTime t; t.start(); int stop = t.elapsed() + seconds * 1000; int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 }; int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 }; int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 }; const QString text( "Opie Benchmark Test" ); int w = QApplication::desktop()->width(); int h = QApplication::desktop()->height(); srand( time( NULL ) ); BenchmarkPaintWidget bpw; int loops = 0; while ( t.elapsed() < stop ) { int k = rand() % 9; int s = rand() % 100; bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); bpw.p.setFont( QFont( "Vera", s ) ); bpw.p.drawText( rand() % w, rand() % h, text, text.length() ); ++loops; } return loops * text.length(); } int BenchmarkInfo::gfxRendering( int seconds ) { int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 }; int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 }; int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 }; int w = QApplication::desktop()->width(); int h = QApplication::desktop()->height(); srand( time( NULL ) ); BenchmarkPaintWidget bpw; QTime t; t.start(); int stop = t.elapsed() + seconds*1000; int loops = 0; while ( t.elapsed() < stop ) { int k = rand() % 9; bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); bpw.p.drawLine( rand()%w, rand()%h, rand()%w, rand()%h ); ++loops; } t.restart(); stop = t.elapsed() + seconds*1000; while ( t.elapsed() < stop ) { int k = rand() % 9; bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); bpw.p.drawArc( rand()%w, rand()%h, rand()%w, rand()%h, 360 * 16, 360 * 16 ); ++loops; } QBrush br1; br1.setStyle( SolidPattern ); t.restart(); stop = t.elapsed() + seconds*1000; while ( t.elapsed() < stop ) { int k = rand() % 9; br1.setColor( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); bpw.p.fillRect( rand()%w, rand()%h, rand()%w, rand()%h, br1 ); ++loops; } QPixmap p = Resource::loadPixmap( "sysinfo/pattern" ); t.restart(); stop = t.elapsed() + seconds*1000; while ( t.elapsed() < stop ) { bpw.p.drawPixmap( rand()%w, rand()%h, p ); ++loops; } return loops; } void BenchmarkInfo::performFileTest( const QString& fname, OCheckListItem* item ) { QTime time; time.start(); if ( writeFile( fname ) && readFile( fname ) ) { QFile::remove( fname ); item->setText( 1, QString( "%1 kb/sec" ).arg( QString::number( 1024.0 / ( time.elapsed() / 1000.0 ) ) ) ); item->setOn( false ); } else { item->setText( 1, tr( "error" ) ); } } char FileBuf[ BUFF_SIZE + 1 ]; bool BenchmarkInfo::writeFile( const QString& w_path ) { int i; int k; int n; int pos; int len; char *data = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; // 62 // /*------------------------------------ int w_len; QFile writeFile( w_path ); srand( time( NULL ) ); for ( n = 0 ; n < 20 ; n++ ) { if ( ! writeFile.open( IO_WriteOnly ) ) { writeFile.close(); writeFile.remove(); return ( false ); } // ------------------------------------------ sequential write for ( k = 0 ; k < 256 ; k++ ) { n = rand() % 30; memcpy( &FileBuf[ k * 32 ], &data[ n ], 32 ); } for ( i = 0 ; i < FILE_SIZE / BUFF_SIZE ; i++ ) { w_len = writeFile.writeBlock( FileBuf, BUFF_SIZE ); if ( w_len != BUFF_SIZE ) { writeFile.close(); writeFile.remove(); return ( false ); } writeFile.flush(); } // ------------------------------------------ random write for ( i = 0 ; i < 400 ; i++ ) { len = rand() % 90 + 4000; for ( k = 0 ; k < 128 ; k++ ) { n = rand() % 30; memcpy( &FileBuf[ k * 8 ], &data[ n ], 32 ); } pos = rand() % ( FILE_SIZE - BUFF_SIZE ); writeFile.at( pos ); w_len = writeFile.writeBlock( FileBuf, len ); if ( w_len != len ) { writeFile.close(); writeFile.remove(); return ( false ); } writeFile.flush(); } writeFile.close(); } return ( true ); } bool BenchmarkInfo::readFile( const QString& r_path ) { int i; int k; int len; int pos; int r_len; QFile readFile( r_path ); srand( time( NULL ) ); for ( k = 0 ; k < 200 ; k++ ) { if ( ! readFile.open( IO_ReadOnly ) ) { readFile.remove(); return ( false ); } // ------------------------------------------ sequential read readFile.at( 0 ); for ( i = 0 ; i < FILE_SIZE / BUFF_SIZE ; i++ ) { readFile.at( i * BUFF_SIZE ); r_len = readFile.readBlock( FileBuf, BUFF_SIZE ); if ( r_len != BUFF_SIZE ) { readFile.close(); readFile.remove(); return ( false ); } } // ------------------------------------------ random read for ( i = 0 ; i < 1000 ; i++ ) { len = rand() % 120 + 8; pos = rand() % ( FILE_SIZE / BUFF_SIZE - BUFF_SIZE ); readFile.at( pos ); r_len = readFile.readBlock( FileBuf, len ); if ( r_len != len ) { readFile.close(); readFile.remove(); return ( false ); } } readFile.close(); } return ( true ); } |