summaryrefslogtreecommitdiffstats
path: root/examples/network/bearercloud
diff options
context:
space:
mode:
authorAaron McCarthy <aaron.mccarthy@nokia.com>2009-12-22 02:17:58 (GMT)
committerAaron McCarthy <aaron.mccarthy@nokia.com>2009-12-22 03:53:28 (GMT)
commit0f31f63e11d4fcb2b399979de28368a89275b911 (patch)
tree81cd495848d4bc5e576350fc1f1a3c044d93a2da /examples/network/bearercloud
parentc2c31f30830a4e1e455a13321dd7bae6ac8b360f (diff)
downloadQt-0f31f63e11d4fcb2b399979de28368a89275b911.zip
Qt-0f31f63e11d4fcb2b399979de28368a89275b911.tar.gz
Qt-0f31f63e11d4fcb2b399979de28368a89275b911.tar.bz2
Bearer Management Integration 1.
Diffstat (limited to 'examples/network/bearercloud')
-rw-r--r--examples/network/bearercloud/bearercloud.cpp197
-rw-r--r--examples/network/bearercloud/bearercloud.h81
-rw-r--r--examples/network/bearercloud/bearercloud.pro30
-rw-r--r--examples/network/bearercloud/cloud.cpp361
-rw-r--r--examples/network/bearercloud/cloud.h97
-rw-r--r--examples/network/bearercloud/icons.qrc7
-rw-r--r--examples/network/bearercloud/lan.svg76
-rw-r--r--examples/network/bearercloud/main.cpp89
-rw-r--r--examples/network/bearercloud/unknown.svg76
-rw-r--r--examples/network/bearercloud/wlan.svg151
10 files changed, 1165 insertions, 0 deletions
diff --git a/examples/network/bearercloud/bearercloud.cpp b/examples/network/bearercloud/bearercloud.cpp
new file mode 100644
index 0000000..182d4ec
--- /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 Qt Mobility Components.
+**
+** $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..c18ffd3
--- /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 Qt Mobility Components.
+**
+** $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>
+
+QTM_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..308ddda
--- /dev/null
+++ b/examples/network/bearercloud/bearercloud.pro
@@ -0,0 +1,30 @@
+HEADERS = bearercloud.h \
+ cloud.h
+
+SOURCES = main.cpp \
+ bearercloud.cpp \
+ cloud.cpp
+
+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.cpp b/examples/network/bearercloud/cloud.cpp
new file mode 100644
index 0000000..4a1bde7
--- /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 Qt Mobility Components.
+**
+** $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->isActive())
+ 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 = session->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->isActive())
+ s = s.arg(tr("Active"));
+ else
+ s = s.arg(tr("Inactive"));
+
+ 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 = session->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..4ce43df
--- /dev/null
+++ b/examples/network/bearercloud/cloud.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** 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 Qt Mobility Components.
+**
+** $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>
+QTM_USE_NAMESPACE
+
+class QGraphicsTextItem;
+class QGraphicsSvgItem;
+
+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..33c55e9
--- /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 Qt Mobility Components.
+**
+** $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>