diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/manual/bearerex/bearerex.cpp | 90 | ||||
-rw-r--r-- | tests/manual/bearerex/bearerex.h | 15 | ||||
-rw-r--r-- | tests/manual/bearerex/bearerex.pro | 6 | ||||
-rw-r--r-- | tests/manual/bearerex/sessiondialog.ui | 168 |
4 files changed, 174 insertions, 105 deletions
diff --git a/tests/manual/bearerex/bearerex.cpp b/tests/manual/bearerex/bearerex.cpp index bf60dd1..00cb481 100644 --- a/tests/manual/bearerex/bearerex.cpp +++ b/tests/manual/bearerex/bearerex.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -40,6 +40,7 @@ ****************************************************************************/ #include "bearerex.h" +#include "datatransferer.h" #include <QtNetwork> @@ -261,8 +262,8 @@ SessionTab::SessionTab(QNetworkConfiguration* apNetworkConfiguration, QListWidget* eventListWidget, int index, BearerEx * parent) - : QWidget(parent), m_http(0), m_eventListWidget(eventListWidget), - m_index(index), m_httpRequestOngoing(false), m_alrEnabled (false) + : QWidget(parent), m_dataTransferer(0), m_eventListWidget(eventListWidget), + m_index(index), m_alrEnabled (false) { setupUi(this); @@ -300,41 +301,46 @@ SessionTab::SessionTab(QNetworkConfiguration* apNetworkConfiguration, SessionTab::~SessionTab() { - // Need to be nulled, because modal dialogs may return after destruction of this object and - // use already released resources. - delete m_NetworkSession; - m_NetworkSession = NULL; - delete m_http; - m_http = NULL; + delete m_NetworkSession; m_NetworkSession = 0; + delete m_dataTransferer; m_dataTransferer = 0; } -void SessionTab::on_createQHttpButton_clicked() +void SessionTab::on_createQNetworkAccessManagerButton_clicked() { - if (m_httpRequestOngoing) { - return; + if (m_dataTransferer) { + disconnect(m_dataTransferer, 0, 0, 0); + delete m_dataTransferer; + m_dataTransferer = 0; } - - if (m_http) { - disconnect(m_http, 0, 0, 0); - delete m_http; + // Create new object according to current selection + QString type(comboBox->currentText()); + if (type == "QNAM") { + m_dataTransferer = new DataTransfererQNam(this); + } else if (type == "QTcpSocket") { + m_dataTransferer = new DataTransfererQTcp(this); + } else if (type == "QHttp") { + m_dataTransferer = new DataTransfererQHttp(this); + } else { + qDebug("BearerEx Warning, unknown data transfer object requested, not creating anything."); + return; } - m_http = new QHttp(this); - createQHttpButton->setText("Recreate QHttp"); - connect(m_http, SIGNAL(done(bool)), this, SLOT(done(bool))); + createQNetworkAccessManagerButton->setText("Recreate"); + connect(m_dataTransferer, SIGNAL(finished(quint32, qint64, QString)), this, SLOT(finished(quint32, qint64, QString))); } void SessionTab::on_sendRequestButton_clicked() { - if (m_http) { - QString urlstring("http://www.google.com"); - QUrl url(urlstring); - m_http->setHost(url.host(), QHttp::ConnectionModeHttp, url.port() == -1 ? 0 : url.port()); - m_http->get(urlstring); - m_httpRequestOngoing = true; + if (m_dataTransferer) { + if (!m_dataTransferer->transferData()) { + QMessageBox msgBox; + msgBox.setStandardButtons(QMessageBox::Close); + msgBox.setText("Data transfer not started. \nVery likely data transfer ongoing."); + msgBox.exec(); + } } else { QMessageBox msgBox; msgBox.setStandardButtons(QMessageBox::Close); - msgBox.setText("QHttp not created.\nCreate QHttp First."); + msgBox.setText("Data object not created.\nCreate data object first."); msgBox.exec(); } } @@ -419,7 +425,7 @@ void SessionTab::opened() listItem->setText(QString("S")+QString::number(m_index)+QString(" - ")+QString("Opened")); m_eventListWidget->addItem(listItem); - QVariant identifier = m_NetworkSession->property("ActiveConfiguration"); + QVariant identifier = m_NetworkSession->sessionProperty("ActiveConfiguration"); if (!identifier.isNull()) { QString configId = identifier.toString(); QNetworkConfiguration config = m_ConfigManager->configurationFromIdentifier(configId); @@ -429,7 +435,7 @@ void SessionTab::opened() } if (m_NetworkSession->configuration().type() == QNetworkConfiguration::UserChoice) { - QVariant identifier = m_NetworkSession->property("UserChoiceConfiguration"); + QVariant identifier = m_NetworkSession->sessionProperty("UserChoiceConfiguration"); if (!identifier.isNull()) { QString configId = identifier.toString(); QNetworkConfiguration config = m_ConfigManager->configurationFromIdentifier(configId); @@ -480,6 +486,18 @@ QString SessionTab::stateString(QNetworkSession::State state) return stateString; } +void SessionTab::on_dataObjectChanged(const QString &newObjectType) +{ + qDebug() << "BearerEx SessionTab dataObjectChanged to: " << newObjectType; + if (m_dataTransferer) { + disconnect(m_dataTransferer, 0, 0, 0); + delete m_dataTransferer; m_dataTransferer = 0; + qDebug() << "BearerEx SessionTab, previous data object deleted."; + } + createQNetworkAccessManagerButton->setText("Create"); +} + + void SessionTab::stateChanged(QNetworkSession::State state) { newState(state); @@ -491,7 +509,7 @@ void SessionTab::stateChanged(QNetworkSession::State state) void SessionTab::newState(QNetworkSession::State state) { - QVariant identifier = m_NetworkSession->property("ActiveConfiguration"); + QVariant identifier = m_NetworkSession->sessionProperty("ActiveConfiguration"); if (state == QNetworkSession::Connected && !identifier.isNull()) { QString configId = identifier.toString(); QNetworkConfiguration config = m_ConfigManager->configurationFromIdentifier(configId); @@ -542,18 +560,14 @@ void SessionTab::error(QNetworkSession::SessionError error) msgBox.exec(); } -void SessionTab::done(bool error) +void SessionTab::finished(quint32 errorCode, qint64 dataReceived, QString errorType) { - m_httpRequestOngoing = false; - QMessageBox msgBox; msgBox.setStandardButtons(QMessageBox::Close); - if (error) { - msgBox.setText("HTTP request failed."); - } else { - QString result(m_http->readAll()); - msgBox.setText(QString("HTTP request finished successfully.\nReceived ")+QString::number(result.length())+QString(" bytes.")); - } + msgBox.setText(QString("Data transfer completed. \nError code: ") + QString::number(errorCode) + + "\nError type: " + errorType + + "\nBytes received: " + + QString::number(dataReceived)); msgBox.exec(); // Check if the networksession still exists - it may have gone after returning from // the modal dialog (in the case that app has been closed, and deleting QHttp will diff --git a/tests/manual/bearerex/bearerex.h b/tests/manual/bearerex/bearerex.h index 6bcb3e5..b81d486 100644 --- a/tests/manual/bearerex/bearerex.h +++ b/tests/manual/bearerex/bearerex.h @@ -55,13 +55,16 @@ #endif #include "qnetworkconfigmanager.h" #include "qnetworksession.h" +#include "datatransferer.h" #include "xqlistwidget.h" QT_BEGIN_NAMESPACE -class QHttp; +class QNetworkAccessManager; +class QNetworkReply; QT_END_NAMESPACE class SessionTab; +class DataTransferer; QT_USE_NAMESPACE @@ -113,14 +116,15 @@ public: QString stateString(QNetworkSession::State state); private Q_SLOTS: - void on_createQHttpButton_clicked(); + void on_createQNetworkAccessManagerButton_clicked(); void on_sendRequestButton_clicked(); void on_openSessionButton_clicked(); void on_closeSessionButton_clicked(); void on_stopConnectionButton_clicked(); void on_deleteSessionButton_clicked(); + void on_dataObjectChanged(const QString& newObjectType); void on_alrButton_clicked(); - void done(bool error); + void finished(quint32 errorCode, qint64 dataReceived, QString errorType); void newConfigurationActivated(); void preferredConfigurationChanged(const QNetworkConfiguration& config, bool isSeamless); @@ -131,13 +135,14 @@ private Q_SLOTS: void error(QNetworkSession::SessionError error); private: //data - QHttp* m_http; + // QNetworkAccessManager* m_networkAccessManager; + DataTransferer* m_dataTransferer; QNetworkSession* m_NetworkSession; QNetworkConfigurationManager* m_ConfigManager; QListWidget* m_eventListWidget; QNetworkConfiguration m_config; int m_index; - bool m_httpRequestOngoing; + bool m_dataTransferOngoing; bool m_alrEnabled; }; diff --git a/tests/manual/bearerex/bearerex.pro b/tests/manual/bearerex/bearerex.pro index 7b21183..df39c85 100644 --- a/tests/manual/bearerex/bearerex.pro +++ b/tests/manual/bearerex/bearerex.pro @@ -17,10 +17,12 @@ maemo5|maemo6 { # Example headers and sources HEADERS += bearerex.h \ - xqlistwidget.h + xqlistwidget.h \ + datatransferer.h SOURCES += bearerex.cpp \ main.cpp \ - xqlistwidget.cpp + xqlistwidget.cpp \ + datatransferer.cpp symbian:TARGET.CAPABILITY = NetworkServices NetworkControl ReadUserData diff --git a/tests/manual/bearerex/sessiondialog.ui b/tests/manual/bearerex/sessiondialog.ui index fcf2136..c50af70 100644 --- a/tests/manual/bearerex/sessiondialog.ui +++ b/tests/manual/bearerex/sessiondialog.ui @@ -1,78 +1,87 @@ -<ui version="4.0" > +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> <class>SessionTab</class> - <widget class="QWidget" name="SessionTab" > - <layout class="QVBoxLayout" name="verticalLayout" > + <widget class="QWidget" name="SessionTab"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>192</width> + <height>262</height> + </rect> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> <item> - <layout class="QFormLayout" name="formLayout" > - <item row="0" column="0" > - <widget class="QLabel" name="snapLabel" > - <property name="text" > + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="snapLabel"> + <property name="text"> <string>SNAP</string> </property> </widget> </item> - <item row="0" column="1" > - <widget class="QLineEdit" name="snapLineEdit" > - <property name="readOnly" > + <item row="0" column="1"> + <widget class="QLineEdit" name="snapLineEdit"> + <property name="readOnly"> <bool>true</bool> </property> </widget> </item> - <item row="1" column="0" > - <widget class="QLabel" name="iapLabel" > - <property name="text" > + <item row="1" column="0"> + <widget class="QLabel" name="iapLabel"> + <property name="text"> <string>IAP</string> </property> </widget> </item> - <item row="1" column="1" > - <widget class="QLineEdit" name="iapLineEdit" > - <property name="enabled" > + <item row="1" column="1"> + <widget class="QLineEdit" name="iapLineEdit"> + <property name="enabled"> <bool>true</bool> </property> - <property name="readOnly" > + <property name="readOnly"> <bool>true</bool> </property> </widget> </item> - <item row="2" column="0" > - <widget class="QLabel" name="bearerLabel" > - <property name="text" > + <item row="2" column="0"> + <widget class="QLabel" name="bearerLabel"> + <property name="text"> <string>Bearer</string> </property> </widget> </item> - <item row="2" column="1" > - <widget class="QLineEdit" name="bearerLineEdit" > - <property name="readOnly" > + <item row="2" column="1"> + <widget class="QLineEdit" name="bearerLineEdit"> + <property name="readOnly"> <bool>true</bool> </property> </widget> </item> - <item row="3" column="0" > - <widget class="QLabel" name="sentRecDataLabel" > - <property name="text" > + <item row="3" column="0"> + <widget class="QLabel" name="sentRecDataLabel"> + <property name="text"> <string>Sent/Rec.</string> </property> </widget> </item> - <item row="3" column="1" > - <widget class="QLineEdit" name="sentRecDataLineEdit" > - <property name="readOnly" > + <item row="3" column="1"> + <widget class="QLineEdit" name="sentRecDataLineEdit"> + <property name="readOnly"> <bool>true</bool> </property> </widget> </item> - <item row="4" column="0" > - <widget class="QLabel" name="stateLabel" > - <property name="text" > + <item row="4" column="0"> + <widget class="QLabel" name="stateLabel"> + <property name="text"> <string>State</string> </property> </widget> </item> - <item row="4" column="1" > - <widget class="QLineEdit" name="stateLineEdit" > - <property name="readOnly" > + <item row="4" column="1"> + <widget class="QLineEdit" name="stateLineEdit"> + <property name="readOnly"> <bool>true</bool> </property> </widget> @@ -80,52 +89,71 @@ </layout> </item> <item> - <layout class="QGridLayout" name="gridLayout" > - <item row="0" column="0" > - <widget class="QPushButton" name="openSessionButton" > - <property name="text" > + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QPushButton" name="openSessionButton"> + <property name="text"> <string>Open Session</string> </property> </widget> </item> - <item row="0" column="1" > - <widget class="QPushButton" name="closeSessionButton" > - <property name="text" > + <item row="0" column="1"> + <widget class="QPushButton" name="closeSessionButton"> + <property name="text"> <string>Close Session</string> </property> </widget> </item> - <item row="1" column="0" > - <widget class="QPushButton" name="stopConnectionButton" > - <property name="text" > + <item row="1" column="0"> + <widget class="QPushButton" name="stopConnectionButton"> + <property name="text"> <string>Stop Conn.</string> </property> </widget> </item> - <item row="2" column="0" > - <widget class="QPushButton" name="createQHttpButton" > - <property name="text" > - <string>Create QHttp</string> + <item row="1" column="1"> + <widget class="QPushButton" name="alrButton"> + <property name="text"> + <string>Enable ALR</string> </property> </widget> </item> - <item row="2" column="1" > - <widget class="QPushButton" name="sendRequestButton" > - <property name="text" > + <item row="3" column="0"> + <widget class="QPushButton" name="sendRequestButton"> + <property name="text"> <string>Send Test Req.</string> </property> </widget> </item> - <item row="3" column="0" > - <widget class="QPushButton" name="alrButton" > - <property name="text" > - <string>Enable ALR</string> + <item row="2" column="1"> + <widget class="QPushButton" name="createQNetworkAccessManagerButton"> + <property name="text"> + <string>Create</string> </property> </widget> </item> - <item row="3" column="1" > - <widget class="QPushButton" name="deleteSessionButton" > - <property name="text" > + <item row="2" column="0"> + <widget class="QComboBox" name="comboBox"> + <item> + <property name="text"> + <string>QNAM</string> + </property> + </item> + <item> + <property name="text"> + <string>QTcpSocket</string> + </property> + </item> + <item> + <property name="text"> + <string>QHttp</string> + </property> + </item> + </widget> + </item> + <item row="3" column="1"> + <widget class="QPushButton" name="deleteSessionButton"> + <property name="text"> <string>Delete Session</string> </property> </widget> @@ -135,5 +163,25 @@ </layout> </widget> <resources/> - <connections/> + <connections> + <connection> + <sender>comboBox</sender> + <signal>currentIndexChanged(QString)</signal> + <receiver>SessionTab</receiver> + <slot>on_dataObjectChanged(QString)</slot> + <hints> + <hint type="sourcelabel"> + <x>40</x> + <y>211</y> + </hint> + <hint type="destinationlabel"> + <x>10</x> + <y>258</y> + </hint> + </hints> + </connection> + </connections> + <slots> + <slot>on_dataObjectChanged(QString)</slot> + </slots> </ui> |