From 38be0d13830efd2d98281c645c3a60afe05ffece Mon Sep 17 00:00:00 2001 From: Qt by Nokia Date: Wed, 27 Apr 2011 12:05:43 +0200 Subject: Initial import from the monolithic Qt. This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12 --- examples/network/bearermonitor/bearermonitor.cpp | 423 +++++++++++++++++++++ examples/network/bearermonitor/bearermonitor.h | 94 +++++ examples/network/bearermonitor/bearermonitor.pro | 26 ++ .../network/bearermonitor/bearermonitor_240_320.ui | 420 ++++++++++++++++++++ .../network/bearermonitor/bearermonitor_640_480.ui | 386 +++++++++++++++++++ .../network/bearermonitor/bearermonitor_maemo.ui | 369 ++++++++++++++++++ examples/network/bearermonitor/main.cpp | 59 +++ examples/network/bearermonitor/sessionwidget.cpp | 204 ++++++++++ examples/network/bearermonitor/sessionwidget.h | 86 +++++ examples/network/bearermonitor/sessionwidget.ui | 307 +++++++++++++++ .../network/bearermonitor/sessionwidget_maemo.ui | 310 +++++++++++++++ 11 files changed, 2684 insertions(+) create mode 100644 examples/network/bearermonitor/bearermonitor.cpp create mode 100644 examples/network/bearermonitor/bearermonitor.h create mode 100644 examples/network/bearermonitor/bearermonitor.pro create mode 100644 examples/network/bearermonitor/bearermonitor_240_320.ui create mode 100644 examples/network/bearermonitor/bearermonitor_640_480.ui create mode 100644 examples/network/bearermonitor/bearermonitor_maemo.ui create mode 100644 examples/network/bearermonitor/main.cpp create mode 100644 examples/network/bearermonitor/sessionwidget.cpp create mode 100644 examples/network/bearermonitor/sessionwidget.h create mode 100644 examples/network/bearermonitor/sessionwidget.ui create mode 100644 examples/network/bearermonitor/sessionwidget_maemo.ui (limited to 'examples/network/bearermonitor') diff --git a/examples/network/bearermonitor/bearermonitor.cpp b/examples/network/bearermonitor/bearermonitor.cpp new file mode 100644 index 0000000000..942b19ce01 --- /dev/null +++ b/examples/network/bearermonitor/bearermonitor.cpp @@ -0,0 +1,423 @@ +/**************************************************************************** +** +** Copyright (C) 2011 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "bearermonitor.h" +#include "sessionwidget.h" + +#include + +#ifdef Q_OS_WIN +#include +#undef interface + +#ifndef NS_NLA +#define NS_NLA 15 +#endif +#endif + +BearerMonitor::BearerMonitor(QWidget *parent) +: QWidget(parent) +{ + setupUi(this); +#ifdef MAEMO_UI + newSessionButton->hide(); + deleteSessionButton->hide(); +#else + delete tabWidget->currentWidget(); + sessionGroup->hide(); +#endif +#if defined(Q_OS_SYMBIAN) || defined(Q_OS_WINCE) || defined(MAEMO_UI) + 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(onlineStateChanged(bool)), this ,SLOT(onlineStateChanged(bool))); + 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())); + +#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())); +#ifndef MAEMO_UI + connect(deleteSessionButton, SIGNAL(clicked()), + this, SLOT(deleteSession())); +#endif + connect(scanButton, SIGNAL(clicked()), + this, SLOT(performScan())); + + // Just in case update all configurations so that all + // configurations are up to date. + manager.updateConfigurations(); +} + +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 itemMap; + foreach (QTreeWidgetItem *item, parent->takeChildren()) + itemMap.insert(item->data(0, Qt::UserRole).toString(), item); + + QList allConfigurations = snap.children(); + + while (!allConfigurations.isEmpty()) { + QNetworkConfiguration config = allConfigurations.takeFirst(); + + QTreeWidgetItem *item = itemMap.take(config.identifier()); + if (item) { + updateItem(item, config); + + parent->addChild(item); + + if (config.type() == QNetworkConfiguration::ServiceNetwork) + updateSnapConfiguration(item, config); + } else { + configurationAdded(config, parent); + } + } + + qDeleteAll(itemMap); +} + +void BearerMonitor::updateConfigurations() +{ + progressBar->hide(); + scanButton->show(); + + // Just in case update online state, on Symbian platform + // WLAN scan needs to be triggered initially to have their true state. + onlineStateChanged(manager.isOnline()); + + QList items = treeWidget->findItems(QLatin1String("*"), Qt::MatchWildcard); + QMap itemMap; + while (!items.isEmpty()) { + QTreeWidgetItem *item = items.takeFirst(); + itemMap.insert(item->data(0, Qt::UserRole).toString(), item); + } + + QNetworkConfiguration defaultConfiguration = manager.defaultConfiguration(); + QTreeWidgetItem *defaultItem = itemMap.take(defaultConfiguration.identifier()); + + if (defaultItem) { + updateItem(defaultItem, defaultConfiguration); + + if (defaultConfiguration.type() == QNetworkConfiguration::ServiceNetwork) + updateSnapConfiguration(defaultItem, defaultConfiguration); + } else if (defaultConfiguration.isValid()) { + configurationAdded(defaultConfiguration); + } + + QList allConfigurations = manager.allConfigurations(); + + while (!allConfigurations.isEmpty()) { + QNetworkConfiguration config = allConfigurations.takeFirst(); + + if (config.identifier() == defaultConfiguration.identifier()) + continue; + + QTreeWidgetItem *item = itemMap.take(config.identifier()); + if (item) { + updateItem(item, config); + + if (config.type() == QNetworkConfiguration::ServiceNetwork) + updateSnapConfiguration(item, config); + } else { + configurationAdded(config); + } + } + + qDeleteAll(itemMap); +} + +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(); + if (!item) return; + + 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(); + if (!item) return; + + 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()); + +#ifndef MAEMO_UI + sessionGroup->show(); +#endif + + sessionWidgets.append(session); +} + +void BearerMonitor::createNewSession() +{ + QTreeWidgetItem *item = treeWidget->currentItem(); + if (!item) return; + + createSessionFor(item); +} + +#ifndef MAEMO_UI +void BearerMonitor::deleteSession() +{ + SessionWidget *session = qobject_cast(tabWidget->currentWidget()); + if (session) { + sessionWidgets.removeAll(session); + + delete session; + + if (tabWidget->count() == 0) + sessionGroup->hide(); + } +} +#endif + +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 0000000000..a06522fafa --- /dev/null +++ b/examples/network/bearermonitor/bearermonitor.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2011 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BEARERMONITOR_H +#define BEARERMONITOR_H + +#include +#include +#if defined (Q_OS_SYMBIAN) || defined(Q_OS_WINCE) +#include "ui_bearermonitor_240_320.h" +#elif defined(MAEMO_UI) +#include "ui_bearermonitor_maemo.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(); +#ifndef MAEMO_UI + void deleteSession(); +#endif + void performScan(); + +private: + QNetworkConfigurationManager manager; + QList sessionWidgets; +}; + +#endif //BEARERMONITOR_H diff --git a/examples/network/bearermonitor/bearermonitor.pro b/examples/network/bearermonitor/bearermonitor.pro new file mode 100644 index 0000000000..bd9bd68e5c --- /dev/null +++ b/examples/network/bearermonitor/bearermonitor.pro @@ -0,0 +1,26 @@ +TARGET = bearermonitor +QT = core gui network + +HEADERS = sessionwidget.h \ + bearermonitor.h + +SOURCES = main.cpp \ + bearermonitor.cpp \ + sessionwidget.cpp + +maemo5|maemo6|linux-g++-maemo { + DEFINES += MAEMO_UI + FORMS = bearermonitor_maemo.ui \ + sessionwidget_maemo.ui +} else { + FORMS = bearermonitor_240_320.ui \ + bearermonitor_640_480.ui \ + sessionwidget.ui +} + +win32:!wince*:LIBS += -lws2_32 +wince*: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 0000000000..93cfc5e0e3 --- /dev/null +++ b/examples/network/bearermonitor/bearermonitor_240_320.ui @@ -0,0 +1,420 @@ + + + BearerMonitor + + + + 0 + 0 + 240 + 320 + + + + BearerMonitor + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + true + + + + + 0 + -274 + 206 + 576 + + + + + + + System State + + + true + + + + 0 + + + 0 + + + 0 + + + + + + + Online State: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + + Configurations + + + true + + + + 0 + + + 0 + + + 0 + + + + + + + + + Name: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + State: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Type: + + + + + + + + 0 + 0 + + + + Invalid + + + + + + + + + + + Purpose: + + + + + + + + 0 + 0 + + + + Unknown + + + + + + + + + + + Identifier: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Roaming: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Children: + + + + + + + + 0 + 0 + + + + + + + + + + + + + Network Location Awareness + + + + + + Register + + + + + + + Unregister + + + + + + + + + + New Session + + + + + + + Delete Session + + + + + + + Scan + + + + + + + 0 + + + -1 + + + false + + + false + + + %p% + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 0 + 0 + + + + Qt::ScrollBarAlwaysOff + + + false + + + + 1 + + + + + + + + + + + + + Sessions + + + true + + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + 0 + + + + Session 1 + + + + + + + + + + + + + + + + diff --git a/examples/network/bearermonitor/bearermonitor_640_480.ui b/examples/network/bearermonitor/bearermonitor_640_480.ui new file mode 100644 index 0000000000..52866bc9cd --- /dev/null +++ b/examples/network/bearermonitor/bearermonitor_640_480.ui @@ -0,0 +1,386 @@ + + + BearerMonitor + + + + 0 + 0 + 640 + 515 + + + + BearerMonitor + + + + + + System State + + + true + + + + 0 + + + 0 + + + 0 + + + + + + + Online State: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + + Configurations + + + true + + + + 0 + + + 0 + + + 0 + + + + + false + + + + 1 + + + + + + + + + + + + Name: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + State: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Type: + + + + + + + + 0 + 0 + + + + Invalid + + + + + + + + + + + Purpose: + + + + + + + + 0 + 0 + + + + Unknown + + + + + + + + + + + Identifier: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Roaming: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Children: + + + + + + + + 0 + 0 + + + + + + + + + + + + + Network Location Awareness + + + + + + Register + + + + + + + Unregister + + + + + + + + + + New Session + + + + + + + Delete Session + + + + + + + Scan + + + + + + + 0 + + + -1 + + + false + + + false + + + %p% + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + Sessions + + + true + + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + 0 + + + + Session 1 + + + + + + + + + + + + diff --git a/examples/network/bearermonitor/bearermonitor_maemo.ui b/examples/network/bearermonitor/bearermonitor_maemo.ui new file mode 100644 index 0000000000..9c72bfd5b1 --- /dev/null +++ b/examples/network/bearermonitor/bearermonitor_maemo.ui @@ -0,0 +1,369 @@ + + + BearerMonitor + + + + 0 + 0 + 612 + 555 + + + + BearerMonitor + + + + + + System State + + + true + + + + 0 + + + + + Online State: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + Configurations && Sessions + + + true + + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + 0 + + + false + + + + Configurations + + + + + + + 0 + 0 + + + + false + + + false + + + + 1 + + + + + + + + + + + + Name: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + State: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Type: + + + + + + + + 0 + 0 + + + + Invalid + + + + + + + + + + + Purpose: + + + + + + + + 0 + 0 + + + + Unknown + + + + + + + + + + + Identifier: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Roaming: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Children: + + + + + + + + 0 + 0 + + + + + + + + + + + + + Network Location Awareness + + + + + + Register + + + + + + + Unregister + + + + + + + + + + New Session + + + + + + + Delete Session + + + + + + + Scan + + + + + + + 0 + + + 23280 + + + false + + + false + + + %p% + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + + + diff --git a/examples/network/bearermonitor/main.cpp b/examples/network/bearermonitor/main.cpp new file mode 100644 index 0000000000..1358033fc2 --- /dev/null +++ b/examples/network/bearermonitor/main.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2011 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include "bearermonitor.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + QMainWindow mainWindow; + + BearerMonitor monitor; + + mainWindow.setCentralWidget(&monitor); + mainWindow.show(); + + return app.exec(); +} + diff --git a/examples/network/bearermonitor/sessionwidget.cpp b/examples/network/bearermonitor/sessionwidget.cpp new file mode 100644 index 0000000000..eed3660ca0 --- /dev/null +++ b/examples/network/bearermonitor/sessionwidget.cpp @@ -0,0 +1,204 @@ +/**************************************************************************** +** +** Copyright (C) 2011 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sessionwidget.h" +#include "qnetworkconfigmanager.h" + +SessionWidget::SessionWidget(const QNetworkConfiguration &config, QWidget *parent) +: QWidget(parent), statsTimer(-1) +{ + setupUi(this); + +#ifdef QT_NO_NETWORKINTERFACE + interfaceName->setVisible(false); + interfaceNameLabel->setVisible(false); + interfaceGuid->setVisible(false); + interfaceGuidLabel->setVisible(false); +#endif + + session = new QNetworkSession(config, this); + + connect(session, SIGNAL(stateChanged(QNetworkSession::State)), + this, SLOT(updateSession())); + connect(session, SIGNAL(error(QNetworkSession::SessionError)), + this, SLOT(updateSessionError(QNetworkSession::SessionError))); + + 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())); +#ifdef MAEMO_UI + connect(deleteSessionButton, SIGNAL(clicked()), + this, SLOT(deleteSession())); +#endif +} + +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())); + } +} + +#ifdef MAEMO_UI +void SessionWidget::deleteSession() +{ + delete this; +} +#endif + +void SessionWidget::updateSession() +{ + updateSessionState(session->state()); + + if (session->state() == QNetworkSession::Connected) + statsTimer = startTimer(1000); + else if (statsTimer != -1) + killTimer(statsTimer); + + if (session->configuration().type() == QNetworkConfiguration::InternetAccessPoint) + bearer->setText(session->configuration().bearerTypeName()); + else { + QNetworkConfigurationManager mgr; + QNetworkConfiguration c = mgr.configurationFromIdentifier(session->sessionProperty("ActiveConfiguration").toString()); + bearer->setText(c.bearerTypeName()); + } + +#ifndef QT_NO_NETWORKINTERFACE + interfaceName->setText(session->interface().humanReadableName()); + interfaceGuid->setText(session->interface().name()); +#endif +} + +void SessionWidget::openSession() +{ + clearError(); + session->open(); + updateSession(); +} + +void SessionWidget::openSyncSession() +{ + clearError(); + session->open(); + session->waitForOpened(); + updateSession(); +} + +void SessionWidget::closeSession() +{ + clearError(); + session->close(); + updateSession(); +} + +void SessionWidget::stopSession() +{ + clearError(); + 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()); +} + +void SessionWidget::clearError() +{ + lastError->clear(); + errorString->clear(); +} diff --git a/examples/network/bearermonitor/sessionwidget.h b/examples/network/bearermonitor/sessionwidget.h new file mode 100644 index 0000000000..4b14993082 --- /dev/null +++ b/examples/network/bearermonitor/sessionwidget.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2011 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:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SESSIONWIDGET_H +#define SESSIONWIDGET_H + +#include + +#ifdef MAEMO_UI +#include "ui_sessionwidget_maemo.h" +#else +#include "ui_sessionwidget.h" +#endif + +QT_USE_NAMESPACE + +class SessionWidget : public QWidget, public Ui_SessionWidget +{ + Q_OBJECT + +public: + explicit SessionWidget(const QNetworkConfiguration &config, QWidget *parent = 0); + ~SessionWidget(); + + void timerEvent(QTimerEvent *); + +private: + void updateSessionState(QNetworkSession::State state); + void clearError(); + +private Q_SLOTS: + void openSession(); + void openSyncSession(); + void closeSession(); + void stopSession(); + void updateSession(); + void updateSessionError(QNetworkSession::SessionError error); +#ifdef MAEMO_UI + void deleteSession(); +#endif + + +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 0000000000..4199109ce3 --- /dev/null +++ b/examples/network/bearermonitor/sessionwidget.ui @@ -0,0 +1,307 @@ + + + SessionWidget + + + + 0 + 0 + 340 + 276 + + + + Session Details + + + + + + + + + + Session ID: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + + 0 + 0 + + + + Session State: + + + + + + + + 0 + 0 + + + + Invalid + + + + + + + + + + + Configuration: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Bearer: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Interface Name: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Interface GUID: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Last Error: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Error String: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + 0 + + + Qt::AlignCenter + + + + + + + 0 + + + Qt::AlignCenter + + + + + + + + + + + Active Time: + + + + + + + + 0 + 0 + + + + 0 seconds + + + + + + + + + + + Open + + + + + + + Blocking Open + + + + + + + + + + + Close + + + + + + + Stop + + + + + + + + + + + + diff --git a/examples/network/bearermonitor/sessionwidget_maemo.ui b/examples/network/bearermonitor/sessionwidget_maemo.ui new file mode 100644 index 0000000000..8867509d01 --- /dev/null +++ b/examples/network/bearermonitor/sessionwidget_maemo.ui @@ -0,0 +1,310 @@ + + + SessionWidget + + + + 0 + 0 + 497 + 615 + + + + Session Details + + + + + + + + + + Session ID: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + + 0 + 0 + + + + Session State: + + + + + + + + 0 + 0 + + + + Invalid + + + + + + + + + + + Configuration: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Bearer: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Interface Name: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Interface GUID: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Last Error: + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + Error String + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + 0 + + + Qt::AlignCenter + + + + + + + 0 + + + Qt::AlignCenter + + + + + + + + + + + Active Time: + + + + + + + + 0 + 0 + + + + 0 seconds + + + + + + + + + + + + + Open + + + + + + + Close + + + + + + + Blocking Open + + + + + + + Stop + + + + + + + Delete + + + + + + + + + + -- cgit v1.2.3