diff options
author | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2010-07-07 06:28:45 (GMT) |
---|---|---|
committer | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2010-07-19 00:32:33 (GMT) |
commit | 75db37022a9fd479e2a446b57e774eaf8e3e73ea (patch) | |
tree | c00dffdb4fe9f38aba2385ff686c2d16b2cae2e3 /examples/network/fortuneserver | |
parent | 192a3c6d69b42f02aa9033c30502a6930cceb8f7 (diff) | |
download | Qt-75db37022a9fd479e2a446b57e774eaf8e3e73ea.zip Qt-75db37022a9fd479e2a446b57e774eaf8e3e73ea.tar.gz Qt-75db37022a9fd479e2a446b57e774eaf8e3e73ea.tar.bz2 |
Convert examples and demos to use Bearer Management.
Task-number: QTBUG-10439
Diffstat (limited to 'examples/network/fortuneserver')
-rw-r--r-- | examples/network/fortuneserver/fortuneserver.pro | 2 | ||||
-rw-r--r-- | examples/network/fortuneserver/main.cpp | 7 | ||||
-rw-r--r-- | examples/network/fortuneserver/server.cpp | 96 | ||||
-rw-r--r-- | examples/network/fortuneserver/server.h | 3 |
4 files changed, 71 insertions, 37 deletions
diff --git a/examples/network/fortuneserver/fortuneserver.pro b/examples/network/fortuneserver/fortuneserver.pro index 474ec11..e13f309 100644 --- a/examples/network/fortuneserver/fortuneserver.pro +++ b/examples/network/fortuneserver/fortuneserver.pro @@ -12,8 +12,6 @@ INSTALLS += target sources symbian { TARGET.UID3 = 0xA000CF71 include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) - INCLUDEPATH += $$QT_SOURCE_TREE/examples/network/qftp/ - LIBS += -lesock -lcommdb -linsock # For IAP selection TARGET.CAPABILITY = "NetworkServices ReadUserData" TARGET.EPOCHEAPSIZE = 0x20000 0x2000000 } diff --git a/examples/network/fortuneserver/main.cpp b/examples/network/fortuneserver/main.cpp index 29fe777..53149c0 100644 --- a/examples/network/fortuneserver/main.cpp +++ b/examples/network/fortuneserver/main.cpp @@ -45,15 +45,8 @@ #include "server.h" -#ifdef Q_OS_SYMBIAN -#include "sym_iap_util.h" -#endif - int main(int argc, char *argv[]) { -#ifdef Q_OS_SYMBIAN - qt_SetDefaultIap(); -#endif QApplication app(argc, argv); Server server; #ifdef Q_OS_SYMBIAN diff --git a/examples/network/fortuneserver/server.cpp b/examples/network/fortuneserver/server.cpp index 98234e0..b931b96 100644 --- a/examples/network/fortuneserver/server.cpp +++ b/examples/network/fortuneserver/server.cpp @@ -46,12 +46,79 @@ #include "server.h" Server::Server(QWidget *parent) - : QDialog(parent) +: QDialog(parent), tcpServer(0), networkSession(0) { statusLabel = new QLabel; quitButton = new QPushButton(tr("Quit")); quitButton->setAutoDefault(false); + QNetworkConfigurationManager manager; + if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) { + // Get saved network configuration + QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); + settings.beginGroup(QLatin1String("QtNetwork")); + const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString(); + settings.endGroup(); + + // If the saved network configuration is not currently discovered use the system default + QNetworkConfiguration config = manager.configurationFromIdentifier(id); + if ((config.state() & QNetworkConfiguration::Discovered) != + QNetworkConfiguration::Discovered) { + config = manager.defaultConfiguration(); + } + + networkSession = new QNetworkSession(config, this); + connect(networkSession, SIGNAL(opened()), this, SLOT(sessionOpened())); + + statusLabel->setText(tr("Opening network session.")); + networkSession->open(); + } else { + sessionOpened(); + } + + //! [2] + fortunes << tr("You've been leading a dog's life. Stay off the furniture.") + << tr("You've got to think about tomorrow.") + << tr("You will be surprised by a loud noise.") + << tr("You will feel hungry again in another hour.") + << tr("You might have mail.") + << tr("You cannot kill time without injuring eternity.") + << tr("Computers are not intelligent. They only think they are."); + //! [2] + + connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); + //! [3] + connect(tcpServer, SIGNAL(newConnection()), this, SLOT(sendFortune())); + //! [3] + + QHBoxLayout *buttonLayout = new QHBoxLayout; + buttonLayout->addStretch(1); + buttonLayout->addWidget(quitButton); + buttonLayout->addStretch(1); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(statusLabel); + mainLayout->addLayout(buttonLayout); + setLayout(mainLayout); + + setWindowTitle(tr("Fortune Server")); +} + +void Server::sessionOpened() +{ + // Save the used configuration + QNetworkConfiguration config = networkSession->configuration(); + QString id; + if (config.type() == QNetworkConfiguration::UserChoice) + id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString(); + else + id = config.identifier(); + + QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); + settings.beginGroup(QLatin1String("QtNetwork")); + settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); + settings.endGroup(); + //! [0] //! [1] tcpServer = new QTcpServer(this); if (!tcpServer->listen()) { @@ -79,33 +146,6 @@ Server::Server(QWidget *parent) "Run the Fortune Client example now.") .arg(ipAddress).arg(tcpServer->serverPort())); //! [1] - -//! [2] - fortunes << tr("You've been leading a dog's life. Stay off the furniture.") - << tr("You've got to think about tomorrow.") - << tr("You will be surprised by a loud noise.") - << tr("You will feel hungry again in another hour.") - << tr("You might have mail.") - << tr("You cannot kill time without injuring eternity.") - << tr("Computers are not intelligent. They only think they are."); -//! [2] - - connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); -//! [3] - connect(tcpServer, SIGNAL(newConnection()), this, SLOT(sendFortune())); -//! [3] - - QHBoxLayout *buttonLayout = new QHBoxLayout; - buttonLayout->addStretch(1); - buttonLayout->addWidget(quitButton); - buttonLayout->addStretch(1); - - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addWidget(statusLabel); - mainLayout->addLayout(buttonLayout); - setLayout(mainLayout); - - setWindowTitle(tr("Fortune Server")); } //! [4] diff --git a/examples/network/fortuneserver/server.h b/examples/network/fortuneserver/server.h index 2d8d116..9d9ef62 100644 --- a/examples/network/fortuneserver/server.h +++ b/examples/network/fortuneserver/server.h @@ -47,6 +47,7 @@ QT_BEGIN_NAMESPACE class QLabel; class QPushButton; class QTcpServer; +class QNetworkSession; QT_END_NAMESPACE //! [0] @@ -58,6 +59,7 @@ public: Server(QWidget *parent = 0); private slots: + void sessionOpened(); void sendFortune(); private: @@ -65,6 +67,7 @@ private: QPushButton *quitButton; QTcpServer *tcpServer; QStringList fortunes; + QNetworkSession *networkSession; }; //! [0] |