summaryrefslogtreecommitdiffstats
path: root/examples/network/fortuneclient
diff options
context:
space:
mode:
Diffstat (limited to 'examples/network/fortuneclient')
-rw-r--r--examples/network/fortuneclient/client.cpp65
-rw-r--r--examples/network/fortuneclient/client.h7
-rw-r--r--examples/network/fortuneclient/fortuneclient.pro2
3 files changed, 53 insertions, 21 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();
+}
+
diff --git a/examples/network/fortuneclient/client.h b/examples/network/fortuneclient/client.h
index 50a9037..d0c0718 100644
--- a/examples/network/fortuneclient/client.h
+++ b/examples/network/fortuneclient/client.h
@@ -50,6 +50,7 @@ class QLabel;
class QLineEdit;
class QPushButton;
class QTcpSocket;
+class QNetworkSession;
QT_END_NAMESPACE
//! [0]
@@ -65,6 +66,7 @@ private slots:
void readFortune();
void displayError(QAbstractSocket::SocketError socketError);
void enableGetFortuneButton();
+ void sessionOpened();
private:
QLabel *hostLabel;
@@ -79,9 +81,8 @@ private:
QTcpSocket *tcpSocket;
QString currentFortune;
quint16 blockSize;
-#ifdef Q_OS_SYMBIAN
- bool isDefaultIapSet;
-#endif
+
+ QNetworkSession *networkSession;
};
//! [0]
diff --git a/examples/network/fortuneclient/fortuneclient.pro b/examples/network/fortuneclient/fortuneclient.pro
index edbf14d..f79679d 100644
--- a/examples/network/fortuneclient/fortuneclient.pro
+++ b/examples/network/fortuneclient/fortuneclient.pro
@@ -11,8 +11,6 @@ INSTALLS += target sources
symbian {
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 WriteUserData"
TARGET.EPOCHEAPSIZE = 0x20000 0x2000000
}