From aedf9f81641ba4a85b15e35e6ac8ff457265133a Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 22 Dec 2009 13:54:49 +1000 Subject: Make compile. --- examples/network/bearercloud/bearercloud.h | 2 +- examples/network/bearercloud/bearercloud.pro | 18 --- examples/network/bearercloud/cloud.h | 2 +- examples/network/bearermonitor/bearermonitor.h | 2 +- examples/network/bearermonitor/bearermonitor.pro | 24 ++-- examples/network/bearermonitor/sessionwidget.h | 2 +- examples/network/network.pro | 4 +- src/network/bearer/bearer.pri | 130 +++++++++++++++++++++ src/network/bearer/qcorewlanengine_mac.mm | 4 +- src/network/bearer/qcorewlanengine_mac_p.h | 5 +- src/network/bearer/qgenericengine.cpp | 4 +- src/network/bearer/qgenericengine_p.h | 4 +- src/network/bearer/qnativewifiengine_win.cpp | 4 +- src/network/bearer/qnativewifiengine_win_p.h | 4 +- src/network/bearer/qnetworkconfigmanager.cpp | 4 +- src/network/bearer/qnetworkconfigmanager.h | 8 +- src/network/bearer/qnetworkconfigmanager_maemo.cpp | 4 +- src/network/bearer/qnetworkconfigmanager_maemo_p.h | 4 +- src/network/bearer/qnetworkconfigmanager_p.cpp | 4 +- src/network/bearer/qnetworkconfigmanager_p.h | 4 +- src/network/bearer/qnetworkconfigmanager_s60_p.cpp | 4 +- src/network/bearer/qnetworkconfigmanager_s60_p.h | 4 +- src/network/bearer/qnetworkconfiguration.cpp | 4 +- src/network/bearer/qnetworkconfiguration.h | 9 +- src/network/bearer/qnetworkconfiguration_maemo_p.h | 4 +- src/network/bearer/qnetworkconfiguration_p.h | 4 +- src/network/bearer/qnetworkconfiguration_s60_p.cpp | 4 +- src/network/bearer/qnetworkconfiguration_s60_p.h | 4 +- src/network/bearer/qnetworkmanagerservice_p.cpp | 4 +- src/network/bearer/qnetworkmanagerservice_p.h | 13 +-- src/network/bearer/qnetworksession.cpp | 4 +- src/network/bearer/qnetworksession.h | 8 +- src/network/bearer/qnetworksession_maemo.cpp | 4 +- src/network/bearer/qnetworksession_maemo_p.h | 4 +- src/network/bearer/qnetworksession_p.cpp | 4 +- src/network/bearer/qnetworksession_p.h | 5 +- src/network/bearer/qnetworksession_s60_p.cpp | 4 +- src/network/bearer/qnetworksession_s60_p.h | 4 +- src/network/bearer/qnetworksessionengine.cpp | 4 +- src/network/bearer/qnetworksessionengine_p.h | 5 +- src/network/bearer/qnlaengine_win.cpp | 4 +- src/network/bearer/qnlaengine_win_p.h | 4 +- src/network/bearer/qnmdbushelper.cpp | 4 +- src/network/bearer/qnmdbushelper_p.h | 5 +- src/network/bearer/qnmwifiengine_unix.cpp | 10 +- src/network/bearer/qnmwifiengine_unix_p.h | 4 +- src/network/network.pro | 1 + tests/auto/auto.pro | 3 + .../qnetworkconfigmanager.pro | 12 +- .../tst_qnetworkconfigmanager.cpp | 2 +- .../qnetworkconfiguration.pro | 12 +- .../tst_qnetworkconfiguration.cpp | 2 +- tests/auto/qnetworksession/lackey/lackey.pro | 10 +- tests/auto/qnetworksession/lackey/main.cpp | 2 +- .../tst_qnetworksession/tst_qnetworksession.cpp | 2 +- .../tst_qnetworksession/tst_qnetworksession.pro | 18 +-- tests/manual/bearerex/bearerex.h | 2 +- tests/manual/bearerex/bearerex.pro | 16 --- tests/manual/networkmanager/networkmanager.pro | 10 -- tests/manual/networkmanager/nmview.cpp | 2 +- tests/manual/networkmanager/nmview.h | 2 +- 61 files changed, 245 insertions(+), 219 deletions(-) create mode 100644 src/network/bearer/bearer.pri diff --git a/examples/network/bearercloud/bearercloud.h b/examples/network/bearercloud/bearercloud.h index c18ffd3..79b441f 100644 --- a/examples/network/bearercloud/bearercloud.h +++ b/examples/network/bearercloud/bearercloud.h @@ -45,7 +45,7 @@ #include #include -QTM_USE_NAMESPACE +QT_USE_NAMESPACE class Cloud; diff --git a/examples/network/bearercloud/bearercloud.pro b/examples/network/bearercloud/bearercloud.pro index 308ddda..c45d62a 100644 --- a/examples/network/bearercloud/bearercloud.pro +++ b/examples/network/bearercloud/bearercloud.pro @@ -10,21 +10,3 @@ RESOURCES = icons.qrc TARGET = bearercloud QT = core gui network svg - -INCLUDEPATH += ../../src/bearer - -include(../examples.pri) - -qtAddLibrary(QtBearer) - -CONFIG += console - -include(../examples.pri) - - -macx: { - contains(QT_CONFIG,qt_framework):LIBS += -framework QtBearer - INCLUDEPATH += ../../ - contains(CONFIG, debug) { - } -} diff --git a/examples/network/bearercloud/cloud.h b/examples/network/bearercloud/cloud.h index 4ce43df..f844725 100644 --- a/examples/network/bearercloud/cloud.h +++ b/examples/network/bearercloud/cloud.h @@ -43,7 +43,7 @@ #include #include -QTM_USE_NAMESPACE +QT_USE_NAMESPACE class QGraphicsTextItem; class QGraphicsSvgItem; diff --git a/examples/network/bearermonitor/bearermonitor.h b/examples/network/bearermonitor/bearermonitor.h index d1f4601..9306d90 100644 --- a/examples/network/bearermonitor/bearermonitor.h +++ b/examples/network/bearermonitor/bearermonitor.h @@ -50,7 +50,7 @@ #include "ui_bearermonitor_640_480.h" #endif -QTM_USE_NAMESPACE +QT_USE_NAMESPACE class SessionWidget; diff --git a/examples/network/bearermonitor/bearermonitor.pro b/examples/network/bearermonitor/bearermonitor.pro index c8fb3c2..a854b55 100644 --- a/examples/network/bearermonitor/bearermonitor.pro +++ b/examples/network/bearermonitor/bearermonitor.pro @@ -4,7 +4,7 @@ HEADERS = sessionwidget.h \ SOURCES = main.cpp \ bearermonitor.cpp \ sessionwidget.cpp - + FORMS = bearermonitor_240_320.ui \ bearermonitor_640_480.ui \ sessionwidget.ui @@ -13,20 +13,10 @@ TARGET = bearermonitor QT = core gui network -INCLUDEPATH += ../../src/bearer - -include(../examples.pri) - -qtAddLibrary(QtBearer) -win32:!wince*:LIBS += -lWs2_32 -wince*:LIBS += -lWs2 - -CONFIG += console - -include(../examples.pri) - -macx: { - contains(QT_CONFIG,qt_framework):LIBS += -framework QtBearer - contains(CONFIG, debug) { - } +win32 { + !wince* { + LIBS += -lWs2_32 + } else { + LIBS += -lWs2 + } } diff --git a/examples/network/bearermonitor/sessionwidget.h b/examples/network/bearermonitor/sessionwidget.h index cb6591e..8bc60e4 100644 --- a/examples/network/bearermonitor/sessionwidget.h +++ b/examples/network/bearermonitor/sessionwidget.h @@ -46,7 +46,7 @@ #include -QTM_USE_NAMESPACE +QT_USE_NAMESPACE class SessionWidget : public QWidget, public Ui_SessionWidget { diff --git a/examples/network/network.pro b/examples/network/network.pro index c5a97fb..bd632b8 100644 --- a/examples/network/network.pro +++ b/examples/network/network.pro @@ -11,7 +11,9 @@ SUBDIRS = blockingfortuneclient \ loopback \ threadedfortuneserver \ googlesuggest \ - torrent + torrent \ + bearercloud \ + bearermonitor # no QProcess !vxworks:!qnx:SUBDIRS += network-chat diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri new file mode 100644 index 0000000..d8ddce5 --- /dev/null +++ b/src/network/bearer/bearer.pri @@ -0,0 +1,130 @@ +# Qt network bearer management module + +#DEFINES += BEARER_MANAGEMENT_DEBUG + +HEADERS += bearer/qnetworkconfiguration.h \ + bearer/qnetworksession.h \ + bearer/qnetworkconfigmanager.h + +SOURCES += bearer/qnetworksession.cpp \ + bearer/qnetworkconfigmanager.cpp \ + bearer/qnetworkconfiguration.cpp + +symbian { + exists($${EPOCROOT}epoc32/release/winscw/udeb/cmmanager.lib)| \ + exists($${EPOCROOT}epoc32/release/armv5/lib/cmmanager.lib) { + message("Building with SNAP support") + DEFINES += SNAP_FUNCTIONALITY_AVAILABLE + LIBS += -lcmmanager + } else { + message("Building without SNAP support") + LIBS += -lapengine + } + + INCLUDEPATH += $$APP_LAYER_SYSTEMINCLUDE + + HEADERS += bearer/qnetworkconfigmanager_s60_p.h \ + bearer/qnetworkconfiguration_s60_p.h \ + bearer/qnetworksession_s60_p.h + SOURCES += bearer/qnetworkconfigmanager_s60_p.cpp \ + bearer/qnetworkconfiguration_s60_p.cpp \ + bearer/qnetworksession_s60_p.cpp + + LIBS += -lcommdb \ + -lapsettingshandlerui \ + -lconnmon \ + -lcentralrepository \ + -lesock \ + -linsock \ + -lecom \ + -lefsrv \ + -lnetmeta +} else:maemo { + QT += dbus + CONFIG += link_pkgconfig + + exists(../debug) { + message("Enabling debug messages.") + DEFINES += BEARER_MANAGEMENT_DEBUG + } + + HEADERS += bearer/qnetworksession_maemo_p.h \ + bearer/qnetworkconfigmanager_maemo_p.h \ + bearer/qnetworkconfiguration_maemo_p.h + + SOURCES += bearer/qnetworkconfigmanager_maemo.cpp \ + bearer/qnetworksession_maemo.cpp + + documentation.path = $$QT_MOBILITY_PREFIX/doc + documentation.files = doc/html + + PKGCONFIG += glib-2.0 dbus-glib-1 gconf-2.0 osso-ic conninet + + CONFIG += create_pc create_prl + QMAKE_PKGCONFIG_REQUIRES = glib-2.0 dbus-glib-1 gconf-2.0 osso-ic conninet + pkgconfig.path = $$QT_MOBILITY_LIB/pkgconfig + pkgconfig.files = QtBearer.pc + + INSTALLS += pkgconfig documentation +} else { + DEFINES += BEARER_ENGINE + + HEADERS += bearer/qnetworkconfigmanager_p.h \ + bearer/qnetworkconfiguration_p.h \ + bearer/qnetworksession_p.h \ + bearer/qnetworksessionengine_p.h \ + bearer/qgenericengine_p.h + + SOURCES += bearer/qnetworkconfigmanager_p.cpp \ + bearer/qnetworksession_p.cpp \ + bearer/qnetworksessionengine.cpp \ + bearer/qgenericengine.cpp + + unix:!mac:contains(networkmanager_enabled, yes) { + contains(QT_CONFIG,dbus) { + DEFINES += BACKEND_NM + QT += dbus + + HEADERS += bearer/qnmdbushelper_p.h \ + bearer/qnetworkmanagerservice_p.h \ + bearer/qnmwifiengine_unix_p.h + + SOURCES += bearer/qnmdbushelper.cpp \ + bearer/qnetworkmanagerservice_p.cpp \ + bearer/qnmwifiengine_unix.cpp + } else { + message("NetworkManager backend requires Qt DBus support") + } + } + + win32 { + HEADERS += bearer/qnlaengine_win_p.h \ + bearer/qnetworksessionengine_win_p.h + + SOURCES += bearer/qnlaengine_win.cpp + + !wince* { + HEADERS += bearer/qnativewifiengine_win_p.h + + SOURCES += bearer/qnativewifiengine_win.cpp + + LIBS += -lWs2_32 + } else { + LIBS += -lWs2 + } + } + + macx { + HEADERS += bearer/qcorewlanengine_mac_p.h + SOURCES+= bearer/qcorewlanengine_mac.mm + LIBS += -framework Foundation -framework SystemConfiguration + + contains(corewlan_enabled, yes) { + isEmpty(QMAKE_MAC_SDK)|contains(QMAKE_MAC_SDK, "/Developer/SDKs/MacOSX10.6.sdk") { + LIBS += -framework CoreWLAN + DEFINES += MAC_SDK_10_6 + } + } + } +} + diff --git a/src/network/bearer/qcorewlanengine_mac.mm b/src/network/bearer/qcorewlanengine_mac.mm index 5451615..5854384 100644 --- a/src/network/bearer/qcorewlanengine_mac.mm +++ b/src/network/bearer/qcorewlanengine_mac.mm @@ -63,7 +63,7 @@ #include QMap networkInterfaces; -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QCoreWlanEngine, coreWlanEngine) @@ -457,5 +457,5 @@ bool QCoreWlanEngine::getAllScInterfaces() #include "moc_qcorewlanengine_mac_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qcorewlanengine_mac_p.h b/src/network/bearer/qcorewlanengine_mac_p.h index fc8e4b5..660ddb5 100644 --- a/src/network/bearer/qcorewlanengine_mac_p.h +++ b/src/network/bearer/qcorewlanengine_mac_p.h @@ -56,7 +56,8 @@ #include "qnetworksessionengine_p.h" #include #include -QTM_BEGIN_NAMESPACE + +QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; @@ -94,7 +95,7 @@ private: bool isKnownSsid(const QString &interfaceName, const QString &ssid); }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif diff --git a/src/network/bearer/qgenericengine.cpp b/src/network/bearer/qgenericengine.cpp index 184a69c..2e48ce8 100644 --- a/src/network/bearer/qgenericengine.cpp +++ b/src/network/bearer/qgenericengine.cpp @@ -53,7 +53,7 @@ #include "qnetworksessionengine_win_p.h" #endif -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QGenericEngine, genericEngine) @@ -230,5 +230,5 @@ QGenericEngine *QGenericEngine::instance() } #include "moc_qgenericengine_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qgenericengine_p.h b/src/network/bearer/qgenericengine_p.h index 976776e..88de2a0 100644 --- a/src/network/bearer/qgenericengine_p.h +++ b/src/network/bearer/qgenericengine_p.h @@ -58,7 +58,7 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; @@ -88,7 +88,7 @@ private: QTimer pollTimer; }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif diff --git a/src/network/bearer/qnativewifiengine_win.cpp b/src/network/bearer/qnativewifiengine_win.cpp index d8fe5fb..b4b3888 100644 --- a/src/network/bearer/qnativewifiengine_win.cpp +++ b/src/network/bearer/qnativewifiengine_win.cpp @@ -52,7 +52,7 @@ #include #undef interface -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QNativeWifiEngine, nativeWifiEngine) @@ -723,4 +723,4 @@ QNativeWifiEngine *QNativeWifiEngine::instance() #include "moc_qnativewifiengine_win_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnativewifiengine_win_p.h b/src/network/bearer/qnativewifiengine_win_p.h index 0d5bcb0..adc75e1 100644 --- a/src/network/bearer/qnativewifiengine_win_p.h +++ b/src/network/bearer/qnativewifiengine_win_p.h @@ -57,7 +57,7 @@ #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; @@ -90,6 +90,6 @@ private: Qt::HANDLE handle; }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 264f0df..4b28b22 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -47,7 +47,7 @@ #include "qnetworkconfigmanager_p.h" #endif -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QNetworkConfigurationManagerPrivate, connManager); @@ -329,5 +329,5 @@ void QNetworkConfigurationManager::updateConfigurations() #include "moc_qnetworkconfigmanager.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfigmanager.h b/src/network/bearer/qnetworkconfigmanager.h index 98641f6..940fcc5 100644 --- a/src/network/bearer/qnetworkconfigmanager.h +++ b/src/network/bearer/qnetworkconfigmanager.h @@ -42,17 +42,15 @@ #ifndef QNETWORKCONFIGURATIONMANAGER_H #define QNETWORKCONFIGURATIONMANAGER_H -#include "qmobilityglobal.h" - #include #include "qnetworkconfiguration.h" QT_BEGIN_HEADER -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationManagerPrivate; -class Q_BEARER_EXPORT QNetworkConfigurationManager : public QObject +class Q_NETWORK_EXPORT QNetworkConfigurationManager : public QObject { Q_OBJECT @@ -93,7 +91,7 @@ Q_SIGNALS: Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkConfigurationManager::Capabilities) -QTM_END_NAMESPACE +QT_END_NAMESPACE QT_END_HEADER diff --git a/src/network/bearer/qnetworkconfigmanager_maemo.cpp b/src/network/bearer/qnetworkconfigmanager_maemo.cpp index 795b054..26909f9 100644 --- a/src/network/bearer/qnetworkconfigmanager_maemo.cpp +++ b/src/network/bearer/qnetworkconfigmanager_maemo.cpp @@ -53,7 +53,7 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE #define IAP "/system/osso/connectivity/IAP" static int iap_prefix_len; @@ -757,4 +757,4 @@ void QNetworkConfigurationManagerPrivate::configChanged(QNetworkConfigurationPri #include "qnetworkconfigmanager_maemo.moc" #include "moc_qnetworkconfigmanager_maemo_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfigmanager_maemo_p.h b/src/network/bearer/qnetworkconfigmanager_maemo_p.h index e182495..a5462b8 100644 --- a/src/network/bearer/qnetworkconfigmanager_maemo_p.h +++ b/src/network/bearer/qnetworkconfigmanager_maemo_p.h @@ -60,7 +60,7 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationManagerPrivate : public QObject @@ -136,6 +136,6 @@ Q_SIGNALS: void onlineStateChanged(bool isOnline); }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif //QNETWORKCONFIGURATIONMANAGERPRIVATE_H diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 8b15f41..49135c1 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -59,7 +59,7 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE void QNetworkConfigurationManagerPrivate::registerPlatformCapabilities() { @@ -446,5 +446,5 @@ void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() #include "moc_qnetworkconfigmanager_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 0c42f9b..184d1bd 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -59,7 +59,7 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE #ifdef BEARER_ENGINE class QNetworkSessionEngine; @@ -173,6 +173,6 @@ private Q_SLOTS: #endif }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif //QNETWORKCONFIGURATIONMANAGERPRIVATE_H diff --git a/src/network/bearer/qnetworkconfigmanager_s60_p.cpp b/src/network/bearer/qnetworkconfigmanager_s60_p.cpp index 760a194..8859a4e 100644 --- a/src/network/bearer/qnetworkconfigmanager_s60_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_s60_p.cpp @@ -58,7 +58,7 @@ #include #endif -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE static const int KValueThatWillBeAddedToSNAPId = 1000; static const int KUserChoiceIAPId = 0; @@ -971,4 +971,4 @@ void AccessPointsAvailabilityScanner::RunL() } } #include "moc_qnetworkconfigmanager_s60_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfigmanager_s60_p.h b/src/network/bearer/qnetworkconfigmanager_s60_p.h index 296d67f..cd48df6 100644 --- a/src/network/bearer/qnetworkconfigmanager_s60_p.h +++ b/src/network/bearer/qnetworkconfigmanager_s60_p.h @@ -65,7 +65,7 @@ class CCommsDatabase; class QTimer; -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkSessionPrivate; class AccessPointsAvailabilityScanner; @@ -177,6 +177,6 @@ private: // Data TConnMonIapInfoBuf iIapBuf; }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif //QNETWORKCONFIGURATIONMANAGERPRIVATE_H diff --git a/src/network/bearer/qnetworkconfiguration.cpp b/src/network/bearer/qnetworkconfiguration.cpp index c92b356..9422f07 100644 --- a/src/network/bearer/qnetworkconfiguration.cpp +++ b/src/network/bearer/qnetworkconfiguration.cpp @@ -47,7 +47,7 @@ #include "qnetworkconfiguration_p.h" #endif -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE /*! \class QNetworkConfiguration @@ -345,5 +345,5 @@ QList QNetworkConfiguration::children() const } -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfiguration.h b/src/network/bearer/qnetworkconfiguration.h index f8c17d5..e1fbc43 100644 --- a/src/network/bearer/qnetworkconfiguration.h +++ b/src/network/bearer/qnetworkconfiguration.h @@ -42,18 +42,17 @@ #ifndef QNETWORKCONFIGURATION_H #define QNETWORKCONFIGURATION_H -#include "qmobilityglobal.h" - +#include #include #include #include QT_BEGIN_HEADER -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; -class Q_BEARER_EXPORT QNetworkConfiguration +class Q_NETWORK_EXPORT QNetworkConfiguration { public: QNetworkConfiguration(); @@ -106,7 +105,7 @@ private: QExplicitlySharedDataPointer d; }; -QTM_END_NAMESPACE +QT_END_NAMESPACE QT_END_HEADER diff --git a/src/network/bearer/qnetworkconfiguration_maemo_p.h b/src/network/bearer/qnetworkconfiguration_maemo_p.h index 8d786aa..8d7fbcf 100644 --- a/src/network/bearer/qnetworkconfiguration_maemo_p.h +++ b/src/network/bearer/qnetworkconfiguration_maemo_p.h @@ -57,7 +57,7 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate : public QSharedData { @@ -104,6 +104,6 @@ private: QNetworkConfigurationPrivate(const QNetworkConfigurationPrivate &other); }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif //QNETWORKCONFIGURATIONPRIVATE_H diff --git a/src/network/bearer/qnetworkconfiguration_p.h b/src/network/bearer/qnetworkconfiguration_p.h index a3bcd9a..1dd53c4 100644 --- a/src/network/bearer/qnetworkconfiguration_p.h +++ b/src/network/bearer/qnetworkconfiguration_p.h @@ -57,7 +57,7 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate : public QSharedData { @@ -99,6 +99,6 @@ private: QNetworkConfigurationPrivate(const QNetworkConfigurationPrivate &other); }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif //QNETWORKCONFIGURATIONPRIVATE_H diff --git a/src/network/bearer/qnetworkconfiguration_s60_p.cpp b/src/network/bearer/qnetworkconfiguration_s60_p.cpp index 61548ba..289e09c 100644 --- a/src/network/bearer/qnetworkconfiguration_s60_p.cpp +++ b/src/network/bearer/qnetworkconfiguration_s60_p.cpp @@ -41,7 +41,7 @@ #include "qnetworkconfiguration_s60_p.h" -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE QNetworkConfigurationPrivate::QNetworkConfigurationPrivate() : isValid(false), type(QNetworkConfiguration::Invalid), @@ -57,4 +57,4 @@ QNetworkConfigurationPrivate::~QNetworkConfigurationPrivate() serviceNetworkMembers.clear(); } -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfiguration_s60_p.h b/src/network/bearer/qnetworkconfiguration_s60_p.h index 44f8f56..bccad0c 100644 --- a/src/network/bearer/qnetworkconfiguration_s60_p.h +++ b/src/network/bearer/qnetworkconfiguration_s60_p.h @@ -56,7 +56,7 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate : public QSharedData { @@ -102,7 +102,7 @@ private: QNetworkConfigurationPrivate(const QNetworkConfigurationPrivate &other); }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif //QNETWORKCONFIGURATIONPRIVATE_H diff --git a/src/network/bearer/qnetworkmanagerservice_p.cpp b/src/network/bearer/qnetworkmanagerservice_p.cpp index 2f91af0..4e25533 100644 --- a/src/network/bearer/qnetworkmanagerservice_p.cpp +++ b/src/network/bearer/qnetworkmanagerservice_p.cpp @@ -57,7 +57,7 @@ #include "qnetworkmanagerservice_p.h" //Q_DECLARE_METATYPE(QList) -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE static QDBusConnection dbusConnection = QDBusConnection::systemBus(); //static QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbusConnection); @@ -1008,4 +1008,4 @@ QStringList QNetworkManagerIp4Config::domains() const #include "moc_qnetworkmanagerservice_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkmanagerservice_p.h b/src/network/bearer/qnetworkmanagerservice_p.h index 8569e71..91bf69d 100644 --- a/src/network/bearer/qnetworkmanagerservice_p.h +++ b/src/network/bearer/qnetworkmanagerservice_p.h @@ -64,19 +64,16 @@ #include -#include +#include "qnmdbushelper_p.h" +QT_BEGIN_NAMESPACE -QTM_BEGIN_NAMESPACE typedef QMap< QString, QMap > QNmSettingsMap; typedef QList ServerThing; -QTM_END_NAMESPACE -Q_DECLARE_METATYPE(QTM_PREPEND_NAMESPACE(QNmSettingsMap)) -Q_DECLARE_METATYPE(QTM_PREPEND_NAMESPACE(ServerThing)) +Q_DECLARE_METATYPE(QNmSettingsMap) +Q_DECLARE_METATYPE(ServerThing) - -QTM_BEGIN_NAMESPACE class QNetworkManagerInterfacePrivate; class QNetworkManagerInterface : public QObject { @@ -395,6 +392,6 @@ public: }; //// -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif //QNETWORKMANAGERSERVICE_H diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp index d3a323a..bdae9bc 100644 --- a/src/network/bearer/qnetworksession.cpp +++ b/src/network/bearer/qnetworksession.cpp @@ -52,7 +52,7 @@ #include "qnetworksession_p.h" #endif -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE /*! \class QNetworkSession @@ -686,4 +686,4 @@ void QNetworkSession::disconnectNotify(const char *signal) #include "moc_qnetworksession.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworksession.h b/src/network/bearer/qnetworksession.h index 47377c4..61093c7 100644 --- a/src/network/bearer/qnetworksession.h +++ b/src/network/bearer/qnetworksession.h @@ -42,8 +42,6 @@ #ifndef QNETWORKSESSION_H #define QNETWORKSESSION_H -#include "qmobilityglobal.h" - #include #include #include @@ -54,10 +52,10 @@ QT_BEGIN_HEADER -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkSessionPrivate; -class Q_BEARER_EXPORT QNetworkSession : public QObject +class Q_NETWORK_EXPORT QNetworkSession : public QObject { Q_OBJECT public: @@ -128,7 +126,7 @@ private: friend class QNetworkSessionPrivate; }; -QTM_END_NAMESPACE +QT_END_NAMESPACE QT_END_HEADER diff --git a/src/network/bearer/qnetworksession_maemo.cpp b/src/network/bearer/qnetworksession_maemo.cpp index c7c7a31..742499c 100644 --- a/src/network/bearer/qnetworksession_maemo.cpp +++ b/src/network/bearer/qnetworksession_maemo.cpp @@ -54,7 +54,7 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE static QHash properties; @@ -1178,4 +1178,4 @@ QNetworkSession::SessionError QNetworkSessionPrivate::error() const #include "qnetworksession_maemo.moc" #include "moc_qnetworksession_maemo_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworksession_maemo_p.h b/src/network/bearer/qnetworksession_maemo_p.h index e233087..6594176 100644 --- a/src/network/bearer/qnetworksession_maemo_p.h +++ b/src/network/bearer/qnetworksession_maemo_p.h @@ -62,7 +62,7 @@ #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkSessionPrivate : public QObject { @@ -161,7 +161,7 @@ private: void cleanupSession(void); }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif //QNETWORKSESSIONPRIVATE_H diff --git a/src/network/bearer/qnetworksession_p.cpp b/src/network/bearer/qnetworksession_p.cpp index c6f9833..6df4fdb9 100644 --- a/src/network/bearer/qnetworksession_p.cpp +++ b/src/network/bearer/qnetworksession_p.cpp @@ -63,7 +63,7 @@ #include "qnmwifiengine_unix_p.h" #endif -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE #if defined(BACKEND_NM) static bool NetworkManagerAvailable() @@ -538,5 +538,5 @@ if(serviceName.isEmpty()) #endif #include "moc_qnetworksession_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworksession_p.h b/src/network/bearer/qnetworksession_p.h index a2aaa6a..45e0ebf 100644 --- a/src/network/bearer/qnetworksession_p.h +++ b/src/network/bearer/qnetworksession_p.h @@ -63,7 +63,8 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE + #ifdef BEARER_ENGINE class QNetworkSessionEngine; #endif @@ -161,7 +162,7 @@ private: #endif }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif //QNETWORKSESSIONPRIVATE_H diff --git a/src/network/bearer/qnetworksession_s60_p.cpp b/src/network/bearer/qnetworksession_s60_p.cpp index 764c1c4..0a54b87 100644 --- a/src/network/bearer/qnetworksession_s60_p.cpp +++ b/src/network/bearer/qnetworksession_s60_p.cpp @@ -49,7 +49,7 @@ #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE QNetworkSessionPrivate::QNetworkSessionPrivate() : CActive(CActive::EPriorityStandard), state(QNetworkSession::Invalid), @@ -1165,4 +1165,4 @@ void ConnectionProgressNotifier::RunL() #include "moc_qnetworksession_s60_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworksession_s60_p.h b/src/network/bearer/qnetworksession_s60_p.h index cfb99c9..6e62f10 100644 --- a/src/network/bearer/qnetworksession_s60_p.h +++ b/src/network/bearer/qnetworksession_s60_p.h @@ -67,7 +67,7 @@ typedef int(*TOpenCSetdefaultifFunction)(const struct ifreq*); -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class ConnectionProgressNotifier; @@ -207,7 +207,7 @@ private: // Data }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif //QNETWORKSESSIONPRIVATE_H diff --git a/src/network/bearer/qnetworksessionengine.cpp b/src/network/bearer/qnetworksessionengine.cpp index 55fc4f3..7148d14 100644 --- a/src/network/bearer/qnetworksessionengine.cpp +++ b/src/network/bearer/qnetworksessionengine.cpp @@ -41,7 +41,7 @@ #include "qnetworksessionengine_p.h" -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE QNetworkSessionEngine::QNetworkSessionEngine(QObject *parent) : QObject(parent) @@ -53,5 +53,5 @@ QNetworkSessionEngine::~QNetworkSessionEngine() } #include "moc_qnetworksessionengine_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworksessionengine_p.h b/src/network/bearer/qnetworksessionengine_p.h index 795a209..6be750f 100644 --- a/src/network/bearer/qnetworksessionengine_p.h +++ b/src/network/bearer/qnetworksessionengine_p.h @@ -53,13 +53,12 @@ // We mean it. // -#include #include #include #include #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; class QNetworkSessionEngine : public QObject @@ -93,6 +92,6 @@ Q_SIGNALS: void connectionError(const QString &id, QNetworkSessionEngine::ConnectionError error); }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif diff --git a/src/network/bearer/qnlaengine_win.cpp b/src/network/bearer/qnlaengine_win.cpp index b606ef4..b1156d0 100644 --- a/src/network/bearer/qnlaengine_win.cpp +++ b/src/network/bearer/qnlaengine_win.cpp @@ -51,7 +51,7 @@ #include "qnetworksessionengine_win_p.h" -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QNlaEngine, nlaEngine) @@ -586,7 +586,7 @@ QNlaEngine *QNlaEngine::instance() #include "qnlaengine_win.moc" #include "moc_qnlaengine_win_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnlaengine_win_p.h b/src/network/bearer/qnlaengine_win_p.h index 394b8cf..d9d752b 100644 --- a/src/network/bearer/qnlaengine_win_p.h +++ b/src/network/bearer/qnlaengine_win_p.h @@ -57,7 +57,7 @@ #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; class QNlaThread; @@ -99,6 +99,6 @@ private: QMap configurationInterface; }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif diff --git a/src/network/bearer/qnmdbushelper.cpp b/src/network/bearer/qnmdbushelper.cpp index 3b780f6..e8ac78e 100644 --- a/src/network/bearer/qnmdbushelper.cpp +++ b/src/network/bearer/qnmdbushelper.cpp @@ -54,7 +54,7 @@ #include -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE void QNmDBusHelper::deviceStateChanged(quint32 state) { @@ -114,4 +114,4 @@ void QNmDBusHelper::slotSettingsRemoved() } #include "moc_qnmdbushelper_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnmdbushelper_p.h b/src/network/bearer/qnmdbushelper_p.h index f0248dc..ebd4e63 100644 --- a/src/network/bearer/qnmdbushelper_p.h +++ b/src/network/bearer/qnmdbushelper_p.h @@ -53,14 +53,13 @@ // We mean it. // -#include #if !defined(QT_NO_DBUS) && !defined(Q_OS_MAC) #include #include #include #endif -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE #if !defined(QT_NO_DBUS) && !defined(Q_OS_MAC) @@ -85,6 +84,6 @@ Q_SIGNALS: }; #endif -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif// QNMDBUSHELPERPRIVATE_H diff --git a/src/network/bearer/qnmwifiengine_unix.cpp b/src/network/bearer/qnmwifiengine_unix.cpp index f558fa8..c228bcc 100644 --- a/src/network/bearer/qnmwifiengine_unix.cpp +++ b/src/network/bearer/qnmwifiengine_unix.cpp @@ -51,16 +51,12 @@ #include +QT_BEGIN_NAMESPACE - -QTM_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QNmWifiEngine, nmWifiEngine) typedef QList > QNmSettingsAddressMap; -QTM_END_NAMESPACE - -Q_DECLARE_METATYPE(QTM_PREPEND_NAMESPACE(QNmSettingsAddressMap)) -QTM_BEGIN_NAMESPACE +Q_DECLARE_METATYPE(QNmSettingsAddressMap) QNmWifiEngine::QNmWifiEngine(QObject *parent) : QNetworkSessionEngine(parent) @@ -1129,5 +1125,5 @@ QStringList QNmWifiEngine::getConnectionPathForId(const QString &uuid) #include "moc_qnmwifiengine_unix_p.cpp" -QTM_END_NAMESPACE +QT_END_NAMESPACE diff --git a/src/network/bearer/qnmwifiengine_unix_p.h b/src/network/bearer/qnmwifiengine_unix_p.h index 1287800..a1bdb7b 100644 --- a/src/network/bearer/qnmwifiengine_unix_p.h +++ b/src/network/bearer/qnmwifiengine_unix_p.h @@ -67,7 +67,7 @@ -QTM_BEGIN_NAMESPACE +QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; @@ -157,7 +157,7 @@ private slots: void slotActivationFinished(QDBusPendingCallWatcher*); }; -QTM_END_NAMESPACE +QT_END_NAMESPACE #endif diff --git a/src/network/network.pro b/src/network/network.pro index e890b94..8582d8a 100644 --- a/src/network/network.pro +++ b/src/network/network.pro @@ -17,6 +17,7 @@ unix:QMAKE_PKGCONFIG_REQUIRES = QtCore include(../qbase.pri) include(access/access.pri) +include(bearer/bearer.pri) include(kernel/kernel.pri) include(socket/socket.pri) include(ssl/ssl.pri) diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index d5d72a7..176cc3a 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -434,7 +434,10 @@ SUBDIRS += \ qmargins \ qnetworkaddressentry \ qnetworkcachemetadata \ + qnetworkconfigmanager \ + qnetworkconfiguration \ qnetworkdiskcache \ + qnetworksession \ qobjectperformance \ qpainterpathstroker \ qplugin \ diff --git a/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro b/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro index 0b2ed1a..b539dd3 100644 --- a/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro +++ b/tests/auto/qnetworkconfigmanager/qnetworkconfigmanager.pro @@ -1,15 +1,5 @@ +load(qttest_p4) SOURCES += tst_qnetworkconfigmanager.cpp HEADERS += ../qbearertestcommon.h -TARGET = tst_qnetworkconfigurationmanager -CONFIG += testcase QT = core network - -INCLUDEPATH += ../../../src/bearer - -include(../../../common.pri) -qtAddLibrary(QtBearer) - -symbian { - TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData -} diff --git a/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp b/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp index 796677d..f92704d 100644 --- a/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp +++ b/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp @@ -49,7 +49,7 @@ #include #endif -QTM_USE_NAMESPACE +QT_USE_NAMESPACE class tst_QNetworkConfigurationManager : public QObject { Q_OBJECT diff --git a/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro b/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro index 61e4097..078983d 100644 --- a/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro +++ b/tests/auto/qnetworkconfiguration/qnetworkconfiguration.pro @@ -1,15 +1,5 @@ +load(qttest_p4) SOURCES += tst_qnetworkconfiguration.cpp HEADERS += ../qbearertestcommon.h -TARGET = tst_qnetworkconfiguration -CONFIG += testcase QT = core network - -INCLUDEPATH += ../../../src/bearer - -include(../../../common.pri) -qtAddLibrary(QtBearer) - -symbian { - TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData -} diff --git a/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp b/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp index cbb13f3..ac0f054 100644 --- a/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp +++ b/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp @@ -49,7 +49,7 @@ #include #endif -QTM_USE_NAMESPACE +QT_USE_NAMESPACE class tst_QNetworkConfiguration : public QObject { Q_OBJECT diff --git a/tests/auto/qnetworksession/lackey/lackey.pro b/tests/auto/qnetworksession/lackey/lackey.pro index 4cb8555..ccbdd98 100644 --- a/tests/auto/qnetworksession/lackey/lackey.pro +++ b/tests/auto/qnetworksession/lackey/lackey.pro @@ -1,12 +1,4 @@ +load(qttest_p4) SOURCES += main.cpp -TARGET = qnetworksessionlackey -INCLUDEPATH += ../../../../src/bearer -DEPENDPATH += ../../../../src/bearer QT = core network - -CONFIG+= testcase - -include(../../../../common.pri) - -qtAddLibrary(QtBearer) diff --git a/tests/auto/qnetworksession/lackey/main.cpp b/tests/auto/qnetworksession/lackey/main.cpp index 53f6f4f..8190292 100644 --- a/tests/auto/qnetworksession/lackey/main.cpp +++ b/tests/auto/qnetworksession/lackey/main.cpp @@ -48,7 +48,7 @@ #include -QTM_USE_NAMESPACE +QT_USE_NAMESPACE #define NO_DISCOVERED_CONFIGURATIONS_ERROR 1 diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp index cbd4c8f..b5935e1 100644 --- a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp +++ b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp @@ -51,7 +51,7 @@ #include #endif -QTM_USE_NAMESPACE +QT_USE_NAMESPACE Q_DECLARE_METATYPE(QNetworkConfiguration) Q_DECLARE_METATYPE(QNetworkSession::State); diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro index 1410601..bf33122 100644 --- a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro +++ b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.pro @@ -1,21 +1,5 @@ +load(qttest_p4) SOURCES += tst_qnetworksession.cpp HEADERS += ../../qbearertestcommon.h -TARGET = tst_qnetworksession -CONFIG += testcase QT = core network - -INCLUDEPATH += ../../../../src/bearer - -include(../../../../common.pri) -qtAddLibrary(QtBearer) - -wince* { - LACKEY.sources = $$OUTPUT_DIR/build/tests/bin/qnetworksessionlackey.exe - LACKEY.path = . - DEPLOYMENT += LACKEY -} - -symbian { - TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData -} diff --git a/tests/manual/bearerex/bearerex.h b/tests/manual/bearerex/bearerex.h index f18180e..04da6ca 100644 --- a/tests/manual/bearerex/bearerex.h +++ b/tests/manual/bearerex/bearerex.h @@ -54,7 +54,7 @@ class QHttp; class SessionTab; -QTM_USE_NAMESPACE +QT_USE_NAMESPACE class BearerEx : public QMainWindow, public Ui::BearerExMainWindow { diff --git a/tests/manual/bearerex/bearerex.pro b/tests/manual/bearerex/bearerex.pro index a870eb1..476e87c 100644 --- a/tests/manual/bearerex/bearerex.pro +++ b/tests/manual/bearerex/bearerex.pro @@ -8,13 +8,6 @@ QT += core \ FORMS += sessiondialog.ui \ bearerex.ui \ detailedinfodialog.ui -include(../../common.pri) -#not really a test case but deployment happens same way -CONFIG += testcase - -DEPENDPATH += . -INCLUDEPATH += . \ - ../../src/bearer # Example headers and sources HEADERS += bearerex.h \ @@ -23,12 +16,3 @@ HEADERS += bearerex.h \ SOURCES += bearerex.cpp \ main.cpp \ xqlistwidget.cpp - -symbian: { - bearerex.sources = Qtbearer.dll - bearerex.path = /sys/bin - DEPLOYMENT += bearerex - - TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData -} -qtAddLibrary(QtBearer) diff --git a/tests/manual/networkmanager/networkmanager.pro b/tests/manual/networkmanager/networkmanager.pro index 31b2af1..84289d3 100644 --- a/tests/manual/networkmanager/networkmanager.pro +++ b/tests/manual/networkmanager/networkmanager.pro @@ -4,16 +4,6 @@ TARGET = tst_networkmanagertest QT = core network dbus gui -#not really a test case but deployment happens same way -CONFIG += testcase - requires(contains(QT_CONFIG,dbus)) -INCLUDEPATH += ../../src/bearer -include(../../common.pri) - -qtAddLibrary(QtBearer) - -#MOC_DIR = .moc -#OBJECTS_DIR = .obj FORMS += dialog.ui diff --git a/tests/manual/networkmanager/nmview.cpp b/tests/manual/networkmanager/nmview.cpp index ca9d907..35a0204 100644 --- a/tests/manual/networkmanager/nmview.cpp +++ b/tests/manual/networkmanager/nmview.cpp @@ -68,7 +68,7 @@ #include #include #include -#include +#include //static QDBusConnection dbc = QDBusConnection::systemBus(); //typedef QMap< QString, QMap > SettingsMap; diff --git a/tests/manual/networkmanager/nmview.h b/tests/manual/networkmanager/nmview.h index 641385e..7db56d4 100644 --- a/tests/manual/networkmanager/nmview.h +++ b/tests/manual/networkmanager/nmview.h @@ -47,7 +47,7 @@ #include "ui_dialog.h" -QTM_USE_NAMESPACE +QT_USE_NAMESPACE class QListWidget; class QTreeWidget; -- cgit v0.12 From ce2439e97af96f6a704522b1aefebd888efd4fff Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 22 Dec 2009 14:34:51 +1000 Subject: Fix up license headers. --- config.tests/mac/corelwan/corewlantest.mm | 2 +- config.tests/unix/networkmanager/main.cpp | 2 +- examples/network/bearercloud/bearercloud.cpp | 2 +- examples/network/bearercloud/bearercloud.h | 2 +- examples/network/bearercloud/cloud.cpp | 2 +- examples/network/bearercloud/cloud.h | 2 +- examples/network/bearercloud/main.cpp | 2 +- examples/network/bearermonitor/bearermonitor.cpp | 2 +- examples/network/bearermonitor/bearermonitor.h | 2 +- examples/network/bearermonitor/main.cpp | 2 +- examples/network/bearermonitor/sessionwidget.cpp | 2 +- examples/network/bearermonitor/sessionwidget.h | 2 +- src/network/bearer/qcorewlanengine_mac_p.h | 2 +- src/network/bearer/qgenericengine.cpp | 2 +- src/network/bearer/qgenericengine_p.h | 2 +- src/network/bearer/qnativewifiengine_win.cpp | 2 +- src/network/bearer/qnativewifiengine_win_p.h | 2 +- src/network/bearer/qnetworkconfigmanager.cpp | 2 +- src/network/bearer/qnetworkconfigmanager.h | 2 +- src/network/bearer/qnetworkconfigmanager_maemo.cpp | 2 +- src/network/bearer/qnetworkconfigmanager_maemo_p.h | 2 +- src/network/bearer/qnetworkconfigmanager_p.cpp | 2 +- src/network/bearer/qnetworkconfigmanager_p.h | 2 +- src/network/bearer/qnetworkconfigmanager_s60_p.cpp | 2 +- src/network/bearer/qnetworkconfigmanager_s60_p.h | 2 +- src/network/bearer/qnetworkconfiguration.cpp | 2 +- src/network/bearer/qnetworkconfiguration.h | 2 +- src/network/bearer/qnetworkconfiguration_maemo_p.h | 2 +- src/network/bearer/qnetworkconfiguration_p.h | 2 +- src/network/bearer/qnetworkconfiguration_s60_p.cpp | 2 +- src/network/bearer/qnetworkconfiguration_s60_p.h | 2 +- src/network/bearer/qnetworkmanagerservice_p.cpp | 2 +- src/network/bearer/qnetworkmanagerservice_p.h | 2 +- src/network/bearer/qnetworksession.cpp | 2 +- src/network/bearer/qnetworksession.h | 2 +- src/network/bearer/qnetworksession_maemo.cpp | 2 +- src/network/bearer/qnetworksession_maemo_p.h | 2 +- src/network/bearer/qnetworksession_p.cpp | 2 +- src/network/bearer/qnetworksession_p.h | 2 +- src/network/bearer/qnetworksession_s60_p.cpp | 2 +- src/network/bearer/qnetworksession_s60_p.h | 2 +- src/network/bearer/qnetworksessionengine.cpp | 2 +- src/network/bearer/qnetworksessionengine_p.h | 2 +- src/network/bearer/qnetworksessionengine_win_p.h | 2 +- src/network/bearer/qnlaengine_win.cpp | 2 +- src/network/bearer/qnlaengine_win_p.h | 2 +- src/network/bearer/qnmdbushelper.cpp | 2 +- src/network/bearer/qnmdbushelper_p.h | 2 +- src/network/bearer/qnmwifiengine_unix.cpp | 2 +- src/network/bearer/qnmwifiengine_unix_p.h | 2 +- tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp | 2 +- tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp | 2 +- tests/auto/qnetworksession/lackey/main.cpp | 2 +- tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp | 2 +- tests/manual/bearerex/bearerex.cpp | 3 ++- tests/manual/bearerex/bearerex.h | 3 ++- tests/manual/bearerex/main.cpp | 3 ++- tests/manual/bearerex/xqlistwidget.cpp | 3 ++- tests/manual/bearerex/xqlistwidget.h | 3 ++- tests/manual/networkmanager/networkmanagertest.cpp | 2 +- tests/manual/networkmanager/nmview.cpp | 2 +- tests/manual/networkmanager/nmview.h | 2 +- tests/manual/networkmanager/startdlg.cpp | 3 ++- tests/manual/networkmanager/startdlg.h | 3 ++- 64 files changed, 71 insertions(+), 64 deletions(-) diff --git a/config.tests/mac/corelwan/corewlantest.mm b/config.tests/mac/corelwan/corewlantest.mm index bcddf44..3a29d84 100644 --- a/config.tests/mac/corelwan/corewlantest.mm +++ b/config.tests/mac/corelwan/corewlantest.mm @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the config.tests of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/config.tests/unix/networkmanager/main.cpp b/config.tests/unix/networkmanager/main.cpp index 6f2bae6..27e6bd1 100644 --- a/config.tests/unix/networkmanager/main.cpp +++ b/config.tests/unix/networkmanager/main.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the config.tests of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/examples/network/bearercloud/bearercloud.cpp b/examples/network/bearercloud/bearercloud.cpp index 182d4ec..27a296d 100644 --- a/examples/network/bearercloud/bearercloud.cpp +++ b/examples/network/bearercloud/bearercloud.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/examples/network/bearercloud/bearercloud.h b/examples/network/bearercloud/bearercloud.h index 79b441f..f09cb53 100644 --- a/examples/network/bearercloud/bearercloud.h +++ b/examples/network/bearercloud/bearercloud.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/examples/network/bearercloud/cloud.cpp b/examples/network/bearercloud/cloud.cpp index 4a1bde7..dcb7caf 100644 --- a/examples/network/bearercloud/cloud.cpp +++ b/examples/network/bearercloud/cloud.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/examples/network/bearercloud/cloud.h b/examples/network/bearercloud/cloud.h index f844725..7a45ff2 100644 --- a/examples/network/bearercloud/cloud.h +++ b/examples/network/bearercloud/cloud.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/examples/network/bearercloud/main.cpp b/examples/network/bearercloud/main.cpp index 33c55e9..86ef46f 100644 --- a/examples/network/bearercloud/main.cpp +++ b/examples/network/bearercloud/main.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/examples/network/bearermonitor/bearermonitor.cpp b/examples/network/bearermonitor/bearermonitor.cpp index 70c8269..5b2bad1 100644 --- a/examples/network/bearermonitor/bearermonitor.cpp +++ b/examples/network/bearermonitor/bearermonitor.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/examples/network/bearermonitor/bearermonitor.h b/examples/network/bearermonitor/bearermonitor.h index 9306d90..d7025dd 100644 --- a/examples/network/bearermonitor/bearermonitor.h +++ b/examples/network/bearermonitor/bearermonitor.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/examples/network/bearermonitor/main.cpp b/examples/network/bearermonitor/main.cpp index 9685181..b7ac4fe 100644 --- a/examples/network/bearermonitor/main.cpp +++ b/examples/network/bearermonitor/main.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/examples/network/bearermonitor/sessionwidget.cpp b/examples/network/bearermonitor/sessionwidget.cpp index 7633dd7..1e59935 100644 --- a/examples/network/bearermonitor/sessionwidget.cpp +++ b/examples/network/bearermonitor/sessionwidget.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/examples/network/bearermonitor/sessionwidget.h b/examples/network/bearermonitor/sessionwidget.h index 8bc60e4..868de3a 100644 --- a/examples/network/bearermonitor/sessionwidget.h +++ b/examples/network/bearermonitor/sessionwidget.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qcorewlanengine_mac_p.h b/src/network/bearer/qcorewlanengine_mac_p.h index 660ddb5..d6454ca 100644 --- a/src/network/bearer/qcorewlanengine_mac_p.h +++ b/src/network/bearer/qcorewlanengine_mac_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qgenericengine.cpp b/src/network/bearer/qgenericengine.cpp index 2e48ce8..14fa886 100644 --- a/src/network/bearer/qgenericengine.cpp +++ b/src/network/bearer/qgenericengine.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qgenericengine_p.h b/src/network/bearer/qgenericengine_p.h index 88de2a0..28d6e90 100644 --- a/src/network/bearer/qgenericengine_p.h +++ b/src/network/bearer/qgenericengine_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnativewifiengine_win.cpp b/src/network/bearer/qnativewifiengine_win.cpp index b4b3888..46d4ead 100644 --- a/src/network/bearer/qnativewifiengine_win.cpp +++ b/src/network/bearer/qnativewifiengine_win.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnativewifiengine_win_p.h b/src/network/bearer/qnativewifiengine_win_p.h index adc75e1..4817867 100644 --- a/src/network/bearer/qnativewifiengine_win_p.h +++ b/src/network/bearer/qnativewifiengine_win_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 4b28b22..5031dd4 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfigmanager.h b/src/network/bearer/qnetworkconfigmanager.h index 940fcc5..b7ab72b 100644 --- a/src/network/bearer/qnetworkconfigmanager.h +++ b/src/network/bearer/qnetworkconfigmanager.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfigmanager_maemo.cpp b/src/network/bearer/qnetworkconfigmanager_maemo.cpp index 26909f9..2188d61 100644 --- a/src/network/bearer/qnetworkconfigmanager_maemo.cpp +++ b/src/network/bearer/qnetworkconfigmanager_maemo.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfigmanager_maemo_p.h b/src/network/bearer/qnetworkconfigmanager_maemo_p.h index a5462b8..5cc99c2 100644 --- a/src/network/bearer/qnetworkconfigmanager_maemo_p.h +++ b/src/network/bearer/qnetworkconfigmanager_maemo_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 49135c1..47b23d2 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 184d1bd..f2e2ee5 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfigmanager_s60_p.cpp b/src/network/bearer/qnetworkconfigmanager_s60_p.cpp index 8859a4e..b5bd4d2 100644 --- a/src/network/bearer/qnetworkconfigmanager_s60_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_s60_p.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfigmanager_s60_p.h b/src/network/bearer/qnetworkconfigmanager_s60_p.h index cd48df6..c4d4e30 100644 --- a/src/network/bearer/qnetworkconfigmanager_s60_p.h +++ b/src/network/bearer/qnetworkconfigmanager_s60_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfiguration.cpp b/src/network/bearer/qnetworkconfiguration.cpp index 9422f07..c105dfb 100644 --- a/src/network/bearer/qnetworkconfiguration.cpp +++ b/src/network/bearer/qnetworkconfiguration.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfiguration.h b/src/network/bearer/qnetworkconfiguration.h index e1fbc43..63c37e5 100644 --- a/src/network/bearer/qnetworkconfiguration.h +++ b/src/network/bearer/qnetworkconfiguration.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfiguration_maemo_p.h b/src/network/bearer/qnetworkconfiguration_maemo_p.h index 8d7fbcf..0ae6ea6 100644 --- a/src/network/bearer/qnetworkconfiguration_maemo_p.h +++ b/src/network/bearer/qnetworkconfiguration_maemo_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfiguration_p.h b/src/network/bearer/qnetworkconfiguration_p.h index 1dd53c4..69d7e18 100644 --- a/src/network/bearer/qnetworkconfiguration_p.h +++ b/src/network/bearer/qnetworkconfiguration_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfiguration_s60_p.cpp b/src/network/bearer/qnetworkconfiguration_s60_p.cpp index 289e09c..978c62c 100644 --- a/src/network/bearer/qnetworkconfiguration_s60_p.cpp +++ b/src/network/bearer/qnetworkconfiguration_s60_p.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkconfiguration_s60_p.h b/src/network/bearer/qnetworkconfiguration_s60_p.h index bccad0c..faacd64 100644 --- a/src/network/bearer/qnetworkconfiguration_s60_p.h +++ b/src/network/bearer/qnetworkconfiguration_s60_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkmanagerservice_p.cpp b/src/network/bearer/qnetworkmanagerservice_p.cpp index 4e25533..9516f31 100644 --- a/src/network/bearer/qnetworkmanagerservice_p.cpp +++ b/src/network/bearer/qnetworkmanagerservice_p.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworkmanagerservice_p.h b/src/network/bearer/qnetworkmanagerservice_p.h index 91bf69d..520aeac 100644 --- a/src/network/bearer/qnetworkmanagerservice_p.h +++ b/src/network/bearer/qnetworkmanagerservice_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp index bdae9bc..8ebe1c2 100644 --- a/src/network/bearer/qnetworksession.cpp +++ b/src/network/bearer/qnetworksession.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksession.h b/src/network/bearer/qnetworksession.h index 61093c7..0573c70 100644 --- a/src/network/bearer/qnetworksession.h +++ b/src/network/bearer/qnetworksession.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksession_maemo.cpp b/src/network/bearer/qnetworksession_maemo.cpp index 742499c..a35d8cb 100644 --- a/src/network/bearer/qnetworksession_maemo.cpp +++ b/src/network/bearer/qnetworksession_maemo.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksession_maemo_p.h b/src/network/bearer/qnetworksession_maemo_p.h index 6594176..c5483a9 100644 --- a/src/network/bearer/qnetworksession_maemo_p.h +++ b/src/network/bearer/qnetworksession_maemo_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksession_p.cpp b/src/network/bearer/qnetworksession_p.cpp index 6df4fdb9..8e39216 100644 --- a/src/network/bearer/qnetworksession_p.cpp +++ b/src/network/bearer/qnetworksession_p.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksession_p.h b/src/network/bearer/qnetworksession_p.h index 45e0ebf..0e11b3d 100644 --- a/src/network/bearer/qnetworksession_p.h +++ b/src/network/bearer/qnetworksession_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksession_s60_p.cpp b/src/network/bearer/qnetworksession_s60_p.cpp index 0a54b87..ed5269e 100644 --- a/src/network/bearer/qnetworksession_s60_p.cpp +++ b/src/network/bearer/qnetworksession_s60_p.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksession_s60_p.h b/src/network/bearer/qnetworksession_s60_p.h index 6e62f10..9aaedb7 100644 --- a/src/network/bearer/qnetworksession_s60_p.h +++ b/src/network/bearer/qnetworksession_s60_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksessionengine.cpp b/src/network/bearer/qnetworksessionengine.cpp index 7148d14..9e6839e 100644 --- a/src/network/bearer/qnetworksessionengine.cpp +++ b/src/network/bearer/qnetworksessionengine.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksessionengine_p.h b/src/network/bearer/qnetworksessionengine_p.h index 6be750f..8eb17d4 100644 --- a/src/network/bearer/qnetworksessionengine_p.h +++ b/src/network/bearer/qnetworksessionengine_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnetworksessionengine_win_p.h b/src/network/bearer/qnetworksessionengine_win_p.h index cf01719..e68a35b 100644 --- a/src/network/bearer/qnetworksessionengine_win_p.h +++ b/src/network/bearer/qnetworksessionengine_win_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnlaengine_win.cpp b/src/network/bearer/qnlaengine_win.cpp index b1156d0..579b0e1 100644 --- a/src/network/bearer/qnlaengine_win.cpp +++ b/src/network/bearer/qnlaengine_win.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnlaengine_win_p.h b/src/network/bearer/qnlaengine_win_p.h index d9d752b..1e7d051 100644 --- a/src/network/bearer/qnlaengine_win_p.h +++ b/src/network/bearer/qnlaengine_win_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnmdbushelper.cpp b/src/network/bearer/qnmdbushelper.cpp index e8ac78e..5d7403b 100644 --- a/src/network/bearer/qnmdbushelper.cpp +++ b/src/network/bearer/qnmdbushelper.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnmdbushelper_p.h b/src/network/bearer/qnmdbushelper_p.h index ebd4e63..99b0357 100644 --- a/src/network/bearer/qnmdbushelper_p.h +++ b/src/network/bearer/qnmdbushelper_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnmwifiengine_unix.cpp b/src/network/bearer/qnmwifiengine_unix.cpp index c228bcc..5870a9f 100644 --- a/src/network/bearer/qnmwifiengine_unix.cpp +++ b/src/network/bearer/qnmwifiengine_unix.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/network/bearer/qnmwifiengine_unix_p.h b/src/network/bearer/qnmwifiengine_unix_p.h index a1bdb7b..3af73ea 100644 --- a/src/network/bearer/qnmwifiengine_unix_p.h +++ b/src/network/bearer/qnmwifiengine_unix_p.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp b/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp index f92704d..f065f78 100644 --- a/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp +++ b/tests/auto/qnetworkconfigmanager/tst_qnetworkconfigmanager.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp b/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp index ac0f054..9ac9e47 100644 --- a/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp +++ b/tests/auto/qnetworkconfiguration/tst_qnetworkconfiguration.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/tests/auto/qnetworksession/lackey/main.cpp b/tests/auto/qnetworksession/lackey/main.cpp index 8190292..9f32696 100644 --- a/tests/auto/qnetworksession/lackey/main.cpp +++ b/tests/auto/qnetworksession/lackey/main.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp index b5935e1..fc0db05 100644 --- a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp +++ b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/tests/manual/bearerex/bearerex.cpp b/tests/manual/bearerex/bearerex.cpp index 68590cc..c5bf786 100644 --- a/tests/manual/bearerex/bearerex.cpp +++ b/tests/manual/bearerex/bearerex.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include "bearerex.h" #include diff --git a/tests/manual/bearerex/bearerex.h b/tests/manual/bearerex/bearerex.h index 04da6ca..ff5f23c 100644 --- a/tests/manual/bearerex/bearerex.h +++ b/tests/manual/bearerex/bearerex.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef ACCESSPOINTMANAGEREX_H #define ACCESSPOINTMANAGEREX_H diff --git a/tests/manual/bearerex/main.cpp b/tests/manual/bearerex/main.cpp index e13a494..20b167e 100644 --- a/tests/manual/bearerex/main.cpp +++ b/tests/manual/bearerex/main.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include #include "bearerex.h" diff --git a/tests/manual/bearerex/xqlistwidget.cpp b/tests/manual/bearerex/xqlistwidget.cpp index 0618725..8104779 100644 --- a/tests/manual/bearerex/xqlistwidget.cpp +++ b/tests/manual/bearerex/xqlistwidget.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include "xqlistwidget.h" XQListWidget::XQListWidget(QWidget* parent) : QListWidget(parent) diff --git a/tests/manual/bearerex/xqlistwidget.h b/tests/manual/bearerex/xqlistwidget.h index 1053328..0649c2b 100644 --- a/tests/manual/bearerex/xqlistwidget.h +++ b/tests/manual/bearerex/xqlistwidget.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef XQLISTWIDGET_H #define XQLISTWIDGET_H diff --git a/tests/manual/networkmanager/networkmanagertest.cpp b/tests/manual/networkmanager/networkmanagertest.cpp index a39b041..8a6c5fa 100644 --- a/tests/manual/networkmanager/networkmanagertest.cpp +++ b/tests/manual/networkmanager/networkmanagertest.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/tests/manual/networkmanager/nmview.cpp b/tests/manual/networkmanager/nmview.cpp index 35a0204..f7611f0 100644 --- a/tests/manual/networkmanager/nmview.cpp +++ b/tests/manual/networkmanager/nmview.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/tests/manual/networkmanager/nmview.h b/tests/manual/networkmanager/nmview.h index 7db56d4..b725ade 100644 --- a/tests/manual/networkmanager/nmview.h +++ b/tests/manual/networkmanager/nmview.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/tests/manual/networkmanager/startdlg.cpp b/tests/manual/networkmanager/startdlg.cpp index 4720932..e34b5e9 100644 --- a/tests/manual/networkmanager/startdlg.cpp +++ b/tests/manual/networkmanager/startdlg.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include "startdlg.h" #include diff --git a/tests/manual/networkmanager/startdlg.h b/tests/manual/networkmanager/startdlg.h index a9f1e7c..32c8557 100644 --- a/tests/manual/networkmanager/startdlg.h +++ b/tests/manual/networkmanager/startdlg.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include #include #include -- cgit v0.12 From f9d1d43e714c467d4101c6bd8eca072fdf9fbdec Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 22 Dec 2009 14:01:30 +1000 Subject: Fix compile warnings. --- src/network/bearer/qgenericengine.cpp | 2 +- src/network/bearer/qnetworksession.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/network/bearer/qgenericengine.cpp b/src/network/bearer/qgenericengine.cpp index 14fa886..d14f0fa 100644 --- a/src/network/bearer/qgenericengine.cpp +++ b/src/network/bearer/qgenericengine.cpp @@ -159,7 +159,7 @@ QList QGenericEngine::getConfigurations(bool *ok continue; // ignore WLAN interface handled in seperate engine - if (qGetInterfaceType(interface.name()) == "WLAN") + if (qGetInterfaceType(interface.name()) == QLatin1String("WLAN")) continue; QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp index 8ebe1c2..dbea087 100644 --- a/src/network/bearer/qnetworksession.cpp +++ b/src/network/bearer/qnetworksession.cpp @@ -509,14 +509,14 @@ QVariant QNetworkSession::sessionProperty(const QString& key) const if (!d->publicConfig.isValid()) return QVariant(); - if (key == "ActiveConfigurationIdentifier") { + if (key == QLatin1String("ActiveConfigurationIdentifier")) { if (!d->isActive) return QString(); else return d->activeConfig.identifier(); } - if (key == "UserChoiceConfigurationIdentifier") { + if (key == QLatin1String("UserChoiceConfigurationIdentifier")) { if (!d->isActive || d->publicConfig.type() != QNetworkConfiguration::UserChoice) return QString(); @@ -539,9 +539,10 @@ QVariant QNetworkSession::sessionProperty(const QString& key) const */ void QNetworkSession::setSessionProperty(const QString& key, const QVariant& value) { - if (key == "ActiveConfigurationIdentifier" - || key == "UserChoiceConfigurationIdentifier") + if (key == QLatin1String("ActiveConfigurationIdentifier") || + key == QLatin1String("UserChoiceConfigurationIdentifier")) { return; + } d->setSessionProperty(key, value); } -- cgit v0.12 From d5b6c723973449914134231c01a381ef9af9f6d4 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 22 Dec 2009 14:40:53 +1000 Subject: Make unit tests compile. --- tests/auto/qnetworksession/lackey/lackey.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/qnetworksession/lackey/lackey.pro b/tests/auto/qnetworksession/lackey/lackey.pro index ccbdd98..6cc1b43 100644 --- a/tests/auto/qnetworksession/lackey/lackey.pro +++ b/tests/auto/qnetworksession/lackey/lackey.pro @@ -1,4 +1,4 @@ -load(qttest_p4) SOURCES += main.cpp +TARGET = qnetworksessionlackey QT = core network -- cgit v0.12 From 27b47c630f8b71897ba56c983c24afe1538f33dc Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 1 Dec 2009 15:46:59 +1000 Subject: Convert generic engine into a plugin. --- src/network/bearer/bearer.pri | 12 +- src/network/bearer/qbearerplugin.cpp | 58 ++++++ src/network/bearer/qbearerplugin.h | 82 +++++++++ src/network/bearer/qgenericengine.cpp | 234 ------------------------- src/network/bearer/qgenericengine_p.h | 94 ---------- src/network/bearer/qnetworkconfigmanager.cpp | 7 + src/network/bearer/qnetworkconfigmanager_p.cpp | 23 ++- src/network/bearer/qnetworkconfigmanager_p.h | 4 +- src/network/bearer/qnetworkconfiguration_p.h | 2 +- src/network/bearer/qnetworksession_p.cpp | 10 +- src/network/bearer/qnetworksessionengine_p.h | 4 +- src/plugins/bearer/bearer.pro | 3 + src/plugins/bearer/generic/generic.pro | 13 ++ src/plugins/bearer/generic/main.cpp | 88 ++++++++++ src/plugins/bearer/generic/qgenericengine.cpp | 234 +++++++++++++++++++++++++ src/plugins/bearer/generic/qgenericengine.h | 83 +++++++++ src/plugins/plugins.pro | 2 +- 17 files changed, 606 insertions(+), 347 deletions(-) create mode 100644 src/network/bearer/qbearerplugin.cpp create mode 100644 src/network/bearer/qbearerplugin.h delete mode 100644 src/network/bearer/qgenericengine.cpp delete mode 100644 src/network/bearer/qgenericengine_p.h create mode 100644 src/plugins/bearer/bearer.pro create mode 100644 src/plugins/bearer/generic/generic.pro create mode 100644 src/plugins/bearer/generic/main.cpp create mode 100644 src/plugins/bearer/generic/qgenericengine.cpp create mode 100644 src/plugins/bearer/generic/qgenericengine.h diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index d8ddce5..4f53621 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -4,11 +4,13 @@ HEADERS += bearer/qnetworkconfiguration.h \ bearer/qnetworksession.h \ - bearer/qnetworkconfigmanager.h + bearer/qnetworkconfigmanager.h \ + bearer/qbearerplugin.h SOURCES += bearer/qnetworksession.cpp \ bearer/qnetworkconfigmanager.cpp \ - bearer/qnetworkconfiguration.cpp + bearer/qnetworkconfiguration.cpp \ + bearer/qbearerplugin.cpp symbian { exists($${EPOCROOT}epoc32/release/winscw/udeb/cmmanager.lib)| \ @@ -72,13 +74,11 @@ symbian { HEADERS += bearer/qnetworkconfigmanager_p.h \ bearer/qnetworkconfiguration_p.h \ bearer/qnetworksession_p.h \ - bearer/qnetworksessionengine_p.h \ - bearer/qgenericengine_p.h + bearer/qnetworksessionengine_p.h SOURCES += bearer/qnetworkconfigmanager_p.cpp \ bearer/qnetworksession_p.cpp \ - bearer/qnetworksessionengine.cpp \ - bearer/qgenericengine.cpp + bearer/qnetworksessionengine.cpp unix:!mac:contains(networkmanager_enabled, yes) { contains(QT_CONFIG,dbus) { diff --git a/src/network/bearer/qbearerplugin.cpp b/src/network/bearer/qbearerplugin.cpp new file mode 100644 index 0000000..252ee71 --- /dev/null +++ b/src/network/bearer/qbearerplugin.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtNetwork module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qbearerplugin.h" + +#include + +QT_BEGIN_NAMESPACE + +QBearerEnginePlugin::QBearerEnginePlugin(QObject *parent) +: QObject(parent) +{ + qDebug() << Q_FUNC_INFO; +} + +QBearerEnginePlugin::~QBearerEnginePlugin() +{ +} + +QT_END_NAMESPACE diff --git a/src/network/bearer/qbearerplugin.h b/src/network/bearer/qbearerplugin.h new file mode 100644 index 0000000..036d712 --- /dev/null +++ b/src/network/bearer/qbearerplugin.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtNetwork module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QBEARERPLUGIN_H +#define QBEARERPLUGIN_H + +#include "qnetworksessionengine_p.h" + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Network) + +struct Q_NETWORK_EXPORT QBearerEngineFactoryInterface : public QFactoryInterface +{ + virtual QBearerEngine *create(const QString &key = QString()) const = 0; +}; + +#define QBearerEngineFactoryInterface_iid "com.trolltech.Qt.QBearerEngineFactoryInterface" +Q_DECLARE_INTERFACE(QBearerEngineFactoryInterface, QBearerEngineFactoryInterface_iid) + +class Q_NETWORK_EXPORT QBearerEnginePlugin : public QObject, public QBearerEngineFactoryInterface +{ + Q_OBJECT + Q_INTERFACES(QBearerEngineFactoryInterface:QFactoryInterface) + +public: + explicit QBearerEnginePlugin(QObject *parent = 0); + virtual ~QBearerEnginePlugin(); + + virtual QStringList keys() const = 0; + virtual QBearerEngine *create(const QString &key = QString()) const = 0; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif + diff --git a/src/network/bearer/qgenericengine.cpp b/src/network/bearer/qgenericengine.cpp deleted file mode 100644 index d14f0fa..0000000 --- a/src/network/bearer/qgenericengine.cpp +++ /dev/null @@ -1,234 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qgenericengine_p.h" -#include "qnetworkconfiguration_p.h" - -#include -#include -#include -#include - -#include - -#ifdef Q_OS_WIN -#include "qnetworksessionengine_win_p.h" -#endif - -QT_BEGIN_NAMESPACE - -Q_GLOBAL_STATIC(QGenericEngine, genericEngine) - -static QString qGetInterfaceType(const QString &interface) -{ -#ifdef Q_OS_WIN32 - unsigned long oid; - DWORD bytesWritten; - - NDIS_MEDIUM medium; - NDIS_PHYSICAL_MEDIUM physicalMedium; - - HANDLE handle = CreateFile((TCHAR *)QString("\\\\.\\%1").arg(interface).utf16(), 0, - FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); - if (handle == INVALID_HANDLE_VALUE) - return QString(); - - oid = OID_GEN_MEDIA_SUPPORTED; - bytesWritten = 0; - bool result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), - &medium, sizeof(medium), &bytesWritten, 0); - if (!result) { - CloseHandle(handle); - return QString(); - } - - oid = OID_GEN_PHYSICAL_MEDIUM; - bytesWritten = 0; - result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), - &physicalMedium, sizeof(physicalMedium), &bytesWritten, 0); - if (!result) { - CloseHandle(handle); - - if (medium == NdisMedium802_3) - return QLatin1String("Ethernet"); - else - return QString(); - } - - CloseHandle(handle); - - if (medium == NdisMedium802_3) { - switch (physicalMedium) { - case NdisPhysicalMediumWirelessLan: - return QLatin1String("WLAN"); - case NdisPhysicalMediumBluetooth: - return QLatin1String("Bluetooth"); - case NdisPhysicalMediumWiMax: - return QLatin1String("WiMAX"); - default: -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "Physical Medium" << physicalMedium; -#endif - return QLatin1String("Ethernet"); - } - } - -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << medium << physicalMedium; -#endif -#else - Q_UNUSED(interface); -#endif - - return QString(); -} - -QGenericEngine::QGenericEngine(QObject *parent) -: QNetworkSessionEngine(parent) -{ - connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); - pollTimer.setInterval(10000); -} - -QGenericEngine::~QGenericEngine() -{ -} - -QList QGenericEngine::getConfigurations(bool *ok) -{ - if (ok) - *ok = true; - - QList foundConfigurations; - - // Immediately after connecting with a wireless access point - // QNetworkInterface::allInterfaces() will sometimes return an empty list. Calling it again a - // second time results in a non-empty list. If we loose interfaces we will end up removing - // network configurations which will break current sessions. - QList interfaces = QNetworkInterface::allInterfaces(); - if (interfaces.isEmpty()) - interfaces = QNetworkInterface::allInterfaces(); - - // create configuration for each interface - while (!interfaces.isEmpty()) { - QNetworkInterface interface = interfaces.takeFirst(); - - if (!interface.isValid()) - continue; - - // ignore loopback interface - if (interface.flags() & QNetworkInterface::IsLoopBack) - continue; - - // ignore WLAN interface handled in seperate engine - if (qGetInterfaceType(interface.name()) == QLatin1String("WLAN")) - continue; - - QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; - const QString humanReadableName = interface.humanReadableName(); - cpPriv->name = humanReadableName.isEmpty() ? interface.name() : humanReadableName; - cpPriv->isValid = true; - - uint identifier; - if (interface.index()) - identifier = qHash(QLatin1String("NLA:") + QString::number(interface.index())); - else - identifier = qHash(QLatin1String("NLA:") + interface.hardwareAddress()); - - cpPriv->id = QString::number(identifier); - cpPriv->state = QNetworkConfiguration::Discovered; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - if (interface.flags() & QNetworkInterface::IsUp) - cpPriv->state |= QNetworkConfiguration::Active; - - configurationInterface[identifier] = interface.name(); - - foundConfigurations.append(cpPriv); - } - - pollTimer.start(); - - return foundConfigurations; -} - -QString QGenericEngine::getInterfaceFromId(const QString &id) -{ - return configurationInterface.value(id.toUInt()); -} - -bool QGenericEngine::hasIdentifier(const QString &id) -{ - return configurationInterface.contains(id.toUInt()); -} - -QString QGenericEngine::bearerName(const QString &id) -{ - QString interface = getInterfaceFromId(id); - - if (interface.isEmpty()) - return QString(); - - return qGetInterfaceType(interface); -} - -void QGenericEngine::connectToId(const QString &id) -{ - emit connectionError(id, OperationNotSupported); -} - -void QGenericEngine::disconnectFromId(const QString &id) -{ - emit connectionError(id, OperationNotSupported); -} - -void QGenericEngine::requestUpdate() -{ - emit configurationsChanged(); -} - -QGenericEngine *QGenericEngine::instance() -{ - return genericEngine(); -} - -#include "moc_qgenericengine_p.cpp" -QT_END_NAMESPACE - diff --git a/src/network/bearer/qgenericengine_p.h b/src/network/bearer/qgenericengine_p.h deleted file mode 100644 index 28d6e90..0000000 --- a/src/network/bearer/qgenericengine_p.h +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGENERICENGINE_P_H -#define QGENERICENGINE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qnetworksessionengine_p.h" - -#include -#include - -QT_BEGIN_NAMESPACE - -class QNetworkConfigurationPrivate; - -class QGenericEngine : public QNetworkSessionEngine -{ - Q_OBJECT - -public: - QGenericEngine(QObject *parent = 0); - ~QGenericEngine(); - - QList getConfigurations(bool *ok = 0); - QString getInterfaceFromId(const QString &id); - bool hasIdentifier(const QString &id); - - QString bearerName(const QString &id); - - void connectToId(const QString &id); - void disconnectFromId(const QString &id); - - void requestUpdate(); - - static QGenericEngine *instance(); - -private: - QMap configurationInterface; - QTimer pollTimer; -}; - -QT_END_NAMESPACE - -#endif - diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 5031dd4..02cc652 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -51,6 +51,13 @@ QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QNetworkConfigurationManagerPrivate, connManager); +#ifndef Q_OS_SYMBIAN +QNetworkConfigurationManagerPrivate *qNetworkConfigurationManagerPrivate() +{ + return connManager(); +} +#endif + /*! \class QNetworkConfigurationManager diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 47b23d2..3e82ab7 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -40,7 +40,6 @@ ****************************************************************************/ #include "qnetworkconfigmanager_p.h" -#include "qgenericengine_p.h" #ifdef Q_OS_WIN #include "qnlaengine_win_p.h" @@ -55,12 +54,19 @@ #include "qcorewlanengine_mac_p.h" #endif +#include "qbearerplugin.h" + +#include + #include #include #include QT_BEGIN_NAMESPACE +Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, + (QBearerEngineFactoryInterface_iid, QLatin1String("/bearer"))) + void QNetworkConfigurationManagerPrivate::registerPlatformCapabilities() { capFlags = QNetworkConfigurationManager::ForcedRoaming; @@ -228,6 +234,9 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() updateState = NotUpdating; onlineConfigurations = 0; + QFactoryLoader *l = loader(); + QStringList keys = l->keys(); + #if defined (Q_OS_DARWIN) coreWifi = QCoreWlanEngine::instance(); if (coreWifi) { @@ -242,10 +251,14 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() this, SLOT(updateConfigurations())); } else { #endif - generic = QGenericEngine::instance(); - if (generic) { - connect(generic, SIGNAL(configurationsChanged()), - this, SLOT(updateConfigurations())); + QBearerEnginePlugin *genericPlugin = + qobject_cast(l->instance(QLatin1String("generic"))); + if (genericPlugin) { + generic = genericPlugin->create(QLatin1String("generic")); + if (generic) { + connect(generic, SIGNAL(configurationsChanged()), + this, SLOT(updateConfigurations())); + } } #if defined(BACKEND_NM) } diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index f2e2ee5..2ac6401 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -135,7 +135,7 @@ private: #endif #ifdef BEARER_ENGINE - QGenericEngine *generic; + QNetworkSessionEngine *generic; #ifdef Q_OS_WIN QNlaEngine *nla; #ifndef Q_OS_WINCE @@ -173,6 +173,8 @@ private Q_SLOTS: #endif }; +QNetworkConfigurationManagerPrivate *qNetworkConfigurationManagerPrivate(); + QT_END_NAMESPACE #endif //QNETWORKCONFIGURATIONMANAGERPRIVATE_H diff --git a/src/network/bearer/qnetworkconfiguration_p.h b/src/network/bearer/qnetworkconfiguration_p.h index 69d7e18..f00bcfa 100644 --- a/src/network/bearer/qnetworkconfiguration_p.h +++ b/src/network/bearer/qnetworkconfiguration_p.h @@ -55,7 +55,7 @@ #include "qnetworkconfiguration.h" #include -#include +#include QT_BEGIN_NAMESPACE diff --git a/src/network/bearer/qnetworksession_p.cpp b/src/network/bearer/qnetworksession_p.cpp index 8e39216..c2491ae 100644 --- a/src/network/bearer/qnetworksession_p.cpp +++ b/src/network/bearer/qnetworksession_p.cpp @@ -42,7 +42,7 @@ #include "qnetworksession_p.h" #include "qnetworksession.h" #include "qnetworksessionengine_p.h" -#include "qgenericengine_p.h" +#include "qnetworkconfigmanager_p.h" #ifdef Q_OS_WIN #include "qnlaengine_win_p.h" @@ -81,6 +81,8 @@ static bool NetworkManagerAvailable() static QNetworkSessionEngine *getEngineFromId(const QString &id) { + QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); + #ifdef Q_OS_WIN QNlaEngine *nla = QNlaEngine::instance(); if (nla && nla->hasIdentifier(id)) @@ -106,9 +108,9 @@ static QNetworkSessionEngine *getEngineFromId(const QString &id) return coreWifi; #endif - QGenericEngine *generic = QGenericEngine::instance(); - if (generic && generic->hasIdentifier(id)) - return generic; + QNetworkSessionEngine *engine = priv->configurationEngine.value(id); + if (engine && engine->hasIdentifier(id)) + return engine; return 0; } diff --git a/src/network/bearer/qnetworksessionengine_p.h b/src/network/bearer/qnetworksessionengine_p.h index 8eb17d4..9fbd4ac 100644 --- a/src/network/bearer/qnetworksessionengine_p.h +++ b/src/network/bearer/qnetworksessionengine_p.h @@ -61,7 +61,7 @@ QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; -class QNetworkSessionEngine : public QObject +class Q_NETWORK_EXPORT QNetworkSessionEngine : public QObject { Q_OBJECT @@ -92,6 +92,8 @@ Q_SIGNALS: void connectionError(const QString &id, QNetworkSessionEngine::ConnectionError error); }; +typedef QNetworkSessionEngine QBearerEngine; + QT_END_NAMESPACE #endif diff --git a/src/plugins/bearer/bearer.pro b/src/plugins/bearer/bearer.pro new file mode 100644 index 0000000..0e3ef48 --- /dev/null +++ b/src/plugins/bearer/bearer.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs + +SUBDIRS += generic diff --git a/src/plugins/bearer/generic/generic.pro b/src/plugins/bearer/generic/generic.pro new file mode 100644 index 0000000..d32dbe6 --- /dev/null +++ b/src/plugins/bearer/generic/generic.pro @@ -0,0 +1,13 @@ +TARGET = qgenericbearer +include(../../qpluginbase.pri) + +QT += network + +DEFINES += BEARER_ENGINE + +HEADERS += qgenericengine.h +SOURCES += qgenericengine.cpp main.cpp + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer +target.path += $$[QT_INSTALL_PLUGINS]/bearer +INSTALLS += target diff --git a/src/plugins/bearer/generic/main.cpp b/src/plugins/bearer/generic/main.cpp new file mode 100644 index 0000000..c877fce --- /dev/null +++ b/src/plugins/bearer/generic/main.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgenericengine.h" + +#include + +#include + +QT_BEGIN_NAMESPACE + +class QGenericEnginePlugin : public QBearerEnginePlugin +{ +public: + QGenericEnginePlugin(); + ~QGenericEnginePlugin(); + + QStringList keys() const; + QBearerEngine *create(const QString &key) const; +}; + +QGenericEnginePlugin::QGenericEnginePlugin() +{ +} + +QGenericEnginePlugin::~QGenericEnginePlugin() +{ +} + +QStringList QGenericEnginePlugin::keys() const +{ + qDebug() << Q_FUNC_INFO; + + return QStringList() << QLatin1String("generic"); +} + +QBearerEngine *QGenericEnginePlugin::create(const QString &key) const +{ + qDebug() << Q_FUNC_INFO; + + if (key == QLatin1String("generic")) + return new QGenericEngine; + else + return 0; +} + +Q_EXPORT_STATIC_PLUGIN(QGenericEnginePlugin) +Q_EXPORT_PLUGIN2(qgenericbearer, QGenericEnginePlugin) + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp new file mode 100644 index 0000000..89db82b --- /dev/null +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -0,0 +1,234 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgenericengine.h" + +#include + +#include +#include +#include +#include + +#include + +#ifdef Q_OS_WIN +#include "qnetworksessionengine_win_p.h" +#endif + +QT_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QGenericEngine, genericEngine) + +static QString qGetInterfaceType(const QString &interface) +{ +#ifdef Q_OS_WIN32 + unsigned long oid; + DWORD bytesWritten; + + NDIS_MEDIUM medium; + NDIS_PHYSICAL_MEDIUM physicalMedium; + + HANDLE handle = CreateFile((TCHAR *)QString("\\\\.\\%1").arg(interface).utf16(), 0, + FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); + if (handle == INVALID_HANDLE_VALUE) + return QString(); + + oid = OID_GEN_MEDIA_SUPPORTED; + bytesWritten = 0; + bool result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), + &medium, sizeof(medium), &bytesWritten, 0); + if (!result) { + CloseHandle(handle); + return QString(); + } + + oid = OID_GEN_PHYSICAL_MEDIUM; + bytesWritten = 0; + result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), + &physicalMedium, sizeof(physicalMedium), &bytesWritten, 0); + if (!result) { + CloseHandle(handle); + + if (medium == NdisMedium802_3) + return QLatin1String("Ethernet"); + else + return QString(); + } + + CloseHandle(handle); + + if (medium == NdisMedium802_3) { + switch (physicalMedium) { + case NdisPhysicalMediumWirelessLan: + return QLatin1String("WLAN"); + case NdisPhysicalMediumBluetooth: + return QLatin1String("Bluetooth"); + case NdisPhysicalMediumWiMax: + return QLatin1String("WiMAX"); + default: +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Physical Medium" << physicalMedium; +#endif + return QLatin1String("Ethernet"); + } + } + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << medium << physicalMedium; +#endif +#else + Q_UNUSED(interface); +#endif + + return QString(); +} + +QGenericEngine::QGenericEngine(QObject *parent) +: QNetworkSessionEngine(parent) +{ + connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); + pollTimer.setInterval(10000); +} + +QGenericEngine::~QGenericEngine() +{ +} + +QList QGenericEngine::getConfigurations(bool *ok) +{ + if (ok) + *ok = true; + + QList foundConfigurations; + + // Immediately after connecting with a wireless access point + // QNetworkInterface::allInterfaces() will sometimes return an empty list. Calling it again a + // second time results in a non-empty list. If we loose interfaces we will end up removing + // network configurations which will break current sessions. + QList interfaces = QNetworkInterface::allInterfaces(); + if (interfaces.isEmpty()) + interfaces = QNetworkInterface::allInterfaces(); + + // create configuration for each interface + while (!interfaces.isEmpty()) { + QNetworkInterface interface = interfaces.takeFirst(); + + if (!interface.isValid()) + continue; + + // ignore loopback interface + if (interface.flags() & QNetworkInterface::IsLoopBack) + continue; + + // ignore WLAN interface handled in seperate engine + if (qGetInterfaceType(interface.name()) == QLatin1String("WLAN")) + continue; + + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + const QString humanReadableName = interface.humanReadableName(); + cpPriv->name = humanReadableName.isEmpty() ? interface.name() : humanReadableName; + cpPriv->isValid = true; + + uint identifier; + if (interface.index()) + identifier = qHash(QLatin1String("NLA:") + QString::number(interface.index())); + else + identifier = qHash(QLatin1String("NLA:") + interface.hardwareAddress()); + + cpPriv->id = QString::number(identifier); + cpPriv->state = QNetworkConfiguration::Discovered; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + if (interface.flags() & QNetworkInterface::IsUp) + cpPriv->state |= QNetworkConfiguration::Active; + + configurationInterface[identifier] = interface.name(); + + foundConfigurations.append(cpPriv); + } + + pollTimer.start(); + + return foundConfigurations; +} + +QString QGenericEngine::getInterfaceFromId(const QString &id) +{ + return configurationInterface.value(id.toUInt()); +} + +bool QGenericEngine::hasIdentifier(const QString &id) +{ + return configurationInterface.contains(id.toUInt()); +} + +QString QGenericEngine::bearerName(const QString &id) +{ + QString interface = getInterfaceFromId(id); + + if (interface.isEmpty()) + return QString(); + + return qGetInterfaceType(interface); +} + +void QGenericEngine::connectToId(const QString &id) +{ + emit connectionError(id, OperationNotSupported); +} + +void QGenericEngine::disconnectFromId(const QString &id) +{ + emit connectionError(id, OperationNotSupported); +} + +void QGenericEngine::requestUpdate() +{ + emit configurationsChanged(); +} + +QGenericEngine *QGenericEngine::instance() +{ + return genericEngine(); +} + +QT_END_NAMESPACE + diff --git a/src/plugins/bearer/generic/qgenericengine.h b/src/plugins/bearer/generic/qgenericengine.h new file mode 100644 index 0000000..9923a9b --- /dev/null +++ b/src/plugins/bearer/generic/qgenericengine.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGENERICENGINE_H +#define QGENERICENGINE_H + +#include + +#include +#include + +QT_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; + +class QGenericEngine : public QNetworkSessionEngine +{ + Q_OBJECT + +public: + QGenericEngine(QObject *parent = 0); + ~QGenericEngine(); + + QList getConfigurations(bool *ok = 0); + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + static QGenericEngine *instance(); + +private: + QMap configurationInterface; + QTimer pollTimer; +}; + +QT_END_NAMESPACE + +#endif + diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 004b816..d6a426f 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -1,6 +1,6 @@ TEMPLATE = subdirs -SUBDIRS *= accessible imageformats sqldrivers iconengines script +SUBDIRS *= accessible imageformats sqldrivers iconengines script bearer unix:!symbian { contains(QT_CONFIG,iconv)|contains(QT_CONFIG,gnu-libiconv):SUBDIRS *= codecs } else { -- cgit v0.12 From 70d0623570936696ca28536a46a3be63c691f50b Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Wed, 2 Dec 2009 09:26:54 +1000 Subject: Add compile test for NetworkManager. --- .../unix/networkmanager/networkmanager.pro | 14 +- configure | 217 +++++++++++---------- 2 files changed, 119 insertions(+), 112 deletions(-) diff --git a/config.tests/unix/networkmanager/networkmanager.pro b/config.tests/unix/networkmanager/networkmanager.pro index 554f513..c41204f 100644 --- a/config.tests/unix/networkmanager/networkmanager.pro +++ b/config.tests/unix/networkmanager/networkmanager.pro @@ -1,11 +1,3 @@ -###################################################################### -# Automatically generated by qmake (2.01a) Mon Oct 19 12:58:26 2009 -###################################################################### - -TEMPLATE = app -TARGET = -DEPENDPATH += . -INCLUDEPATH += . - -# Input -SOURCES += main.cpp +SOURCES = main.cpp +CONFIG -= qt dylib +mac:CONFIG -= app_bundle diff --git a/configure b/configure index 0b11bf3..dcd7d2d 100755 --- a/configure +++ b/configure @@ -765,6 +765,7 @@ OPT_HELP= CFG_SILENT=no CFG_GRAPHICS_SYSTEM=default CFG_ALSA=auto +CFG_NETWORKMANAGER=auto # initalize variables used for installation QT_INSTALL_PREFIX= @@ -5820,6 +5821,14 @@ if [ "$CFG_ALSA" = "auto" ]; then fi fi +if [ "$CFG_NETWORKMANAGER" = "auto" ]; then + if "$unixtests/compile.test" "$XQMAKESPEC" "$QMAKE_CONFIG" $OPT_VERBOSE "$relpath" "$outpath" config.tests/unix/networkmanager "NetworkManager" $L_FLAGS $I_FLAGS $l_FLAGS; then + CFG_NETWORKMANAGER=yes + else + CFG_NETWORKMANAGER=no + fi +fi + if [ -f "$relpath/src/declarative/declarative.pro" ]; then if [ "$CFG_DECLARATIVE" = "auto" ]; then CFG_DECLARATIVE=yes @@ -6297,6 +6306,10 @@ if [ "$CFG_ALSA" = "yes" ]; then QT_CONFIG="$QT_CONFIG alsa" fi +if [ "$CFG_NETWORKMANAGER" = "yes" ]; then + QT_CONFIG="$QT_CONFIG networkmanager" +fi + # # Some Qt modules are too advanced in C++ for some old compilers # Detect here the platforms where they are known to work. @@ -6997,6 +7010,7 @@ fi [ "$CFG_XRANDR" = "runtime" ] && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_RUNTIME_XRANDR" [ "$CFG_XINPUT" = "runtime" ] && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_RUNTIME_XINPUT" [ "$CFG_ALSA" = "no" ] && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_ALSA" +[ "$CFG_NETWORKMANAGER" = "no" ] && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_NETWORKMANAGER" # sort QCONFIG_FLAGS for neatness if we can [ '!' -z "$AWK" ] && QCONFIG_FLAGS=`echo $QCONFIG_FLAGS | $AWK '{ gsub(" ", "\n"); print }' | sort | uniq` @@ -7332,163 +7346,163 @@ fi if [ "$OPT_VERBOSE" = "yes" ]; then if echo '\c' | grep '\c' >/dev/null; then - echo -n "qmake vars .......... " + echo -n "qmake vars ............. " else - echo "qmake vars .......... \c" + echo "qmake vars ............. \c" fi cat "$QMAKE_VARS_FILE" | tr '\n' ' ' - echo "qmake switches ...... $QMAKE_SWITCHES" + echo "qmake switches ......... $QMAKE_SWITCHES" fi -[ "$CFG_INCREMENTAL" = "yes" ] && [ '!' -z "$INCREMENTAL" ] && echo "Incremental ......... $INCREMENTAL" -echo "Build ............... $CFG_BUILD_PARTS" -echo "Configuration ....... $QMAKE_CONFIG $QT_CONFIG" +[ "$CFG_INCREMENTAL" = "yes" ] && [ '!' -z "$INCREMENTAL" ] && echo "Incremental ............ $INCREMENTAL" +echo "Build .................. $CFG_BUILD_PARTS" +echo "Configuration .......... $QMAKE_CONFIG $QT_CONFIG" if [ "$CFG_DEBUG_RELEASE" = "yes" ]; then - echo "Debug ............... yes (combined)" + echo "Debug .................. yes (combined)" if [ "$CFG_DEBUG" = "yes" ]; then - echo "Default Link ........ debug" + echo "Default Link ........... debug" else - echo "Default Link ........ release" + echo "Default Link ........... release" fi else - echo "Debug ............... $CFG_DEBUG" -fi -echo "Qt 3 compatibility .. $CFG_QT3SUPPORT" -[ "$CFG_DBUS" = "no" ] && echo "QtDBus module ....... no" -[ "$CFG_DBUS" = "yes" ] && echo "QtDBus module ....... yes (run-time)" -[ "$CFG_DBUS" = "linked" ] && echo "QtDBus module ....... yes (linked)" -echo "QtConcurrent code.... $CFG_CONCURRENT" -echo "QtScript module ..... $CFG_SCRIPT" -echo "QtScriptTools module $CFG_SCRIPTTOOLS" -echo "QtXmlPatterns module $CFG_XMLPATTERNS" -echo "Phonon module ....... $CFG_PHONON" -echo "Multimedia module ... $CFG_MULTIMEDIA" -echo "SVG module .......... $CFG_SVG" -echo "WebKit module ....... $CFG_WEBKIT" + echo "Debug .................. $CFG_DEBUG" +fi +echo "Qt 3 compatibility ..... $CFG_QT3SUPPORT" +[ "$CFG_DBUS" = "no" ] && echo "QtDBus module .......... no" +[ "$CFG_DBUS" = "yes" ] && echo "QtDBus module .......... yes (run-time)" +[ "$CFG_DBUS" = "linked" ] && echo "QtDBus module .......... yes (linked)" +echo "QtConcurrent code ...... $CFG_CONCURRENT" +echo "QtScript module ........ $CFG_SCRIPT" +echo "QtScriptTools module ... $CFG_SCRIPTTOOLS" +echo "QtXmlPatterns module ... $CFG_XMLPATTERNS" +echo "Phonon module .......... $CFG_PHONON" +echo "Multimedia module ...... $CFG_MULTIMEDIA" +echo "SVG module ............. $CFG_SVG" +echo "WebKit module .......... $CFG_WEBKIT" if [ "$CFG_WEBKIT" = "yes" ]; then if [ "$CFG_JAVASCRIPTCORE_JIT" = "auto" ]; then - echo "JavaScriptCore JIT .. To be decided by JavaScriptCore" + echo "JavaScriptCore JIT ..... To be decided by JavaScriptCore" else - echo "JavaScriptCore JIT .. $CFG_JAVASCRIPTCORE_JIT" + echo "JavaScriptCore JIT ..... $CFG_JAVASCRIPTCORE_JIT" fi fi -echo "Declarative module .. $CFG_DECLARATIVE" -echo "STL support ......... $CFG_STL" -echo "PCH support ......... $CFG_PRECOMPILE" -echo "MMX/3DNOW/SSE/SSE2.. ${CFG_MMX}/${CFG_3DNOW}/${CFG_SSE}/${CFG_SSE2}" +echo "Declarative module ..... $CFG_DECLARATIVE" +echo "STL support ............ $CFG_STL" +echo "PCH support ............ $CFG_PRECOMPILE" +echo "MMX/3DNOW/SSE/SSE2 ..... ${CFG_MMX}/${CFG_3DNOW}/${CFG_SSE}/${CFG_SSE2}" if [ "${CFG_ARCH}" = "arm" ]; then - echo "iWMMXt support ...... ${CFG_IWMMXT}" -fi -[ "${PLATFORM_QWS}" != "yes" ] && echo "Graphics System ..... $CFG_GRAPHICS_SYSTEM" -echo "IPv6 support ........ $CFG_IPV6" -echo "IPv6 ifname support . $CFG_IPV6IFNAME" -echo "getaddrinfo support . $CFG_GETADDRINFO" -echo "getifaddrs support .. $CFG_GETIFADDRS" -echo "Accessibility ....... $CFG_ACCESSIBILITY" -echo "NIS support ......... $CFG_NIS" -echo "CUPS support ........ $CFG_CUPS" -echo "Iconv support ....... $CFG_ICONV" -echo "Glib support ........ $CFG_GLIB" -echo "GStreamer support ... $CFG_GSTREAMER" -echo "Large File support .. $CFG_LARGEFILE" -echo "GIF support ......... $CFG_GIF" + echo "iWMMXt support ......... ${CFG_IWMMXT}" +fi +[ "${PLATFORM_QWS}" != "yes" ] && echo "Graphics System ........ $CFG_GRAPHICS_SYSTEM" +echo "IPv6 support ........... $CFG_IPV6" +echo "IPv6 ifname support .... $CFG_IPV6IFNAME" +echo "getaddrinfo support .... $CFG_GETADDRINFO" +echo "getifaddrs support ..... $CFG_GETIFADDRS" +echo "Accessibility .......... $CFG_ACCESSIBILITY" +echo "NIS support ............ $CFG_NIS" +echo "CUPS support ........... $CFG_CUPS" +echo "Iconv support .......... $CFG_ICONV" +echo "Glib support ........... $CFG_GLIB" +echo "GStreamer support ...... $CFG_GSTREAMER" +echo "Large File support ..... $CFG_LARGEFILE" +echo "GIF support ............ $CFG_GIF" if [ "$CFG_TIFF" = "no" ]; then - echo "TIFF support ........ $CFG_TIFF" + echo "TIFF support ........... $CFG_TIFF" else - echo "TIFF support ........ $CFG_TIFF ($CFG_LIBTIFF)" + echo "TIFF support ........... $CFG_TIFF ($CFG_LIBTIFF)" fi if [ "$CFG_JPEG" = "no" ]; then - echo "JPEG support ........ $CFG_JPEG" + echo "JPEG support ........... $CFG_JPEG" else - echo "JPEG support ........ $CFG_JPEG ($CFG_LIBJPEG)" + echo "JPEG support ........... $CFG_JPEG ($CFG_LIBJPEG)" fi if [ "$CFG_PNG" = "no" ]; then - echo "PNG support ......... $CFG_PNG" + echo "PNG support ............ $CFG_PNG" else - echo "PNG support ......... $CFG_PNG ($CFG_LIBPNG)" + echo "PNG support ............ $CFG_PNG ($CFG_LIBPNG)" fi if [ "$CFG_MNG" = "no" ]; then - echo "MNG support ......... $CFG_MNG" + echo "MNG support ............ $CFG_MNG" else - echo "MNG support ......... $CFG_MNG ($CFG_LIBMNG)" + echo "MNG support ............ $CFG_MNG ($CFG_LIBMNG)" fi -echo "zlib support ........ $CFG_ZLIB" -echo "Session management .. $CFG_SM" +echo "zlib support ........... $CFG_ZLIB" +echo "Session management ..... $CFG_SM" if [ "$PLATFORM_QWS" = "yes" ]; then - echo "Embedded support .... $CFG_EMBEDDED" + echo "Embedded support ....... $CFG_EMBEDDED" if [ "$CFG_QWS_FREETYPE" = "auto" ]; then - echo "Freetype2 support ... $CFG_QWS_FREETYPE ($CFG_LIBFREETYPE)" + echo "Freetype2 support ...... $CFG_QWS_FREETYPE ($CFG_LIBFREETYPE)" else - echo "Freetype2 support ... $CFG_QWS_FREETYPE" + echo "Freetype2 support ...... $CFG_QWS_FREETYPE" fi # Normalize the decoration output first CFG_GFX_ON=`echo ${CFG_GFX_ON}` CFG_GFX_PLUGIN=`echo ${CFG_GFX_PLUGIN}` - echo "Graphics (qt) ....... ${CFG_GFX_ON}" - echo "Graphics (plugin) ... ${CFG_GFX_PLUGIN}" + echo "Graphics (qt) .......... ${CFG_GFX_ON}" + echo "Graphics (plugin) ...... ${CFG_GFX_PLUGIN}" CFG_DECORATION_ON=`echo ${CFG_DECORATION_ON}` CFG_DECORATION_PLUGIN=`echo ${CFG_DECORATION_PLUGIN}` - echo "Decorations (qt) .... $CFG_DECORATION_ON" - echo "Decorations (plugin) $CFG_DECORATION_PLUGIN" + echo "Decorations (qt) ....... $CFG_DECORATION_ON" + echo "Decorations (plugin) ... $CFG_DECORATION_PLUGIN" CFG_KBD_ON=`echo ${CFG_KBD_ON}` CFG_KBD_PLUGIN=`echo ${CFG_KBD_PLUGIN}` - echo "Keyboard driver (qt). ${CFG_KBD_ON}" - echo "Keyboard driver (plugin) ${CFG_KBD_PLUGIN}" + echo "Keyboard driver (qt) ... ${CFG_KBD_ON}" + echo "Keyboard driver (plugin) .. ${CFG_KBD_PLUGIN}" CFG_MOUSE_ON=`echo ${CFG_MOUSE_ON}` CFG_MOUSE_PLUGIN=`echo ${CFG_MOUSE_PLUGIN}` - echo "Mouse driver (qt) ... $CFG_MOUSE_ON" - echo "Mouse driver (plugin) $CFG_MOUSE_PLUGIN" + echo "Mouse driver (qt) ...... $CFG_MOUSE_ON" + echo "Mouse driver (plugin) .. $CFG_MOUSE_PLUGIN" fi if [ "$CFG_OPENGL" = "desktop" ]; then - echo "OpenGL support ...... yes (Desktop OpenGL)" + echo "OpenGL support ......... yes (Desktop OpenGL)" elif [ "$CFG_OPENGL" = "es1" ]; then - echo "OpenGL support ...... yes (OpenGL ES 1.x Common profile)" + echo "OpenGL support ......... yes (OpenGL ES 1.x Common profile)" elif [ "$CFG_OPENGL" = "es1cl" ]; then - echo "OpenGL support ...... yes (OpenGL ES 1.x Common Lite profile)" + echo "OpenGL support ......... yes (OpenGL ES 1.x Common Lite profile)" elif [ "$CFG_OPENGL" = "es2" ]; then - echo "OpenGL support ...... yes (OpenGL ES 2.x)" + echo "OpenGL support ......... yes (OpenGL ES 2.x)" else - echo "OpenGL support ...... no" + echo "OpenGL support ......... no" fi if [ "$CFG_EGL" != "no" ]; then if [ "$CFG_EGL_GLES_INCLUDES" != "no" ]; then - echo "EGL support ......... yes " + echo "EGL support ............ yes " else - echo "EGL support ......... yes " + echo "EGL support ............ yes " fi fi if [ "$CFG_OPENVG" ]; then if [ "$CFG_OPENVG_SHIVA" = "yes" ]; then - echo "OpenVG support ...... ShivaVG" + echo "OpenVG support ......... ShivaVG" else - echo "OpenVG support ...... $CFG_OPENVG" + echo "OpenVG support ......... $CFG_OPENVG" fi fi if [ "$PLATFORM_X11" = "yes" ]; then - echo "NAS sound support ... $CFG_NAS" - echo "XShape support ...... $CFG_XSHAPE" - echo "XSync support ....... $CFG_XSYNC" - echo "Xinerama support .... $CFG_XINERAMA" - echo "Xcursor support ..... $CFG_XCURSOR" - echo "Xfixes support ...... $CFG_XFIXES" - echo "Xrandr support ...... $CFG_XRANDR" - echo "Xrender support ..... $CFG_XRENDER" - echo "Xi support .......... $CFG_XINPUT" - echo "MIT-SHM support ..... $CFG_MITSHM" - echo "FontConfig support .. $CFG_FONTCONFIG" - echo "XKB Support ......... $CFG_XKB" - echo "immodule support .... $CFG_IM" - echo "GTK theme support ... $CFG_QGTKSTYLE" -fi -[ "$CFG_SQL_mysql" != "no" ] && echo "MySQL support ....... $CFG_SQL_mysql" -[ "$CFG_SQL_psql" != "no" ] && echo "PostgreSQL support .. $CFG_SQL_psql" -[ "$CFG_SQL_odbc" != "no" ] && echo "ODBC support ........ $CFG_SQL_odbc" -[ "$CFG_SQL_oci" != "no" ] && echo "OCI support ......... $CFG_SQL_oci" -[ "$CFG_SQL_tds" != "no" ] && echo "TDS support ......... $CFG_SQL_tds" -[ "$CFG_SQL_db2" != "no" ] && echo "DB2 support ......... $CFG_SQL_db2" -[ "$CFG_SQL_ibase" != "no" ] && echo "InterBase support ... $CFG_SQL_ibase" -[ "$CFG_SQL_sqlite2" != "no" ] && echo "SQLite 2 support .... $CFG_SQL_sqlite2" -[ "$CFG_SQL_sqlite" != "no" ] && echo "SQLite support ...... $CFG_SQL_sqlite ($CFG_SQLITE)" + echo "NAS sound support ...... $CFG_NAS" + echo "XShape support ......... $CFG_XSHAPE" + echo "XSync support .......... $CFG_XSYNC" + echo "Xinerama support ....... $CFG_XINERAMA" + echo "Xcursor support ........ $CFG_XCURSOR" + echo "Xfixes support ......... $CFG_XFIXES" + echo "Xrandr support ......... $CFG_XRANDR" + echo "Xrender support ........ $CFG_XRENDER" + echo "Xi support ............. $CFG_XINPUT" + echo "MIT-SHM support ........ $CFG_MITSHM" + echo "FontConfig support ..... $CFG_FONTCONFIG" + echo "XKB Support ............ $CFG_XKB" + echo "immodule support ....... $CFG_IM" + echo "GTK theme support ...... $CFG_QGTKSTYLE" +fi +[ "$CFG_SQL_mysql" != "no" ] && echo "MySQL support .......... $CFG_SQL_mysql" +[ "$CFG_SQL_psql" != "no" ] && echo "PostgreSQL support ..... $CFG_SQL_psql" +[ "$CFG_SQL_odbc" != "no" ] && echo "ODBC support ........... $CFG_SQL_odbc" +[ "$CFG_SQL_oci" != "no" ] && echo "OCI support ............ $CFG_SQL_oci" +[ "$CFG_SQL_tds" != "no" ] && echo "TDS support ............ $CFG_SQL_tds" +[ "$CFG_SQL_db2" != "no" ] && echo "DB2 support ............ $CFG_SQL_db2" +[ "$CFG_SQL_ibase" != "no" ] && echo "InterBase support ...... $CFG_SQL_ibase" +[ "$CFG_SQL_sqlite2" != "no" ] && echo "SQLite 2 support ....... $CFG_SQL_sqlite2" +[ "$CFG_SQL_sqlite" != "no" ] && echo "SQLite support ......... $CFG_SQL_sqlite ($CFG_SQLITE)" OPENSSL_LINKAGE="" if [ "$CFG_OPENSSL" = "yes" ]; then @@ -7496,9 +7510,9 @@ if [ "$CFG_OPENSSL" = "yes" ]; then elif [ "$CFG_OPENSSL" = "linked" ]; then OPENSSL_LINKAGE="(linked)" fi -echo "OpenSSL support ..... $CFG_OPENSSL $OPENSSL_LINKAGE" +echo "OpenSSL support ........ $CFG_OPENSSL $OPENSSL_LINKAGE" -[ "$CFG_PTMALLOC" != "no" ] && echo "Use ptmalloc ........ $CFG_PTMALLOC" +[ "$CFG_PTMALLOC" != "no" ] && echo "Use ptmalloc ........... $CFG_PTMALLOC" # complain about not being able to use dynamic plugins if we are using a static build if [ "$CFG_SHARED" = "no" ]; then @@ -7521,7 +7535,8 @@ if [ "$PLATFORM_MAC" = "yes" ] && [ "$CFG_FRAMEWORK" = "yes" ] && [ "$CFG_DEBUG" echo "NOTE: Mac OS X frameworks implicitly build debug and release Qt libraries." echo fi -echo "alsa support ........ $CFG_ALSA" +echo "alsa support ........... $CFG_ALSA" +echo "NetworkManager support . $CFG_NETWORKMANAGER" echo sepath=`echo "$relpath" | sed -e 's/\\./\\\\./g'` -- cgit v0.12 From 5c07b6b24144774f16a20115eec1a6700d0db254 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 22 Dec 2009 15:08:34 +1000 Subject: Convert NetworkManager engine into a plugin. Conflicts: src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp src/plugins/bearer/networkmanager/qnetworkmanagerservice.h src/plugins/bearer/networkmanager/qnmdbushelper.cpp src/plugins/bearer/networkmanager/qnmdbushelper.h src/plugins/bearer/networkmanager/qnmwifiengine.cpp src/plugins/bearer/networkmanager/qnmwifiengine.h --- src/network/bearer/bearer.pri | 17 +- src/network/bearer/qnetworkconfigmanager_p.cpp | 32 +- src/network/bearer/qnetworkconfigmanager_p.h | 2 +- src/network/bearer/qnetworkmanagerservice_p.cpp | 1011 ------------------ src/network/bearer/qnetworkmanagerservice_p.h | 397 ------- src/network/bearer/qnetworksession_p.cpp | 33 +- src/network/bearer/qnmdbushelper.cpp | 117 -- src/network/bearer/qnmdbushelper_p.h | 89 -- src/network/bearer/qnmwifiengine_unix.cpp | 1129 -------------------- src/network/bearer/qnmwifiengine_unix_p.h | 164 --- src/plugins/bearer/bearer.pro | 1 + src/plugins/bearer/networkmanager/main.cpp | 88 ++ .../bearer/networkmanager/networkmanager.pro | 19 + .../networkmanager/qnetworkmanagerservice.cpp | 1009 +++++++++++++++++ .../bearer/networkmanager/qnetworkmanagerservice.h | 397 +++++++ .../bearer/networkmanager/qnmdbushelper.cpp | 114 ++ src/plugins/bearer/networkmanager/qnmdbushelper.h | 87 ++ .../bearer/networkmanager/qnmwifiengine.cpp | 1128 +++++++++++++++++++ src/plugins/bearer/networkmanager/qnmwifiengine.h | 165 +++ 19 files changed, 3032 insertions(+), 2967 deletions(-) delete mode 100644 src/network/bearer/qnetworkmanagerservice_p.cpp delete mode 100644 src/network/bearer/qnetworkmanagerservice_p.h delete mode 100644 src/network/bearer/qnmdbushelper.cpp delete mode 100644 src/network/bearer/qnmdbushelper_p.h delete mode 100644 src/network/bearer/qnmwifiengine_unix.cpp delete mode 100644 src/network/bearer/qnmwifiengine_unix_p.h create mode 100644 src/plugins/bearer/networkmanager/main.cpp create mode 100644 src/plugins/bearer/networkmanager/networkmanager.pro create mode 100644 src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp create mode 100644 src/plugins/bearer/networkmanager/qnetworkmanagerservice.h create mode 100644 src/plugins/bearer/networkmanager/qnmdbushelper.cpp create mode 100644 src/plugins/bearer/networkmanager/qnmdbushelper.h create mode 100644 src/plugins/bearer/networkmanager/qnmwifiengine.cpp create mode 100644 src/plugins/bearer/networkmanager/qnmwifiengine.h diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index 4f53621..bed2597 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -80,22 +80,7 @@ symbian { bearer/qnetworksession_p.cpp \ bearer/qnetworksessionengine.cpp - unix:!mac:contains(networkmanager_enabled, yes) { - contains(QT_CONFIG,dbus) { - DEFINES += BACKEND_NM - QT += dbus - - HEADERS += bearer/qnmdbushelper_p.h \ - bearer/qnetworkmanagerservice_p.h \ - bearer/qnmwifiengine_unix_p.h - - SOURCES += bearer/qnmdbushelper.cpp \ - bearer/qnetworkmanagerservice_p.cpp \ - bearer/qnmwifiengine_unix.cpp - } else { - message("NetworkManager backend requires Qt DBus support") - } - } + contains(QT_CONFIG, networkmanager):DEFINES += BACKEND_NM win32 { HEADERS += bearer/qnlaengine_win_p.h \ diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 3e82ab7..7b68394 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -47,9 +47,6 @@ #ifdef Q_OS_WIN32 #include "qnativewifiengine_win_p.h" #endif -#if defined(BACKEND_NM) -#include "qnmwifiengine_unix_p.h" -#endif #ifdef Q_OS_DARWIN #include "qcorewlanengine_mac_p.h" #endif @@ -244,13 +241,21 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() this, SLOT(updateConfigurations())); } #else -#if defined(BACKEND_NM) - nmWifi = QNmWifiEngine::instance(); - if (nmWifi) { - connect(nmWifi, SIGNAL(configurationsChanged()), - this, SLOT(updateConfigurations())); - } else { +#ifdef BACKEND_NM + if (keys.contains(QLatin1String("networkmanager"))) { + QBearerEnginePlugin *nmPlugin = + qobject_cast(l->instance(QLatin1String("networkmanager"))); + if (nmPlugin) { + nmWifi = nmPlugin->create(QLatin1String("networkmanager")); + if (nmWifi) { + connect(nmWifi, SIGNAL(configurationsChanged()), + this, SLOT(updateConfigurations())); + } + } + } #endif + + if (keys.contains(QLatin1String("generic"))) { QBearerEnginePlugin *genericPlugin = qobject_cast(l->instance(QLatin1String("generic"))); if (genericPlugin) { @@ -260,10 +265,8 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() this, SLOT(updateConfigurations())); } } -#if defined(BACKEND_NM) } #endif -#endif #ifdef Q_OS_WIN nla = QNlaEngine::instance(); @@ -293,7 +296,7 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() #if defined(BACKEND_NM) if (engine == nmWifi) updateState &= ~NmUpdating; - else if (engine == generic) + if (engine == generic) updateState &= ~GenericUpdating; #else if (engine == generic) @@ -319,7 +322,7 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() #if defined(BACKEND_NM) if (nmWifi) engines << nmWifi; - else if (generic) + if (generic) engines << generic; #else if (generic) @@ -431,7 +434,8 @@ void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() if (nmWifi) { updateState |= NmUpdating; nmWifi->requestUpdate(); - } else if (generic) { + } + if (generic) { updateState |= GenericUpdating; generic->requestUpdate(); } diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 2ac6401..6a61891 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -143,7 +143,7 @@ private: #endif #endif #ifdef BACKEND_NM - QNmWifiEngine *nmWifi; + QNetworkSessionEngine *nmWifi; #endif #ifdef Q_OS_DARWIN QCoreWlanEngine *coreWifi; diff --git a/src/network/bearer/qnetworkmanagerservice_p.cpp b/src/network/bearer/qnetworkmanagerservice_p.cpp deleted file mode 100644 index 9516f31..0000000 --- a/src/network/bearer/qnetworkmanagerservice_p.cpp +++ /dev/null @@ -1,1011 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include "qnetworkmanagerservice_p.h" - -//Q_DECLARE_METATYPE(QList) -QT_BEGIN_NAMESPACE - -static QDBusConnection dbusConnection = QDBusConnection::systemBus(); -//static QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbusConnection); - -class QNetworkManagerInterfacePrivate -{ -public: - QDBusInterface *connectionInterface; - bool valid; -}; - -QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent) - : QObject(parent) -{ - d = new QNetworkManagerInterfacePrivate(); - d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, - NM_DBUS_PATH, - NM_DBUS_INTERFACE, - dbusConnection); - if (!d->connectionInterface->isValid()) { - qWarning() << "Could not find NetworkManager"; - d->valid = false; - return; - } - d->valid = true; - nmDBusHelper = new QNmDBusHelper; - connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), - this,SIGNAL(propertiesChanged( const QString &, QMap))); - connect(nmDBusHelper,SIGNAL(pathForStateChanged(const QString &, quint32)), - this, SIGNAL(stateChanged(const QString&, quint32))); - -} - -QNetworkManagerInterface::~QNetworkManagerInterface() -{ - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerInterface::isValid() -{ - return d->valid; -} - -bool QNetworkManagerInterface::setConnections() -{ - if(!isValid() ) - return false; - bool allOk = false; - if (!dbusConnection.connect(NM_DBUS_SERVICE, - NM_DBUS_PATH, - NM_DBUS_INTERFACE, - "PropertiesChanged", - nmDBusHelper,SLOT(slotPropertiesChanged( QMap)))) { - allOk = true; - } - if (!dbusConnection.connect(NM_DBUS_SERVICE, - NM_DBUS_PATH, - NM_DBUS_INTERFACE, - "DeviceAdded", - this,SIGNAL(deviceAdded(QDBusObjectPath)))) { - allOk = true; - } - if (!dbusConnection.connect(NM_DBUS_SERVICE, - NM_DBUS_PATH, - NM_DBUS_INTERFACE, - "DeviceRemoved", - this,SIGNAL(deviceRemoved(QDBusObjectPath)))) { - allOk = true; - } - - return allOk; -} - -QDBusInterface *QNetworkManagerInterface::connectionInterface() const -{ - return d->connectionInterface; -} - -QList QNetworkManagerInterface::getDevices() const -{ - QDBusReply > reply = d->connectionInterface->call("GetDevices"); - return reply.value(); -} - -void QNetworkManagerInterface::activateConnection( const QString &serviceName, - QDBusObjectPath connectionPath, - QDBusObjectPath devicePath, - QDBusObjectPath specificObject) -{ - QDBusPendingCall pendingCall = d->connectionInterface->asyncCall("ActivateConnection", - QVariant(serviceName), - QVariant::fromValue(connectionPath), - QVariant::fromValue(devicePath), - QVariant::fromValue(specificObject)); - - QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(pendingCall, this); - connect(callWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), - this, SIGNAL(activationFinished(QDBusPendingCallWatcher*))); -} - -void QNetworkManagerInterface::deactivateConnection(QDBusObjectPath connectionPath) const -{ - d->connectionInterface->call("DeactivateConnection", QVariant::fromValue(connectionPath)); -} - -bool QNetworkManagerInterface::wirelessEnabled() const -{ - return d->connectionInterface->property("WirelessEnabled").toBool(); -} - -bool QNetworkManagerInterface::wirelessHardwareEnabled() const -{ - return d->connectionInterface->property("WirelessHardwareEnabled").toBool(); -} - -QList QNetworkManagerInterface::activeConnections() const -{ - QVariant prop = d->connectionInterface->property("ActiveConnections"); - return prop.value >(); -} - -quint32 QNetworkManagerInterface::state() -{ - return d->connectionInterface->property("State").toUInt(); -} - -///////////// -class QNetworkManagerInterfaceAccessPointPrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; - -QNetworkManagerInterfaceAccessPoint::QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent) - : QObject(parent) -{ - d = new QNetworkManagerInterfaceAccessPointPrivate(); - d->path = dbusPathName; - d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_ACCESS_POINT, - dbusConnection); - if (!d->connectionInterface->isValid()) { - d->valid = false; - qWarning() << "Could not find InterfaceAccessPoint"; - return; - } - d->valid = true; - -} - -QNetworkManagerInterfaceAccessPoint::~QNetworkManagerInterfaceAccessPoint() -{ - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerInterfaceAccessPoint::isValid() -{ - return d->valid; -} - -bool QNetworkManagerInterfaceAccessPoint::setConnections() -{ - if(!isValid() ) - return false; - - bool allOk = false; - nmDBusHelper = new QNmDBusHelper; - connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), - this,SIGNAL(propertiesChanged( const QString &, QMap))); - - if(dbusConnection.connect(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_ACCESS_POINT, - "PropertiesChanged", - nmDBusHelper,SLOT(slotPropertiesChanged( QMap))) ) { - allOk = true; - - } - return allOk; -} - -QDBusInterface *QNetworkManagerInterfaceAccessPoint::connectionInterface() const -{ - return d->connectionInterface; -} - -quint32 QNetworkManagerInterfaceAccessPoint::flags() const -{ - return d->connectionInterface->property("Flags").toUInt(); -} - -quint32 QNetworkManagerInterfaceAccessPoint::wpaFlags() const -{ - return d->connectionInterface->property("WpaFlags").toUInt(); -} - -quint32 QNetworkManagerInterfaceAccessPoint::rsnFlags() const -{ - return d->connectionInterface->property("RsnFlags").toUInt(); -} - -QString QNetworkManagerInterfaceAccessPoint::ssid() const -{ - return d->connectionInterface->property("Ssid").toString(); -} - -quint32 QNetworkManagerInterfaceAccessPoint::frequency() const -{ - return d->connectionInterface->property("Frequency").toUInt(); -} - -QString QNetworkManagerInterfaceAccessPoint::hwAddress() const -{ - return d->connectionInterface->property("HwAddress").toString(); -} - -quint32 QNetworkManagerInterfaceAccessPoint::mode() const -{ - return d->connectionInterface->property("Mode").toUInt(); -} - -quint32 QNetworkManagerInterfaceAccessPoint::maxBitrate() const -{ - return d->connectionInterface->property("MaxBitrate").toUInt(); -} - -quint32 QNetworkManagerInterfaceAccessPoint::strength() const -{ - return d->connectionInterface->property("Strength").toUInt(); -} - -///////////// -class QNetworkManagerInterfaceDevicePrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; - -QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &deviceObjectPath, QObject *parent) - : QObject(parent) -{ - d = new QNetworkManagerInterfaceDevicePrivate(); - d->path = deviceObjectPath; - d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_DEVICE, - dbusConnection); - if (!d->connectionInterface->isValid()) { - d->valid = false; - qWarning() << "Could not find NetworkManager"; - return; - } - d->valid = true; -} - -QNetworkManagerInterfaceDevice::~QNetworkManagerInterfaceDevice() -{ - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerInterfaceDevice::isValid() -{ - return d->valid; -} - -bool QNetworkManagerInterfaceDevice::setConnections() -{ - if(!isValid() ) - return false; - - bool allOk = false; - nmDBusHelper = new QNmDBusHelper; - connect(nmDBusHelper,SIGNAL(pathForStateChanged(const QString &, quint32)), - this, SIGNAL(stateChanged(const QString&, quint32))); - if(dbusConnection.connect(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_DEVICE, - "StateChanged", - nmDBusHelper,SLOT(deviceStateChanged(quint32)))) { - allOk = true; - } - return allOk; -} - -QDBusInterface *QNetworkManagerInterfaceDevice::connectionInterface() const -{ - return d->connectionInterface; -} - -QString QNetworkManagerInterfaceDevice::udi() const -{ - return d->connectionInterface->property("Udi").toString(); -} - -QNetworkInterface QNetworkManagerInterfaceDevice::interface() const -{ - return QNetworkInterface::interfaceFromName(d->connectionInterface->property("Interface").toString()); -} - -quint32 QNetworkManagerInterfaceDevice::ip4Address() const -{ - return d->connectionInterface->property("Ip4Address").toUInt(); -} - -quint32 QNetworkManagerInterfaceDevice::state() const -{ - return d->connectionInterface->property("State").toUInt(); -} - -quint32 QNetworkManagerInterfaceDevice::deviceType() const -{ - return d->connectionInterface->property("DeviceType").toUInt(); -} - -QDBusObjectPath QNetworkManagerInterfaceDevice::ip4config() const -{ - QVariant prop = d->connectionInterface->property("Ip4Config"); - return prop.value(); -} - -///////////// -class QNetworkManagerInterfaceDeviceWiredPrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; - -QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const QString &ifaceDevicePath, QObject *parent) -{ - d = new QNetworkManagerInterfaceDeviceWiredPrivate(); - d->path = ifaceDevicePath; - d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_DEVICE_WIRED, - dbusConnection, parent); - if (!d->connectionInterface->isValid()) { - d->valid = false; - qWarning() << "Could not find InterfaceDeviceWired"; - return; - } - d->valid = true; -} - -QNetworkManagerInterfaceDeviceWired::~QNetworkManagerInterfaceDeviceWired() -{ - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerInterfaceDeviceWired::isValid() -{ - - return d->valid; -} - -bool QNetworkManagerInterfaceDeviceWired::setConnections() -{ - if(!isValid() ) - return false; - - bool allOk = false; - - nmDBusHelper = new QNmDBusHelper; - connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), - this,SIGNAL(propertiesChanged( const QString &, QMap))); - if(dbusConnection.connect(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_DEVICE_WIRED, - "PropertiesChanged", - nmDBusHelper,SLOT(slotPropertiesChanged( QMap))) ) { - allOk = true; - } - return allOk; -} - -QDBusInterface *QNetworkManagerInterfaceDeviceWired::connectionInterface() const -{ - return d->connectionInterface; -} - -QString QNetworkManagerInterfaceDeviceWired::hwAddress() const -{ - return d->connectionInterface->property("HwAddress").toString(); -} - -quint32 QNetworkManagerInterfaceDeviceWired::speed() const -{ - return d->connectionInterface->property("Speed").toUInt(); -} - -bool QNetworkManagerInterfaceDeviceWired::carrier() const -{ - return d->connectionInterface->property("Carrier").toBool(); -} - -///////////// -class QNetworkManagerInterfaceDeviceWirelessPrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; - -QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(const QString &ifaceDevicePath, QObject *parent) -{ - d = new QNetworkManagerInterfaceDeviceWirelessPrivate(); - d->path = ifaceDevicePath; - d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_DEVICE_WIRELESS, - dbusConnection, parent); - if (!d->connectionInterface->isValid()) { - d->valid = false; - qWarning() << "Could not find InterfaceDeviceWireless"; - return; - } - d->valid = true; -} - -QNetworkManagerInterfaceDeviceWireless::~QNetworkManagerInterfaceDeviceWireless() -{ - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerInterfaceDeviceWireless::isValid() -{ - return d->valid; -} - -bool QNetworkManagerInterfaceDeviceWireless::setConnections() -{ - if(!isValid() ) - return false; - - bool allOk = false; - nmDBusHelper = new QNmDBusHelper; - connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), - this,SIGNAL(propertiesChanged( const QString &, QMap))); - - connect(nmDBusHelper, SIGNAL(pathForAccessPointAdded(const QString &,QDBusObjectPath)), - this,SIGNAL(accessPointAdded(const QString &,QDBusObjectPath))); - - connect(nmDBusHelper, SIGNAL(pathForAccessPointRemoved(const QString &,QDBusObjectPath)), - this,SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath))); - - if(!dbusConnection.connect(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_DEVICE_WIRELESS, - "AccessPointAdded", - nmDBusHelper, SLOT(slotAccessPointAdded( QDBusObjectPath )))) { - allOk = true; - } - - - if(!dbusConnection.connect(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_DEVICE_WIRELESS, - "AccessPointRemoved", - nmDBusHelper, SLOT(slotAccessPointRemoved( QDBusObjectPath )))) { - allOk = true; - } - - - if(!dbusConnection.connect(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_DEVICE_WIRELESS, - "PropertiesChanged", - nmDBusHelper,SLOT(slotPropertiesChanged( QMap)))) { - allOk = true; - } - - return allOk; -} - -QDBusInterface *QNetworkManagerInterfaceDeviceWireless::connectionInterface() const -{ - return d->connectionInterface; -} - -QList QNetworkManagerInterfaceDeviceWireless::getAccessPoints() -{ - QDBusReply > reply = d->connectionInterface->call("GetAccessPoints"); - return reply.value(); -} - -QString QNetworkManagerInterfaceDeviceWireless::hwAddress() const -{ - return d->connectionInterface->property("HwAddress").toString(); -} - -quint32 QNetworkManagerInterfaceDeviceWireless::mode() const -{ - return d->connectionInterface->property("Mode").toUInt(); -} - -quint32 QNetworkManagerInterfaceDeviceWireless::bitrate() const -{ - return d->connectionInterface->property("Bitrate").toUInt(); -} - -QDBusObjectPath QNetworkManagerInterfaceDeviceWireless::activeAccessPoint() const -{ - return d->connectionInterface->property("ActiveAccessPoint").value(); -} - -quint32 QNetworkManagerInterfaceDeviceWireless::wirelessCapabilities() const -{ - return d->connectionInterface->property("WirelelessCapabilities").toUInt(); -} - -///////////// -class QNetworkManagerSettingsPrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; - -QNetworkManagerSettings::QNetworkManagerSettings(const QString &settingsService, QObject *parent) - : QObject(parent) -{ -// qWarning() << __PRETTY_FUNCTION__; - d = new QNetworkManagerSettingsPrivate(); - d->path = settingsService; - d->connectionInterface = new QDBusInterface(settingsService, - NM_DBUS_PATH_SETTINGS, - NM_DBUS_IFACE_SETTINGS, - dbusConnection); - if (!d->connectionInterface->isValid()) { - d->valid = false; - qWarning() << "Could not find NetworkManagerSettings"; - return; - } - d->valid = true; -} - -QNetworkManagerSettings::~QNetworkManagerSettings() -{ - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerSettings::isValid() -{ - return d->valid; -} - -bool QNetworkManagerSettings::setConnections() -{ - bool allOk = false; - - if (!dbusConnection.connect(d->path, NM_DBUS_PATH_SETTINGS, - NM_DBUS_IFACE_SETTINGS, "NewConnection", - this, SIGNAL(newConnection(QDBusObjectPath)))) { - allOk = true; - } - - return allOk; -} - -QList QNetworkManagerSettings::listConnections() -{ - QDBusReply > reply = d->connectionInterface->call("ListConnections"); - return reply.value(); -} - -QDBusInterface *QNetworkManagerSettings::connectionInterface() const -{ - return d->connectionInterface; -} - - -///////////// -class QNetworkManagerSettingsConnectionPrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - QString service; - QNmSettingsMap settingsMap; - bool valid; -}; - -QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent) -{ - qDBusRegisterMetaType(); - d = new QNetworkManagerSettingsConnectionPrivate(); - d->path = connectionObjectPath; - d->service = settingsService; - d->connectionInterface = new QDBusInterface(settingsService, - d->path, - NM_DBUS_IFACE_SETTINGS_CONNECTION, - dbusConnection, parent); - if (!d->connectionInterface->isValid()) { - qWarning() << "Could not find NetworkManagerSettingsConnection"; - d->valid = false; - return; - } - d->valid = true; - QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call("GetSettings"); - d->settingsMap = rep.value(); -} - -QNetworkManagerSettingsConnection::~QNetworkManagerSettingsConnection() -{ - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerSettingsConnection::isValid() -{ - return d->valid; -} - -bool QNetworkManagerSettingsConnection::setConnections() -{ - if(!isValid() ) - return false; - - bool allOk = false; - if(!dbusConnection.connect(d->service, d->path, - NM_DBUS_IFACE_SETTINGS_CONNECTION, "NewConnection", - this, SIGNAL(updated(QNmSettingsMap)))) { - allOk = true; - } - - nmDBusHelper = new QNmDBusHelper; - connect(nmDBusHelper, SIGNAL(pathForSettingsRemoved(const QString &)), - this,SIGNAL(removed( const QString &))); - - if (!dbusConnection.connect(d->service, d->path, - NM_DBUS_IFACE_SETTINGS_CONNECTION, "Removed", - nmDBusHelper, SIGNAL(slotSettingsRemoved()))) { - allOk = true; - } - - return allOk; -} -//QNetworkManagerSettingsConnection::update(QNmSettingsMap map) -//{ -// d->connectionInterface->call("Update", QVariant::fromValue(map)); -//} - -QDBusInterface *QNetworkManagerSettingsConnection::connectionInterface() const -{ - return d->connectionInterface; -} - -QNmSettingsMap QNetworkManagerSettingsConnection::getSettings() -{ - QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call("GetSettings"); - d->settingsMap = rep.value(); - return d->settingsMap; -} - -NMDeviceType QNetworkManagerSettingsConnection::getType() -{ - QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); - while (i != d->settingsMap.end() && i.key() == "connection") { - QMap innerMap = i.value(); - QMap::const_iterator ii = innerMap.find("type"); - while (ii != innerMap.end() && ii.key() == "type") { - QString devType = ii.value().toString(); - if (devType == "802-3-ethernet") { - return DEVICE_TYPE_802_3_ETHERNET; - } - if (devType == "802-11-wireless") { - return DEVICE_TYPE_802_11_WIRELESS; - } - ii++; - } - i++; - } - return DEVICE_TYPE_UNKNOWN; -} - -bool QNetworkManagerSettingsConnection::isAutoConnect() -{ - QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); - while (i != d->settingsMap.end() && i.key() == "connection") { - QMap innerMap = i.value(); - QMap::const_iterator ii = innerMap.find("autoconnect"); - while (ii != innerMap.end() && ii.key() == "autoconnect") { - return ii.value().toBool(); - ii++; - } - i++; - } - return true; //default networkmanager is autoconnect -} - -quint64 QNetworkManagerSettingsConnection::getTimestamp() -{ - QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); - while (i != d->settingsMap.end() && i.key() == "connection") { - QMap innerMap = i.value(); - QMap::const_iterator ii = innerMap.find("timestamp"); - while (ii != innerMap.end() && ii.key() == "timestamp") { - return ii.value().toUInt(); - ii++; - } - i++; - } - return 0; -} - -QString QNetworkManagerSettingsConnection::getId() -{ - QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); - while (i != d->settingsMap.end() && i.key() == "connection") { - QMap innerMap = i.value(); - QMap::const_iterator ii = innerMap.find("id"); - while (ii != innerMap.end() && ii.key() == "id") { - return ii.value().toString(); - ii++; - } - i++; - } - return QString(); -} - -QString QNetworkManagerSettingsConnection::getUuid() -{ - QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); - while (i != d->settingsMap.end() && i.key() == "connection") { - QMap innerMap = i.value(); - QMap::const_iterator ii = innerMap.find("uuid"); - while (ii != innerMap.end() && ii.key() == "uuid") { - return ii.value().toString(); - ii++; - } - i++; - } - // is no uuid, return the connection path - return d->connectionInterface->path(); -} - -QString QNetworkManagerSettingsConnection::getSsid() -{ - QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless"); - while (i != d->settingsMap.end() && i.key() == "802-11-wireless") { - QMap innerMap = i.value(); - QMap::const_iterator ii = innerMap.find("ssid"); - while (ii != innerMap.end() && ii.key() == "ssid") { - return ii.value().toString(); - ii++; - } - i++; - } - return QString(); -} - -QString QNetworkManagerSettingsConnection::getMacAddress() -{ - if(getType() == DEVICE_TYPE_802_3_ETHERNET) { - QNmSettingsMap::const_iterator i = d->settingsMap.find("802-3-ethernet"); - while (i != d->settingsMap.end() && i.key() == "802-3-ethernet") { - QMap innerMap = i.value(); - QMap::const_iterator ii = innerMap.find("mac-address"); - while (ii != innerMap.end() && ii.key() == "mac-address") { - return ii.value().toString(); - ii++; - } - i++; - } - } - - else if(getType() == DEVICE_TYPE_802_11_WIRELESS) { - QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless"); - while (i != d->settingsMap.end() && i.key() == "802-11-wireless") { - QMap innerMap = i.value(); - QMap::const_iterator ii = innerMap.find("mac-address"); - while (ii != innerMap.end() && ii.key() == "mac-address") { - return ii.value().toString(); - ii++; - } - i++; - } - } - return QString(); -} - -QStringList QNetworkManagerSettingsConnection::getSeenBssids() -{ - if(getType() == DEVICE_TYPE_802_11_WIRELESS) { - QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless"); - while (i != d->settingsMap.end() && i.key() == "802-11-wireless") { - QMap innerMap = i.value(); - QMap::const_iterator ii = innerMap.find("seen-bssids"); - while (ii != innerMap.end() && ii.key() == "seen-bssids") { - return ii.value().toStringList(); - ii++; - } - i++; - } - } - return QStringList(); -} - -///////////// -class QNetworkManagerConnectionActivePrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; - -QNetworkManagerConnectionActive::QNetworkManagerConnectionActive( const QString &activeConnectionObjectPath, QObject *parent) -{ - d = new QNetworkManagerConnectionActivePrivate(); - d->path = activeConnectionObjectPath; - d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_ACTIVE_CONNECTION, - dbusConnection, parent); - if (!d->connectionInterface->isValid()) { - d->valid = false; - qWarning() << "Could not find NetworkManagerSettingsConnection"; - return; - } - d->valid = true; -} - -QNetworkManagerConnectionActive::~QNetworkManagerConnectionActive() -{ - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerConnectionActive::isValid() -{ - return d->valid; -} - -bool QNetworkManagerConnectionActive::setConnections() -{ - if(!isValid() ) - return false; - - bool allOk = false; - nmDBusHelper = new QNmDBusHelper; - connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), - this,SIGNAL(propertiesChanged( const QString &, QMap))); - if(dbusConnection.connect(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_ACTIVE_CONNECTION, - "PropertiesChanged", - nmDBusHelper,SLOT(slotPropertiesChanged( QMap))) ) { - allOk = true; - } - - return allOk; -} - -QDBusInterface *QNetworkManagerConnectionActive::connectionInterface() const -{ - return d->connectionInterface; -} - -QString QNetworkManagerConnectionActive::serviceName() const -{ - return d->connectionInterface->property("ServiceName").toString(); -} - -QDBusObjectPath QNetworkManagerConnectionActive::connection() const -{ - QVariant prop = d->connectionInterface->property("Connection"); - return prop.value(); -} - -QDBusObjectPath QNetworkManagerConnectionActive::specificObject() const -{ - QVariant prop = d->connectionInterface->property("SpecificObject"); - return prop.value(); -} - -QList QNetworkManagerConnectionActive::devices() const -{ - QVariant prop = d->connectionInterface->property("Devices"); - return prop.value >(); -} - -quint32 QNetworkManagerConnectionActive::state() const -{ - return d->connectionInterface->property("State").toUInt(); -} - -bool QNetworkManagerConnectionActive::defaultRoute() const -{ - return d->connectionInterface->property("Default").toBool(); -} - - -//// -class QNetworkManagerIp4ConfigPrivate -{ -public: - QDBusInterface *connectionInterface; - QString path; - bool valid; -}; - -QNetworkManagerIp4Config::QNetworkManagerIp4Config( const QString &deviceObjectPath, QObject *parent) -{ - d = new QNetworkManagerIp4ConfigPrivate(); - d->path = deviceObjectPath; - d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, - d->path, - NM_DBUS_INTERFACE_IP4_CONFIG, - dbusConnection, parent); - if (!d->connectionInterface->isValid()) { - d->valid = false; - qWarning() << "Could not find NetworkManagerIp4Config"; - return; - } - d->valid = true; -} - -QNetworkManagerIp4Config::~QNetworkManagerIp4Config() -{ - delete d->connectionInterface; - delete d; -} - -bool QNetworkManagerIp4Config::isValid() -{ - return d->valid; -} - -QStringList QNetworkManagerIp4Config::domains() const -{ - return d->connectionInterface->property("Domains").toStringList(); -} - -#include "moc_qnetworkmanagerservice_p.cpp" - -QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkmanagerservice_p.h b/src/network/bearer/qnetworkmanagerservice_p.h deleted file mode 100644 index 520aeac..0000000 --- a/src/network/bearer/qnetworkmanagerservice_p.h +++ /dev/null @@ -1,397 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QNETWORKMANAGERSERVICE_H -#define QNETWORKMANAGERSERVICE_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include -#include -#include -#include -#include -#include -#include - - -#include -#include "qnmdbushelper_p.h" - -QT_BEGIN_NAMESPACE - -typedef QMap< QString, QMap > QNmSettingsMap; -typedef QList ServerThing; - -Q_DECLARE_METATYPE(QNmSettingsMap) -Q_DECLARE_METATYPE(ServerThing) - -class QNetworkManagerInterfacePrivate; -class QNetworkManagerInterface : public QObject -{ - Q_OBJECT - -public: - - QNetworkManagerInterface(QObject *parent = 0); - ~QNetworkManagerInterface(); - - QList getDevices() const; - void activateConnection(const QString &serviceName, QDBusObjectPath connection, QDBusObjectPath device, QDBusObjectPath specificObject); - void deactivateConnection(QDBusObjectPath connectionPath) const; - - QDBusObjectPath path() const; - QDBusInterface *connectionInterface() const; - - bool wirelessEnabled() const; - bool wirelessHardwareEnabled() const; - QList activeConnections() const; - quint32 state(); - bool setConnections(); - bool isValid(); - -Q_SIGNALS: - void deviceAdded(QDBusObjectPath); - void deviceRemoved(QDBusObjectPath); - void propertiesChanged( const QString &, QMap); - void stateChanged(const QString&, quint32); - void activationFinished(QDBusPendingCallWatcher*); - -private Q_SLOTS: -private: -// Q_DISABLE_COPY(QNetworkManagerInterface); ?? - QNetworkManagerInterfacePrivate *d; - QNmDBusHelper *nmDBusHelper; -}; //end QNetworkManagerInterface - -//////// -class QNetworkManagerInterfaceAccessPointPrivate; -class QNetworkManagerInterfaceAccessPoint : public QObject -{ - Q_OBJECT - -public: - - // NM_DEVICE_STATE - enum DeviceState { - Unknown = 0, - Unmanaged, - Unavailable, - Disconnected, - Prepare, - Config, - NeedAuthentication, - IpConfig, - Activated, - Failed - }; - - enum ApFlag { - ApNone = 0x0, - Privacy = 0x1 - }; - - Q_DECLARE_FLAGS(ApFlags, ApFlag); - - enum ApSecurityFlag { - ApSecurityNone = 0x0, - PairWep40 = 0x1, - PairWep104 = 0x2, - PairTkip = 0x4, - PairCcmp = 0x8, - GroupWep40 = 0x10, - GroupWep104 = 0x20, - GroupTkip = 0x40, - GroupCcmp = 0x80, - KeyPsk = 0x100, - Key8021x = 0x200 - }; - - Q_DECLARE_FLAGS(ApSecurityFlags, ApSecurityFlag); - - QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent = 0); - ~QNetworkManagerInterfaceAccessPoint(); - - QDBusInterface *connectionInterface() const; - - quint32 flags() const; - quint32 wpaFlags() const; - quint32 rsnFlags() const; - QString ssid() const; - quint32 frequency() const; - QString hwAddress() const; - quint32 mode() const; - quint32 maxBitrate() const; - quint32 strength() const; - bool setConnections(); - bool isValid(); - -Q_SIGNALS: - void propertiesChanged(QMap ); - void propertiesChanged( const QString &, QMap); -private: - QNetworkManagerInterfaceAccessPointPrivate *d; - QNmDBusHelper *nmDBusHelper; - -}; //end QNetworkManagerInterfaceAccessPoint - -//////// -class QNetworkManagerInterfaceDevicePrivate; -class QNetworkManagerInterfaceDevice : public QObject -{ - Q_OBJECT - -public: - - QNetworkManagerInterfaceDevice(const QString &deviceObjectPath, QObject *parent = 0); - ~QNetworkManagerInterfaceDevice(); - - QString udi() const; - QNetworkInterface interface() const; - QDBusInterface *connectionInterface() const; - quint32 ip4Address() const; - quint32 state() const; - quint32 deviceType() const; - - QDBusObjectPath ip4config() const; - bool setConnections(); - bool isValid(); - -Q_SIGNALS: - void stateChanged(const QString &, quint32); - -private: - QNetworkManagerInterfaceDevicePrivate *d; - QNmDBusHelper *nmDBusHelper; -}; //end QNetworkManagerInterfaceDevice - -//////// -class QNetworkManagerInterfaceDeviceWiredPrivate; -class QNetworkManagerInterfaceDeviceWired : public QObject -{ - Q_OBJECT - -public: - - QNetworkManagerInterfaceDeviceWired(const QString &ifaceDevicePath, QObject *parent = 0); - ~QNetworkManagerInterfaceDeviceWired(); - - QDBusInterface *connectionInterface() const; - QString hwAddress() const; - quint32 speed() const; - bool carrier() const; - bool setConnections(); - bool isValid(); - -Q_SIGNALS: - void propertiesChanged( const QString &, QMap); -private: - QNetworkManagerInterfaceDeviceWiredPrivate *d; - QNmDBusHelper *nmDBusHelper; -}; // end QNetworkManagerInterfaceDeviceWired - -//// -class QNetworkManagerInterfaceDeviceWirelessPrivate; -class QNetworkManagerInterfaceDeviceWireless : public QObject -{ - Q_OBJECT - -public: - - enum DeviceCapability { - None = 0x0, - Wep40 = 0x1, - Wep104 = 0x2, - Tkip = 0x4, - Ccmp = 0x8, - Wpa = 0x10, - Rsn = 0x20 - }; - - QNetworkManagerInterfaceDeviceWireless(const QString &ifaceDevicePath, QObject *parent = 0); - ~QNetworkManagerInterfaceDeviceWireless(); - - QDBusObjectPath path() const; - QList getAccessPoints(); - QDBusInterface *connectionInterface() const; - - QString hwAddress() const; - quint32 mode() const; - quint32 bitrate() const; - QDBusObjectPath activeAccessPoint() const; - quint32 wirelessCapabilities() const; - bool setConnections(); - bool isValid(); - -Q_SIGNALS: - void propertiesChanged( const QString &, QMap); - void accessPointAdded(const QString &,QDBusObjectPath); - void accessPointRemoved(const QString &,QDBusObjectPath); -private: - QNetworkManagerInterfaceDeviceWirelessPrivate *d; - QNmDBusHelper *nmDBusHelper; -}; // end QNetworkManagerInterfaceDeviceWireless - -//// -class QNetworkManagerSettingsPrivate; -class QNetworkManagerSettings : public QObject -{ - Q_OBJECT - -public: - - QNetworkManagerSettings(const QString &settingsService, QObject *parent = 0); - ~QNetworkManagerSettings(); - - QDBusInterface *connectionInterface() const; - QList listConnections(); - bool setConnections(); - bool isValid(); - -Q_SIGNALS: - void newConnection(QDBusObjectPath); -private: - QNetworkManagerSettingsPrivate *d; -}; //end QNetworkManagerSettings - -//// -class QNetworkManagerSettingsConnectionPrivate; -class QNetworkManagerSettingsConnection : public QObject -{ - Q_OBJECT - -public: - - QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent = 0); - ~QNetworkManagerSettingsConnection(); - - QDBusInterface *connectionInterface() const; - QNmSettingsMap getSettings(); - // void update(QNmSettingsMap map); - bool setConnections(); - NMDeviceType getType(); - bool isAutoConnect(); - quint64 getTimestamp(); - QString getId(); - QString getUuid(); - QString getSsid(); - QString getMacAddress(); - QStringList getSeenBssids(); - bool isValid(); - -Q_SIGNALS: - - void updated(QMap< QString, QMap > s); - void removed(const QString &); - -private: - QNmDBusHelper *nmDBusHelper; - QNetworkManagerSettingsConnectionPrivate *d; -}; //end QNetworkManagerSettingsConnection - -//// -class QNetworkManagerConnectionActivePrivate; -class QNetworkManagerConnectionActive : public QObject -{ - Q_OBJECT - -public: - - enum ActiveConnectionState { - Unknown = 0, - Activating = 1, - Activated = 2 - }; - - QNetworkManagerConnectionActive(const QString &dbusPathName, QObject *parent = 0); - ~ QNetworkManagerConnectionActive(); - - QDBusInterface *connectionInterface() const; - QString serviceName() const; - QDBusObjectPath connection() const; - QDBusObjectPath specificObject() const; - QList devices() const; - quint32 state() const; - bool defaultRoute() const; - bool setConnections(); - bool isValid(); - - -Q_SIGNALS: - void propertiesChanged(QList); - void propertiesChanged( const QString &, QMap); -private: - QNetworkManagerConnectionActivePrivate *d; - QNmDBusHelper *nmDBusHelper; -}; //QNetworkManagerConnectionActive - -//// -class QNetworkManagerIp4ConfigPrivate; -class QNetworkManagerIp4Config : public QObject -{ - Q_OBJECT - -public: - QNetworkManagerIp4Config(const QString &dbusPathName, QObject *parent = 0); - ~QNetworkManagerIp4Config(); - - // QList nameservers(); - QStringList domains() const; - bool isValid(); - - private: - QNetworkManagerIp4ConfigPrivate *d; -}; -//// - -QT_END_NAMESPACE - -#endif //QNETWORKMANAGERSERVICE_H diff --git a/src/network/bearer/qnetworksession_p.cpp b/src/network/bearer/qnetworksession_p.cpp index c2491ae..cb170e8 100644 --- a/src/network/bearer/qnetworksession_p.cpp +++ b/src/network/bearer/qnetworksession_p.cpp @@ -59,26 +59,8 @@ #include -#if defined(BACKEND_NM) -#include "qnmwifiengine_unix_p.h" -#endif - QT_BEGIN_NAMESPACE -#if defined(BACKEND_NM) -static bool NetworkManagerAvailable() -{ - QDBusConnection dbusConnection = QDBusConnection::systemBus(); - if (dbusConnection.isConnected()) { - QDBusConnectionInterface *dbiface = dbusConnection.interface(); - QDBusReply reply = dbiface->isServiceRegistered("org.freedesktop.NetworkManager"); - if (reply.isValid()) - return reply.value(); - } - return false; -} -#endif - static QNetworkSessionEngine *getEngineFromId(const QString &id) { QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); @@ -95,13 +77,6 @@ static QNetworkSessionEngine *getEngineFromId(const QString &id) return nativeWifi; #endif -#if defined(BACKEND_NM) - if(NetworkManagerAvailable()) { - QNmWifiEngine *nmwiifi = QNmWifiEngine::instance(); - if (nmwiifi && nmwiifi->hasIdentifier(id)) - return nmwiifi; - } -#endif #ifdef Q_OS_DARWIN QCoreWlanEngine *coreWifi = QCoreWlanEngine::instance(); if (coreWifi && coreWifi->hasIdentifier(id)) @@ -322,7 +297,7 @@ QNetworkSession::SessionError QNetworkSessionPrivate::error() const quint64 QNetworkSessionPrivate::bytesWritten() const { -#if defined(BACKEND_NM) +#if defined(BACKEND_NM) && 0 if( state == QNetworkSession::Connected ) { if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { foreach (const QNetworkConfiguration &config, publicConfig.children()) { @@ -340,7 +315,7 @@ quint64 QNetworkSessionPrivate::bytesWritten() const quint64 QNetworkSessionPrivate::bytesReceived() const { -#if defined(BACKEND_NM) +#if defined(BACKEND_NM) && 0 if( state == QNetworkSession::Connected ) { if (publicConfig.type() == QNetworkConfiguration::ServiceNetwork) { foreach (const QNetworkConfiguration &config, publicConfig.children()) { @@ -445,7 +420,7 @@ void QNetworkSessionPrivate::networkConfigurationsChanged() updateStateFromServiceNetwork(); else updateStateFromActiveConfig(); -#if defined(BACKEND_NM) +#if defined(BACKEND_NM) && 0 setActiveTimeStamp(); #endif } @@ -492,7 +467,7 @@ void QNetworkSessionPrivate::connectionError(const QString &id, QNetworkSessionE } } -#if defined(BACKEND_NM) +#if defined(BACKEND_NM) && 0 void QNetworkSessionPrivate::setActiveTimeStamp() { if(NetworkManagerAvailable()) { diff --git a/src/network/bearer/qnmdbushelper.cpp b/src/network/bearer/qnmdbushelper.cpp deleted file mode 100644 index 5d7403b..0000000 --- a/src/network/bearer/qnmdbushelper.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// this class is for helping qdbus get stuff - -#include "qnmdbushelper_p.h" - -#if !defined(QT_NO_DBUS) && !defined(Q_OS_MAC) -#include - -#include -#include -#include -#include -#endif - -#include - -QT_BEGIN_NAMESPACE - -void QNmDBusHelper::deviceStateChanged(quint32 state) - { - QDBusMessage msg = this->message(); - if(state == NM_DEVICE_STATE_ACTIVATED - || state == NM_DEVICE_STATE_DISCONNECTED - || state == NM_DEVICE_STATE_UNAVAILABLE - || state == NM_DEVICE_STATE_FAILED) { - emit pathForStateChanged(msg.path(), state); - } - } - -void QNmDBusHelper::slotAccessPointAdded(QDBusObjectPath path) -{ - if(path.path().length() > 2) { - QDBusMessage msg = this->message(); - emit pathForAccessPointAdded(msg.path(), path); - } -} - -void QNmDBusHelper::slotAccessPointRemoved(QDBusObjectPath path) -{ - if(path.path().length() > 2) { - QDBusMessage msg = this->message(); - emit pathForAccessPointRemoved(msg.path(), path); - } -} - -void QNmDBusHelper::slotPropertiesChanged(QMap map) -{ - QDBusMessage msg = this->message(); - QMapIterator i(map); - while (i.hasNext()) { - i.next(); - if( i.key() == "State") { //state only applies to device interfaces - quint32 state = i.value().toUInt(); - if( state == NM_DEVICE_STATE_ACTIVATED - || state == NM_DEVICE_STATE_DISCONNECTED - || state == NM_DEVICE_STATE_UNAVAILABLE - || state == NM_DEVICE_STATE_FAILED) { - emit pathForPropertiesChanged( msg.path(), map); - } - } else if( i.key() == "ActiveAccessPoint") { - // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().value().path(); - // } else if( i.key() == "Strength") - // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().toUInt(); - // else - // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value(); - } - } -} - -void QNmDBusHelper::slotSettingsRemoved() -{ - QDBusMessage msg = this->message(); - emit pathForSettingsRemoved(msg.path()); -} - -#include "moc_qnmdbushelper_p.cpp" -QT_END_NAMESPACE diff --git a/src/network/bearer/qnmdbushelper_p.h b/src/network/bearer/qnmdbushelper_p.h deleted file mode 100644 index 99b0357..0000000 --- a/src/network/bearer/qnmdbushelper_p.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QNMDBUSHELPERPRIVATE_H -#define QNMDBUSHELPERPRIVATE_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#if !defined(QT_NO_DBUS) && !defined(Q_OS_MAC) -#include -#include -#include -#endif - -QT_BEGIN_NAMESPACE - -#if !defined(QT_NO_DBUS) && !defined(Q_OS_MAC) - -class QNmDBusHelper: public QObject, protected QDBusContext - { - Q_OBJECT - public: - - public slots: - void deviceStateChanged(quint32); - void slotAccessPointAdded( QDBusObjectPath ); - void slotAccessPointRemoved( QDBusObjectPath ); - void slotPropertiesChanged( QMap); - void slotSettingsRemoved(); - -Q_SIGNALS: - void pathForStateChanged(const QString &, quint32); - void pathForAccessPointAdded(const QString &, QDBusObjectPath ); - void pathForAccessPointRemoved(const QString &, QDBusObjectPath ); - void pathForPropertiesChanged(const QString &, QMap); - void pathForSettingsRemoved(const QString &); -}; -#endif - -QT_END_NAMESPACE - -#endif// QNMDBUSHELPERPRIVATE_H diff --git a/src/network/bearer/qnmwifiengine_unix.cpp b/src/network/bearer/qnmwifiengine_unix.cpp deleted file mode 100644 index 5870a9f..0000000 --- a/src/network/bearer/qnmwifiengine_unix.cpp +++ /dev/null @@ -1,1129 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qnmwifiengine_unix_p.h" -#include "qnetworkconfiguration_p.h" -#include - -#include - -#include -#include -#include - -#include - -QT_BEGIN_NAMESPACE - -Q_GLOBAL_STATIC(QNmWifiEngine, nmWifiEngine) -typedef QList > QNmSettingsAddressMap; - -Q_DECLARE_METATYPE(QNmSettingsAddressMap) - -QNmWifiEngine::QNmWifiEngine(QObject *parent) -: QNetworkSessionEngine(parent) -{ - iface = new QNetworkManagerInterface(); - if(!iface->isValid()) { - return; - } - iface->setConnections(); - connect(iface,SIGNAL(deviceAdded(QDBusObjectPath)), - this,SLOT(addDevice(QDBusObjectPath))); - connect(iface,SIGNAL(deviceRemoved(QDBusObjectPath)), - this,SLOT(removeDevice(QDBusObjectPath))); - - QList list = iface->getDevices(); - - foreach(QDBusObjectPath path, list) { - addDevice(path); - } - - QStringList connectionServices; - connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; - connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; - foreach (QString service, connectionServices) { - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); - settingsiface->setConnections(); - connect(settingsiface,SIGNAL(newConnection(QDBusObjectPath)), - this,(SLOT(newConnection(QDBusObjectPath)))); - } - - updated = false; -} - -QNmWifiEngine::~QNmWifiEngine() -{ -} - -QString QNmWifiEngine::getNameForConfiguration(QNetworkManagerInterfaceDevice *devIface) -{ - QString newname; - if (devIface->state() == NM_DEVICE_STATE_ACTIVATED) { - QString path = devIface->ip4config().path(); - QNetworkManagerIp4Config * ipIface; - ipIface = new QNetworkManagerIp4Config(path); - newname = ipIface->domains().join(" "); - } - //fallback to interface name - if(newname.isEmpty()) - newname = devIface->interface().name(); - return newname; -} - - -QList QNmWifiEngine::getConfigurations(bool *ok) -{ -// qWarning() << Q_FUNC_INFO << updated; - if (ok) - *ok = false; - - if(!updated) { - foundConfigurations.clear(); - if(knownSsids.isEmpty()) - getKnownSsids(); // list of ssids that have user configurations. - - scanForAccessPoints(); - getActiveConnectionsPaths(); - knownConnections(); - - accessPointConnections(); - -// findConnections(); - //add access points - updated = true; - } - return foundConfigurations; -} - -void QNmWifiEngine::findConnections() -{ - QList list = iface->getDevices(); - - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); - - //// eth - switch (devIface->deviceType()) { -// qWarning() << devIface->connectionInterface()->path(); - - case DEVICE_TYPE_802_3_ETHERNET: - { - QString ident; - QNetworkManagerInterfaceDeviceWired *devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); - - ident = devWiredIface->hwAddress(); - - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - cpPriv->name = getNameForConfiguration(devIface); - cpPriv->isValid = true; - cpPriv->id = ident; - cpPriv->internet = devWiredIface->carrier(); - - cpPriv->serviceInterface = devIface->interface(); - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - switch (devIface->state()) { - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_UNMANAGED: - case NM_DEVICE_STATE_FAILED: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Undefined); - break; - case NM_DEVICE_STATE_UNAVAILABLE: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Defined); - break; - case NM_DEVICE_STATE_PREPARE: - case NM_DEVICE_STATE_CONFIG: - case NM_DEVICE_STATE_NEED_AUTH: - case NM_DEVICE_STATE_IP_CONFIG: - case NM_DEVICE_STATE_DISCONNECTED: - { - cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Discovered - | QNetworkConfiguration::Defined); - } - break; - case NM_DEVICE_STATE_ACTIVATED: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Active ); - break; - default: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Undefined); - break; - }; - cpPriv->purpose = QNetworkConfiguration::PublicPurpose; - foundConfigurations.append(cpPriv); - configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); - } - break; - case DEVICE_TYPE_802_11_WIRELESS: - { -// QNetworkManagerInterfaceDeviceWireless *devWirelessIface; -// devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); -// -// //// connections -// QStringList connectionServices; -// connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; -// connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; -// -// QString connPath; -// -// foreach (QString service, connectionServices) { -// QString ident; -// QNetworkManagerSettings *settingsiface; -// settingsiface = new QNetworkManagerSettings(service); -// QList list = settingsiface->listConnections(); -// -// foreach(QDBusObjectPath path, list) { //for each connection path -//qWarning() << path.path(); -// ident = path.path(); -// bool addIt = false; -// QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); -// cpPriv->isValid = true; -// cpPriv->id = ident; -// cpPriv->internet = true; -// -// cpPriv->type = QNetworkConfiguration::InternetAccessPoint; -// cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Discovered -// | QNetworkConfiguration::Defined); -// cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; -// -// QNetworkManagerSettingsConnection *sysIface; -// sysIface = new QNetworkManagerSettingsConnection(service, path.path()); -// cpPriv->name = sysIface->getId();//ii.value().toString(); -//qWarning() << cpPriv->name; -// if(sysIface->getType() == DEVICE_TYPE_802_3_ETHERNET/*type == "802-3-ethernet"*/ -// && devIface->deviceType() == DEVICE_TYPE_802_3_ETHERNET) { -// cpPriv->serviceInterface = devIface->interface(); -// addIt = true; -// } else if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS/*type == "802-11-wireless"*/ -// && devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { -// cpPriv->serviceInterface = devIface->interface(); -// addIt = true; -// // get the wifi interface state first.. do we need this? -// // QString activeAPPath = devWirelessIface->activeAccessPoint().path(); -// } -// -// //#if 0 -// foreach(QString conpath, activeConnectionPaths) { -// QNetworkManagerConnectionActive *aConn; -// aConn = new QNetworkManagerConnectionActive(conpath); -// // in case of accesspoint, specificObject will hold the accessPOintObjectPath -// // qWarning() << aConn->connection().path() << aConn->specificObject().path() << aConn->devices().count(); -// if( aConn->connection().path() == ident) { -// -// QList devs = aConn->devices(); -// foreach(QDBusObjectPath device, devs) { -// QNetworkManagerInterfaceDevice *ifaceDevice; -// ifaceDevice = new QNetworkManagerInterfaceDevice(device.path()); -// cpPriv->serviceInterface = ifaceDevice->interface(); -// cpPriv->state = getStateFlag(ifaceDevice->state()); -// //cpPriv->accessPoint = aConn->specificObject().path(); -// -// break; -// } -// } -// } -// //#endif -// // } //end while connection -// if(addIt) { -// foundConfigurations.append(cpPriv); -// configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); -// } -// } -// } //end each connection service -// -// // ////////////// AccessPoints -//// QList apList = devWirelessIface->getAccessPoints(); -////// qWarning() << apList.count(); -//// foreach(QDBusObjectPath path, apList) { -//// QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); -//// cpPriv = addAccessPoint( devIface->connectionInterface()->path(), path); -//// if(cpPriv->isValid) { -//// foundConfigurations.append(cpPriv); -//// } -//// } - } // end DEVICE_TYPE_802_11_WIRELESS - break; - }; - } //end foreach device -} - -void QNmWifiEngine::knownConnections() -{ -// qWarning() << Q_FUNC_INFO; - //// connections - QStringList connectionServices; - connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; - connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; - - QString connPath; - - foreach (QString service, connectionServices) { - QString ident; - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); - QList list = settingsiface->listConnections(); - -// qWarning() <setConnections(); - connect(sysIface, SIGNAL(removed(QString)), - this,SLOT(settingsConnectionRemoved(QString))); - - cpPriv->name = sysIface->getId(); - cpPriv->isValid = true; - cpPriv->id = sysIface->getUuid(); -// cpPriv->id = ident; - cpPriv->internet = true; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; -//qWarning() << cpPriv->name; - cpPriv->state = getStateForId(cpPriv->id); - - cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; - - if(sysIface->getType() == DEVICE_TYPE_802_3_ETHERNET) { - QString mac = sysIface->getMacAddress(); - if(!mac.length() > 2) { - qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXX" << mac << "type ethernet"; - QString devPath; - devPath = deviceConnectionPath(mac); - - // qWarning() << Q_FUNC_INFO << devPath; - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(devPath); - cpPriv->serviceInterface = devIface->interface(); - QNetworkManagerInterfaceDeviceWired *devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); - cpPriv->internet = devWiredIface->carrier(); - - // use this mac addy - } else { - cpPriv->serviceInterface = getBestInterface( DEVICE_TYPE_802_3_ETHERNET, cpPriv->id); - } - - cpPriv->internet = true;//sysIface->isAutoConnect(); - - addIt = true; - } else if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) { - QString mac = sysIface->getMacAddress();; - if(!mac.length() > 2) { - qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXX" << mac << "type wireless"; - QString devPath; - devPath = deviceConnectionPath(mac); -// qWarning() << Q_FUNC_INFO << devPath; - - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(devPath); - cpPriv->serviceInterface = devIface->interface(); - // use this mac addy - } else { - cpPriv->serviceInterface = getBestInterface( DEVICE_TYPE_802_11_WIRELESS, cpPriv->id); - } - // cpPriv->serviceInterface = devIface->interface(); - addIt = true; - // get the wifi interface state first.. do we need this? - // QString activeAPPath = devWirelessIface->activeAccessPoint().path(); - } - if(addIt) { - foundConfigurations.append(cpPriv); - configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); - } - } //end each connection service - } -} - -void QNmWifiEngine::accessPointConnections() -{ - //qWarning() << Q_FUNC_INFO; - QList list = iface->getDevices(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(path.path()); - if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { - QList apList = availableAccessPoints.uniqueKeys(); - - QList::const_iterator i; - for (i = apList.constBegin(); i != apList.constEnd(); ++i) { - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - cpPriv = addAccessPoint( devIface->connectionInterface()->path(), availableAccessPoints[*i]); - if(cpPriv->isValid) { - foundConfigurations.append(cpPriv); - // qWarning() << "adding" << cpPriv->name << "to things"; - configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); - } - } - } - } -} - -QString QNmWifiEngine::getInterfaceFromId(const QString &id) -{ - return configurationInterface.value(id); -} - -bool QNmWifiEngine::hasIdentifier(const QString &id) -{ - if (configurationInterface.contains(id)) - return true; - foreach (QNetworkConfigurationPrivate *cpPriv, getConfigurations()) { - if (cpPriv->id == id) - return true; - } - return false; -} - -QString QNmWifiEngine::bearerName(const QString &id) -{ - QString interface = getInterfaceFromId(id); - - QList list = iface->getDevices(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(path.path()); - if(interface == devIface->interface().name()) { - switch(devIface->deviceType()) { - case DEVICE_TYPE_802_3_ETHERNET/*NM_DEVICE_TYPE_ETHERNET*/: - return QLatin1String("Ethernet"); - break; - case DEVICE_TYPE_802_11_WIRELESS/*NM_DEVICE_TYPE_WIFI*/: - return QLatin1String("WLAN"); - break; - case DEVICE_TYPE_GSM/*NM_DEVICE_TYPE_GSM*/: - return QLatin1String("2G"); - break; - case DEVICE_TYPE_CDMA/*NM_DEVICE_TYPE_CDMA*/: - return QLatin1String("CDMA2000"); - break; - default: - break; - }; - } - } - return QString(); -} - -void QNmWifiEngine::connectToId(const QString &id) -{ -// qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << __FUNCTION__ << id; - activatingConnectionPath = id; - QStringList connectionSettings = getConnectionPathForId(id); - if(connectionSettings.isEmpty()) { - emit connectionError(id, OperationNotSupported); - return; - } - - QDBusObjectPath connectionPath(connectionSettings.at(1)); - QString interface = getInterfaceFromId(id); - - interface = QNetworkInterface::interfaceFromName(interface).hardwareAddress().toLower(); - QString devPath; - devPath = deviceConnectionPath(interface); - QDBusObjectPath devicePath(devPath); - - iface = new QNetworkManagerInterface(); - iface->activateConnection( - connectionSettings.at(0), - connectionPath, - devicePath, - connectionPath); - - connect(iface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)), - this, SLOT(slotActivationFinished(QDBusPendingCallWatcher*))); -} - -void QNmWifiEngine::disconnectFromId(const QString &id) -{ - QString activeConnectionPath = getActiveConnectionPath(id); - //qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << __FUNCTION__ << id << activeConnectionPath ; - - if (!activeConnectionPath.isEmpty()) { - QNetworkManagerConnectionActive *activeCon; - activeCon = new QNetworkManagerConnectionActive(activeConnectionPath); - QNetworkManagerSettingsConnection *settingsCon; - settingsCon = new QNetworkManagerSettingsConnection(activeCon->serviceName(), activeCon->connection().path()); - - if(settingsCon->isAutoConnect()) { -// qWarning() << id << "is autoconnect"; - emit connectionError(id, OperationNotSupported); - //unsupported - } else { -// qWarning() <deactivateConnection(dbpath); - activatingConnectionPath = ""; - } - } -} - -void QNmWifiEngine::requestUpdate() -{ - updated = false; - knownSsids.clear(); - availableAccessPoints.clear(); - emitConfigurationsChanged(); -} - -QNmWifiEngine *QNmWifiEngine::instance() -{ - QDBusConnection dbusConnection = QDBusConnection::systemBus(); - if (dbusConnection.isConnected()) { - QDBusConnectionInterface *dbiface = dbusConnection.interface(); - QDBusReply reply = dbiface->isServiceRegistered("org.freedesktop.NetworkManager"); - if (reply.isValid() && reply.value()) - return nmWifiEngine(); - } - - return 0; -} - -void QNmWifiEngine::getKnownSsids() -{ - QStringList connectionServices; - connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; - connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; -//qWarning() << Q_FUNC_INFO; - foreach (QString service, connectionServices) { - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); - QList list = settingsiface->listConnections(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(service, path.path()); -// qWarning() << sysIface->getSsid(); - knownSsids << sysIface->getSsid(); - } - } -} - -void QNmWifiEngine::getActiveConnectionsPaths() -{ -// qWarning() << Q_FUNC_INFO; - QNetworkManagerInterface *dbIface; - activeConnectionPaths.clear(); - dbIface = new QNetworkManagerInterface; - QList connections = dbIface->activeConnections(); - - foreach(QDBusObjectPath conpath, connections) { - activeConnectionPaths << conpath.path(); -// qWarning() << __FUNCTION__ << conpath.path() << activeConnectionPaths.count(); - - QNetworkManagerConnectionActive *activeConn; - activeConn = new QNetworkManagerConnectionActive(conpath.path()); - -// qWarning() << activeConn->connection().path() /*<< activeConn->specificObject().path() */<< activeConn->devices()[0].path(); - - } -} - -QNetworkConfigurationPrivate * QNmWifiEngine::addAccessPoint( const QString &iPath, QDBusObjectPath path) -{ //foreach accessPoint - //qWarning() << Q_FUNC_INFO << iPath << path.path(); - - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(iPath); - QNetworkManagerInterfaceDeviceWireless *devWirelessIface; - devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(iPath); - - QString activeAPPath = devWirelessIface->activeAccessPoint().path(); - - QNetworkManagerInterfaceAccessPoint *accessPointIface; - accessPointIface = new QNetworkManagerInterfaceAccessPoint(path.path()); - - QString ident = accessPointIface->connectionInterface()->path(); - quint32 nmState = devIface->state(); - - QString ssid = accessPointIface->ssid(); - QString hwAddy = accessPointIface->hwAddress(); - QString sInterface = devIface->interface().name(); - - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - bool addIt = true; - //qWarning() << availableAccessPoints.count() << ssid; - -// if(availableAccessPoints.contains(ssid)) { -// addIt = false; -// -// } -// foreach (QNetworkConfigurationPrivate *cpPriv, foundConfigurations) { -// if (cpPriv->name == ssid) { //weed out duplicate ssid's ?? -// addIt = false; -// break; -// } -// } - - if(addIt) { - - cpPriv->name = ssid; - cpPriv->isValid = true; - cpPriv->id = ident; - cpPriv->internet = true; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - cpPriv->serviceInterface = devIface->interface(); - - //qWarning() <<__FUNCTION__ << ssid; - - cpPriv->state = getAPState(nmState, knownSsids.contains(cpPriv->name)); - - if(activeAPPath == accessPointIface->connectionInterface()->path()) { - cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Active); - } - if(accessPointIface->flags() == NM_802_11_AP_FLAGS_PRIVACY) - cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; - else - cpPriv->purpose = QNetworkConfiguration::PublicPurpose; - return cpPriv; - } else { - cpPriv->isValid = false; - } - return cpPriv; -} - - - QNetworkConfiguration::StateFlags QNmWifiEngine::getAPState(qint32 nmState, bool isKnown) -{ - QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; -//qWarning() << nmState << knownSsids; - // this is the state of the wifi device interface - if(isKnown) - state = ( QNetworkConfiguration::Defined); - - switch(nmState) { //device interface state, not AP state - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_UNMANAGED: - case NM_DEVICE_STATE_UNAVAILABLE: - state = (QNetworkConfiguration::Undefined); - break; - case NM_DEVICE_STATE_DISCONNECTED: - { - if(isKnown) - state = ( state | QNetworkConfiguration::Discovered); - } - break; - case NM_DEVICE_STATE_PREPARE: - case NM_DEVICE_STATE_CONFIG: - case NM_DEVICE_STATE_NEED_AUTH: - case NM_DEVICE_STATE_IP_CONFIG: - if(isKnown) - state = ( state | QNetworkConfiguration::Discovered); - break; - case NM_DEVICE_STATE_ACTIVATED: - { - if(isKnown) - state = ( state | QNetworkConfiguration::Discovered); - } - break; - }; - return state; -} - -QString QNmWifiEngine::getActiveConnectionPath(const QString &id) -{ - //qWarning() << Q_FUNC_INFO << id; - QStringList connectionSettings = getConnectionPathForId(id); - //qWarning() << Q_FUNC_INFO << id << connectionSettings.count(); - QNetworkManagerInterface * ifaceD; - ifaceD = new QNetworkManagerInterface(); - QList connections = ifaceD->activeConnections(); - foreach(QDBusObjectPath path, connections) { - QNetworkManagerConnectionActive *conDetailsD; - conDetailsD = new QNetworkManagerConnectionActive( path.path()); - if(conDetailsD->connection().path() == connectionSettings.at(1) - && conDetailsD->serviceName() == connectionSettings.at(0)) - return path.path(); - } - return QString(); -} - - QNetworkConfiguration::StateFlags QNmWifiEngine::getStateFlag(quint32 nmstate) - { -// qWarning() << Q_FUNC_INFO << nmstate; - QNetworkConfiguration::StateFlags flag; - switch (nmstate) { - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_FAILED: - case NM_DEVICE_STATE_UNMANAGED: - flag = (QNetworkConfiguration::Undefined); - break; - case NM_DEVICE_STATE_PREPARE: - case NM_DEVICE_STATE_CONFIG: - case NM_DEVICE_STATE_NEED_AUTH: - case NM_DEVICE_STATE_IP_CONFIG: - case NM_DEVICE_STATE_UNAVAILABLE: - flag = (QNetworkConfiguration::Defined); - break; - case NM_DEVICE_STATE_DISCONNECTED: - flag = ( flag | QNetworkConfiguration::Discovered ); - break; - case NM_DEVICE_STATE_ACTIVATED: - { - flag = ( flag | QNetworkConfiguration::Discovered - | QNetworkConfiguration::Active ); - } - break; - default: - flag = ( QNetworkConfiguration::Defined); - break; - }; - return flag; - } - -void QNmWifiEngine::updateDeviceInterfaceState(const QString &/*path*/, quint32 nmState) -{ -// qWarning() << Q_FUNC_INFO << path << nmState; - - if(nmState == NM_DEVICE_STATE_ACTIVATED - || nmState == NM_DEVICE_STATE_DISCONNECTED - || nmState == NM_DEVICE_STATE_UNAVAILABLE - || nmState == NM_DEVICE_STATE_FAILED) { - -/* InterfaceLookupError = 0, - ConnectError, - OperationNotSupported, - DisconnectionError, -*/ -// qWarning() << Q_FUNC_INFO << ident; - QNetworkConfiguration::StateFlags state = (QNetworkConfiguration::Defined); - switch (nmState) { - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_FAILED: - state = (QNetworkConfiguration::Undefined); - emit connectionError(activatingConnectionPath, ConnectError); - requestUpdate(); -// qWarning() << Q_FUNC_INFO; - break; - case NM_DEVICE_STATE_UNAVAILABLE: - state = (QNetworkConfiguration::Defined); -// emit connectionError(activatingConnectionPath, ConnectError); - requestUpdate(); - break; - case NM_DEVICE_STATE_DISCONNECTED: - state = ( state | QNetworkConfiguration::Discovered ); - requestUpdate(); - break; - case NM_DEVICE_STATE_ACTIVATED: - { - state = ( state | QNetworkConfiguration::Discovered - | QNetworkConfiguration::Active ); - requestUpdate(); - } - break; - default: - state = ( QNetworkConfiguration::Defined); - break; - }; - } -} - -void QNmWifiEngine::addDevice(QDBusObjectPath path) -{ - //qWarning() << Q_FUNC_INFO << path.path(); - QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); - devIface->setConnections(); - connect(devIface,SIGNAL(stateChanged(const QString &, quint32)), - this, SLOT(updateDeviceInterfaceState(const QString&, quint32))); - - if(!devicePaths.contains(path.path())) - devicePaths << path.path(); - - switch(devIface->deviceType()) { - case DEVICE_TYPE_802_3_ETHERNET: - { - QNetworkManagerInterfaceDeviceWired * devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); - devWiredIface->setConnections(); - connect(devWiredIface, SIGNAL(propertiesChanged(const QString &,QMap)), - this,SLOT(cmpPropertiesChanged( const QString &, QMap))); - requestUpdate(); - } - break; - case DEVICE_TYPE_802_11_WIRELESS: - { - QNetworkManagerInterfaceDeviceWireless *devWirelessIface; - devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); - devWirelessIface->setConnections(); - - connect(devWirelessIface, SIGNAL(propertiesChanged(const QString &,QMap)), - this,SLOT(cmpPropertiesChanged( const QString &, QMap))); - - connect(devWirelessIface, SIGNAL(accessPointAdded(const QString &,QDBusObjectPath)), - this,SLOT(accessPointAdded(const QString &,QDBusObjectPath))); - - connect(devWirelessIface, SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath)), - this,SLOT(accessPointRemoved(const QString &,QDBusObjectPath))); - requestUpdate(); - - } - break; - default: - break; - }; -} - -void QNmWifiEngine::removeDevice(QDBusObjectPath /*path*/) -{ -// qWarning() << Q_FUNC_INFO << path.path(); -// disconnect(devIface,SIGNAL(stateChanged(const QString &, quint32)), -// this, SLOT(updateDeviceInterfaceState(const QString&, quint32))); -// -// if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { -// // devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); -// // devWirelessIface->setConnections(); -// -// disconnect(devWirelessIface, SIGNAL(propertiesChanged(const QString &,QMap)), -// this,SIGNAL(cmpPropertiesChanged( const QString &, QMap))); -// -// disconnect(devWirelessIface, SIGNAL(accessPointAdded(const QString &,QDBusObjectPath)), -// this,SIGNAL(accessPointAdded(const QString &,QDBusObjectPath))); -// -// disconnect(devWirelessIface, SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath)), -// this,SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath))); -// -// } -} -void QNmWifiEngine::cmpPropertiesChanged(const QString &path, QMap map) -{ - QMapIterator i(map); - while (i.hasNext()) { - i.next(); -// qWarning() << Q_FUNC_INFO << path << i.key() << i.value().toUInt(); - if( i.key() == "State") { //only applies to device interfaces - updateDeviceInterfaceState(path, i.value().toUInt()); - } - if( i.key() == "ActiveAccessPoint") { - } - if( i.key() == "Carrier") { //someone got plugged in - // requestUpdate(); - } - } -} - -void QNmWifiEngine::accessPointRemoved( const QString &aPath, QDBusObjectPath /*oPath*/) -{ - //qWarning() << Q_FUNC_INFO << aPath << oPath.path(); - - if(aPath.contains("devices")) { - requestUpdate(); - } -} - -void QNmWifiEngine::accessPointAdded( const QString &aPath, QDBusObjectPath oPath) -{ - //qWarning() << Q_FUNC_INFO << aPath << oPath.path(); - - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - cpPriv = addAccessPoint( aPath, oPath); - requestUpdate(); -} - -QNetworkConfiguration::StateFlags QNmWifiEngine::getStateForId(const QString &id) -{ - //qWarning() << Q_FUNC_INFO << id; - bool isAvailable = false; - QStringList conPath = getConnectionPathForId(id); - QString aconpath = getActiveConnectionPath(id); - - //qWarning() << Q_FUNC_INFO << id << aconpath; - - if(!aconpath.isEmpty()) { - //active connection - QNetworkManagerConnectionActive *aConn; - aConn = new QNetworkManagerConnectionActive(aconpath); - - QList devs = aConn->devices(); - - foreach(QDBusObjectPath dev, devs) { - //qWarning() << "foreach" << dev.path(); - QNetworkManagerInterfaceDevice *ifaceDevice; - ifaceDevice = new QNetworkManagerInterfaceDevice(dev.path()); - - if(ifaceDevice->deviceType() == DEVICE_TYPE_802_3_ETHERNET) { - - if(isAddressOfConnection(id, ifaceDevice->ip4Address())) { - // this is it! - return getStateFlag(ifaceDevice->state()); - } else { - continue; - } - - if(ifaceDevice->state() == NM_DEVICE_STATE_UNAVAILABLE || - ifaceDevice->state() == NM_DEVICE_STATE_DISCONNECTED) { - isAvailable = true; - - QNetworkManagerInterfaceDeviceWired *devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(ifaceDevice->connectionInterface()->path()); - if(!devWiredIface->carrier()) - return QNetworkConfiguration::Defined; - } //end eth - } else if(ifaceDevice->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { - qWarning() << "FIXME!!!!!!!!!!!!!!!!!"; - } - - return getStateFlag(ifaceDevice->state()); - } - } else { - // not active - //qWarning() << Q_FUNC_INFO << "Not active"; - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(conPath.at(0),conPath.at(1)); - if(sysIface->isValid()) { - if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) { - QString ssid = sysIface->getSsid(); - bool ok = false; - - if(knownSsids.contains(ssid, Qt::CaseSensitive)) { - foreach(QString onessid, knownSsids) { - // qWarning() << ssid << onessid; - if(onessid == ssid && availableAccessPoints.contains(ssid)) { - // qWarning() < devices = aConn->devices(); - foreach(QDBusObjectPath device, devices) { - QNetworkManagerInterfaceDevice *ifaceDevice; - ifaceDevice = new QNetworkManagerInterfaceDevice(device.path()); - if(ifaceDevice->ip4Address() == ipaddress) { - return true; - } - } - return false; -} - -QNetworkInterface QNmWifiEngine::getBestInterface( quint32 type, const QString &id) -{ - // check active connections first. - QStringList conIdPath = getConnectionPathForId(id); -// qWarning() << Q_FUNC_INFO << id << conIdPath; - - QNetworkInterface interface; - foreach(QString conpath, activeConnectionPaths) { - QNetworkManagerConnectionActive *aConn; - aConn = new QNetworkManagerConnectionActive(conpath); - - if(aConn->connection().path() == conIdPath.at(1) - && aConn->serviceName() == conIdPath.at(0)) { - - QList devs = aConn->devices(); - QNetworkManagerInterfaceDevice *ifaceDevice; - ifaceDevice = new QNetworkManagerInterfaceDevice(devs[0].path()); //just take the first one - interface = ifaceDevice->interface(); - return interface; - } - } - -//try guessing - QList list = iface->getDevices(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); - if(devIface->deviceType() == type /*&& devIface->managed()*/) { - interface = devIface->interface(); - if(devIface->state() == NM_STATE_DISCONNECTED) { - return interface; - } - } - } - return interface; -} - -quint64 QNmWifiEngine::receivedDataForId(const QString &id) const -{ - if(configurationInterface.count() > 1) - return 0; - quint64 result = 0; - - QString devFile; - devFile = configurationInterface.value(id); - QFile rx("/sys/class/net/"+devFile+"/statistics/rx_bytes"); - if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) { - QTextStream in(&rx); - in >> result; - rx.close(); - } - return result; -} - -quint64 QNmWifiEngine::sentDataForId(const QString &id) const -{ - if(configurationInterface.count() > 1) - return 0; - quint64 result = 0; - QString devFile; - devFile = configurationInterface.value(id); - - QFile tx("/sys/class/net/"+devFile+"/statistics/tx_bytes"); - if(tx.exists() && tx.open(QIODevice::ReadOnly | QIODevice::Text)) { - QTextStream in(&tx); - in >> result; - tx.close(); - } - return result; -} - -void QNmWifiEngine::newConnection(QDBusObjectPath /*path*/) -{ - //qWarning() << Q_FUNC_INFO; - requestUpdate(); -} - -void QNmWifiEngine::settingsConnectionRemoved(const QString &/*path*/) -{ - //qWarning() << Q_FUNC_INFO; - requestUpdate(); -} - -void QNmWifiEngine::slotActivationFinished(QDBusPendingCallWatcher *openCall) -{ - QDBusPendingReply reply = *openCall; - if (reply.isError()) { - qWarning() <<"Error" << reply.error().name() << reply.error().message() - < list = iface->getDevices(); - - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(path.path()); - - if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { - -// qWarning() << devIface->connectionInterface()->path(); - - QNetworkManagerInterfaceDeviceWireless *devWirelessIface; - devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); - ////////////// AccessPoints - QList apList = devWirelessIface->getAccessPoints(); - - foreach(QDBusObjectPath path, apList) { - QNetworkManagerInterfaceAccessPoint *accessPointIface; - accessPointIface = new QNetworkManagerInterfaceAccessPoint(path.path()); - QString ssid = accessPointIface->ssid(); - availableAccessPoints.insert(ssid, path); - } - } - } -} - -QString QNmWifiEngine::deviceConnectionPath(const QString &mac) -{ -// qWarning() << __FUNCTION__ << mac; - QString newMac = mac; - newMac = newMac.replace(":","_").toLower(); - //device object path might not contain just mac address - //might contain extra numbers on the end. thanks HAL - foreach(QString device, devicePaths) { - if(device.contains(newMac)) { - newMac = device; - break; - } - } - return newMac; -} - -QStringList QNmWifiEngine::getConnectionPathForId(const QString &uuid) -{ - QStringList connectionServices; - connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; - connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; -//qWarning() << Q_FUNC_INFO; - foreach (QString service, connectionServices) { - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); - QList list = settingsiface->listConnections(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(service, path.path()); -// qWarning() << uuid << sysIface->getUuid(); - if(sysIface->getUuid() == uuid) { -// qWarning() <<__FUNCTION__ << service << sysIface->getId() << sysIface->connectionInterface()->path(); - return QStringList() << service << sysIface->connectionInterface()->path(); - } - } - } - return QStringList(); -} - -#include "moc_qnmwifiengine_unix_p.cpp" - -QT_END_NAMESPACE - diff --git a/src/network/bearer/qnmwifiengine_unix_p.h b/src/network/bearer/qnmwifiengine_unix_p.h deleted file mode 100644 index 3af73ea..0000000 --- a/src/network/bearer/qnmwifiengine_unix_p.h +++ /dev/null @@ -1,164 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QNMWIFIENGINE_P_H -#define QNMWIFIENGINE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -//#include - -#include -#include -#include -#include - -#include "qnetworksessionengine_p.h" -#include -#include -#include - - - -QT_BEGIN_NAMESPACE - -class QNetworkConfigurationPrivate; - -class QNmWifiEngine : public QNetworkSessionEngine -{ - Q_OBJECT - -public: - QNmWifiEngine(QObject *parent = 0); - ~QNmWifiEngine(); - - QList getConfigurations(bool *ok = 0); - QString getInterfaceFromId(const QString &id); - bool hasIdentifier(const QString &id); - - QString bearerName(const QString &id); - - void connectToId(const QString &id); - void disconnectFromId(const QString &id); - - void requestUpdate(); - - static QNmWifiEngine *instance(); - - QStringList knownSsids; - inline void emitConfigurationsChanged() { emit configurationsChanged(); } - QNetworkConfigurationPrivate * addAccessPoint(const QString &, QDBusObjectPath ); - - QStringList getConnectionPathForId(const QString &uuid); - //QString getConnectionPathForId(const QString &name = QString()); - quint64 sentDataForId(const QString &id) const; - quint64 receivedDataForId(const QString &id) const; - -private: - bool updated; - QString activatingConnectionPath; - QStringList activeConnectionPaths; - - - QMap availableAccessPoints; - void scanForAccessPoints(); - - QStringList devicePaths; - - void getActiveConnectionsPaths(); - void getKnownSsids(); - void accessPointConnections(); - void knownConnections(); - void findConnections(); - QString deviceConnectionPath(const QString &mac); - - QList foundConfigurations; - // QHash > allConfigurations; - - QNetworkManagerInterface *iface; - - QNetworkConfiguration::StateFlags getAPState(qint32 vState, bool isKnown); - QNetworkConfiguration::StateFlags getStateFlag(quint32 nmstate); - - QString getActiveConnectionPath(const QString &identifier); - QString getNameForConfiguration(QNetworkManagerInterfaceDevice *devIface); - - QNetworkConfiguration::StateFlags getStateForId(const QString &id); - - QNetworkInterface getBestInterface(quint32 type, const QString &conPath); - - QMap configurationInterface; - - bool isAddressOfConnection(const QString &conPath, quint32 ipaddress); - -private slots: - void updateDeviceInterfaceState(const QString &, quint32); - void addDevice(QDBusObjectPath path); - void removeDevice(QDBusObjectPath path); - -Q_SIGNALS: - void configurationChanged(const QNetworkConfiguration& config); - void updateAccessPointState(const QString &, quint32); -// void slotActivationFinished(QDBusPendingCallWatcher*); - -private slots: - void accessPointAdded( const QString &aPath, QDBusObjectPath oPath); - void accessPointRemoved( const QString &aPath, QDBusObjectPath oPath); - void cmpPropertiesChanged(const QString &, QMap map); - void newConnection(QDBusObjectPath); - void settingsConnectionRemoved(const QString &); - void slotActivationFinished(QDBusPendingCallWatcher*); -}; - -QT_END_NAMESPACE - -#endif - - diff --git a/src/plugins/bearer/bearer.pro b/src/plugins/bearer/bearer.pro index 0e3ef48..60ba81b 100644 --- a/src/plugins/bearer/bearer.pro +++ b/src/plugins/bearer/bearer.pro @@ -1,3 +1,4 @@ TEMPLATE = subdirs SUBDIRS += generic +contains(QT_CONFIG, dbus):contains(QT_CONFIG, networkmanager):SUBDIRS += networkmanager diff --git a/src/plugins/bearer/networkmanager/main.cpp b/src/plugins/bearer/networkmanager/main.cpp new file mode 100644 index 0000000..c79fe91 --- /dev/null +++ b/src/plugins/bearer/networkmanager/main.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnmwifiengine.h" + +#include + +#include + +QT_BEGIN_NAMESPACE + +class QNetworkManagerEnginePlugin : public QBearerEnginePlugin +{ +public: + QNetworkManagerEnginePlugin(); + ~QNetworkManagerEnginePlugin(); + + QStringList keys() const; + QBearerEngine *create(const QString &key) const; +}; + +QNetworkManagerEnginePlugin::QNetworkManagerEnginePlugin() +{ +} + +QNetworkManagerEnginePlugin::~QNetworkManagerEnginePlugin() +{ +} + +QStringList QNetworkManagerEnginePlugin::keys() const +{ + qDebug() << Q_FUNC_INFO; + + return QStringList() << QLatin1String("networkmanager"); +} + +QBearerEngine *QNetworkManagerEnginePlugin::create(const QString &key) const +{ + qDebug() << Q_FUNC_INFO; + + if (key == QLatin1String("networkmanager")) + return new QNmWifiEngine; + else + return 0; +} + +Q_EXPORT_STATIC_PLUGIN(QNetworkManagerEnginePlugin) +Q_EXPORT_PLUGIN2(qnmbearer, QNetworkManagerEnginePlugin) + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/networkmanager/networkmanager.pro b/src/plugins/bearer/networkmanager/networkmanager.pro new file mode 100644 index 0000000..36d150a --- /dev/null +++ b/src/plugins/bearer/networkmanager/networkmanager.pro @@ -0,0 +1,19 @@ +TARGET = qnmbearer +include(../../qpluginbase.pri) + +QT += network dbus + +DEFINES += BEARER_ENGINE BACKEND_NM + +HEADERS += qnmdbushelper.h \ + qnetworkmanagerservice.h \ + qnmwifiengine.h + +SOURCES += main.cpp \ + qnmdbushelper.cpp \ + qnetworkmanagerservice.cpp \ + qnmwifiengine.cpp + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer +target.path += $$[QT_INSTALL_PLUGINS]/bearer +INSTALLS += target diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp new file mode 100644 index 0000000..e95c2e6 --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp @@ -0,0 +1,1009 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "qnmdbushelper.h" +#include "qnetworkmanagerservice.h" + +//Q_DECLARE_METATYPE(QList) +QT_BEGIN_NAMESPACE + +static QDBusConnection dbusConnection = QDBusConnection::systemBus(); +//static QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbusConnection); + +class QNetworkManagerInterfacePrivate +{ +public: + QDBusInterface *connectionInterface; + bool valid; +}; + +QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent) + : QObject(parent) +{ + d = new QNetworkManagerInterfacePrivate(); + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + dbusConnection); + if (!d->connectionInterface->isValid()) { + qWarning() << "Could not find NetworkManager"; + d->valid = false; + return; + } + d->valid = true; + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), + this,SIGNAL(propertiesChanged( const QString &, QMap))); + connect(nmDBusHelper,SIGNAL(pathForStateChanged(const QString &, quint32)), + this, SIGNAL(stateChanged(const QString&, quint32))); + +} + +QNetworkManagerInterface::~QNetworkManagerInterface() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterface::isValid() +{ + return d->valid; +} + +bool QNetworkManagerInterface::setConnections() +{ + if(!isValid() ) + return false; + bool allOk = false; + if (!dbusConnection.connect(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "PropertiesChanged", + nmDBusHelper,SLOT(slotPropertiesChanged( QMap)))) { + allOk = true; + } + if (!dbusConnection.connect(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "DeviceAdded", + this,SIGNAL(deviceAdded(QDBusObjectPath)))) { + allOk = true; + } + if (!dbusConnection.connect(NM_DBUS_SERVICE, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "DeviceRemoved", + this,SIGNAL(deviceRemoved(QDBusObjectPath)))) { + allOk = true; + } + + return allOk; +} + +QDBusInterface *QNetworkManagerInterface::connectionInterface() const +{ + return d->connectionInterface; +} + +QList QNetworkManagerInterface::getDevices() const +{ + QDBusReply > reply = d->connectionInterface->call("GetDevices"); + return reply.value(); +} + +void QNetworkManagerInterface::activateConnection( const QString &serviceName, + QDBusObjectPath connectionPath, + QDBusObjectPath devicePath, + QDBusObjectPath specificObject) +{ + QDBusPendingCall pendingCall = d->connectionInterface->asyncCall("ActivateConnection", + QVariant(serviceName), + QVariant::fromValue(connectionPath), + QVariant::fromValue(devicePath), + QVariant::fromValue(specificObject)); + + QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(pendingCall, this); + connect(callWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SIGNAL(activationFinished(QDBusPendingCallWatcher*))); +} + +void QNetworkManagerInterface::deactivateConnection(QDBusObjectPath connectionPath) const +{ + d->connectionInterface->call("DeactivateConnection", QVariant::fromValue(connectionPath)); +} + +bool QNetworkManagerInterface::wirelessEnabled() const +{ + return d->connectionInterface->property("WirelessEnabled").toBool(); +} + +bool QNetworkManagerInterface::wirelessHardwareEnabled() const +{ + return d->connectionInterface->property("WirelessHardwareEnabled").toBool(); +} + +QList QNetworkManagerInterface::activeConnections() const +{ + QVariant prop = d->connectionInterface->property("ActiveConnections"); + return prop.value >(); +} + +quint32 QNetworkManagerInterface::state() +{ + return d->connectionInterface->property("State").toUInt(); +} + +///////////// +class QNetworkManagerInterfaceAccessPointPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerInterfaceAccessPoint::QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent) + : QObject(parent) +{ + d = new QNetworkManagerInterfaceAccessPointPrivate(); + d->path = dbusPathName; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_ACCESS_POINT, + dbusConnection); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find InterfaceAccessPoint"; + return; + } + d->valid = true; + +} + +QNetworkManagerInterfaceAccessPoint::~QNetworkManagerInterfaceAccessPoint() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterfaceAccessPoint::isValid() +{ + return d->valid; +} + +bool QNetworkManagerInterfaceAccessPoint::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), + this,SIGNAL(propertiesChanged( const QString &, QMap))); + + if(dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_ACCESS_POINT, + "PropertiesChanged", + nmDBusHelper,SLOT(slotPropertiesChanged( QMap))) ) { + allOk = true; + + } + return allOk; +} + +QDBusInterface *QNetworkManagerInterfaceAccessPoint::connectionInterface() const +{ + return d->connectionInterface; +} + +quint32 QNetworkManagerInterfaceAccessPoint::flags() const +{ + return d->connectionInterface->property("Flags").toUInt(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::wpaFlags() const +{ + return d->connectionInterface->property("WpaFlags").toUInt(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::rsnFlags() const +{ + return d->connectionInterface->property("RsnFlags").toUInt(); +} + +QString QNetworkManagerInterfaceAccessPoint::ssid() const +{ + return d->connectionInterface->property("Ssid").toString(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::frequency() const +{ + return d->connectionInterface->property("Frequency").toUInt(); +} + +QString QNetworkManagerInterfaceAccessPoint::hwAddress() const +{ + return d->connectionInterface->property("HwAddress").toString(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::mode() const +{ + return d->connectionInterface->property("Mode").toUInt(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::maxBitrate() const +{ + return d->connectionInterface->property("MaxBitrate").toUInt(); +} + +quint32 QNetworkManagerInterfaceAccessPoint::strength() const +{ + return d->connectionInterface->property("Strength").toUInt(); +} + +///////////// +class QNetworkManagerInterfaceDevicePrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &deviceObjectPath, QObject *parent) + : QObject(parent) +{ + d = new QNetworkManagerInterfaceDevicePrivate(); + d->path = deviceObjectPath; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE, + dbusConnection); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find NetworkManager"; + return; + } + d->valid = true; +} + +QNetworkManagerInterfaceDevice::~QNetworkManagerInterfaceDevice() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterfaceDevice::isValid() +{ + return d->valid; +} + +bool QNetworkManagerInterfaceDevice::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper,SIGNAL(pathForStateChanged(const QString &, quint32)), + this, SIGNAL(stateChanged(const QString&, quint32))); + if(dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE, + "StateChanged", + nmDBusHelper,SLOT(deviceStateChanged(quint32)))) { + allOk = true; + } + return allOk; +} + +QDBusInterface *QNetworkManagerInterfaceDevice::connectionInterface() const +{ + return d->connectionInterface; +} + +QString QNetworkManagerInterfaceDevice::udi() const +{ + return d->connectionInterface->property("Udi").toString(); +} + +QNetworkInterface QNetworkManagerInterfaceDevice::interface() const +{ + return QNetworkInterface::interfaceFromName(d->connectionInterface->property("Interface").toString()); +} + +quint32 QNetworkManagerInterfaceDevice::ip4Address() const +{ + return d->connectionInterface->property("Ip4Address").toUInt(); +} + +quint32 QNetworkManagerInterfaceDevice::state() const +{ + return d->connectionInterface->property("State").toUInt(); +} + +quint32 QNetworkManagerInterfaceDevice::deviceType() const +{ + return d->connectionInterface->property("DeviceType").toUInt(); +} + +QDBusObjectPath QNetworkManagerInterfaceDevice::ip4config() const +{ + QVariant prop = d->connectionInterface->property("Ip4Config"); + return prop.value(); +} + +///////////// +class QNetworkManagerInterfaceDeviceWiredPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const QString &ifaceDevicePath, QObject *parent) +{ + d = new QNetworkManagerInterfaceDeviceWiredPrivate(); + d->path = ifaceDevicePath; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRED, + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find InterfaceDeviceWired"; + return; + } + d->valid = true; +} + +QNetworkManagerInterfaceDeviceWired::~QNetworkManagerInterfaceDeviceWired() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterfaceDeviceWired::isValid() +{ + + return d->valid; +} + +bool QNetworkManagerInterfaceDeviceWired::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), + this,SIGNAL(propertiesChanged( const QString &, QMap))); + if(dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRED, + "PropertiesChanged", + nmDBusHelper,SLOT(slotPropertiesChanged( QMap))) ) { + allOk = true; + } + return allOk; +} + +QDBusInterface *QNetworkManagerInterfaceDeviceWired::connectionInterface() const +{ + return d->connectionInterface; +} + +QString QNetworkManagerInterfaceDeviceWired::hwAddress() const +{ + return d->connectionInterface->property("HwAddress").toString(); +} + +quint32 QNetworkManagerInterfaceDeviceWired::speed() const +{ + return d->connectionInterface->property("Speed").toUInt(); +} + +bool QNetworkManagerInterfaceDeviceWired::carrier() const +{ + return d->connectionInterface->property("Carrier").toBool(); +} + +///////////// +class QNetworkManagerInterfaceDeviceWirelessPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(const QString &ifaceDevicePath, QObject *parent) +{ + d = new QNetworkManagerInterfaceDeviceWirelessPrivate(); + d->path = ifaceDevicePath; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find InterfaceDeviceWireless"; + return; + } + d->valid = true; +} + +QNetworkManagerInterfaceDeviceWireless::~QNetworkManagerInterfaceDeviceWireless() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerInterfaceDeviceWireless::isValid() +{ + return d->valid; +} + +bool QNetworkManagerInterfaceDeviceWireless::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), + this,SIGNAL(propertiesChanged( const QString &, QMap))); + + connect(nmDBusHelper, SIGNAL(pathForAccessPointAdded(const QString &,QDBusObjectPath)), + this,SIGNAL(accessPointAdded(const QString &,QDBusObjectPath))); + + connect(nmDBusHelper, SIGNAL(pathForAccessPointRemoved(const QString &,QDBusObjectPath)), + this,SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath))); + + if(!dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + "AccessPointAdded", + nmDBusHelper, SLOT(slotAccessPointAdded( QDBusObjectPath )))) { + allOk = true; + } + + + if(!dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + "AccessPointRemoved", + nmDBusHelper, SLOT(slotAccessPointRemoved( QDBusObjectPath )))) { + allOk = true; + } + + + if(!dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_DEVICE_WIRELESS, + "PropertiesChanged", + nmDBusHelper,SLOT(slotPropertiesChanged( QMap)))) { + allOk = true; + } + + return allOk; +} + +QDBusInterface *QNetworkManagerInterfaceDeviceWireless::connectionInterface() const +{ + return d->connectionInterface; +} + +QList QNetworkManagerInterfaceDeviceWireless::getAccessPoints() +{ + QDBusReply > reply = d->connectionInterface->call("GetAccessPoints"); + return reply.value(); +} + +QString QNetworkManagerInterfaceDeviceWireless::hwAddress() const +{ + return d->connectionInterface->property("HwAddress").toString(); +} + +quint32 QNetworkManagerInterfaceDeviceWireless::mode() const +{ + return d->connectionInterface->property("Mode").toUInt(); +} + +quint32 QNetworkManagerInterfaceDeviceWireless::bitrate() const +{ + return d->connectionInterface->property("Bitrate").toUInt(); +} + +QDBusObjectPath QNetworkManagerInterfaceDeviceWireless::activeAccessPoint() const +{ + return d->connectionInterface->property("ActiveAccessPoint").value(); +} + +quint32 QNetworkManagerInterfaceDeviceWireless::wirelessCapabilities() const +{ + return d->connectionInterface->property("WirelelessCapabilities").toUInt(); +} + +///////////// +class QNetworkManagerSettingsPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerSettings::QNetworkManagerSettings(const QString &settingsService, QObject *parent) + : QObject(parent) +{ +// qWarning() << __PRETTY_FUNCTION__; + d = new QNetworkManagerSettingsPrivate(); + d->path = settingsService; + d->connectionInterface = new QDBusInterface(settingsService, + NM_DBUS_PATH_SETTINGS, + NM_DBUS_IFACE_SETTINGS, + dbusConnection); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find NetworkManagerSettings"; + return; + } + d->valid = true; +} + +QNetworkManagerSettings::~QNetworkManagerSettings() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerSettings::isValid() +{ + return d->valid; +} + +bool QNetworkManagerSettings::setConnections() +{ + bool allOk = false; + + if (!dbusConnection.connect(d->path, NM_DBUS_PATH_SETTINGS, + NM_DBUS_IFACE_SETTINGS, "NewConnection", + this, SIGNAL(newConnection(QDBusObjectPath)))) { + allOk = true; + } + + return allOk; +} + +QList QNetworkManagerSettings::listConnections() +{ + QDBusReply > reply = d->connectionInterface->call("ListConnections"); + return reply.value(); +} + +QDBusInterface *QNetworkManagerSettings::connectionInterface() const +{ + return d->connectionInterface; +} + + +///////////// +class QNetworkManagerSettingsConnectionPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + QString service; + QNmSettingsMap settingsMap; + bool valid; +}; + +QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent) +{ + qDBusRegisterMetaType(); + d = new QNetworkManagerSettingsConnectionPrivate(); + d->path = connectionObjectPath; + d->service = settingsService; + d->connectionInterface = new QDBusInterface(settingsService, + d->path, + NM_DBUS_IFACE_SETTINGS_CONNECTION, + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + qWarning() << "Could not find NetworkManagerSettingsConnection"; + d->valid = false; + return; + } + d->valid = true; + QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call("GetSettings"); + d->settingsMap = rep.value(); +} + +QNetworkManagerSettingsConnection::~QNetworkManagerSettingsConnection() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerSettingsConnection::isValid() +{ + return d->valid; +} + +bool QNetworkManagerSettingsConnection::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + if(!dbusConnection.connect(d->service, d->path, + NM_DBUS_IFACE_SETTINGS_CONNECTION, "NewConnection", + this, SIGNAL(updated(QNmSettingsMap)))) { + allOk = true; + } + + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForSettingsRemoved(const QString &)), + this,SIGNAL(removed( const QString &))); + + if (!dbusConnection.connect(d->service, d->path, + NM_DBUS_IFACE_SETTINGS_CONNECTION, "Removed", + nmDBusHelper, SIGNAL(slotSettingsRemoved()))) { + allOk = true; + } + + return allOk; +} +//QNetworkManagerSettingsConnection::update(QNmSettingsMap map) +//{ +// d->connectionInterface->call("Update", QVariant::fromValue(map)); +//} + +QDBusInterface *QNetworkManagerSettingsConnection::connectionInterface() const +{ + return d->connectionInterface; +} + +QNmSettingsMap QNetworkManagerSettingsConnection::getSettings() +{ + QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call("GetSettings"); + d->settingsMap = rep.value(); + return d->settingsMap; +} + +NMDeviceType QNetworkManagerSettingsConnection::getType() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); + while (i != d->settingsMap.end() && i.key() == "connection") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("type"); + while (ii != innerMap.end() && ii.key() == "type") { + QString devType = ii.value().toString(); + if (devType == "802-3-ethernet") { + return DEVICE_TYPE_802_3_ETHERNET; + } + if (devType == "802-11-wireless") { + return DEVICE_TYPE_802_11_WIRELESS; + } + ii++; + } + i++; + } + return DEVICE_TYPE_UNKNOWN; +} + +bool QNetworkManagerSettingsConnection::isAutoConnect() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); + while (i != d->settingsMap.end() && i.key() == "connection") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("autoconnect"); + while (ii != innerMap.end() && ii.key() == "autoconnect") { + return ii.value().toBool(); + ii++; + } + i++; + } + return true; //default networkmanager is autoconnect +} + +quint64 QNetworkManagerSettingsConnection::getTimestamp() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); + while (i != d->settingsMap.end() && i.key() == "connection") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("timestamp"); + while (ii != innerMap.end() && ii.key() == "timestamp") { + return ii.value().toUInt(); + ii++; + } + i++; + } + return 0; +} + +QString QNetworkManagerSettingsConnection::getId() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); + while (i != d->settingsMap.end() && i.key() == "connection") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("id"); + while (ii != innerMap.end() && ii.key() == "id") { + return ii.value().toString(); + ii++; + } + i++; + } + return QString(); +} + +QString QNetworkManagerSettingsConnection::getUuid() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); + while (i != d->settingsMap.end() && i.key() == "connection") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("uuid"); + while (ii != innerMap.end() && ii.key() == "uuid") { + return ii.value().toString(); + ii++; + } + i++; + } + // is no uuid, return the connection path + return d->connectionInterface->path(); +} + +QString QNetworkManagerSettingsConnection::getSsid() +{ + QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless"); + while (i != d->settingsMap.end() && i.key() == "802-11-wireless") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("ssid"); + while (ii != innerMap.end() && ii.key() == "ssid") { + return ii.value().toString(); + ii++; + } + i++; + } + return QString(); +} + +QString QNetworkManagerSettingsConnection::getMacAddress() +{ + if(getType() == DEVICE_TYPE_802_3_ETHERNET) { + QNmSettingsMap::const_iterator i = d->settingsMap.find("802-3-ethernet"); + while (i != d->settingsMap.end() && i.key() == "802-3-ethernet") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("mac-address"); + while (ii != innerMap.end() && ii.key() == "mac-address") { + return ii.value().toString(); + ii++; + } + i++; + } + } + + else if(getType() == DEVICE_TYPE_802_11_WIRELESS) { + QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless"); + while (i != d->settingsMap.end() && i.key() == "802-11-wireless") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("mac-address"); + while (ii != innerMap.end() && ii.key() == "mac-address") { + return ii.value().toString(); + ii++; + } + i++; + } + } + return QString(); +} + +QStringList QNetworkManagerSettingsConnection::getSeenBssids() +{ + if(getType() == DEVICE_TYPE_802_11_WIRELESS) { + QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless"); + while (i != d->settingsMap.end() && i.key() == "802-11-wireless") { + QMap innerMap = i.value(); + QMap::const_iterator ii = innerMap.find("seen-bssids"); + while (ii != innerMap.end() && ii.key() == "seen-bssids") { + return ii.value().toStringList(); + ii++; + } + i++; + } + } + return QStringList(); +} + +///////////// +class QNetworkManagerConnectionActivePrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerConnectionActive::QNetworkManagerConnectionActive( const QString &activeConnectionObjectPath, QObject *parent) +{ + d = new QNetworkManagerConnectionActivePrivate(); + d->path = activeConnectionObjectPath; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find NetworkManagerSettingsConnection"; + return; + } + d->valid = true; +} + +QNetworkManagerConnectionActive::~QNetworkManagerConnectionActive() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerConnectionActive::isValid() +{ + return d->valid; +} + +bool QNetworkManagerConnectionActive::setConnections() +{ + if(!isValid() ) + return false; + + bool allOk = false; + nmDBusHelper = new QNmDBusHelper; + connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap)), + this,SIGNAL(propertiesChanged( const QString &, QMap))); + if(dbusConnection.connect(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + "PropertiesChanged", + nmDBusHelper,SLOT(slotPropertiesChanged( QMap))) ) { + allOk = true; + } + + return allOk; +} + +QDBusInterface *QNetworkManagerConnectionActive::connectionInterface() const +{ + return d->connectionInterface; +} + +QString QNetworkManagerConnectionActive::serviceName() const +{ + return d->connectionInterface->property("ServiceName").toString(); +} + +QDBusObjectPath QNetworkManagerConnectionActive::connection() const +{ + QVariant prop = d->connectionInterface->property("Connection"); + return prop.value(); +} + +QDBusObjectPath QNetworkManagerConnectionActive::specificObject() const +{ + QVariant prop = d->connectionInterface->property("SpecificObject"); + return prop.value(); +} + +QList QNetworkManagerConnectionActive::devices() const +{ + QVariant prop = d->connectionInterface->property("Devices"); + return prop.value >(); +} + +quint32 QNetworkManagerConnectionActive::state() const +{ + return d->connectionInterface->property("State").toUInt(); +} + +bool QNetworkManagerConnectionActive::defaultRoute() const +{ + return d->connectionInterface->property("Default").toBool(); +} + + +//// +class QNetworkManagerIp4ConfigPrivate +{ +public: + QDBusInterface *connectionInterface; + QString path; + bool valid; +}; + +QNetworkManagerIp4Config::QNetworkManagerIp4Config( const QString &deviceObjectPath, QObject *parent) +{ + d = new QNetworkManagerIp4ConfigPrivate(); + d->path = deviceObjectPath; + d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->path, + NM_DBUS_INTERFACE_IP4_CONFIG, + dbusConnection, parent); + if (!d->connectionInterface->isValid()) { + d->valid = false; + qWarning() << "Could not find NetworkManagerIp4Config"; + return; + } + d->valid = true; +} + +QNetworkManagerIp4Config::~QNetworkManagerIp4Config() +{ + delete d->connectionInterface; + delete d; +} + +bool QNetworkManagerIp4Config::isValid() +{ + return d->valid; +} + +QStringList QNetworkManagerIp4Config::domains() const +{ + return d->connectionInterface->property("Domains").toStringList(); +} + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h new file mode 100644 index 0000000..8bed45b --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h @@ -0,0 +1,397 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKMANAGERSERVICE_H +#define QNETWORKMANAGERSERVICE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include +#include +#include +#include +#include +#include +#include + + +#include +#include "qnmdbushelper.h" + +QT_BEGIN_NAMESPACE + +typedef QMap< QString, QMap > QNmSettingsMap; +typedef QList ServerThing; + +Q_DECLARE_METATYPE(QNmSettingsMap) +Q_DECLARE_METATYPE(ServerThing) + +class QNetworkManagerInterfacePrivate; +class QNetworkManagerInterface : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerInterface(QObject *parent = 0); + ~QNetworkManagerInterface(); + + QList getDevices() const; + void activateConnection(const QString &serviceName, QDBusObjectPath connection, QDBusObjectPath device, QDBusObjectPath specificObject); + void deactivateConnection(QDBusObjectPath connectionPath) const; + + QDBusObjectPath path() const; + QDBusInterface *connectionInterface() const; + + bool wirelessEnabled() const; + bool wirelessHardwareEnabled() const; + QList activeConnections() const; + quint32 state(); + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void deviceAdded(QDBusObjectPath); + void deviceRemoved(QDBusObjectPath); + void propertiesChanged( const QString &, QMap); + void stateChanged(const QString&, quint32); + void activationFinished(QDBusPendingCallWatcher*); + +private Q_SLOTS: +private: +// Q_DISABLE_COPY(QNetworkManagerInterface); ?? + QNetworkManagerInterfacePrivate *d; + QNmDBusHelper *nmDBusHelper; +}; //end QNetworkManagerInterface + +//////// +class QNetworkManagerInterfaceAccessPointPrivate; +class QNetworkManagerInterfaceAccessPoint : public QObject +{ + Q_OBJECT + +public: + + // NM_DEVICE_STATE + enum DeviceState { + Unknown = 0, + Unmanaged, + Unavailable, + Disconnected, + Prepare, + Config, + NeedAuthentication, + IpConfig, + Activated, + Failed + }; + + enum ApFlag { + ApNone = 0x0, + Privacy = 0x1 + }; + + Q_DECLARE_FLAGS(ApFlags, ApFlag); + + enum ApSecurityFlag { + ApSecurityNone = 0x0, + PairWep40 = 0x1, + PairWep104 = 0x2, + PairTkip = 0x4, + PairCcmp = 0x8, + GroupWep40 = 0x10, + GroupWep104 = 0x20, + GroupTkip = 0x40, + GroupCcmp = 0x80, + KeyPsk = 0x100, + Key8021x = 0x200 + }; + + Q_DECLARE_FLAGS(ApSecurityFlags, ApSecurityFlag); + + QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent = 0); + ~QNetworkManagerInterfaceAccessPoint(); + + QDBusInterface *connectionInterface() const; + + quint32 flags() const; + quint32 wpaFlags() const; + quint32 rsnFlags() const; + QString ssid() const; + quint32 frequency() const; + QString hwAddress() const; + quint32 mode() const; + quint32 maxBitrate() const; + quint32 strength() const; + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void propertiesChanged(QMap ); + void propertiesChanged( const QString &, QMap); +private: + QNetworkManagerInterfaceAccessPointPrivate *d; + QNmDBusHelper *nmDBusHelper; + +}; //end QNetworkManagerInterfaceAccessPoint + +//////// +class QNetworkManagerInterfaceDevicePrivate; +class QNetworkManagerInterfaceDevice : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerInterfaceDevice(const QString &deviceObjectPath, QObject *parent = 0); + ~QNetworkManagerInterfaceDevice(); + + QString udi() const; + QNetworkInterface interface() const; + QDBusInterface *connectionInterface() const; + quint32 ip4Address() const; + quint32 state() const; + quint32 deviceType() const; + + QDBusObjectPath ip4config() const; + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void stateChanged(const QString &, quint32); + +private: + QNetworkManagerInterfaceDevicePrivate *d; + QNmDBusHelper *nmDBusHelper; +}; //end QNetworkManagerInterfaceDevice + +//////// +class QNetworkManagerInterfaceDeviceWiredPrivate; +class QNetworkManagerInterfaceDeviceWired : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerInterfaceDeviceWired(const QString &ifaceDevicePath, QObject *parent = 0); + ~QNetworkManagerInterfaceDeviceWired(); + + QDBusInterface *connectionInterface() const; + QString hwAddress() const; + quint32 speed() const; + bool carrier() const; + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void propertiesChanged( const QString &, QMap); +private: + QNetworkManagerInterfaceDeviceWiredPrivate *d; + QNmDBusHelper *nmDBusHelper; +}; // end QNetworkManagerInterfaceDeviceWired + +//// +class QNetworkManagerInterfaceDeviceWirelessPrivate; +class QNetworkManagerInterfaceDeviceWireless : public QObject +{ + Q_OBJECT + +public: + + enum DeviceCapability { + None = 0x0, + Wep40 = 0x1, + Wep104 = 0x2, + Tkip = 0x4, + Ccmp = 0x8, + Wpa = 0x10, + Rsn = 0x20 + }; + + QNetworkManagerInterfaceDeviceWireless(const QString &ifaceDevicePath, QObject *parent = 0); + ~QNetworkManagerInterfaceDeviceWireless(); + + QDBusObjectPath path() const; + QList getAccessPoints(); + QDBusInterface *connectionInterface() const; + + QString hwAddress() const; + quint32 mode() const; + quint32 bitrate() const; + QDBusObjectPath activeAccessPoint() const; + quint32 wirelessCapabilities() const; + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void propertiesChanged( const QString &, QMap); + void accessPointAdded(const QString &,QDBusObjectPath); + void accessPointRemoved(const QString &,QDBusObjectPath); +private: + QNetworkManagerInterfaceDeviceWirelessPrivate *d; + QNmDBusHelper *nmDBusHelper; +}; // end QNetworkManagerInterfaceDeviceWireless + +//// +class QNetworkManagerSettingsPrivate; +class QNetworkManagerSettings : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerSettings(const QString &settingsService, QObject *parent = 0); + ~QNetworkManagerSettings(); + + QDBusInterface *connectionInterface() const; + QList listConnections(); + bool setConnections(); + bool isValid(); + +Q_SIGNALS: + void newConnection(QDBusObjectPath); +private: + QNetworkManagerSettingsPrivate *d; +}; //end QNetworkManagerSettings + +//// +class QNetworkManagerSettingsConnectionPrivate; +class QNetworkManagerSettingsConnection : public QObject +{ + Q_OBJECT + +public: + + QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent = 0); + ~QNetworkManagerSettingsConnection(); + + QDBusInterface *connectionInterface() const; + QNmSettingsMap getSettings(); + // void update(QNmSettingsMap map); + bool setConnections(); + NMDeviceType getType(); + bool isAutoConnect(); + quint64 getTimestamp(); + QString getId(); + QString getUuid(); + QString getSsid(); + QString getMacAddress(); + QStringList getSeenBssids(); + bool isValid(); + +Q_SIGNALS: + + void updated(QMap< QString, QMap > s); + void removed(const QString &); + +private: + QNmDBusHelper *nmDBusHelper; + QNetworkManagerSettingsConnectionPrivate *d; +}; //end QNetworkManagerSettingsConnection + +//// +class QNetworkManagerConnectionActivePrivate; +class QNetworkManagerConnectionActive : public QObject +{ + Q_OBJECT + +public: + + enum ActiveConnectionState { + Unknown = 0, + Activating = 1, + Activated = 2 + }; + + QNetworkManagerConnectionActive(const QString &dbusPathName, QObject *parent = 0); + ~ QNetworkManagerConnectionActive(); + + QDBusInterface *connectionInterface() const; + QString serviceName() const; + QDBusObjectPath connection() const; + QDBusObjectPath specificObject() const; + QList devices() const; + quint32 state() const; + bool defaultRoute() const; + bool setConnections(); + bool isValid(); + + +Q_SIGNALS: + void propertiesChanged(QList); + void propertiesChanged( const QString &, QMap); +private: + QNetworkManagerConnectionActivePrivate *d; + QNmDBusHelper *nmDBusHelper; +}; //QNetworkManagerConnectionActive + +//// +class QNetworkManagerIp4ConfigPrivate; +class QNetworkManagerIp4Config : public QObject +{ + Q_OBJECT + +public: + QNetworkManagerIp4Config(const QString &dbusPathName, QObject *parent = 0); + ~QNetworkManagerIp4Config(); + + // QList nameservers(); + QStringList domains() const; + bool isValid(); + + private: + QNetworkManagerIp4ConfigPrivate *d; +}; +//// + +QT_END_NAMESPACE + +#endif //QNETWORKMANAGERSERVICE_H diff --git a/src/plugins/bearer/networkmanager/qnmdbushelper.cpp b/src/plugins/bearer/networkmanager/qnmdbushelper.cpp new file mode 100644 index 0000000..1d16e55 --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnmdbushelper.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// this class is for helping qdbus get stuff + +#include "qnmdbushelper.h" + +#include + +#include +#include +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +void QNmDBusHelper::deviceStateChanged(quint32 state) + { + QDBusMessage msg = this->message(); + if(state == NM_DEVICE_STATE_ACTIVATED + || state == NM_DEVICE_STATE_DISCONNECTED + || state == NM_DEVICE_STATE_UNAVAILABLE + || state == NM_DEVICE_STATE_FAILED) { + emit pathForStateChanged(msg.path(), state); + } + } + +void QNmDBusHelper::slotAccessPointAdded(QDBusObjectPath path) +{ + if(path.path().length() > 2) { + QDBusMessage msg = this->message(); + emit pathForAccessPointAdded(msg.path(), path); + } +} + +void QNmDBusHelper::slotAccessPointRemoved(QDBusObjectPath path) +{ + if(path.path().length() > 2) { + QDBusMessage msg = this->message(); + emit pathForAccessPointRemoved(msg.path(), path); + } +} + +void QNmDBusHelper::slotPropertiesChanged(QMap map) +{ + QDBusMessage msg = this->message(); + QMapIterator i(map); + while (i.hasNext()) { + i.next(); + if( i.key() == "State") { //state only applies to device interfaces + quint32 state = i.value().toUInt(); + if( state == NM_DEVICE_STATE_ACTIVATED + || state == NM_DEVICE_STATE_DISCONNECTED + || state == NM_DEVICE_STATE_UNAVAILABLE + || state == NM_DEVICE_STATE_FAILED) { + emit pathForPropertiesChanged( msg.path(), map); + } + } else if( i.key() == "ActiveAccessPoint") { + // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().value().path(); + // } else if( i.key() == "Strength") + // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().toUInt(); + // else + // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value(); + } + } +} + +void QNmDBusHelper::slotSettingsRemoved() +{ + QDBusMessage msg = this->message(); + emit pathForSettingsRemoved(msg.path()); +} + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/networkmanager/qnmdbushelper.h b/src/plugins/bearer/networkmanager/qnmdbushelper.h new file mode 100644 index 0000000..9794f98 --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnmdbushelper.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNMDBUSHELPERPRIVATE_H +#define QNMDBUSHELPERPRIVATE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +#if !defined(QT_NO_DBUS) && !defined(Q_OS_MAC) + +class QNmDBusHelper: public QObject, protected QDBusContext + { + Q_OBJECT + public: + + public slots: + void deviceStateChanged(quint32); + void slotAccessPointAdded( QDBusObjectPath ); + void slotAccessPointRemoved( QDBusObjectPath ); + void slotPropertiesChanged( QMap); + void slotSettingsRemoved(); + +Q_SIGNALS: + void pathForStateChanged(const QString &, quint32); + void pathForAccessPointAdded(const QString &, QDBusObjectPath ); + void pathForAccessPointRemoved(const QString &, QDBusObjectPath ); + void pathForPropertiesChanged(const QString &, QMap); + void pathForSettingsRemoved(const QString &); +}; +#endif + +QT_END_NAMESPACE + +#endif// QNMDBUSHELPERPRIVATE_H diff --git a/src/plugins/bearer/networkmanager/qnmwifiengine.cpp b/src/plugins/bearer/networkmanager/qnmwifiengine.cpp new file mode 100644 index 0000000..4a814ec --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnmwifiengine.cpp @@ -0,0 +1,1128 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnmwifiengine.h" + +#include +#include + +#include + +#include +#include +#include "qnetworkmanagerservice.h" + +#include + +QT_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QNmWifiEngine, nmWifiEngine) +typedef QList > QNmSettingsAddressMap; + +Q_DECLARE_METATYPE(QNmSettingsAddressMap) + +QNmWifiEngine::QNmWifiEngine(QObject *parent) +: QNetworkSessionEngine(parent) +{ + iface = new QNetworkManagerInterface(); + if(!iface->isValid()) { + return; + } + iface->setConnections(); + connect(iface,SIGNAL(deviceAdded(QDBusObjectPath)), + this,SLOT(addDevice(QDBusObjectPath))); + connect(iface,SIGNAL(deviceRemoved(QDBusObjectPath)), + this,SLOT(removeDevice(QDBusObjectPath))); + + QList list = iface->getDevices(); + + foreach(QDBusObjectPath path, list) { + addDevice(path); + } + + QStringList connectionServices; + connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; + connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; + foreach (QString service, connectionServices) { + QNetworkManagerSettings *settingsiface; + settingsiface = new QNetworkManagerSettings(service); + settingsiface->setConnections(); + connect(settingsiface,SIGNAL(newConnection(QDBusObjectPath)), + this,(SLOT(newConnection(QDBusObjectPath)))); + } + + updated = false; +} + +QNmWifiEngine::~QNmWifiEngine() +{ +} + +QString QNmWifiEngine::getNameForConfiguration(QNetworkManagerInterfaceDevice *devIface) +{ + QString newname; + if (devIface->state() == NM_DEVICE_STATE_ACTIVATED) { + QString path = devIface->ip4config().path(); + QNetworkManagerIp4Config * ipIface; + ipIface = new QNetworkManagerIp4Config(path); + newname = ipIface->domains().join(" "); + } + //fallback to interface name + if(newname.isEmpty()) + newname = devIface->interface().name(); + return newname; +} + + +QList QNmWifiEngine::getConfigurations(bool *ok) +{ +// qWarning() << Q_FUNC_INFO << updated; + if (ok) + *ok = false; + + if(!updated) { + foundConfigurations.clear(); + if(knownSsids.isEmpty()) + getKnownSsids(); // list of ssids that have user configurations. + + scanForAccessPoints(); + getActiveConnectionsPaths(); + knownConnections(); + + accessPointConnections(); + +// findConnections(); + //add access points + updated = true; + } + return foundConfigurations; +} + +void QNmWifiEngine::findConnections() +{ + QList list = iface->getDevices(); + + foreach(QDBusObjectPath path, list) { + QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); + + //// eth + switch (devIface->deviceType()) { +// qWarning() << devIface->connectionInterface()->path(); + + case DEVICE_TYPE_802_3_ETHERNET: + { + QString ident; + QNetworkManagerInterfaceDeviceWired *devWiredIface; + devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); + + ident = devWiredIface->hwAddress(); + + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + cpPriv->name = getNameForConfiguration(devIface); + cpPriv->isValid = true; + cpPriv->id = ident; + cpPriv->internet = devWiredIface->carrier(); + + cpPriv->serviceInterface = devIface->interface(); + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + switch (devIface->state()) { + case NM_DEVICE_STATE_UNKNOWN: + case NM_DEVICE_STATE_UNMANAGED: + case NM_DEVICE_STATE_FAILED: + cpPriv->state = (cpPriv->state | QNetworkConfiguration::Undefined); + break; + case NM_DEVICE_STATE_UNAVAILABLE: + cpPriv->state = (cpPriv->state | QNetworkConfiguration::Defined); + break; + case NM_DEVICE_STATE_PREPARE: + case NM_DEVICE_STATE_CONFIG: + case NM_DEVICE_STATE_NEED_AUTH: + case NM_DEVICE_STATE_IP_CONFIG: + case NM_DEVICE_STATE_DISCONNECTED: + { + cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Discovered + | QNetworkConfiguration::Defined); + } + break; + case NM_DEVICE_STATE_ACTIVATED: + cpPriv->state = (cpPriv->state | QNetworkConfiguration::Active ); + break; + default: + cpPriv->state = (cpPriv->state | QNetworkConfiguration::Undefined); + break; + }; + cpPriv->purpose = QNetworkConfiguration::PublicPurpose; + foundConfigurations.append(cpPriv); + configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); + } + break; + case DEVICE_TYPE_802_11_WIRELESS: + { +// QNetworkManagerInterfaceDeviceWireless *devWirelessIface; +// devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); +// +// //// connections +// QStringList connectionServices; +// connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; +// connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; +// +// QString connPath; +// +// foreach (QString service, connectionServices) { +// QString ident; +// QNetworkManagerSettings *settingsiface; +// settingsiface = new QNetworkManagerSettings(service); +// QList list = settingsiface->listConnections(); +// +// foreach(QDBusObjectPath path, list) { //for each connection path +//qWarning() << path.path(); +// ident = path.path(); +// bool addIt = false; +// QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); +// cpPriv->isValid = true; +// cpPriv->id = ident; +// cpPriv->internet = true; +// +// cpPriv->type = QNetworkConfiguration::InternetAccessPoint; +// cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Discovered +// | QNetworkConfiguration::Defined); +// cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; +// +// QNetworkManagerSettingsConnection *sysIface; +// sysIface = new QNetworkManagerSettingsConnection(service, path.path()); +// cpPriv->name = sysIface->getId();//ii.value().toString(); +//qWarning() << cpPriv->name; +// if(sysIface->getType() == DEVICE_TYPE_802_3_ETHERNET/*type == "802-3-ethernet"*/ +// && devIface->deviceType() == DEVICE_TYPE_802_3_ETHERNET) { +// cpPriv->serviceInterface = devIface->interface(); +// addIt = true; +// } else if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS/*type == "802-11-wireless"*/ +// && devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { +// cpPriv->serviceInterface = devIface->interface(); +// addIt = true; +// // get the wifi interface state first.. do we need this? +// // QString activeAPPath = devWirelessIface->activeAccessPoint().path(); +// } +// +// //#if 0 +// foreach(QString conpath, activeConnectionPaths) { +// QNetworkManagerConnectionActive *aConn; +// aConn = new QNetworkManagerConnectionActive(conpath); +// // in case of accesspoint, specificObject will hold the accessPOintObjectPath +// // qWarning() << aConn->connection().path() << aConn->specificObject().path() << aConn->devices().count(); +// if( aConn->connection().path() == ident) { +// +// QList devs = aConn->devices(); +// foreach(QDBusObjectPath device, devs) { +// QNetworkManagerInterfaceDevice *ifaceDevice; +// ifaceDevice = new QNetworkManagerInterfaceDevice(device.path()); +// cpPriv->serviceInterface = ifaceDevice->interface(); +// cpPriv->state = getStateFlag(ifaceDevice->state()); +// //cpPriv->accessPoint = aConn->specificObject().path(); +// +// break; +// } +// } +// } +// //#endif +// // } //end while connection +// if(addIt) { +// foundConfigurations.append(cpPriv); +// configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); +// } +// } +// } //end each connection service +// +// // ////////////// AccessPoints +//// QList apList = devWirelessIface->getAccessPoints(); +////// qWarning() << apList.count(); +//// foreach(QDBusObjectPath path, apList) { +//// QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); +//// cpPriv = addAccessPoint( devIface->connectionInterface()->path(), path); +//// if(cpPriv->isValid) { +//// foundConfigurations.append(cpPriv); +//// } +//// } + } // end DEVICE_TYPE_802_11_WIRELESS + break; + }; + } //end foreach device +} + +void QNmWifiEngine::knownConnections() +{ +// qWarning() << Q_FUNC_INFO; + //// connections + QStringList connectionServices; + connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; + connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; + + QString connPath; + + foreach (QString service, connectionServices) { + QString ident; + QNetworkManagerSettings *settingsiface; + settingsiface = new QNetworkManagerSettings(service); + QList list = settingsiface->listConnections(); + +// qWarning() <setConnections(); + connect(sysIface, SIGNAL(removed(QString)), + this,SLOT(settingsConnectionRemoved(QString))); + + cpPriv->name = sysIface->getId(); + cpPriv->isValid = true; + cpPriv->id = sysIface->getUuid(); +// cpPriv->id = ident; + cpPriv->internet = true; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; +//qWarning() << cpPriv->name; + cpPriv->state = getStateForId(cpPriv->id); + + cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; + + if(sysIface->getType() == DEVICE_TYPE_802_3_ETHERNET) { + QString mac = sysIface->getMacAddress(); + if(!mac.length() > 2) { + qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXX" << mac << "type ethernet"; + QString devPath; + devPath = deviceConnectionPath(mac); + + // qWarning() << Q_FUNC_INFO << devPath; + QNetworkManagerInterfaceDevice *devIface; + devIface = new QNetworkManagerInterfaceDevice(devPath); + cpPriv->serviceInterface = devIface->interface(); + QNetworkManagerInterfaceDeviceWired *devWiredIface; + devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); + cpPriv->internet = devWiredIface->carrier(); + + // use this mac addy + } else { + cpPriv->serviceInterface = getBestInterface( DEVICE_TYPE_802_3_ETHERNET, cpPriv->id); + } + + cpPriv->internet = true;//sysIface->isAutoConnect(); + + addIt = true; + } else if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) { + QString mac = sysIface->getMacAddress();; + if(!mac.length() > 2) { + qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXX" << mac << "type wireless"; + QString devPath; + devPath = deviceConnectionPath(mac); +// qWarning() << Q_FUNC_INFO << devPath; + + QNetworkManagerInterfaceDevice *devIface; + devIface = new QNetworkManagerInterfaceDevice(devPath); + cpPriv->serviceInterface = devIface->interface(); + // use this mac addy + } else { + cpPriv->serviceInterface = getBestInterface( DEVICE_TYPE_802_11_WIRELESS, cpPriv->id); + } + // cpPriv->serviceInterface = devIface->interface(); + addIt = true; + // get the wifi interface state first.. do we need this? + // QString activeAPPath = devWirelessIface->activeAccessPoint().path(); + } + if(addIt) { + foundConfigurations.append(cpPriv); + configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); + } + } //end each connection service + } +} + +void QNmWifiEngine::accessPointConnections() +{ + //qWarning() << Q_FUNC_INFO; + QList list = iface->getDevices(); + foreach(QDBusObjectPath path, list) { + QNetworkManagerInterfaceDevice *devIface; + devIface = new QNetworkManagerInterfaceDevice(path.path()); + if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { + QList apList = availableAccessPoints.uniqueKeys(); + + QList::const_iterator i; + for (i = apList.constBegin(); i != apList.constEnd(); ++i) { + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + cpPriv = addAccessPoint( devIface->connectionInterface()->path(), availableAccessPoints[*i]); + if(cpPriv->isValid) { + foundConfigurations.append(cpPriv); + // qWarning() << "adding" << cpPriv->name << "to things"; + configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); + } + } + } + } +} + +QString QNmWifiEngine::getInterfaceFromId(const QString &id) +{ + return configurationInterface.value(id); +} + +bool QNmWifiEngine::hasIdentifier(const QString &id) +{ + if (configurationInterface.contains(id)) + return true; + foreach (QNetworkConfigurationPrivate *cpPriv, getConfigurations()) { + if (cpPriv->id == id) + return true; + } + return false; +} + +QString QNmWifiEngine::bearerName(const QString &id) +{ + QString interface = getInterfaceFromId(id); + + QList list = iface->getDevices(); + foreach(QDBusObjectPath path, list) { + QNetworkManagerInterfaceDevice *devIface; + devIface = new QNetworkManagerInterfaceDevice(path.path()); + if(interface == devIface->interface().name()) { + switch(devIface->deviceType()) { + case DEVICE_TYPE_802_3_ETHERNET/*NM_DEVICE_TYPE_ETHERNET*/: + return QLatin1String("Ethernet"); + break; + case DEVICE_TYPE_802_11_WIRELESS/*NM_DEVICE_TYPE_WIFI*/: + return QLatin1String("WLAN"); + break; + case DEVICE_TYPE_GSM/*NM_DEVICE_TYPE_GSM*/: + return QLatin1String("2G"); + break; + case DEVICE_TYPE_CDMA/*NM_DEVICE_TYPE_CDMA*/: + return QLatin1String("CDMA2000"); + break; + default: + break; + }; + } + } + return QString(); +} + +void QNmWifiEngine::connectToId(const QString &id) +{ +// qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << __FUNCTION__ << id; + activatingConnectionPath = id; + QStringList connectionSettings = getConnectionPathForId(id); + if(connectionSettings.isEmpty()) { + emit connectionError(id, OperationNotSupported); + return; + } + + QDBusObjectPath connectionPath(connectionSettings.at(1)); + QString interface = getInterfaceFromId(id); + + interface = QNetworkInterface::interfaceFromName(interface).hardwareAddress().toLower(); + QString devPath; + devPath = deviceConnectionPath(interface); + QDBusObjectPath devicePath(devPath); + + iface = new QNetworkManagerInterface(); + iface->activateConnection( + connectionSettings.at(0), + connectionPath, + devicePath, + connectionPath); + + connect(iface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)), + this, SLOT(slotActivationFinished(QDBusPendingCallWatcher*))); +} + +void QNmWifiEngine::disconnectFromId(const QString &id) +{ + QString activeConnectionPath = getActiveConnectionPath(id); + //qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << __FUNCTION__ << id << activeConnectionPath ; + + if (!activeConnectionPath.isEmpty()) { + QNetworkManagerConnectionActive *activeCon; + activeCon = new QNetworkManagerConnectionActive(activeConnectionPath); + QNetworkManagerSettingsConnection *settingsCon; + settingsCon = new QNetworkManagerSettingsConnection(activeCon->serviceName(), activeCon->connection().path()); + + if(settingsCon->isAutoConnect()) { +// qWarning() << id << "is autoconnect"; + emit connectionError(id, OperationNotSupported); + //unsupported + } else { +// qWarning() <deactivateConnection(dbpath); + activatingConnectionPath = ""; + } + } +} + +void QNmWifiEngine::requestUpdate() +{ + updated = false; + knownSsids.clear(); + availableAccessPoints.clear(); + emitConfigurationsChanged(); +} + +QNmWifiEngine *QNmWifiEngine::instance() +{ + QDBusConnection dbusConnection = QDBusConnection::systemBus(); + if (dbusConnection.isConnected()) { + QDBusConnectionInterface *dbiface = dbusConnection.interface(); + QDBusReply reply = dbiface->isServiceRegistered("org.freedesktop.NetworkManager"); + if (reply.isValid() && reply.value()) + return nmWifiEngine(); + } + + return 0; +} + +void QNmWifiEngine::getKnownSsids() +{ + QStringList connectionServices; + connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; + connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; +//qWarning() << Q_FUNC_INFO; + foreach (QString service, connectionServices) { + QNetworkManagerSettings *settingsiface; + settingsiface = new QNetworkManagerSettings(service); + QList list = settingsiface->listConnections(); + foreach(QDBusObjectPath path, list) { + QNetworkManagerSettingsConnection *sysIface; + sysIface = new QNetworkManagerSettingsConnection(service, path.path()); +// qWarning() << sysIface->getSsid(); + knownSsids << sysIface->getSsid(); + } + } +} + +void QNmWifiEngine::getActiveConnectionsPaths() +{ +// qWarning() << Q_FUNC_INFO; + QNetworkManagerInterface *dbIface; + activeConnectionPaths.clear(); + dbIface = new QNetworkManagerInterface; + QList connections = dbIface->activeConnections(); + + foreach(QDBusObjectPath conpath, connections) { + activeConnectionPaths << conpath.path(); +// qWarning() << __FUNCTION__ << conpath.path() << activeConnectionPaths.count(); + + QNetworkManagerConnectionActive *activeConn; + activeConn = new QNetworkManagerConnectionActive(conpath.path()); + +// qWarning() << activeConn->connection().path() /*<< activeConn->specificObject().path() */<< activeConn->devices()[0].path(); + + } +} + +QNetworkConfigurationPrivate * QNmWifiEngine::addAccessPoint( const QString &iPath, QDBusObjectPath path) +{ //foreach accessPoint + //qWarning() << Q_FUNC_INFO << iPath << path.path(); + + QNetworkManagerInterfaceDevice *devIface; + devIface = new QNetworkManagerInterfaceDevice(iPath); + QNetworkManagerInterfaceDeviceWireless *devWirelessIface; + devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(iPath); + + QString activeAPPath = devWirelessIface->activeAccessPoint().path(); + + QNetworkManagerInterfaceAccessPoint *accessPointIface; + accessPointIface = new QNetworkManagerInterfaceAccessPoint(path.path()); + + QString ident = accessPointIface->connectionInterface()->path(); + quint32 nmState = devIface->state(); + + QString ssid = accessPointIface->ssid(); + QString hwAddy = accessPointIface->hwAddress(); + QString sInterface = devIface->interface().name(); + + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + bool addIt = true; + //qWarning() << availableAccessPoints.count() << ssid; + +// if(availableAccessPoints.contains(ssid)) { +// addIt = false; +// +// } +// foreach (QNetworkConfigurationPrivate *cpPriv, foundConfigurations) { +// if (cpPriv->name == ssid) { //weed out duplicate ssid's ?? +// addIt = false; +// break; +// } +// } + + if(addIt) { + + cpPriv->name = ssid; + cpPriv->isValid = true; + cpPriv->id = ident; + cpPriv->internet = true; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->serviceInterface = devIface->interface(); + + //qWarning() <<__FUNCTION__ << ssid; + + cpPriv->state = getAPState(nmState, knownSsids.contains(cpPriv->name)); + + if(activeAPPath == accessPointIface->connectionInterface()->path()) { + cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Active); + } + if(accessPointIface->flags() == NM_802_11_AP_FLAGS_PRIVACY) + cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; + else + cpPriv->purpose = QNetworkConfiguration::PublicPurpose; + return cpPriv; + } else { + cpPriv->isValid = false; + } + return cpPriv; +} + + + QNetworkConfiguration::StateFlags QNmWifiEngine::getAPState(qint32 nmState, bool isKnown) +{ + QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; +//qWarning() << nmState << knownSsids; + // this is the state of the wifi device interface + if(isKnown) + state = ( QNetworkConfiguration::Defined); + + switch(nmState) { //device interface state, not AP state + case NM_DEVICE_STATE_UNKNOWN: + case NM_DEVICE_STATE_UNMANAGED: + case NM_DEVICE_STATE_UNAVAILABLE: + state = (QNetworkConfiguration::Undefined); + break; + case NM_DEVICE_STATE_DISCONNECTED: + { + if(isKnown) + state = ( state | QNetworkConfiguration::Discovered); + } + break; + case NM_DEVICE_STATE_PREPARE: + case NM_DEVICE_STATE_CONFIG: + case NM_DEVICE_STATE_NEED_AUTH: + case NM_DEVICE_STATE_IP_CONFIG: + if(isKnown) + state = ( state | QNetworkConfiguration::Discovered); + break; + case NM_DEVICE_STATE_ACTIVATED: + { + if(isKnown) + state = ( state | QNetworkConfiguration::Discovered); + } + break; + }; + return state; +} + +QString QNmWifiEngine::getActiveConnectionPath(const QString &id) +{ + //qWarning() << Q_FUNC_INFO << id; + QStringList connectionSettings = getConnectionPathForId(id); + //qWarning() << Q_FUNC_INFO << id << connectionSettings.count(); + QNetworkManagerInterface * ifaceD; + ifaceD = new QNetworkManagerInterface(); + QList connections = ifaceD->activeConnections(); + foreach(QDBusObjectPath path, connections) { + QNetworkManagerConnectionActive *conDetailsD; + conDetailsD = new QNetworkManagerConnectionActive( path.path()); + if(conDetailsD->connection().path() == connectionSettings.at(1) + && conDetailsD->serviceName() == connectionSettings.at(0)) + return path.path(); + } + return QString(); +} + + QNetworkConfiguration::StateFlags QNmWifiEngine::getStateFlag(quint32 nmstate) + { +// qWarning() << Q_FUNC_INFO << nmstate; + QNetworkConfiguration::StateFlags flag; + switch (nmstate) { + case NM_DEVICE_STATE_UNKNOWN: + case NM_DEVICE_STATE_FAILED: + case NM_DEVICE_STATE_UNMANAGED: + flag = (QNetworkConfiguration::Undefined); + break; + case NM_DEVICE_STATE_PREPARE: + case NM_DEVICE_STATE_CONFIG: + case NM_DEVICE_STATE_NEED_AUTH: + case NM_DEVICE_STATE_IP_CONFIG: + case NM_DEVICE_STATE_UNAVAILABLE: + flag = (QNetworkConfiguration::Defined); + break; + case NM_DEVICE_STATE_DISCONNECTED: + flag = ( flag | QNetworkConfiguration::Discovered ); + break; + case NM_DEVICE_STATE_ACTIVATED: + { + flag = ( flag | QNetworkConfiguration::Discovered + | QNetworkConfiguration::Active ); + } + break; + default: + flag = ( QNetworkConfiguration::Defined); + break; + }; + return flag; + } + +void QNmWifiEngine::updateDeviceInterfaceState(const QString &/*path*/, quint32 nmState) +{ +// qWarning() << Q_FUNC_INFO << path << nmState; + + if(nmState == NM_DEVICE_STATE_ACTIVATED + || nmState == NM_DEVICE_STATE_DISCONNECTED + || nmState == NM_DEVICE_STATE_UNAVAILABLE + || nmState == NM_DEVICE_STATE_FAILED) { + +/* InterfaceLookupError = 0, + ConnectError, + OperationNotSupported, + DisconnectionError, +*/ +// qWarning() << Q_FUNC_INFO << ident; + QNetworkConfiguration::StateFlags state = (QNetworkConfiguration::Defined); + switch (nmState) { + case NM_DEVICE_STATE_UNKNOWN: + case NM_DEVICE_STATE_FAILED: + state = (QNetworkConfiguration::Undefined); + emit connectionError(activatingConnectionPath, ConnectError); + requestUpdate(); +// qWarning() << Q_FUNC_INFO; + break; + case NM_DEVICE_STATE_UNAVAILABLE: + state = (QNetworkConfiguration::Defined); +// emit connectionError(activatingConnectionPath, ConnectError); + requestUpdate(); + break; + case NM_DEVICE_STATE_DISCONNECTED: + state = ( state | QNetworkConfiguration::Discovered ); + requestUpdate(); + break; + case NM_DEVICE_STATE_ACTIVATED: + { + state = ( state | QNetworkConfiguration::Discovered + | QNetworkConfiguration::Active ); + requestUpdate(); + } + break; + default: + state = ( QNetworkConfiguration::Defined); + break; + }; + } +} + +void QNmWifiEngine::addDevice(QDBusObjectPath path) +{ + //qWarning() << Q_FUNC_INFO << path.path(); + QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); + devIface->setConnections(); + connect(devIface,SIGNAL(stateChanged(const QString &, quint32)), + this, SLOT(updateDeviceInterfaceState(const QString&, quint32))); + + if(!devicePaths.contains(path.path())) + devicePaths << path.path(); + + switch(devIface->deviceType()) { + case DEVICE_TYPE_802_3_ETHERNET: + { + QNetworkManagerInterfaceDeviceWired * devWiredIface; + devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); + devWiredIface->setConnections(); + connect(devWiredIface, SIGNAL(propertiesChanged(const QString &,QMap)), + this,SLOT(cmpPropertiesChanged( const QString &, QMap))); + requestUpdate(); + } + break; + case DEVICE_TYPE_802_11_WIRELESS: + { + QNetworkManagerInterfaceDeviceWireless *devWirelessIface; + devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); + devWirelessIface->setConnections(); + + connect(devWirelessIface, SIGNAL(propertiesChanged(const QString &,QMap)), + this,SLOT(cmpPropertiesChanged( const QString &, QMap))); + + connect(devWirelessIface, SIGNAL(accessPointAdded(const QString &,QDBusObjectPath)), + this,SLOT(accessPointAdded(const QString &,QDBusObjectPath))); + + connect(devWirelessIface, SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath)), + this,SLOT(accessPointRemoved(const QString &,QDBusObjectPath))); + requestUpdate(); + + } + break; + default: + break; + }; +} + +void QNmWifiEngine::removeDevice(QDBusObjectPath /*path*/) +{ +// qWarning() << Q_FUNC_INFO << path.path(); +// disconnect(devIface,SIGNAL(stateChanged(const QString &, quint32)), +// this, SLOT(updateDeviceInterfaceState(const QString&, quint32))); +// +// if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { +// // devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); +// // devWirelessIface->setConnections(); +// +// disconnect(devWirelessIface, SIGNAL(propertiesChanged(const QString &,QMap)), +// this,SIGNAL(cmpPropertiesChanged( const QString &, QMap))); +// +// disconnect(devWirelessIface, SIGNAL(accessPointAdded(const QString &,QDBusObjectPath)), +// this,SIGNAL(accessPointAdded(const QString &,QDBusObjectPath))); +// +// disconnect(devWirelessIface, SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath)), +// this,SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath))); +// +// } +} +void QNmWifiEngine::cmpPropertiesChanged(const QString &path, QMap map) +{ + QMapIterator i(map); + while (i.hasNext()) { + i.next(); +// qWarning() << Q_FUNC_INFO << path << i.key() << i.value().toUInt(); + if( i.key() == "State") { //only applies to device interfaces + updateDeviceInterfaceState(path, i.value().toUInt()); + } + if( i.key() == "ActiveAccessPoint") { + } + if( i.key() == "Carrier") { //someone got plugged in + // requestUpdate(); + } + } +} + +void QNmWifiEngine::accessPointRemoved( const QString &aPath, QDBusObjectPath /*oPath*/) +{ + //qWarning() << Q_FUNC_INFO << aPath << oPath.path(); + + if(aPath.contains("devices")) { + requestUpdate(); + } +} + +void QNmWifiEngine::accessPointAdded( const QString &aPath, QDBusObjectPath oPath) +{ + //qWarning() << Q_FUNC_INFO << aPath << oPath.path(); + + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + cpPriv = addAccessPoint( aPath, oPath); + requestUpdate(); +} + +QNetworkConfiguration::StateFlags QNmWifiEngine::getStateForId(const QString &id) +{ + //qWarning() << Q_FUNC_INFO << id; + bool isAvailable = false; + QStringList conPath = getConnectionPathForId(id); + QString aconpath = getActiveConnectionPath(id); + + //qWarning() << Q_FUNC_INFO << id << aconpath; + + if(!aconpath.isEmpty()) { + //active connection + QNetworkManagerConnectionActive *aConn; + aConn = new QNetworkManagerConnectionActive(aconpath); + + QList devs = aConn->devices(); + + foreach(QDBusObjectPath dev, devs) { + //qWarning() << "foreach" << dev.path(); + QNetworkManagerInterfaceDevice *ifaceDevice; + ifaceDevice = new QNetworkManagerInterfaceDevice(dev.path()); + + if(ifaceDevice->deviceType() == DEVICE_TYPE_802_3_ETHERNET) { + + if(isAddressOfConnection(id, ifaceDevice->ip4Address())) { + // this is it! + return getStateFlag(ifaceDevice->state()); + } else { + continue; + } + + if(ifaceDevice->state() == NM_DEVICE_STATE_UNAVAILABLE || + ifaceDevice->state() == NM_DEVICE_STATE_DISCONNECTED) { + isAvailable = true; + + QNetworkManagerInterfaceDeviceWired *devWiredIface; + devWiredIface = new QNetworkManagerInterfaceDeviceWired(ifaceDevice->connectionInterface()->path()); + if(!devWiredIface->carrier()) + return QNetworkConfiguration::Defined; + } //end eth + } else if(ifaceDevice->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { + qWarning() << "FIXME!!!!!!!!!!!!!!!!!"; + } + + return getStateFlag(ifaceDevice->state()); + } + } else { + // not active + //qWarning() << Q_FUNC_INFO << "Not active"; + QNetworkManagerSettingsConnection *sysIface; + sysIface = new QNetworkManagerSettingsConnection(conPath.at(0),conPath.at(1)); + if(sysIface->isValid()) { + if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) { + QString ssid = sysIface->getSsid(); + bool ok = false; + + if(knownSsids.contains(ssid, Qt::CaseSensitive)) { + foreach(QString onessid, knownSsids) { + // qWarning() << ssid << onessid; + if(onessid == ssid && availableAccessPoints.contains(ssid)) { + // qWarning() < devices = aConn->devices(); + foreach(QDBusObjectPath device, devices) { + QNetworkManagerInterfaceDevice *ifaceDevice; + ifaceDevice = new QNetworkManagerInterfaceDevice(device.path()); + if(ifaceDevice->ip4Address() == ipaddress) { + return true; + } + } + return false; +} + +QNetworkInterface QNmWifiEngine::getBestInterface( quint32 type, const QString &id) +{ + // check active connections first. + QStringList conIdPath = getConnectionPathForId(id); +// qWarning() << Q_FUNC_INFO << id << conIdPath; + + QNetworkInterface interface; + foreach(QString conpath, activeConnectionPaths) { + QNetworkManagerConnectionActive *aConn; + aConn = new QNetworkManagerConnectionActive(conpath); + + if(aConn->connection().path() == conIdPath.at(1) + && aConn->serviceName() == conIdPath.at(0)) { + + QList devs = aConn->devices(); + QNetworkManagerInterfaceDevice *ifaceDevice; + ifaceDevice = new QNetworkManagerInterfaceDevice(devs[0].path()); //just take the first one + interface = ifaceDevice->interface(); + return interface; + } + } + +//try guessing + QList list = iface->getDevices(); + foreach(QDBusObjectPath path, list) { + QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); + if(devIface->deviceType() == type /*&& devIface->managed()*/) { + interface = devIface->interface(); + if(devIface->state() == NM_STATE_DISCONNECTED) { + return interface; + } + } + } + return interface; +} + +quint64 QNmWifiEngine::receivedDataForId(const QString &id) const +{ + if(configurationInterface.count() > 1) + return 0; + quint64 result = 0; + + QString devFile; + devFile = configurationInterface.value(id); + QFile rx("/sys/class/net/"+devFile+"/statistics/rx_bytes"); + if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&rx); + in >> result; + rx.close(); + } + return result; +} + +quint64 QNmWifiEngine::sentDataForId(const QString &id) const +{ + if(configurationInterface.count() > 1) + return 0; + quint64 result = 0; + QString devFile; + devFile = configurationInterface.value(id); + + QFile tx("/sys/class/net/"+devFile+"/statistics/tx_bytes"); + if(tx.exists() && tx.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&tx); + in >> result; + tx.close(); + } + return result; +} + +void QNmWifiEngine::newConnection(QDBusObjectPath /*path*/) +{ + //qWarning() << Q_FUNC_INFO; + requestUpdate(); +} + +void QNmWifiEngine::settingsConnectionRemoved(const QString &/*path*/) +{ + //qWarning() << Q_FUNC_INFO; + requestUpdate(); +} + +void QNmWifiEngine::slotActivationFinished(QDBusPendingCallWatcher *openCall) +{ + QDBusPendingReply reply = *openCall; + if (reply.isError()) { + qWarning() <<"Error" << reply.error().name() << reply.error().message() + < list = iface->getDevices(); + + foreach(QDBusObjectPath path, list) { + QNetworkManagerInterfaceDevice *devIface; + devIface = new QNetworkManagerInterfaceDevice(path.path()); + + if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { + +// qWarning() << devIface->connectionInterface()->path(); + + QNetworkManagerInterfaceDeviceWireless *devWirelessIface; + devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); + ////////////// AccessPoints + QList apList = devWirelessIface->getAccessPoints(); + + foreach(QDBusObjectPath path, apList) { + QNetworkManagerInterfaceAccessPoint *accessPointIface; + accessPointIface = new QNetworkManagerInterfaceAccessPoint(path.path()); + QString ssid = accessPointIface->ssid(); + availableAccessPoints.insert(ssid, path); + } + } + } +} + +QString QNmWifiEngine::deviceConnectionPath(const QString &mac) +{ +// qWarning() << __FUNCTION__ << mac; + QString newMac = mac; + newMac = newMac.replace(":","_").toLower(); + //device object path might not contain just mac address + //might contain extra numbers on the end. thanks HAL + foreach(QString device, devicePaths) { + if(device.contains(newMac)) { + newMac = device; + break; + } + } + return newMac; +} + +QStringList QNmWifiEngine::getConnectionPathForId(const QString &uuid) +{ + QStringList connectionServices; + connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; + connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; +//qWarning() << Q_FUNC_INFO; + foreach (QString service, connectionServices) { + QNetworkManagerSettings *settingsiface; + settingsiface = new QNetworkManagerSettings(service); + QList list = settingsiface->listConnections(); + foreach(QDBusObjectPath path, list) { + QNetworkManagerSettingsConnection *sysIface; + sysIface = new QNetworkManagerSettingsConnection(service, path.path()); +// qWarning() << uuid << sysIface->getUuid(); + if(sysIface->getUuid() == uuid) { +// qWarning() <<__FUNCTION__ << service << sysIface->getId() << sysIface->connectionInterface()->path(); + return QStringList() << service << sysIface->connectionInterface()->path(); + } + } + } + return QStringList(); +} + +QT_END_NAMESPACE + diff --git a/src/plugins/bearer/networkmanager/qnmwifiengine.h b/src/plugins/bearer/networkmanager/qnmwifiengine.h new file mode 100644 index 0000000..4d514e7 --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnmwifiengine.h @@ -0,0 +1,165 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNMWIFIENGINE_P_H +#define QNMWIFIENGINE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +//#include + +#include +#include +#include + +#include "qnetworkmanagerservice.h" + +#include +#include +#include +#include + + + +QT_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; + +class QNmWifiEngine : public QNetworkSessionEngine +{ + Q_OBJECT + +public: + QNmWifiEngine(QObject *parent = 0); + ~QNmWifiEngine(); + + QList getConfigurations(bool *ok = 0); + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + static QNmWifiEngine *instance(); + + QStringList knownSsids; + inline void emitConfigurationsChanged() { emit configurationsChanged(); } + QNetworkConfigurationPrivate * addAccessPoint(const QString &, QDBusObjectPath ); + + QStringList getConnectionPathForId(const QString &uuid); + //QString getConnectionPathForId(const QString &name = QString()); + quint64 sentDataForId(const QString &id) const; + quint64 receivedDataForId(const QString &id) const; + +private: + bool updated; + QString activatingConnectionPath; + QStringList activeConnectionPaths; + + + QMap availableAccessPoints; + void scanForAccessPoints(); + + QStringList devicePaths; + + void getActiveConnectionsPaths(); + void getKnownSsids(); + void accessPointConnections(); + void knownConnections(); + void findConnections(); + QString deviceConnectionPath(const QString &mac); + + QList foundConfigurations; + // QHash > allConfigurations; + + QNetworkManagerInterface *iface; + + QNetworkConfiguration::StateFlags getAPState(qint32 vState, bool isKnown); + QNetworkConfiguration::StateFlags getStateFlag(quint32 nmstate); + + QString getActiveConnectionPath(const QString &identifier); + QString getNameForConfiguration(QNetworkManagerInterfaceDevice *devIface); + + QNetworkConfiguration::StateFlags getStateForId(const QString &id); + + QNetworkInterface getBestInterface(quint32 type, const QString &conPath); + + QMap configurationInterface; + + bool isAddressOfConnection(const QString &conPath, quint32 ipaddress); + +private slots: + void updateDeviceInterfaceState(const QString &, quint32); + void addDevice(QDBusObjectPath path); + void removeDevice(QDBusObjectPath path); + +Q_SIGNALS: + void configurationChanged(const QNetworkConfiguration& config); + void updateAccessPointState(const QString &, quint32); +// void slotActivationFinished(QDBusPendingCallWatcher*); + +private slots: + void accessPointAdded( const QString &aPath, QDBusObjectPath oPath); + void accessPointRemoved( const QString &aPath, QDBusObjectPath oPath); + void cmpPropertiesChanged(const QString &, QMap map); + void newConnection(QDBusObjectPath); + void settingsConnectionRemoved(const QString &); + void slotActivationFinished(QDBusPendingCallWatcher*); +}; + +QT_END_NAMESPACE + +#endif + + -- cgit v0.12 From c2254fdcba61c0aceb89f2f5e6dc926a9493c1a2 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 3 Dec 2009 12:36:31 +1000 Subject: Fix QNetworkSession unit tests. Fix out of process test by trimming input read from lackey. Don't fail in cleanupTestCase() if sessionOpenCloseStop() is not run due to command line. --- .../qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp index fc0db05..c7ce963 100644 --- a/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp +++ b/tests/auto/qnetworksession/tst_qnetworksession/tst_qnetworksession.cpp @@ -170,7 +170,7 @@ void tst_QNetworkSession::initTestCase() dbus_send.waitForFinished(); #endif - inProcessSessionManagementCount = 0; + inProcessSessionManagementCount = -1; QSignalSpy spy(&manager, SIGNAL(updateCompleted())); manager.updateConfigurations(); @@ -415,6 +415,8 @@ void tst_QNetworkSession::sessionOpenCloseStop_data() QTest::newRow((name + QLatin1String(" stop")).toLocal8Bit().constData()) << config << true; } + + inProcessSessionManagementCount = 0; } void tst_QNetworkSession::sessionOpenCloseStop() @@ -803,7 +805,7 @@ void tst_QNetworkSession::outOfProcessSession() output = oopSocket->readLine().trimmed(); if (output.startsWith("Started session ")) { - QString identifier = QString::fromLocal8Bit(output.mid(16).constData()); + QString identifier = QString::fromLocal8Bit(output.mid(20).constData()); QNetworkConfiguration changed; -- cgit v0.12 From 2374a4209f9edcc865b18f63e07a50cdaddc70b7 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 3 Dec 2009 12:44:11 +1000 Subject: Convert NLA engine nito a plugin. --- src/network/bearer/bearer.pri | 17 +- src/network/bearer/qnetworkconfigmanager_p.cpp | 17 +- src/network/bearer/qnetworkconfigmanager_p.h | 2 +- src/network/bearer/qnetworksession_p.cpp | 11 +- src/network/bearer/qnetworksessionengine_win_p.h | 145 ------ src/network/bearer/qnlaengine_win.cpp | 592 ----------------------- src/network/bearer/qnlaengine_win_p.h | 104 ---- src/plugins/bearer/bearer.pro | 1 + src/plugins/bearer/generic/generic.pro | 3 +- src/plugins/bearer/generic/qgenericengine.cpp | 2 +- src/plugins/bearer/nla/main.cpp | 88 ++++ src/plugins/bearer/nla/nla.pro | 20 + src/plugins/bearer/nla/qnlaengine.cpp | 591 ++++++++++++++++++++++ src/plugins/bearer/nla/qnlaengine.h | 105 ++++ src/plugins/bearer/platformdefs_win.h | 134 +++++ 15 files changed, 958 insertions(+), 874 deletions(-) delete mode 100644 src/network/bearer/qnetworksessionengine_win_p.h delete mode 100644 src/network/bearer/qnlaengine_win.cpp delete mode 100644 src/network/bearer/qnlaengine_win_p.h create mode 100644 src/plugins/bearer/nla/main.cpp create mode 100644 src/plugins/bearer/nla/nla.pro create mode 100644 src/plugins/bearer/nla/qnlaengine.cpp create mode 100644 src/plugins/bearer/nla/qnlaengine.h create mode 100644 src/plugins/bearer/platformdefs_win.h diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index bed2597..2c2d255 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -82,21 +82,10 @@ symbian { contains(QT_CONFIG, networkmanager):DEFINES += BACKEND_NM - win32 { - HEADERS += bearer/qnlaengine_win_p.h \ - bearer/qnetworksessionengine_win_p.h + win32:!wince* { + HEADERS += bearer/qnativewifiengine_win_p.h - SOURCES += bearer/qnlaengine_win.cpp - - !wince* { - HEADERS += bearer/qnativewifiengine_win_p.h - - SOURCES += bearer/qnativewifiengine_win.cpp - - LIBS += -lWs2_32 - } else { - LIBS += -lWs2 - } + SOURCES += bearer/qnativewifiengine_win.cpp } macx { diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 7b68394..c61bcd3 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -41,9 +41,6 @@ #include "qnetworkconfigmanager_p.h" -#ifdef Q_OS_WIN -#include "qnlaengine_win_p.h" -#endif #ifdef Q_OS_WIN32 #include "qnativewifiengine_win_p.h" #endif @@ -269,11 +266,17 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() #endif #ifdef Q_OS_WIN - nla = QNlaEngine::instance(); - if (nla) { - connect(nla, SIGNAL(configurationsChanged()), - this, SLOT(updateConfigurations())); + if (keys.contains(QLatin1String("nla"))) { + QBearerEnginePlugin *nlaPlugin = + qobject_cast(l->instance(QLatin1String("nla"))); + if (nlaPlugin) { + nla = nlaPlugin->create(QLatin1String("nla")); + if (nla) { + connect(nla, SIGNAL(configurationsChanged()), + this, SLOT(updateConfigurations())); + } } + } #endif #ifdef Q_OS_WIN32 diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 6a61891..7b824f0 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -137,7 +137,7 @@ private: #ifdef BEARER_ENGINE QNetworkSessionEngine *generic; #ifdef Q_OS_WIN - QNlaEngine *nla; + QNetworkSessionEngine *nla; #ifndef Q_OS_WINCE QNativeWifiEngine *nativeWifi; #endif diff --git a/src/network/bearer/qnetworksession_p.cpp b/src/network/bearer/qnetworksession_p.cpp index cb170e8..1ce94e2 100644 --- a/src/network/bearer/qnetworksession_p.cpp +++ b/src/network/bearer/qnetworksession_p.cpp @@ -44,9 +44,6 @@ #include "qnetworksessionengine_p.h" #include "qnetworkconfigmanager_p.h" -#ifdef Q_OS_WIN -#include "qnlaengine_win_p.h" -#endif #ifdef Q_OS_WIN32 #include "qnativewifiengine_win_p.h" #endif @@ -59,18 +56,14 @@ #include +#undef interface + QT_BEGIN_NAMESPACE static QNetworkSessionEngine *getEngineFromId(const QString &id) { QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); -#ifdef Q_OS_WIN - QNlaEngine *nla = QNlaEngine::instance(); - if (nla && nla->hasIdentifier(id)) - return nla; -#endif - #ifdef Q_OS_WIN32 QNativeWifiEngine *nativeWifi = QNativeWifiEngine::instance(); if (nativeWifi && nativeWifi->hasIdentifier(id)) diff --git a/src/network/bearer/qnetworksessionengine_win_p.h b/src/network/bearer/qnetworksessionengine_win_p.h deleted file mode 100644 index e68a35b..0000000 --- a/src/network/bearer/qnetworksessionengine_win_p.h +++ /dev/null @@ -1,145 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QNETWORKSESSIONENGINE_WIN_P_H -#define QNETWORKSESSIONENGINE_WIN_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include -#include -#undef interface -#include - -#ifndef NS_NLA - -#define NS_NLA 15 - -enum NLA_BLOB_DATA_TYPE { - NLA_RAW_DATA = 0, - NLA_INTERFACE = 1, - NLA_802_1X_LOCATION = 2, - NLA_CONNECTIVITY = 3, - NLA_ICS = 4 -}; - -enum NLA_CONNECTIVITY_TYPE { - NLA_NETWORK_AD_HOC = 0, - NLA_NETWORK_MANAGED = 1, - NLA_NETWORK_UNMANAGED = 2, - NLA_NETWORK_UNKNOWN = 3 -}; - -enum NLA_INTERNET { - NLA_INTERNET_UNKNOWN = 0, - NLA_INTERNET_NO = 1, - NLA_INTERNET_YES = 2 -}; - -struct NLA_BLOB { - struct { - NLA_BLOB_DATA_TYPE type; - DWORD dwSize; - DWORD nextOffset; - } header; - - union { - // NLA_RAW_DATA - CHAR rawData[1]; - - // NLA_INTERFACE - struct { - DWORD dwType; - DWORD dwSpeed; - CHAR adapterName[1]; - } interfaceData; - - // NLA_802_1X_LOCATION - struct { - CHAR information[1]; - } locationData; - - // NLA_CONNECTIVITY - struct { - NLA_CONNECTIVITY_TYPE type; - NLA_INTERNET internet; - } connectivity; - - // NLA_ICS - struct { - struct { - DWORD speed; - DWORD type; - DWORD state; - WCHAR machineName[256]; - WCHAR sharedAdapterName[256]; - } remote; - } ICS; - } data; -}; -#endif - -enum NDIS_MEDIUM { - NdisMedium802_3 = 0, -}; - -enum NDIS_PHYSICAL_MEDIUM { - NdisPhysicalMediumWirelessLan = 1, - NdisPhysicalMediumBluetooth = 10, - NdisPhysicalMediumWiMax = 12, -}; - -#define OID_GEN_MEDIA_SUPPORTED 0x00010103 -#define OID_GEN_PHYSICAL_MEDIUM 0x00010202 - -#define IOCTL_NDIS_QUERY_GLOBAL_STATS \ - CTL_CODE(FILE_DEVICE_PHYSICAL_NETCARD, 0, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) - -#endif // QNETWORKSESSIONENGINE_WIN_P_H diff --git a/src/network/bearer/qnlaengine_win.cpp b/src/network/bearer/qnlaengine_win.cpp deleted file mode 100644 index 579b0e1..0000000 --- a/src/network/bearer/qnlaengine_win.cpp +++ /dev/null @@ -1,592 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qnlaengine_win_p.h" -#include "qnetworkconfiguration_p.h" - -#include -#include -#include -#include - -#include - -#include "qnetworksessionengine_win_p.h" - -QT_BEGIN_NAMESPACE - -Q_GLOBAL_STATIC(QNlaEngine, nlaEngine) - -QWindowsSockInit::QWindowsSockInit() -: version(0) -{ - //### should we try for 2.2 on all platforms ?? - WSAData wsadata; - - // IPv6 requires Winsock v2.0 or better. - if (WSAStartup(MAKEWORD(2,0), &wsadata) != 0) { - qWarning("QBearerManagementAPI: WinSock v2.0 initialization failed."); - } else { - version = 0x20; - } -} - -QWindowsSockInit::~QWindowsSockInit() -{ - WSACleanup(); -} - -#ifdef BEARER_MANAGEMENT_DEBUG -static void printBlob(NLA_BLOB *blob) -{ - qDebug() << "==== BEGIN NLA_BLOB ===="; - - qDebug() << "type:" << blob->header.type; - qDebug() << "size:" << blob->header.dwSize; - qDebug() << "next offset:" << blob->header.nextOffset; - - switch (blob->header.type) { - case NLA_RAW_DATA: - qDebug() << "Raw Data"; - qDebug() << '\t' << blob->data.rawData; - break; - case NLA_INTERFACE: - qDebug() << "Interface"; - qDebug() << "\ttype:" << blob->data.interfaceData.dwType; - qDebug() << "\tspeed:" << blob->data.interfaceData.dwSpeed; - qDebug() << "\tadapter:" << blob->data.interfaceData.adapterName; - break; - case NLA_802_1X_LOCATION: - qDebug() << "802.1x Location"; - qDebug() << '\t' << blob->data.locationData.information; - break; - case NLA_CONNECTIVITY: - qDebug() << "Connectivity"; - qDebug() << "\ttype:" << blob->data.connectivity.type; - qDebug() << "\tinternet:" << blob->data.connectivity.internet; - break; - case NLA_ICS: - qDebug() << "ICS"; - qDebug() << "\tspeed:" << blob->data.ICS.remote.speed; - qDebug() << "\ttype:" << blob->data.ICS.remote.type; - qDebug() << "\tstate:" << blob->data.ICS.remote.state; - qDebug() << "\tmachine name:" << blob->data.ICS.remote.machineName; - qDebug() << "\tshared adapter name:" << blob->data.ICS.remote.sharedAdapterName; - break; - default: - qDebug() << "UNKNOWN BLOB TYPE"; - } - - qDebug() << "===== END NLA_BLOB ====="; -} -#endif - -static QString qGetInterfaceType(const QString &interface) -{ -#ifdef Q_OS_WINCE - Q_UNUSED(interface) -#else - unsigned long oid; - DWORD bytesWritten; - - NDIS_MEDIUM medium; - NDIS_PHYSICAL_MEDIUM physicalMedium; - - HANDLE handle = CreateFile((TCHAR *)QString("\\\\.\\%1").arg(interface).utf16(), 0, - FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); - if (handle == INVALID_HANDLE_VALUE) - return QString(); - - oid = OID_GEN_MEDIA_SUPPORTED; - bytesWritten = 0; - bool result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), - &medium, sizeof(medium), &bytesWritten, 0); - if (!result) { - CloseHandle(handle); - return QString(); - } - - oid = OID_GEN_PHYSICAL_MEDIUM; - bytesWritten = 0; - result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), - &physicalMedium, sizeof(physicalMedium), &bytesWritten, 0); - if (!result) { - CloseHandle(handle); - - if (medium == NdisMedium802_3) - return QLatin1String("Ethernet"); - else - return QString(); - } - - CloseHandle(handle); - - if (medium == NdisMedium802_3) { - switch (physicalMedium) { - case NdisPhysicalMediumWirelessLan: - return QLatin1String("WLAN"); - case NdisPhysicalMediumBluetooth: - return QLatin1String("Bluetooth"); - case NdisPhysicalMediumWiMax: - return QLatin1String("WiMAX"); - default: -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "Physical Medium" << physicalMedium; -#endif - return QLatin1String("Ethernet"); - } - } - -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << medium << physicalMedium; -#endif - -#endif - - return QString(); -} - -class QNlaThread : public QThread -{ - Q_OBJECT - -public: - QNlaThread(QNlaEngine *parent = 0); - ~QNlaThread(); - - QList getConfigurations(); - - void forceUpdate(); - -protected: - virtual void run(); - -private: - void updateConfigurations(QList &configs); - DWORD parseBlob(NLA_BLOB *blob, QNetworkConfigurationPrivate *cpPriv) const; - QNetworkConfigurationPrivate *parseQuerySet(const WSAQUERYSET *querySet) const; - void fetchConfigurations(); - -signals: - void networksChanged(); - -private: - QMutex mutex; - HANDLE handle; - bool done; - QList fetchedConfigurations; -}; - -QNlaThread::QNlaThread(QNlaEngine *parent) -: QThread(parent), handle(0), done(false) -{ -} - -QNlaThread::~QNlaThread() -{ - mutex.lock(); - - done = true; - - if (handle) { - /* cancel completion event */ - if (WSALookupServiceEnd(handle) == SOCKET_ERROR) - qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); - } - mutex.unlock(); - - wait(); -} - -QList QNlaThread::getConfigurations() -{ - QMutexLocker locker(&mutex); - - QList foundConfigurations; - - for (int i = 0; i < fetchedConfigurations.count(); ++i) { - QNetworkConfigurationPrivate *config = new QNetworkConfigurationPrivate; - config->name = fetchedConfigurations.at(i)->name; - config->isValid = fetchedConfigurations.at(i)->isValid; - config->id = fetchedConfigurations.at(i)->id; - config->state = fetchedConfigurations.at(i)->state; - config->type = fetchedConfigurations.at(i)->type; - config->roamingSupported = fetchedConfigurations.at(i)->roamingSupported; - config->purpose = fetchedConfigurations.at(i)->purpose; - config->internet = fetchedConfigurations.at(i)->internet; - - foundConfigurations.append(config); - } - - return foundConfigurations; -} - -void QNlaThread::forceUpdate() -{ - mutex.lock(); - - if (handle) { - /* cancel completion event */ - if (WSALookupServiceEnd(handle) == SOCKET_ERROR) - qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); - handle = 0; - } - mutex.unlock(); -} - -void QNlaThread::run() -{ - WSAEVENT changeEvent = WSACreateEvent(); - if (changeEvent == WSA_INVALID_EVENT) { - qWarning("WSACreateEvent error %d", WSAGetLastError()); - return; - } - - while (true) { - fetchConfigurations(); - - WSAQUERYSET qsRestrictions; - - memset(&qsRestrictions, 0, sizeof(qsRestrictions)); - qsRestrictions.dwSize = sizeof(qsRestrictions); - qsRestrictions.dwNameSpace = NS_NLA; - - mutex.lock(); - if (done) { - mutex.unlock(); - break; - } - int result = WSALookupServiceBegin(&qsRestrictions, LUP_RETURN_ALL, &handle); - mutex.unlock(); - - if (result == SOCKET_ERROR) { - qWarning("%s: WSALookupServiceBegin error %d", __FUNCTION__, WSAGetLastError()); - break; - } - - WSACOMPLETION completion; - WSAOVERLAPPED overlapped; - - memset(&overlapped, 0, sizeof(overlapped)); - overlapped.hEvent = changeEvent; - - memset(&completion, 0, sizeof(completion)); - completion.Type = NSP_NOTIFY_EVENT; - completion.Parameters.Event.lpOverlapped = &overlapped; - - DWORD bytesReturned = 0; - result = WSANSPIoctl(handle, SIO_NSP_NOTIFY_CHANGE, 0, 0, 0, 0, - &bytesReturned, &completion); - if (result == SOCKET_ERROR) { - int error = WSAGetLastError(); - if (error != WSA_IO_PENDING) { - qWarning("WSANSPIoctl error %d", error); - break; - } - } - -#ifndef Q_OS_WINCE - // Not interested in unrelated IO completion events - // although we also don't want to block them - while (WaitForSingleObjectEx(changeEvent, WSA_INFINITE, true) != WAIT_IO_COMPLETION) {} -#else - WaitForSingleObject(changeEvent, WSA_INFINITE); -#endif - - mutex.lock(); - if (handle) { - result = WSALookupServiceEnd(handle); - if (result == SOCKET_ERROR) { - qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); - mutex.unlock(); - break; - } - handle = 0; - } - mutex.unlock(); - } - - WSACloseEvent(changeEvent); -} - -void QNlaThread::updateConfigurations(QList &configs) -{ - mutex.lock(); - - while (!fetchedConfigurations.isEmpty()) - delete fetchedConfigurations.takeFirst(); - - fetchedConfigurations = configs; - - mutex.unlock(); - - emit networksChanged(); -} - -DWORD QNlaThread::parseBlob(NLA_BLOB *blob, QNetworkConfigurationPrivate *cpPriv) const -{ -#ifdef BEARER_MANAGEMENT_DEBUG - printBlob(blob); -#endif - - switch (blob->header.type) { - case NLA_RAW_DATA: -#ifdef BEARER_MANAGEMENT_DEBUG - qWarning("%s: unhandled header type NLA_RAW_DATA", __FUNCTION__); -#endif - break; - case NLA_INTERFACE: - cpPriv->state = QNetworkConfiguration::Active; - if (QNlaEngine *engine = qobject_cast(parent())) { - engine->configurationInterface[cpPriv->id.toUInt()] = - QString(blob->data.interfaceData.adapterName); - } - break; - case NLA_802_1X_LOCATION: -#ifdef BEARER_MANAGEMENT_DEBUG - qWarning("%s: unhandled header type NLA_802_1X_LOCATION", __FUNCTION__); -#endif - break; - case NLA_CONNECTIVITY: - if (blob->data.connectivity.internet == NLA_INTERNET_YES) - cpPriv->internet = true; - else - cpPriv->internet = false; -#ifdef BEARER_MANAGEMENT_DEBUG - qWarning("%s: unhandled header type NLA_CONNECTIVITY", __FUNCTION__); -#endif - break; - case NLA_ICS: -#ifdef BEARER_MANAGEMENT_DEBUG - qWarning("%s: unhandled header type NLA_ICS", __FUNCTION__); -#endif - break; - default: -#ifdef BEARER_MANAGEMENT_DEBUG - qWarning("%s: unhandled header type %d", __FUNCTION__, blob->header.type); -#endif - ; - } - - return blob->header.nextOffset; -} - -QNetworkConfigurationPrivate *QNlaThread::parseQuerySet(const WSAQUERYSET *querySet) const -{ - QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; - - cpPriv->name = QString::fromWCharArray(querySet->lpszServiceInstanceName); - cpPriv->isValid = true; - cpPriv->id = QString::number(qHash(QLatin1String("NLA:") + cpPriv->name)); - cpPriv->state = QNetworkConfiguration::Defined; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "size:" << querySet->dwSize; - qDebug() << "service instance name:" << QString::fromUtf16(querySet->lpszServiceInstanceName); - qDebug() << "service class id:" << querySet->lpServiceClassId; - qDebug() << "version:" << querySet->lpVersion; - qDebug() << "comment:" << QString::fromUtf16(querySet->lpszComment); - qDebug() << "namespace:" << querySet->dwNameSpace; - qDebug() << "namespace provider id:" << querySet->lpNSProviderId; - qDebug() << "context:" << QString::fromUtf16(querySet->lpszContext); - qDebug() << "number of protocols:" << querySet->dwNumberOfProtocols; - qDebug() << "protocols:" << querySet->lpafpProtocols; - qDebug() << "query string:" << QString::fromUtf16(querySet->lpszQueryString); - qDebug() << "number of cs addresses:" << querySet->dwNumberOfCsAddrs; - qDebug() << "cs addresses:" << querySet->lpcsaBuffer; - qDebug() << "output flags:" << querySet->dwOutputFlags; -#endif - - if (querySet->lpBlob) { -#ifdef BEARER_MANAGEMENT_DEBUG - qDebug() << "blob size:" << querySet->lpBlob->cbSize; - qDebug() << "blob data:" << querySet->lpBlob->pBlobData; -#endif - - DWORD offset = 0; - do { - NLA_BLOB *blob = reinterpret_cast(querySet->lpBlob->pBlobData + offset); - DWORD nextOffset = parseBlob(blob, cpPriv); - if (nextOffset == offset) - break; - else - offset = nextOffset; - } while (offset != 0 && offset < querySet->lpBlob->cbSize); - } - - return cpPriv; -} - -void QNlaThread::fetchConfigurations() -{ - QList foundConfigurations; - - WSAQUERYSET qsRestrictions; - HANDLE hLookup = 0; - - memset(&qsRestrictions, 0, sizeof(qsRestrictions)); - qsRestrictions.dwSize = sizeof(qsRestrictions); - qsRestrictions.dwNameSpace = NS_NLA; - - int result = WSALookupServiceBegin(&qsRestrictions, LUP_RETURN_ALL | LUP_DEEP, &hLookup); - if (result == SOCKET_ERROR) { - qWarning("%s: WSALookupServiceBegin error %d", __FUNCTION__, WSAGetLastError()); - mutex.lock(); - fetchedConfigurations.clear(); - mutex.unlock(); - } - - char buffer[0x10000]; - while (result == 0) { - DWORD bufferLength = sizeof(buffer); - result = WSALookupServiceNext(hLookup, LUP_RETURN_ALL, - &bufferLength, reinterpret_cast(buffer)); - - if (result == SOCKET_ERROR) { - int error = WSAGetLastError(); - - if (error == WSA_E_NO_MORE) - break; - - if (error == WSAEFAULT) { - qDebug() << "buffer not big enough" << bufferLength; - break; - } - - qWarning("WSALookupServiceNext error %d", WSAGetLastError()); - break; - } - - QNetworkConfigurationPrivate *cpPriv = - parseQuerySet(reinterpret_cast(buffer)); - - foundConfigurations.append(cpPriv); - } - - if (hLookup) { - result = WSALookupServiceEnd(hLookup); - if (result == SOCKET_ERROR) { - qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); - } - } - - updateConfigurations(foundConfigurations); -} - -QNlaEngine::QNlaEngine(QObject *parent) -: QNetworkSessionEngine(parent), nlaThread(0) -{ - nlaThread = new QNlaThread(this); - connect(nlaThread, SIGNAL(networksChanged()), - this, SIGNAL(configurationsChanged())); - nlaThread->start(); - - qApp->processEvents(QEventLoop::ExcludeUserInputEvents); -} - -QNlaEngine::~QNlaEngine() -{ - delete nlaThread; -} - -QList QNlaEngine::getConfigurations(bool *ok) -{ - if (ok) - *ok = true; - - return nlaThread->getConfigurations(); -} - -QString QNlaEngine::getInterfaceFromId(const QString &id) -{ - return configurationInterface.value(id.toUInt()); -} - -bool QNlaEngine::hasIdentifier(const QString &id) -{ - if (configurationInterface.contains(id.toUInt())) - return true; - - foreach (QNetworkConfigurationPrivate *cpPriv, nlaThread->getConfigurations()) { - if (cpPriv->id == id) - return true; - } - - return false; -} - -QString QNlaEngine::bearerName(const QString &id) -{ - QString interface = getInterfaceFromId(id); - - if (interface.isEmpty()) - return QString(); - - return qGetInterfaceType(interface); -} - -void QNlaEngine::connectToId(const QString &id) -{ - emit connectionError(id, OperationNotSupported); -} - -void QNlaEngine::disconnectFromId(const QString &id) -{ - emit connectionError(id, OperationNotSupported); -} - -void QNlaEngine::requestUpdate() -{ - nlaThread->forceUpdate(); -} - -QNlaEngine *QNlaEngine::instance() -{ - return nlaEngine(); -} - -#include "qnlaengine_win.moc" -#include "moc_qnlaengine_win_p.cpp" -QT_END_NAMESPACE - - - diff --git a/src/network/bearer/qnlaengine_win_p.h b/src/network/bearer/qnlaengine_win_p.h deleted file mode 100644 index 1e7d051..0000000 --- a/src/network/bearer/qnlaengine_win_p.h +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QNLAENGINE_P_H -#define QNLAENGINE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qnetworksessionengine_p.h" - -#include - -QT_BEGIN_NAMESPACE - -class QNetworkConfigurationPrivate; -class QNlaThread; - -class QWindowsSockInit -{ -public: - QWindowsSockInit(); - ~QWindowsSockInit(); - int version; -}; - -class QNlaEngine : public QNetworkSessionEngine -{ - Q_OBJECT - - friend class QNlaThread; - -public: - QNlaEngine(QObject *parent = 0); - ~QNlaEngine(); - - QList getConfigurations(bool *ok = 0); - QString getInterfaceFromId(const QString &id); - bool hasIdentifier(const QString &id); - - QString bearerName(const QString &id); - - void connectToId(const QString &id); - void disconnectFromId(const QString &id); - - void requestUpdate(); - - static QNlaEngine *instance(); - -private: - QWindowsSockInit winSock; - QNlaThread *nlaThread; - QMap configurationInterface; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/bearer/bearer.pro b/src/plugins/bearer/bearer.pro index 60ba81b..51323b0 100644 --- a/src/plugins/bearer/bearer.pro +++ b/src/plugins/bearer/bearer.pro @@ -2,3 +2,4 @@ TEMPLATE = subdirs SUBDIRS += generic contains(QT_CONFIG, dbus):contains(QT_CONFIG, networkmanager):SUBDIRS += networkmanager +win32:SUBDIRS += nla diff --git a/src/plugins/bearer/generic/generic.pro b/src/plugins/bearer/generic/generic.pro index d32dbe6..506417c 100644 --- a/src/plugins/bearer/generic/generic.pro +++ b/src/plugins/bearer/generic/generic.pro @@ -5,7 +5,8 @@ QT += network DEFINES += BEARER_ENGINE -HEADERS += qgenericengine.h +HEADERS += qgenericengine.h \ + ../platformdefs_win.h SOURCES += qgenericengine.cpp main.cpp QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index 89db82b..4be27ba 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -51,7 +51,7 @@ #include #ifdef Q_OS_WIN -#include "qnetworksessionengine_win_p.h" +#include "../platformdefs_win.h" #endif QT_BEGIN_NAMESPACE diff --git a/src/plugins/bearer/nla/main.cpp b/src/plugins/bearer/nla/main.cpp new file mode 100644 index 0000000..f0d36c4 --- /dev/null +++ b/src/plugins/bearer/nla/main.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnlaengine.h" + +#include + +#include + +QT_BEGIN_NAMESPACE + +class QNlaEnginePlugin : public QBearerEnginePlugin +{ +public: + QNlaEnginePlugin(); + ~QNlaEnginePlugin(); + + QStringList keys() const; + QBearerEngine *create(const QString &key) const; +}; + +QNlaEnginePlugin::QNlaEnginePlugin() +{ +} + +QNlaEnginePlugin::~QNlaEnginePlugin() +{ +} + +QStringList QNlaEnginePlugin::keys() const +{ + qDebug() << Q_FUNC_INFO; + + return QStringList() << QLatin1String("nla"); +} + +QBearerEngine *QNlaEnginePlugin::create(const QString &key) const +{ + qDebug() << Q_FUNC_INFO; + + if (key == QLatin1String("nla")) + return new QNlaEngine; + else + return 0; +} + +Q_EXPORT_STATIC_PLUGIN(QNlaEnginePlugin) +Q_EXPORT_PLUGIN2(qnlabearer, QNlaEnginePlugin) + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/nla/nla.pro b/src/plugins/bearer/nla/nla.pro new file mode 100644 index 0000000..78f3271 --- /dev/null +++ b/src/plugins/bearer/nla/nla.pro @@ -0,0 +1,20 @@ +TARGET = qnlabearer +include(../../qpluginbase.pri) + +QT += network + +!wince* { + LIBS += -lWs2_32 +} else { + LIBS += -lWs2 +} + +DEFINES += BEARER_ENGINE + +HEADERS += qnlaengine.h \ + ../platformdefs_win.h +SOURCES += qnlaengine.cpp main.cpp + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer +target.path += $$[QT_INSTALL_PLUGINS]/bearer +INSTALLS += target diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp new file mode 100644 index 0000000..527776f --- /dev/null +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -0,0 +1,591 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtNetwork module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnlaengine.h" +#include + +#include +#include +#include +#include + +#include + +#include "../platformdefs_win.h" + +QT_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QNlaEngine, nlaEngine) + +QWindowsSockInit2::QWindowsSockInit2() +: version(0) +{ + //### should we try for 2.2 on all platforms ?? + WSAData wsadata; + + // IPv6 requires Winsock v2.0 or better. + if (WSAStartup(MAKEWORD(2,0), &wsadata) != 0) { + qWarning("QBearerManagementAPI: WinSock v2.0 initialization failed."); + } else { + version = 0x20; + } +} + +QWindowsSockInit2::~QWindowsSockInit2() +{ + WSACleanup(); +} + +#ifdef BEARER_MANAGEMENT_DEBUG +static void printBlob(NLA_BLOB *blob) +{ + qDebug() << "==== BEGIN NLA_BLOB ===="; + + qDebug() << "type:" << blob->header.type; + qDebug() << "size:" << blob->header.dwSize; + qDebug() << "next offset:" << blob->header.nextOffset; + + switch (blob->header.type) { + case NLA_RAW_DATA: + qDebug() << "Raw Data"; + qDebug() << '\t' << blob->data.rawData; + break; + case NLA_INTERFACE: + qDebug() << "Interface"; + qDebug() << "\ttype:" << blob->data.interfaceData.dwType; + qDebug() << "\tspeed:" << blob->data.interfaceData.dwSpeed; + qDebug() << "\tadapter:" << blob->data.interfaceData.adapterName; + break; + case NLA_802_1X_LOCATION: + qDebug() << "802.1x Location"; + qDebug() << '\t' << blob->data.locationData.information; + break; + case NLA_CONNECTIVITY: + qDebug() << "Connectivity"; + qDebug() << "\ttype:" << blob->data.connectivity.type; + qDebug() << "\tinternet:" << blob->data.connectivity.internet; + break; + case NLA_ICS: + qDebug() << "ICS"; + qDebug() << "\tspeed:" << blob->data.ICS.remote.speed; + qDebug() << "\ttype:" << blob->data.ICS.remote.type; + qDebug() << "\tstate:" << blob->data.ICS.remote.state; + qDebug() << "\tmachine name:" << blob->data.ICS.remote.machineName; + qDebug() << "\tshared adapter name:" << blob->data.ICS.remote.sharedAdapterName; + break; + default: + qDebug() << "UNKNOWN BLOB TYPE"; + } + + qDebug() << "===== END NLA_BLOB ====="; +} +#endif + +static QString qGetInterfaceType(const QString &interface) +{ +#ifdef Q_OS_WINCE + Q_UNUSED(interface) +#else + unsigned long oid; + DWORD bytesWritten; + + NDIS_MEDIUM medium; + NDIS_PHYSICAL_MEDIUM physicalMedium; + + HANDLE handle = CreateFile((TCHAR *)QString(QLatin1String("\\\\.\\%1")).arg(interface).utf16(), + 0, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); + if (handle == INVALID_HANDLE_VALUE) + return QString(); + + oid = OID_GEN_MEDIA_SUPPORTED; + bytesWritten = 0; + bool result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), + &medium, sizeof(medium), &bytesWritten, 0); + if (!result) { + CloseHandle(handle); + return QString(); + } + + oid = OID_GEN_PHYSICAL_MEDIUM; + bytesWritten = 0; + result = DeviceIoControl(handle, IOCTL_NDIS_QUERY_GLOBAL_STATS, &oid, sizeof(oid), + &physicalMedium, sizeof(physicalMedium), &bytesWritten, 0); + if (!result) { + CloseHandle(handle); + + if (medium == NdisMedium802_3) + return QLatin1String("Ethernet"); + else + return QString(); + } + + CloseHandle(handle); + + if (medium == NdisMedium802_3) { + switch (physicalMedium) { + case NdisPhysicalMediumWirelessLan: + return QLatin1String("WLAN"); + case NdisPhysicalMediumBluetooth: + return QLatin1String("Bluetooth"); + case NdisPhysicalMediumWiMax: + return QLatin1String("WiMAX"); + default: +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "Physical Medium" << physicalMedium; +#endif + return QLatin1String("Ethernet"); + } + } + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << medium << physicalMedium; +#endif + +#endif + + return QString(); +} + +class QNlaThread : public QThread +{ + Q_OBJECT + +public: + QNlaThread(QNlaEngine *parent = 0); + ~QNlaThread(); + + QList getConfigurations(); + + void forceUpdate(); + +protected: + virtual void run(); + +private: + void updateConfigurations(QList &configs); + DWORD parseBlob(NLA_BLOB *blob, QNetworkConfigurationPrivate *cpPriv) const; + QNetworkConfigurationPrivate *parseQuerySet(const WSAQUERYSET *querySet) const; + void fetchConfigurations(); + +signals: + void networksChanged(); + +private: + QMutex mutex; + HANDLE handle; + bool done; + QList fetchedConfigurations; +}; + +QNlaThread::QNlaThread(QNlaEngine *parent) +: QThread(parent), handle(0), done(false) +{ +} + +QNlaThread::~QNlaThread() +{ + mutex.lock(); + + done = true; + + if (handle) { + /* cancel completion event */ + if (WSALookupServiceEnd(handle) == SOCKET_ERROR) + qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); + } + mutex.unlock(); + + wait(); +} + +QList QNlaThread::getConfigurations() +{ + QMutexLocker locker(&mutex); + + QList foundConfigurations; + + for (int i = 0; i < fetchedConfigurations.count(); ++i) { + QNetworkConfigurationPrivate *config = new QNetworkConfigurationPrivate; + config->name = fetchedConfigurations.at(i)->name; + config->isValid = fetchedConfigurations.at(i)->isValid; + config->id = fetchedConfigurations.at(i)->id; + config->state = fetchedConfigurations.at(i)->state; + config->type = fetchedConfigurations.at(i)->type; + config->roamingSupported = fetchedConfigurations.at(i)->roamingSupported; + config->purpose = fetchedConfigurations.at(i)->purpose; + config->internet = fetchedConfigurations.at(i)->internet; + + foundConfigurations.append(config); + } + + return foundConfigurations; +} + +void QNlaThread::forceUpdate() +{ + mutex.lock(); + + if (handle) { + /* cancel completion event */ + if (WSALookupServiceEnd(handle) == SOCKET_ERROR) + qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); + handle = 0; + } + mutex.unlock(); +} + +void QNlaThread::run() +{ + WSAEVENT changeEvent = WSACreateEvent(); + if (changeEvent == WSA_INVALID_EVENT) { + qWarning("WSACreateEvent error %d", WSAGetLastError()); + return; + } + + while (true) { + fetchConfigurations(); + + WSAQUERYSET qsRestrictions; + + memset(&qsRestrictions, 0, sizeof(qsRestrictions)); + qsRestrictions.dwSize = sizeof(qsRestrictions); + qsRestrictions.dwNameSpace = NS_NLA; + + mutex.lock(); + if (done) { + mutex.unlock(); + break; + } + int result = WSALookupServiceBegin(&qsRestrictions, LUP_RETURN_ALL, &handle); + mutex.unlock(); + + if (result == SOCKET_ERROR) { + qWarning("%s: WSALookupServiceBegin error %d", __FUNCTION__, WSAGetLastError()); + break; + } + + WSACOMPLETION completion; + WSAOVERLAPPED overlapped; + + memset(&overlapped, 0, sizeof(overlapped)); + overlapped.hEvent = changeEvent; + + memset(&completion, 0, sizeof(completion)); + completion.Type = NSP_NOTIFY_EVENT; + completion.Parameters.Event.lpOverlapped = &overlapped; + + DWORD bytesReturned = 0; + result = WSANSPIoctl(handle, SIO_NSP_NOTIFY_CHANGE, 0, 0, 0, 0, + &bytesReturned, &completion); + if (result == SOCKET_ERROR) { + int error = WSAGetLastError(); + if (error != WSA_IO_PENDING) { + qWarning("WSANSPIoctl error %d", error); + break; + } + } + +#ifndef Q_OS_WINCE + // Not interested in unrelated IO completion events + // although we also don't want to block them + while (WaitForSingleObjectEx(changeEvent, WSA_INFINITE, true) != WAIT_IO_COMPLETION) {} +#else + WaitForSingleObject(changeEvent, WSA_INFINITE); +#endif + + mutex.lock(); + if (handle) { + result = WSALookupServiceEnd(handle); + if (result == SOCKET_ERROR) { + qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); + mutex.unlock(); + break; + } + handle = 0; + } + mutex.unlock(); + } + + WSACloseEvent(changeEvent); +} + +void QNlaThread::updateConfigurations(QList &configs) +{ + mutex.lock(); + + while (!fetchedConfigurations.isEmpty()) + delete fetchedConfigurations.takeFirst(); + + fetchedConfigurations = configs; + + mutex.unlock(); + + emit networksChanged(); +} + +DWORD QNlaThread::parseBlob(NLA_BLOB *blob, QNetworkConfigurationPrivate *cpPriv) const +{ +#ifdef BEARER_MANAGEMENT_DEBUG + printBlob(blob); +#endif + + switch (blob->header.type) { + case NLA_RAW_DATA: +#ifdef BEARER_MANAGEMENT_DEBUG + qWarning("%s: unhandled header type NLA_RAW_DATA", __FUNCTION__); +#endif + break; + case NLA_INTERFACE: + cpPriv->state = QNetworkConfiguration::Active; + if (QNlaEngine *engine = qobject_cast(parent())) { + engine->configurationInterface[cpPriv->id.toUInt()] = + QString::fromLatin1(blob->data.interfaceData.adapterName); + } + break; + case NLA_802_1X_LOCATION: +#ifdef BEARER_MANAGEMENT_DEBUG + qWarning("%s: unhandled header type NLA_802_1X_LOCATION", __FUNCTION__); +#endif + break; + case NLA_CONNECTIVITY: + if (blob->data.connectivity.internet == NLA_INTERNET_YES) + cpPriv->internet = true; + else + cpPriv->internet = false; +#ifdef BEARER_MANAGEMENT_DEBUG + qWarning("%s: unhandled header type NLA_CONNECTIVITY", __FUNCTION__); +#endif + break; + case NLA_ICS: +#ifdef BEARER_MANAGEMENT_DEBUG + qWarning("%s: unhandled header type NLA_ICS", __FUNCTION__); +#endif + break; + default: +#ifdef BEARER_MANAGEMENT_DEBUG + qWarning("%s: unhandled header type %d", __FUNCTION__, blob->header.type); +#endif + ; + } + + return blob->header.nextOffset; +} + +QNetworkConfigurationPrivate *QNlaThread::parseQuerySet(const WSAQUERYSET *querySet) const +{ + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + + cpPriv->name = QString::fromWCharArray(querySet->lpszServiceInstanceName); + cpPriv->isValid = true; + cpPriv->id = QString::number(qHash(QLatin1String("NLA:") + cpPriv->name)); + cpPriv->state = QNetworkConfiguration::Defined; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "size:" << querySet->dwSize; + qDebug() << "service instance name:" << QString::fromUtf16(querySet->lpszServiceInstanceName); + qDebug() << "service class id:" << querySet->lpServiceClassId; + qDebug() << "version:" << querySet->lpVersion; + qDebug() << "comment:" << QString::fromUtf16(querySet->lpszComment); + qDebug() << "namespace:" << querySet->dwNameSpace; + qDebug() << "namespace provider id:" << querySet->lpNSProviderId; + qDebug() << "context:" << QString::fromUtf16(querySet->lpszContext); + qDebug() << "number of protocols:" << querySet->dwNumberOfProtocols; + qDebug() << "protocols:" << querySet->lpafpProtocols; + qDebug() << "query string:" << QString::fromUtf16(querySet->lpszQueryString); + qDebug() << "number of cs addresses:" << querySet->dwNumberOfCsAddrs; + qDebug() << "cs addresses:" << querySet->lpcsaBuffer; + qDebug() << "output flags:" << querySet->dwOutputFlags; +#endif + + if (querySet->lpBlob) { +#ifdef BEARER_MANAGEMENT_DEBUG + qDebug() << "blob size:" << querySet->lpBlob->cbSize; + qDebug() << "blob data:" << querySet->lpBlob->pBlobData; +#endif + + DWORD offset = 0; + do { + NLA_BLOB *blob = reinterpret_cast(querySet->lpBlob->pBlobData + offset); + DWORD nextOffset = parseBlob(blob, cpPriv); + if (nextOffset == offset) + break; + else + offset = nextOffset; + } while (offset != 0 && offset < querySet->lpBlob->cbSize); + } + + return cpPriv; +} + +void QNlaThread::fetchConfigurations() +{ + QList foundConfigurations; + + WSAQUERYSET qsRestrictions; + HANDLE hLookup = 0; + + memset(&qsRestrictions, 0, sizeof(qsRestrictions)); + qsRestrictions.dwSize = sizeof(qsRestrictions); + qsRestrictions.dwNameSpace = NS_NLA; + + int result = WSALookupServiceBegin(&qsRestrictions, LUP_RETURN_ALL | LUP_DEEP, &hLookup); + if (result == SOCKET_ERROR) { + qWarning("%s: WSALookupServiceBegin error %d", __FUNCTION__, WSAGetLastError()); + mutex.lock(); + fetchedConfigurations.clear(); + mutex.unlock(); + } + + char buffer[0x10000]; + while (result == 0) { + DWORD bufferLength = sizeof(buffer); + result = WSALookupServiceNext(hLookup, LUP_RETURN_ALL, + &bufferLength, reinterpret_cast(buffer)); + + if (result == SOCKET_ERROR) { + int error = WSAGetLastError(); + + if (error == WSA_E_NO_MORE) + break; + + if (error == WSAEFAULT) { + qDebug() << "buffer not big enough" << bufferLength; + break; + } + + qWarning("WSALookupServiceNext error %d", WSAGetLastError()); + break; + } + + QNetworkConfigurationPrivate *cpPriv = + parseQuerySet(reinterpret_cast(buffer)); + + foundConfigurations.append(cpPriv); + } + + if (hLookup) { + result = WSALookupServiceEnd(hLookup); + if (result == SOCKET_ERROR) { + qWarning("WSALookupServiceEnd error %d", WSAGetLastError()); + } + } + + updateConfigurations(foundConfigurations); +} + +QNlaEngine::QNlaEngine(QObject *parent) +: QNetworkSessionEngine(parent), nlaThread(0) +{ + nlaThread = new QNlaThread(this); + connect(nlaThread, SIGNAL(networksChanged()), + this, SIGNAL(configurationsChanged())); + nlaThread->start(); + + qApp->processEvents(QEventLoop::ExcludeUserInputEvents); +} + +QNlaEngine::~QNlaEngine() +{ + delete nlaThread; +} + +QList QNlaEngine::getConfigurations(bool *ok) +{ + if (ok) + *ok = true; + + return nlaThread->getConfigurations(); +} + +QString QNlaEngine::getInterfaceFromId(const QString &id) +{ + return configurationInterface.value(id.toUInt()); +} + +bool QNlaEngine::hasIdentifier(const QString &id) +{ + if (configurationInterface.contains(id.toUInt())) + return true; + + foreach (QNetworkConfigurationPrivate *cpPriv, nlaThread->getConfigurations()) { + if (cpPriv->id == id) + return true; + } + + return false; +} + +QString QNlaEngine::bearerName(const QString &id) +{ + QString interface = getInterfaceFromId(id); + + if (interface.isEmpty()) + return QString(); + + return qGetInterfaceType(interface); +} + +void QNlaEngine::connectToId(const QString &id) +{ + emit connectionError(id, OperationNotSupported); +} + +void QNlaEngine::disconnectFromId(const QString &id) +{ + emit connectionError(id, OperationNotSupported); +} + +void QNlaEngine::requestUpdate() +{ + nlaThread->forceUpdate(); +} + +QNlaEngine *QNlaEngine::instance() +{ + return nlaEngine(); +} + +#include "qnlaengine.moc" +QT_END_NAMESPACE + + + diff --git a/src/plugins/bearer/nla/qnlaengine.h b/src/plugins/bearer/nla/qnlaengine.h new file mode 100644 index 0000000..76505fb --- /dev/null +++ b/src/plugins/bearer/nla/qnlaengine.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtNetwork module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNLAENGINE_P_H +#define QNLAENGINE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; +class QNlaThread; + +class QWindowsSockInit2 +{ +public: + QWindowsSockInit2(); + ~QWindowsSockInit2(); + int version; +}; + +class QNlaEngine : public QNetworkSessionEngine +{ + Q_OBJECT + + friend class QNlaThread; + +public: + QNlaEngine(QObject *parent = 0); + ~QNlaEngine(); + + QList getConfigurations(bool *ok = 0); + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + static QNlaEngine *instance(); + +private: + QWindowsSockInit2 winSock; + QNlaThread *nlaThread; + QMap configurationInterface; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/bearer/platformdefs_win.h b/src/plugins/bearer/platformdefs_win.h new file mode 100644 index 0000000..133b7b1 --- /dev/null +++ b/src/plugins/bearer/platformdefs_win.h @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtNetwork module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPLATFORMDEFS_WIN_H +#define QPLATFORMDEFS_WIN_H + +#include +#include +#undef interface +#include + +#ifndef NS_NLA + +#define NS_NLA 15 + +enum NLA_BLOB_DATA_TYPE { + NLA_RAW_DATA = 0, + NLA_INTERFACE = 1, + NLA_802_1X_LOCATION = 2, + NLA_CONNECTIVITY = 3, + NLA_ICS = 4 +}; + +enum NLA_CONNECTIVITY_TYPE { + NLA_NETWORK_AD_HOC = 0, + NLA_NETWORK_MANAGED = 1, + NLA_NETWORK_UNMANAGED = 2, + NLA_NETWORK_UNKNOWN = 3 +}; + +enum NLA_INTERNET { + NLA_INTERNET_UNKNOWN = 0, + NLA_INTERNET_NO = 1, + NLA_INTERNET_YES = 2 +}; + +struct NLA_BLOB { + struct { + NLA_BLOB_DATA_TYPE type; + DWORD dwSize; + DWORD nextOffset; + } header; + + union { + // NLA_RAW_DATA + CHAR rawData[1]; + + // NLA_INTERFACE + struct { + DWORD dwType; + DWORD dwSpeed; + CHAR adapterName[1]; + } interfaceData; + + // NLA_802_1X_LOCATION + struct { + CHAR information[1]; + } locationData; + + // NLA_CONNECTIVITY + struct { + NLA_CONNECTIVITY_TYPE type; + NLA_INTERNET internet; + } connectivity; + + // NLA_ICS + struct { + struct { + DWORD speed; + DWORD type; + DWORD state; + WCHAR machineName[256]; + WCHAR sharedAdapterName[256]; + } remote; + } ICS; + } data; +}; +#endif + +enum NDIS_MEDIUM { + NdisMedium802_3 = 0, +}; + +enum NDIS_PHYSICAL_MEDIUM { + NdisPhysicalMediumWirelessLan = 1, + NdisPhysicalMediumBluetooth = 10, + NdisPhysicalMediumWiMax = 12, +}; + +#define OID_GEN_MEDIA_SUPPORTED 0x00010103 +#define OID_GEN_PHYSICAL_MEDIUM 0x00010202 + +#define IOCTL_NDIS_QUERY_GLOBAL_STATS \ + CTL_CODE(FILE_DEVICE_PHYSICAL_NETCARD, 0, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) + +#endif -- cgit v0.12 From 3d9d69e56b33935a1af825d837ca81081332963f Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 3 Dec 2009 13:46:36 +1000 Subject: Convert NativeWifi engine into a plugin. --- src/network/bearer/bearer.pri | 6 - src/network/bearer/qnativewifiengine_win.cpp | 726 --------------------- src/network/bearer/qnativewifiengine_win_p.h | 95 --- src/network/bearer/qnetworkconfigmanager_p.cpp | 25 +- src/network/bearer/qnetworkconfigmanager_p.h | 2 +- src/network/bearer/qnetworksession_p.cpp | 9 - src/plugins/bearer/bearer.pro | 1 + src/plugins/bearer/nativewifi/main.cpp | 143 ++++ src/plugins/bearer/nativewifi/nativewifi.pro | 13 + src/plugins/bearer/nativewifi/platformdefs.h | 322 +++++++++ .../bearer/nativewifi/qnativewifiengine.cpp | 406 ++++++++++++ src/plugins/bearer/nativewifi/qnativewifiengine.h | 95 +++ 12 files changed, 998 insertions(+), 845 deletions(-) delete mode 100644 src/network/bearer/qnativewifiengine_win.cpp delete mode 100644 src/network/bearer/qnativewifiengine_win_p.h create mode 100644 src/plugins/bearer/nativewifi/main.cpp create mode 100644 src/plugins/bearer/nativewifi/nativewifi.pro create mode 100644 src/plugins/bearer/nativewifi/platformdefs.h create mode 100644 src/plugins/bearer/nativewifi/qnativewifiengine.cpp create mode 100644 src/plugins/bearer/nativewifi/qnativewifiengine.h diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index 2c2d255..9476239 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -82,12 +82,6 @@ symbian { contains(QT_CONFIG, networkmanager):DEFINES += BACKEND_NM - win32:!wince* { - HEADERS += bearer/qnativewifiengine_win_p.h - - SOURCES += bearer/qnativewifiengine_win.cpp - } - macx { HEADERS += bearer/qcorewlanengine_mac_p.h SOURCES+= bearer/qcorewlanengine_mac.mm diff --git a/src/network/bearer/qnativewifiengine_win.cpp b/src/network/bearer/qnativewifiengine_win.cpp deleted file mode 100644 index 46d4ead..0000000 --- a/src/network/bearer/qnativewifiengine_win.cpp +++ /dev/null @@ -1,726 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qnativewifiengine_win_p.h" -#include "qnetworkconfiguration_p.h" - -#include -#include -#include -#include - -#include - -#include -#undef interface - -QT_BEGIN_NAMESPACE - -Q_GLOBAL_STATIC(QNativeWifiEngine, nativeWifiEngine) - -#define WLAN_MAX_NAME_LENGTH 256 -#define WLAN_MAX_PHY_TYPE_NUMBER 8 -#define WLAN_NOTIFICATION_SOURCE_ALL 0x0000ffff -#define WLAN_AVAILABLE_NETWORK_CONNECTED 1 -#define WLAN_AVAILABLE_NETWORK_HAS_PROFILE 2 -#define DOT11_SSID_MAX_LENGTH 32 - -struct WLAN_NOTIFICATION_DATA { - DWORD NotificationSource; - DWORD NotificationCode; - GUID InterfaceGuid; - DWORD dwDataSize; - PVOID pData; -}; - -enum WLAN_INTERFACE_STATE { - wlan_interface_state_not_ready = 0, - wlan_interface_state_connected, - wlan_interface_state_ad_hoc_network_formed, - wlan_interface_state_disconnecting, - wlan_interface_state_disconnected, - wlan_interface_state_associating, - wlan_interface_state_discovering, - wlan_interface_state_authenticating -}; - -struct WLAN_INTERFACE_INFO { - GUID InterfaceGuid; - WCHAR strInterfaceDescription[WLAN_MAX_NAME_LENGTH]; - WLAN_INTERFACE_STATE isState; -}; - -struct WLAN_INTERFACE_INFO_LIST { - DWORD dwNumberOfItems; - DWORD dwIndex; - WLAN_INTERFACE_INFO InterfaceInfo[1]; -}; - -struct DOT11_SSID { - ULONG uSSIDLength; - UCHAR ucSSID[DOT11_SSID_MAX_LENGTH]; -}; - -struct NDIS_OBJECT_HEADER { - UCHAR Type; - UCHAR Revision; - USHORT Size; -}; - -typedef UCHAR DOT11_MAC_ADDRESS[6]; -struct DOT11_BSSID_LIST { - NDIS_OBJECT_HEADER Header; - ULONG uNumberOfEntries; - ULONG uTotalNumOfEntries; - DOT11_MAC_ADDRESS BSSIDs[1]; -}; - -enum DOT11_BSS_TYPE { - dot11_BSS_type_infrastructure = 1, - dot11_BSS_type_independent = 2, - dot11_BSS_type_any = 3 -}; - -enum DOT11_PHY_TYPE { - dot11_phy_type_unknown = 0, - dot11_phy_type_any = dot11_phy_type_unknown, - dot11_phy_type_fhss = 1, - dot11_phy_type_dsss = 2, - dot11_phy_type_irbaseband = 3, - dot11_phy_type_ofdm = 4, - dot11_phy_type_hrdsss = 5, - dot11_phy_type_erp = 6, - dot11_phy_type_ht = 7, - dot11_phy_type_IHV_start = 0x80000000, - dot11_phy_type_IHV_end = 0xffffffff -}; - -enum DOT11_AUTH_ALGORITHM { - DOT11_AUTH_ALGO_80211_OPEN = 1, - DOT11_AUTH_ALGO_80211_SHARED_KEY = 2, - DOT11_AUTH_ALGO_WPA = 3, - DOT11_AUTH_ALGO_WPA_PSK = 4, - DOT11_AUTH_ALGO_WPA_NONE = 5, - DOT11_AUTH_ALGO_RSNA = 6, - DOT11_AUTH_ALGO_RSNA_PSK = 7, - DOT11_AUTH_ALGO_IHV_START = 0x80000000, - DOT11_AUTH_ALGO_IHV_END = 0xffffffff -}; - -enum DOT11_CIPHER_ALGORITHM { - DOT11_CIPHER_ALGO_NONE = 0x00, - DOT11_CIPHER_ALGO_WEP40 = 0x01, - DOT11_CIPHER_ALGO_TKIP = 0x02, - DOT11_CIPHER_ALGO_CCMP = 0x04, - DOT11_CIPHER_ALGO_WEP104 = 0x05, - DOT11_CIPHER_ALGO_WPA_USE_GROUP = 0x100, - DOT11_CIPHER_ALGO_RSN_USE_GROUP = 0x100, - DOT11_CIPHER_ALGO_WEP = 0x101, - DOT11_CIPHER_ALGO_IHV_START = 0x80000000, - DOT11_CIPHER_ALGO_IHV_END = 0xffffffff -}; - -struct WLAN_AVAILABLE_NETWORK { - WCHAR strProfileName[WLAN_MAX_NAME_LENGTH]; - DOT11_SSID dot11Ssid; - DOT11_BSS_TYPE dot11BssType; - ULONG uNumberOfBssids; - BOOL bNetworkConnectable; - DWORD wlanNotConnectableReason; - ULONG uNumberOfPhyTypes; - DOT11_PHY_TYPE dot11PhyTypes[WLAN_MAX_PHY_TYPE_NUMBER]; - BOOL bMorePhyTypes; - ULONG wlanSignalQuality; - BOOL bSecurityEnabled; - DOT11_AUTH_ALGORITHM dot11DefaultAuthAlgorithm; - DOT11_CIPHER_ALGORITHM dot11DefaultCipherAlgorithm; - DWORD dwFlags; - DWORD dwReserved; -}; - -struct WLAN_AVAILABLE_NETWORK_LIST { - DWORD dwNumberOfItems; - DWORD dwIndex; - WLAN_AVAILABLE_NETWORK Network[1]; -}; - -enum WLAN_INTF_OPCODE { - wlan_intf_opcode_autoconf_start = 0x000000000, - wlan_intf_opcode_autoconf_enabled, - wlan_intf_opcode_background_scan_enabled, - wlan_intf_opcode_media_streaming_mode, - wlan_intf_opcode_radio_state, - wlan_intf_opcode_bss_type, - wlan_intf_opcode_interface_state, - wlan_intf_opcode_current_connection, - wlan_intf_opcode_channel_number, - wlan_intf_opcode_supported_infrastructure_auth_cipher_pairs, - wlan_intf_opcode_supported_adhoc_auth_cipher_pairs, - wlan_intf_opcode_supported_country_or_region_string_list, - wlan_intf_opcode_current_operation_mode, - wlan_intf_opcode_supported_safe_mode, - wlan_intf_opcode_certified_safe_mode, - wlan_intf_opcode_autoconf_end = 0x0fffffff, - wlan_intf_opcode_msm_start = 0x10000100, - wlan_intf_opcode_statistics, - wlan_intf_opcode_rssi, - wlan_intf_opcode_msm_end = 0x1fffffff, - wlan_intf_opcode_security_start = 0x20010000, - wlan_intf_opcode_security_end = 0x2fffffff, - wlan_intf_opcode_ihv_start = 0x30000000, - wlan_intf_opcode_ihv_end = 0x3fffffff -}; - -enum WLAN_OPCODE_VALUE_TYPE { - wlan_opcode_value_type_query_only = 0, - wlan_opcode_value_type_set_by_group_policy, - wlan_opcode_value_type_set_by_user, - wlan_opcode_value_type_invalid -}; - -enum WLAN_CONNECTION_MODE { - wlan_connection_mode_profile = 0, - wlan_connection_mode_temporary_profile, - wlan_connection_mode_discovery_secure, - wlan_connection_mode_discovery_unsecure, - wlan_connection_mode_auto, - wlan_connection_mode_invalid -}; - -struct WLAN_CONNECTION_PARAMETERS { - WLAN_CONNECTION_MODE wlanConnectionMode; - LPCWSTR strProfile; - DOT11_SSID *pDot11Ssid; - DOT11_BSSID_LIST *pDesiredBssidList; - DOT11_BSS_TYPE dot11BssType; - DWORD dwFlags; -}; - -struct WLAN_RAW_DATA { - DWORD dwDataSize; - BYTE DataBlob[1]; -}; - -enum WLAN_NOTIFICATION_ACM { - wlan_notification_acm_start = 0, - wlan_notification_acm_autoconf_enabled, - wlan_notification_acm_autoconf_disabled, - wlan_notification_acm_background_scan_enabled, - wlan_notification_acm_background_scan_disabled, - wlan_notification_acm_bss_type_change, - wlan_notification_acm_power_setting_change, - wlan_notification_acm_scan_complete, - wlan_notification_acm_scan_fail, - wlan_notification_acm_connection_start, - wlan_notification_acm_connection_complete, - wlan_notification_acm_connection_attempt_fail, - wlan_notification_acm_filter_list_change, - wlan_notification_acm_interface_arrival, - wlan_notification_acm_interface_removal, - wlan_notification_acm_profile_change, - wlan_notification_acm_profile_name_change, - wlan_notification_acm_profiles_exhausted, - wlan_notification_acm_network_not_available, - wlan_notification_acm_network_available, - wlan_notification_acm_disconnecting, - wlan_notification_acm_disconnected, - wlan_notification_acm_adhoc_network_state_change, - wlan_notification_acm_end -}; - -struct WLAN_ASSOCIATION_ATTRIBUTES { - DOT11_SSID dot11Ssid; - DOT11_BSS_TYPE dot11BssType; - DOT11_MAC_ADDRESS dot11Bssid; - DOT11_PHY_TYPE dot11PhyType; - ULONG uDot11PhyIndex; - ULONG wlanSignalQuality; - ULONG ulRxRate; - ULONG ulTxRate; -}; - -struct WLAN_SECURITY_ATTRIBUTES { - BOOL bSecurityEnabled; - BOOL bOneXEnabled; - DOT11_AUTH_ALGORITHM dot11AuthAlgorithm; - DOT11_CIPHER_ALGORITHM dot11CipherAlgorithm; -}; - -struct WLAN_CONNECTION_ATTRIBUTES { - WLAN_INTERFACE_STATE isState; - WLAN_CONNECTION_MODE wlanConnectionMode; - WCHAR strProfileName[WLAN_MAX_NAME_LENGTH]; - WLAN_ASSOCIATION_ATTRIBUTES wlanAssociationAttributes; - WLAN_SECURITY_ATTRIBUTES wlanSecurityAttributes; -}; - -typedef void (WINAPI *WLAN_NOTIFICATION_CALLBACK)(WLAN_NOTIFICATION_DATA *, PVOID); - -typedef DWORD (WINAPI *WlanOpenHandleProto) - (DWORD dwClientVersion, PVOID pReserved, PDWORD pdwNegotiatedVersion, PHANDLE phClientHandle); -typedef DWORD (WINAPI *WlanRegisterNotificationProto) - (HANDLE hClientHandle, DWORD dwNotifSource, BOOL bIgnoreDuplicate, - WLAN_NOTIFICATION_CALLBACK funcCallback, PVOID pCallbackContext, - PVOID pReserved, PDWORD pdwPrevNotifSource); -typedef DWORD (WINAPI *WlanEnumInterfacesProto) - (HANDLE hClientHandle, PVOID pReserved, WLAN_INTERFACE_INFO_LIST **ppInterfaceList); -typedef DWORD (WINAPI *WlanGetAvailableNetworkListProto) - (HANDLE hClientHandle, const GUID* pInterfaceGuid, DWORD dwFlags, PVOID pReserved, - WLAN_AVAILABLE_NETWORK_LIST **ppAvailableNetworkList); -typedef DWORD (WINAPI *WlanQueryInterfaceProto) - (HANDLE hClientHandle, const GUID *pInterfaceGuid, WLAN_INTF_OPCODE OpCode, PVOID pReserved, - PDWORD pdwDataSize, PVOID *ppData, WLAN_OPCODE_VALUE_TYPE *pWlanOpcodeValueType); -typedef DWORD (WINAPI *WlanConnectProto) - (HANDLE hClientHandle, const GUID *pInterfaceGuid, - const WLAN_CONNECTION_PARAMETERS *pConnectionParameters, PVOID pReserved); -typedef DWORD (WINAPI *WlanDisconnectProto) - (HANDLE hClientHandle, const GUID *pInterfaceGuid, PVOID pReserved); -typedef DWORD (WINAPI *WlanScanProto) - (HANDLE hClientHandle, const GUID *pInterfaceGuid, const DOT11_SSID *pDot11Ssid, - const WLAN_RAW_DATA *pIeData, PVOID pReserved); -typedef VOID (WINAPI *WlanFreeMemoryProto)(PVOID pMemory); -typedef DWORD (WINAPI *WlanCloseHandleProto)(HANDLE hClientHandle, PVOID pReserved); - -static WlanOpenHandleProto local_WlanOpenHandle = 0; -static WlanRegisterNotificationProto local_WlanRegisterNotification = 0; -static WlanEnumInterfacesProto local_WlanEnumInterfaces = 0; -static WlanGetAvailableNetworkListProto local_WlanGetAvailableNetworkList = 0; -static WlanQueryInterfaceProto local_WlanQueryInterface = 0; -static WlanConnectProto local_WlanConnect = 0; -static WlanDisconnectProto local_WlanDisconnect = 0; -static WlanScanProto local_WlanScan = 0; -static WlanFreeMemoryProto local_WlanFreeMemory = 0; -static WlanCloseHandleProto local_WlanCloseHandle = 0; - -static void resolveLibrary() -{ - static volatile bool triedResolve = false; - - if (!triedResolve) { -#ifndef QT_NO_THREAD - QMutexLocker locker(QMutexPool::globalInstanceGet(&local_WlanOpenHandle)); -#endif - - if (!triedResolve) { - local_WlanOpenHandle = (WlanOpenHandleProto) - QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanOpenHandle"); - local_WlanRegisterNotification = (WlanRegisterNotificationProto) - QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanRegisterNotification"); - local_WlanEnumInterfaces = (WlanEnumInterfacesProto) - QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanEnumInterfaces"); - local_WlanGetAvailableNetworkList = (WlanGetAvailableNetworkListProto) - QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanGetAvailableNetworkList"); - local_WlanQueryInterface = (WlanQueryInterfaceProto) - QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanQueryInterface"); - local_WlanConnect = (WlanConnectProto) - QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanConnect"); - local_WlanDisconnect = (WlanDisconnectProto) - QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanDisconnect"); - local_WlanScan = (WlanScanProto) - QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanScan"); - local_WlanFreeMemory = (WlanFreeMemoryProto) - QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanFreeMemory"); - local_WlanCloseHandle = (WlanCloseHandleProto) - QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanCloseHandle"); - - triedResolve = true; - } - } -} - -void qNotificationCallback(WLAN_NOTIFICATION_DATA *data, QNativeWifiEngine *d) -{ - Q_UNUSED(d); - - switch (data->NotificationCode) { - case wlan_notification_acm_connection_complete: - case wlan_notification_acm_disconnected: - d->emitConfigurationsChanged(); - break; - default: - qDebug() << "wlan unknown notification"; - } -} - -QNativeWifiEngine::QNativeWifiEngine(QObject *parent) -: QNetworkSessionEngine(parent), handle(0) -{ - DWORD clientVersion; - - DWORD result = local_WlanOpenHandle(1, 0, &clientVersion, &handle); - if (result != ERROR_SUCCESS) { - if (result != ERROR_SERVICE_NOT_ACTIVE) - qWarning("%s: WlanOpenHandle failed with error %ld\n", __FUNCTION__, result); - - return; - } - - result = local_WlanRegisterNotification(handle, WLAN_NOTIFICATION_SOURCE_ALL, true, - WLAN_NOTIFICATION_CALLBACK(qNotificationCallback), - this, 0, 0); - if (result != ERROR_SUCCESS) - qWarning("%s: WlanRegisterNotification failed with error %ld\n", __FUNCTION__, result); - - // On Windows XP SP2 and SP3 only connection and disconnection notifications are available. - // We need to poll for changes in available wireless networks. - connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); - pollTimer.setInterval(10000); -} - -QNativeWifiEngine::~QNativeWifiEngine() -{ - local_WlanCloseHandle(handle, 0); -} - -QList QNativeWifiEngine::getConfigurations(bool *ok) -{ - if (ok) - *ok = false; - - QList foundConfigurations; - - // enumerate interfaces - WLAN_INTERFACE_INFO_LIST *interfaceList; - DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); - if (result != ERROR_SUCCESS) { - qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); - return foundConfigurations; - } - - for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { - const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; - - WLAN_AVAILABLE_NETWORK_LIST *networkList; - result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid, - 3, 0, &networkList); - if (result != ERROR_SUCCESS) { - qWarning("%s: WlanGetAvailableNetworkList failed with error %ld\n", - __FUNCTION__, result); - continue; - } - - QStringList seenNetworks; - - for (unsigned int j = 0; j < networkList->dwNumberOfItems; ++j) { - WLAN_AVAILABLE_NETWORK &network = networkList->Network[j]; - - QString networkName; - - if (network.strProfileName[0] != 0) { - networkName = QString::fromWCharArray(network.strProfileName); - } else { - networkName = QByteArray(reinterpret_cast(network.dot11Ssid.ucSSID), - network.dot11Ssid.uSSIDLength); - } - - // don't add duplicate networks - if (seenNetworks.contains(networkName)) - continue; - else - seenNetworks.append(networkName); - - QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; - - cpPriv->isValid = true; - - cpPriv->name = networkName; - cpPriv->id = QString::number(qHash(QLatin1String("WLAN:") + cpPriv->name)); - - if (!(network.dwFlags & WLAN_AVAILABLE_NETWORK_HAS_PROFILE)) - cpPriv->state = QNetworkConfiguration::Undefined; - - if (network.strProfileName[0] != 0) { - if (network.bNetworkConnectable) { - if (network.dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) - cpPriv->state = QNetworkConfiguration::Active; - else - cpPriv->state = QNetworkConfiguration::Discovered; - } else { - cpPriv->state = QNetworkConfiguration::Defined; - } - } - - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - - foundConfigurations.append(cpPriv); - } - - local_WlanFreeMemory(networkList); - } - - local_WlanFreeMemory(interfaceList); - - if (ok) - *ok = true; - - pollTimer.start(); - - return foundConfigurations; -} - -QString QNativeWifiEngine::getInterfaceFromId(const QString &id) -{ - // enumerate interfaces - WLAN_INTERFACE_INFO_LIST *interfaceList; - DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); - if (result != ERROR_SUCCESS) { - qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); - return QString(); - } - - for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { - const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; - - DWORD dataSize; - WLAN_CONNECTION_ATTRIBUTES *connectionAttributes; - result = local_WlanQueryInterface(handle, &interface.InterfaceGuid, - wlan_intf_opcode_current_connection, 0, &dataSize, - reinterpret_cast(&connectionAttributes), 0); - if (result != ERROR_SUCCESS) { - if (result != ERROR_INVALID_STATE) - qWarning("%s: WlanQueryInterface failed with error %ld\n", __FUNCTION__, result); - - continue; - } - - if (qHash(QLatin1String("WLAN:") + - QString::fromWCharArray(connectionAttributes->strProfileName)) == id.toUInt()) { - QString guid("{%1-%2-%3-%4%5-%6%7%8%9%10%11}"); - - guid = guid.arg(interface.InterfaceGuid.Data1, 8, 16, QChar('0')); - guid = guid.arg(interface.InterfaceGuid.Data2, 4, 16, QChar('0')); - guid = guid.arg(interface.InterfaceGuid.Data3, 4, 16, QChar('0')); - for (int i = 0; i < 8; ++i) - guid = guid.arg(interface.InterfaceGuid.Data4[i], 2, 16, QChar('0')); - - local_WlanFreeMemory(connectionAttributes); - - return guid.toUpper(); - } - - local_WlanFreeMemory(connectionAttributes); - } - - return QString(); -} - -bool QNativeWifiEngine::hasIdentifier(const QString &id) -{ - // enumerate interfaces - WLAN_INTERFACE_INFO_LIST *interfaceList; - DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); - if (result != ERROR_SUCCESS) { - qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); - return false; - } - - for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { - const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; - - WLAN_AVAILABLE_NETWORK_LIST *networkList; - result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid, - 3, 0, &networkList); - if (result != ERROR_SUCCESS) { - qWarning("%s: WlanGetAvailableNetworkList failed with error %ld\n", - __FUNCTION__, result); - continue; - } - - for (unsigned int j = 0; j < networkList->dwNumberOfItems; ++j) { - WLAN_AVAILABLE_NETWORK &network = networkList->Network[j]; - - QString networkName; - - if (network.strProfileName[0] != 0) { - networkName = QString::fromWCharArray(network.strProfileName); - } else { - networkName = QByteArray(reinterpret_cast(network.dot11Ssid.ucSSID), - network.dot11Ssid.uSSIDLength); - } - - if (qHash(QLatin1String("WLAN:") + networkName) == id.toUInt()) { - local_WlanFreeMemory(networkList); - local_WlanFreeMemory(interfaceList); - return true; - } - } - - local_WlanFreeMemory(networkList); - } - - local_WlanFreeMemory(interfaceList); - - return false; -} - -QString QNativeWifiEngine::bearerName(const QString &) -{ - return QLatin1String("WLAN"); -} - -void QNativeWifiEngine::connectToId(const QString &id) -{ - WLAN_INTERFACE_INFO_LIST *interfaceList; - DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); - if (result != ERROR_SUCCESS) { - qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); - emit connectionError(id, InterfaceLookupError); - return; - } - - QString profile; - - for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { - const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; - - WLAN_AVAILABLE_NETWORK_LIST *networkList; - result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid, - 3, 0, &networkList); - if (result != ERROR_SUCCESS) { - qWarning("%s: WlanGetAvailableNetworkList failed with error %ld\n", - __FUNCTION__, result); - continue; - } - - for (unsigned int j = 0; j < networkList->dwNumberOfItems; ++j) { - WLAN_AVAILABLE_NETWORK &network = networkList->Network[j]; - - profile = QString::fromWCharArray(network.strProfileName); - - if (qHash(QLatin1String("WLAN:") + profile) == id.toUInt()) - break; - else - profile.clear(); - } - - local_WlanFreeMemory(networkList); - - if (!profile.isEmpty()) { - WLAN_CONNECTION_PARAMETERS parameters; - parameters.wlanConnectionMode = wlan_connection_mode_profile; - parameters.strProfile = reinterpret_cast(profile.utf16()); - parameters.pDot11Ssid = 0; - parameters.pDesiredBssidList = 0; - parameters.dot11BssType = dot11_BSS_type_any; - parameters.dwFlags = 0; - - DWORD result = local_WlanConnect(handle, &interface.InterfaceGuid, ¶meters, 0); - if (result != ERROR_SUCCESS) { - qWarning("%s: WlanConnect failed with error %ld\n", __FUNCTION__, result); - emit connectionError(id, ConnectError); - break; - } - - break; - } - } - - local_WlanFreeMemory(interfaceList); - - if (profile.isEmpty()) - emit connectionError(id, InterfaceLookupError); -} - -void QNativeWifiEngine::disconnectFromId(const QString &id) -{ - QString interface = getInterfaceFromId(id); - - if (interface.isEmpty()) { - emit connectionError(id, InterfaceLookupError); - return; - } - - QStringList split = interface.mid(1, interface.length() - 2).split('-'); - - GUID guid; - guid.Data1 = split.at(0).toUInt(0, 16); - guid.Data2 = split.at(1).toUShort(0, 16); - guid.Data3 = split.at(2).toUShort(0, 16); - guid.Data4[0] = split.at(3).left(2).toUShort(0, 16); - guid.Data4[1] = split.at(3).right(2).toUShort(0, 16); - for (int i = 0; i < 6; ++i) - guid.Data4[i + 2] = split.at(4).mid(i*2, 2).toUShort(0, 16); - - DWORD result = local_WlanDisconnect(handle, &guid, 0); - if (result != ERROR_SUCCESS) { - qWarning("%s: WlanDisconnect failed with error %ld\n", __FUNCTION__, result); - emit connectionError(id, DisconnectionError); - return; - } -} - -void QNativeWifiEngine::requestUpdate() -{ - // enumerate interfaces - WLAN_INTERFACE_INFO_LIST *interfaceList; - DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); - if (result != ERROR_SUCCESS) { - qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); - return; - } - - for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { - result = local_WlanScan(handle, &interfaceList->InterfaceInfo[i].InterfaceGuid, 0, 0, 0); - if (result != ERROR_SUCCESS) - qWarning("%s: WlanScan failed with error %ld\n", __FUNCTION__, result); - } -} - -QNativeWifiEngine *QNativeWifiEngine::instance() -{ - resolveLibrary(); - - // native wifi dll not available - if (!local_WlanOpenHandle) - return 0; - - QNativeWifiEngine *engine = nativeWifiEngine(); - - // could not initialise subsystem - if (engine && engine->handle == 0) - return 0; - - return engine; -} - -#include "moc_qnativewifiengine_win_p.cpp" - -QT_END_NAMESPACE diff --git a/src/network/bearer/qnativewifiengine_win_p.h b/src/network/bearer/qnativewifiengine_win_p.h deleted file mode 100644 index 4817867..0000000 --- a/src/network/bearer/qnativewifiengine_win_p.h +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QNATIVEWIFIENGINE_P_H -#define QNATIVEWIFIENGINE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qnetworksessionengine_p.h" - -#include - -QT_BEGIN_NAMESPACE - -class QNetworkConfigurationPrivate; - -class QNativeWifiEngine : public QNetworkSessionEngine -{ - Q_OBJECT - -public: - QNativeWifiEngine(QObject *parent = 0); - ~QNativeWifiEngine(); - - QList getConfigurations(bool *ok = 0); - QString getInterfaceFromId(const QString &id); - bool hasIdentifier(const QString &id); - - QString bearerName(const QString &id); - - void connectToId(const QString &id); - void disconnectFromId(const QString &id); - - void requestUpdate(); - - inline void emitConfigurationsChanged() { emit configurationsChanged(); } - - static QNativeWifiEngine *instance(); - -private: - QTimer pollTimer; - - Qt::HANDLE handle; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index c61bcd3..c35edbf 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -41,9 +41,6 @@ #include "qnetworkconfigmanager_p.h" -#ifdef Q_OS_WIN32 -#include "qnativewifiengine_win_p.h" -#endif #ifdef Q_OS_DARWIN #include "qcorewlanengine_mac_p.h" #endif @@ -239,6 +236,7 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() } #else #ifdef BACKEND_NM + nmWifi = 0; if (keys.contains(QLatin1String("networkmanager"))) { QBearerEnginePlugin *nmPlugin = qobject_cast(l->instance(QLatin1String("networkmanager"))); @@ -252,6 +250,7 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() } #endif + generic = 0; if (keys.contains(QLatin1String("generic"))) { QBearerEnginePlugin *genericPlugin = qobject_cast(l->instance(QLatin1String("generic"))); @@ -266,10 +265,12 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() #endif #ifdef Q_OS_WIN + nla = 0; if (keys.contains(QLatin1String("nla"))) { QBearerEnginePlugin *nlaPlugin = qobject_cast(l->instance(QLatin1String("nla"))); if (nlaPlugin) { + qDebug() << "creating nla backend"; nla = nlaPlugin->create(QLatin1String("nla")); if (nla) { connect(nla, SIGNAL(configurationsChanged()), @@ -280,13 +281,21 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() #endif #ifdef Q_OS_WIN32 - nativeWifi = QNativeWifiEngine::instance(); - if (nativeWifi) { - connect(nativeWifi, SIGNAL(configurationsChanged()), - this, SLOT(updateConfigurations())); + nativeWifi = 0; + if (keys.contains(QLatin1String("nativewifi"))) { + QBearerEnginePlugin *nativeWifiPlugin = + qobject_cast(l->instance(QLatin1String("nativewifi"))); + if (nativeWifiPlugin) { + qDebug() << "Creating native wifi backend"; + nativeWifi = nativeWifiPlugin->create(QLatin1String("nativewifi")); + if (nativeWifi) { + connect(nativeWifi, SIGNAL(configurationsChanged()), + this, SLOT(updateConfigurations())); - capFlags |= QNetworkConfigurationManager::CanStartAndStopInterfaces; + capFlags |= QNetworkConfigurationManager::CanStartAndStopInterfaces; + } } + } #endif } diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 7b824f0..5d0df18 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -139,7 +139,7 @@ private: #ifdef Q_OS_WIN QNetworkSessionEngine *nla; #ifndef Q_OS_WINCE - QNativeWifiEngine *nativeWifi; + QNetworkSessionEngine *nativeWifi; #endif #endif #ifdef BACKEND_NM diff --git a/src/network/bearer/qnetworksession_p.cpp b/src/network/bearer/qnetworksession_p.cpp index 1ce94e2..3c9054b 100644 --- a/src/network/bearer/qnetworksession_p.cpp +++ b/src/network/bearer/qnetworksession_p.cpp @@ -44,9 +44,6 @@ #include "qnetworksessionengine_p.h" #include "qnetworkconfigmanager_p.h" -#ifdef Q_OS_WIN32 -#include "qnativewifiengine_win_p.h" -#endif #ifdef Q_OS_DARWIN #include "qcorewlanengine_mac_p.h" #endif @@ -64,12 +61,6 @@ static QNetworkSessionEngine *getEngineFromId(const QString &id) { QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); -#ifdef Q_OS_WIN32 - QNativeWifiEngine *nativeWifi = QNativeWifiEngine::instance(); - if (nativeWifi && nativeWifi->hasIdentifier(id)) - return nativeWifi; -#endif - #ifdef Q_OS_DARWIN QCoreWlanEngine *coreWifi = QCoreWlanEngine::instance(); if (coreWifi && coreWifi->hasIdentifier(id)) diff --git a/src/plugins/bearer/bearer.pro b/src/plugins/bearer/bearer.pro index 51323b0..80d6f4b 100644 --- a/src/plugins/bearer/bearer.pro +++ b/src/plugins/bearer/bearer.pro @@ -3,3 +3,4 @@ TEMPLATE = subdirs SUBDIRS += generic contains(QT_CONFIG, dbus):contains(QT_CONFIG, networkmanager):SUBDIRS += networkmanager win32:SUBDIRS += nla +win32:!wince*:SUBDIRS += nativewifi diff --git a/src/plugins/bearer/nativewifi/main.cpp b/src/plugins/bearer/nativewifi/main.cpp new file mode 100644 index 0000000..2aced02 --- /dev/null +++ b/src/plugins/bearer/nativewifi/main.cpp @@ -0,0 +1,143 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnativewifiengine.h" +#include "platformdefs.h" + +#include +#include +#include + +#include + +#include + +QT_BEGIN_NAMESPACE + +static void resolveLibrary() +{ + static volatile bool triedResolve = false; + + if (!triedResolve) { +#ifndef QT_NO_THREAD + QMutexLocker locker(QMutexPool::globalInstanceGet(&local_WlanOpenHandle)); +#endif + + if (!triedResolve) { + local_WlanOpenHandle = (WlanOpenHandleProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanOpenHandle"); + local_WlanRegisterNotification = (WlanRegisterNotificationProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanRegisterNotification"); + local_WlanEnumInterfaces = (WlanEnumInterfacesProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanEnumInterfaces"); + local_WlanGetAvailableNetworkList = (WlanGetAvailableNetworkListProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanGetAvailableNetworkList"); + local_WlanQueryInterface = (WlanQueryInterfaceProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanQueryInterface"); + local_WlanConnect = (WlanConnectProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanConnect"); + local_WlanDisconnect = (WlanDisconnectProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanDisconnect"); + local_WlanScan = (WlanScanProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanScan"); + local_WlanFreeMemory = (WlanFreeMemoryProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanFreeMemory"); + local_WlanCloseHandle = (WlanCloseHandleProto) + QLibrary::resolve(QLatin1String("wlanapi.dll"), "WlanCloseHandle"); + + triedResolve = true; + } + } +} + +class QNativeWifiEnginePlugin : public QBearerEnginePlugin +{ +public: + QNativeWifiEnginePlugin(); + ~QNativeWifiEnginePlugin(); + + QStringList keys() const; + QBearerEngine *create(const QString &key) const; +}; + +QNativeWifiEnginePlugin::QNativeWifiEnginePlugin() +{ +} + +QNativeWifiEnginePlugin::~QNativeWifiEnginePlugin() +{ +} + +QStringList QNativeWifiEnginePlugin::keys() const +{ + qDebug() << Q_FUNC_INFO; + + return QStringList() << QLatin1String("nativewifi"); +} + +QBearerEngine *QNativeWifiEnginePlugin::create(const QString &key) const +{ + qDebug() << Q_FUNC_INFO; + + if (key != QLatin1String("nativewifi")) + return 0; + + resolveLibrary(); + + // native wifi dll not available + if (!local_WlanOpenHandle) + return 0; + + QNativeWifiEngine *engine = new QNativeWifiEngine; + + // could not initialise subsystem + if (engine && !engine->available()) { + delete engine; + return 0; + } + + return engine; +} + +Q_EXPORT_STATIC_PLUGIN(QNativeWifiEnginePlugin) +Q_EXPORT_PLUGIN2(qnativewifibearer, QNativeWifiEnginePlugin) + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/nativewifi/nativewifi.pro b/src/plugins/bearer/nativewifi/nativewifi.pro new file mode 100644 index 0000000..3aab552 --- /dev/null +++ b/src/plugins/bearer/nativewifi/nativewifi.pro @@ -0,0 +1,13 @@ +TARGET = qnativewifibearer +include(../../qpluginbase.pri) + +QT += network + +DEFINES += BEARER_ENGINE + +HEADERS += qnativewifiengine.h platformdefs.h +SOURCES += qnativewifiengine.cpp main.cpp + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer +target.path += $$[QT_INSTALL_PLUGINS]/bearer +INSTALLS += target diff --git a/src/plugins/bearer/nativewifi/platformdefs.h b/src/plugins/bearer/nativewifi/platformdefs.h new file mode 100644 index 0000000..38fbae4 --- /dev/null +++ b/src/plugins/bearer/nativewifi/platformdefs.h @@ -0,0 +1,322 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PLATFORMDEFS_H +#define PLATFORMDEFS_H + +#include +#undef interface + +#define WLAN_MAX_NAME_LENGTH 256 +#define WLAN_MAX_PHY_TYPE_NUMBER 8 +#define WLAN_NOTIFICATION_SOURCE_ALL 0x0000ffff +#define WLAN_AVAILABLE_NETWORK_CONNECTED 1 +#define WLAN_AVAILABLE_NETWORK_HAS_PROFILE 2 +#define DOT11_SSID_MAX_LENGTH 32 + +struct WLAN_NOTIFICATION_DATA { + DWORD NotificationSource; + DWORD NotificationCode; + GUID InterfaceGuid; + DWORD dwDataSize; + PVOID pData; +}; + +enum WLAN_INTERFACE_STATE { + wlan_interface_state_not_ready = 0, + wlan_interface_state_connected, + wlan_interface_state_ad_hoc_network_formed, + wlan_interface_state_disconnecting, + wlan_interface_state_disconnected, + wlan_interface_state_associating, + wlan_interface_state_discovering, + wlan_interface_state_authenticating +}; + +struct WLAN_INTERFACE_INFO { + GUID InterfaceGuid; + WCHAR strInterfaceDescription[WLAN_MAX_NAME_LENGTH]; + WLAN_INTERFACE_STATE isState; +}; + +struct WLAN_INTERFACE_INFO_LIST { + DWORD dwNumberOfItems; + DWORD dwIndex; + WLAN_INTERFACE_INFO InterfaceInfo[1]; +}; + +struct DOT11_SSID { + ULONG uSSIDLength; + UCHAR ucSSID[DOT11_SSID_MAX_LENGTH]; +}; + +struct NDIS_OBJECT_HEADER { + UCHAR Type; + UCHAR Revision; + USHORT Size; +}; + +typedef UCHAR DOT11_MAC_ADDRESS[6]; +struct DOT11_BSSID_LIST { + NDIS_OBJECT_HEADER Header; + ULONG uNumberOfEntries; + ULONG uTotalNumOfEntries; + DOT11_MAC_ADDRESS BSSIDs[1]; +}; + +enum DOT11_BSS_TYPE { + dot11_BSS_type_infrastructure = 1, + dot11_BSS_type_independent = 2, + dot11_BSS_type_any = 3 +}; + +enum DOT11_PHY_TYPE { + dot11_phy_type_unknown = 0, + dot11_phy_type_any = dot11_phy_type_unknown, + dot11_phy_type_fhss = 1, + dot11_phy_type_dsss = 2, + dot11_phy_type_irbaseband = 3, + dot11_phy_type_ofdm = 4, + dot11_phy_type_hrdsss = 5, + dot11_phy_type_erp = 6, + dot11_phy_type_ht = 7, + dot11_phy_type_IHV_start = 0x80000000, + dot11_phy_type_IHV_end = 0xffffffff +}; + +enum DOT11_AUTH_ALGORITHM { + DOT11_AUTH_ALGO_80211_OPEN = 1, + DOT11_AUTH_ALGO_80211_SHARED_KEY = 2, + DOT11_AUTH_ALGO_WPA = 3, + DOT11_AUTH_ALGO_WPA_PSK = 4, + DOT11_AUTH_ALGO_WPA_NONE = 5, + DOT11_AUTH_ALGO_RSNA = 6, + DOT11_AUTH_ALGO_RSNA_PSK = 7, + DOT11_AUTH_ALGO_IHV_START = 0x80000000, + DOT11_AUTH_ALGO_IHV_END = 0xffffffff +}; + +enum DOT11_CIPHER_ALGORITHM { + DOT11_CIPHER_ALGO_NONE = 0x00, + DOT11_CIPHER_ALGO_WEP40 = 0x01, + DOT11_CIPHER_ALGO_TKIP = 0x02, + DOT11_CIPHER_ALGO_CCMP = 0x04, + DOT11_CIPHER_ALGO_WEP104 = 0x05, + DOT11_CIPHER_ALGO_WPA_USE_GROUP = 0x100, + DOT11_CIPHER_ALGO_RSN_USE_GROUP = 0x100, + DOT11_CIPHER_ALGO_WEP = 0x101, + DOT11_CIPHER_ALGO_IHV_START = 0x80000000, + DOT11_CIPHER_ALGO_IHV_END = 0xffffffff +}; + +struct WLAN_AVAILABLE_NETWORK { + WCHAR strProfileName[WLAN_MAX_NAME_LENGTH]; + DOT11_SSID dot11Ssid; + DOT11_BSS_TYPE dot11BssType; + ULONG uNumberOfBssids; + BOOL bNetworkConnectable; + DWORD wlanNotConnectableReason; + ULONG uNumberOfPhyTypes; + DOT11_PHY_TYPE dot11PhyTypes[WLAN_MAX_PHY_TYPE_NUMBER]; + BOOL bMorePhyTypes; + ULONG wlanSignalQuality; + BOOL bSecurityEnabled; + DOT11_AUTH_ALGORITHM dot11DefaultAuthAlgorithm; + DOT11_CIPHER_ALGORITHM dot11DefaultCipherAlgorithm; + DWORD dwFlags; + DWORD dwReserved; +}; + +struct WLAN_AVAILABLE_NETWORK_LIST { + DWORD dwNumberOfItems; + DWORD dwIndex; + WLAN_AVAILABLE_NETWORK Network[1]; +}; + +enum WLAN_INTF_OPCODE { + wlan_intf_opcode_autoconf_start = 0x000000000, + wlan_intf_opcode_autoconf_enabled, + wlan_intf_opcode_background_scan_enabled, + wlan_intf_opcode_media_streaming_mode, + wlan_intf_opcode_radio_state, + wlan_intf_opcode_bss_type, + wlan_intf_opcode_interface_state, + wlan_intf_opcode_current_connection, + wlan_intf_opcode_channel_number, + wlan_intf_opcode_supported_infrastructure_auth_cipher_pairs, + wlan_intf_opcode_supported_adhoc_auth_cipher_pairs, + wlan_intf_opcode_supported_country_or_region_string_list, + wlan_intf_opcode_current_operation_mode, + wlan_intf_opcode_supported_safe_mode, + wlan_intf_opcode_certified_safe_mode, + wlan_intf_opcode_autoconf_end = 0x0fffffff, + wlan_intf_opcode_msm_start = 0x10000100, + wlan_intf_opcode_statistics, + wlan_intf_opcode_rssi, + wlan_intf_opcode_msm_end = 0x1fffffff, + wlan_intf_opcode_security_start = 0x20010000, + wlan_intf_opcode_security_end = 0x2fffffff, + wlan_intf_opcode_ihv_start = 0x30000000, + wlan_intf_opcode_ihv_end = 0x3fffffff +}; + +enum WLAN_OPCODE_VALUE_TYPE { + wlan_opcode_value_type_query_only = 0, + wlan_opcode_value_type_set_by_group_policy, + wlan_opcode_value_type_set_by_user, + wlan_opcode_value_type_invalid +}; + +enum WLAN_CONNECTION_MODE { + wlan_connection_mode_profile = 0, + wlan_connection_mode_temporary_profile, + wlan_connection_mode_discovery_secure, + wlan_connection_mode_discovery_unsecure, + wlan_connection_mode_auto, + wlan_connection_mode_invalid +}; + +struct WLAN_CONNECTION_PARAMETERS { + WLAN_CONNECTION_MODE wlanConnectionMode; + LPCWSTR strProfile; + DOT11_SSID *pDot11Ssid; + DOT11_BSSID_LIST *pDesiredBssidList; + DOT11_BSS_TYPE dot11BssType; + DWORD dwFlags; +}; + +struct WLAN_RAW_DATA { + DWORD dwDataSize; + BYTE DataBlob[1]; +}; + +enum WLAN_NOTIFICATION_ACM { + wlan_notification_acm_start = 0, + wlan_notification_acm_autoconf_enabled, + wlan_notification_acm_autoconf_disabled, + wlan_notification_acm_background_scan_enabled, + wlan_notification_acm_background_scan_disabled, + wlan_notification_acm_bss_type_change, + wlan_notification_acm_power_setting_change, + wlan_notification_acm_scan_complete, + wlan_notification_acm_scan_fail, + wlan_notification_acm_connection_start, + wlan_notification_acm_connection_complete, + wlan_notification_acm_connection_attempt_fail, + wlan_notification_acm_filter_list_change, + wlan_notification_acm_interface_arrival, + wlan_notification_acm_interface_removal, + wlan_notification_acm_profile_change, + wlan_notification_acm_profile_name_change, + wlan_notification_acm_profiles_exhausted, + wlan_notification_acm_network_not_available, + wlan_notification_acm_network_available, + wlan_notification_acm_disconnecting, + wlan_notification_acm_disconnected, + wlan_notification_acm_adhoc_network_state_change, + wlan_notification_acm_end +}; + +struct WLAN_ASSOCIATION_ATTRIBUTES { + DOT11_SSID dot11Ssid; + DOT11_BSS_TYPE dot11BssType; + DOT11_MAC_ADDRESS dot11Bssid; + DOT11_PHY_TYPE dot11PhyType; + ULONG uDot11PhyIndex; + ULONG wlanSignalQuality; + ULONG ulRxRate; + ULONG ulTxRate; +}; + +struct WLAN_SECURITY_ATTRIBUTES { + BOOL bSecurityEnabled; + BOOL bOneXEnabled; + DOT11_AUTH_ALGORITHM dot11AuthAlgorithm; + DOT11_CIPHER_ALGORITHM dot11CipherAlgorithm; +}; + +struct WLAN_CONNECTION_ATTRIBUTES { + WLAN_INTERFACE_STATE isState; + WLAN_CONNECTION_MODE wlanConnectionMode; + WCHAR strProfileName[WLAN_MAX_NAME_LENGTH]; + WLAN_ASSOCIATION_ATTRIBUTES wlanAssociationAttributes; + WLAN_SECURITY_ATTRIBUTES wlanSecurityAttributes; +}; + +typedef void (WINAPI *WLAN_NOTIFICATION_CALLBACK)(WLAN_NOTIFICATION_DATA *, PVOID); + +typedef DWORD (WINAPI *WlanOpenHandleProto) + (DWORD dwClientVersion, PVOID pReserved, PDWORD pdwNegotiatedVersion, PHANDLE phClientHandle); +typedef DWORD (WINAPI *WlanRegisterNotificationProto) + (HANDLE hClientHandle, DWORD dwNotifSource, BOOL bIgnoreDuplicate, + WLAN_NOTIFICATION_CALLBACK funcCallback, PVOID pCallbackContext, + PVOID pReserved, PDWORD pdwPrevNotifSource); +typedef DWORD (WINAPI *WlanEnumInterfacesProto) + (HANDLE hClientHandle, PVOID pReserved, WLAN_INTERFACE_INFO_LIST **ppInterfaceList); +typedef DWORD (WINAPI *WlanGetAvailableNetworkListProto) + (HANDLE hClientHandle, const GUID* pInterfaceGuid, DWORD dwFlags, PVOID pReserved, + WLAN_AVAILABLE_NETWORK_LIST **ppAvailableNetworkList); +typedef DWORD (WINAPI *WlanQueryInterfaceProto) + (HANDLE hClientHandle, const GUID *pInterfaceGuid, WLAN_INTF_OPCODE OpCode, PVOID pReserved, + PDWORD pdwDataSize, PVOID *ppData, WLAN_OPCODE_VALUE_TYPE *pWlanOpcodeValueType); +typedef DWORD (WINAPI *WlanConnectProto) + (HANDLE hClientHandle, const GUID *pInterfaceGuid, + const WLAN_CONNECTION_PARAMETERS *pConnectionParameters, PVOID pReserved); +typedef DWORD (WINAPI *WlanDisconnectProto) + (HANDLE hClientHandle, const GUID *pInterfaceGuid, PVOID pReserved); +typedef DWORD (WINAPI *WlanScanProto) + (HANDLE hClientHandle, const GUID *pInterfaceGuid, const DOT11_SSID *pDot11Ssid, + const WLAN_RAW_DATA *pIeData, PVOID pReserved); +typedef VOID (WINAPI *WlanFreeMemoryProto)(PVOID pMemory); +typedef DWORD (WINAPI *WlanCloseHandleProto)(HANDLE hClientHandle, PVOID pReserved); + +extern WlanOpenHandleProto local_WlanOpenHandle; +extern WlanRegisterNotificationProto local_WlanRegisterNotification; +extern WlanEnumInterfacesProto local_WlanEnumInterfaces; +extern WlanGetAvailableNetworkListProto local_WlanGetAvailableNetworkList; +extern WlanQueryInterfaceProto local_WlanQueryInterface; +extern WlanConnectProto local_WlanConnect; +extern WlanDisconnectProto local_WlanDisconnect; +extern WlanScanProto local_WlanScan; +extern WlanFreeMemoryProto local_WlanFreeMemory; +extern WlanCloseHandleProto local_WlanCloseHandle; + +#endif // PLATFORMDEFS_H diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp new file mode 100644 index 0000000..5ca49a9 --- /dev/null +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp @@ -0,0 +1,406 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnativewifiengine.h" +#include "platformdefs.h" + +#include + +#include + +#include + +QT_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QNativeWifiEngine, nativeWifiEngine) + +WlanOpenHandleProto local_WlanOpenHandle = 0; +WlanRegisterNotificationProto local_WlanRegisterNotification = 0; +WlanEnumInterfacesProto local_WlanEnumInterfaces = 0; +WlanGetAvailableNetworkListProto local_WlanGetAvailableNetworkList = 0; +WlanQueryInterfaceProto local_WlanQueryInterface = 0; +WlanConnectProto local_WlanConnect = 0; +WlanDisconnectProto local_WlanDisconnect = 0; +WlanScanProto local_WlanScan = 0; +WlanFreeMemoryProto local_WlanFreeMemory = 0; +WlanCloseHandleProto local_WlanCloseHandle = 0; + + + +void qNotificationCallback(WLAN_NOTIFICATION_DATA *data, QNativeWifiEngine *d) +{ + Q_UNUSED(d); + + switch (data->NotificationCode) { + case wlan_notification_acm_connection_complete: + case wlan_notification_acm_disconnected: + d->emitConfigurationsChanged(); + break; + default: + qDebug() << "wlan unknown notification"; + } +} + +QNativeWifiEngine::QNativeWifiEngine(QObject *parent) +: QNetworkSessionEngine(parent), handle(0) +{ + DWORD clientVersion; + + DWORD result = local_WlanOpenHandle(1, 0, &clientVersion, &handle); + if (result != ERROR_SUCCESS) { + if (result != ERROR_SERVICE_NOT_ACTIVE) + qWarning("%s: WlanOpenHandle failed with error %ld\n", __FUNCTION__, result); + + return; + } + + result = local_WlanRegisterNotification(handle, WLAN_NOTIFICATION_SOURCE_ALL, true, + WLAN_NOTIFICATION_CALLBACK(qNotificationCallback), + this, 0, 0); + if (result != ERROR_SUCCESS) + qWarning("%s: WlanRegisterNotification failed with error %ld\n", __FUNCTION__, result); + + // On Windows XP SP2 and SP3 only connection and disconnection notifications are available. + // We need to poll for changes in available wireless networks. + connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); + pollTimer.setInterval(10000); +} + +QNativeWifiEngine::~QNativeWifiEngine() +{ + local_WlanCloseHandle(handle, 0); +} + +QList QNativeWifiEngine::getConfigurations(bool *ok) +{ + if (ok) + *ok = false; + + QList foundConfigurations; + + // enumerate interfaces + WLAN_INTERFACE_INFO_LIST *interfaceList; + DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); + return foundConfigurations; + } + + for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { + const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; + + WLAN_AVAILABLE_NETWORK_LIST *networkList; + result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid, + 3, 0, &networkList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanGetAvailableNetworkList failed with error %ld\n", + __FUNCTION__, result); + continue; + } + + QStringList seenNetworks; + + for (unsigned int j = 0; j < networkList->dwNumberOfItems; ++j) { + WLAN_AVAILABLE_NETWORK &network = networkList->Network[j]; + + QString networkName; + + if (network.strProfileName[0] != 0) { + networkName = QString::fromWCharArray(network.strProfileName); + } else { + networkName = QByteArray(reinterpret_cast(network.dot11Ssid.ucSSID), + network.dot11Ssid.uSSIDLength); + } + + // don't add duplicate networks + if (seenNetworks.contains(networkName)) + continue; + else + seenNetworks.append(networkName); + + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + + cpPriv->isValid = true; + + cpPriv->name = networkName; + cpPriv->id = QString::number(qHash(QLatin1String("WLAN:") + cpPriv->name)); + + if (!(network.dwFlags & WLAN_AVAILABLE_NETWORK_HAS_PROFILE)) + cpPriv->state = QNetworkConfiguration::Undefined; + + if (network.strProfileName[0] != 0) { + if (network.bNetworkConnectable) { + if (network.dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) + cpPriv->state = QNetworkConfiguration::Active; + else + cpPriv->state = QNetworkConfiguration::Discovered; + } else { + cpPriv->state = QNetworkConfiguration::Defined; + } + } + + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + + foundConfigurations.append(cpPriv); + } + + local_WlanFreeMemory(networkList); + } + + local_WlanFreeMemory(interfaceList); + + if (ok) + *ok = true; + + pollTimer.start(); + + return foundConfigurations; +} + +QString QNativeWifiEngine::getInterfaceFromId(const QString &id) +{ + // enumerate interfaces + WLAN_INTERFACE_INFO_LIST *interfaceList; + DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); + return QString(); + } + + for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { + const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; + + DWORD dataSize; + WLAN_CONNECTION_ATTRIBUTES *connectionAttributes; + result = local_WlanQueryInterface(handle, &interface.InterfaceGuid, + wlan_intf_opcode_current_connection, 0, &dataSize, + reinterpret_cast(&connectionAttributes), 0); + if (result != ERROR_SUCCESS) { + if (result != ERROR_INVALID_STATE) + qWarning("%s: WlanQueryInterface failed with error %ld\n", __FUNCTION__, result); + + continue; + } + + if (qHash(QLatin1String("WLAN:") + + QString::fromWCharArray(connectionAttributes->strProfileName)) == id.toUInt()) { + QString guid("{%1-%2-%3-%4%5-%6%7%8%9%10%11}"); + + guid = guid.arg(interface.InterfaceGuid.Data1, 8, 16, QChar('0')); + guid = guid.arg(interface.InterfaceGuid.Data2, 4, 16, QChar('0')); + guid = guid.arg(interface.InterfaceGuid.Data3, 4, 16, QChar('0')); + for (int i = 0; i < 8; ++i) + guid = guid.arg(interface.InterfaceGuid.Data4[i], 2, 16, QChar('0')); + + local_WlanFreeMemory(connectionAttributes); + + return guid.toUpper(); + } + + local_WlanFreeMemory(connectionAttributes); + } + + return QString(); +} + +bool QNativeWifiEngine::hasIdentifier(const QString &id) +{ + // enumerate interfaces + WLAN_INTERFACE_INFO_LIST *interfaceList; + DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); + return false; + } + + for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { + const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; + + WLAN_AVAILABLE_NETWORK_LIST *networkList; + result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid, + 3, 0, &networkList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanGetAvailableNetworkList failed with error %ld\n", + __FUNCTION__, result); + continue; + } + + for (unsigned int j = 0; j < networkList->dwNumberOfItems; ++j) { + WLAN_AVAILABLE_NETWORK &network = networkList->Network[j]; + + QString networkName; + + if (network.strProfileName[0] != 0) { + networkName = QString::fromWCharArray(network.strProfileName); + } else { + networkName = QByteArray(reinterpret_cast(network.dot11Ssid.ucSSID), + network.dot11Ssid.uSSIDLength); + } + + if (qHash(QLatin1String("WLAN:") + networkName) == id.toUInt()) { + local_WlanFreeMemory(networkList); + local_WlanFreeMemory(interfaceList); + return true; + } + } + + local_WlanFreeMemory(networkList); + } + + local_WlanFreeMemory(interfaceList); + + return false; +} + +QString QNativeWifiEngine::bearerName(const QString &) +{ + return QLatin1String("WLAN"); +} + +void QNativeWifiEngine::connectToId(const QString &id) +{ + WLAN_INTERFACE_INFO_LIST *interfaceList; + DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); + emit connectionError(id, InterfaceLookupError); + return; + } + + QString profile; + + for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { + const WLAN_INTERFACE_INFO &interface = interfaceList->InterfaceInfo[i]; + + WLAN_AVAILABLE_NETWORK_LIST *networkList; + result = local_WlanGetAvailableNetworkList(handle, &interface.InterfaceGuid, + 3, 0, &networkList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanGetAvailableNetworkList failed with error %ld\n", + __FUNCTION__, result); + continue; + } + + for (unsigned int j = 0; j < networkList->dwNumberOfItems; ++j) { + WLAN_AVAILABLE_NETWORK &network = networkList->Network[j]; + + profile = QString::fromWCharArray(network.strProfileName); + + if (qHash(QLatin1String("WLAN:") + profile) == id.toUInt()) + break; + else + profile.clear(); + } + + local_WlanFreeMemory(networkList); + + if (!profile.isEmpty()) { + WLAN_CONNECTION_PARAMETERS parameters; + parameters.wlanConnectionMode = wlan_connection_mode_profile; + parameters.strProfile = reinterpret_cast(profile.utf16()); + parameters.pDot11Ssid = 0; + parameters.pDesiredBssidList = 0; + parameters.dot11BssType = dot11_BSS_type_any; + parameters.dwFlags = 0; + + DWORD result = local_WlanConnect(handle, &interface.InterfaceGuid, ¶meters, 0); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanConnect failed with error %ld\n", __FUNCTION__, result); + emit connectionError(id, ConnectError); + break; + } + + break; + } + } + + local_WlanFreeMemory(interfaceList); + + if (profile.isEmpty()) + emit connectionError(id, InterfaceLookupError); +} + +void QNativeWifiEngine::disconnectFromId(const QString &id) +{ + QString interface = getInterfaceFromId(id); + + if (interface.isEmpty()) { + emit connectionError(id, InterfaceLookupError); + return; + } + + QStringList split = interface.mid(1, interface.length() - 2).split('-'); + + GUID guid; + guid.Data1 = split.at(0).toUInt(0, 16); + guid.Data2 = split.at(1).toUShort(0, 16); + guid.Data3 = split.at(2).toUShort(0, 16); + guid.Data4[0] = split.at(3).left(2).toUShort(0, 16); + guid.Data4[1] = split.at(3).right(2).toUShort(0, 16); + for (int i = 0; i < 6; ++i) + guid.Data4[i + 2] = split.at(4).mid(i*2, 2).toUShort(0, 16); + + DWORD result = local_WlanDisconnect(handle, &guid, 0); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanDisconnect failed with error %ld\n", __FUNCTION__, result); + emit connectionError(id, DisconnectionError); + return; + } +} + +void QNativeWifiEngine::requestUpdate() +{ + // enumerate interfaces + WLAN_INTERFACE_INFO_LIST *interfaceList; + DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); + if (result != ERROR_SUCCESS) { + qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); + return; + } + + for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { + result = local_WlanScan(handle, &interfaceList->InterfaceInfo[i].InterfaceGuid, 0, 0, 0); + if (result != ERROR_SUCCESS) + qWarning("%s: WlanScan failed with error %ld\n", __FUNCTION__, result); + } +} + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.h b/src/plugins/bearer/nativewifi/qnativewifiengine.h new file mode 100644 index 0000000..6686ea8 --- /dev/null +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNATIVEWIFIENGINE_P_H +#define QNATIVEWIFIENGINE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +#include + +QT_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; + +class QNativeWifiEngine : public QNetworkSessionEngine +{ + Q_OBJECT + +public: + QNativeWifiEngine(QObject *parent = 0); + ~QNativeWifiEngine(); + + QList getConfigurations(bool *ok = 0); + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + inline void emitConfigurationsChanged() { emit configurationsChanged(); } + + inline bool available() const { return handle != 0; } + +private: + QTimer pollTimer; + + Qt::HANDLE handle; +}; + +QT_END_NAMESPACE + +#endif -- cgit v0.12 From 33934fc640c8f7cad0841ab2ae9c1ec22fd09654 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 3 Dec 2009 15:38:14 +1000 Subject: Fix license headers. --- src/network/bearer/qcorewlanengine_mac.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/bearer/qcorewlanengine_mac.mm b/src/network/bearer/qcorewlanengine_mac.mm index 5854384..2455f86 100644 --- a/src/network/bearer/qcorewlanengine_mac.mm +++ b/src/network/bearer/qcorewlanengine_mac.mm @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the QtNetwork module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage -- cgit v0.12 From a28dff36ae1e25be3748b2c26dcbb5b7b4ea6100 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 3 Dec 2009 15:42:07 +1000 Subject: Update license headers. --- src/plugins/bearer/nla/qnlaengine.cpp | 2 +- src/plugins/bearer/nla/qnlaengine.h | 2 +- src/plugins/bearer/platformdefs_win.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp index 527776f..2ad9cac 100644 --- a/src/plugins/bearer/nla/qnlaengine.cpp +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the QtNetwork module of the Qt Toolkit. +** This file is part of the plugins of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/plugins/bearer/nla/qnlaengine.h b/src/plugins/bearer/nla/qnlaengine.h index 76505fb..1e66c83 100644 --- a/src/plugins/bearer/nla/qnlaengine.h +++ b/src/plugins/bearer/nla/qnlaengine.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the QtNetwork module of the Qt Toolkit. +** This file is part of the plugins of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/plugins/bearer/platformdefs_win.h b/src/plugins/bearer/platformdefs_win.h index 133b7b1..f2f44a1 100644 --- a/src/plugins/bearer/platformdefs_win.h +++ b/src/plugins/bearer/platformdefs_win.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the QtNetwork module of the Qt Toolkit. +** This file is part of the plugins of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage -- cgit v0.12 From 13a519ce2d85ee006f2a30a50029195465249b01 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 3 Dec 2009 15:44:21 +1000 Subject: Update license headers. --- tests/auto/qbearertestcommon.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/qbearertestcommon.h b/tests/auto/qbearertestcommon.h index 3356bd6..0bfe622 100644 --- a/tests/auto/qbearertestcommon.h +++ b/tests/auto/qbearertestcommon.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the Qt Mobility Components. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage -- cgit v0.12 From 0bcb2788e1eb225e0e3babb4ca113bcb5769dfc2 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 3 Dec 2009 14:55:23 +1000 Subject: Add config.test for CoreWlan. Untested, I don't have a mac. --- config.tests/mac/corewlan/corewlan.pro | 3 ++ config.tests/mac/corewlan/corewlantest.mm | 49 +++++++++++++++++++++++++++++++ configure | 15 ++++++++++ 3 files changed, 67 insertions(+) create mode 100644 config.tests/mac/corewlan/corewlan.pro create mode 100644 config.tests/mac/corewlan/corewlantest.mm diff --git a/config.tests/mac/corewlan/corewlan.pro b/config.tests/mac/corewlan/corewlan.pro new file mode 100644 index 0000000..8451af3 --- /dev/null +++ b/config.tests/mac/corewlan/corewlan.pro @@ -0,0 +1,3 @@ +SOURCES = corewlantest.mm +LIBS += -framework CoreWLAN -framework Foundation +CONFIG -= app_bundle qt diff --git a/config.tests/mac/corewlan/corewlantest.mm b/config.tests/mac/corewlan/corewlantest.mm new file mode 100644 index 0000000..3a29d84 --- /dev/null +++ b/config.tests/mac/corewlan/corewlantest.mm @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the config.tests of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +int main() +{ + [CWInterface interfaceWithName:@"en2"]; + return 0; +} diff --git a/configure b/configure index dcd7d2d..b686081 100755 --- a/configure +++ b/configure @@ -766,6 +766,7 @@ CFG_SILENT=no CFG_GRAPHICS_SYSTEM=default CFG_ALSA=auto CFG_NETWORKMANAGER=auto +CFG_COREWLAN=auto # initalize variables used for installation QT_INSTALL_PREFIX= @@ -5365,6 +5366,14 @@ if [ "$PLATFORM_MAC" = "yes" ]; then # Always enable Phonon (unless it was explicitly disabled) CFG_PHONON=yes fi + + if [ "$CFG_COREWLAN" = "auto" ]; then + if "$unixtests/compile.test" "$XQMAKESPEC" "$QMAKE_CONFIG" $OPT_VERBOSE "$relpath" "$outpath" config.tests/mac/corewlan "CoreWlan" $L_FLAGS $I_FLAGS $l_FLAGS; then + CFG_COREWLAN=yes + else + CFG_COREWLAN=no + fi + fi fi # QWS @@ -6310,6 +6319,10 @@ if [ "$CFG_NETWORKMANAGER" = "yes" ]; then QT_CONFIG="$QT_CONFIG networkmanager" fi +if [ "$CFG_COREWLAN" = "yes" ]; then + QT_CONFIG="$QT_CONFIG corewlan" +fi + # # Some Qt modules are too advanced in C++ for some old compilers # Detect here the platforms where they are known to work. @@ -7011,6 +7024,7 @@ fi [ "$CFG_XINPUT" = "runtime" ] && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_RUNTIME_XINPUT" [ "$CFG_ALSA" = "no" ] && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_ALSA" [ "$CFG_NETWORKMANAGER" = "no" ] && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_NETWORKMANAGER" +[ "$CFG_COREWLAN" = "no" ] && QCONFIG_FLAGS="$QCONFIG_FLAGS QT_NO_COREWLAN" # sort QCONFIG_FLAGS for neatness if we can [ '!' -z "$AWK" ] && QCONFIG_FLAGS=`echo $QCONFIG_FLAGS | $AWK '{ gsub(" ", "\n"); print }' | sort | uniq` @@ -7537,6 +7551,7 @@ if [ "$PLATFORM_MAC" = "yes" ] && [ "$CFG_FRAMEWORK" = "yes" ] && [ "$CFG_DEBUG" fi echo "alsa support ........... $CFG_ALSA" echo "NetworkManager support . $CFG_NETWORKMANAGER" +echo "CoreWlan support ....... $CFG_COREWLAN" echo sepath=`echo "$relpath" | sed -e 's/\\./\\\\./g'` -- cgit v0.12 From f7eb78d6b7cc0e07275ab64bec2743c5b2c0705f Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 3 Dec 2009 15:00:24 +1000 Subject: Convert CoreWlan engine into a plugin. --- src/network/bearer/bearer.pri | 13 - src/network/bearer/qcorewlanengine_mac.mm | 461 ------------------------- src/network/bearer/qcorewlanengine_mac_p.h | 101 ------ src/network/bearer/qnetworkconfigmanager_p.cpp | 23 +- src/network/bearer/qnetworkconfigmanager_p.h | 2 +- src/network/bearer/qnetworksession_p.cpp | 13 - src/plugins/bearer/bearer.pro | 1 + src/plugins/bearer/corewlan/corewlan.pro | 21 ++ src/plugins/bearer/corewlan/main.cpp | 88 +++++ src/plugins/bearer/corewlan/qcorewlanengine.h | 91 +++++ src/plugins/bearer/corewlan/qcorewlanengine.mm | 459 ++++++++++++++++++++++++ 11 files changed, 672 insertions(+), 601 deletions(-) delete mode 100644 src/network/bearer/qcorewlanengine_mac.mm delete mode 100644 src/network/bearer/qcorewlanengine_mac_p.h create mode 100644 src/plugins/bearer/corewlan/corewlan.pro create mode 100644 src/plugins/bearer/corewlan/main.cpp create mode 100644 src/plugins/bearer/corewlan/qcorewlanengine.h create mode 100644 src/plugins/bearer/corewlan/qcorewlanengine.mm diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index 9476239..5bae333 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -81,18 +81,5 @@ symbian { bearer/qnetworksessionengine.cpp contains(QT_CONFIG, networkmanager):DEFINES += BACKEND_NM - - macx { - HEADERS += bearer/qcorewlanengine_mac_p.h - SOURCES+= bearer/qcorewlanengine_mac.mm - LIBS += -framework Foundation -framework SystemConfiguration - - contains(corewlan_enabled, yes) { - isEmpty(QMAKE_MAC_SDK)|contains(QMAKE_MAC_SDK, "/Developer/SDKs/MacOSX10.6.sdk") { - LIBS += -framework CoreWLAN - DEFINES += MAC_SDK_10_6 - } - } - } } diff --git a/src/network/bearer/qcorewlanengine_mac.mm b/src/network/bearer/qcorewlanengine_mac.mm deleted file mode 100644 index 2455f86..0000000 --- a/src/network/bearer/qcorewlanengine_mac.mm +++ /dev/null @@ -1,461 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qcorewlanengine_mac_p.h" -#include "qnetworkconfiguration_p.h" - -#include -#include -#include -#include - -#include - -#if defined(MAC_SDK_10_6) //not much functionality without this -#include -#include -#include -#include -#endif - -#include -#include -#include - -#include -QMap networkInterfaces; - -QT_BEGIN_NAMESPACE - -Q_GLOBAL_STATIC(QCoreWlanEngine, coreWlanEngine) - -inline QString cfstringRefToQstring(CFStringRef cfStringRef) { -// return QString([cfStringRef UTF8String]); - QString retVal; - CFIndex maxLength = 2 * CFStringGetLength(cfStringRef) + 1/*zero term*/; // max UTF8 - char *cstring = new char[maxLength]; - if (CFStringGetCString(CFStringRef(cfStringRef), cstring, maxLength, kCFStringEncodingUTF8)) { - retVal = QString::fromUtf8(cstring); - } - delete cstring; - return retVal; -} - -inline CFStringRef qstringToCFStringRef(const QString &string) -{ - return CFStringCreateWithCharacters(0, reinterpret_cast(string.unicode()), - string.length()); -} - -inline NSString *qstringToNSString(const QString &qstr) -{ return [reinterpret_cast(qstringToCFStringRef(qstr)) autorelease]; } - -inline QString nsstringToQString(const NSString *nsstr) -{ return cfstringRefToQstring(reinterpret_cast(nsstr)); } - -inline QStringList nsarrayToQStringList(void *nsarray) -{ - QStringList result; - NSArray *array = static_cast(nsarray); - for (NSUInteger i=0; i<[array count]; ++i) - result << nsstringToQString([array objectAtIndex:i]); - return result; -} - -static QString qGetInterfaceType(const QString &interfaceString) -{ - return networkInterfaces.value(interfaceString); -} - -QCoreWlanEngine::QCoreWlanEngine(QObject *parent) -: QNetworkSessionEngine(parent) -{ - getAllScInterfaces(); - connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); - pollTimer.setInterval(10000); -} - -QCoreWlanEngine::~QCoreWlanEngine() -{ -} - -QList QCoreWlanEngine::getWifiConfigurations() -{ - QMapIterator i(networkInterfaces); - while (i.hasNext()) { - i.next(); - QString interfaceName = i.key(); - if (i.value() == "WLAN") { - if(!isWifiReady(interfaceName)) { - qWarning() << "wifi not powered on"; - return QList(); - } else { - // QList profs = getWlanProfiles(interfaceName); - scanForSsids(interfaceName); - } - } else { - - } - } - return QList (); -} - -QList QCoreWlanEngine::getConfigurations(bool *ok) -{ - if (ok) - *ok = true; - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; - - QList foundConfigurations; - QList wificonfigs = getWifiConfigurations(); - - uint identifier; - QMapIterator i(networkInterfaces); - while (i.hasNext()) { - i.next(); - if (i.value() == "WLAN") { - QList fetchedConfigurations = scanForSsids(i.key()); - for (int i = 0; i < fetchedConfigurations.count(); ++i) { - - QNetworkConfigurationPrivate *config = new QNetworkConfigurationPrivate; - config->name = fetchedConfigurations.at(i)->name; - config->isValid = fetchedConfigurations.at(i)->isValid; - config->id = fetchedConfigurations.at(i)->id; - - config->state = fetchedConfigurations.at(i)->state; - config->type = fetchedConfigurations.at(i)->type; - config->roamingSupported = fetchedConfigurations.at(i)->roamingSupported; - config->purpose = fetchedConfigurations.at(i)->purpose; - config->internet = fetchedConfigurations.at(i)->internet; - config->serviceInterface = fetchedConfigurations.at(i)->serviceInterface; - - identifier = config->name.toUInt(); - configurationInterface[identifier] = config->serviceInterface.name(); - foundConfigurations.append(config); - } - } - - QNetworkInterface interface = QNetworkInterface::interfaceFromName(i.key()); - QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; - const QString humanReadableName = interface.humanReadableName(); - cpPriv->name = humanReadableName.isEmpty() ? interface.name() : humanReadableName; - cpPriv->isValid = true; - - if (interface.index()) - identifier = interface.index(); - else - identifier = qHash(interface.hardwareAddress()); - - cpPriv->id = QString::number(identifier); - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - cpPriv->state = QNetworkConfiguration::Undefined; - - if (interface.flags() & QNetworkInterface::IsRunning) { - cpPriv->state = QNetworkConfiguration::Defined; - cpPriv->internet = true; - } - if ( !interface.addressEntries().isEmpty()) { - cpPriv->state |= QNetworkConfiguration::Active; - cpPriv->internet = true; - } - configurationInterface[identifier] = interface.name(); - foundConfigurations.append(cpPriv); - } - [autoreleasepool release]; - pollTimer.start(); - return foundConfigurations; -} - -QString QCoreWlanEngine::getInterfaceFromId(const QString &id) -{ - return configurationInterface.value(id.toUInt()); -} - -bool QCoreWlanEngine::hasIdentifier(const QString &id) -{ - return configurationInterface.contains(id.toUInt()); -} - -QString QCoreWlanEngine::bearerName(const QString &id) -{ - QString interface = getInterfaceFromId(id); - - if (interface.isEmpty()) - return QString(); - - return qGetInterfaceType(interface); -} - -void QCoreWlanEngine::connectToId(const QString &id) -{ - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; - QString interfaceString = getInterfaceFromId(id); - - if(networkInterfaces.value(interfaceString) == "WLAN") { -#if defined(MAC_SDK_10_6) - CWInterface *wifiInterface = [CWInterface interfaceWithName: qstringToNSString(interfaceString)]; - CWConfiguration *userConfig = [ wifiInterface configuration]; - - NSSet *remNets = [userConfig rememberedNetworks]; //CWWirelessProfile - - NSEnumerator *enumerator = [remNets objectEnumerator]; - CWWirelessProfile *wProfile; - NSUInteger index=0; - while ((wProfile = [enumerator nextObject])) { //CWWirelessProfile - - if(id == nsstringToQString([wProfile ssid])) { - CW8021XProfile *user8021XProfile = nil; - user8021XProfile = [ wProfile user8021XProfile]; - - NSError *err = nil; - NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0]; - - if(user8021XProfile) { - [params setValue: user8021XProfile forKey:kCWAssocKey8021XProfile]; - } else { - [params setValue: [wProfile passphrase] forKey: kCWAssocKeyPassphrase]; - } - - NSDictionary *parametersDict = nil; - NSArray* apArray = [NSMutableArray arrayWithArray:[wifiInterface scanForNetworksWithParameters:parametersDict error:&err]]; - if(!err) { - for(uint row=0; row < [apArray count]; row++ ) { - CWNetwork *apNetwork = [apArray objectAtIndex:row]; - if([[apNetwork ssid] compare:[wProfile ssid]] == NSOrderedSame) { - bool result = [wifiInterface associateToNetwork: apNetwork parameters:[NSDictionary dictionaryWithDictionary:params] error:&err]; - if(!result) { - qWarning() <<"ERROR"<< nsstringToQString([err localizedDescription ]); - emit connectionError(id, ConnectError); - } else { - [autoreleasepool release]; - return; - } - } - } - } - } - index++; - } - emit connectionError(id, InterfaceLookupError); -#endif - } else { - // not wifi - } - emit connectionError(id, OperationNotSupported); - [autoreleasepool release]; -} - -void QCoreWlanEngine::disconnectFromId(const QString &id) -{ - QString interfaceString = getInterfaceFromId(id); - if(networkInterfaces.value(getInterfaceFromId(id)) == "WLAN") { //wifi only for now -#if defined(MAC_SDK_10_6) - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; - CWInterface *wifiInterface = [CWInterface interfaceWithName: qstringToNSString(interfaceString)]; - [wifiInterface disassociate]; - if([[wifiInterface interfaceState]intValue] != kCWInterfaceStateInactive) { - emit connectionError(id, DisconnectionError); - } - [autoreleasepool release]; - return; -#endif - } else { - - } - emit connectionError(id, OperationNotSupported); -} - -void QCoreWlanEngine::requestUpdate() -{ - getAllScInterfaces(); - emit configurationsChanged(); -} - -QCoreWlanEngine *QCoreWlanEngine::instance() -{ - return coreWlanEngine(); -} - -QList QCoreWlanEngine::scanForSsids(const QString &interfaceName) -{ - QList foundConfigs; -#if defined(MAC_SDK_10_6) - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; - - CWInterface *currentInterface = [CWInterface interfaceWithName:qstringToNSString(interfaceName)]; - NSError *err = nil; - NSDictionary *parametersDict = nil; - NSArray* apArray = [NSMutableArray arrayWithArray:[currentInterface scanForNetworksWithParameters:parametersDict error:&err]]; - - if(!err) { - for(uint row=0; row < [apArray count]; row++ ) { - CWNetwork *apNetwork = [apArray objectAtIndex:row]; - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - QString networkSsid = nsstringToQString([apNetwork ssid]); - cpPriv->name = networkSsid; - cpPriv->isValid = true; - cpPriv->id = networkSsid; - cpPriv->internet = true; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - cpPriv->serviceInterface = QNetworkInterface::interfaceFromName(nsstringToQString([[CWInterface interface] name])); - - CWWirelessProfile *networkProfile = apNetwork.wirelessProfile; - CW8021XProfile *userNetworkProfile = networkProfile.user8021XProfile; - if(!userNetworkProfile) { - } else { - qWarning() <<"Has profile!" ; - } - - if( [currentInterface.interfaceState intValue] == kCWInterfaceStateRunning) { - QString interfaceSsidString = nsstringToQString( [currentInterface ssid]); - if( cpPriv->name == interfaceSsidString) { - cpPriv->state |= QNetworkConfiguration::Active; - } - } else { - if(isKnownSsid(cpPriv->serviceInterface.name(), networkSsid)) { - cpPriv->state = QNetworkConfiguration::Discovered; - } else { - cpPriv->state = QNetworkConfiguration::Defined; - } - } - if(!cpPriv->state) { - cpPriv->state = QNetworkConfiguration::Undefined; - } - if([[apNetwork securityMode ] intValue]== kCWSecurityModeOpen) - cpPriv->purpose = QNetworkConfiguration::PublicPurpose; - else - cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; - foundConfigs.append(cpPriv); - } - } else { - qWarning() << "ERROR scanning for ssids" << nsstringToQString([err localizedDescription]) - < QCoreWlanEngine::getWlanProfiles(const QString &interfaceName) -{ - Q_UNUSED(interfaceName) -#if defined(MAC_SDK_10_6) -// for( CW8021XProfile *each8021XProfile in [CW8021XProfile allUser8021XProfiles] ) { -// qWarning() << "Profile name" << nsstringToQString([each8021XProfile ssid]); -// } - -#endif - return QList (); -} - -bool QCoreWlanEngine::getAllScInterfaces() -{ - networkInterfaces.clear(); - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; - - CFArrayRef interfaces = SCNetworkInterfaceCopyAll(); - if (interfaces != NULL) { - CFIndex interfaceCount; - CFIndex interfaceIndex; - interfaceCount = CFArrayGetCount(interfaces); - for (interfaceIndex = 0; interfaceIndex < interfaceCount; interfaceIndex++) { - - CFStringRef bsdName; - CFTypeRef thisInterface = CFArrayGetValueAtIndex(interfaces, interfaceIndex); - bsdName = SCNetworkInterfaceGetBSDName((SCNetworkInterfaceRef)thisInterface); - QString interfaceName = cfstringRefToQstring(bsdName); - QString typeStr; - CFStringRef type = SCNetworkInterfaceGetInterfaceType((SCNetworkInterfaceRef)thisInterface); - if ( CFEqual(type, kSCNetworkInterfaceTypeIEEE80211)) { - typeStr = "WLAN"; -// } else if (CFEqual(type, kSCNetworkInterfaceTypeBluetooth)) { -// typeStr = "Bluetooth"; - } else if(CFEqual(type, kSCNetworkInterfaceTypeEthernet)) { - typeStr = "Ethernet"; - } else if(CFEqual(type, kSCNetworkInterfaceTypeFireWire)) { - typeStr = "Ethernet"; //ok a bit fudged - } - if(!networkInterfaces.contains(interfaceName) && !typeStr.isEmpty()) { - networkInterfaces.insert(interfaceName,typeStr); - } - } - } - CFRelease(interfaces); - - [autoreleasepool release]; - return true; -} - -#include "moc_qcorewlanengine_mac_p.cpp" - -QT_END_NAMESPACE - diff --git a/src/network/bearer/qcorewlanengine_mac_p.h b/src/network/bearer/qcorewlanengine_mac_p.h deleted file mode 100644 index d6454ca..0000000 --- a/src/network/bearer/qcorewlanengine_mac_p.h +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtNetwork module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QCOREWLANENGINE_P_H -#define QCOREWLANENGINE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "qnetworksessionengine_p.h" -#include -#include - -QT_BEGIN_NAMESPACE - -class QNetworkConfigurationPrivate; - -class QCoreWlanEngine : public QNetworkSessionEngine -{ - Q_OBJECT - -public: - QCoreWlanEngine(QObject *parent = 0); - ~QCoreWlanEngine(); - - QList getConfigurations(bool *ok = 0); - QString getInterfaceFromId(const QString &id); - bool hasIdentifier(const QString &id); - - QString bearerName(const QString &id); - - void connectToId(const QString &id); - void disconnectFromId(const QString &id); - - void requestUpdate(); - - static QCoreWlanEngine *instance(); - static bool getAllScInterfaces(); - -private: - bool isWifiReady(const QString &dev); - QMap configurationInterface; - QTimer pollTimer; - QList scanForSsids(const QString &interfaceName); - - QList getWlanProfiles(const QString &interfaceName); - - QList getWifiConfigurations(); - bool isKnownSsid(const QString &interfaceName, const QString &ssid); -}; - -QT_END_NAMESPACE - -#endif - diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index c35edbf..f8e0d7b 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -40,11 +40,6 @@ ****************************************************************************/ #include "qnetworkconfigmanager_p.h" - -#ifdef Q_OS_DARWIN -#include "qcorewlanengine_mac_p.h" -#endif - #include "qbearerplugin.h" #include @@ -229,10 +224,17 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() QStringList keys = l->keys(); #if defined (Q_OS_DARWIN) - coreWifi = QCoreWlanEngine::instance(); - if (coreWifi) { - connect(coreWifi, SIGNAL(configurationsChanged()), - this, SLOT(updateConfigurations())); + coreWifi = 0; + if (keys.contains(QLatin1String("corewlan"))) { + QBearerEnginePlugin *coreWlanPlugin = + qobject_cast(l->instance(QLatin1String("corewlan"))); + if (coreWlanPlugin) { + coreWifi = coreWlanPlugin->create(QLatin1String("corewlan")); + if (coreWifi) { + connect(coreWifi, SIGNAL(configurationsChanged()), + this, SLOT(updateConfigurations())); + } + } } #else #ifdef BACKEND_NM @@ -473,7 +475,4 @@ void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() #endif } -#include "moc_qnetworkconfigmanager_p.cpp" - QT_END_NAMESPACE - diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 5d0df18..95358bc 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -146,7 +146,7 @@ private: QNetworkSessionEngine *nmWifi; #endif #ifdef Q_OS_DARWIN - QCoreWlanEngine *coreWifi; + QNetworkSessionEngine *coreWifi; #endif uint onlineConfigurations; diff --git a/src/network/bearer/qnetworksession_p.cpp b/src/network/bearer/qnetworksession_p.cpp index 3c9054b..df0ad3e 100644 --- a/src/network/bearer/qnetworksession_p.cpp +++ b/src/network/bearer/qnetworksession_p.cpp @@ -44,29 +44,18 @@ #include "qnetworksessionengine_p.h" #include "qnetworkconfigmanager_p.h" -#ifdef Q_OS_DARWIN -#include "qcorewlanengine_mac_p.h" -#endif #include #include #include #include -#undef interface - QT_BEGIN_NAMESPACE static QNetworkSessionEngine *getEngineFromId(const QString &id) { QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); -#ifdef Q_OS_DARWIN - QCoreWlanEngine *coreWifi = QCoreWlanEngine::instance(); - if (coreWifi && coreWifi->hasIdentifier(id)) - return coreWifi; - -#endif QNetworkSessionEngine *engine = priv->configurationEngine.value(id); if (engine && engine->hasIdentifier(id)) return engine; @@ -498,6 +487,4 @@ if(serviceName.isEmpty()) } #endif -#include "moc_qnetworksession_p.cpp" QT_END_NAMESPACE - diff --git a/src/plugins/bearer/bearer.pro b/src/plugins/bearer/bearer.pro index 80d6f4b..58d2613 100644 --- a/src/plugins/bearer/bearer.pro +++ b/src/plugins/bearer/bearer.pro @@ -4,3 +4,4 @@ SUBDIRS += generic contains(QT_CONFIG, dbus):contains(QT_CONFIG, networkmanager):SUBDIRS += networkmanager win32:SUBDIRS += nla win32:!wince*:SUBDIRS += nativewifi +macx:SUBDIRS += corewlan diff --git a/src/plugins/bearer/corewlan/corewlan.pro b/src/plugins/bearer/corewlan/corewlan.pro new file mode 100644 index 0000000..ffac6df --- /dev/null +++ b/src/plugins/bearer/corewlan/corewlan.pro @@ -0,0 +1,21 @@ +TARGET = qcorewlanbearer +include(../../qpluginbase.pri) + +QT += network +LIBS += -framework Foundation -framework SystemConfiguration + +contains(QT_CONFIG, corewlan) { + isEmpty(QMAKE_MAC_SDK)|contains(QMAKE_MAC_SDK, "/Developer/SDKs/MacOSX10.6.sdk") { + LIBS += -framework CoreWLAN + DEFINES += MAC_SDK_10_6 + } +} + +DEFINES += BEARER_ENGINE + +HEADERS += qcorewlanengine.h +SOURCES += qcorewlanengine.mm main.cpp + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer +target.path += $$[QT_INSTALL_PLUGINS]/bearer +INSTALLS += target diff --git a/src/plugins/bearer/corewlan/main.cpp b/src/plugins/bearer/corewlan/main.cpp new file mode 100644 index 0000000..c0d1efe --- /dev/null +++ b/src/plugins/bearer/corewlan/main.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qcorewlanengine.h" + +#include + +#include + +QT_BEGIN_NAMESPACE + +class QCoreWlanEnginePlugin : public QBearerEnginePlugin +{ +public: + QCoreWlanEnginePlugin(); + ~QCoreWlanEnginePlugin(); + + QStringList keys() const; + QBearerEngine *create(const QString &key) const; +}; + +QCoreWlanEnginePlugin::QCoreWlanEnginePlugin() +{ +} + +QCoreWlanEnginePlugin::~QCoreWlanEnginePlugin() +{ +} + +QStringList QCoreWlanEnginePlugin::keys() const +{ + qDebug() << Q_FUNC_INFO; + + return QStringList() << QLatin1String("corewlan"); +} + +QBearerEngine *QCoreWlanEnginePlugin::create(const QString &key) const +{ + qDebug() << Q_FUNC_INFO; + + if (key == QLatin1String("corewlan")) + return new QCoreWlanEngine; + else + return 0; +} + +Q_EXPORT_STATIC_PLUGIN(QCoreWlanEnginePlugin) +Q_EXPORT_PLUGIN2(qcorewlanbearer, QCoreWlanEnginePlugin) + +QT_END_NAMESPACE diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.h b/src/plugins/bearer/corewlan/qcorewlanengine.h new file mode 100644 index 0000000..7ccfeea --- /dev/null +++ b/src/plugins/bearer/corewlan/qcorewlanengine.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QCOREWLANENGINE_P_H +#define QCOREWLANENGINE_P_H + +#include + +#include +#include + +QT_BEGIN_NAMESPACE + +class QNetworkConfigurationPrivate; + +class QCoreWlanEngine : public QNetworkSessionEngine +{ + Q_OBJECT + +public: + QCoreWlanEngine(QObject *parent = 0); + ~QCoreWlanEngine(); + + QList getConfigurations(bool *ok = 0); + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + static QCoreWlanEngine *instance(); + static bool getAllScInterfaces(); + +private: + bool isWifiReady(const QString &dev); + QMap configurationInterface; + QTimer pollTimer; + QList scanForSsids(const QString &interfaceName); + + QList getWlanProfiles(const QString &interfaceName); + + QList getWifiConfigurations(); + bool isKnownSsid(const QString &interfaceName, const QString &ssid); +}; + +QT_END_NAMESPACE + +#endif + diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm new file mode 100644 index 0000000..9dea217 --- /dev/null +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -0,0 +1,459 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qcorewlanengine.h" + +#include + +#include +#include +#include +#include + +#include + +#if defined(MAC_SDK_10_6) //not much functionality without this +#include +#include +#include +#include +#endif + +#include +#include +#include + +#include +QMap networkInterfaces; + +QT_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(QCoreWlanEngine, coreWlanEngine) + +inline QString cfstringRefToQstring(CFStringRef cfStringRef) { +// return QString([cfStringRef UTF8String]); + QString retVal; + CFIndex maxLength = 2 * CFStringGetLength(cfStringRef) + 1/*zero term*/; // max UTF8 + char *cstring = new char[maxLength]; + if (CFStringGetCString(CFStringRef(cfStringRef), cstring, maxLength, kCFStringEncodingUTF8)) { + retVal = QString::fromUtf8(cstring); + } + delete cstring; + return retVal; +} + +inline CFStringRef qstringToCFStringRef(const QString &string) +{ + return CFStringCreateWithCharacters(0, reinterpret_cast(string.unicode()), + string.length()); +} + +inline NSString *qstringToNSString(const QString &qstr) +{ return [reinterpret_cast(qstringToCFStringRef(qstr)) autorelease]; } + +inline QString nsstringToQString(const NSString *nsstr) +{ return cfstringRefToQstring(reinterpret_cast(nsstr)); } + +inline QStringList nsarrayToQStringList(void *nsarray) +{ + QStringList result; + NSArray *array = static_cast(nsarray); + for (NSUInteger i=0; i<[array count]; ++i) + result << nsstringToQString([array objectAtIndex:i]); + return result; +} + +static QString qGetInterfaceType(const QString &interfaceString) +{ + return networkInterfaces.value(interfaceString); +} + +QCoreWlanEngine::QCoreWlanEngine(QObject *parent) +: QNetworkSessionEngine(parent) +{ + getAllScInterfaces(); + connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); + pollTimer.setInterval(10000); +} + +QCoreWlanEngine::~QCoreWlanEngine() +{ +} + +QList QCoreWlanEngine::getWifiConfigurations() +{ + QMapIterator i(networkInterfaces); + while (i.hasNext()) { + i.next(); + QString interfaceName = i.key(); + if (i.value() == "WLAN") { + if(!isWifiReady(interfaceName)) { + qWarning() << "wifi not powered on"; + return QList(); + } else { + // QList profs = getWlanProfiles(interfaceName); + scanForSsids(interfaceName); + } + } else { + + } + } + return QList (); +} + +QList QCoreWlanEngine::getConfigurations(bool *ok) +{ + if (ok) + *ok = true; + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + + QList foundConfigurations; + QList wificonfigs = getWifiConfigurations(); + + uint identifier; + QMapIterator i(networkInterfaces); + while (i.hasNext()) { + i.next(); + if (i.value() == "WLAN") { + QList fetchedConfigurations = scanForSsids(i.key()); + for (int i = 0; i < fetchedConfigurations.count(); ++i) { + + QNetworkConfigurationPrivate *config = new QNetworkConfigurationPrivate; + config->name = fetchedConfigurations.at(i)->name; + config->isValid = fetchedConfigurations.at(i)->isValid; + config->id = fetchedConfigurations.at(i)->id; + + config->state = fetchedConfigurations.at(i)->state; + config->type = fetchedConfigurations.at(i)->type; + config->roamingSupported = fetchedConfigurations.at(i)->roamingSupported; + config->purpose = fetchedConfigurations.at(i)->purpose; + config->internet = fetchedConfigurations.at(i)->internet; + config->serviceInterface = fetchedConfigurations.at(i)->serviceInterface; + + identifier = config->name.toUInt(); + configurationInterface[identifier] = config->serviceInterface.name(); + foundConfigurations.append(config); + } + } + + QNetworkInterface interface = QNetworkInterface::interfaceFromName(i.key()); + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + const QString humanReadableName = interface.humanReadableName(); + cpPriv->name = humanReadableName.isEmpty() ? interface.name() : humanReadableName; + cpPriv->isValid = true; + + if (interface.index()) + identifier = interface.index(); + else + identifier = qHash(interface.hardwareAddress()); + + cpPriv->id = QString::number(identifier); + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->state = QNetworkConfiguration::Undefined; + + if (interface.flags() & QNetworkInterface::IsRunning) { + cpPriv->state = QNetworkConfiguration::Defined; + cpPriv->internet = true; + } + if ( !interface.addressEntries().isEmpty()) { + cpPriv->state |= QNetworkConfiguration::Active; + cpPriv->internet = true; + } + configurationInterface[identifier] = interface.name(); + foundConfigurations.append(cpPriv); + } + [autoreleasepool release]; + pollTimer.start(); + return foundConfigurations; +} + +QString QCoreWlanEngine::getInterfaceFromId(const QString &id) +{ + return configurationInterface.value(id.toUInt()); +} + +bool QCoreWlanEngine::hasIdentifier(const QString &id) +{ + return configurationInterface.contains(id.toUInt()); +} + +QString QCoreWlanEngine::bearerName(const QString &id) +{ + QString interface = getInterfaceFromId(id); + + if (interface.isEmpty()) + return QString(); + + return qGetInterfaceType(interface); +} + +void QCoreWlanEngine::connectToId(const QString &id) +{ + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + QString interfaceString = getInterfaceFromId(id); + + if(networkInterfaces.value(interfaceString) == "WLAN") { +#if defined(MAC_SDK_10_6) + CWInterface *wifiInterface = [CWInterface interfaceWithName: qstringToNSString(interfaceString)]; + CWConfiguration *userConfig = [ wifiInterface configuration]; + + NSSet *remNets = [userConfig rememberedNetworks]; //CWWirelessProfile + + NSEnumerator *enumerator = [remNets objectEnumerator]; + CWWirelessProfile *wProfile; + NSUInteger index=0; + while ((wProfile = [enumerator nextObject])) { //CWWirelessProfile + + if(id == nsstringToQString([wProfile ssid])) { + CW8021XProfile *user8021XProfile = nil; + user8021XProfile = [ wProfile user8021XProfile]; + + NSError *err = nil; + NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0]; + + if(user8021XProfile) { + [params setValue: user8021XProfile forKey:kCWAssocKey8021XProfile]; + } else { + [params setValue: [wProfile passphrase] forKey: kCWAssocKeyPassphrase]; + } + + NSDictionary *parametersDict = nil; + NSArray* apArray = [NSMutableArray arrayWithArray:[wifiInterface scanForNetworksWithParameters:parametersDict error:&err]]; + if(!err) { + for(uint row=0; row < [apArray count]; row++ ) { + CWNetwork *apNetwork = [apArray objectAtIndex:row]; + if([[apNetwork ssid] compare:[wProfile ssid]] == NSOrderedSame) { + bool result = [wifiInterface associateToNetwork: apNetwork parameters:[NSDictionary dictionaryWithDictionary:params] error:&err]; + if(!result) { + qWarning() <<"ERROR"<< nsstringToQString([err localizedDescription ]); + emit connectionError(id, ConnectError); + } else { + [autoreleasepool release]; + return; + } + } + } + } + } + index++; + } + emit connectionError(id, InterfaceLookupError); +#endif + } else { + // not wifi + } + emit connectionError(id, OperationNotSupported); + [autoreleasepool release]; +} + +void QCoreWlanEngine::disconnectFromId(const QString &id) +{ + QString interfaceString = getInterfaceFromId(id); + if(networkInterfaces.value(getInterfaceFromId(id)) == "WLAN") { //wifi only for now +#if defined(MAC_SDK_10_6) + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + CWInterface *wifiInterface = [CWInterface interfaceWithName: qstringToNSString(interfaceString)]; + [wifiInterface disassociate]; + if([[wifiInterface interfaceState]intValue] != kCWInterfaceStateInactive) { + emit connectionError(id, DisconnectionError); + } + [autoreleasepool release]; + return; +#endif + } else { + + } + emit connectionError(id, OperationNotSupported); +} + +void QCoreWlanEngine::requestUpdate() +{ + getAllScInterfaces(); + emit configurationsChanged(); +} + +QCoreWlanEngine *QCoreWlanEngine::instance() +{ + return coreWlanEngine(); +} + +QList QCoreWlanEngine::scanForSsids(const QString &interfaceName) +{ + QList foundConfigs; +#if defined(MAC_SDK_10_6) + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + + CWInterface *currentInterface = [CWInterface interfaceWithName:qstringToNSString(interfaceName)]; + NSError *err = nil; + NSDictionary *parametersDict = nil; + NSArray* apArray = [NSMutableArray arrayWithArray:[currentInterface scanForNetworksWithParameters:parametersDict error:&err]]; + + if(!err) { + for(uint row=0; row < [apArray count]; row++ ) { + CWNetwork *apNetwork = [apArray objectAtIndex:row]; + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + QString networkSsid = nsstringToQString([apNetwork ssid]); + cpPriv->name = networkSsid; + cpPriv->isValid = true; + cpPriv->id = networkSsid; + cpPriv->internet = true; + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + cpPriv->serviceInterface = QNetworkInterface::interfaceFromName(nsstringToQString([[CWInterface interface] name])); + + CWWirelessProfile *networkProfile = apNetwork.wirelessProfile; + CW8021XProfile *userNetworkProfile = networkProfile.user8021XProfile; + if(!userNetworkProfile) { + } else { + qWarning() <<"Has profile!" ; + } + + if( [currentInterface.interfaceState intValue] == kCWInterfaceStateRunning) { + QString interfaceSsidString = nsstringToQString( [currentInterface ssid]); + if( cpPriv->name == interfaceSsidString) { + cpPriv->state |= QNetworkConfiguration::Active; + } + } else { + if(isKnownSsid(cpPriv->serviceInterface.name(), networkSsid)) { + cpPriv->state = QNetworkConfiguration::Discovered; + } else { + cpPriv->state = QNetworkConfiguration::Defined; + } + } + if(!cpPriv->state) { + cpPriv->state = QNetworkConfiguration::Undefined; + } + if([[apNetwork securityMode ] intValue]== kCWSecurityModeOpen) + cpPriv->purpose = QNetworkConfiguration::PublicPurpose; + else + cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; + foundConfigs.append(cpPriv); + } + } else { + qWarning() << "ERROR scanning for ssids" << nsstringToQString([err localizedDescription]) + < QCoreWlanEngine::getWlanProfiles(const QString &interfaceName) +{ + Q_UNUSED(interfaceName) +#if defined(MAC_SDK_10_6) +// for( CW8021XProfile *each8021XProfile in [CW8021XProfile allUser8021XProfiles] ) { +// qWarning() << "Profile name" << nsstringToQString([each8021XProfile ssid]); +// } + +#endif + return QList (); +} + +bool QCoreWlanEngine::getAllScInterfaces() +{ + networkInterfaces.clear(); + NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; + + CFArrayRef interfaces = SCNetworkInterfaceCopyAll(); + if (interfaces != NULL) { + CFIndex interfaceCount; + CFIndex interfaceIndex; + interfaceCount = CFArrayGetCount(interfaces); + for (interfaceIndex = 0; interfaceIndex < interfaceCount; interfaceIndex++) { + + CFStringRef bsdName; + CFTypeRef thisInterface = CFArrayGetValueAtIndex(interfaces, interfaceIndex); + bsdName = SCNetworkInterfaceGetBSDName((SCNetworkInterfaceRef)thisInterface); + QString interfaceName = cfstringRefToQstring(bsdName); + QString typeStr; + CFStringRef type = SCNetworkInterfaceGetInterfaceType((SCNetworkInterfaceRef)thisInterface); + if ( CFEqual(type, kSCNetworkInterfaceTypeIEEE80211)) { + typeStr = "WLAN"; +// } else if (CFEqual(type, kSCNetworkInterfaceTypeBluetooth)) { +// typeStr = "Bluetooth"; + } else if(CFEqual(type, kSCNetworkInterfaceTypeEthernet)) { + typeStr = "Ethernet"; + } else if(CFEqual(type, kSCNetworkInterfaceTypeFireWire)) { + typeStr = "Ethernet"; //ok a bit fudged + } + if(!networkInterfaces.contains(interfaceName) && !typeStr.isEmpty()) { + networkInterfaces.insert(interfaceName,typeStr); + } + } + } + CFRelease(interfaces); + + [autoreleasepool release]; + return true; +} + +QT_END_NAMESPACE -- cgit v0.12 From 19e64169b8f3b0b0c12d99327e8c68c5c8a26498 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 7 Dec 2009 16:03:38 +1000 Subject: Remove debug. --- src/network/bearer/qbearerplugin.cpp | 1 - src/plugins/bearer/corewlan/main.cpp | 4 ---- src/plugins/bearer/generic/main.cpp | 4 ---- src/plugins/bearer/nativewifi/main.cpp | 4 ---- src/plugins/bearer/networkmanager/main.cpp | 4 ---- src/plugins/bearer/nla/main.cpp | 4 ---- 6 files changed, 21 deletions(-) diff --git a/src/network/bearer/qbearerplugin.cpp b/src/network/bearer/qbearerplugin.cpp index 252ee71..7b81b13 100644 --- a/src/network/bearer/qbearerplugin.cpp +++ b/src/network/bearer/qbearerplugin.cpp @@ -48,7 +48,6 @@ QT_BEGIN_NAMESPACE QBearerEnginePlugin::QBearerEnginePlugin(QObject *parent) : QObject(parent) { - qDebug() << Q_FUNC_INFO; } QBearerEnginePlugin::~QBearerEnginePlugin() diff --git a/src/plugins/bearer/corewlan/main.cpp b/src/plugins/bearer/corewlan/main.cpp index c0d1efe..ce0611e 100644 --- a/src/plugins/bearer/corewlan/main.cpp +++ b/src/plugins/bearer/corewlan/main.cpp @@ -67,15 +67,11 @@ QCoreWlanEnginePlugin::~QCoreWlanEnginePlugin() QStringList QCoreWlanEnginePlugin::keys() const { - qDebug() << Q_FUNC_INFO; - return QStringList() << QLatin1String("corewlan"); } QBearerEngine *QCoreWlanEnginePlugin::create(const QString &key) const { - qDebug() << Q_FUNC_INFO; - if (key == QLatin1String("corewlan")) return new QCoreWlanEngine; else diff --git a/src/plugins/bearer/generic/main.cpp b/src/plugins/bearer/generic/main.cpp index c877fce..a7df023 100644 --- a/src/plugins/bearer/generic/main.cpp +++ b/src/plugins/bearer/generic/main.cpp @@ -67,15 +67,11 @@ QGenericEnginePlugin::~QGenericEnginePlugin() QStringList QGenericEnginePlugin::keys() const { - qDebug() << Q_FUNC_INFO; - return QStringList() << QLatin1String("generic"); } QBearerEngine *QGenericEnginePlugin::create(const QString &key) const { - qDebug() << Q_FUNC_INFO; - if (key == QLatin1String("generic")) return new QGenericEngine; else diff --git a/src/plugins/bearer/nativewifi/main.cpp b/src/plugins/bearer/nativewifi/main.cpp index 2aced02..64ed73d 100644 --- a/src/plugins/bearer/nativewifi/main.cpp +++ b/src/plugins/bearer/nativewifi/main.cpp @@ -108,15 +108,11 @@ QNativeWifiEnginePlugin::~QNativeWifiEnginePlugin() QStringList QNativeWifiEnginePlugin::keys() const { - qDebug() << Q_FUNC_INFO; - return QStringList() << QLatin1String("nativewifi"); } QBearerEngine *QNativeWifiEnginePlugin::create(const QString &key) const { - qDebug() << Q_FUNC_INFO; - if (key != QLatin1String("nativewifi")) return 0; diff --git a/src/plugins/bearer/networkmanager/main.cpp b/src/plugins/bearer/networkmanager/main.cpp index c79fe91..d4b74a1 100644 --- a/src/plugins/bearer/networkmanager/main.cpp +++ b/src/plugins/bearer/networkmanager/main.cpp @@ -67,15 +67,11 @@ QNetworkManagerEnginePlugin::~QNetworkManagerEnginePlugin() QStringList QNetworkManagerEnginePlugin::keys() const { - qDebug() << Q_FUNC_INFO; - return QStringList() << QLatin1String("networkmanager"); } QBearerEngine *QNetworkManagerEnginePlugin::create(const QString &key) const { - qDebug() << Q_FUNC_INFO; - if (key == QLatin1String("networkmanager")) return new QNmWifiEngine; else diff --git a/src/plugins/bearer/nla/main.cpp b/src/plugins/bearer/nla/main.cpp index f0d36c4..541d2c5 100644 --- a/src/plugins/bearer/nla/main.cpp +++ b/src/plugins/bearer/nla/main.cpp @@ -67,15 +67,11 @@ QNlaEnginePlugin::~QNlaEnginePlugin() QStringList QNlaEnginePlugin::keys() const { - qDebug() << Q_FUNC_INFO; - return QStringList() << QLatin1String("nla"); } QBearerEngine *QNlaEnginePlugin::create(const QString &key) const { - qDebug() << Q_FUNC_INFO; - if (key == QLatin1String("nla")) return new QNlaEngine; else -- cgit v0.12 From 63d59200884a68e569cce9d0ee470447b8239f6b Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 7 Dec 2009 16:11:11 +1000 Subject: Convert generic engine plugin to be incremental. --- src/network/bearer/qnetworkconfigmanager.cpp | 66 +++-- src/network/bearer/qnetworkconfigmanager_p.cpp | 318 +++++---------------- src/network/bearer/qnetworkconfigmanager_p.h | 70 +---- src/network/bearer/qnetworkconfiguration_p.h | 3 +- src/network/bearer/qnetworksessionengine.cpp | 11 + src/network/bearer/qnetworksessionengine_p.h | 23 +- src/plugins/bearer/generic/qgenericengine.cpp | 149 ++++++---- src/plugins/bearer/generic/qgenericengine.h | 4 +- .../bearer/networkmanager/qnmwifiengine.cpp | 8 +- src/plugins/bearer/networkmanager/qnmwifiengine.h | 4 +- 10 files changed, 266 insertions(+), 390 deletions(-) diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 02cc652..6c0b17d 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -45,6 +45,7 @@ #include "qnetworkconfigmanager_s60_p.h" #else #include "qnetworkconfigmanager_p.h" +#include "qnetworksessionengine_p.h" #endif QT_BEGIN_NAMESPACE @@ -234,28 +235,31 @@ QList QNetworkConfigurationManager::allConfigurations(QNe { QList result; QNetworkConfigurationManagerPrivate* conPriv = connManager(); - QList cpsIdents = conPriv->accessPointConfigurations.keys(); - - //find all InternetAccessPoints - foreach( QString ii, cpsIdents) { - QExplicitlySharedDataPointer p = - conPriv->accessPointConfigurations.value(ii); - if ( (p->state & filter) == filter ) { - QNetworkConfiguration pt; - pt.d = conPriv->accessPointConfigurations.value(ii); - result << pt; + + foreach (QNetworkSessionEngine *engine, conPriv->sessionEngines) { + QStringList cpsIdents = engine->accessPointConfigurations.keys(); + + //find all InternetAccessPoints + foreach (const QString &ii, cpsIdents) { + QExplicitlySharedDataPointer p = + engine->accessPointConfigurations.value(ii); + if ((p->state & filter) == filter) { + QNetworkConfiguration pt; + pt.d = engine->accessPointConfigurations.value(ii); + result << pt; + } } - } - //find all service networks - cpsIdents = conPriv->snapConfigurations.keys(); - foreach( QString ii, cpsIdents) { - QExplicitlySharedDataPointer p = - conPriv->snapConfigurations.value(ii); - if ( (p->state & filter) == filter ) { - QNetworkConfiguration pt; - pt.d = conPriv->snapConfigurations.value(ii); - result << pt; + //find all service networks + cpsIdents = engine->snapConfigurations.keys(); + foreach (const QString &ii, cpsIdents) { + QExplicitlySharedDataPointer p = + engine->snapConfigurations.value(ii); + if ((p->state & filter) == filter) { + QNetworkConfiguration pt; + pt.d = engine->snapConfigurations.value(ii); + result << pt; + } } } @@ -271,15 +275,23 @@ QList QNetworkConfigurationManager::allConfigurations(QNe QNetworkConfiguration QNetworkConfigurationManager::configurationFromIdentifier(const QString& identifier) const { QNetworkConfigurationManagerPrivate* conPriv = connManager(); + QNetworkConfiguration item; - if (conPriv->accessPointConfigurations.contains(identifier)) - item.d = conPriv->accessPointConfigurations.value(identifier); - else if (conPriv->snapConfigurations.contains(identifier)) - item.d = conPriv->snapConfigurations.value(identifier); - else if (conPriv->userChoiceConfigurations.contains(identifier)) - item.d = conPriv->userChoiceConfigurations.value(identifier); - return item; + foreach (QNetworkSessionEngine *engine, conPriv->sessionEngines) { + if (engine->accessPointConfigurations.contains(identifier)) + item.d = engine->accessPointConfigurations.value(identifier); + else if (engine->snapConfigurations.contains(identifier)) + item.d = engine->snapConfigurations.value(identifier); + else if (engine->userChoiceConfigurations.contains(identifier)) + item.d = engine->userChoiceConfigurations.value(identifier); + else + continue; + + return item; + } + + return item; } /*! diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index f8e0d7b..09714e5 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -53,50 +53,34 @@ QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, (QBearerEngineFactoryInterface_iid, QLatin1String("/bearer"))) +QNetworkConfigurationManagerPrivate::~QNetworkConfigurationManagerPrivate() +{ + while (!sessionEngines.isEmpty()) + delete sessionEngines.takeFirst(); +} + void QNetworkConfigurationManagerPrivate::registerPlatformCapabilities() { capFlags = QNetworkConfigurationManager::ForcedRoaming; } -void QNetworkConfigurationManagerPrivate::configurationAdded(QNetworkConfigurationPrivate *cpPriv, QNetworkSessionEngine *engine) +void QNetworkConfigurationManagerPrivate::configurationAdded(QNetworkConfigurationPrivatePointer ptr) { - QExplicitlySharedDataPointer ptr(new QNetworkConfigurationPrivate); - - ptr.data()->isValid = cpPriv->isValid; - ptr.data()->name = cpPriv->name; - ptr.data()->id = cpPriv->id; - ptr.data()->state = cpPriv->state; - ptr.data()->type = cpPriv->type; - ptr.data()->roamingSupported = cpPriv->roamingSupported; - ptr.data()->purpose = cpPriv->purpose; - ptr.data()->internet = cpPriv->internet; - - accessPointConfigurations.insert(cpPriv->id, ptr); - configurationEngine.insert(cpPriv->id, engine); - if (!firstUpdate) { QNetworkConfiguration item; item.d = ptr; emit configurationAdded(item); } - if (ptr.data()->state == QNetworkConfiguration::Active) { + if (ptr->state == QNetworkConfiguration::Active) { ++onlineConfigurations; if (!firstUpdate && onlineConfigurations == 1) emit onlineStateChanged(true); } } -void QNetworkConfigurationManagerPrivate::configurationRemoved(const QString &id) +void QNetworkConfigurationManagerPrivate::configurationRemoved(QNetworkConfigurationPrivatePointer ptr) { - if (!accessPointConfigurations.contains(id)) - return; - - QExplicitlySharedDataPointer ptr = - accessPointConfigurations.take(id); - - configurationEngine.remove(id); - ptr.data()->isValid = false; if (!firstUpdate) { @@ -112,57 +96,34 @@ void QNetworkConfigurationManagerPrivate::configurationRemoved(const QString &id } } -void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigurationPrivate *cpPriv) +void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigurationPrivatePointer ptr) { - if (!accessPointConfigurations.contains(cpPriv->id)) - return; - - QExplicitlySharedDataPointer ptr = - accessPointConfigurations.value(cpPriv->id); - - if (ptr.data()->isValid != cpPriv->isValid || - ptr.data()->name != cpPriv->name || - ptr.data()->id != cpPriv->id || - ptr.data()->state != cpPriv->state || - ptr.data()->type != cpPriv->type || - ptr.data()->roamingSupported != cpPriv->roamingSupported || - ptr.data()->purpose != cpPriv->purpose || - ptr.data()->internet != cpPriv->internet) { - - const QNetworkConfiguration::StateFlags oldState = ptr.data()->state; - - ptr.data()->isValid = cpPriv->isValid; - ptr.data()->name = cpPriv->name; - ptr.data()->id = cpPriv->id; - ptr.data()->state = cpPriv->state; - ptr.data()->type = cpPriv->type; - ptr.data()->roamingSupported = cpPriv->roamingSupported; - ptr.data()->purpose = cpPriv->purpose; - ptr.data()->internet = cpPriv->internet; + if (!firstUpdate) { + QNetworkConfiguration item; + item.d = ptr; + emit configurationChanged(item); + } - if (!firstUpdate) { - QNetworkConfiguration item; - item.d = ptr; - emit configurationChanged(item); - } + qDebug() << "Need to recalculate online state."; + QNetworkConfiguration::StateFlags oldState = ptr->state; - if (ptr.data()->state == QNetworkConfiguration::Active && oldState != ptr.data()->state) { - // configuration went online - ++onlineConfigurations; - if (!firstUpdate && onlineConfigurations == 1) - emit onlineStateChanged(true); - } else if (ptr.data()->state != QNetworkConfiguration::Active && oldState == QNetworkConfiguration::Active) { - // configuration went offline - --onlineConfigurations; - if (!firstUpdate && onlineConfigurations == 0) - emit onlineStateChanged(false); - } + if (ptr->state == QNetworkConfiguration::Active && oldState != ptr->state) { + // configuration went online + ++onlineConfigurations; + if (!firstUpdate && onlineConfigurations == 1) + emit onlineStateChanged(true); + } else if (ptr->state != QNetworkConfiguration::Active && oldState == QNetworkConfiguration::Active) { + // configuration went offline + --onlineConfigurations; + if (!firstUpdate && onlineConfigurations == 0) + emit onlineStateChanged(false); } } void QNetworkConfigurationManagerPrivate::updateInternetServiceConfiguration() { - if (!snapConfigurations.contains(QLatin1String("Internet Service Network"))) { +#if 0 + if (!generic->snapConfigurations.contains(QLatin1String("Internet Service Network"))) { QNetworkConfigurationPrivate *serviceNetwork = new QNetworkConfigurationPrivate; serviceNetwork->name = tr("Internet"); serviceNetwork->isValid = true; @@ -172,7 +133,7 @@ void QNetworkConfigurationManagerPrivate::updateInternetServiceConfiguration() QExplicitlySharedDataPointer ptr(serviceNetwork); - snapConfigurations.insert(serviceNetwork->id, ptr); + generic->snapConfigurations.insert(serviceNetwork->id, ptr); if (!firstUpdate) { QNetworkConfiguration item; @@ -182,15 +143,15 @@ void QNetworkConfigurationManagerPrivate::updateInternetServiceConfiguration() } QExplicitlySharedDataPointer ptr = - snapConfigurations.value(QLatin1String("Internet Service Network")); + generic->snapConfigurations.value(QLatin1String("Internet Service Network")); QList > serviceNetworkMembers; QHash >::const_iterator i = - accessPointConfigurations.constBegin(); + generic->accessPointConfigurations.constBegin(); QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Defined; - while (i != accessPointConfigurations.constEnd()) { + while (i != generic->accessPointConfigurations.constEnd()) { QExplicitlySharedDataPointer child = i.value(); if (child.data()->internet && ((child.data()->state & QNetworkConfiguration::Defined) @@ -212,186 +173,92 @@ void QNetworkConfigurationManagerPrivate::updateInternetServiceConfiguration() item.d = ptr; emit configurationChanged(item); } +#endif } void QNetworkConfigurationManagerPrivate::updateConfigurations() { if (firstUpdate) { - updateState = NotUpdating; onlineConfigurations = 0; QFactoryLoader *l = loader(); QStringList keys = l->keys(); -#if defined (Q_OS_DARWIN) - coreWifi = 0; if (keys.contains(QLatin1String("corewlan"))) { QBearerEnginePlugin *coreWlanPlugin = qobject_cast(l->instance(QLatin1String("corewlan"))); if (coreWlanPlugin) { - coreWifi = coreWlanPlugin->create(QLatin1String("corewlan")); + QNetworkSessionEngine *coreWifi = coreWlanPlugin->create(QLatin1String("corewlan")); if (coreWifi) { - connect(coreWifi, SIGNAL(configurationsChanged()), - this, SLOT(updateConfigurations())); + sessionEngines.append(coreWifi); } } } -#else -#ifdef BACKEND_NM - nmWifi = 0; + if (keys.contains(QLatin1String("networkmanager"))) { QBearerEnginePlugin *nmPlugin = qobject_cast(l->instance(QLatin1String("networkmanager"))); if (nmPlugin) { - nmWifi = nmPlugin->create(QLatin1String("networkmanager")); + QNetworkSessionEngine *nmWifi = nmPlugin->create(QLatin1String("networkmanager")); if (nmWifi) { - connect(nmWifi, SIGNAL(configurationsChanged()), - this, SLOT(updateConfigurations())); + sessionEngines.append(nmWifi); } } } -#endif - generic = 0; if (keys.contains(QLatin1String("generic"))) { QBearerEnginePlugin *genericPlugin = qobject_cast(l->instance(QLatin1String("generic"))); if (genericPlugin) { - generic = genericPlugin->create(QLatin1String("generic")); + QNetworkSessionEngine *generic = genericPlugin->create(QLatin1String("generic")); if (generic) { - connect(generic, SIGNAL(configurationsChanged()), - this, SLOT(updateConfigurations())); + sessionEngines.append(generic); + connect(generic, SIGNAL(updateCompleted()), + this, SIGNAL(configurationUpdateComplete())); + connect(generic, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); + connect(generic, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationRemoved(QNetworkConfigurationPrivatePointer))); + connect(generic, SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer))); } } } -#endif -#ifdef Q_OS_WIN - nla = 0; if (keys.contains(QLatin1String("nla"))) { QBearerEnginePlugin *nlaPlugin = qobject_cast(l->instance(QLatin1String("nla"))); if (nlaPlugin) { - qDebug() << "creating nla backend"; - nla = nlaPlugin->create(QLatin1String("nla")); + QNetworkSessionEngine *nla = nlaPlugin->create(QLatin1String("nla")); if (nla) { - connect(nla, SIGNAL(configurationsChanged()), - this, SLOT(updateConfigurations())); + sessionEngines.append(nla); } } } -#endif -#ifdef Q_OS_WIN32 - nativeWifi = 0; if (keys.contains(QLatin1String("nativewifi"))) { QBearerEnginePlugin *nativeWifiPlugin = qobject_cast(l->instance(QLatin1String("nativewifi"))); if (nativeWifiPlugin) { - qDebug() << "Creating native wifi backend"; - nativeWifi = nativeWifiPlugin->create(QLatin1String("nativewifi")); + QNetworkSessionEngine *nativeWifi = nativeWifiPlugin->create(QLatin1String("nativewifi")); if (nativeWifi) { - connect(nativeWifi, SIGNAL(configurationsChanged()), - this, SLOT(updateConfigurations())); + sessionEngines.append(nativeWifi); capFlags |= QNetworkConfigurationManager::CanStartAndStopInterfaces; } } } -#endif } QNetworkSessionEngine *engine = qobject_cast(sender()); - if (updateState & Updating && engine) { -#if defined (Q_OS_DARWIN) - if (engine == coreWifi) - updateState &= ~CoreWifiUpdating; -#else -#if defined(BACKEND_NM) - if (engine == nmWifi) - updateState &= ~NmUpdating; - if (engine == generic) - updateState &= ~GenericUpdating; -#else - if (engine == generic) - updateState &= ~GenericUpdating; -#endif -#endif - -#ifdef Q_OS_WIN - else if (engine == nla) - updateState &= ~NlaUpdating; -#ifdef Q_OS_WIN32 - else if (engine == nativeWifi) - updateState &= ~NativeWifiUpdating; -#endif -#endif - } - QList engines; - if (firstUpdate) { -#if defined (Q_OS_DARWIN) - if (coreWifi) - engines << coreWifi; -#else -#if defined(BACKEND_NM) - if (nmWifi) - engines << nmWifi; - if (generic) - engines << generic; -#else - if (generic) - engines << generic; -#endif -#endif - -#ifdef Q_OS_WIN - if (nla) - engines << nla; -#ifdef Q_OS_WIN32 - if (nativeWifi) - engines << nativeWifi; -#endif -#endif - } else if (engine) { - engines << engine; - } - - while (!engines.isEmpty()) { - engine = engines.takeFirst(); - - bool ok; - QList foundConfigurations = engine->getConfigurations(&ok); - - // Find removed configurations. - QList removedIdentifiers = configurationEngine.keys(); - for (int i = 0; i < foundConfigurations.count(); ++i) - removedIdentifiers.removeOne(foundConfigurations.at(i)->id); - - // Update or add configurations. - while (!foundConfigurations.isEmpty()) { - QNetworkConfigurationPrivate *cpPriv = foundConfigurations.takeFirst(); - - if (accessPointConfigurations.contains(cpPriv->id)) - configurationChanged(cpPriv); - else - configurationAdded(cpPriv, engine); - - delete cpPriv; - } - - // Remove configurations. - while (!removedIdentifiers.isEmpty()) { - const QString id = removedIdentifiers.takeFirst(); - - if (configurationEngine.value(id) == engine) - configurationRemoved(id); - } + if (!updatingEngines.isEmpty() && engine) { + int index = sessionEngines.indexOf(engine); + if (index >= 0) + updatingEngines.remove(index); } - updateInternetServiceConfiguration(); - - if (updateState == Updating) { - updateState = NotUpdating; + if (updating && updatingEngines.isEmpty()) { + updating = false; emit configurationUpdateComplete(); } @@ -407,22 +274,25 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() */ QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration() { - QExplicitlySharedDataPointer firstActive; - QExplicitlySharedDataPointer firstDiscovered; + QNetworkConfigurationPrivatePointer firstActive; + QNetworkConfigurationPrivatePointer firstDiscovered; - QHash >::const_iterator i = - accessPointConfigurations.constBegin(); - while (i != accessPointConfigurations.constEnd()) { - QNetworkConfigurationPrivate *priv = i.value().data(); + foreach (QNetworkSessionEngine *engine, sessionEngines) { + QHash::const_iterator i = + engine->accessPointConfigurations.constBegin(); - if (!firstActive && priv->isValid && - (priv->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) - firstActive = i.value(); - if (!firstDiscovered && priv->isValid && - (priv->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) - firstDiscovered = i.value(); + while (i != engine->accessPointConfigurations.constEnd()) { + QNetworkConfigurationPrivatePointer priv = i.value(); - ++i; + if (!firstActive && priv->isValid && + (priv->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) + firstActive = priv; + if (!firstDiscovered && priv->isValid && + (priv->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) + firstDiscovered = priv; + + ++i; + } } QNetworkConfiguration item; @@ -437,42 +307,12 @@ QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration( void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() { - updateState = Updating; -#if defined (Q_OS_DARWIN) - if (coreWifi) { - updateState |= CoreWifiUpdating; - coreWifi->requestUpdate(); - } -#else -#if defined(BACKEND_NM) - if (nmWifi) { - updateState |= NmUpdating; - nmWifi->requestUpdate(); - } - if (generic) { - updateState |= GenericUpdating; - generic->requestUpdate(); - } -#else - if (generic) { - updateState |= GenericUpdating; - generic->requestUpdate(); - } -#endif -#endif -#ifdef Q_OS_WIN - if (nla) { - updateState |= NlaUpdating; - nla->requestUpdate(); - } -#endif + updating = true; -#ifdef Q_OS_WIN32 - if (nativeWifi) { - updateState |= NativeWifiUpdating; - nativeWifi->requestUpdate(); + for (int i = 0; i < sessionEngines.count(); ++i) { + updatingEngines.insert(i); + sessionEngines.at(i)->requestUpdate(); } -#endif } QT_END_NAMESPACE diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 95358bc..27a0252 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -56,20 +56,9 @@ #include "qnetworkconfigmanager.h" #include "qnetworkconfiguration_p.h" -#include -#include - QT_BEGIN_NAMESPACE -#ifdef BEARER_ENGINE class QNetworkSessionEngine; -class QGenericEngine; -class QNlaEngine; -class QNativeWifiEngine; -class QNmWifiEngine; -class QCoreWlanEngine; -#endif - class QNetworkConfigurationManagerPrivate : public QObject { @@ -82,22 +71,7 @@ public: updateConfigurations(); } - virtual ~QNetworkConfigurationManagerPrivate() - { - QList configIdents = snapConfigurations.keys(); - foreach(const QString oldIface, configIdents) { - QExplicitlySharedDataPointer priv = snapConfigurations.take(oldIface); - priv->isValid = false; - priv->id.clear(); - } - - configIdents = accessPointConfigurations.keys(); - foreach(const QString oldIface, configIdents) { - QExplicitlySharedDataPointer priv = accessPointConfigurations.take(oldIface); - priv->isValid = false; - priv->id.clear(); - } - } + virtual ~QNetworkConfigurationManagerPrivate(); QNetworkConfiguration defaultConfiguration(); @@ -106,12 +80,6 @@ public: void performAsyncConfigurationUpdate(); - //this table contains an up to date list of all configs at any time. - //it must be updated if configurations change, are added/removed or - //the members of ServiceNetworks change - QHash > accessPointConfigurations; - QHash > snapConfigurations; - QHash > userChoiceConfigurations; #ifdef BEARER_ENGINE QHash configurationEngine; #endif @@ -135,41 +103,21 @@ private: #endif #ifdef BEARER_ENGINE - QNetworkSessionEngine *generic; -#ifdef Q_OS_WIN - QNetworkSessionEngine *nla; -#ifndef Q_OS_WINCE - QNetworkSessionEngine *nativeWifi; -#endif -#endif -#ifdef BACKEND_NM - QNetworkSessionEngine *nmWifi; -#endif -#ifdef Q_OS_DARWIN - QNetworkSessionEngine *coreWifi; -#endif +public: + QList sessionEngines; +private: uint onlineConfigurations; - enum EngineUpdate { - NotUpdating = 0x00, - Updating = 0x01, - GenericUpdating = 0x02, - NlaUpdating = 0x04, - NativeWifiUpdating = 0x08, - NmUpdating = 0x20, - CoreWifiUpdating = 0x40, - }; - Q_DECLARE_FLAGS(EngineUpdateState, EngineUpdate) - - EngineUpdateState updateState; + bool updating; + QSet updatingEngines; #endif private Q_SLOTS: #ifdef BEARER_ENGINE - void configurationAdded(QNetworkConfigurationPrivate *cpPriv, QNetworkSessionEngine *engine); - void configurationRemoved(const QString &id); - void configurationChanged(QNetworkConfigurationPrivate *cpPriv); + void configurationAdded(QNetworkConfigurationPrivatePointer ptr); + void configurationRemoved(QNetworkConfigurationPrivatePointer ptr); + void configurationChanged(QNetworkConfigurationPrivatePointer ptr); #endif }; diff --git a/src/network/bearer/qnetworkconfiguration_p.h b/src/network/bearer/qnetworkconfiguration_p.h index f00bcfa..8e69248 100644 --- a/src/network/bearer/qnetworkconfiguration_p.h +++ b/src/network/bearer/qnetworkconfiguration_p.h @@ -59,6 +59,7 @@ QT_BEGIN_NAMESPACE +typedef QExplicitlySharedDataPointer QNetworkConfigurationPrivatePointer; class QNetworkConfigurationPrivate : public QSharedData { public: @@ -89,7 +90,7 @@ public: bool internet; #endif - QList > serviceNetworkMembers; + QList serviceNetworkMembers; QNetworkInterface serviceInterface; private: diff --git a/src/network/bearer/qnetworksessionengine.cpp b/src/network/bearer/qnetworksessionengine.cpp index 9e6839e..0aa9d19 100644 --- a/src/network/bearer/qnetworksessionengine.cpp +++ b/src/network/bearer/qnetworksessionengine.cpp @@ -50,6 +50,17 @@ QNetworkSessionEngine::QNetworkSessionEngine(QObject *parent) QNetworkSessionEngine::~QNetworkSessionEngine() { + foreach (const QString &oldIface, snapConfigurations.keys()) { + QNetworkConfigurationPrivatePointer priv = snapConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + } + + foreach (const QString &oldIface, accessPointConfigurations.keys()) { + QNetworkConfigurationPrivatePointer priv = accessPointConfigurations.take(oldIface); + priv->isValid = false; + priv->id.clear(); + } } #include "moc_qnetworksessionengine_p.cpp" diff --git a/src/network/bearer/qnetworksessionengine_p.h b/src/network/bearer/qnetworksessionengine_p.h index 9fbd4ac..0145976 100644 --- a/src/network/bearer/qnetworksessionengine_p.h +++ b/src/network/bearer/qnetworksessionengine_p.h @@ -53,14 +53,19 @@ // We mean it. // +#include "qnetworkconfiguration_p.h" + #include #include #include #include +#include +#include QT_BEGIN_NAMESPACE -class QNetworkConfigurationPrivate; +class QNetworkConfiguration; + class Q_NETWORK_EXPORT QNetworkSessionEngine : public QObject { Q_OBJECT @@ -76,7 +81,6 @@ public: QNetworkSessionEngine(QObject *parent = 0); virtual ~QNetworkSessionEngine(); - virtual QList getConfigurations(bool *ok = 0) = 0; virtual QString getInterfaceFromId(const QString &id) = 0; virtual bool hasIdentifier(const QString &id) = 0; @@ -87,8 +91,21 @@ public: virtual void requestUpdate() = 0; +public: + //this table contains an up to date list of all configs at any time. + //it must be updated if configurations change, are added/removed or + //the members of ServiceNetworks change + QHash accessPointConfigurations; + QHash snapConfigurations; + QHash userChoiceConfigurations; + Q_SIGNALS: - void configurationsChanged(); + void configurationAdded(QNetworkConfigurationPrivatePointer config); + void configurationRemoved(QNetworkConfigurationPrivatePointer config); + void configurationChanged(QNetworkConfigurationPrivatePointer config); + + void updateCompleted(); + void connectionError(const QString &id, QNetworkSessionEngine::ConnectionError error); }; diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index 4be27ba..11dfb3e 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -125,21 +125,58 @@ static QString qGetInterfaceType(const QString &interface) QGenericEngine::QGenericEngine(QObject *parent) : QNetworkSessionEngine(parent) { - connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); + connect(&pollTimer, SIGNAL(timeout()), this, SLOT(doRequestUpdate())); pollTimer.setInterval(10000); + doRequestUpdate(); } QGenericEngine::~QGenericEngine() { } -QList QGenericEngine::getConfigurations(bool *ok) +QString QGenericEngine::getInterfaceFromId(const QString &id) +{ + return configurationInterface.value(id.toUInt()); +} + +bool QGenericEngine::hasIdentifier(const QString &id) +{ + return configurationInterface.contains(id.toUInt()); +} + +QString QGenericEngine::bearerName(const QString &id) +{ + QString interface = getInterfaceFromId(id); + + if (interface.isEmpty()) + return QString(); + + return qGetInterfaceType(interface); +} + +void QGenericEngine::connectToId(const QString &id) +{ + emit connectionError(id, OperationNotSupported); +} + +void QGenericEngine::disconnectFromId(const QString &id) +{ + emit connectionError(id, OperationNotSupported); +} + +void QGenericEngine::requestUpdate() { - if (ok) - *ok = true; + pollTimer.stop(); + QTimer::singleShot(0, this, SLOT(doRequestUpdate())); +} - QList foundConfigurations; +QGenericEngine *QGenericEngine::instance() +{ + return genericEngine(); +} +void QGenericEngine::doRequestUpdate() +{ // Immediately after connecting with a wireless access point // QNetworkInterface::allInterfaces() will sometimes return an empty list. Calling it again a // second time results in a non-empty list. If we loose interfaces we will end up removing @@ -148,6 +185,8 @@ QList QGenericEngine::getConfigurations(bool *ok if (interfaces.isEmpty()) interfaces = QNetworkInterface::allInterfaces(); + QStringList previous = accessPointConfigurations.keys(); + // create configuration for each interface while (!interfaces.isEmpty()) { QNetworkInterface interface = interfaces.takeFirst(); @@ -163,71 +202,77 @@ QList QGenericEngine::getConfigurations(bool *ok if (qGetInterfaceType(interface.name()) == QLatin1String("WLAN")) continue; - QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; - const QString humanReadableName = interface.humanReadableName(); - cpPriv->name = humanReadableName.isEmpty() ? interface.name() : humanReadableName; - cpPriv->isValid = true; - uint identifier; if (interface.index()) - identifier = qHash(QLatin1String("NLA:") + QString::number(interface.index())); + identifier = qHash(QLatin1String("generic:") + QString::number(interface.index())); else - identifier = qHash(QLatin1String("NLA:") + interface.hardwareAddress()); + identifier = qHash(QLatin1String("generic:") + interface.hardwareAddress()); + + const QString id = QString::number(identifier); - cpPriv->id = QString::number(identifier); - cpPriv->state = QNetworkConfiguration::Discovered; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + previous.removeAll(id); + + QString name = interface.humanReadableName(); + if (name.isEmpty()) + name = interface.name(); + + QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Discovered; if (interface.flags() & QNetworkInterface::IsUp) - cpPriv->state |= QNetworkConfiguration::Active; + state |= QNetworkConfiguration::Active; - configurationInterface[identifier] = interface.name(); + if (accessPointConfigurations.contains(id)) { + QExplicitlySharedDataPointer ptr = + accessPointConfigurations.value(id); - foundConfigurations.append(cpPriv); - } + bool changed = false; - pollTimer.start(); + if (!ptr->isValid) { + ptr->isValid = true; + changed = true; + } - return foundConfigurations; -} + if (ptr->name != name) { + ptr->name = name; + changed = true; + } -QString QGenericEngine::getInterfaceFromId(const QString &id) -{ - return configurationInterface.value(id.toUInt()); -} + if (ptr->id != id) { + ptr->id = id; + changed = true; + } -bool QGenericEngine::hasIdentifier(const QString &id) -{ - return configurationInterface.contains(id.toUInt()); -} + if (ptr->state != state) { + ptr->state = state; + changed = true; + } -QString QGenericEngine::bearerName(const QString &id) -{ - QString interface = getInterfaceFromId(id); + if (changed) + emit configurationChanged(ptr); + } else { + QExplicitlySharedDataPointer ptr(new QNetworkConfigurationPrivate); - if (interface.isEmpty()) - return QString(); + ptr->name = name; + ptr->isValid = true; + ptr->id = id; + ptr->state = state; + ptr->type = QNetworkConfiguration::InternetAccessPoint; - return qGetInterfaceType(interface); -} + accessPointConfigurations.insert(id, ptr); -void QGenericEngine::connectToId(const QString &id) -{ - emit connectionError(id, OperationNotSupported); -} + emit configurationAdded(ptr); + } + } -void QGenericEngine::disconnectFromId(const QString &id) -{ - emit connectionError(id, OperationNotSupported); -} + while (!previous.isEmpty()) { + QExplicitlySharedDataPointer ptr = + accessPointConfigurations.take(previous.takeFirst()); -void QGenericEngine::requestUpdate() -{ - emit configurationsChanged(); -} + emit configurationRemoved(ptr); + } -QGenericEngine *QGenericEngine::instance() -{ - return genericEngine(); + pollTimer.start(); + + emit updateCompleted(); } QT_END_NAMESPACE diff --git a/src/plugins/bearer/generic/qgenericengine.h b/src/plugins/bearer/generic/qgenericengine.h index 9923a9b..62f964a 100644 --- a/src/plugins/bearer/generic/qgenericengine.h +++ b/src/plugins/bearer/generic/qgenericengine.h @@ -59,7 +59,6 @@ public: QGenericEngine(QObject *parent = 0); ~QGenericEngine(); - QList getConfigurations(bool *ok = 0); QString getInterfaceFromId(const QString &id); bool hasIdentifier(const QString &id); @@ -72,6 +71,9 @@ public: static QGenericEngine *instance(); +private Q_SLOTS: + void doRequestUpdate(); + private: QMap configurationInterface; QTimer pollTimer; diff --git a/src/plugins/bearer/networkmanager/qnmwifiengine.cpp b/src/plugins/bearer/networkmanager/qnmwifiengine.cpp index 4a814ec..b215023 100644 --- a/src/plugins/bearer/networkmanager/qnmwifiengine.cpp +++ b/src/plugins/bearer/networkmanager/qnmwifiengine.cpp @@ -112,7 +112,7 @@ QString QNmWifiEngine::getNameForConfiguration(QNetworkManagerInterfaceDevice *d } -QList QNmWifiEngine::getConfigurations(bool *ok) +QList QNmWifiEngine::getConfigurations(bool *ok) { // qWarning() << Q_FUNC_INFO << updated; if (ok) @@ -133,7 +133,7 @@ QList QNmWifiEngine::getConfigurations(bool *ok) //add access points updated = true; } - return foundConfigurations; + return QList(); //foundConfigurations; } void QNmWifiEngine::findConnections() @@ -411,7 +411,7 @@ bool QNmWifiEngine::hasIdentifier(const QString &id) { if (configurationInterface.contains(id)) return true; - foreach (QNetworkConfigurationPrivate *cpPriv, getConfigurations()) { + foreach (QNetworkConfigurationPrivatePointer cpPriv, getConfigurations()) { if (cpPriv->id == id) return true; } @@ -506,7 +506,7 @@ void QNmWifiEngine::requestUpdate() updated = false; knownSsids.clear(); availableAccessPoints.clear(); - emitConfigurationsChanged(); + //emitConfigurationsChanged(); } QNmWifiEngine *QNmWifiEngine::instance() diff --git a/src/plugins/bearer/networkmanager/qnmwifiengine.h b/src/plugins/bearer/networkmanager/qnmwifiengine.h index 4d514e7..d651ef4 100644 --- a/src/plugins/bearer/networkmanager/qnmwifiengine.h +++ b/src/plugins/bearer/networkmanager/qnmwifiengine.h @@ -80,7 +80,7 @@ public: QNmWifiEngine(QObject *parent = 0); ~QNmWifiEngine(); - QList getConfigurations(bool *ok = 0); + QList getConfigurations(bool *ok = 0); QString getInterfaceFromId(const QString &id); bool hasIdentifier(const QString &id); @@ -94,7 +94,7 @@ public: static QNmWifiEngine *instance(); QStringList knownSsids; - inline void emitConfigurationsChanged() { emit configurationsChanged(); } + //inline void emitConfigurationsChanged() { emit configurationsChanged(); } QNetworkConfigurationPrivate * addAccessPoint(const QString &, QDBusObjectPath ); QStringList getConnectionPathForId(const QString &uuid); -- cgit v0.12 From ee8b1156400791a077280138863336ea93a774a7 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Wed, 9 Dec 2009 16:49:06 +1000 Subject: Keep track of which QNetworkInterface is for each QNetworkConfiguration. --- src/plugins/bearer/generic/qgenericengine.cpp | 6 ++++-- src/plugins/bearer/generic/qgenericengine.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index 11dfb3e..e70d23d 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -136,12 +136,12 @@ QGenericEngine::~QGenericEngine() QString QGenericEngine::getInterfaceFromId(const QString &id) { - return configurationInterface.value(id.toUInt()); + return configurationInterface.value(id); } bool QGenericEngine::hasIdentifier(const QString &id) { - return configurationInterface.contains(id.toUInt()); + return configurationInterface.contains(id); } QString QGenericEngine::bearerName(const QString &id) @@ -258,6 +258,7 @@ void QGenericEngine::doRequestUpdate() ptr->type = QNetworkConfiguration::InternetAccessPoint; accessPointConfigurations.insert(id, ptr); + configurationInterface.insert(id, interface.name()); emit configurationAdded(ptr); } @@ -267,6 +268,7 @@ void QGenericEngine::doRequestUpdate() QExplicitlySharedDataPointer ptr = accessPointConfigurations.take(previous.takeFirst()); + configurationInterface.remove(ptr->id); emit configurationRemoved(ptr); } diff --git a/src/plugins/bearer/generic/qgenericengine.h b/src/plugins/bearer/generic/qgenericengine.h index 62f964a..32d762d 100644 --- a/src/plugins/bearer/generic/qgenericengine.h +++ b/src/plugins/bearer/generic/qgenericengine.h @@ -75,7 +75,7 @@ private Q_SLOTS: void doRequestUpdate(); private: - QMap configurationInterface; + QMap configurationInterface; QTimer pollTimer; }; -- cgit v0.12 From 7858758772ad01e6a772cb048e4f1eda7f4ec9c3 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Wed, 9 Dec 2009 15:44:52 +1000 Subject: Rework NetworkManager backend. --- src/network/bearer/qnetworkconfigmanager.cpp | 2 + src/network/bearer/qnetworkconfigmanager_p.cpp | 47 +- src/network/bearer/qnetworkconfigmanager_p.h | 5 +- src/network/bearer/qnetworksession_p.cpp | 30 +- src/network/bearer/qnetworksessionengine_p.h | 3 + src/plugins/bearer/generic/qgenericengine.cpp | 26 +- src/plugins/bearer/generic/qgenericengine.h | 2 + src/plugins/bearer/networkmanager/main.cpp | 4 +- .../bearer/networkmanager/networkmanager.pro | 4 +- .../networkmanager/qnetworkmanagerengine.cpp | 654 ++++++++++++ .../bearer/networkmanager/qnetworkmanagerengine.h | 125 +++ .../networkmanager/qnetworkmanagerservice.cpp | 6 +- .../bearer/networkmanager/qnetworkmanagerservice.h | 4 +- .../bearer/networkmanager/qnmdbushelper.cpp | 3 + src/plugins/bearer/networkmanager/qnmdbushelper.h | 14 - .../bearer/networkmanager/qnmwifiengine.cpp | 1128 -------------------- src/plugins/bearer/networkmanager/qnmwifiengine.h | 165 --- 17 files changed, 863 insertions(+), 1359 deletions(-) create mode 100644 src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp create mode 100644 src/plugins/bearer/networkmanager/qnetworkmanagerengine.h delete mode 100644 src/plugins/bearer/networkmanager/qnmwifiengine.cpp delete mode 100644 src/plugins/bearer/networkmanager/qnmwifiengine.h diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 6c0b17d..6b73e3c 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -48,6 +48,8 @@ #include "qnetworksessionengine_p.h" #endif +#include + QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QNetworkConfigurationManagerPrivate, connManager); diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 09714e5..6f833f3 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -73,15 +73,15 @@ void QNetworkConfigurationManagerPrivate::configurationAdded(QNetworkConfigurati } if (ptr->state == QNetworkConfiguration::Active) { - ++onlineConfigurations; - if (!firstUpdate && onlineConfigurations == 1) + onlineConfigurations.insert(ptr); + if (!firstUpdate && onlineConfigurations.count() == 1) emit onlineStateChanged(true); } } void QNetworkConfigurationManagerPrivate::configurationRemoved(QNetworkConfigurationPrivatePointer ptr) { - ptr.data()->isValid = false; + ptr->isValid = false; if (!firstUpdate) { QNetworkConfiguration item; @@ -89,11 +89,9 @@ void QNetworkConfigurationManagerPrivate::configurationRemoved(QNetworkConfigura emit configurationRemoved(item); } - if (ptr.data()->state == QNetworkConfiguration::Active) { - --onlineConfigurations; - if (!firstUpdate && onlineConfigurations == 0) - emit onlineStateChanged(false); - } + onlineConfigurations.remove(ptr); + if (!firstUpdate && onlineConfigurations.isEmpty()) + emit onlineStateChanged(false); } void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigurationPrivatePointer ptr) @@ -104,20 +102,17 @@ void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigura emit configurationChanged(item); } - qDebug() << "Need to recalculate online state."; - QNetworkConfiguration::StateFlags oldState = ptr->state; + bool previous = !onlineConfigurations.isEmpty(); - if (ptr->state == QNetworkConfiguration::Active && oldState != ptr->state) { - // configuration went online - ++onlineConfigurations; - if (!firstUpdate && onlineConfigurations == 1) - emit onlineStateChanged(true); - } else if (ptr->state != QNetworkConfiguration::Active && oldState == QNetworkConfiguration::Active) { - // configuration went offline - --onlineConfigurations; - if (!firstUpdate && onlineConfigurations == 0) - emit onlineStateChanged(false); - } + if (ptr->state == QNetworkConfiguration::Active) + onlineConfigurations.insert(ptr); + else + onlineConfigurations.remove(ptr); + + bool online = !onlineConfigurations.isEmpty(); + + if (!firstUpdate && online != previous) + emit onlineStateChanged(online); } void QNetworkConfigurationManagerPrivate::updateInternetServiceConfiguration() @@ -179,7 +174,7 @@ void QNetworkConfigurationManagerPrivate::updateInternetServiceConfiguration() void QNetworkConfigurationManagerPrivate::updateConfigurations() { if (firstUpdate) { - onlineConfigurations = 0; + updating = false; QFactoryLoader *l = loader(); QStringList keys = l->keys(); @@ -202,6 +197,14 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() QNetworkSessionEngine *nmWifi = nmPlugin->create(QLatin1String("networkmanager")); if (nmWifi) { sessionEngines.append(nmWifi); + connect(nmWifi, SIGNAL(updateCompleted()), + this, SIGNAL(configurationUpdateComplete())); + connect(nmWifi, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); + connect(nmWifi, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationRemoved(QNetworkConfigurationPrivatePointer))); + connect(nmWifi, SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer))); } } } diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 27a0252..37e88d3 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -80,9 +80,6 @@ public: void performAsyncConfigurationUpdate(); -#ifdef BEARER_ENGINE - QHash configurationEngine; -#endif bool firstUpdate; public slots: @@ -107,7 +104,7 @@ public: QList sessionEngines; private: - uint onlineConfigurations; + QSet onlineConfigurations; bool updating; QSet updatingEngines; diff --git a/src/network/bearer/qnetworksession_p.cpp b/src/network/bearer/qnetworksession_p.cpp index df0ad3e..8421fbc 100644 --- a/src/network/bearer/qnetworksession_p.cpp +++ b/src/network/bearer/qnetworksession_p.cpp @@ -56,9 +56,10 @@ static QNetworkSessionEngine *getEngineFromId(const QString &id) { QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); - QNetworkSessionEngine *engine = priv->configurationEngine.value(id); - if (engine && engine->hasIdentifier(id)) - return engine; + foreach (QNetworkSessionEngine *engine, priv->sessionEngines) { + if (engine->hasIdentifier(id)) + return engine; + } return 0; } @@ -104,6 +105,7 @@ void QNetworkSessionPrivate::syncStateWithInterface() this, SLOT(forcedSessionClose(QNetworkConfiguration))); opened = false; + isActive = false; state = QNetworkSession::Invalid; lastError = QNetworkSession::UnknownSessionError; @@ -341,6 +343,7 @@ void QNetworkSessionPrivate::updateStateFromServiceNetwork() } state = QNetworkSession::Connected; + qDebug() << oldState << "->" << state; if (state != oldState) emit q->stateChanged(state); @@ -352,31 +355,22 @@ void QNetworkSessionPrivate::updateStateFromServiceNetwork() else state = QNetworkSession::Disconnected; + qDebug() << oldState << "->" << state; if (state != oldState) emit q->stateChanged(state); } void QNetworkSessionPrivate::updateStateFromActiveConfig() { - QNetworkSession::State oldState = state; + if (!engine) + return; - bool newActive = false; + QNetworkSession::State oldState = state; - if (!activeConfig.isValid()) { - state = QNetworkSession::Invalid; - } else if ((activeConfig.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { - state = QNetworkSession::Connected; - newActive = opened; - } else if ((activeConfig.state() & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) { - state = QNetworkSession::Disconnected; - } else if ((activeConfig.state() & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) { - state = QNetworkSession::NotAvailable; - } else if ((activeConfig.state() & QNetworkConfiguration::Undefined) == QNetworkConfiguration::Undefined) { - state = QNetworkSession::NotAvailable; - } + state = engine->sessionStateForId(activeConfig.identifier()); bool oldActive = isActive; - isActive = newActive; + isActive = (state == QNetworkSession::Connected) ? opened : false; if (!oldActive && isActive) emit quitPendingWaitsForOpened(); diff --git a/src/network/bearer/qnetworksessionengine_p.h b/src/network/bearer/qnetworksessionengine_p.h index 0145976..a698c40 100644 --- a/src/network/bearer/qnetworksessionengine_p.h +++ b/src/network/bearer/qnetworksessionengine_p.h @@ -54,6 +54,7 @@ // #include "qnetworkconfiguration_p.h" +#include "qnetworksession.h" #include #include @@ -91,6 +92,8 @@ public: virtual void requestUpdate() = 0; + virtual QNetworkSession::State sessionStateForId(const QString &id) = 0; + public: //this table contains an up to date list of all configs at any time. //it must be updated if configurations change, are added/removed or diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index e70d23d..339ef9c 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -249,7 +249,7 @@ void QGenericEngine::doRequestUpdate() if (changed) emit configurationChanged(ptr); } else { - QExplicitlySharedDataPointer ptr(new QNetworkConfigurationPrivate); + QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); ptr->name = name; ptr->isValid = true; @@ -277,5 +277,29 @@ void QGenericEngine::doRequestUpdate() emit updateCompleted(); } +QNetworkSession::State QGenericEngine::sessionStateForId(const QString &id) +{ + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + if (!ptr) + return QNetworkSession::Invalid; + + if (!ptr->isValid) { + return QNetworkSession::Invalid; + } else if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + return QNetworkSession::Connected; + } else if ((ptr->state & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + return QNetworkSession::Disconnected; + } else if ((ptr->state & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) { + return QNetworkSession::NotAvailable; + } else if ((ptr->state & QNetworkConfiguration::Undefined) == + QNetworkConfiguration::Undefined) { + return QNetworkSession::NotAvailable; + } + + return QNetworkSession::Invalid; +} + QT_END_NAMESPACE diff --git a/src/plugins/bearer/generic/qgenericengine.h b/src/plugins/bearer/generic/qgenericengine.h index 32d762d..9359d7f 100644 --- a/src/plugins/bearer/generic/qgenericengine.h +++ b/src/plugins/bearer/generic/qgenericengine.h @@ -69,6 +69,8 @@ public: void requestUpdate(); + QNetworkSession::State sessionStateForId(const QString &id); + static QGenericEngine *instance(); private Q_SLOTS: diff --git a/src/plugins/bearer/networkmanager/main.cpp b/src/plugins/bearer/networkmanager/main.cpp index d4b74a1..b561415 100644 --- a/src/plugins/bearer/networkmanager/main.cpp +++ b/src/plugins/bearer/networkmanager/main.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qnmwifiengine.h" +#include "qnetworkmanagerengine.h" #include @@ -73,7 +73,7 @@ QStringList QNetworkManagerEnginePlugin::keys() const QBearerEngine *QNetworkManagerEnginePlugin::create(const QString &key) const { if (key == QLatin1String("networkmanager")) - return new QNmWifiEngine; + return new QNetworkManagerEngine; else return 0; } diff --git a/src/plugins/bearer/networkmanager/networkmanager.pro b/src/plugins/bearer/networkmanager/networkmanager.pro index 36d150a..79c68ea 100644 --- a/src/plugins/bearer/networkmanager/networkmanager.pro +++ b/src/plugins/bearer/networkmanager/networkmanager.pro @@ -7,12 +7,12 @@ DEFINES += BEARER_ENGINE BACKEND_NM HEADERS += qnmdbushelper.h \ qnetworkmanagerservice.h \ - qnmwifiengine.h + qnetworkmanagerengine.h SOURCES += main.cpp \ qnmdbushelper.cpp \ qnetworkmanagerservice.cpp \ - qnmwifiengine.cpp + qnetworkmanagerengine.cpp QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/bearer target.path += $$[QT_INSTALL_PLUGINS]/bearer diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp new file mode 100644 index 0000000..3de20a3 --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -0,0 +1,654 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qnetworkmanagerengine.h" +#include "qnetworkmanagerservice.h" + +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +QNetworkManagerEngine::QNetworkManagerEngine(QObject *parent) +: QNetworkSessionEngine(parent), + interface(new QNetworkManagerInterface(this)), + systemSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE_SYSTEM_SETTINGS, this)), + userSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE_USER_SETTINGS, this)) +{ + interface->setConnections(); + connect(interface, SIGNAL(deviceAdded(QDBusObjectPath)), + this, SLOT(deviceAdded(QDBusObjectPath))); + connect(interface, SIGNAL(deviceRemoved(QDBusObjectPath)), + this, SLOT(deviceRemoved(QDBusObjectPath))); +#if 0 + connect(interface, SIGNAL(stateChanged(const QString,quint32)), + this, SIGNAL(configurationsChanged())); +#endif + connect(interface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)), + this, SLOT(activationFinished(QDBusPendingCallWatcher*))); + connect(interface, SIGNAL(propertiesChanged(QString,QMap)), + this, SLOT(interfacePropertiesChanged(QString,QMap))); + + qDBusRegisterMetaType(); + + systemSettings->setConnections(); + connect(systemSettings, SIGNAL(newConnection(QDBusObjectPath)), + this, SLOT(newConnection(QDBusObjectPath))); + + userSettings->setConnections(); + connect(userSettings, SIGNAL(newConnection(QDBusObjectPath)), + this, SLOT(newConnection(QDBusObjectPath))); + + // Get current list of access points. + foreach (const QDBusObjectPath &devicePath, interface->getDevices()) + deviceAdded(devicePath); + + // Get connections. + foreach (const QDBusObjectPath &settingsPath, systemSettings->listConnections()) + newConnection(settingsPath, systemSettings); + foreach (const QDBusObjectPath &settingsPath, userSettings->listConnections()) + newConnection(settingsPath, userSettings); + + // Get active connections. + foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { + QNetworkManagerConnectionActive *activeConnection = + new QNetworkManagerConnectionActive(acPath.path()); + activeConnections.insert(acPath.path(), activeConnection); + + activeConnection->setConnections(); + connect(activeConnection, SIGNAL(propertiesChanged(QString,QMap)), + this, SLOT(activeConnectionPropertiesChanged(QString,QMap))); + } +} + +QNetworkManagerEngine::~QNetworkManagerEngine() +{ +} + +void QNetworkManagerEngine::doRequestUpdate() +{ +} + +QString QNetworkManagerEngine::getInterfaceFromId(const QString &id) +{ + foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { + QNetworkManagerConnectionActive activeConnection(acPath.path()); + + const QString identifier = QString::number(qHash(activeConnection.serviceName() + ' ' + + activeConnection.connection().path())); + + if (id == identifier) { + QList devices = activeConnection.devices(); + + if (devices.isEmpty()) + continue; + + if (devices.count() > 1) + qDebug() << "multiple network interfaces for" << id; + + QNetworkManagerInterfaceDevice device(devices.at(0).path()); + return device.interface().name(); + } + } + + return QString(); +} + +bool QNetworkManagerEngine::hasIdentifier(const QString &id) +{ + if (connectionFromId(id)) + return true; + + for (int i = 0; i < accessPoints.count(); ++i) { + QNetworkManagerInterfaceAccessPoint *accessPoint = accessPoints.at(i); + + const QString identifier = + QString::number(qHash(accessPoint->connectionInterface()->path())); + + if (id == identifier) + return true; + } + + return false; +} + +QString QNetworkManagerEngine::bearerName(const QString &id) +{ + QNetworkManagerSettingsConnection *connection = connectionFromId(id); + + if (!connection) + return QString(); + + QNmSettingsMap map = connection->getSettings(); + const QString connectionType = map.value("connection").value("type").toString(); + + if (connectionType == "802-3-ethernet") + return QLatin1String("Ethernet"); + else if (connectionType == "802-11-wireless") + return QLatin1String("WLAN"); + else if (connectionType == "gsm") + return QLatin1String("2G"); + else if (connectionType == "cdma") + return QLatin1String("CDMA2000"); + else + return QString(); +} + +void QNetworkManagerEngine::connectToId(const QString &id) +{ + QNetworkManagerSettingsConnection *connection = connectionFromId(id); + + if (!connection) + return; + + QNmSettingsMap map = connection->getSettings(); + const QString connectionType = map.value("connection").value("type").toString(); + + QString dbusDevicePath; + foreach (const QDBusObjectPath &devicePath, interface->getDevices()) { + QNetworkManagerInterfaceDevice device(devicePath.path()); + if (device.deviceType() == DEVICE_TYPE_802_3_ETHERNET && + connectionType == QLatin1String("802-3-ethernet")) { + dbusDevicePath = devicePath.path(); + break; + } else if (device.deviceType() == DEVICE_TYPE_802_11_WIRELESS && + connectionType == QLatin1String("802-11-wireless")) { + dbusDevicePath = devicePath.path(); + break; + } + } + + const QString service = connection->connectionInterface()->service(); + const QString settingsPath = connection->connectionInterface()->path(); + + interface->activateConnection(service, QDBusObjectPath(settingsPath), + QDBusObjectPath(dbusDevicePath), QDBusObjectPath("/")); +} + +void QNetworkManagerEngine::disconnectFromId(const QString &id) +{ + foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { + QNetworkManagerConnectionActive activeConnection(acPath.path()); + + const QString identifier = QString::number(qHash(activeConnection.serviceName() + ' ' + + activeConnection.connection().path())); + + if (id == identifier && accessPointConfigurations.contains(id)) { + interface->deactivateConnection(acPath); + break; + } + } +} + +void QNetworkManagerEngine::requestUpdate() +{ + QTimer::singleShot(0, this, SLOT(doRequestUpdate())); +} + +void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path, + const QMap &properties) +{ + QMapIterator i(properties); + while (i.hasNext()) { + i.next(); + + if (i.key() == QLatin1String("ActiveConnections")) { + // Active connections changed, update configurations. + + QList activeConnections = + qdbus_cast >(i.value().value()); + + QStringList identifiers = accessPointConfigurations.keys(); + foreach (const QString &id, identifiers) + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + QStringList priorActiveConnections = this->activeConnections.keys(); + + foreach (const QDBusObjectPath &acPath, activeConnections) { + priorActiveConnections.removeOne(acPath.path()); + QNetworkManagerConnectionActive *activeConnection = + this->activeConnections.value(acPath.path()); + if (!activeConnection) { + activeConnection = new QNetworkManagerConnectionActive(acPath.path()); + this->activeConnections.insert(acPath.path(), activeConnection); + + activeConnection->setConnections(); + connect(activeConnection, SIGNAL(propertiesChanged(QString,QMap)), + this, SLOT(activeConnectionPropertiesChanged(QString,QMap))); + } + + const QString id = QString::number(qHash(activeConnection->serviceName() + ' ' + + activeConnection->connection().path())); + + identifiers.removeOne(id); + + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + if (ptr) { + if (activeConnection->state() == 2 && + ptr->state != QNetworkConfiguration::Active) { + ptr->state = QNetworkConfiguration::Active; + emit configurationChanged(ptr); + } + } + } + + while (!priorActiveConnections.isEmpty()) + delete this->activeConnections.take(priorActiveConnections.takeFirst()); + + while (!identifiers.isEmpty()) { + // These configurations are not active + QNetworkConfigurationPrivatePointer ptr = + accessPointConfigurations.value(identifiers.takeFirst()); + + if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + ptr->state = QNetworkConfiguration::Discovered; + emit configurationChanged(ptr); + } + } + } + } +} + +void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QString &path, + const QMap &properties) +{ + QNetworkManagerConnectionActive *activeConnection = activeConnections.value(path); + + if (!activeConnection) + return; + + const QString id = QString::number(qHash(activeConnection->serviceName() + ' ' + + activeConnection->connection().path())); + + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + if (ptr) { + if (activeConnection->state() == 2 && + ptr->state != QNetworkConfiguration::Active) { + ptr->state = QNetworkConfiguration::Active; + emit configurationChanged(ptr); + } + } +} + +void QNetworkManagerEngine::deviceAdded(const QDBusObjectPath &path) +{ + QNetworkManagerInterfaceDevice device(path.path()); + if (device.deviceType() == DEVICE_TYPE_802_11_WIRELESS) { + QNetworkManagerInterfaceDeviceWireless *wirelessDevice = + new QNetworkManagerInterfaceDeviceWireless(device.connectionInterface()->path()); + wirelessDevices.insert(path.path(), wirelessDevice); + + wirelessDevice->setConnections(); + connect(wirelessDevice, SIGNAL(accessPointAdded(QString,QDBusObjectPath)), + this, SLOT(newAccessPoint(QString,QDBusObjectPath))); + connect(wirelessDevice, SIGNAL(accessPointRemoved(QString,QDBusObjectPath)), + this, SLOT(removeAccessPoint(QString,QDBusObjectPath))); + connect(wirelessDevice, SIGNAL(propertiesChanged(QString,QMap)), + this, SLOT(devicePropertiesChanged(QString,QMap))); + + foreach (const QDBusObjectPath &apPath, wirelessDevice->getAccessPoints()) + newAccessPoint(QString(), apPath); + } +} + +void QNetworkManagerEngine::deviceRemoved(const QDBusObjectPath &path) +{ + delete wirelessDevices.value(path.path()); +} + +void QNetworkManagerEngine::newConnection(const QDBusObjectPath &path, + QNetworkManagerSettings *settings) +{ + if (!settings) + settings = qobject_cast(sender()); + + if (!settings) + return; + + QNetworkManagerSettingsConnection *connection = + new QNetworkManagerSettingsConnection(settings->connectionInterface()->service(), + path.path()); + connections.append(connection); + + connect(connection, SIGNAL(removed(QString)), this, SLOT(removeConnection(QString))); + connect(connection, SIGNAL(updated(const QNmSettingsMap&)), + this, SLOT(updateConnection(const QNmSettingsMap&))); + + const QString service = connection->connectionInterface()->service(); + const QString settingsPath = connection->connectionInterface()->path(); + + QNetworkConfigurationPrivate *cpPriv = + parseConnection(service, settingsPath, connection->getSettings()); + + // Check if connection is active. + foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { + QNetworkManagerConnectionActive activeConnection(acPath.path()); + + if (activeConnection.serviceName() == service && + activeConnection.connection().path() == settingsPath && + activeConnection.state() == 2) { + cpPriv->state |= QNetworkConfiguration::Active; + break; + } + } + + QNetworkConfigurationPrivatePointer ptr(cpPriv); + accessPointConfigurations.insert(ptr->id, ptr); + emit configurationAdded(ptr); +} + +void QNetworkManagerEngine::removeConnection(const QString &path) +{ + QNetworkManagerSettingsConnection *connection = + qobject_cast(sender()); + if (!connection) + return; + + connections.removeAll(connection); + + const QString id = QString::number(qHash(connection->connectionInterface()->service() + ' ' + + connection->connectionInterface()->path())); + + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(id); + ptr->isValid = false; + emit configurationRemoved(ptr); +} + +void QNetworkManagerEngine::updateConnection(const QNmSettingsMap &settings) +{ + QNetworkManagerSettingsConnection *connection = + qobject_cast(sender()); + if (!connection) + return; + + const QString service = connection->connectionInterface()->service(); + const QString settingsPath = connection->connectionInterface()->path(); + + qDebug() << "Should parse connection directly into existing configuration"; + QNetworkConfigurationPrivate *cpPriv = parseConnection(service, settingsPath, settings); + + // Check if connection is active. + foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { + QNetworkManagerConnectionActive activeConnection(acPath.path()); + + if (activeConnection.serviceName() == service && + activeConnection.connection().path() == settingsPath && + activeConnection.state() == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { + cpPriv->state |= QNetworkConfiguration::Active; + break; + } + } + + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(cpPriv->id); + + ptr->isValid = cpPriv->isValid; + ptr->name = cpPriv->name; + ptr->id = cpPriv->id; + ptr->state = cpPriv->state; + + emit configurationChanged(ptr); + delete cpPriv; +} + +void QNetworkManagerEngine::activationFinished(QDBusPendingCallWatcher *watcher) +{ + QDBusPendingReply reply = *watcher; + if (reply.isError()) { + qDebug() << "error connecting NM connection"; + } else { + QDBusObjectPath result = reply.value(); + + QNetworkManagerConnectionActive activeConnection(result.path()); + + const QString id = QString::number(qHash(activeConnection.serviceName() + ' ' + + activeConnection.connection().path())); + + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + if (ptr) { + if (activeConnection.state() == 2 && + ptr->state != QNetworkConfiguration::Active) { + ptr->state = QNetworkConfiguration::Active; + emit configurationChanged(ptr); + } + } + } +} + +void QNetworkManagerEngine::newAccessPoint(const QString &path, const QDBusObjectPath &objectPath) +{ + QNetworkManagerInterfaceAccessPoint *accessPoint = + new QNetworkManagerInterfaceAccessPoint(objectPath.path()); + accessPoints.append(accessPoint); + + accessPoint->setConnections(); + connect(accessPoint, SIGNAL(propertiesChanged(QMap)), + this, SLOT(updateAccessPoint(QMap))); + + // Check if configuration for this SSID already exists. + for (int i = 0; i < accessPoints.count(); ++i) { + if (accessPoint != accessPoints.at(i) && + accessPoint->ssid() == accessPoints.at(i)->ssid()) { + return; + } + } + + // Check if configuration exists for connection. + for (int i = 0; i < connections.count(); ++i) { + QNetworkManagerSettingsConnection *connection = connections.at(i); + + if (accessPoint->ssid() == connection->getSsid()) { + const QString service = connection->connectionInterface()->service(); + const QString settingsPath = connection->connectionInterface()->path(); + const QString connectionId = QString::number(qHash(service + ' ' + settingsPath)); + + QNetworkConfigurationPrivatePointer ptr = + accessPointConfigurations.value(connectionId); + ptr->state = QNetworkConfiguration::Discovered; + emit configurationChanged(ptr); + return; + } + } + + // New access point. + QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); + + ptr->name = accessPoint->ssid(); + ptr->isValid = true; + ptr->id = QString::number(qHash(objectPath.path())); + ptr->type = QNetworkConfiguration::InternetAccessPoint; + ptr->purpose = QNetworkConfiguration::PublicPurpose; + ptr->state = QNetworkConfiguration::Undefined; + + accessPointConfigurations.insert(ptr->id, ptr); + emit configurationAdded(ptr); +} + +void QNetworkManagerEngine::removeAccessPoint(const QString &path, + const QDBusObjectPath &objectPath) +{ + for (int i = 0; i < accessPoints.count(); ++i) { + QNetworkManagerInterfaceAccessPoint *accessPoint = accessPoints.at(i); + + if (accessPoint->connectionInterface()->path() == objectPath.path()) { + accessPoints.removeOne(accessPoint); + + if (configuredAccessPoints.contains(accessPoint)) { + // find connection and change state to Defined + configuredAccessPoints.removeOne(accessPoint); + qDebug() << "At least one connection is no longer discovered."; + } else { + // emit configurationRemoved(cpPriv); + qDebug() << "An unconfigured wifi access point was removed."; + } + + break; + } + } +} + +void QNetworkManagerEngine::updateAccessPoint(const QMap &map) +{ + QNetworkManagerInterfaceAccessPoint *accessPoint = + qobject_cast(sender()); + if (!accessPoint) + return; + + qDebug() << "update access point" << accessPoint; +} + +QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QString &service, + const QString &settingsPath, + const QNmSettingsMap &map) +{ + QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + cpPriv->name = map.value("connection").value("id").toString(); + cpPriv->isValid = true; + cpPriv->id = QString::number(qHash(service + ' ' + settingsPath)); + cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + + cpPriv->purpose = QNetworkConfiguration::PublicPurpose; + + cpPriv->state = QNetworkConfiguration::Defined; + + const QString connectionType = map.value("connection").value("type").toString(); + + if (connectionType == QLatin1String("802-3-ethernet")) { + foreach (const QDBusObjectPath &devicePath, interface->getDevices()) { + QNetworkManagerInterfaceDevice device(devicePath.path()); + if (device.deviceType() == DEVICE_TYPE_802_3_ETHERNET) { + QNetworkManagerInterfaceDeviceWired wiredDevice(device.connectionInterface()->path()); + if (wiredDevice.carrier()) { + cpPriv->state |= QNetworkConfiguration::Discovered; + break; + } + + } + } + } else if (connectionType == QLatin1String("802-11-wireless")) { + const QString connectionSsid = map.value("802-11-wireless").value("ssid").toString(); + + for (int i = 0; i < accessPoints.count(); ++i) { + if (connectionSsid == accessPoints.at(i)->ssid()) { + cpPriv->state |= QNetworkConfiguration::Discovered; + if (!configuredAccessPoints.contains(accessPoints.at(i))) { + configuredAccessPoints.append(accessPoints.at(i)); + + const QString accessPointId = + QString::number(qHash(accessPoints.at(i)->connectionInterface()->path())); + QNetworkConfigurationPrivatePointer ptr = + accessPointConfigurations.take(accessPointId); + emit configurationRemoved(ptr); + } + break; + } + } + } + + return cpPriv; +} + +QNetworkManagerSettingsConnection *QNetworkManagerEngine::connectionFromId(const QString &id) const +{ + for (int i = 0; i < connections.count(); ++i) { + QNetworkManagerSettingsConnection *connection = connections.at(i); + const QString service = connection->connectionInterface()->service(); + const QString settingsPath = connection->connectionInterface()->path(); + + const QString identifier = QString::number(qHash(service + ' ' + settingsPath)); + + if (id == identifier) + return connection; + } + + return 0; +} + +QNetworkSession::State QNetworkManagerEngine::sessionStateForId(const QString &id) +{ + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + if (!ptr) + return QNetworkSession::Invalid; + + if (!ptr->isValid) + return QNetworkSession::Invalid; + + foreach (const QString &acPath, activeConnections.keys()) { + QNetworkManagerConnectionActive *activeConnection = activeConnections.value(acPath); + + const QString identifier = QString::number(qHash(activeConnection->serviceName() + ' ' + + activeConnection->connection().path())); + + if (id == identifier) { + switch (activeConnection->state()) { + case 0: + return QNetworkSession::Disconnected; + case 1: + return QNetworkSession::Connecting; + case 2: + return QNetworkSession::Connected; + } + } + } + + if ((ptr->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) + return QNetworkSession::Disconnected; + else if ((ptr->state & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) + return QNetworkSession::NotAvailable; + else if ((ptr->state & QNetworkConfiguration::Undefined) == QNetworkConfiguration::Undefined) + return QNetworkSession::NotAvailable; + + return QNetworkSession::Invalid; +} + +QT_END_NAMESPACE + diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h new file mode 100644 index 0000000..9e8af3b --- /dev/null +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QNETWORKMANAGERENGINE_P_H +#define QNETWORKMANAGERENGINE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of the QLibrary class. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include + +#include "qnetworkmanagerservice.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +class QNetworkManagerEngine : public QNetworkSessionEngine +{ + Q_OBJECT + +public: + QNetworkManagerEngine(QObject *parent = 0); + ~QNetworkManagerEngine(); + + QString getInterfaceFromId(const QString &id); + bool hasIdentifier(const QString &id); + + QString bearerName(const QString &id); + + void connectToId(const QString &id); + void disconnectFromId(const QString &id); + + void requestUpdate(); + + QNetworkSession::State sessionStateForId(const QString &id); + +private Q_SLOTS: + void interfacePropertiesChanged(const QString &path, + const QMap &properties); + void activeConnectionPropertiesChanged(const QString &path, + const QMap &properties); + + void deviceAdded(const QDBusObjectPath &path); + void deviceRemoved(const QDBusObjectPath &path); + + void newConnection(const QDBusObjectPath &path, QNetworkManagerSettings *settings = 0); + void removeConnection(const QString &path); + void updateConnection(const QNmSettingsMap &settings); + void activationFinished(QDBusPendingCallWatcher *watcher); + + void newAccessPoint(const QString &path, const QDBusObjectPath &objectPath); + void removeAccessPoint(const QString &path, const QDBusObjectPath &objectPath); + void updateAccessPoint(const QMap &map); + + void doRequestUpdate(); + +private: + QNetworkConfigurationPrivate *parseConnection(const QString &service, + const QString &settingsPath, + const QNmSettingsMap &map); + QNetworkManagerSettingsConnection *connectionFromId(const QString &id) const; + +private: + QNetworkManagerInterface *interface; + QNetworkManagerSettings *systemSettings; + QNetworkManagerSettings *userSettings; + QHash wirelessDevices; + QHash activeConnections; + QList connections; + QList accessPoints; + QList configuredAccessPoints; +}; + +QT_END_NAMESPACE + +#endif + diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp index e95c2e6..9376324 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp @@ -95,6 +95,7 @@ QNetworkManagerInterface::~QNetworkManagerInterface() { delete d->connectionInterface; delete d; + delete nmDBusHelper; } bool QNetworkManagerInterface::isValid() @@ -692,9 +693,12 @@ bool QNetworkManagerSettingsConnection::setConnections() bool allOk = false; if(!dbusConnection.connect(d->service, d->path, - NM_DBUS_IFACE_SETTINGS_CONNECTION, "NewConnection", + NM_DBUS_IFACE_SETTINGS_CONNECTION, "Updated", this, SIGNAL(updated(QNmSettingsMap)))) { allOk = true; + } else { + QDBusError error = dbusConnection.lastError(); + qDebug() << error.name() << error.message() << error.type(); } nmDBusHelper = new QNmDBusHelper; diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h index 8bed45b..dbed01e 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h @@ -329,8 +329,8 @@ public: Q_SIGNALS: - void updated(QMap< QString, QMap > s); - void removed(const QString &); + void updated(const QNmSettingsMap &settings); + void removed(const QString &path); private: QNmDBusHelper *nmDBusHelper; diff --git a/src/plugins/bearer/networkmanager/qnmdbushelper.cpp b/src/plugins/bearer/networkmanager/qnmdbushelper.cpp index 1d16e55..f93a63d 100644 --- a/src/plugins/bearer/networkmanager/qnmdbushelper.cpp +++ b/src/plugins/bearer/networkmanager/qnmdbushelper.cpp @@ -96,11 +96,14 @@ void QNmDBusHelper::slotPropertiesChanged(QMap map) emit pathForPropertiesChanged( msg.path(), map); } } else if( i.key() == "ActiveAccessPoint") { + emit pathForPropertiesChanged(msg.path(), map); // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().value().path(); // } else if( i.key() == "Strength") // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().toUInt(); // else // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value(); + } else if (i.key() == "ActiveConnections") { + emit pathForPropertiesChanged(msg.path(), map); } } } diff --git a/src/plugins/bearer/networkmanager/qnmdbushelper.h b/src/plugins/bearer/networkmanager/qnmdbushelper.h index 9794f98..410b69f 100644 --- a/src/plugins/bearer/networkmanager/qnmdbushelper.h +++ b/src/plugins/bearer/networkmanager/qnmdbushelper.h @@ -42,25 +42,12 @@ #ifndef QNMDBUSHELPERPRIVATE_H #define QNMDBUSHELPERPRIVATE_H -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - #include #include #include QT_BEGIN_NAMESPACE -#if !defined(QT_NO_DBUS) && !defined(Q_OS_MAC) - class QNmDBusHelper: public QObject, protected QDBusContext { Q_OBJECT @@ -80,7 +67,6 @@ Q_SIGNALS: void pathForPropertiesChanged(const QString &, QMap); void pathForSettingsRemoved(const QString &); }; -#endif QT_END_NAMESPACE diff --git a/src/plugins/bearer/networkmanager/qnmwifiengine.cpp b/src/plugins/bearer/networkmanager/qnmwifiengine.cpp deleted file mode 100644 index b215023..0000000 --- a/src/plugins/bearer/networkmanager/qnmwifiengine.cpp +++ /dev/null @@ -1,1128 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qnmwifiengine.h" - -#include -#include - -#include - -#include -#include -#include "qnetworkmanagerservice.h" - -#include - -QT_BEGIN_NAMESPACE - -Q_GLOBAL_STATIC(QNmWifiEngine, nmWifiEngine) -typedef QList > QNmSettingsAddressMap; - -Q_DECLARE_METATYPE(QNmSettingsAddressMap) - -QNmWifiEngine::QNmWifiEngine(QObject *parent) -: QNetworkSessionEngine(parent) -{ - iface = new QNetworkManagerInterface(); - if(!iface->isValid()) { - return; - } - iface->setConnections(); - connect(iface,SIGNAL(deviceAdded(QDBusObjectPath)), - this,SLOT(addDevice(QDBusObjectPath))); - connect(iface,SIGNAL(deviceRemoved(QDBusObjectPath)), - this,SLOT(removeDevice(QDBusObjectPath))); - - QList list = iface->getDevices(); - - foreach(QDBusObjectPath path, list) { - addDevice(path); - } - - QStringList connectionServices; - connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; - connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; - foreach (QString service, connectionServices) { - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); - settingsiface->setConnections(); - connect(settingsiface,SIGNAL(newConnection(QDBusObjectPath)), - this,(SLOT(newConnection(QDBusObjectPath)))); - } - - updated = false; -} - -QNmWifiEngine::~QNmWifiEngine() -{ -} - -QString QNmWifiEngine::getNameForConfiguration(QNetworkManagerInterfaceDevice *devIface) -{ - QString newname; - if (devIface->state() == NM_DEVICE_STATE_ACTIVATED) { - QString path = devIface->ip4config().path(); - QNetworkManagerIp4Config * ipIface; - ipIface = new QNetworkManagerIp4Config(path); - newname = ipIface->domains().join(" "); - } - //fallback to interface name - if(newname.isEmpty()) - newname = devIface->interface().name(); - return newname; -} - - -QList QNmWifiEngine::getConfigurations(bool *ok) -{ -// qWarning() << Q_FUNC_INFO << updated; - if (ok) - *ok = false; - - if(!updated) { - foundConfigurations.clear(); - if(knownSsids.isEmpty()) - getKnownSsids(); // list of ssids that have user configurations. - - scanForAccessPoints(); - getActiveConnectionsPaths(); - knownConnections(); - - accessPointConnections(); - -// findConnections(); - //add access points - updated = true; - } - return QList(); //foundConfigurations; -} - -void QNmWifiEngine::findConnections() -{ - QList list = iface->getDevices(); - - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); - - //// eth - switch (devIface->deviceType()) { -// qWarning() << devIface->connectionInterface()->path(); - - case DEVICE_TYPE_802_3_ETHERNET: - { - QString ident; - QNetworkManagerInterfaceDeviceWired *devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); - - ident = devWiredIface->hwAddress(); - - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - cpPriv->name = getNameForConfiguration(devIface); - cpPriv->isValid = true; - cpPriv->id = ident; - cpPriv->internet = devWiredIface->carrier(); - - cpPriv->serviceInterface = devIface->interface(); - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - switch (devIface->state()) { - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_UNMANAGED: - case NM_DEVICE_STATE_FAILED: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Undefined); - break; - case NM_DEVICE_STATE_UNAVAILABLE: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Defined); - break; - case NM_DEVICE_STATE_PREPARE: - case NM_DEVICE_STATE_CONFIG: - case NM_DEVICE_STATE_NEED_AUTH: - case NM_DEVICE_STATE_IP_CONFIG: - case NM_DEVICE_STATE_DISCONNECTED: - { - cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Discovered - | QNetworkConfiguration::Defined); - } - break; - case NM_DEVICE_STATE_ACTIVATED: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Active ); - break; - default: - cpPriv->state = (cpPriv->state | QNetworkConfiguration::Undefined); - break; - }; - cpPriv->purpose = QNetworkConfiguration::PublicPurpose; - foundConfigurations.append(cpPriv); - configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); - } - break; - case DEVICE_TYPE_802_11_WIRELESS: - { -// QNetworkManagerInterfaceDeviceWireless *devWirelessIface; -// devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); -// -// //// connections -// QStringList connectionServices; -// connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; -// connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; -// -// QString connPath; -// -// foreach (QString service, connectionServices) { -// QString ident; -// QNetworkManagerSettings *settingsiface; -// settingsiface = new QNetworkManagerSettings(service); -// QList list = settingsiface->listConnections(); -// -// foreach(QDBusObjectPath path, list) { //for each connection path -//qWarning() << path.path(); -// ident = path.path(); -// bool addIt = false; -// QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); -// cpPriv->isValid = true; -// cpPriv->id = ident; -// cpPriv->internet = true; -// -// cpPriv->type = QNetworkConfiguration::InternetAccessPoint; -// cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Discovered -// | QNetworkConfiguration::Defined); -// cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; -// -// QNetworkManagerSettingsConnection *sysIface; -// sysIface = new QNetworkManagerSettingsConnection(service, path.path()); -// cpPriv->name = sysIface->getId();//ii.value().toString(); -//qWarning() << cpPriv->name; -// if(sysIface->getType() == DEVICE_TYPE_802_3_ETHERNET/*type == "802-3-ethernet"*/ -// && devIface->deviceType() == DEVICE_TYPE_802_3_ETHERNET) { -// cpPriv->serviceInterface = devIface->interface(); -// addIt = true; -// } else if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS/*type == "802-11-wireless"*/ -// && devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { -// cpPriv->serviceInterface = devIface->interface(); -// addIt = true; -// // get the wifi interface state first.. do we need this? -// // QString activeAPPath = devWirelessIface->activeAccessPoint().path(); -// } -// -// //#if 0 -// foreach(QString conpath, activeConnectionPaths) { -// QNetworkManagerConnectionActive *aConn; -// aConn = new QNetworkManagerConnectionActive(conpath); -// // in case of accesspoint, specificObject will hold the accessPOintObjectPath -// // qWarning() << aConn->connection().path() << aConn->specificObject().path() << aConn->devices().count(); -// if( aConn->connection().path() == ident) { -// -// QList devs = aConn->devices(); -// foreach(QDBusObjectPath device, devs) { -// QNetworkManagerInterfaceDevice *ifaceDevice; -// ifaceDevice = new QNetworkManagerInterfaceDevice(device.path()); -// cpPriv->serviceInterface = ifaceDevice->interface(); -// cpPriv->state = getStateFlag(ifaceDevice->state()); -// //cpPriv->accessPoint = aConn->specificObject().path(); -// -// break; -// } -// } -// } -// //#endif -// // } //end while connection -// if(addIt) { -// foundConfigurations.append(cpPriv); -// configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); -// } -// } -// } //end each connection service -// -// // ////////////// AccessPoints -//// QList apList = devWirelessIface->getAccessPoints(); -////// qWarning() << apList.count(); -//// foreach(QDBusObjectPath path, apList) { -//// QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); -//// cpPriv = addAccessPoint( devIface->connectionInterface()->path(), path); -//// if(cpPriv->isValid) { -//// foundConfigurations.append(cpPriv); -//// } -//// } - } // end DEVICE_TYPE_802_11_WIRELESS - break; - }; - } //end foreach device -} - -void QNmWifiEngine::knownConnections() -{ -// qWarning() << Q_FUNC_INFO; - //// connections - QStringList connectionServices; - connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; - connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; - - QString connPath; - - foreach (QString service, connectionServices) { - QString ident; - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); - QList list = settingsiface->listConnections(); - -// qWarning() <setConnections(); - connect(sysIface, SIGNAL(removed(QString)), - this,SLOT(settingsConnectionRemoved(QString))); - - cpPriv->name = sysIface->getId(); - cpPriv->isValid = true; - cpPriv->id = sysIface->getUuid(); -// cpPriv->id = ident; - cpPriv->internet = true; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; -//qWarning() << cpPriv->name; - cpPriv->state = getStateForId(cpPriv->id); - - cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; - - if(sysIface->getType() == DEVICE_TYPE_802_3_ETHERNET) { - QString mac = sysIface->getMacAddress(); - if(!mac.length() > 2) { - qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXX" << mac << "type ethernet"; - QString devPath; - devPath = deviceConnectionPath(mac); - - // qWarning() << Q_FUNC_INFO << devPath; - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(devPath); - cpPriv->serviceInterface = devIface->interface(); - QNetworkManagerInterfaceDeviceWired *devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); - cpPriv->internet = devWiredIface->carrier(); - - // use this mac addy - } else { - cpPriv->serviceInterface = getBestInterface( DEVICE_TYPE_802_3_ETHERNET, cpPriv->id); - } - - cpPriv->internet = true;//sysIface->isAutoConnect(); - - addIt = true; - } else if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) { - QString mac = sysIface->getMacAddress();; - if(!mac.length() > 2) { - qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXX" << mac << "type wireless"; - QString devPath; - devPath = deviceConnectionPath(mac); -// qWarning() << Q_FUNC_INFO << devPath; - - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(devPath); - cpPriv->serviceInterface = devIface->interface(); - // use this mac addy - } else { - cpPriv->serviceInterface = getBestInterface( DEVICE_TYPE_802_11_WIRELESS, cpPriv->id); - } - // cpPriv->serviceInterface = devIface->interface(); - addIt = true; - // get the wifi interface state first.. do we need this? - // QString activeAPPath = devWirelessIface->activeAccessPoint().path(); - } - if(addIt) { - foundConfigurations.append(cpPriv); - configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); - } - } //end each connection service - } -} - -void QNmWifiEngine::accessPointConnections() -{ - //qWarning() << Q_FUNC_INFO; - QList list = iface->getDevices(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(path.path()); - if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { - QList apList = availableAccessPoints.uniqueKeys(); - - QList::const_iterator i; - for (i = apList.constBegin(); i != apList.constEnd(); ++i) { - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - cpPriv = addAccessPoint( devIface->connectionInterface()->path(), availableAccessPoints[*i]); - if(cpPriv->isValid) { - foundConfigurations.append(cpPriv); - // qWarning() << "adding" << cpPriv->name << "to things"; - configurationInterface[cpPriv->id] = cpPriv->serviceInterface.name(); - } - } - } - } -} - -QString QNmWifiEngine::getInterfaceFromId(const QString &id) -{ - return configurationInterface.value(id); -} - -bool QNmWifiEngine::hasIdentifier(const QString &id) -{ - if (configurationInterface.contains(id)) - return true; - foreach (QNetworkConfigurationPrivatePointer cpPriv, getConfigurations()) { - if (cpPriv->id == id) - return true; - } - return false; -} - -QString QNmWifiEngine::bearerName(const QString &id) -{ - QString interface = getInterfaceFromId(id); - - QList list = iface->getDevices(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(path.path()); - if(interface == devIface->interface().name()) { - switch(devIface->deviceType()) { - case DEVICE_TYPE_802_3_ETHERNET/*NM_DEVICE_TYPE_ETHERNET*/: - return QLatin1String("Ethernet"); - break; - case DEVICE_TYPE_802_11_WIRELESS/*NM_DEVICE_TYPE_WIFI*/: - return QLatin1String("WLAN"); - break; - case DEVICE_TYPE_GSM/*NM_DEVICE_TYPE_GSM*/: - return QLatin1String("2G"); - break; - case DEVICE_TYPE_CDMA/*NM_DEVICE_TYPE_CDMA*/: - return QLatin1String("CDMA2000"); - break; - default: - break; - }; - } - } - return QString(); -} - -void QNmWifiEngine::connectToId(const QString &id) -{ -// qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << __FUNCTION__ << id; - activatingConnectionPath = id; - QStringList connectionSettings = getConnectionPathForId(id); - if(connectionSettings.isEmpty()) { - emit connectionError(id, OperationNotSupported); - return; - } - - QDBusObjectPath connectionPath(connectionSettings.at(1)); - QString interface = getInterfaceFromId(id); - - interface = QNetworkInterface::interfaceFromName(interface).hardwareAddress().toLower(); - QString devPath; - devPath = deviceConnectionPath(interface); - QDBusObjectPath devicePath(devPath); - - iface = new QNetworkManagerInterface(); - iface->activateConnection( - connectionSettings.at(0), - connectionPath, - devicePath, - connectionPath); - - connect(iface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)), - this, SLOT(slotActivationFinished(QDBusPendingCallWatcher*))); -} - -void QNmWifiEngine::disconnectFromId(const QString &id) -{ - QString activeConnectionPath = getActiveConnectionPath(id); - //qWarning() <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << __FUNCTION__ << id << activeConnectionPath ; - - if (!activeConnectionPath.isEmpty()) { - QNetworkManagerConnectionActive *activeCon; - activeCon = new QNetworkManagerConnectionActive(activeConnectionPath); - QNetworkManagerSettingsConnection *settingsCon; - settingsCon = new QNetworkManagerSettingsConnection(activeCon->serviceName(), activeCon->connection().path()); - - if(settingsCon->isAutoConnect()) { -// qWarning() << id << "is autoconnect"; - emit connectionError(id, OperationNotSupported); - //unsupported - } else { -// qWarning() <deactivateConnection(dbpath); - activatingConnectionPath = ""; - } - } -} - -void QNmWifiEngine::requestUpdate() -{ - updated = false; - knownSsids.clear(); - availableAccessPoints.clear(); - //emitConfigurationsChanged(); -} - -QNmWifiEngine *QNmWifiEngine::instance() -{ - QDBusConnection dbusConnection = QDBusConnection::systemBus(); - if (dbusConnection.isConnected()) { - QDBusConnectionInterface *dbiface = dbusConnection.interface(); - QDBusReply reply = dbiface->isServiceRegistered("org.freedesktop.NetworkManager"); - if (reply.isValid() && reply.value()) - return nmWifiEngine(); - } - - return 0; -} - -void QNmWifiEngine::getKnownSsids() -{ - QStringList connectionServices; - connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; - connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; -//qWarning() << Q_FUNC_INFO; - foreach (QString service, connectionServices) { - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); - QList list = settingsiface->listConnections(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(service, path.path()); -// qWarning() << sysIface->getSsid(); - knownSsids << sysIface->getSsid(); - } - } -} - -void QNmWifiEngine::getActiveConnectionsPaths() -{ -// qWarning() << Q_FUNC_INFO; - QNetworkManagerInterface *dbIface; - activeConnectionPaths.clear(); - dbIface = new QNetworkManagerInterface; - QList connections = dbIface->activeConnections(); - - foreach(QDBusObjectPath conpath, connections) { - activeConnectionPaths << conpath.path(); -// qWarning() << __FUNCTION__ << conpath.path() << activeConnectionPaths.count(); - - QNetworkManagerConnectionActive *activeConn; - activeConn = new QNetworkManagerConnectionActive(conpath.path()); - -// qWarning() << activeConn->connection().path() /*<< activeConn->specificObject().path() */<< activeConn->devices()[0].path(); - - } -} - -QNetworkConfigurationPrivate * QNmWifiEngine::addAccessPoint( const QString &iPath, QDBusObjectPath path) -{ //foreach accessPoint - //qWarning() << Q_FUNC_INFO << iPath << path.path(); - - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(iPath); - QNetworkManagerInterfaceDeviceWireless *devWirelessIface; - devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(iPath); - - QString activeAPPath = devWirelessIface->activeAccessPoint().path(); - - QNetworkManagerInterfaceAccessPoint *accessPointIface; - accessPointIface = new QNetworkManagerInterfaceAccessPoint(path.path()); - - QString ident = accessPointIface->connectionInterface()->path(); - quint32 nmState = devIface->state(); - - QString ssid = accessPointIface->ssid(); - QString hwAddy = accessPointIface->hwAddress(); - QString sInterface = devIface->interface().name(); - - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - bool addIt = true; - //qWarning() << availableAccessPoints.count() << ssid; - -// if(availableAccessPoints.contains(ssid)) { -// addIt = false; -// -// } -// foreach (QNetworkConfigurationPrivate *cpPriv, foundConfigurations) { -// if (cpPriv->name == ssid) { //weed out duplicate ssid's ?? -// addIt = false; -// break; -// } -// } - - if(addIt) { - - cpPriv->name = ssid; - cpPriv->isValid = true; - cpPriv->id = ident; - cpPriv->internet = true; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - cpPriv->serviceInterface = devIface->interface(); - - //qWarning() <<__FUNCTION__ << ssid; - - cpPriv->state = getAPState(nmState, knownSsids.contains(cpPriv->name)); - - if(activeAPPath == accessPointIface->connectionInterface()->path()) { - cpPriv->state = ( cpPriv->state | QNetworkConfiguration::Active); - } - if(accessPointIface->flags() == NM_802_11_AP_FLAGS_PRIVACY) - cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; - else - cpPriv->purpose = QNetworkConfiguration::PublicPurpose; - return cpPriv; - } else { - cpPriv->isValid = false; - } - return cpPriv; -} - - - QNetworkConfiguration::StateFlags QNmWifiEngine::getAPState(qint32 nmState, bool isKnown) -{ - QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; -//qWarning() << nmState << knownSsids; - // this is the state of the wifi device interface - if(isKnown) - state = ( QNetworkConfiguration::Defined); - - switch(nmState) { //device interface state, not AP state - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_UNMANAGED: - case NM_DEVICE_STATE_UNAVAILABLE: - state = (QNetworkConfiguration::Undefined); - break; - case NM_DEVICE_STATE_DISCONNECTED: - { - if(isKnown) - state = ( state | QNetworkConfiguration::Discovered); - } - break; - case NM_DEVICE_STATE_PREPARE: - case NM_DEVICE_STATE_CONFIG: - case NM_DEVICE_STATE_NEED_AUTH: - case NM_DEVICE_STATE_IP_CONFIG: - if(isKnown) - state = ( state | QNetworkConfiguration::Discovered); - break; - case NM_DEVICE_STATE_ACTIVATED: - { - if(isKnown) - state = ( state | QNetworkConfiguration::Discovered); - } - break; - }; - return state; -} - -QString QNmWifiEngine::getActiveConnectionPath(const QString &id) -{ - //qWarning() << Q_FUNC_INFO << id; - QStringList connectionSettings = getConnectionPathForId(id); - //qWarning() << Q_FUNC_INFO << id << connectionSettings.count(); - QNetworkManagerInterface * ifaceD; - ifaceD = new QNetworkManagerInterface(); - QList connections = ifaceD->activeConnections(); - foreach(QDBusObjectPath path, connections) { - QNetworkManagerConnectionActive *conDetailsD; - conDetailsD = new QNetworkManagerConnectionActive( path.path()); - if(conDetailsD->connection().path() == connectionSettings.at(1) - && conDetailsD->serviceName() == connectionSettings.at(0)) - return path.path(); - } - return QString(); -} - - QNetworkConfiguration::StateFlags QNmWifiEngine::getStateFlag(quint32 nmstate) - { -// qWarning() << Q_FUNC_INFO << nmstate; - QNetworkConfiguration::StateFlags flag; - switch (nmstate) { - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_FAILED: - case NM_DEVICE_STATE_UNMANAGED: - flag = (QNetworkConfiguration::Undefined); - break; - case NM_DEVICE_STATE_PREPARE: - case NM_DEVICE_STATE_CONFIG: - case NM_DEVICE_STATE_NEED_AUTH: - case NM_DEVICE_STATE_IP_CONFIG: - case NM_DEVICE_STATE_UNAVAILABLE: - flag = (QNetworkConfiguration::Defined); - break; - case NM_DEVICE_STATE_DISCONNECTED: - flag = ( flag | QNetworkConfiguration::Discovered ); - break; - case NM_DEVICE_STATE_ACTIVATED: - { - flag = ( flag | QNetworkConfiguration::Discovered - | QNetworkConfiguration::Active ); - } - break; - default: - flag = ( QNetworkConfiguration::Defined); - break; - }; - return flag; - } - -void QNmWifiEngine::updateDeviceInterfaceState(const QString &/*path*/, quint32 nmState) -{ -// qWarning() << Q_FUNC_INFO << path << nmState; - - if(nmState == NM_DEVICE_STATE_ACTIVATED - || nmState == NM_DEVICE_STATE_DISCONNECTED - || nmState == NM_DEVICE_STATE_UNAVAILABLE - || nmState == NM_DEVICE_STATE_FAILED) { - -/* InterfaceLookupError = 0, - ConnectError, - OperationNotSupported, - DisconnectionError, -*/ -// qWarning() << Q_FUNC_INFO << ident; - QNetworkConfiguration::StateFlags state = (QNetworkConfiguration::Defined); - switch (nmState) { - case NM_DEVICE_STATE_UNKNOWN: - case NM_DEVICE_STATE_FAILED: - state = (QNetworkConfiguration::Undefined); - emit connectionError(activatingConnectionPath, ConnectError); - requestUpdate(); -// qWarning() << Q_FUNC_INFO; - break; - case NM_DEVICE_STATE_UNAVAILABLE: - state = (QNetworkConfiguration::Defined); -// emit connectionError(activatingConnectionPath, ConnectError); - requestUpdate(); - break; - case NM_DEVICE_STATE_DISCONNECTED: - state = ( state | QNetworkConfiguration::Discovered ); - requestUpdate(); - break; - case NM_DEVICE_STATE_ACTIVATED: - { - state = ( state | QNetworkConfiguration::Discovered - | QNetworkConfiguration::Active ); - requestUpdate(); - } - break; - default: - state = ( QNetworkConfiguration::Defined); - break; - }; - } -} - -void QNmWifiEngine::addDevice(QDBusObjectPath path) -{ - //qWarning() << Q_FUNC_INFO << path.path(); - QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); - devIface->setConnections(); - connect(devIface,SIGNAL(stateChanged(const QString &, quint32)), - this, SLOT(updateDeviceInterfaceState(const QString&, quint32))); - - if(!devicePaths.contains(path.path())) - devicePaths << path.path(); - - switch(devIface->deviceType()) { - case DEVICE_TYPE_802_3_ETHERNET: - { - QNetworkManagerInterfaceDeviceWired * devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(devIface->connectionInterface()->path()); - devWiredIface->setConnections(); - connect(devWiredIface, SIGNAL(propertiesChanged(const QString &,QMap)), - this,SLOT(cmpPropertiesChanged( const QString &, QMap))); - requestUpdate(); - } - break; - case DEVICE_TYPE_802_11_WIRELESS: - { - QNetworkManagerInterfaceDeviceWireless *devWirelessIface; - devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); - devWirelessIface->setConnections(); - - connect(devWirelessIface, SIGNAL(propertiesChanged(const QString &,QMap)), - this,SLOT(cmpPropertiesChanged( const QString &, QMap))); - - connect(devWirelessIface, SIGNAL(accessPointAdded(const QString &,QDBusObjectPath)), - this,SLOT(accessPointAdded(const QString &,QDBusObjectPath))); - - connect(devWirelessIface, SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath)), - this,SLOT(accessPointRemoved(const QString &,QDBusObjectPath))); - requestUpdate(); - - } - break; - default: - break; - }; -} - -void QNmWifiEngine::removeDevice(QDBusObjectPath /*path*/) -{ -// qWarning() << Q_FUNC_INFO << path.path(); -// disconnect(devIface,SIGNAL(stateChanged(const QString &, quint32)), -// this, SLOT(updateDeviceInterfaceState(const QString&, quint32))); -// -// if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { -// // devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); -// // devWirelessIface->setConnections(); -// -// disconnect(devWirelessIface, SIGNAL(propertiesChanged(const QString &,QMap)), -// this,SIGNAL(cmpPropertiesChanged( const QString &, QMap))); -// -// disconnect(devWirelessIface, SIGNAL(accessPointAdded(const QString &,QDBusObjectPath)), -// this,SIGNAL(accessPointAdded(const QString &,QDBusObjectPath))); -// -// disconnect(devWirelessIface, SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath)), -// this,SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath))); -// -// } -} -void QNmWifiEngine::cmpPropertiesChanged(const QString &path, QMap map) -{ - QMapIterator i(map); - while (i.hasNext()) { - i.next(); -// qWarning() << Q_FUNC_INFO << path << i.key() << i.value().toUInt(); - if( i.key() == "State") { //only applies to device interfaces - updateDeviceInterfaceState(path, i.value().toUInt()); - } - if( i.key() == "ActiveAccessPoint") { - } - if( i.key() == "Carrier") { //someone got plugged in - // requestUpdate(); - } - } -} - -void QNmWifiEngine::accessPointRemoved( const QString &aPath, QDBusObjectPath /*oPath*/) -{ - //qWarning() << Q_FUNC_INFO << aPath << oPath.path(); - - if(aPath.contains("devices")) { - requestUpdate(); - } -} - -void QNmWifiEngine::accessPointAdded( const QString &aPath, QDBusObjectPath oPath) -{ - //qWarning() << Q_FUNC_INFO << aPath << oPath.path(); - - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - cpPriv = addAccessPoint( aPath, oPath); - requestUpdate(); -} - -QNetworkConfiguration::StateFlags QNmWifiEngine::getStateForId(const QString &id) -{ - //qWarning() << Q_FUNC_INFO << id; - bool isAvailable = false; - QStringList conPath = getConnectionPathForId(id); - QString aconpath = getActiveConnectionPath(id); - - //qWarning() << Q_FUNC_INFO << id << aconpath; - - if(!aconpath.isEmpty()) { - //active connection - QNetworkManagerConnectionActive *aConn; - aConn = new QNetworkManagerConnectionActive(aconpath); - - QList devs = aConn->devices(); - - foreach(QDBusObjectPath dev, devs) { - //qWarning() << "foreach" << dev.path(); - QNetworkManagerInterfaceDevice *ifaceDevice; - ifaceDevice = new QNetworkManagerInterfaceDevice(dev.path()); - - if(ifaceDevice->deviceType() == DEVICE_TYPE_802_3_ETHERNET) { - - if(isAddressOfConnection(id, ifaceDevice->ip4Address())) { - // this is it! - return getStateFlag(ifaceDevice->state()); - } else { - continue; - } - - if(ifaceDevice->state() == NM_DEVICE_STATE_UNAVAILABLE || - ifaceDevice->state() == NM_DEVICE_STATE_DISCONNECTED) { - isAvailable = true; - - QNetworkManagerInterfaceDeviceWired *devWiredIface; - devWiredIface = new QNetworkManagerInterfaceDeviceWired(ifaceDevice->connectionInterface()->path()); - if(!devWiredIface->carrier()) - return QNetworkConfiguration::Defined; - } //end eth - } else if(ifaceDevice->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { - qWarning() << "FIXME!!!!!!!!!!!!!!!!!"; - } - - return getStateFlag(ifaceDevice->state()); - } - } else { - // not active - //qWarning() << Q_FUNC_INFO << "Not active"; - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(conPath.at(0),conPath.at(1)); - if(sysIface->isValid()) { - if(sysIface->getType() == DEVICE_TYPE_802_11_WIRELESS) { - QString ssid = sysIface->getSsid(); - bool ok = false; - - if(knownSsids.contains(ssid, Qt::CaseSensitive)) { - foreach(QString onessid, knownSsids) { - // qWarning() << ssid << onessid; - if(onessid == ssid && availableAccessPoints.contains(ssid)) { - // qWarning() < devices = aConn->devices(); - foreach(QDBusObjectPath device, devices) { - QNetworkManagerInterfaceDevice *ifaceDevice; - ifaceDevice = new QNetworkManagerInterfaceDevice(device.path()); - if(ifaceDevice->ip4Address() == ipaddress) { - return true; - } - } - return false; -} - -QNetworkInterface QNmWifiEngine::getBestInterface( quint32 type, const QString &id) -{ - // check active connections first. - QStringList conIdPath = getConnectionPathForId(id); -// qWarning() << Q_FUNC_INFO << id << conIdPath; - - QNetworkInterface interface; - foreach(QString conpath, activeConnectionPaths) { - QNetworkManagerConnectionActive *aConn; - aConn = new QNetworkManagerConnectionActive(conpath); - - if(aConn->connection().path() == conIdPath.at(1) - && aConn->serviceName() == conIdPath.at(0)) { - - QList devs = aConn->devices(); - QNetworkManagerInterfaceDevice *ifaceDevice; - ifaceDevice = new QNetworkManagerInterfaceDevice(devs[0].path()); //just take the first one - interface = ifaceDevice->interface(); - return interface; - } - } - -//try guessing - QList list = iface->getDevices(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface = new QNetworkManagerInterfaceDevice(path.path()); - if(devIface->deviceType() == type /*&& devIface->managed()*/) { - interface = devIface->interface(); - if(devIface->state() == NM_STATE_DISCONNECTED) { - return interface; - } - } - } - return interface; -} - -quint64 QNmWifiEngine::receivedDataForId(const QString &id) const -{ - if(configurationInterface.count() > 1) - return 0; - quint64 result = 0; - - QString devFile; - devFile = configurationInterface.value(id); - QFile rx("/sys/class/net/"+devFile+"/statistics/rx_bytes"); - if(rx.exists() && rx.open(QIODevice::ReadOnly | QIODevice::Text)) { - QTextStream in(&rx); - in >> result; - rx.close(); - } - return result; -} - -quint64 QNmWifiEngine::sentDataForId(const QString &id) const -{ - if(configurationInterface.count() > 1) - return 0; - quint64 result = 0; - QString devFile; - devFile = configurationInterface.value(id); - - QFile tx("/sys/class/net/"+devFile+"/statistics/tx_bytes"); - if(tx.exists() && tx.open(QIODevice::ReadOnly | QIODevice::Text)) { - QTextStream in(&tx); - in >> result; - tx.close(); - } - return result; -} - -void QNmWifiEngine::newConnection(QDBusObjectPath /*path*/) -{ - //qWarning() << Q_FUNC_INFO; - requestUpdate(); -} - -void QNmWifiEngine::settingsConnectionRemoved(const QString &/*path*/) -{ - //qWarning() << Q_FUNC_INFO; - requestUpdate(); -} - -void QNmWifiEngine::slotActivationFinished(QDBusPendingCallWatcher *openCall) -{ - QDBusPendingReply reply = *openCall; - if (reply.isError()) { - qWarning() <<"Error" << reply.error().name() << reply.error().message() - < list = iface->getDevices(); - - foreach(QDBusObjectPath path, list) { - QNetworkManagerInterfaceDevice *devIface; - devIface = new QNetworkManagerInterfaceDevice(path.path()); - - if(devIface->deviceType() == DEVICE_TYPE_802_11_WIRELESS) { - -// qWarning() << devIface->connectionInterface()->path(); - - QNetworkManagerInterfaceDeviceWireless *devWirelessIface; - devWirelessIface = new QNetworkManagerInterfaceDeviceWireless(devIface->connectionInterface()->path()); - ////////////// AccessPoints - QList apList = devWirelessIface->getAccessPoints(); - - foreach(QDBusObjectPath path, apList) { - QNetworkManagerInterfaceAccessPoint *accessPointIface; - accessPointIface = new QNetworkManagerInterfaceAccessPoint(path.path()); - QString ssid = accessPointIface->ssid(); - availableAccessPoints.insert(ssid, path); - } - } - } -} - -QString QNmWifiEngine::deviceConnectionPath(const QString &mac) -{ -// qWarning() << __FUNCTION__ << mac; - QString newMac = mac; - newMac = newMac.replace(":","_").toLower(); - //device object path might not contain just mac address - //might contain extra numbers on the end. thanks HAL - foreach(QString device, devicePaths) { - if(device.contains(newMac)) { - newMac = device; - break; - } - } - return newMac; -} - -QStringList QNmWifiEngine::getConnectionPathForId(const QString &uuid) -{ - QStringList connectionServices; - connectionServices << NM_DBUS_SERVICE_SYSTEM_SETTINGS; - connectionServices << NM_DBUS_SERVICE_USER_SETTINGS; -//qWarning() << Q_FUNC_INFO; - foreach (QString service, connectionServices) { - QNetworkManagerSettings *settingsiface; - settingsiface = new QNetworkManagerSettings(service); - QList list = settingsiface->listConnections(); - foreach(QDBusObjectPath path, list) { - QNetworkManagerSettingsConnection *sysIface; - sysIface = new QNetworkManagerSettingsConnection(service, path.path()); -// qWarning() << uuid << sysIface->getUuid(); - if(sysIface->getUuid() == uuid) { -// qWarning() <<__FUNCTION__ << service << sysIface->getId() << sysIface->connectionInterface()->path(); - return QStringList() << service << sysIface->connectionInterface()->path(); - } - } - } - return QStringList(); -} - -QT_END_NAMESPACE - diff --git a/src/plugins/bearer/networkmanager/qnmwifiengine.h b/src/plugins/bearer/networkmanager/qnmwifiengine.h deleted file mode 100644 index d651ef4..0000000 --- a/src/plugins/bearer/networkmanager/qnmwifiengine.h +++ /dev/null @@ -1,165 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QNMWIFIENGINE_P_H -#define QNMWIFIENGINE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -//#include - -#include -#include -#include - -#include "qnetworkmanagerservice.h" - -#include -#include -#include -#include - - - -QT_BEGIN_NAMESPACE - -class QNetworkConfigurationPrivate; - -class QNmWifiEngine : public QNetworkSessionEngine -{ - Q_OBJECT - -public: - QNmWifiEngine(QObject *parent = 0); - ~QNmWifiEngine(); - - QList getConfigurations(bool *ok = 0); - QString getInterfaceFromId(const QString &id); - bool hasIdentifier(const QString &id); - - QString bearerName(const QString &id); - - void connectToId(const QString &id); - void disconnectFromId(const QString &id); - - void requestUpdate(); - - static QNmWifiEngine *instance(); - - QStringList knownSsids; - //inline void emitConfigurationsChanged() { emit configurationsChanged(); } - QNetworkConfigurationPrivate * addAccessPoint(const QString &, QDBusObjectPath ); - - QStringList getConnectionPathForId(const QString &uuid); - //QString getConnectionPathForId(const QString &name = QString()); - quint64 sentDataForId(const QString &id) const; - quint64 receivedDataForId(const QString &id) const; - -private: - bool updated; - QString activatingConnectionPath; - QStringList activeConnectionPaths; - - - QMap availableAccessPoints; - void scanForAccessPoints(); - - QStringList devicePaths; - - void getActiveConnectionsPaths(); - void getKnownSsids(); - void accessPointConnections(); - void knownConnections(); - void findConnections(); - QString deviceConnectionPath(const QString &mac); - - QList foundConfigurations; - // QHash > allConfigurations; - - QNetworkManagerInterface *iface; - - QNetworkConfiguration::StateFlags getAPState(qint32 vState, bool isKnown); - QNetworkConfiguration::StateFlags getStateFlag(quint32 nmstate); - - QString getActiveConnectionPath(const QString &identifier); - QString getNameForConfiguration(QNetworkManagerInterfaceDevice *devIface); - - QNetworkConfiguration::StateFlags getStateForId(const QString &id); - - QNetworkInterface getBestInterface(quint32 type, const QString &conPath); - - QMap configurationInterface; - - bool isAddressOfConnection(const QString &conPath, quint32 ipaddress); - -private slots: - void updateDeviceInterfaceState(const QString &, quint32); - void addDevice(QDBusObjectPath path); - void removeDevice(QDBusObjectPath path); - -Q_SIGNALS: - void configurationChanged(const QNetworkConfiguration& config); - void updateAccessPointState(const QString &, quint32); -// void slotActivationFinished(QDBusPendingCallWatcher*); - -private slots: - void accessPointAdded( const QString &aPath, QDBusObjectPath oPath); - void accessPointRemoved( const QString &aPath, QDBusObjectPath oPath); - void cmpPropertiesChanged(const QString &, QMap map); - void newConnection(QDBusObjectPath); - void settingsConnectionRemoved(const QString &); - void slotActivationFinished(QDBusPendingCallWatcher*); -}; - -QT_END_NAMESPACE - -#endif - - -- cgit v0.12 From b22d0a9c4d6e3309287aefdc1a300e2fc566c2c7 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 10 Dec 2009 16:57:42 +1000 Subject: Remove unused global statics. --- src/plugins/bearer/corewlan/qcorewlanengine.h | 1 - src/plugins/bearer/corewlan/qcorewlanengine.mm | 7 ------- src/plugins/bearer/generic/qgenericengine.cpp | 7 ------- src/plugins/bearer/generic/qgenericengine.h | 2 -- src/plugins/bearer/nativewifi/qnativewifiengine.cpp | 4 ---- src/plugins/bearer/nla/qnlaengine.cpp | 9 --------- src/plugins/bearer/nla/qnlaengine.h | 2 -- 7 files changed, 32 deletions(-) diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.h b/src/plugins/bearer/corewlan/qcorewlanengine.h index 7ccfeea..2be81d1 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.h +++ b/src/plugins/bearer/corewlan/qcorewlanengine.h @@ -70,7 +70,6 @@ public: void requestUpdate(); - static QCoreWlanEngine *instance(); static bool getAllScInterfaces(); private: diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm index 9dea217..c6ea56a 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.mm +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -66,8 +66,6 @@ QMap networkInterfaces; QT_BEGIN_NAMESPACE -Q_GLOBAL_STATIC(QCoreWlanEngine, coreWlanEngine) - inline QString cfstringRefToQstring(CFStringRef cfStringRef) { // return QString([cfStringRef UTF8String]); QString retVal; @@ -310,11 +308,6 @@ void QCoreWlanEngine::requestUpdate() emit configurationsChanged(); } -QCoreWlanEngine *QCoreWlanEngine::instance() -{ - return coreWlanEngine(); -} - QList QCoreWlanEngine::scanForSsids(const QString &interfaceName) { QList foundConfigs; diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index 339ef9c..0d9a958 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -56,8 +56,6 @@ QT_BEGIN_NAMESPACE -Q_GLOBAL_STATIC(QGenericEngine, genericEngine) - static QString qGetInterfaceType(const QString &interface) { #ifdef Q_OS_WIN32 @@ -170,11 +168,6 @@ void QGenericEngine::requestUpdate() QTimer::singleShot(0, this, SLOT(doRequestUpdate())); } -QGenericEngine *QGenericEngine::instance() -{ - return genericEngine(); -} - void QGenericEngine::doRequestUpdate() { // Immediately after connecting with a wireless access point diff --git a/src/plugins/bearer/generic/qgenericengine.h b/src/plugins/bearer/generic/qgenericengine.h index 9359d7f..a671ceb 100644 --- a/src/plugins/bearer/generic/qgenericengine.h +++ b/src/plugins/bearer/generic/qgenericengine.h @@ -71,8 +71,6 @@ public: QNetworkSession::State sessionStateForId(const QString &id); - static QGenericEngine *instance(); - private Q_SLOTS: void doRequestUpdate(); diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp index 5ca49a9..93fc9ca 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp @@ -50,8 +50,6 @@ QT_BEGIN_NAMESPACE -Q_GLOBAL_STATIC(QNativeWifiEngine, nativeWifiEngine) - WlanOpenHandleProto local_WlanOpenHandle = 0; WlanRegisterNotificationProto local_WlanRegisterNotification = 0; WlanEnumInterfacesProto local_WlanEnumInterfaces = 0; @@ -63,8 +61,6 @@ WlanScanProto local_WlanScan = 0; WlanFreeMemoryProto local_WlanFreeMemory = 0; WlanCloseHandleProto local_WlanCloseHandle = 0; - - void qNotificationCallback(WLAN_NOTIFICATION_DATA *data, QNativeWifiEngine *d) { Q_UNUSED(d); diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp index 2ad9cac..47bd8d5 100644 --- a/src/plugins/bearer/nla/qnlaengine.cpp +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -53,8 +53,6 @@ QT_BEGIN_NAMESPACE -Q_GLOBAL_STATIC(QNlaEngine, nlaEngine) - QWindowsSockInit2::QWindowsSockInit2() : version(0) { @@ -579,13 +577,6 @@ void QNlaEngine::requestUpdate() nlaThread->forceUpdate(); } -QNlaEngine *QNlaEngine::instance() -{ - return nlaEngine(); -} - #include "qnlaengine.moc" QT_END_NAMESPACE - - diff --git a/src/plugins/bearer/nla/qnlaengine.h b/src/plugins/bearer/nla/qnlaengine.h index 1e66c83..464275d 100644 --- a/src/plugins/bearer/nla/qnlaengine.h +++ b/src/plugins/bearer/nla/qnlaengine.h @@ -92,8 +92,6 @@ public: void requestUpdate(); - static QNlaEngine *instance(); - private: QWindowsSockInit2 winSock; QNlaThread *nlaThread; -- cgit v0.12 From 6f0a0af87c2063cd1dac75134f5cd05291a9196d Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Thu, 10 Dec 2009 17:10:53 +1000 Subject: Convert NLA plugin to be incremental. --- src/network/bearer/qnetworkconfigmanager_p.cpp | 12 ++- src/plugins/bearer/nla/qnlaengine.cpp | 101 ++++++++++++++++++++----- src/plugins/bearer/nla/qnlaengine.h | 6 +- 3 files changed, 95 insertions(+), 24 deletions(-) diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 6f833f3..495be4a 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -198,7 +198,7 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() if (nmWifi) { sessionEngines.append(nmWifi); connect(nmWifi, SIGNAL(updateCompleted()), - this, SIGNAL(configurationUpdateComplete())); + this, SLOT(updateConfigurations())); connect(nmWifi, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); connect(nmWifi, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), @@ -217,7 +217,7 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() if (generic) { sessionEngines.append(generic); connect(generic, SIGNAL(updateCompleted()), - this, SIGNAL(configurationUpdateComplete())); + this, SLOT(updateConfigurations())); connect(generic, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); connect(generic, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), @@ -235,6 +235,14 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() QNetworkSessionEngine *nla = nlaPlugin->create(QLatin1String("nla")); if (nla) { sessionEngines.append(nla); + connect(nla, SIGNAL(updateCompleted()), + this, SLOT(updateConfigurations())); + connect(nla, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); + connect(nla, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationRemoved(QNetworkConfigurationPrivatePointer))); + connect(nla, SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer))); } } } diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp index 47bd8d5..a9fc2ee 100644 --- a/src/plugins/bearer/nla/qnlaengine.cpp +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -238,21 +238,8 @@ QList QNlaThread::getConfigurations() { QMutexLocker locker(&mutex); - QList foundConfigurations; - - for (int i = 0; i < fetchedConfigurations.count(); ++i) { - QNetworkConfigurationPrivate *config = new QNetworkConfigurationPrivate; - config->name = fetchedConfigurations.at(i)->name; - config->isValid = fetchedConfigurations.at(i)->isValid; - config->id = fetchedConfigurations.at(i)->id; - config->state = fetchedConfigurations.at(i)->state; - config->type = fetchedConfigurations.at(i)->type; - config->roamingSupported = fetchedConfigurations.at(i)->roamingSupported; - config->purpose = fetchedConfigurations.at(i)->purpose; - config->internet = fetchedConfigurations.at(i)->internet; - - foundConfigurations.append(config); - } + QList foundConfigurations = fetchedConfigurations; + fetchedConfigurations.clear(); return foundConfigurations; } @@ -324,7 +311,10 @@ void QNlaThread::run() #ifndef Q_OS_WINCE // Not interested in unrelated IO completion events // although we also don't want to block them - while (WaitForSingleObjectEx(changeEvent, WSA_INFINITE, true) != WAIT_IO_COMPLETION) {} + while (WaitForSingleObjectEx(changeEvent, WSA_INFINITE, true) != WAIT_IO_COMPLETION && + handle) + { + } #else WaitForSingleObject(changeEvent, WSA_INFINITE); #endif @@ -515,7 +505,7 @@ QNlaEngine::QNlaEngine(QObject *parent) { nlaThread = new QNlaThread(this); connect(nlaThread, SIGNAL(networksChanged()), - this, SIGNAL(configurationsChanged())); + this, SLOT(networksChanged())); nlaThread->start(); qApp->processEvents(QEventLoop::ExcludeUserInputEvents); @@ -526,12 +516,57 @@ QNlaEngine::~QNlaEngine() delete nlaThread; } -QList QNlaEngine::getConfigurations(bool *ok) +void QNlaEngine::networksChanged() { - if (ok) - *ok = true; + QStringList previous = accessPointConfigurations.keys(); + + QList foundConfigurations = nlaThread->getConfigurations(); + while (!foundConfigurations.isEmpty()) { + QNetworkConfigurationPrivate *cpPriv = foundConfigurations.takeFirst(); + + previous.removeAll(cpPriv->id); + + if (accessPointConfigurations.contains(cpPriv->id)) { + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(cpPriv->id); + + bool changed = false; + + if (ptr->isValid != cpPriv->isValid) { + ptr->isValid = cpPriv->isValid; + changed = true; + } + + if (ptr->name != cpPriv->name) { + ptr->name = cpPriv->name; + changed = true; + } + + if (ptr->state != cpPriv->state) { + ptr->state = cpPriv->state; + changed = true; + } - return nlaThread->getConfigurations(); + if (changed) + emit configurationChanged(ptr); + + delete cpPriv; + } else { + QNetworkConfigurationPrivatePointer ptr(cpPriv); + + accessPointConfigurations.insert(ptr->id, ptr); + + emit configurationAdded(ptr); + } + } + + while (!previous.isEmpty()) { + QNetworkConfigurationPrivatePointer ptr = + accessPointConfigurations.take(previous.takeFirst()); + + emit configurationRemoved(ptr); + } + + emit updateCompleted(); } QString QNlaEngine::getInterfaceFromId(const QString &id) @@ -577,6 +612,30 @@ void QNlaEngine::requestUpdate() nlaThread->forceUpdate(); } +QNetworkSession::State QNlaEngine::sessionStateForId(const QString &id) +{ + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + if (!ptr) + return QNetworkSession::Invalid; + + if (!ptr->isValid) { + return QNetworkSession::Invalid; + } else if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + return QNetworkSession::Connected; + } else if ((ptr->state & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + return QNetworkSession::Disconnected; + } else if ((ptr->state & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) { + return QNetworkSession::NotAvailable; + } else if ((ptr->state & QNetworkConfiguration::Undefined) == + QNetworkConfiguration::Undefined) { + return QNetworkSession::NotAvailable; + } + + return QNetworkSession::Invalid; +} + #include "qnlaengine.moc" QT_END_NAMESPACE diff --git a/src/plugins/bearer/nla/qnlaengine.h b/src/plugins/bearer/nla/qnlaengine.h index 464275d..dd038d1 100644 --- a/src/plugins/bearer/nla/qnlaengine.h +++ b/src/plugins/bearer/nla/qnlaengine.h @@ -81,7 +81,6 @@ public: QNlaEngine(QObject *parent = 0); ~QNlaEngine(); - QList getConfigurations(bool *ok = 0); QString getInterfaceFromId(const QString &id); bool hasIdentifier(const QString &id); @@ -92,6 +91,11 @@ public: void requestUpdate(); + QNetworkSession::State sessionStateForId(const QString &id); + +private Q_SLOTS: + void networksChanged(); + private: QWindowsSockInit2 winSock; QNlaThread *nlaThread; -- cgit v0.12 From a60b9d95fddb75a53cde258dbf4b9063a58a88b8 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Fri, 11 Dec 2009 11:27:14 +1000 Subject: Convert Native Wifi plugin to be incremental. --- src/network/bearer/qnetworkconfigmanager_p.cpp | 14 ++- .../bearer/nativewifi/qnativewifiengine.cpp | 115 ++++++++++++++++----- src/plugins/bearer/nativewifi/qnativewifiengine.h | 7 +- 3 files changed, 106 insertions(+), 30 deletions(-) diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 495be4a..c9b10dd 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -251,9 +251,21 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() QBearerEnginePlugin *nativeWifiPlugin = qobject_cast(l->instance(QLatin1String("nativewifi"))); if (nativeWifiPlugin) { - QNetworkSessionEngine *nativeWifi = nativeWifiPlugin->create(QLatin1String("nativewifi")); + QNetworkSessionEngine *nativeWifi = + nativeWifiPlugin->create(QLatin1String("nativewifi")); if (nativeWifi) { sessionEngines.append(nativeWifi); + connect(nativeWifi, SIGNAL(updateCompleted()), + this, SLOT(updateConfigurations())); + connect(nativeWifi, + SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); + connect(nativeWifi, + SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationRemoved(QNetworkConfigurationPrivatePointer))); + connect(nativeWifi, + SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer))); capFlags |= QNetworkConfigurationManager::CanStartAndStopInterfaces; } diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp index 93fc9ca..e65eeea 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp @@ -68,7 +68,7 @@ void qNotificationCallback(WLAN_NOTIFICATION_DATA *data, QNativeWifiEngine *d) switch (data->NotificationCode) { case wlan_notification_acm_connection_complete: case wlan_notification_acm_disconnected: - d->emitConfigurationsChanged(); + QMetaObject::invokeMethod(d, "scanComplete", Qt::QueuedConnection); break; default: qDebug() << "wlan unknown notification"; @@ -96,8 +96,9 @@ QNativeWifiEngine::QNativeWifiEngine(QObject *parent) // On Windows XP SP2 and SP3 only connection and disconnection notifications are available. // We need to poll for changes in available wireless networks. - connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); + connect(&pollTimer, SIGNAL(timeout()), this, SLOT(scanComplete())); pollTimer.setInterval(10000); + scanComplete(); } QNativeWifiEngine::~QNativeWifiEngine() @@ -105,19 +106,16 @@ QNativeWifiEngine::~QNativeWifiEngine() local_WlanCloseHandle(handle, 0); } -QList QNativeWifiEngine::getConfigurations(bool *ok) +void QNativeWifiEngine::scanComplete() { - if (ok) - *ok = false; - - QList foundConfigurations; + QStringList previous = accessPointConfigurations.keys(); // enumerate interfaces WLAN_INTERFACE_INFO_LIST *interfaceList; DWORD result = local_WlanEnumInterfaces(handle, 0, &interfaceList); if (result != ERROR_SUCCESS) { qWarning("%s: WlanEnumInterfaces failed with error %ld\n", __FUNCTION__, result); - return foundConfigurations; + return; } for (unsigned int i = 0; i < interfaceList->dwNumberOfItems; ++i) { @@ -146,36 +144,66 @@ QList QNativeWifiEngine::getConfigurations(bool network.dot11Ssid.uSSIDLength); } - // don't add duplicate networks - if (seenNetworks.contains(networkName)) - continue; - else - seenNetworks.append(networkName); - - QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; + const QString id = QString::number(qHash(QLatin1String("WLAN:") + networkName)); - cpPriv->isValid = true; + previous.removeAll(id); - cpPriv->name = networkName; - cpPriv->id = QString::number(qHash(QLatin1String("WLAN:") + cpPriv->name)); + QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; if (!(network.dwFlags & WLAN_AVAILABLE_NETWORK_HAS_PROFILE)) - cpPriv->state = QNetworkConfiguration::Undefined; + state = QNetworkConfiguration::Undefined; if (network.strProfileName[0] != 0) { if (network.bNetworkConnectable) { if (network.dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED) - cpPriv->state = QNetworkConfiguration::Active; + state = QNetworkConfiguration::Active; else - cpPriv->state = QNetworkConfiguration::Discovered; + state = QNetworkConfiguration::Discovered; } else { - cpPriv->state = QNetworkConfiguration::Defined; + state = QNetworkConfiguration::Defined; } } - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; + if (seenNetworks.contains(networkName)) + continue; + else + seenNetworks.append(networkName); + + if (accessPointConfigurations.contains(id)) { + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); - foundConfigurations.append(cpPriv); + bool changed = false; + + if (!ptr->isValid) { + ptr->isValid = true; + changed = true; + } + + if (ptr->name != networkName) { + ptr->name = networkName; + changed = true; + } + + if (ptr->state != state) { + ptr->state = state; + changed = true; + } + + if (changed) + emit configurationChanged(ptr); + } else { + QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); + + ptr->name = networkName; + ptr->isValid = true; + ptr->id = id; + ptr->state = state; + ptr->type = QNetworkConfiguration::InternetAccessPoint; + + accessPointConfigurations.insert(id, ptr); + + emit configurationAdded(ptr); + } } local_WlanFreeMemory(networkList); @@ -183,12 +211,16 @@ QList QNativeWifiEngine::getConfigurations(bool local_WlanFreeMemory(interfaceList); - if (ok) - *ok = true; + while (!previous.isEmpty()) { + QNetworkConfigurationPrivatePointer ptr = + accessPointConfigurations.take(previous.takeFirst()); + + emit configurationRemoved(ptr); + } pollTimer.start(); - return foundConfigurations; + emit updateCompleted(); } QString QNativeWifiEngine::getInterfaceFromId(const QString &id) @@ -227,6 +259,7 @@ QString QNativeWifiEngine::getInterfaceFromId(const QString &id) guid = guid.arg(interface.InterfaceGuid.Data4[i], 2, 16, QChar('0')); local_WlanFreeMemory(connectionAttributes); + local_WlanFreeMemory(interfaceList); return guid.toUpper(); } @@ -234,6 +267,8 @@ QString QNativeWifiEngine::getInterfaceFromId(const QString &id) local_WlanFreeMemory(connectionAttributes); } + local_WlanFreeMemory(interfaceList); + return QString(); } @@ -397,6 +432,32 @@ void QNativeWifiEngine::requestUpdate() if (result != ERROR_SUCCESS) qWarning("%s: WlanScan failed with error %ld\n", __FUNCTION__, result); } + + local_WlanFreeMemory(interfaceList); +} + +QNetworkSession::State QNativeWifiEngine::sessionStateForId(const QString &id) +{ + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + if (!ptr) + return QNetworkSession::Invalid; + + if (!ptr->isValid) { + return QNetworkSession::Invalid; + } else if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + return QNetworkSession::Connected; + } else if ((ptr->state & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + return QNetworkSession::Disconnected; + } else if ((ptr->state & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) { + return QNetworkSession::NotAvailable; + } else if ((ptr->state & QNetworkConfiguration::Undefined) == + QNetworkConfiguration::Undefined) { + return QNetworkSession::NotAvailable; + } + + return QNetworkSession::Invalid; } QT_END_NAMESPACE diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.h b/src/plugins/bearer/nativewifi/qnativewifiengine.h index 6686ea8..5d6af40 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.h +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.h @@ -60,6 +60,7 @@ QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; +struct WLAN_NOTIFICATION_DATA; class QNativeWifiEngine : public QNetworkSessionEngine { @@ -69,7 +70,6 @@ public: QNativeWifiEngine(QObject *parent = 0); ~QNativeWifiEngine(); - QList getConfigurations(bool *ok = 0); QString getInterfaceFromId(const QString &id); bool hasIdentifier(const QString &id); @@ -80,10 +80,13 @@ public: void requestUpdate(); - inline void emitConfigurationsChanged() { emit configurationsChanged(); } + QNetworkSession::State sessionStateForId(const QString &id); inline bool available() const { return handle != 0; } +public Q_SLOTS: + void scanComplete(); + private: QTimer pollTimer; -- cgit v0.12 From 33ff53925ba6d62ecc868920c6bc914824feec54 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Fri, 11 Dec 2009 12:45:40 +1000 Subject: Remove unused BEARER_ENGINE preprocessor define. --- src/network/bearer/bearer.pri | 2 -- src/network/bearer/qnetworkconfigmanager_p.h | 6 ------ src/network/bearer/qnetworkconfiguration_p.h | 9 ++------- src/network/bearer/qnetworksession_p.h | 11 ++--------- src/plugins/bearer/corewlan/corewlan.pro | 2 -- src/plugins/bearer/generic/generic.pro | 2 -- src/plugins/bearer/nativewifi/nativewifi.pro | 2 -- src/plugins/bearer/networkmanager/networkmanager.pro | 2 +- src/plugins/bearer/nla/nla.pro | 2 -- 9 files changed, 5 insertions(+), 33 deletions(-) diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index 5bae333..4f6c549 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -69,8 +69,6 @@ symbian { INSTALLS += pkgconfig documentation } else { - DEFINES += BEARER_ENGINE - HEADERS += bearer/qnetworkconfigmanager_p.h \ bearer/qnetworkconfiguration_p.h \ bearer/qnetworksession_p.h \ diff --git a/src/network/bearer/qnetworkconfigmanager_p.h b/src/network/bearer/qnetworkconfigmanager_p.h index 37e88d3..a45d534 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.h +++ b/src/network/bearer/qnetworkconfigmanager_p.h @@ -93,13 +93,10 @@ Q_SIGNALS: void onlineStateChanged(bool isOnline); private: -#ifdef BEARER_ENGINE void updateInternetServiceConfiguration(); void abort(); -#endif -#ifdef BEARER_ENGINE public: QList sessionEngines; @@ -108,14 +105,11 @@ private: bool updating; QSet updatingEngines; -#endif private Q_SLOTS: -#ifdef BEARER_ENGINE void configurationAdded(QNetworkConfigurationPrivatePointer ptr); void configurationRemoved(QNetworkConfigurationPrivatePointer ptr); void configurationChanged(QNetworkConfigurationPrivatePointer ptr); -#endif }; QNetworkConfigurationManagerPrivate *qNetworkConfigurationManagerPrivate(); diff --git a/src/network/bearer/qnetworkconfiguration_p.h b/src/network/bearer/qnetworkconfiguration_p.h index 8e69248..365ec95 100644 --- a/src/network/bearer/qnetworkconfiguration_p.h +++ b/src/network/bearer/qnetworkconfiguration_p.h @@ -64,12 +64,9 @@ class QNetworkConfigurationPrivate : public QSharedData { public: QNetworkConfigurationPrivate () - : isValid(false), type(QNetworkConfiguration::Invalid), - roamingSupported(false), purpose(QNetworkConfiguration::UnknownPurpose) + : isValid(false), type(QNetworkConfiguration::Invalid), + roamingSupported(false), purpose(QNetworkConfiguration::UnknownPurpose), internet(false) { -#ifdef BEARER_ENGINE - internet = false; -#endif } ~QNetworkConfigurationPrivate() @@ -86,9 +83,7 @@ public: bool roamingSupported; QNetworkConfiguration::Purpose purpose; -#ifdef BEARER_ENGINE bool internet; -#endif QList serviceNetworkMembers; QNetworkInterface serviceInterface; diff --git a/src/network/bearer/qnetworksession_p.h b/src/network/bearer/qnetworksession_p.h index 0e11b3d..0a45c92 100644 --- a/src/network/bearer/qnetworksession_p.h +++ b/src/network/bearer/qnetworksession_p.h @@ -55,9 +55,7 @@ #include "qnetworkconfigmanager_p.h" #include "qnetworksession.h" -#ifdef BEARER_ENGINE #include "qnetworksessionengine_p.h" -#endif #include "qnetworksession.h" #include @@ -65,9 +63,7 @@ QT_BEGIN_NAMESPACE -#ifdef BEARER_ENGINE class QNetworkSessionEngine; -#endif class QNetworkSessionPrivate : public QObject { @@ -117,12 +113,10 @@ Q_SIGNALS: void quitPendingWaitsForOpened(); private Q_SLOTS: -#ifdef BEARER_ENGINE void networkConfigurationsChanged(); void configurationChanged(const QNetworkConfiguration &config); void forcedSessionClose(const QNetworkConfiguration &config); void connectionError(const QString &id, QNetworkSessionEngine::ConnectionError error); -#endif private: QNetworkConfigurationManager manager; @@ -146,17 +140,16 @@ private: QNetworkSession::State state; bool isActive; -#ifdef BEARER_ENGINE bool opened; QNetworkSessionEngine *engine; -#endif + QNetworkSession::SessionError lastError; QNetworkSession* q; friend class QNetworkSession; -#if defined(BEARER_ENGINE) && defined(BACKEND_NM) +#if defined(BACKEND_NM) QDateTime startTime; void setActiveTimeStamp(); #endif diff --git a/src/plugins/bearer/corewlan/corewlan.pro b/src/plugins/bearer/corewlan/corewlan.pro index ffac6df..ac04e95 100644 --- a/src/plugins/bearer/corewlan/corewlan.pro +++ b/src/plugins/bearer/corewlan/corewlan.pro @@ -11,8 +11,6 @@ contains(QT_CONFIG, corewlan) { } } -DEFINES += BEARER_ENGINE - HEADERS += qcorewlanengine.h SOURCES += qcorewlanengine.mm main.cpp diff --git a/src/plugins/bearer/generic/generic.pro b/src/plugins/bearer/generic/generic.pro index 506417c..0015041 100644 --- a/src/plugins/bearer/generic/generic.pro +++ b/src/plugins/bearer/generic/generic.pro @@ -3,8 +3,6 @@ include(../../qpluginbase.pri) QT += network -DEFINES += BEARER_ENGINE - HEADERS += qgenericengine.h \ ../platformdefs_win.h SOURCES += qgenericengine.cpp main.cpp diff --git a/src/plugins/bearer/nativewifi/nativewifi.pro b/src/plugins/bearer/nativewifi/nativewifi.pro index 3aab552..583edd4 100644 --- a/src/plugins/bearer/nativewifi/nativewifi.pro +++ b/src/plugins/bearer/nativewifi/nativewifi.pro @@ -3,8 +3,6 @@ include(../../qpluginbase.pri) QT += network -DEFINES += BEARER_ENGINE - HEADERS += qnativewifiengine.h platformdefs.h SOURCES += qnativewifiengine.cpp main.cpp diff --git a/src/plugins/bearer/networkmanager/networkmanager.pro b/src/plugins/bearer/networkmanager/networkmanager.pro index 79c68ea..57f7ca7 100644 --- a/src/plugins/bearer/networkmanager/networkmanager.pro +++ b/src/plugins/bearer/networkmanager/networkmanager.pro @@ -3,7 +3,7 @@ include(../../qpluginbase.pri) QT += network dbus -DEFINES += BEARER_ENGINE BACKEND_NM +DEFINES += BACKEND_NM HEADERS += qnmdbushelper.h \ qnetworkmanagerservice.h \ diff --git a/src/plugins/bearer/nla/nla.pro b/src/plugins/bearer/nla/nla.pro index 78f3271..62a920a 100644 --- a/src/plugins/bearer/nla/nla.pro +++ b/src/plugins/bearer/nla/nla.pro @@ -9,8 +9,6 @@ QT += network LIBS += -lWs2 } -DEFINES += BEARER_ENGINE - HEADERS += qnlaengine.h \ ../platformdefs_win.h SOURCES += qnlaengine.cpp main.cpp -- cgit v0.12 From 56c7d0baf1b7611f17938cf0eb920ccdae53e7ed Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 4 Jan 2010 11:19:18 +1000 Subject: Remove bearer.pro. --- src/network/bearer/bearer.pro | 163 ------------------------------------------ 1 file changed, 163 deletions(-) delete mode 100644 src/network/bearer/bearer.pro diff --git a/src/network/bearer/bearer.pro b/src/network/bearer/bearer.pro deleted file mode 100644 index 2255b7c..0000000 --- a/src/network/bearer/bearer.pro +++ /dev/null @@ -1,163 +0,0 @@ -# Qt bearer management library -TEMPLATE = lib -TARGET = QtBearer - -QT += network -include (../../common.pri) - -DEFINES += QT_BUILD_BEARER_LIB QT_MAKEDLL - -#DEFINES += BEARER_MANAGEMENT_DEBUG - -PUBLIC_HEADERS += qnetworkconfiguration.h \ - qnetworksession.h \ - qnetworkconfigmanager.h - -HEADERS += $$PUBLIC_HEADERS -SOURCES += qnetworksession.cpp \ - qnetworkconfigmanager.cpp \ - qnetworkconfiguration.cpp - -symbian: { - exists($${EPOCROOT}epoc32/release/winscw/udeb/cmmanager.lib)| \ - exists($${EPOCROOT}epoc32/release/armv5/lib/cmmanager.lib) { - message("Building with SNAP support") - DEFINES += SNAP_FUNCTIONALITY_AVAILABLE=1 - LIBS += -lcmmanager - } else { - message("Building without SNAP support") - LIBS += -lapengine - } - - INCLUDEPATH += $$APP_LAYER_SYSTEMINCLUDE - - HEADERS += qnetworkconfigmanager_s60_p.h \ - qnetworkconfiguration_s60_p.h \ - qnetworksession_s60_p.h - SOURCES += qnetworkconfigmanager_s60_p.cpp \ - qnetworkconfiguration_s60_p.cpp \ - qnetworksession_s60_p.cpp - - LIBS += -lcommdb \ - -lapsettingshandlerui \ - -lconnmon \ - -lcentralrepository \ - -lesock \ - -linsock \ - -lecom \ - -lefsrv \ - -lnetmeta - - deploy.path = $${EPOCROOT} - exportheaders.sources = $$PUBLIC_HEADERS - exportheaders.path = epoc32/include - - for(header, exportheaders.sources) { - BLD_INF_RULES.prj_exports += "$$header $$deploy.path$$exportheaders.path/$$basename(header)" - } - - bearer_deployment.sources = QtBearer.dll - bearer_deployment.path = /sys/bin - DEPLOYMENT += bearer_deployment - - TARGET.CAPABILITY = All -TCB -} else { - maemo { - QT += dbus - CONFIG += link_pkgconfig - - exists(../debug) { - message("Enabling debug messages.") - DEFINES += BEARER_MANAGEMENT_DEBUG - } - - HEADERS += qnetworksession_maemo_p.h \ - qnetworkconfigmanager_maemo_p.h \ - qnetworkconfiguration_maemo_p.h - - SOURCES += qnetworkconfigmanager_maemo.cpp \ - qnetworksession_maemo.cpp - - documentation.path = $$QT_MOBILITY_PREFIX/doc - documentation.files = doc/html - - PKGCONFIG += glib-2.0 dbus-glib-1 gconf-2.0 osso-ic conninet - - CONFIG += create_pc create_prl - QMAKE_PKGCONFIG_REQUIRES = glib-2.0 dbus-glib-1 gconf-2.0 osso-ic conninet - pkgconfig.path = $$QT_MOBILITY_LIB/pkgconfig - pkgconfig.files = QtBearer.pc - - INSTALLS += pkgconfig documentation - - } else { - - DEFINES += BEARER_ENGINE - - HEADERS += qnetworkconfigmanager_p.h \ - qnetworkconfiguration_p.h \ - qnetworksession_p.h \ - qnetworksessionengine_p.h \ - qgenericengine_p.h - - SOURCES += qnetworkconfigmanager_p.cpp \ - qnetworksession_p.cpp \ - qnetworksessionengine.cpp \ - qgenericengine.cpp - - unix:!mac:contains(networkmanager_enabled, yes) { - contains(QT_CONFIG,dbus) { - DEFINES += BACKEND_NM - QT += dbus - - HEADERS += qnmdbushelper_p.h \ - qnetworkmanagerservice_p.h \ - qnmwifiengine_unix_p.h - - SOURCES += qnmdbushelper.cpp \ - qnetworkmanagerservice_p.cpp \ - qnmwifiengine_unix.cpp - } else { - message("NetworkManager backend requires Qt DBus support") - } - } - - win32: { - HEADERS += qnlaengine_win_p.h \ - qnetworksessionengine_win_p.h - - !wince*:HEADERS += qnativewifiengine_win_p.h - - SOURCES += qnlaengine_win.cpp - - !wince*:SOURCES += qnativewifiengine_win.cpp - - !wince*:LIBS += -lWs2_32 - wince*:LIBS += -lWs2 - } - } - macx: { - HEADERS += qcorewlanengine_mac_p.h - SOURCES+= qcorewlanengine_mac.mm - LIBS += -framework Foundation -framework SystemConfiguration - - contains(corewlan_enabled, yes) { - isEmpty(QMAKE_MAC_SDK) { - SDK6="yes" - } else { - contains(QMAKE_MAC_SDK, "/Developer/SDKs/MacOSX10.6.sdk") { - SDK6="yes" - } - } - - !isEmpty(SDK6) { - LIBS += -framework CoreWLAN - DEFINES += MAC_SDK_10_6 - } - } - - - } -} - -include(../../features/deploy.pri) -- cgit v0.12 From 2fa4daa2acd0af503f5802eff773f1fa2117a788 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Tue, 22 Dec 2009 09:20:17 +1000 Subject: Fix memory leak in NLA engine. --- src/plugins/bearer/nla/qnlaengine.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp index a9fc2ee..bf0d74f 100644 --- a/src/plugins/bearer/nla/qnlaengine.cpp +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -576,15 +576,7 @@ QString QNlaEngine::getInterfaceFromId(const QString &id) bool QNlaEngine::hasIdentifier(const QString &id) { - if (configurationInterface.contains(id.toUInt())) - return true; - - foreach (QNetworkConfigurationPrivate *cpPriv, nlaThread->getConfigurations()) { - if (cpPriv->id == id) - return true; - } - - return false; + return configurationInterface.contains(id.toUInt()); } QString QNlaEngine::bearerName(const QString &id) -- cgit v0.12 From c68598b2bd82abee5da2596949e1e95c9a59e584 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 4 Jan 2010 12:13:14 +1000 Subject: Emit updateCompleted() when requestUpdate() is called. --- src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp | 8 ++++++++ src/plugins/bearer/networkmanager/qnetworkmanagerengine.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp index 3de20a3..0af3675 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -116,6 +116,7 @@ QNetworkManagerEngine::~QNetworkManagerEngine() void QNetworkManagerEngine::doRequestUpdate() { + emit updateCompleted(); } QString QNetworkManagerEngine::getInterfaceFromId(const QString &id) @@ -319,6 +320,13 @@ void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QString &pat } } +void QNetworkManagerEngine::devicePropertiesChanged(const QString &path, + const QMap &properties) +{ + qDebug() << Q_FUNC_INFO << path; + qDebug() << properties; +} + void QNetworkManagerEngine::deviceAdded(const QDBusObjectPath &path) { QNetworkManagerInterfaceDevice device(path.path()); diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h index 9e8af3b..1636c91 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h @@ -87,6 +87,8 @@ private Q_SLOTS: const QMap &properties); void activeConnectionPropertiesChanged(const QString &path, const QMap &properties); + void devicePropertiesChanged(const QString &path, + const QMap &properties); void deviceAdded(const QDBusObjectPath &path); void deviceRemoved(const QDBusObjectPath &path); -- cgit v0.12 From c3049983cf0ac72ae4a524a0a365ea88e950bfc0 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 4 Jan 2010 17:11:20 +1000 Subject: Convert Core Wlan plugin to be incremental. --- src/network/bearer/qnetworkconfigmanager_p.cpp | 8 + src/plugins/bearer/corewlan/qcorewlanengine.h | 14 +- src/plugins/bearer/corewlan/qcorewlanengine.mm | 239 +++++++++++++++++++++---- 3 files changed, 220 insertions(+), 41 deletions(-) diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index c9b10dd..cb83789 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -186,6 +186,14 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() QNetworkSessionEngine *coreWifi = coreWlanPlugin->create(QLatin1String("corewlan")); if (coreWifi) { sessionEngines.append(coreWifi); + connect(coreWifi, SIGNAL(updateCompleted()), + this, SLOT(updateConfigurations())); + connect(coreWifi, SIGNAL(configurationAdded(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationAdded(QNetworkConfigurationPrivatePointer))); + connect(coreWifi, SIGNAL(configurationRemoved(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationRemoved(QNetworkConfigurationPrivatePointer))); + connect(coreWifi, SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)), + this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer))); } } } diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.h b/src/plugins/bearer/corewlan/qcorewlanengine.h index 2be81d1..ea9bcfd 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.h +++ b/src/plugins/bearer/corewlan/qcorewlanengine.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QCOREWLANENGINE_P_H -#define QCOREWLANENGINE_P_H +#ifndef QCOREWLANENGINE_H +#define QCOREWLANENGINE_H #include @@ -59,7 +59,6 @@ public: QCoreWlanEngine(QObject *parent = 0); ~QCoreWlanEngine(); - QList getConfigurations(bool *ok = 0); QString getInterfaceFromId(const QString &id); bool hasIdentifier(const QString &id); @@ -70,13 +69,18 @@ public: void requestUpdate(); + QNetworkSession::State sessionStateForId(const QString &id); + static bool getAllScInterfaces(); +private Q_SLOTS: + void doRequestUpdate(); + private: bool isWifiReady(const QString &dev); - QMap configurationInterface; + QMap configurationInterface; QTimer pollTimer; - QList scanForSsids(const QString &interfaceName); + QStringList scanForSsids(const QString &interfaceName); QList getWlanProfiles(const QString &interfaceName); diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm index c6ea56a..7e14e69 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.mm +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -107,9 +107,9 @@ static QString qGetInterfaceType(const QString &interfaceString) QCoreWlanEngine::QCoreWlanEngine(QObject *parent) : QNetworkSessionEngine(parent) { - getAllScInterfaces(); - connect(&pollTimer, SIGNAL(timeout()), this, SIGNAL(configurationsChanged())); + connect(&pollTimer, SIGNAL(timeout()), this, SLOT(doRequestUpdate())); pollTimer.setInterval(10000); + doRequestUpdate(); } QCoreWlanEngine::~QCoreWlanEngine() @@ -137,6 +137,7 @@ QList QCoreWlanEngine::getWifiConfigurations() return QList (); } +#if 0 QList QCoreWlanEngine::getConfigurations(bool *ok) { if (ok) @@ -202,15 +203,16 @@ QList QCoreWlanEngine::getConfigurations(bool *o pollTimer.start(); return foundConfigurations; } +#endif QString QCoreWlanEngine::getInterfaceFromId(const QString &id) { - return configurationInterface.value(id.toUInt()); + return configurationInterface.value(id); } bool QCoreWlanEngine::hasIdentifier(const QString &id) { - return configurationInterface.contains(id.toUInt()); + return configurationInterface.contains(id); } QString QCoreWlanEngine::bearerName(const QString &id) @@ -304,13 +306,119 @@ void QCoreWlanEngine::disconnectFromId(const QString &id) void QCoreWlanEngine::requestUpdate() { + pollTimer.stop(); + QTimer::singleShot(0, this, SLOT(doRequestUpdate())); +} + +void QCoreWlanEngine::doRequestUpdate() +{ getAllScInterfaces(); - emit configurationsChanged(); + + QStringList previous = accessPointConfigurations.keys(); + + QMapIterator i(networkInterfaces); + while (i.hasNext()) { + i.next(); + if (i.value() == QLatin1String("WLAN")) { + QStringList added = scanForSsids(i.key()); + while (!added.isEmpty()) { + previous.removeAll(added.takeFirst()); + } + } + + qDebug() << "Found configuration" << i.key(); + QNetworkInterface interface = QNetworkInterface::interfaceFromName(i.key()); + + if (!interface.isValid()) + continue; + + uint identifier; + if (interface.index()) + identifier = qHash(QLatin1String("corewlan:") + QString::number(interface.index())); + else + identifier = qHash(QLatin1String("corewlan:") + interface.hardwareAddress()); + + const QString id = QString::number(identifier); + + previous.removeAll(id); + + QString name = interface.humanReadableName(); + if (name.isEmpty()) + name = interface.name(); + + QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; + + qDebug() << "interface flags:" << interface.flags(); + + if (interface.flags() && QNetworkInterface::IsRunning) + state = QNetworkConfiguration::Defined; + + if (!interface.addressEntries().isEmpty()) + state = QNetworkConfiguration::Active; + + if (accessPointConfigurations.contains(id)) { + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + bool changed = false; + + if (!ptr->isValid) { + ptr->isValid = true; + changed = true; + } + + if (ptr->name != name) { + ptr->name = name; + changed = true; + } + + if (ptr->id != id) { + ptr->id = id; + changed = true; + } + + if (ptr->state != state) { + ptr->state = state; + changed = true; + } + + if (changed) { + qDebug() << "Configuration changed" << ptr->name << ptr->id; + emit configurationChanged(ptr); + } + } else { + QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); + + ptr->name = name; + ptr->isValid = true; + ptr->id = id; + ptr->state = state; + ptr->type = QNetworkConfiguration::InternetAccessPoint; + + accessPointConfigurations.insert(id, ptr); + configurationInterface.insert(id, interface.name()); + + qDebug() << "Configuration Added" << ptr->name << ptr->id; + emit configurationAdded(ptr); + } + } + + while (!previous.isEmpty()) { + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(previous.takeFirst()); + + qDebug() << "Configuration Removed" << ptr->name << ptr->id; + configurationInterface.remove(ptr->id); + emit configurationRemoved(ptr); + } + + pollTimer.start(); + + emit updateCompleted(); } -QList QCoreWlanEngine::scanForSsids(const QString &interfaceName) +QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) { - QList foundConfigs; + QStringList found; + #if defined(MAC_SDK_10_6) NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; @@ -319,45 +427,80 @@ QList QCoreWlanEngine::scanForSsids(const QStrin NSDictionary *parametersDict = nil; NSArray* apArray = [NSMutableArray arrayWithArray:[currentInterface scanForNetworksWithParameters:parametersDict error:&err]]; - if(!err) { + if (!err) { for(uint row=0; row < [apArray count]; row++ ) { CWNetwork *apNetwork = [apArray objectAtIndex:row]; - QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); - QString networkSsid = nsstringToQString([apNetwork ssid]); - cpPriv->name = networkSsid; - cpPriv->isValid = true; - cpPriv->id = networkSsid; - cpPriv->internet = true; - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - cpPriv->serviceInterface = QNetworkInterface::interfaceFromName(nsstringToQString([[CWInterface interface] name])); + + const QString networkSsid = nsstringToQString([apNetwork ssid]); + + const QString id = QString::number(qHash(QLatin1String("corewlan:") + networkSsid)); + found.append(id); + + QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; + + if ([currentInterface.interfaceState intValue] == kCWInterfaceStateRunning) { + QString interfaceSsidString = nsstringToQString([currentInterface ssid]); + qDebug() << "interfaceSsidString:" << interfaceSsidString; + if (networkSsid == nsstringToQString([currentInterface ssid])) + state = QNetworkConfiguration::Active; + } else { + if (isKnownSsid(interfaceName, networkSsid)) + state = QNetworkConfiguration::Discovered; + else + state = QNetworkConfiguration::Defined; + } + qDebug() << "state is:" << state; CWWirelessProfile *networkProfile = apNetwork.wirelessProfile; CW8021XProfile *userNetworkProfile = networkProfile.user8021XProfile; - if(!userNetworkProfile) { - } else { + if (userNetworkProfile) { qWarning() <<"Has profile!" ; } - if( [currentInterface.interfaceState intValue] == kCWInterfaceStateRunning) { - QString interfaceSsidString = nsstringToQString( [currentInterface ssid]); - if( cpPriv->name == interfaceSsidString) { - cpPriv->state |= QNetworkConfiguration::Active; + if (accessPointConfigurations.contains(id)) { + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + bool changed = false; + + if (!ptr->isValid) { + ptr->isValid = true; + changed = true; } - } else { - if(isKnownSsid(cpPriv->serviceInterface.name(), networkSsid)) { - cpPriv->state = QNetworkConfiguration::Discovered; - } else { - cpPriv->state = QNetworkConfiguration::Defined; + + if (ptr->name != networkSsid) { + ptr->name = networkSsid; + changed = true; } + + if (ptr->id != id) { + ptr->id = id; + changed = true; + } + + if (ptr->state != state) { + ptr->state = state; + changed = true; + } + + if (changed) { + qDebug() << "WLAN Configuration Changed" << interfaceName << ptr->name << ptr->id; + emit configurationChanged(ptr); + } + } else { + QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); + + ptr->name = networkSsid; + ptr->isValid = true; + ptr->id = id; + ptr->state = state; + ptr->type = QNetworkConfiguration::InternetAccessPoint; + + accessPointConfigurations.insert(id, ptr); + configurationInterface.insert(id, interfaceName); + + qDebug() << "WLAN Configuration Added" << interfaceName << ptr->name << ptr->id; + emit configurationAdded(ptr); } - if(!cpPriv->state) { - cpPriv->state = QNetworkConfiguration::Undefined; - } - if([[apNetwork securityMode ] intValue]== kCWSecurityModeOpen) - cpPriv->purpose = QNetworkConfiguration::PublicPurpose; - else - cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; - foundConfigs.append(cpPriv); } } else { qWarning() << "ERROR scanning for ssids" << nsstringToQString([err localizedDescription]) @@ -367,7 +510,7 @@ QList QCoreWlanEngine::scanForSsids(const QStrin #else Q_UNUSED(interfaceName); #endif - return foundConfigs; + return found; } bool QCoreWlanEngine::isWifiReady(const QString &wifiDeviceName) @@ -449,4 +592,28 @@ bool QCoreWlanEngine::getAllScInterfaces() return true; } +QNetworkSession::State QCoreWlanEngine::sessionStateForId(const QString &id) +{ + QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); + + if (!ptr) + return QNetworkSession::Invalid; + + if (!ptr->isValid) { + return QNetworkSession::Invalid; + } else if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { + return QNetworkSession::Connected; + } else if ((ptr->state & QNetworkConfiguration::Discovered) == + QNetworkConfiguration::Discovered) { + return QNetworkSession::Disconnected; + } else if ((ptr->state & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined) { + return QNetworkSession::NotAvailable; + } else if ((ptr->state & QNetworkConfiguration::Undefined) == + QNetworkConfiguration::Undefined) { + return QNetworkSession::NotAvailable; + } + + return QNetworkSession::Invalid; +} + QT_END_NAMESPACE -- cgit v0.12 From ca7fe1713ff82dcde8fb2fdfb0664b5dfa830bd7 Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 4 Jan 2010 17:26:36 +1000 Subject: Remove some unused functions and debug output. --- src/plugins/bearer/corewlan/qcorewlanengine.h | 1 - src/plugins/bearer/corewlan/qcorewlanengine.mm | 106 +------------------------ 2 files changed, 2 insertions(+), 105 deletions(-) diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.h b/src/plugins/bearer/corewlan/qcorewlanengine.h index ea9bcfd..237680a 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.h +++ b/src/plugins/bearer/corewlan/qcorewlanengine.h @@ -84,7 +84,6 @@ private: QList getWlanProfiles(const QString &interfaceName); - QList getWifiConfigurations(); bool isKnownSsid(const QString &interfaceName, const QString &ssid); }; diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm index 7e14e69..6625443 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.mm +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -116,95 +116,6 @@ QCoreWlanEngine::~QCoreWlanEngine() { } -QList QCoreWlanEngine::getWifiConfigurations() -{ - QMapIterator i(networkInterfaces); - while (i.hasNext()) { - i.next(); - QString interfaceName = i.key(); - if (i.value() == "WLAN") { - if(!isWifiReady(interfaceName)) { - qWarning() << "wifi not powered on"; - return QList(); - } else { - // QList profs = getWlanProfiles(interfaceName); - scanForSsids(interfaceName); - } - } else { - - } - } - return QList (); -} - -#if 0 -QList QCoreWlanEngine::getConfigurations(bool *ok) -{ - if (ok) - *ok = true; - NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; - - QList foundConfigurations; - QList wificonfigs = getWifiConfigurations(); - - uint identifier; - QMapIterator i(networkInterfaces); - while (i.hasNext()) { - i.next(); - if (i.value() == "WLAN") { - QList fetchedConfigurations = scanForSsids(i.key()); - for (int i = 0; i < fetchedConfigurations.count(); ++i) { - - QNetworkConfigurationPrivate *config = new QNetworkConfigurationPrivate; - config->name = fetchedConfigurations.at(i)->name; - config->isValid = fetchedConfigurations.at(i)->isValid; - config->id = fetchedConfigurations.at(i)->id; - - config->state = fetchedConfigurations.at(i)->state; - config->type = fetchedConfigurations.at(i)->type; - config->roamingSupported = fetchedConfigurations.at(i)->roamingSupported; - config->purpose = fetchedConfigurations.at(i)->purpose; - config->internet = fetchedConfigurations.at(i)->internet; - config->serviceInterface = fetchedConfigurations.at(i)->serviceInterface; - - identifier = config->name.toUInt(); - configurationInterface[identifier] = config->serviceInterface.name(); - foundConfigurations.append(config); - } - } - - QNetworkInterface interface = QNetworkInterface::interfaceFromName(i.key()); - QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; - const QString humanReadableName = interface.humanReadableName(); - cpPriv->name = humanReadableName.isEmpty() ? interface.name() : humanReadableName; - cpPriv->isValid = true; - - if (interface.index()) - identifier = interface.index(); - else - identifier = qHash(interface.hardwareAddress()); - - cpPriv->id = QString::number(identifier); - cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - cpPriv->state = QNetworkConfiguration::Undefined; - - if (interface.flags() & QNetworkInterface::IsRunning) { - cpPriv->state = QNetworkConfiguration::Defined; - cpPriv->internet = true; - } - if ( !interface.addressEntries().isEmpty()) { - cpPriv->state |= QNetworkConfiguration::Active; - cpPriv->internet = true; - } - configurationInterface[identifier] = interface.name(); - foundConfigurations.append(cpPriv); - } - [autoreleasepool release]; - pollTimer.start(); - return foundConfigurations; -} -#endif - QString QCoreWlanEngine::getInterfaceFromId(const QString &id) { return configurationInterface.value(id); @@ -326,7 +237,6 @@ void QCoreWlanEngine::doRequestUpdate() } } - qDebug() << "Found configuration" << i.key(); QNetworkInterface interface = QNetworkInterface::interfaceFromName(i.key()); if (!interface.isValid()) @@ -348,8 +258,6 @@ void QCoreWlanEngine::doRequestUpdate() QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; - qDebug() << "interface flags:" << interface.flags(); - if (interface.flags() && QNetworkInterface::IsRunning) state = QNetworkConfiguration::Defined; @@ -381,10 +289,8 @@ void QCoreWlanEngine::doRequestUpdate() changed = true; } - if (changed) { - qDebug() << "Configuration changed" << ptr->name << ptr->id; + if (changed) emit configurationChanged(ptr); - } } else { QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); @@ -397,7 +303,6 @@ void QCoreWlanEngine::doRequestUpdate() accessPointConfigurations.insert(id, ptr); configurationInterface.insert(id, interface.name()); - qDebug() << "Configuration Added" << ptr->name << ptr->id; emit configurationAdded(ptr); } } @@ -405,7 +310,6 @@ void QCoreWlanEngine::doRequestUpdate() while (!previous.isEmpty()) { QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(previous.takeFirst()); - qDebug() << "Configuration Removed" << ptr->name << ptr->id; configurationInterface.remove(ptr->id); emit configurationRemoved(ptr); } @@ -439,8 +343,6 @@ QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) QNetworkConfiguration::StateFlags state = QNetworkConfiguration::Undefined; if ([currentInterface.interfaceState intValue] == kCWInterfaceStateRunning) { - QString interfaceSsidString = nsstringToQString([currentInterface ssid]); - qDebug() << "interfaceSsidString:" << interfaceSsidString; if (networkSsid == nsstringToQString([currentInterface ssid])) state = QNetworkConfiguration::Active; } else { @@ -449,7 +351,6 @@ QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) else state = QNetworkConfiguration::Defined; } - qDebug() << "state is:" << state; CWWirelessProfile *networkProfile = apNetwork.wirelessProfile; CW8021XProfile *userNetworkProfile = networkProfile.user8021XProfile; @@ -482,10 +383,8 @@ QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) changed = true; } - if (changed) { - qDebug() << "WLAN Configuration Changed" << interfaceName << ptr->name << ptr->id; + if (changed) emit configurationChanged(ptr); - } } else { QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); @@ -498,7 +397,6 @@ QStringList QCoreWlanEngine::scanForSsids(const QString &interfaceName) accessPointConfigurations.insert(id, ptr); configurationInterface.insert(id, interfaceName); - qDebug() << "WLAN Configuration Added" << interfaceName << ptr->name << ptr->id; emit configurationAdded(ptr); } } -- cgit v0.12