summaryrefslogtreecommitdiffstats
path: root/examples/network/fortuneclient/client.cpp
diff options
context:
space:
mode:
authorJørgen Lind <jorgen.lind@nokia.com>2010-08-03 10:53:57 (GMT)
committerJørgen Lind <jorgen.lind@nokia.com>2010-08-03 10:53:57 (GMT)
commitd5491ecdde14659a913c9f476f18c45f1d9489bb (patch)
tree06cc52249feda9bd9e50ca47abb8ebd676c8a309 /examples/network/fortuneclient/client.cpp
parent42cdfaf86d34afeb6448723839fef70fe477deed (diff)
parenta41128af5373a0225c3548abd3eb82cd7e8f7a0e (diff)
downloadQt-d5491ecdde14659a913c9f476f18c45f1d9489bb.zip
Qt-d5491ecdde14659a913c9f476f18c45f1d9489bb.tar.gz
Qt-d5491ecdde14659a913c9f476f18c45f1d9489bb.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt into lighthouse
Conflicts: configure
Diffstat (limited to 'examples/network/fortuneclient/client.cpp')
-rw-r--r--examples/network/fortuneclient/client.cpp65
1 files changed, 49 insertions, 16 deletions
diff --git a/examples/network/fortuneclient/client.cpp b/examples/network/fortuneclient/client.cpp
index b9a85c4..fe35906 100644
--- a/examples/network/fortuneclient/client.cpp
+++ b/examples/network/fortuneclient/client.cpp
@@ -43,13 +43,9 @@
#include "client.h"
-#ifdef Q_OS_SYMBIAN
-#include "sym_iap_util.h"
-#endif
-
//! [0]
Client::Client(QWidget *parent)
- : QDialog(parent)
+: QDialog(parent), networkSession(0)
{
//! [0]
hostLabel = new QLabel(tr("&Server name:"));
@@ -121,9 +117,28 @@ Client::Client(QWidget *parent)
setWindowTitle(tr("Fortune Client"));
portLineEdit->setFocus();
-#ifdef Q_OS_SYMBIAN
- isDefaultIapSet = false;
-#endif
+ 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()));
+
+ getFortuneButton->setEnabled(false);
+ statusLabel->setText(tr("Opening network session."));
+ networkSession->open();
+ }
//! [5]
}
//! [5]
@@ -132,12 +147,6 @@ Client::Client(QWidget *parent)
void Client::requestNewFortune()
{
getFortuneButton->setEnabled(false);
-#ifdef Q_OS_SYMBIAN
- if(!isDefaultIapSet) {
- qt_SetDefaultIap();
- isDefaultIapSet = true;
- }
-#endif
blockSize = 0;
tcpSocket->abort();
//! [7]
@@ -214,6 +223,30 @@ void Client::displayError(QAbstractSocket::SocketError socketError)
void Client::enableGetFortuneButton()
{
- getFortuneButton->setEnabled(!hostLineEdit->text().isEmpty()
- && !portLineEdit->text().isEmpty());
+ getFortuneButton->setEnabled((!networkSession || networkSession->isOpen()) &&
+ !hostLineEdit->text().isEmpty() &&
+ !portLineEdit->text().isEmpty());
+
}
+
+void Client::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();
+
+ statusLabel->setText(tr("This examples requires that you run the "
+ "Fortune Server example as well."));
+
+ enableGetFortuneButton();
+}
+