diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | bcb704366cb5e333a626c18c308c7e0448a8e69f (patch) | |
tree | f0d6ab7d78ecdd9207cf46536376b44b91a1ca71 /wifi/kwireless | |
download | tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.tar.gz tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'wifi/kwireless')
-rw-r--r-- | wifi/kwireless/Makefile.am | 17 | ||||
-rw-r--r-- | wifi/kwireless/kwireless.cpp | 89 | ||||
-rw-r--r-- | wifi/kwireless/kwireless.desktop | 118 | ||||
-rw-r--r-- | wifi/kwireless/kwireless.h | 46 | ||||
-rw-r--r-- | wifi/kwireless/kwirelesswidget.cpp | 324 | ||||
-rw-r--r-- | wifi/kwireless/kwirelesswidget.h | 103 | ||||
-rw-r--r-- | wifi/kwireless/linuxwirelesswidget.cpp | 227 | ||||
-rw-r--r-- | wifi/kwireless/linuxwirelesswidget.h | 36 | ||||
-rw-r--r-- | wifi/kwireless/propertytable.cpp | 151 | ||||
-rw-r--r-- | wifi/kwireless/propertytable.h | 45 | ||||
-rw-r--r-- | wifi/kwireless/propertytablebase.ui | 68 |
11 files changed, 1224 insertions, 0 deletions
diff --git a/wifi/kwireless/Makefile.am b/wifi/kwireless/Makefile.am new file mode 100644 index 00000000..d5b4fcf7 --- /dev/null +++ b/wifi/kwireless/Makefile.am @@ -0,0 +1,17 @@ +INCLUDES= $(all_includes) +METASOURCES = AUTO + +lib_LTLIBRARIES = libkwireless.la + +libkwireless_la_SOURCES = kwireless.cpp \ + kwirelesswidget.cpp \ + linuxwirelesswidget.cpp \ + propertytablebase.ui propertytable.cpp +libkwireless_la_LDFLAGS = -module -avoid-version $(all_libraries) +libkwireless_la_LIBADD = -liw $(LIB_KDEUI) + +kwireless_DATA = kwireless.desktop +kwirelessdir = $(kde_datadir)/kicker/applets + +messages: rc.cpp + $(XGETTEXT) *.cpp -o $(podir)/kwireless.pot diff --git a/wifi/kwireless/kwireless.cpp b/wifi/kwireless/kwireless.cpp new file mode 100644 index 00000000..ff584603 --- /dev/null +++ b/wifi/kwireless/kwireless.cpp @@ -0,0 +1,89 @@ +/* + $ Author: Mirko Boehm $ + $ License: This code is licensed under the LGPL $ + $ Copyright: (C) 1996-2003, Mirko Boehm $ + $ Contact: Mirko Boehm <[email protected]> + http://www.kde.org + http://www.hackerbuero.org $ +*/ + +#include <kglobal.h> +#include <klocale.h> +#include <kconfig.h> +#include <kapplication.h> +#include <kmessagebox.h> + +#include "kwireless.h" +#include "kwirelesswidget.h" + + +KWireLess::KWireLess(const QString& configFile, Type type, + int actions, QWidget *parent, const char *name) + : KPanelApplet(configFile, type, actions, parent, name) +{ + ksConfig = config(); + + widget = KWireLessWidget::makeWireLessWidget(this); + widget->show(); +} + + +KWireLess::~KWireLess() +{ +} + + +void KWireLess::about() +{ + KMessageBox::information + (0, + i18n("<qt><b>KWireLess</b><br>" + "Displays information about wireless network devices.<br />" + "KWireLess is licensed to you under the terms of the GPL.<br />" + "<i>(C) 2003 Mirko Boehm</i></qt>"), + i18n("About KWireLess")); +} + + +void KWireLess::help() +{ +// KMessageBox::information(0, i18n("This is a help box")); +} + + +void KWireLess::preferences() +{ +// KMessageBox::information(0, i18n("This is a preferences box")); +} + +int KWireLess::widthForHeight(int) const +{ + widget->setMode(KWireLessWidget::Vertical); + return widget->preferredWidth(); +} + +int KWireLess::heightForWidth(int) const +{ + widget->setMode(KWireLessWidget::Horizontal); + return widget->preferredHeight(); +} + +void KWireLess::resizeEvent(QResizeEvent *) +{ + widget->setGeometry(0, 0, width(), height()); +} + + +extern "C" +{ + KDE_EXPORT KPanelApplet* init( QWidget *parent, const QString configFile) + { + KGlobal::locale()->insertCatalogue("kwireless"); + return new KWireLess(configFile, KPanelApplet::Normal, + KPanelApplet::About, + // | KPanelApplet::Help | KPanelApplet::Preferences, + parent, "kwireless"); + } +} + +#include "kwireless.moc" diff --git a/wifi/kwireless/kwireless.desktop b/wifi/kwireless/kwireless.desktop new file mode 100644 index 00000000..8564c742 --- /dev/null +++ b/wifi/kwireless/kwireless.desktop @@ -0,0 +1,118 @@ +[Desktop Entry] +Comment=Displays information about wireless network devices +Comment[ar]=عرض معلومات أجهزة الشبكة الاسلكية +Comment[bg]=Данни за устройствата поддържащи безжичната мрежа +Comment[bn]=ওয়্যারলেস নেটওয়ার্ক ডিভাইস সম্বন্ধে তথ্য প্রদর্শন করে +Comment[bs]=Prikazuje informacije o bežičnim mrežnim uređajima +Comment[ca]=Mostra informació quant als dispositius de la xarxa sense fils +Comment[cs]=Zobrazuje informace o bezdrátových síťových zařízeních +Comment[cy]=Dangos gwybodaeth ynglyn â dyfeisiau rhwydwaith di-wifr +Comment[da]=Giver oplysninger om trådløse netværksenheder +Comment[de]=Zeigt Informationen zu Geräten für drahtlose Netzwerke an +Comment[el]=Εμφανίζει πληροφορίες για συσκευές ασύρματου δικτύου +Comment[es]=Muestra información acerca de los dispositivos de la red inalámbrica +Comment[et]=Näitab infot traadita võrgu seadmete kohta +Comment[eu]=Kablerik gabeko sare gailuen informazioa erakusten du +Comment[fa]=اطلاعاتی دربارۀ دستگاههای شبکۀ بیسیم را نمایش میدهد +Comment[fi]=Tietoja langattoman verkon laitteista +Comment[fr]=Affiche des informations sur les périphériques réseau sans fil +Comment[gl]=Información sobre os dispositivos de rede inalámbirca +Comment[he]=מציג מידע ונתונים על התקני רשת אלחוטית +Comment[hi]=वायरलेस नेटवर्क औज़ार के बारे में जानकारी दिखाए +Comment[hr]=Prikazuje informacije o bežičnim mrežnim uređajima +Comment[hu]=Megjeleníti a vezeték nélküli hálózatok csatolókártyáinak jellemzőit +Comment[is]=Sýnir upplýsingar um tæki fyrir þráðlausar nettengingar +Comment[it]=Visualizza informazioni sui dispositivi di rete senza fili +Comment[ja]=ワイヤレスネットワークデバイスの情報を表示 +Comment[ka]=უკაბელო ქსელების მოწყობილობების შესახებ ინფორმაცია +Comment[kk]=Сымсыз желі құрылғылар туралы мәлімет береді +Comment[km]=បង្ហាញព័ត៌មានអំពីឧបករណ៍បណ្ដាញឥតខ្សែ +Comment[lt]=Pateikia informaciją apie bevielio ryšio įrangą +Comment[mk]=Прикажува информации за уредите на безжичната мрежа +Comment[ms]=Memaparkan maklumat berkaitan peranti jaringan tanpa wayar +Comment[nb]=Viser informasjon om enheter for trådløst nettverk +Comment[nds]=Wiest Informatschonen över Funknettwark-Reedschappen +Comment[ne]=तारविहिन सञ्जाल यन्त्रबारे सूचना प्रदर्शन गर्दछ +Comment[nl]=Toont informatie over draadloze netwerkapparaten +Comment[nn]=Viser informasjon om einingar for trådlause nettverk +Comment[pl]=Wyświetla informacje o bezprzewodowych kartach sieciowych +Comment[pt]=Mostra informações sobre os dispositivos de rede sem-fios ('wireless') +Comment[pt_BR]=Mostra informação sobre dispositivos de rede sem fio +Comment[ru]=Отображает сведения о беспроводных сетевых устройствах +Comment[se]=Čájeha dieđuid jođaskeahttes fierpmádatovttadagaid birra +Comment[sk]=Zobrazí informácie o zariadeniach bezdrôtovej siete +Comment[sl]=Prikaže informacije o napravah brezžičnega omrežja +Comment[sr]=Приказује информације о бежичним мрежним уређајима +Comment[sr@Latn]=Prikazuje informacije o bežičnim mrežnim uređajima +Comment[sv]=Visar information om enheter i trådlösa nätverk +Comment[ta]=கம்பி இல்லா செய்தித்தொடர்பு சாதனம் பற்றிய தகவலைக்காட்டு +Comment[tg]=Ахборотро оиди дастгоҳҳои беноқили шабакавӣ намоиш медиҳад +Comment[tr]=Kablosuz ağ aygıtları hakkında gösterim bilgisi +Comment[uk]=Відображає інформацію про пристрої радіомережі +Comment[uz]=Simsiz tarmoq uskunalari haqida maʼlumotni koʻrsatish +Comment[uz@cyrillic]=Симсиз тармоқ ускуналари ҳақида маълумотни кўрсатиш +Comment[zh_CN]=显示关于无线网络设备的信息 +Comment[zh_HK]=顯示有關無線網絡裝置的資訊 +Comment[zh_TW]=顯示無線網路裝置的資訊 +Name=Wireless Network Information +Name[ar]=معلومات الشبكة الاسلكية +Name[bg]=Данни за безжична мрежа +Name[bn]=ওয়্যারলেস নেটওয়ার্ক তথ্য +Name[br]=Titouroù diwar-benn ar roueded hep neud +Name[bs]=Informacije o bežičnoj mreži +Name[ca]=Informació de la xarxa sense fils +Name[cs]=Informace o bezdrátové síti +Name[cy]=Gwybodaeth Rwydwaith Di-Wifr +Name[da]=Information om trådløst netværk +Name[de]=Informationen über drahtlose Netzwerke +Name[el]=Πληροφορίες ασύρματου δικτύου +Name[eo]=Informoj pri Sendrata Reto +Name[es]=Información de red inalámbrica +Name[et]=Traadita võrgu info +Name[eu]=Kablerik gabeko sarearen informazioa +Name[fa]=اطلاعات شبکۀ بیسیم +Name[fi]=Langattoman verkon tiedot +Name[fr]=Informations sur le réseau sans fil +Name[ga]=Eolas faoi Ghréasán gan sreang +Name[gl]=Información sobre a rede inalámbrica +Name[he]=נתוני רשת אלחוטית +Name[hi]=वायरलेस नेटवर्क जानकारी +Name[hr]=Informacije o bežičnoj mreži +Name[hu]=A vezeték nélküli hálózat jellemzői +Name[is]=Upplýsingar um þráðlausa netið +Name[it]=Informazione rete senza fili +Name[ja]=ワイヤレスネットワーク情報 +Name[ka]=ინფორმაცია უკაბელო ქსელის შესახებ +Name[kk]=Сымсыз желі мәліметі +Name[km]=ព័ត៌មានបណ្ដាញឥតខ្សែ +Name[lt]=Bevielio ryšio tinklo informacija +Name[mk]=Информации за безжичната мрежа +Name[ms]=Maklumat Jaringan Tanpa Wayar +Name[nb]=Informasjon om trådløst nettverk +Name[nds]=Funknettwark-Informatschonen +Name[ne]=तारविहिन सञ्जाल सूचना +Name[nl]=Draadloos netwerk-informatie +Name[nn]=Informasjon om trådlaust nettverk +Name[pa]=ਬੇਤਾਰ ਨੈੱਟਵਰਕ ਜਾਣਕਾਰੀ +Name[pl]=Informacja o sieci bezprzewodowej +Name[pt]=Informação da Rede Sem-Fios ('Wireless') +Name[pt_BR]=Informação sobre Rede Sem Fio +Name[ru]=Сведения о беспроводной сети +Name[se]=Jođaskeahttes fierpmádatdieđut +Name[sk]=Informácie o bezdrôtovej sieti +Name[sl]=Podatki o brezžičnem omrežju +Name[sr]=Информације о бежичној мрежи +Name[sr@Latn]=Informacije o bežičnoj mreži +Name[sv]=Information om trådlöst nätverk +Name[ta]=கம்பியில்லா பிணைய தகவல் +Name[tg]=Ахборот оиди Шабакаи Беноқил +Name[tr]=Kablosuz Ağ Bilgisi +Name[uk]=Інформація про радіомережу +Name[uz]=Simsiz tarmoq haqida maʼlumot +Name[uz@cyrillic]=Симсиз тармоқ ҳақида маълумот +Name[wa]=Informåcion sol rantoele sins fyis +Name[zh_CN]=无线网络信息 +Name[zh_HK]=無線網絡資訊 +Name[zh_TW]=無線網路資訊 +Icon=kwifimanager +X-KDE-Library=libkwireless diff --git a/wifi/kwireless/kwireless.h b/wifi/kwireless/kwireless.h new file mode 100644 index 00000000..5a4597af --- /dev/null +++ b/wifi/kwireless/kwireless.h @@ -0,0 +1,46 @@ +/* + $ Author: Mirko Boehm $ + $ License: This code is licensed under the LGPL $ + $ Copyright: (C) 1996-2003, Mirko Boehm $ + $ Contact: Mirko Boehm <[email protected]> + http://www.kde.org + http://www.hackerbuero.org $ +*/ + +#ifndef KWIRELESS_H +#define KWIRELESS_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <kpanelapplet.h> +#include <qstring.h> +#include <kconfig.h> + +class KWireLessWidget; + +class KWireLess : public KPanelApplet +{ + Q_OBJECT + +public: + KWireLess(const QString& configFile, Type t = Normal, int actions = 0, + QWidget *parent = 0, const char *name = 0); + ~KWireLess(); + + virtual int widthForHeight(int height) const; + virtual int heightForWidth(int width) const; + virtual void about(); + virtual void help(); + virtual void preferences(); + +protected: + void resizeEvent(QResizeEvent *); + +private: + KConfig *ksConfig; + KWireLessWidget *widget; +}; + +#endif diff --git a/wifi/kwireless/kwirelesswidget.cpp b/wifi/kwireless/kwirelesswidget.cpp new file mode 100644 index 00000000..3ae2ff8c --- /dev/null +++ b/wifi/kwireless/kwirelesswidget.cpp @@ -0,0 +1,324 @@ +/* + $ Author: Mirko Boehm $ + $ License: This code is licensed under the LGPL $ + $ Copyright: (C) 1996-2003, Mirko Boehm $ + $ Contact: Mirko Boehm <[email protected]> + http://www.kde.org + http://www.hackerbuero.org $ +*/ + +#include <qtimer.h> +#include <qpainter.h> +#include <qpen.h> +#include <qcolor.h> +#include <qpointarray.h> +#include <kglobalsettings.h> +#include <kdebug.h> +#include <kpassivepopup.h> +#include <klocale.h> + +#include "kwirelesswidget.h" +#include "propertytable.h" +#include "linuxwirelesswidget.h" + +extern "C" { +#include <math.h> +} + +QPtrList<DeviceInfo> KWireLessWidget::deviceInfo; +QMutex KWireLessWidget::mutex; +QTimer *KWireLessWidget::timer; +int KWireLessWidget::m_instances; + +DeviceInfo::DeviceInfo(QString _device, QString _essid, QString _encr, + float _quality, float _signal, float _noise, + int _bitrate) + : m_device(_device), + m_essid(_essid), + m_quality(_quality), + m_noise(_noise), + m_signal(_signal), + m_bitrate(_bitrate), + m_encr(_encr) +{ +} + +float DeviceInfo::quality() +{ + return m_quality; +} + +QString DeviceInfo::qualityString() +{ + return i18n("%1%").arg(QString::number(m_quality*100, 'f', 0)); +} + +float DeviceInfo::signal() +{ + return m_signal; +} + +QString DeviceInfo::signalString() +{ + return i18n("%1%").arg(QString::number(m_signal*100, 'f', 0)); +} + +float DeviceInfo::noise() +{ + return m_noise ; +} + +QString DeviceInfo::noiseString() +{ + return i18n("%1%").arg(QString::number(m_noise*100, 'f', 0)); +} + +const QString& DeviceInfo::device() +{ + return m_device; +} + +const QString& DeviceInfo::essid() +{ + return m_essid; +} + + +QString DeviceInfo::bitrateString() +{ + QString bitrate; + QTextOStream b(&bitrate); + b.precision(2); + + switch((int)log10(m_bitrate)) + { + case 0: + case 1: + case 2: + b << m_bitrate << " bit/s"; + break; + case 3: + case 4: + case 5: + b << m_bitrate/1000 << " kbit/s"; + break; + case 6: + case 7: + case 8: + b << m_bitrate/1000000 << " Mbit/s"; + break; + case 9: + case 10: + case 11: + b << m_bitrate/1000000000 << " Gbit/s"; + break; + default: + b << m_bitrate << " bit/s (!)"; + }; + return bitrate; +} + +bool DeviceInfo::usesEncryption() +{ + return !m_encr.isEmpty(); +} + +QString DeviceInfo::encrString() +{ + if(m_encr.isEmpty()) + { + return i18n("unknown"); + } else { + // we rely on the information provided (that is, it has to + // translated already!): + return m_encr; + } +} + +KWireLessWidget::KWireLessWidget(QWidget *parent, const char* name) + : QWidget(parent, name), + mode(Horizontal), + frameWidth(1), + qualityBarWidth(6), + signalBarWidth(3), + noiseBarWidth(3) +{ + ++m_instances; + deviceInfo.setAutoDelete(true); + // set up the poll timer: + if(timer == 0) + { // this way, only the poll() method of the first instance will + // ever be called (intended behaviour): + timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), SLOT(poll())); + // single shot, will be restartet at the end of poll () + timer->start(100, true); + } +} + +KWireLessWidget::~KWireLessWidget() +{ + --m_instances; +} + +int KWireLessWidget::preferredHeight() +{ + return preferredWidth(); +} + +int KWireLessWidget::preferredWidth() +{ + return 4*frameWidth + qualityBarWidth + signalBarWidth + noiseBarWidth; +} + +int KWireLessWidget::instances() +{ + return m_instances; +} + +void KWireLessWidget::setMode(KWireLessWidget::Mode _mode) +{ + mode = _mode; +} + +void KWireLessWidget::mousePressEvent(QMouseEvent *e) +{ + if( e->button() == QMouseEvent::LeftButton) + { + PropertiesDialog dialog(this); + connect(this, SIGNAL(updateDeviceInfo(QPtrList<DeviceInfo> *)), + &dialog, SLOT(update(QPtrList<DeviceInfo> *))); + dialog.exec(); + } +} + +void KWireLessWidget::paintEvent(QPaintEvent*) +{ + // WORK_TO_DO: paint other devices, too: + // for quick repaints, we need a buffered painter! + int w, h, space; + const int bevel = qualityBarWidth/2; + QPainter painter(this); + QPointArray points; + QColor color, brush; + + // do stuff that does not rely on device being valid (e.g., + // non-nil): + space = 3 * frameWidth + qualityBarWidth + signalBarWidth + noiseBarWidth+1; + + if(mode == Horizontal) + { + h = space; + w = width(); + } else { + // Vertical + h = height(); + w = space; + } + + painter.setPen(QPen(Qt::black, frameWidth)); + painter.setBrush(KGlobalSettings::baseColor()); + painter.drawRect(0, 0, w, h); + + int x = qualityBarWidth + frameWidth; + mode == Vertical + ? painter.drawLine(x, frameWidth, x, h-frameWidth) + : painter.drawLine(frameWidth, x, w-frameWidth, x); + x += signalBarWidth + frameWidth; + mode == Vertical + ? painter.drawLine(x, frameWidth, x, h-frameWidth) + : painter.drawLine(frameWidth, x, w-frameWidth, x); + + DeviceInfo *device = deviceInfo.getFirst(); + if(device != 0) + { + // draw the quality bar: + switch((int)(device->quality()*3)) + { + case 0: + color = Qt::darkRed; + brush = Qt::red; + break; + case 1: + color = Qt::darkYellow; + brush = Qt::yellow; + break; + default: + color = Qt::darkGreen; + brush = Qt::green; + }; + if(mode == Vertical) + { + int position = (int)(((float)(h-2*frameWidth))*(1-device->quality())+0.5); + + points.putPoints + (0, 4, + frameWidth, h - 2*frameWidth, + frameWidth, position + bevel/2, + qualityBarWidth, QMAX(position - bevel/2, frameWidth), + qualityBarWidth, h - 2*frameWidth); + } else { + int position = (int)(((float)(w-2*frameWidth))*device->quality()+0.5); + + points.putPoints + (0, 4, + frameWidth, frameWidth, + QMIN(position - bevel/2, w-frameWidth), frameWidth, + QMIN(position + bevel/2, w-frameWidth), frameWidth+qualityBarWidth-1, + frameWidth, frameWidth+qualityBarWidth-1); + } + painter.setPen(QPen(color)); + painter.setBrush(brush); + painter.drawPolygon(points); + + // draw the signal bar: + painter.setPen(QPen(Qt::darkRed)); + painter.setBrush(Qt::red); + + if(mode == Vertical) + { + int x = 2 * frameWidth + qualityBarWidth; + int h1 = (int)(((float)(h-2*frameWidth))*(1-device->signal())+0.5); + + painter.drawRect(x, h1, signalBarWidth, h - frameWidth - h1); + } else { + int x = frameWidth; + int y = 2 * frameWidth + qualityBarWidth; + int w1 = (int)(((float)(w-2*frameWidth))*device->signal()+0.5); + + painter.drawRect(x, y, w1, signalBarWidth); + } + // draw the noise bar: + painter.setPen(QPen(Qt::gray)); + painter.setBrush(Qt::lightGray); + + if(mode == Vertical) + { + int x = 3 * frameWidth + qualityBarWidth + signalBarWidth; + int h1 = (int)(((float)(h-2*frameWidth))*(1-device->noise())+0.5); + + painter.drawRect(x, h1, signalBarWidth, h - frameWidth - h1); + } else { + int x = frameWidth; + int y = 3 * frameWidth + qualityBarWidth + signalBarWidth; + int w1 = (int)(((float)(w-2*frameWidth))*device->noise()+0.5); + + painter.drawRect(x, y, w1, signalBarWidth); + } + } +} + +KWireLessWidget* KWireLessWidget::makeWireLessWidget(QWidget *parent, + const char *name) +{ +#if 1 + // defined linuxwirelesswidget + return new LinuxWireLessWidget(parent, name); +#else +#error KWireLess is not available for your OS +#endif + // just to shut the compiler up: + parent = parent; name = name; return 0; +} + +#include "kwirelesswidget.moc" diff --git a/wifi/kwireless/kwirelesswidget.h b/wifi/kwireless/kwirelesswidget.h new file mode 100644 index 00000000..5a374d07 --- /dev/null +++ b/wifi/kwireless/kwirelesswidget.h @@ -0,0 +1,103 @@ +/* + $ Author: Mirko Boehm $ + $ License: This code is licensed under the LGPL $ + $ Copyright: (C) 1996-2003, Mirko Boehm $ + $ Contact: Mirko Boehm <[email protected]> + http://www.kde.org + http://www.hackerbuero.org $ +*/ + +#ifndef KWIRELESS_WIDGET_H +#define KWIRELESS_WIDGET_H + +#include <qwidget.h> +#include <qptrlist.h> +#include <qmutex.h> +#include <qstringlist.h> + +class DeviceInfo +{ +public: + DeviceInfo(QString _device=QString::null, QString _essid=QString::null, + QString _encr=QString::null, + float _quality=0, float _signal=0, float _noise=0, + int _bitrate=0); + QString bitrateString(); + float quality(); + QString qualityString(); + float signal(); + QString signalString(); + float noise(); + QString noiseString(); + const QString& device(); + const QString& essid(); + bool usesEncryption(); + QString encrString(); +protected: + QString m_device; // the device name (e.g., eth1) + QString m_essid; // the network name + + // all this values are coefficients (values between 0 and 1): + float m_quality; // link quality level + float m_noise; // the noise level + float m_signal; // the signal level + // all these values are absolut, e.g., 11000000 = 11MBit/sec: + int m_bitrate; // bit rate + QString m_encr; +}; + +/** This wigdet displays the information about one wireless device. + It is supposed to "look good" at about any resolution (to enable + it to be used in the panel). */ + +class KWireLessWidget : public QWidget +{ + Q_OBJECT +public: + enum Mode { + Horizontal, + Vertical + }; + static KWireLessWidget* makeWireLessWidget(QWidget *parent = 0, + const char *name = 0); +protected: + KWireLessWidget(QWidget *parent=0, const char* name=0); +public: + ~KWireLessWidget(); + void setMode(Mode); + // These methods return values according to the mode: + int preferredHeight(); + int preferredWidth(); + int instances(); +protected: + void paintEvent(QPaintEvent*); + void mousePressEvent(QMouseEvent *e); +protected: + Mode mode; + int frameWidth; + int qualityBarWidth; + int signalBarWidth; + int noiseBarWidth; + // some static device information + // a list of DeviceInfo objects, this needs to be filled by the + // poll method: + static QPtrList<DeviceInfo> deviceInfo; + static QTimer *timer; // the poll timer + static QMutex mutex; + static int m_instances; +signals: + void updateDeviceInfo(QPtrList<DeviceInfo> *); +protected slots: + /** poll() is system dependent and needs to be implemented by + deriving classes. + poll() has to put a DeviceInfo object into deviceInfo for each + wireless network device on the system. It uses mutex to + serialize access to this objects. + poll() will be called by a timer. If you cannot implement a + KWireLessWidget for your OS this way, please contact me + ([email protected]). + */ + virtual void poll() = 0; +}; + +#endif // KWIRELESS_WIDGET_H diff --git a/wifi/kwireless/linuxwirelesswidget.cpp b/wifi/kwireless/linuxwirelesswidget.cpp new file mode 100644 index 00000000..de35b84b --- /dev/null +++ b/wifi/kwireless/linuxwirelesswidget.cpp @@ -0,0 +1,227 @@ +/* + $ Author: Mirko Boehm $ + $ License: This code is licensed under the LGPL $ + $ Copyright: (C) 1996-2003, Mirko Boehm $ + $ Contact: Mirko Boehm <[email protected]> + http://www.kde.org + http://www.hackerbuero.org $ +*/ + +#include <qtooltip.h> +#include <qtimer.h> +#include <kdebug.h> +#include <klocale.h> +#include <unistd.h> // for ::close +#include "linuxwirelesswidget.h" +#include "config.h" + +extern "C" { +#include <iwlib.h> +// #include <linux/wireless.h> +} + +int LinuxWireLessWidget::socketFD; +QStringList LinuxWireLessWidget::deviceNames; + +LinuxWireLessWidget::LinuxWireLessWidget(QWidget *parent, const char* name) + : KWireLessWidget(parent, name), + m_number (-1) +{ +} + +LinuxWireLessWidget::~LinuxWireLessWidget() +{ + if(instances() == 1) + { // I am the only one + if(socketFD != 0) + { + kdDebug() << "KWireLessWidget dtor: closing FD, over and out." + << endl; + ::close(socketFD); // prevent from using QWidget::close + socketFD = 0; + } + } +} + + +void LinuxWireLessWidget::poll() +{ + // BE AWARE: do not call this method, only the first instance is + // supposed to do so, and it has been taken care of! + // this will repoll the device names every ReEnumCountDownStart + // timer ticks: + const int ReEnumCountDownStart = 30; + static int ReEnumCountDown; + struct wireless_info info; + struct wireless_config config; + struct iwreq wrq; + bool updateNeeded = false; + bool updateToolTip = false; + + // get a socket file descriptor: + if(socketFD == 0) + { + socketFD = iw_sockets_open(); + } + if(socketFD == 0) + { + kdDebug() << "KWireLessWidget ctor: opening socket file descriptor failed." + << endl; + return; + } + // ----- query the available devices: + mutex.lock(); // querying the device names is protected: + if(ReEnumCountDown-- == 0) + { + ReEnumCountDown = ReEnumCountDownStart; + updateToolTip = true; + + // query device information: + deviceNames.clear(); + iw_enum_devices(socketFD, devEnumHandler, 0, 0); + + if (m_number != (int) deviceNames.count()) + { + m_number = deviceNames.count(); + kdDebug() << "KWireLessWidget::poll: found " + << deviceNames.count() << " wireless " + << ((deviceNames.count() == 1) ? "device" : "devices") + << endl; + } + } + + // ----- get the device information: + QStringList::Iterator it; + + deviceInfo.clear(); + for(it=deviceNames.begin(); it!=deviceNames.end(); ++it) + { + // I think it is OK to use this cast, since the QT docs say the + // returned pointer is valid until the value of the string is + // changed, which will not happen here (horrible cast, anyway + // ...): + char *device_c_str = (char*)(*it).latin1(); + + if(iw_get_basic_config(socketFD, device_c_str, &config) == -1) + { + kdDebug() << "KWireLessWidget::poll: device " + << *it << " does not seem to be a wireless device" + << endl; + } else { + // WORK_TO_DO: decide whether updates are needed or not + // create a DeviceInfo object and fill it: + QString dev, essid, encr; + float quality=0, signal=0, noise=0; + int bitrate; + + dev = *it; + // get the bitrate: + if(iw_get_ext(socketFD, device_c_str, SIOCGIWRATE, &wrq) >=0) + { + info.has_bitrate = 1; + memcpy(&(info.bitrate), &(wrq.u.bitrate), sizeof(iwparam)); + } + bitrate = info.bitrate.value; + // get the ranges (needed to translate the absolute values + // reported by the driver): + if(iw_get_range_info(socketFD, device_c_str, &(info.range)) >= 0) + { + info.has_range = 1; + } + + // get the device statistics: +#ifdef HAVE_IW_27 + if(iw_get_stats(socketFD, device_c_str, &(info.stats), &(info.range), info.has_range)>= 0) +#else + if(iw_get_stats(socketFD, device_c_str, &(info.stats)) >= 0) +#endif + { + info.has_stats = 1; + // get the link quality (logic has been taken from + // wireless-tools, iwlib.c): + + int rqn = info.range.max_qual.noise; + int rql = info.range.max_qual.level; + int rmq = info.range.max_qual.qual; + + // in case the quality levels are zero, do not allow division by zero, and + // instead set the max. possible quality range to 255 (max of "unsigned char") + if (!rqn) rqn = 255; + if (!rql) rql = 255; + if (!rmq) rmq = 255; + + bool isAbs; // true if values are relative tp a peak value, + // otherwise values are dBm + isAbs = (float)info.stats.qual.level > (int)info.range.max_qual.level; + if(isAbs) + { + noise = 1 + ((float)info.stats.qual.noise - 0x100) / rqn; + signal = 1 + ((float)info.stats.qual.level - 0x100) / rql; + } else { + noise = ((float)info.stats.qual.noise) / rqn; + signal = ((float)info.stats.qual.level) / rql; + } + + quality = ((float)info.stats.qual.qual) / rmq; + + updateNeeded = true; + } + if(config.has_essid) + essid = config.essid; + else + essid = i18n("<unknown>"); + + if (config.has_key && config.key_size>0) { + encr = i18n("enabled"); + } else { + // non-root users don't get information about encryption status + encr = (getuid() == 0) ? i18n("disabled") : i18n("no information"); + } + + DeviceInfo *device = new DeviceInfo(dev, essid, encr, quality, signal, + noise, bitrate); + deviceInfo.append(device); + } + } + mutex.unlock(); + if(updateNeeded) + { + emit(updateDeviceInfo(&deviceInfo)); + repaint(false); + } + if(updateToolTip) + { + DeviceInfo *info; + QString text; + + for(info=deviceInfo.first(); info; info=deviceInfo.next()) + { + if (!text.isEmpty()) + text.append('\n'); + text += i18n("%1: Link Quality %2, Bitrate: %3") + .arg(info->device()) + .arg(info->qualityString()) + .arg(info->bitrateString()); + } + QToolTip::add(this, text); + + updateToolTip = false; + } + + timer->start(330, true); // single shot +} + +// static: +int LinuxWireLessWidget::devEnumHandler(int skfd, char * ifname, char **, int) +{ + struct wireless_config config; + + if(iw_get_basic_config(skfd, ifname, &config) != -1) + { + deviceNames.append(ifname); + } + return 0; +} + + +#include "linuxwirelesswidget.moc" diff --git a/wifi/kwireless/linuxwirelesswidget.h b/wifi/kwireless/linuxwirelesswidget.h new file mode 100644 index 00000000..3bbd085c --- /dev/null +++ b/wifi/kwireless/linuxwirelesswidget.h @@ -0,0 +1,36 @@ +/* + $ Author: Mirko Boehm $ + $ License: This code is licensed under the LGPL $ + $ Copyright: (C) 1996-2003, Mirko Boehm $ + $ Contact: Mirko Boehm <[email protected]> + http://www.kde.org + http://www.hackerbuero.org $ +*/ + +#ifndef LINUXWIRELESSWIDGET_H +#define LINUXWIRELESSWIDGET_H + +#include "kwirelesswidget.h" + +class LinuxWireLessWidget : public KWireLessWidget +{ + Q_OBJECT +public: + LinuxWireLessWidget(QWidget *parent=0, const char* name=0); + ~LinuxWireLessWidget(); +protected: + /** poll() is supposed to read the information from + /proc/net/wireless (Linux) and put it into the data members. */ + void poll(); + static int socketFD; // the socket file descriptor to talk to the + // driver + static QStringList deviceNames; + static int devEnumHandler(int skfd, + char * ifname, + char * args[], + int count); + /** Store previously found number of wireless devices. */ + int m_number; +}; + +#endif diff --git a/wifi/kwireless/propertytable.cpp b/wifi/kwireless/propertytable.cpp new file mode 100644 index 00000000..7011c691 --- /dev/null +++ b/wifi/kwireless/propertytable.cpp @@ -0,0 +1,151 @@ +/* + $ Author: Mirko Boehm $ + $ License: This code is licensed under the LGPL $ + $ Copyright: (C) 1996-2003, Mirko Boehm $ + $ Contact: Mirko Boehm <[email protected]> + http://www.kde.org + http://www.hackerbuero.org $ +*/ + +#include <qtable.h> +#include <qcombobox.h> +#include <qtimer.h> +#include <qptrlist.h> +#include <qtextstream.h> +#include <kdialogbase.h> +#include <klocale.h> +#include "propertytable.h" +#include "kwirelesswidget.h" + +extern "C" { +#include <math.h> +} + +PropertyTable::PropertyTable(QWidget *parent, const char* name) + : PropertyTableBase(parent, name) +{ +} + +PropertyTable::~PropertyTable() +{ +} + +PropertiesDialog::PropertiesDialog(QWidget *parent, const char *name) + : KDialogBase(parent, name, true, + i18n("Wireless Network Device Properties"), + KDialogBase::Ok, KDialogBase::Ok, true), + wait(false) +{ + table = new PropertyTable(this); + setMainWidget(table); + table->table->setLeftMargin(0); + table->table->setSorting(false); + table->table->setReadOnly(true); + adjustSize(); + timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), SLOT(timeout())); + timer->start(3000, false); + connect(table->cbDeviceSelector, SIGNAL(activated(int)), + SLOT(selected(int))); +} + +void PropertiesDialog::update(QPtrList<DeviceInfo> *_info) +{ + int selection = table->cbDeviceSelector->currentItem(); + + if(wait) return; + + info = _info; + DeviceInfo *device; + QPtrListIterator<DeviceInfo> it(*info); + + table->cbDeviceSelector->clear(); + + while((device = it.current()) != 0) + { + ++it; + table->cbDeviceSelector->insertItem(device->device()); + } + + if(selection > 0 && selection < table->cbDeviceSelector->count()) + { + selected(selection); + } else { + if(table->cbDeviceSelector->count() == 0) + { + selected(-1); + } else { + selected(0); + } + } + + table->cbDeviceSelector->setEnabled(info->count()>1); + + wait = true; +} + +void PropertiesDialog::timeout() +{ + wait = false; +} + +void PropertiesDialog::selected(int index) +{ + DeviceInfo temp; + DeviceInfo *device; + int count; + + if(index < 0) + { + device = &temp; + } else { + device = info->at(index); + } + + QString fields[] = + { + i18n("Device:"), + i18n("ESSID (network name):"), + i18n("Link quality:"), + i18n("Signal strength:"), + i18n("Noise level:"), + i18n("Bit rate:"), + i18n("Encryption:") + }; + const int NoOfFields = sizeof(fields)/sizeof(fields[0]); + + QString values[] = + { + device->device(), + device->essid(), + device->qualityString(), + device->signalString(), + device->noiseString(), + device->bitrateString(), + device->encrString() + }; + const int NoOfValues = sizeof(values)/sizeof(values[0]); + + if(table->table->numRows() == 0) + { + table->table->insertRows(0, NoOfFields); + // HACK (make more rows visible than the default): + resize(size().width(), (int)(1.8*size().height())); + } + + for(count = 0; count<NoOfFields; ++count) + { + table->table->setText(count, 0, fields[count]); + } + + for(count = 0; count<NoOfValues; ++count) + { + table->table->setText(count, 1, values[count]); + } + + table->table->adjustColumn(0); + table->table->adjustColumn(1); + +} + +#include "propertytable.moc" diff --git a/wifi/kwireless/propertytable.h b/wifi/kwireless/propertytable.h new file mode 100644 index 00000000..4eadc78a --- /dev/null +++ b/wifi/kwireless/propertytable.h @@ -0,0 +1,45 @@ +/* + $ Author: Mirko Boehm $ + $ License: This code is licensed under the LGPL $ + $ Copyright: (C) 1996-2003, Mirko Boehm $ + $ Contact: Mirko Boehm <[email protected]> + http://www.kde.org + http://www.hackerbuero.org $ +*/ + +#ifndef KWIRELESS_PROPERTYTABLE_H +#define KWIRELESS_PROPERTYTABLE_H + +#include <kdialogbase.h> +#include <qptrlist.h> +#include "propertytablebase.h" + +class DeviceInfo; +class QTimer; + +class PropertyTable : public PropertyTableBase +{ + Q_OBJECT +public: + PropertyTable(QWidget *parent = 0, const char* name = 0); + ~PropertyTable(); +}; + + +class PropertiesDialog : public KDialogBase +{ + Q_OBJECT +public: + PropertiesDialog(QWidget *parent = 0, const char *name = 0); +protected: + PropertyTable *table; + QPtrList<DeviceInfo> *info; + bool wait; + QTimer *timer; +public slots: + void update(QPtrList<DeviceInfo> *); + void timeout(); + void selected(int); +}; + +#endif // KWIRELESS_PROPERTYTABLE_H diff --git a/wifi/kwireless/propertytablebase.ui b/wifi/kwireless/propertytablebase.ui new file mode 100644 index 00000000..8f52c58b --- /dev/null +++ b/wifi/kwireless/propertytablebase.ui @@ -0,0 +1,68 @@ +<!DOCTYPE UI><UI version="3.1" stdsetdef="1"> +<class>PropertyTableBase</class> +<widget class="QWidget"> + <property name="name"> + <cstring>PropertyTableBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>552</width> + <height>439</height> + </rect> + </property> + <property name="caption"> + <string>Wireless Network Device Properties</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <widget class="QTable" row="1" column="0" rowspan="1" colspan="2"> + <column> + <property name="text"> + <string>Property</string> + </property> + </column> + <column> + <property name="text"> + <string>Value</string> + </property> + </column> + <property name="name"> + <cstring>table</cstring> + </property> + <property name="numRows"> + <number>0</number> + </property> + <property name="numCols"> + <number>2</number> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + <property name="sorting"> + <bool>true</bool> + </property> + </widget> + <widget class="QComboBox" row="0" column="1"> + <property name="name"> + <cstring>cbDeviceSelector</cstring> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>tlDevice</cstring> + </property> + <property name="text"> + <string>Network device:</string> + </property> + </widget> + </grid> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> |