diff options
Diffstat (limited to 'examples/network')
20 files changed, 3092 insertions, 1 deletions
diff --git a/examples/network/bearercloud/bearercloud.cpp b/examples/network/bearercloud/bearercloud.cpp new file mode 100644 index 0000000..27a296d --- /dev/null +++ b/examples/network/bearercloud/bearercloud.cpp @@ -0,0 +1,197 @@ +/**************************************************************************** +** +** 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 examples 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 "bearercloud.h" +#include "cloud.h" + +#include <QGraphicsTextItem> +#include <QTimer> +#include <QDateTime> +#include <QHostInfo> + +#include <QDebug> + +#include <math.h> + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +//! [0] +BearerCloud::BearerCloud(QObject *parent) +: QGraphicsScene(parent), timerId(0) +{ + setSceneRect(-300, -300, 600, 600); + + qsrand(QDateTime::currentDateTime().toTime_t()); + + offset[QNetworkConfiguration::Active] = 2 * M_PI * qrand() / RAND_MAX; + offset[QNetworkConfiguration::Discovered] = offset[QNetworkConfiguration::Active] + M_PI / 6; + offset[QNetworkConfiguration::Defined] = offset[QNetworkConfiguration::Discovered] - M_PI / 6; + offset[QNetworkConfiguration::Undefined] = offset[QNetworkConfiguration::Undefined] + M_PI / 6; + + thisDevice = new QGraphicsTextItem(QHostInfo::localHostName()); + thisDevice->setData(0, QLatin1String("This Device")); + thisDevice->setPos(thisDevice->boundingRect().width() / -2, + thisDevice->boundingRect().height() / -2); + addItem(thisDevice); + + qreal radius = Cloud::getRadiusForState(QNetworkConfiguration::Active); + QGraphicsEllipseItem *orbit = new QGraphicsEllipseItem(-radius, -radius, 2*radius, 2*radius); + orbit->setPen(QColor(Qt::green)); + addItem(orbit); + radius = Cloud::getRadiusForState(QNetworkConfiguration::Discovered); + orbit = new QGraphicsEllipseItem(-radius, -radius, 2*radius, 2*radius); + orbit->setPen(QColor(Qt::blue)); + addItem(orbit); + radius = Cloud::getRadiusForState(QNetworkConfiguration::Defined); + orbit = new QGraphicsEllipseItem(-radius, -radius, 2*radius, 2*radius); + orbit->setPen(QColor(Qt::darkGray)); + addItem(orbit); + radius = Cloud::getRadiusForState(QNetworkConfiguration::Undefined); + orbit = new QGraphicsEllipseItem(-radius, -radius, 2*radius, 2*radius); + orbit->setPen(QColor(Qt::lightGray)); + addItem(orbit); + + connect(&manager, SIGNAL(configurationAdded(QNetworkConfiguration)), + this, SLOT(configurationAdded(QNetworkConfiguration))); + connect(&manager, SIGNAL(configurationRemoved(QNetworkConfiguration)), + this, SLOT(configurationRemoved(QNetworkConfiguration))); + connect(&manager, SIGNAL(configurationChanged(QNetworkConfiguration)), + this, SLOT(configurationChanged(QNetworkConfiguration))); + + QTimer::singleShot(0, this, SLOT(updateConfigurations())); +} +//! [0] + +BearerCloud::~BearerCloud() +{ +} + +void BearerCloud::cloudMoved() +{ + if (!timerId) + timerId = startTimer(1000 / 25); +} + +void BearerCloud::timerEvent(QTimerEvent *) +{ + QList<Cloud *> clouds; + foreach (QGraphicsItem *item, items()) { + if (Cloud *cloud = qgraphicsitem_cast<Cloud *>(item)) + clouds << cloud; + } + + foreach (Cloud *cloud, clouds) + cloud->calculateForces(); + + bool cloudsMoved = false; + foreach (Cloud *cloud, clouds) + cloudsMoved |= cloud->advance(); + + if (!cloudsMoved) { + killTimer(timerId); + timerId = 0; + } +} + +//! [2] +void BearerCloud::configurationAdded(const QNetworkConfiguration &config) +{ + const QNetworkConfiguration::StateFlags state = config.state(); + + configStates.insert(state, config.identifier()); + + const qreal radius = Cloud::getRadiusForState(state); + const int count = configStates.count(state); + const qreal angle = 2 * M_PI / count; + + Cloud *item = new Cloud(config); + configurations.insert(config.identifier(), item); + + item->setPos(radius * cos((count-1) * angle + offset[state]), + radius * sin((count-1) * angle + offset[state])); + + addItem(item); + + cloudMoved(); +} +//! [2] + +//! [3] +void BearerCloud::configurationRemoved(const QNetworkConfiguration &config) +{ + foreach (const QNetworkConfiguration::StateFlags &state, configStates.uniqueKeys()) + configStates.remove(state, config.identifier()); + + Cloud *item = configurations.take(config.identifier()); + + item->setFinalScale(0.0); + item->setDeleteAfterAnimation(true); + + cloudMoved(); +} +//! [3] + +//! [4] +void BearerCloud::configurationChanged(const QNetworkConfiguration &config) +{ + foreach (const QNetworkConfiguration::StateFlags &state, configStates.uniqueKeys()) + configStates.remove(state, config.identifier()); + + configStates.insert(config.state(), config.identifier()); + + cloudMoved(); +} +//! [4] + +//! [1] +void BearerCloud::updateConfigurations() +{ + QList<QNetworkConfiguration> allConfigurations = manager.allConfigurations(); + + while (!allConfigurations.isEmpty()) + configurationAdded(allConfigurations.takeFirst()); + + cloudMoved(); +} +//! [1] + diff --git a/examples/network/bearercloud/bearercloud.h b/examples/network/bearercloud/bearercloud.h new file mode 100644 index 0000000..f09cb53 --- /dev/null +++ b/examples/network/bearercloud/bearercloud.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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 examples 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 <qnetworkconfigmanager.h> + +#include <QGraphicsScene> +#include <QMap> +#include <QHash> + +QT_USE_NAMESPACE + +class Cloud; + +class BearerCloud : public QGraphicsScene +{ + Q_OBJECT + +public: + BearerCloud(QObject *parent = 0); + ~BearerCloud(); + + void cloudMoved(); + + void timerEvent(QTimerEvent *event); + +private Q_SLOTS: + void configurationAdded(const QNetworkConfiguration &config); + void configurationRemoved(const QNetworkConfiguration &config); + void configurationChanged(const QNetworkConfiguration &config); + void updateConfigurations(); + +private: + QNetworkConfigurationManager manager; + + QGraphicsTextItem *thisDevice; + QHash<QString, Cloud *> configurations; + + QMap<QNetworkConfiguration::StateFlags, qreal> offset; + QMultiMap<QNetworkConfiguration::StateFlags, QString> configStates; + + int timerId; +}; + diff --git a/examples/network/bearercloud/bearercloud.pro b/examples/network/bearercloud/bearercloud.pro new file mode 100644 index 0000000..c07626a --- /dev/null +++ b/examples/network/bearercloud/bearercloud.pro @@ -0,0 +1,16 @@ +HEADERS = bearercloud.h \ + cloud.h + +SOURCES = main.cpp \ + bearercloud.cpp \ + cloud.cpp + +RESOURCES = icons.qrc + +TARGET = bearercloud + +QT = core gui network svg + +CONFIG += console + +symbian:TARGET.CAPABILITY = NetworkServices ReadUserData diff --git a/examples/network/bearercloud/cloud.cpp b/examples/network/bearercloud/cloud.cpp new file mode 100644 index 0000000..81e13a6 --- /dev/null +++ b/examples/network/bearercloud/cloud.cpp @@ -0,0 +1,361 @@ +/**************************************************************************** +** +** 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 examples 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 "cloud.h" +#include "bearercloud.h" + +#include <qnetworksession.h> + +#include <QGraphicsTextItem> +#include <QGraphicsSvgItem> +#include <QGraphicsSceneMouseEvent> +#include <QSvgRenderer> +#include <QPainter> + +#include <QDebug> + +#include <math.h> + +static QMap<QString, QSvgRenderer *> svgCache; + +//! [0] +Cloud::Cloud(const QNetworkConfiguration &config, QGraphicsItem *parent) +: QGraphicsItem(parent), configuration(config), deleteAfterAnimation(false) +{ + session = new QNetworkSession(configuration, this); + connect(session, SIGNAL(newConfigurationActivated()), + this, SLOT(newConfigurationActivated())); + connect(session, SIGNAL(stateChanged(QNetworkSession::State)), + this, SLOT(stateChanged(QNetworkSession::State))); + + setFlag(ItemIsMovable); +#if (QT_VERSION >= QT_VERSION_CHECK(4, 6, 0)) + setFlag(ItemSendsGeometryChanges); +#endif + setZValue(1); + + icon = new QGraphicsSvgItem(this); + text = new QGraphicsTextItem(this); + + currentScale = 0; + finalScale = 1; + setTransform(QTransform::fromScale(currentScale, currentScale), false); + setOpacity(0); + + newConfigurationActivated(); +} +//! [0] + +Cloud::~Cloud() +{ +} + +void Cloud::setFinalScale(qreal factor) +{ + finalScale = factor; +} + +void Cloud::setDeleteAfterAnimation(bool deleteAfter) +{ + deleteAfterAnimation = deleteAfter; +} + +void Cloud::calculateForces() +{ + if (!scene() || scene()->mouseGrabberItem() == this) { + newPos = pos(); + return; + } + + // sum up all the forces push this item away + qreal xvel = 0; + qreal yvel = 0; + QLineF orbitForce; + foreach (QGraphicsItem *item, scene()->items()) { + // other clouds + Cloud *cloud = qgraphicsitem_cast<Cloud *>(item); + if (!cloud && item->data(0) != QLatin1String("This Device")) + continue; + + qreal factor = 1.0; + + QLineF line(cloud ? item->mapToScene(0, 0) : QPointF(0, 0), mapToScene(0, 0)); + if (item->data(0) == QLatin1String("This Device")) + orbitForce = line; + + if (cloud) + factor = cloud->currentScale; + + qreal dx = line.dx(); + qreal dy = line.dy(); + double l = 2.0 * (dx * dx + dy * dy); + if (l > 0) { + xvel += factor * dx * 200.0 / l; + yvel += factor * dy * 200.0 / l; + } + } + + // tendency to stay at a fixed orbit + qreal orbit = getRadiusForState(configuration.state()); + qreal distance = orbitForce.length(); + + QLineF unit = orbitForce.unitVector(); + + orbitForce.setLength(xvel * unit.dx() + yvel * unit.dy()); + + qreal w = 2 - exp(-pow(distance-orbit, 2)/(2 * 50)); + + if (distance < orbit) { + xvel += orbitForce.dx() * w; + yvel += orbitForce.dy() * w; + } else { + xvel -= orbitForce.dx() * w; + yvel -= orbitForce.dy() * w; + } + + if (qAbs(xvel) < 0.1 && qAbs(yvel) < 0.1) + xvel = yvel = 0; + + QRectF sceneRect = scene()->sceneRect(); + newPos = pos() + QPointF(xvel, yvel); + newPos.setX(qMin(qMax(newPos.x(), sceneRect.left() + 10), sceneRect.right() - 10)); + newPos.setY(qMin(qMax(newPos.y(), sceneRect.top() + 10), sceneRect.bottom() - 10)); +} + +bool Cloud::advance() +{ + static const qreal scaleDelta = 0.01; + + bool animated = false; + + if (currentScale < finalScale) { + animated = true; + currentScale = qMin<qreal>(currentScale + scaleDelta, finalScale); + setTransform(QTransform::fromScale(currentScale, currentScale), false); + } else if (currentScale > finalScale) { + animated = true; + currentScale = qMax<qreal>(currentScale - scaleDelta, finalScale); + setTransform(QTransform::fromScale(currentScale, currentScale), false); + } + + if (newPos != pos()) { + setPos(newPos); + animated = true; + } + + if (opacity() != finalOpacity) { + animated = true; + if (qAbs(finalScale - currentScale) > 0.0) { + // use scale as reference + setOpacity(opacity() + scaleDelta * (finalOpacity - opacity()) / + qAbs(finalScale - currentScale)); + } else { + setOpacity(finalOpacity); + } + } + + if (!animated && deleteAfterAnimation) + deleteLater(); + + return animated; +} + +QRectF Cloud::boundingRect() const +{ + return childrenBoundingRect(); +} + +void Cloud::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) +{ +} + +//! [4] +QVariant Cloud::itemChange(GraphicsItemChange change, const QVariant &value) +{ + switch (change) { + case ItemPositionHasChanged: + if (BearerCloud *bearercloud = qobject_cast<BearerCloud *>(scene())) + bearercloud->cloudMoved(); + default: + ; + }; + + return QGraphicsItem::itemChange(change, value); +} +//! [4] + +//! [3] +void Cloud::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { + if (session->isOpen()) + session->close(); + else + session->open(); + + event->accept(); + } +} +//! [3] + +//! [2] +void Cloud::stateChanged(QNetworkSession::State state) +{ + if (configuration.name().isEmpty()) + finalOpacity = qreal(0.1); + else if (session->state() == QNetworkSession::NotAvailable) + finalOpacity = 0.5; + else + finalOpacity = 1.0; + + QString tooltip; + + if (configuration.name().isEmpty()) + tooltip += tr("<b>HIDDEN NETWORK</b><br>"); + else + tooltip += tr("<b>%1</b><br>").arg(configuration.name()); + + const QNetworkInterface interface = session->interface(); + if (interface.isValid()) + tooltip += tr("<br>Interface: %1").arg(interface.humanReadableName()); + tooltip += tr("<br>Id: %1").arg(configuration.identifier()); + + const QString bearerName = configuration.bearerName(); + if (!bearerName.isEmpty()) + tooltip += tr("<br>Bearer: %1").arg(bearerName); + + QString s = tr("<br>State: %1 (%2)"); + switch (state) { + case QNetworkSession::Invalid: + s = s.arg(tr("Invalid")); + break; + case QNetworkSession::NotAvailable: + s = s.arg(tr("Not Available")); + break; + case QNetworkSession::Connecting: + s = s.arg(tr("Connecting")); + break; + case QNetworkSession::Connected: + s = s.arg(tr("Connected")); + break; + case QNetworkSession::Closing: + s = s.arg(tr("Closing")); + break; + case QNetworkSession::Disconnected: + s = s.arg(tr("Disconnected")); + break; + case QNetworkSession::Roaming: + s = s.arg(tr("Roaming")); + break; + default: + s = s.arg(tr("Unknown")); + } + + if (session->isOpen()) + s = s.arg(tr("Open")); + else + s = s.arg(tr("Closed")); + + tooltip += s; + + tooltip += tr("<br><br>Active time: %1 seconds").arg(session->activeTime()); + tooltip += tr("<br>Received data: %1 bytes").arg(session->bytesReceived()); + tooltip += tr("<br>Sent data: %1 bytes").arg(session->bytesWritten()); + + setToolTip(tooltip); +} +//! [2] + +//! [1] +void Cloud::newConfigurationActivated() +{ + const QString bearerName = configuration.bearerName(); + if (!svgCache.contains(bearerName)) { + if (bearerName == QLatin1String("WLAN")) + svgCache.insert(bearerName, new QSvgRenderer(QLatin1String(":wlan.svg"))); + else if (bearerName == QLatin1String("Ethernet")) + svgCache.insert(bearerName, new QSvgRenderer(QLatin1String(":lan.svg"))); + else + svgCache.insert(bearerName, new QSvgRenderer(QLatin1String(":unknown.svg"))); + } + + icon->setSharedRenderer(svgCache[bearerName]); + + if (configuration.name().isEmpty()) { + text->setPlainText(tr("HIDDEN NETWORK")); + } else { + if (configuration.type() == QNetworkConfiguration::ServiceNetwork) + text->setHtml("<b>" + configuration.name() + "</b>"); + else + text->setPlainText(configuration.name()); + } + + const qreal height = icon->boundingRect().height() + text->boundingRect().height(); + + icon->setPos(icon->boundingRect().width() / -2, height / -2); + + text->setPos(text->boundingRect().width() / -2, + height / 2 - text->boundingRect().height()); + + stateChanged(session->state()); +} +//! [1] + +qreal Cloud::getRadiusForState(QNetworkConfiguration::StateFlags state) +{ + switch (state) { + case QNetworkConfiguration::Active: + return 100; + break; + case QNetworkConfiguration::Discovered: + return 150; + break; + case QNetworkConfiguration::Defined: + return 200; + break; + case QNetworkConfiguration::Undefined: + return 250; + break; + default: + return 300; + } +} + diff --git a/examples/network/bearercloud/cloud.h b/examples/network/bearercloud/cloud.h new file mode 100644 index 0000000..38f8aff --- /dev/null +++ b/examples/network/bearercloud/cloud.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** 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 examples 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 <qnetworkconfiguration.h> +#include <qnetworksession.h> + +#include <QGraphicsItem> +QT_USE_NAMESPACE + +QT_BEGIN_NAMESPACE +class QGraphicsTextItem; +class QGraphicsSvgItem; +QT_END_NAMESPACE + +class Cloud : public QObject, public QGraphicsItem +{ + Q_OBJECT + Q_INTERFACES(QGraphicsItem) + +public: + Cloud(const QNetworkConfiguration &config, QGraphicsItem *parent = 0); + ~Cloud(); + + enum { Type = UserType + 1 }; + int type() const { return Type; } + + void setFinalScale(qreal factor); + void setDeleteAfterAnimation(bool deleteAfter); + + void calculateForces(); + + bool advance(); + QRectF boundingRect() const; + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + + static qreal getRadiusForState(QNetworkConfiguration::StateFlags state); + +protected: + QVariant itemChange(GraphicsItemChange change, const QVariant &value); + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); + +private Q_SLOTS: + void stateChanged(QNetworkSession::State state); + void newConfigurationActivated(); + +private: + QNetworkConfiguration configuration; + QNetworkSession *session; + + QGraphicsTextItem *text; + QGraphicsSvgItem *icon; + + qreal finalOpacity; + qreal finalScale; + qreal currentScale; + + QPointF newPos; + + bool deleteAfterAnimation; +}; + diff --git a/examples/network/bearercloud/icons.qrc b/examples/network/bearercloud/icons.qrc new file mode 100644 index 0000000..84a8939 --- /dev/null +++ b/examples/network/bearercloud/icons.qrc @@ -0,0 +1,7 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>wlan.svg</file> + <file>lan.svg</file> + <file>unknown.svg</file> +</qresource> +</RCC> diff --git a/examples/network/bearercloud/lan.svg b/examples/network/bearercloud/lan.svg new file mode 100644 index 0000000..3cce805 --- /dev/null +++ b/examples/network/bearercloud/lan.svg @@ -0,0 +1,76 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="25.000002" + height="9.6406126" + id="svg2" + sodipodi:version="0.32" + inkscape:version="0.46" + version="1.0" + sodipodi:docname="lan.svg" + inkscape:output_extension="org.inkscape.output.svg.inkscape"> + <defs + id="defs4"> + <inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 526.18109 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="744.09448 : 526.18109 : 1" + inkscape:persp3d-origin="372.04724 : 350.78739 : 1" + id="perspective10" /> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + gridtolerance="10000" + guidetolerance="10" + objecttolerance="10" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="19.416667" + inkscape:cx="15.244635" + inkscape:cy="11.639485" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="false" + inkscape:window-width="1459" + inkscape:window-height="964" + inkscape:window-x="453" + inkscape:window-y="166" /> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(-4.0978193e-8,-19.359387)"> + <text + xml:space="preserve" + style="font-size:13.99289513px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans" + x="-1.1205248" + y="29" + id="text3239"><tspan + sodipodi:role="line" + id="tspan3241" + x="-1.1205248" + y="29">LAN</tspan></text> + </g> +</svg> diff --git a/examples/network/bearercloud/main.cpp b/examples/network/bearercloud/main.cpp new file mode 100644 index 0000000..86ef46f --- /dev/null +++ b/examples/network/bearercloud/main.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** 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 examples 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 "bearercloud.h" + +#include <QApplication> +#include <QGraphicsView> + +class CloudView : public QGraphicsView +{ + Q_OBJECT + +public: + CloudView(QGraphicsScene *scene); + ~CloudView() { } + +protected: + void resizeEvent(QResizeEvent *) { + fitInView(sceneRect(), Qt::KeepAspectRatio); + } +#ifdef Q_OS_WINCE + void hideEvent(QHideEvent *) { + qApp->quit(); + } +#endif +}; + +CloudView::CloudView(QGraphicsScene *scene) +: QGraphicsView(scene) +{ + setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing | + QPainter::SmoothPixmapTransform); +#if defined (Q_OS_SYMBIAN) || defined (Q_OS_WINCE) + setWindowState(Qt::WindowMaximized); +#endif +} + +#include "main.moc" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + BearerCloud bearerCloud; + + CloudView view(&bearerCloud); + view.show(); + + return app.exec(); +} + diff --git a/examples/network/bearercloud/unknown.svg b/examples/network/bearercloud/unknown.svg new file mode 100644 index 0000000..fd10298 --- /dev/null +++ b/examples/network/bearercloud/unknown.svg @@ -0,0 +1,76 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="25" + height="9.0681238" + id="svg2" + sodipodi:version="0.32" + inkscape:version="0.46" + version="1.0" + sodipodi:docname="unknown.svg" + inkscape:output_extension="org.inkscape.output.svg.inkscape"> + <defs + id="defs4"> + <inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 526.18109 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="744.09448 : 526.18109 : 1" + inkscape:persp3d-origin="372.04724 : 350.78739 : 1" + id="perspective10" /> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + gridtolerance="10000" + guidetolerance="10" + objecttolerance="10" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="19.416667" + inkscape:cx="15.244635" + inkscape:cy="11.639485" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="false" + inkscape:window-width="1459" + inkscape:window-height="964" + inkscape:window-x="453" + inkscape:window-y="166" /> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(-6.891787e-8,-19.931876)"> + <text + xml:space="preserve" + style="font-size:13.16195393px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans" + x="-1.0539845" + y="29" + id="text3239"><tspan + sodipodi:role="line" + id="tspan3241" + x="-1.0539845" + y="29">NET</tspan></text> + </g> +</svg> diff --git a/examples/network/bearercloud/wlan.svg b/examples/network/bearercloud/wlan.svg new file mode 100644 index 0000000..8b86089 --- /dev/null +++ b/examples/network/bearercloud/wlan.svg @@ -0,0 +1,151 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="27" + height="29" + id="svg2" + sodipodi:version="0.32" + inkscape:version="0.46" + version="1.0" + sodipodi:docname="wlan.svg" + inkscape:output_extension="org.inkscape.output.svg.inkscape"> + <defs + id="defs4"> + <inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 526.18109 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="744.09448 : 526.18109 : 1" + inkscape:persp3d-origin="372.04724 : 350.78739 : 1" + id="perspective10" /> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + gridtolerance="10000" + guidetolerance="10" + objecttolerance="10" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="19.416667" + inkscape:cx="23.665236" + inkscape:cy="11.639485" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="false" + inkscape:window-width="1912" + inkscape:window-height="1130" + inkscape:window-x="0" + inkscape:window-y="0" /> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1"> + <g + id="g6334" + transform="translate(1.0000001,0)"> + <path + id="path2393" + d="M 12.500248,9.499893 L 12.500248,28.500095" + style="fill:none;fill-rule:evenodd;stroke:#3bb3ff;stroke-width:0.99981093;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> + <path + sodipodi:open="true" + sodipodi:end="4.1887902" + sodipodi:start="2.0943951" + transform="matrix(1.0216765,0,0,1.0324764,0.4493163,-22.692096)" + d="M 8.8583691,34.085043 A 3.9141631,3.9141631 0 0 1 8.8583691,27.305513" + sodipodi:ry="3.9141631" + sodipodi:rx="3.9141631" + sodipodi:cy="30.695278" + sodipodi:cx="10.815451" + id="path3171" + style="fill:none;fill-opacity:0;stroke:#3bb3ff;stroke-width:0.97365081;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + sodipodi:type="arc" /> + <path + sodipodi:open="true" + sodipodi:end="4.1887902" + sodipodi:start="2.0943951" + transform="matrix(1.6055152,0,0,1.6224868,-7.5798083,-40.80263)" + d="M 8.8583691,34.085043 A 3.9141631,3.9141631 0 0 1 8.8583691,27.305513" + sodipodi:ry="3.9141631" + sodipodi:rx="3.9141631" + sodipodi:cy="30.695278" + sodipodi:cx="10.815451" + id="path3175" + style="fill:none;fill-opacity:0;stroke:#3bb3ff;stroke-width:0.61958688;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + sodipodi:type="arc" /> + <path + sodipodi:open="true" + sodipodi:end="4.1887902" + sodipodi:start="2.0943951" + transform="matrix(2.4812855,0,0,2.5075146,-17.62358,-67.968804)" + d="M 8.8583691,34.085043 A 3.9141631,3.9141631 0 0 1 8.8583691,27.305513" + sodipodi:ry="3.9141631" + sodipodi:rx="3.9141631" + sodipodi:cy="30.695278" + sodipodi:cx="10.815451" + id="path3177" + style="fill:none;fill-opacity:0;stroke:#3bb3ff;stroke-width:0.40090355;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + sodipodi:type="arc" /> + <path + sodipodi:open="true" + sodipodi:end="4.1887902" + sodipodi:start="2.0943951" + transform="matrix(-1.0216765,0,0,1.0324764,24.550388,-22.692096)" + d="M 8.8583691,34.085043 A 3.9141631,3.9141631 0 0 1 8.8583691,27.305513" + sodipodi:ry="3.9141631" + sodipodi:rx="3.9141631" + sodipodi:cy="30.695278" + sodipodi:cx="10.815451" + id="path3179" + style="fill:none;fill-opacity:0;stroke:#3bb3ff;stroke-width:0.97365081;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + sodipodi:type="arc" /> + <path + sodipodi:open="true" + sodipodi:end="4.1887902" + sodipodi:start="2.0943951" + transform="matrix(-1.6055152,0,0,1.6224868,32.580246,-40.80263)" + d="M 8.8583691,34.085043 A 3.9141631,3.9141631 0 0 1 8.8583691,27.305513" + sodipodi:ry="3.9141631" + sodipodi:rx="3.9141631" + sodipodi:cy="30.695278" + sodipodi:cx="10.815451" + id="path3181" + style="fill:none;fill-opacity:0;stroke:#3bb3ff;stroke-width:0.61958688;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + sodipodi:type="arc" /> + <path + sodipodi:open="true" + sodipodi:end="4.1887902" + sodipodi:start="2.0943951" + transform="matrix(-2.4812855,0,0,2.5075146,42.623143,-67.968804)" + d="M 8.8583691,34.085043 A 3.9141631,3.9141631 0 0 1 8.8583691,27.305513" + sodipodi:ry="3.9141631" + sodipodi:rx="3.9141631" + sodipodi:cy="30.695278" + sodipodi:cx="10.815451" + id="path3183" + style="fill:none;fill-opacity:0;stroke:#3bb3ff;stroke-width:0.40090355;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + sodipodi:type="arc" /> + </g> + </g> +</svg> diff --git a/examples/network/bearermonitor/bearermonitor.cpp b/examples/network/bearermonitor/bearermonitor.cpp new file mode 100644 index 0000000..5b2bad1 --- /dev/null +++ b/examples/network/bearermonitor/bearermonitor.cpp @@ -0,0 +1,395 @@ +/**************************************************************************** +** +** 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 examples 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 "bearermonitor.h" +#include "sessionwidget.h" + +#include <QDebug> + +#ifdef Q_OS_WIN +#include <winsock2.h> +#undef interface + +#ifndef NS_NLA +#define NS_NLA 15 +#endif +#endif + +BearerMonitor::BearerMonitor(QWidget *parent) +: QWidget(parent) +{ + setupUi(this); + delete tabWidget->currentWidget(); + sessionGroup->hide(); +#if defined (Q_OS_SYMBIAN) || defined(Q_OS_WINCE) + setWindowState(Qt::WindowMaximized); +#endif + updateConfigurations(); + + onlineStateChanged(!manager.allConfigurations(QNetworkConfiguration::Active).isEmpty()); + + QNetworkConfiguration defaultConfiguration = manager.defaultConfiguration(); + for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) { + QTreeWidgetItem *item = treeWidget->topLevelItem(i); + + if (item->data(0, Qt::UserRole).toString() == defaultConfiguration.identifier()) { + treeWidget->setCurrentItem(item); + showConfigurationFor(item); + break; + } + } + + connect(&manager, SIGNAL(configurationAdded(const QNetworkConfiguration&)), + this, SLOT(configurationAdded(const QNetworkConfiguration&))); + connect(&manager, SIGNAL(configurationRemoved(const QNetworkConfiguration&)), + this, SLOT(configurationRemoved(const QNetworkConfiguration&))); + connect(&manager, SIGNAL(configurationChanged(const QNetworkConfiguration&)), + this, SLOT(configurationChanged(const QNetworkConfiguration))); + connect(&manager, SIGNAL(updateCompleted()), this, SLOT(updateConfigurations())); + connect(&manager, SIGNAL(onlineStateChanged(bool)), this ,SLOT(onlineStateChanged(bool))); + +#ifdef Q_OS_WIN + connect(registerButton, SIGNAL(clicked()), this, SLOT(registerNetwork())); + connect(unregisterButton, SIGNAL(clicked()), this, SLOT(unregisterNetwork())); +#else + nlaGroup->hide(); +#endif + + connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)), + this, SLOT(createSessionFor(QTreeWidgetItem*))); + + connect(treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), + this, SLOT(showConfigurationFor(QTreeWidgetItem*))); + + connect(newSessionButton, SIGNAL(clicked()), + this, SLOT(createNewSession())); + connect(deleteSessionButton, SIGNAL(clicked()), + this, SLOT(deleteSession())); + + connect(scanButton, SIGNAL(clicked()), + this, SLOT(performScan())); +} + +BearerMonitor::~BearerMonitor() +{ +} + +static void updateItem(QTreeWidgetItem *item, const QNetworkConfiguration &config) +{ + item->setText(0, config.name()); + item->setData(0, Qt::UserRole, config.identifier()); + + QFont font = item->font(1); + font.setBold((config.state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active); + item->setFont(0, font); +} + +void BearerMonitor::configurationAdded(const QNetworkConfiguration &config, QTreeWidgetItem *parent) +{ + QTreeWidgetItem *item = new QTreeWidgetItem; + updateItem(item, config); + + if (parent) + parent->addChild(item); + else + treeWidget->addTopLevelItem(item); + + if (config.type() == QNetworkConfiguration::ServiceNetwork) { + foreach (const QNetworkConfiguration &child, config.children()) + configurationAdded(child, item); + } +} + +void BearerMonitor::configurationRemoved(const QNetworkConfiguration &config) +{ + for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) { + QTreeWidgetItem *item = treeWidget->topLevelItem(i); + + if (item->data(0, Qt::UserRole).toString() == config.identifier()) { + delete item; + break; + } + } +} + +void BearerMonitor::configurationChanged(const QNetworkConfiguration &config) +{ + for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) { + QTreeWidgetItem *item = treeWidget->topLevelItem(i); + + if (item->data(0, Qt::UserRole).toString() == config.identifier()) { + updateItem(item, config); + + if (config.type() == QNetworkConfiguration::ServiceNetwork) + updateSnapConfiguration(item, config); + + if (item == treeWidget->currentItem()) + showConfigurationFor(item); + + break; + } + } +} + +void BearerMonitor::updateSnapConfiguration(QTreeWidgetItem *parent, const QNetworkConfiguration &snap) +{ + QMap<QString, QTreeWidgetItem *> itemMap; + for (int i = 0; i < parent->childCount(); ++i) { + QTreeWidgetItem *item = parent->child(i); + itemMap.insert(item->data(0, Qt::UserRole).toString(), item); + } + + QList<QNetworkConfiguration> allConfigurations = snap.children(); + + while (!allConfigurations.isEmpty()) { + QNetworkConfiguration config = allConfigurations.takeFirst(); + + QTreeWidgetItem *item = itemMap.take(config.identifier()); + if (item) { + updateItem(item, config); + + if (config.type() == QNetworkConfiguration::ServiceNetwork) + updateSnapConfiguration(item, config); + } else { + configurationAdded(config, parent); + } + } + + foreach (const QString &id, itemMap.keys()) + delete itemMap.value(id); + + itemMap.clear(); +} + +void BearerMonitor::updateConfigurations() +{ + progressBar->hide(); + scanButton->show(); + + QList<QTreeWidgetItem *> items = treeWidget->findItems(QLatin1String("*"), Qt::MatchWildcard); + QMap<QString, QTreeWidgetItem *> itemMap; + while (!items.isEmpty()) { + QTreeWidgetItem *item = items.takeFirst(); + itemMap.insert(item->data(0, Qt::UserRole).toString(), item); + } + + QList<QNetworkConfiguration> allConfigurations = manager.allConfigurations(); + + while (!allConfigurations.isEmpty()) { + QNetworkConfiguration config = allConfigurations.takeFirst(); + + QTreeWidgetItem *item = itemMap.take(config.identifier()); + if (item) { + updateItem(item, config); + + if (config.type() == QNetworkConfiguration::ServiceNetwork) + updateSnapConfiguration(item, config); + } else { + configurationAdded(config); + } + } + + foreach (const QString &id, itemMap.keys()) + delete itemMap.value(id); +} + +void BearerMonitor::onlineStateChanged(bool isOnline) +{ + if (isOnline) + onlineState->setText(tr("Online")); + else + onlineState->setText(tr("Offline")); +} + +#ifdef Q_OS_WIN +void BearerMonitor::registerNetwork() +{ + QTreeWidgetItem *item = treeWidget->currentItem(); + + QNetworkConfiguration configuration = + manager.configurationFromIdentifier(item->data(0, Qt::UserRole).toString()); + + const QString name = configuration.name(); + + qDebug() << "Registering" << name << "with system"; + + WSAQUERYSET networkInfo; + memset(&networkInfo, 0, sizeof(networkInfo)); + networkInfo.dwSize = sizeof(networkInfo); + networkInfo.lpszServiceInstanceName = (LPWSTR)name.utf16(); + networkInfo.dwNameSpace = NS_NLA; + + if (WSASetService(&networkInfo, RNRSERVICE_REGISTER, 0) == SOCKET_ERROR) + qDebug() << "WSASetService(RNRSERVICE_REGISTER) returned" << WSAGetLastError(); +} + +void BearerMonitor::unregisterNetwork() +{ + QTreeWidgetItem *item = treeWidget->currentItem(); + + QNetworkConfiguration configuration = + manager.configurationFromIdentifier(item->data(0, Qt::UserRole).toString()); + + const QString name = configuration.name(); + + qDebug() << "Unregistering" << name << "with system"; + + WSAQUERYSET networkInfo; + memset(&networkInfo, 0, sizeof(networkInfo)); + networkInfo.dwSize = sizeof(networkInfo); + networkInfo.lpszServiceInstanceName = (LPWSTR)name.utf16(); + networkInfo.dwNameSpace = NS_NLA; + + if (WSASetService(&networkInfo, RNRSERVICE_DELETE, 0) == SOCKET_ERROR) + qDebug() << "WSASetService(RNRSERVICE_DELETE) returned" << WSAGetLastError(); +} +#endif + +void BearerMonitor::showConfigurationFor(QTreeWidgetItem *item) +{ + QString identifier; + + if (item) + identifier = item->data(0, Qt::UserRole).toString(); + + QNetworkConfiguration conf = manager.configurationFromIdentifier(identifier); + + switch (conf.state()) { + case QNetworkConfiguration::Active: + configurationState->setText(tr("Active")); + break; + case QNetworkConfiguration::Discovered: + configurationState->setText(tr("Discovered")); + break; + case QNetworkConfiguration::Defined: + configurationState->setText(tr("Defined")); + break; + case QNetworkConfiguration::Undefined: + configurationState->setText(tr("Undefined")); + break; + default: + configurationState->setText(QString()); + } + + switch (conf.type()) { + case QNetworkConfiguration::InternetAccessPoint: + configurationType->setText(tr("Internet Access Point")); + break; + case QNetworkConfiguration::ServiceNetwork: + configurationType->setText(tr("Service Network")); + break; + case QNetworkConfiguration::UserChoice: + configurationType->setText(tr("User Choice")); + break; + case QNetworkConfiguration::Invalid: + configurationType->setText(tr("Invalid")); + break; + default: + configurationType->setText(QString()); + } + + switch (conf.purpose()) { + case QNetworkConfiguration::UnknownPurpose: + configurationPurpose->setText(tr("Unknown")); + break; + case QNetworkConfiguration::PublicPurpose: + configurationPurpose->setText(tr("Public")); + break; + case QNetworkConfiguration::PrivatePurpose: + configurationPurpose->setText(tr("Private")); + break; + case QNetworkConfiguration::ServiceSpecificPurpose: + configurationPurpose->setText(tr("Service Specific")); + break; + default: + configurationPurpose->setText(QString()); + } + + configurationIdentifier->setText(conf.identifier()); + + configurationRoaming->setText(conf.isRoamingAvailable() ? tr("Available") : tr("Not available")); + + configurationChildren->setText(QString::number(conf.children().count())); + + configurationName->setText(conf.name()); +} + +void BearerMonitor::createSessionFor(QTreeWidgetItem *item) +{ + const QString identifier = item->data(0, Qt::UserRole).toString(); + + QNetworkConfiguration conf = manager.configurationFromIdentifier(identifier); + + SessionWidget *session = new SessionWidget(conf); + + tabWidget->addTab(session, conf.name()); + + sessionGroup->show(); + + sessionWidgets.append(session); +} + +void BearerMonitor::createNewSession() +{ + QTreeWidgetItem *item = treeWidget->currentItem(); + + createSessionFor(item); +} + +void BearerMonitor::deleteSession() +{ + SessionWidget *session = qobject_cast<SessionWidget *>(tabWidget->currentWidget()); + if (session) { + sessionWidgets.removeAll(session); + + delete session; + + if (tabWidget->count() == 0) + sessionGroup->hide(); + } +} + +void BearerMonitor::performScan() +{ + scanButton->hide(); + progressBar->show(); + manager.updateConfigurations(); +} diff --git a/examples/network/bearermonitor/bearermonitor.h b/examples/network/bearermonitor/bearermonitor.h new file mode 100644 index 0000000..d7025dd --- /dev/null +++ b/examples/network/bearermonitor/bearermonitor.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** 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 examples 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 BEARERMONITOR_H +#define BEARERMONITOR_H + +#include <qnetworkconfigmanager.h> +#include <qnetworksession.h> +#if defined (Q_OS_SYMBIAN) || defined(Q_OS_WINCE) +#include "ui_bearermonitor_240_320.h" +#else +#include "ui_bearermonitor_640_480.h" +#endif + +QT_USE_NAMESPACE + +class SessionWidget; + +class BearerMonitor : public QWidget, public Ui_BearerMonitor +{ + Q_OBJECT + +public: + BearerMonitor(QWidget *parent = 0); + ~BearerMonitor(); + +private slots: + void configurationAdded(const QNetworkConfiguration &config, QTreeWidgetItem *parent = 0); + void configurationRemoved(const QNetworkConfiguration &config); + void configurationChanged(const QNetworkConfiguration &config); + void updateSnapConfiguration(QTreeWidgetItem *parent, const QNetworkConfiguration &snap); + void updateConfigurations(); + + void onlineStateChanged(bool isOnline); + +#ifdef Q_OS_WIN + void registerNetwork(); + void unregisterNetwork(); +#endif + + void showConfigurationFor(QTreeWidgetItem *item); + + void createSessionFor(QTreeWidgetItem *item); + void createNewSession(); + void deleteSession(); + + void performScan(); + +private: + QNetworkConfigurationManager manager; + QList<SessionWidget *> sessionWidgets; +}; + +#endif //BEARERMONITOR_H diff --git a/examples/network/bearermonitor/bearermonitor.pro b/examples/network/bearermonitor/bearermonitor.pro new file mode 100644 index 0000000..4b86187 --- /dev/null +++ b/examples/network/bearermonitor/bearermonitor.pro @@ -0,0 +1,26 @@ +HEADERS = sessionwidget.h \ + bearermonitor.h + +SOURCES = main.cpp \ + bearermonitor.cpp \ + sessionwidget.cpp + +FORMS = bearermonitor_240_320.ui \ + bearermonitor_640_480.ui \ + sessionwidget.ui + +TARGET = bearermonitor + +QT = core gui network + +win32 { + !wince* { + LIBS += -lWs2_32 + } else { + LIBS += -lWs2 + } +} + +CONFIG += console + +symbian:TARGET.CAPABILITY = NetworkServices ReadUserData diff --git a/examples/network/bearermonitor/bearermonitor_240_320.ui b/examples/network/bearermonitor/bearermonitor_240_320.ui new file mode 100644 index 0000000..ce9c2d1 --- /dev/null +++ b/examples/network/bearermonitor/bearermonitor_240_320.ui @@ -0,0 +1,420 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>BearerMonitor</class> + <widget class="QWidget" name="BearerMonitor"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>240</width> + <height>320</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_5"> + <item> + <widget class="QScrollArea" name="scrollArea"> + <property name="frameShape"> + <enum>QFrame::NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Plain</enum> + </property> + <property name="widgetResizable"> + <bool>true</bool> + </property> + <widget class="QWidget" name="scrollAreaWidgetContents"> + <property name="geometry"> + <rect> + <x>0</x> + <y>-274</y> + <width>206</width> + <height>576</height> + </rect> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QGroupBox" name="systemState"> + <property name="title"> + <string>System State</string> + </property> + <property name="flat"> + <bool>true</bool> + </property> + <layout class="QVBoxLayout" name="verticalLayout_4"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <layout class="QHBoxLayout" name="onlineStateLayout"> + <item> + <widget class="QLabel" name="onlineStateLabel"> + <property name="text"> + <string>Online State:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="onlineState"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>Configurations</string> + </property> + <property name="flat"> + <bool>true</bool> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_9"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QHBoxLayout" name="configurationNameLayout"> + <item> + <widget class="QLabel" name="configurationNameLabel"> + <property name="text"> + <string>Name:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="configurationName"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="configurationStateLayout"> + <item> + <widget class="QLabel" name="configurationStateLabel"> + <property name="text"> + <string>State:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="configurationState"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="configurationTypeLayout"> + <item> + <widget class="QLabel" name="configurationTypeLabel"> + <property name="text"> + <string>Type:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="configurationType"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Invalid</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="configurationPurposeLayout"> + <item> + <widget class="QLabel" name="configurationPurposeLabel"> + <property name="text"> + <string>Purpose:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="configurationPurpose"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Unknown</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="configurationIdentifierLayout"> + <item> + <widget class="QLabel" name="configurationIdentifierLabel"> + <property name="text"> + <string>Identifier:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="configurationIdentifier"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="configurationRoamingLayout"> + <item> + <widget class="QLabel" name="configurationRoamingLabel"> + <property name="text"> + <string>Roaming:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="configurationRoaming"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="configurationChildrenLayout"> + <item> + <widget class="QLabel" name="configurationChildrenLabel"> + <property name="text"> + <string>Children:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="configurationChildren"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QGroupBox" name="nlaGroup"> + <property name="title"> + <string>Network Location Awareness</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QPushButton" name="registerButton"> + <property name="text"> + <string>Register</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="unregisterButton"> + <property name="text"> + <string>Unregister</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QPushButton" name="newSessionButton"> + <property name="text"> + <string>New Session</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="deleteSessionButton"> + <property name="text"> + <string>Delete Session</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="scanButton"> + <property name="text"> + <string>Scan</string> + </property> + </widget> + </item> + <item> + <widget class="QProgressBar" name="progressBar"> + <property name="maximum"> + <number>0</number> + </property> + <property name="value"> + <number>-1</number> + </property> + <property name="textVisible"> + <bool>false</bool> + </property> + <property name="invertedAppearance"> + <bool>false</bool> + </property> + <property name="format"> + <string>%p%</string> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QTreeWidget" name="treeWidget"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="verticalScrollBarPolicy"> + <enum>Qt::ScrollBarAlwaysOff</enum> + </property> + <attribute name="headerVisible"> + <bool>false</bool> + </attribute> + <column> + <property name="text"> + <string>1</string> + </property> + </column> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="sessionGroup"> + <property name="title"> + <string>Sessions</string> + </property> + <property name="flat"> + <bool>true</bool> + </property> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QTabWidget" name="tabWidget"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="currentIndex"> + <number>0</number> + </property> + <widget class="QWidget" name="tab"> + <attribute name="title"> + <string>Session 1</string> + </attribute> + </widget> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/examples/network/bearermonitor/bearermonitor_640_480.ui b/examples/network/bearermonitor/bearermonitor_640_480.ui new file mode 100644 index 0000000..941eaa0 --- /dev/null +++ b/examples/network/bearermonitor/bearermonitor_640_480.ui @@ -0,0 +1,386 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>BearerMonitor</class> + <widget class="QWidget" name="BearerMonitor"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>640</width> + <height>515</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QGroupBox" name="systemState"> + <property name="title"> + <string>System State</string> + </property> + <property name="flat"> + <bool>true</bool> + </property> + <layout class="QVBoxLayout" name="verticalLayout_4"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <layout class="QHBoxLayout" name="onlineStateLayout"> + <item> + <widget class="QLabel" name="onlineStateLabel"> + <property name="text"> + <string>Online State:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="onlineState"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + <item row="1" column="0"> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>Configurations</string> + </property> + <property name="flat"> + <bool>true</bool> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_9"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QTreeWidget" name="treeWidget"> + <attribute name="headerVisible"> + <bool>false</bool> + </attribute> + <column> + <property name="text"> + <string>1</string> + </property> + </column> + </widget> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QHBoxLayout" name="configurationNameLayout"> + <item> + <widget class="QLabel" name="configurationNameLabel"> + <property name="text"> + <string>Name:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="configurationName"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="configurationStateLayout"> + <item> + <widget class="QLabel" name="configurationStateLabel"> + <property name="text"> + <string>State:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="configurationState"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="configurationTypeLayout"> + <item> + <widget class="QLabel" name="configurationTypeLabel"> + <property name="text"> + <string>Type:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="configurationType"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Invalid</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="configurationPurposeLayout"> + <item> + <widget class="QLabel" name="configurationPurposeLabel"> + <property name="text"> + <string>Purpose:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="configurationPurpose"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Unknown</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="configurationIdentifierLayout"> + <item> + <widget class="QLabel" name="configurationIdentifierLabel"> + <property name="text"> + <string>Identifier:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="configurationIdentifier"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="configurationRoamingLayout"> + <item> + <widget class="QLabel" name="configurationRoamingLabel"> + <property name="text"> + <string>Roaming:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="configurationRoaming"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="configurationChildrenLayout"> + <item> + <widget class="QLabel" name="configurationChildrenLabel"> + <property name="text"> + <string>Children:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="configurationChildren"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QGroupBox" name="nlaGroup"> + <property name="title"> + <string>Network Location Awareness</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QPushButton" name="registerButton"> + <property name="text"> + <string>Register</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="unregisterButton"> + <property name="text"> + <string>Unregister</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QPushButton" name="newSessionButton"> + <property name="text"> + <string>New Session</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="deleteSessionButton"> + <property name="text"> + <string>Delete Session</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="scanButton"> + <property name="text"> + <string>Scan</string> + </property> + </widget> + </item> + <item> + <widget class="QProgressBar" name="progressBar"> + <property name="maximum"> + <number>0</number> + </property> + <property name="value"> + <number>-1</number> + </property> + <property name="textVisible"> + <bool>false</bool> + </property> + <property name="invertedAppearance"> + <bool>false</bool> + </property> + <property name="format"> + <string>%p%</string> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + </layout> + </widget> + </item> + <item row="2" column="0"> + <widget class="QGroupBox" name="sessionGroup"> + <property name="title"> + <string>Sessions</string> + </property> + <property name="flat"> + <bool>true</bool> + </property> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QTabWidget" name="tabWidget"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="currentIndex"> + <number>0</number> + </property> + <widget class="QWidget" name="tab"> + <attribute name="title"> + <string>Session 1</string> + </attribute> + </widget> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/examples/network/bearermonitor/main.cpp b/examples/network/bearermonitor/main.cpp new file mode 100644 index 0000000..b7ac4fe --- /dev/null +++ b/examples/network/bearermonitor/main.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** 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 examples 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 <QApplication> + +#include "bearermonitor.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + BearerMonitor monitor; + monitor.show(); + + return app.exec(); +} + diff --git a/examples/network/bearermonitor/sessionwidget.cpp b/examples/network/bearermonitor/sessionwidget.cpp new file mode 100644 index 0000000..46ffb20 --- /dev/null +++ b/examples/network/bearermonitor/sessionwidget.cpp @@ -0,0 +1,177 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 "sessionwidget.h" +#include "qnetworkconfigmanager.h" + +SessionWidget::SessionWidget(const QNetworkConfiguration &config, QWidget *parent) +: QWidget(parent), statsTimer(-1) +{ + setupUi(this); + + session = new QNetworkSession(config, this); + + connect(session, SIGNAL(stateChanged(QNetworkSession::State)), + this, SLOT(updateSession())); + connect(session, SIGNAL(error(QNetworkSession::SessionError)), + this, SLOT(updateSession())); + + updateSession(); + + sessionId->setText(QString("0x%1").arg(qulonglong(session), 8, 16, QChar('0'))); + + configuration->setText(session->configuration().name()); + + connect(openSessionButton, SIGNAL(clicked()), + this, SLOT(openSession())); + connect(openSyncSessionButton, SIGNAL(clicked()), + this, SLOT(openSyncSession())); + connect(closeSessionButton, SIGNAL(clicked()), + this, SLOT(closeSession())); + connect(stopSessionButton, SIGNAL(clicked()), + this, SLOT(stopSession())); +} + +SessionWidget::~SessionWidget() +{ + delete session; +} + +void SessionWidget::timerEvent(QTimerEvent *e) +{ + if (e->timerId() == statsTimer) { + rxData->setText(QString::number(session->bytesReceived())); + txData->setText(QString::number(session->bytesWritten())); + activeTime->setText(QString::number(session->activeTime())); + } +} + +void SessionWidget::updateSession() +{ + updateSessionState(session->state()); + updateSessionError(session->error()); + + if (session->state() == QNetworkSession::Connected) + statsTimer = startTimer(1000); + else + killTimer(statsTimer); + + if (session->configuration().type() == QNetworkConfiguration::InternetAccessPoint) + bearer->setText(session->configuration().bearerName()); + else { + QNetworkConfigurationManager mgr; + QNetworkConfiguration c = mgr.configurationFromIdentifier(session->sessionProperty("ActiveConfiguration").toString()); + bearer->setText(c.bearerName()); + } + + interfaceName->setText(session->interface().humanReadableName()); + interfaceGuid->setText(session->interface().name()); +} + +void SessionWidget::openSession() +{ + session->open(); + updateSession(); +} + +void SessionWidget::openSyncSession() +{ + session->open(); + session->waitForOpened(); + updateSession(); +} + +void SessionWidget::closeSession() +{ + session->close(); + updateSession(); +} + +void SessionWidget::stopSession() +{ + session->stop(); + updateSession(); +} + +void SessionWidget::updateSessionState(QNetworkSession::State state) +{ + QString s = tr("%1 (%2)"); + + switch (state) { + case QNetworkSession::Invalid: + s = s.arg(tr("Invalid")); + break; + case QNetworkSession::NotAvailable: + s = s.arg(tr("Not Available")); + break; + case QNetworkSession::Connecting: + s = s.arg(tr("Connecting")); + break; + case QNetworkSession::Connected: + s = s.arg(tr("Connected")); + break; + case QNetworkSession::Closing: + s = s.arg(tr("Closing")); + break; + case QNetworkSession::Disconnected: + s = s.arg(tr("Disconnected")); + break; + case QNetworkSession::Roaming: + s = s.arg(tr("Roaming")); + break; + default: + s = s.arg(tr("Unknown")); + } + + if (session->isOpen()) + s = s.arg(tr("Open")); + else + s = s.arg(tr("Closed")); + + sessionState->setText(s); +} + +void SessionWidget::updateSessionError(QNetworkSession::SessionError error) +{ + lastError->setText(QString::number(error)); + errorString->setText(session->errorString()); +} + diff --git a/examples/network/bearermonitor/sessionwidget.h b/examples/network/bearermonitor/sessionwidget.h new file mode 100644 index 0000000..cc9c067 --- /dev/null +++ b/examples/network/bearermonitor/sessionwidget.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples 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 SESSIONWIDGET_H +#define SESSIONWIDGET_H + +#include "ui_sessionwidget.h" + +#include <qnetworksession.h> + +QT_USE_NAMESPACE + +class SessionWidget : public QWidget, public Ui_SessionWidget +{ + Q_OBJECT + +public: + SessionWidget(const QNetworkConfiguration &config, QWidget *parent = 0); + ~SessionWidget(); + + void timerEvent(QTimerEvent *); + +private: + void updateSessionState(QNetworkSession::State state); + void updateSessionError(QNetworkSession::SessionError error); + +private Q_SLOTS: + void openSession(); + void openSyncSession(); + void closeSession(); + void stopSession(); + void updateSession(); + +private: + QNetworkSession *session; + int statsTimer; +}; + +#endif + diff --git a/examples/network/bearermonitor/sessionwidget.ui b/examples/network/bearermonitor/sessionwidget.ui new file mode 100644 index 0000000..45135f5 --- /dev/null +++ b/examples/network/bearermonitor/sessionwidget.ui @@ -0,0 +1,307 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>SessionWidget</class> + <widget class="QWidget" name="SessionWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>340</width> + <height>276</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QHBoxLayout" name="sessionIdLayout"> + <item> + <widget class="QLabel" name="sessionIdLabel"> + <property name="text"> + <string>Session ID:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="sessionId"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="sessionStateLayout"> + <item> + <widget class="QLabel" name="sessionStateLabel"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Session State:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="sessionState"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Invalid</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="configurationLayout"> + <item> + <widget class="QLabel" name="configurationLabel"> + <property name="text"> + <string>Configuration:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="configuration"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="bearerLayout"> + <item> + <widget class="QLabel" name="bearerLabel"> + <property name="text"> + <string>Bearer:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="bearer"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="interfaceNameLayout"> + <item> + <widget class="QLabel" name="interfaceNameLabel"> + <property name="text"> + <string>Interface Name:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="interfaceName"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="interfaceGuidLayout"> + <item> + <widget class="QLabel" name="interfaceGuidLabel"> + <property name="text"> + <string>Interface GUID:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="interfaceGuid"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="lastErrorLayout"> + <item> + <widget class="QLabel" name="lastErrorLabel"> + <property name="text"> + <string>Last Error:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="lastError"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="errorStringLayout"> + <item> + <widget class="QLabel" name="errorStringLabel"> + <property name="text"> + <string>Error String</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="errorString"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QLabel" name="rxData"> + <property name="text"> + <string>0</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="txData"> + <property name="text"> + <string>0</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_4"> + <item> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Active Time:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="activeTime"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>0 seconds</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QPushButton" name="openSessionButton"> + <property name="text"> + <string>Open</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="openSyncSessionButton"> + <property name="text"> + <string>Blocking Open</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QPushButton" name="closeSessionButton"> + <property name="text"> + <string>Close</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="stopSessionButton"> + <property name="text"> + <string>Stop</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> 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 |