qtmobility/tests/bearerex/bearerex.cpp
branchRCL_3
changeset 10 cd2778e5acfe
equal deleted inserted replaced
9:5d007b20cfd0 10:cd2778e5acfe
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 #include "bearerex.h"
       
    42 #include "datatransferer.h"
       
    43 
       
    44 #include <QtNetwork>
       
    45 
       
    46 Q_DECLARE_METATYPE(QNetworkConfiguration)
       
    47 
       
    48 BearerEx::BearerEx(QWidget* parent)
       
    49      : QMainWindow(parent)
       
    50 {
       
    51     setupUi(this);
       
    52     
       
    53     createMenus();
       
    54     
       
    55     connect(&m_NetworkConfigurationManager, SIGNAL(updateCompleted()), this, SLOT(configurationsUpdateCompleted()));
       
    56     connect(&m_NetworkConfigurationManager, SIGNAL(configurationAdded(const QNetworkConfiguration&)),
       
    57             this, SLOT(configurationAdded(const QNetworkConfiguration&)));
       
    58     connect(&m_NetworkConfigurationManager, SIGNAL(configurationRemoved(const QNetworkConfiguration&)),
       
    59             this, SLOT(configurationRemoved(const QNetworkConfiguration&)));
       
    60     connect(&m_NetworkConfigurationManager, SIGNAL(onlineStateChanged(bool)),
       
    61             this, SLOT(onlineStateChanged(bool)));
       
    62     connect(&m_NetworkConfigurationManager, SIGNAL(configurationChanged(const QNetworkConfiguration&)),
       
    63             this, SLOT(configurationChanged(const QNetworkConfiguration&)));
       
    64     showConfigurations();
       
    65 }
       
    66 
       
    67 void BearerEx::createMenus()
       
    68 {
       
    69     QAction* act1 = new QAction(tr("Show Details"), this);
       
    70     menuBar()->addAction(act1);
       
    71     connect(act1, SIGNAL(triggered()), this, SLOT(on_showDetailsButton_clicked()));
       
    72 
       
    73     QAction* exitAct = new QAction(tr("Exit"), this);
       
    74     menuBar()->addAction(exitAct);
       
    75     connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
       
    76 }
       
    77 
       
    78 void BearerEx::showConfigurations()
       
    79 {
       
    80     listWidget->clear();
       
    81     QListWidgetItem* listItem;
       
    82     
       
    83     QNetworkConfiguration defaultConfig = m_NetworkConfigurationManager.defaultConfiguration();
       
    84     if (defaultConfig.type() == QNetworkConfiguration::UserChoice) {
       
    85         listItem = new QListWidgetItem();
       
    86         QFont font = listItem->font();
       
    87         font.setBold(true);
       
    88         font.setUnderline(true);
       
    89         listItem->setFont(font);        
       
    90         listItem->setText("       UserChoice");
       
    91         listItem->setData(Qt::UserRole, qVariantFromValue(defaultConfig));
       
    92         listWidget->addItem(listItem);
       
    93     }
       
    94     
       
    95     QList<QNetworkConfiguration> configurations = m_NetworkConfigurationManager.allConfigurations();
       
    96     for (int i=0; i<configurations.count(); i++)
       
    97     {
       
    98         listItem = new QListWidgetItem();
       
    99         QString text;
       
   100         if (configurations[i].type() == QNetworkConfiguration::InternetAccessPoint) {
       
   101             text.append("(IAP,");
       
   102         } else if (configurations[i].type() == QNetworkConfiguration::ServiceNetwork) {
       
   103             text.append("(SNAP,");
       
   104         }
       
   105         
       
   106         if ((configurations[i].state() & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) {
       
   107             text.append("Act) ");
       
   108         } else if ((configurations[i].state() & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) {
       
   109             text.append("Disc) ");
       
   110         } else {
       
   111             text.append("Def) ");
       
   112         }
       
   113         text.append(configurations[i].name());
       
   114         
       
   115         if (defaultConfig.isValid() && defaultConfig == configurations[i]) {
       
   116             QFont font = listItem->font();
       
   117             font.setBold(true);
       
   118             font.setUnderline(true);
       
   119             listItem->setFont(font);        
       
   120         }
       
   121         listItem->setText(text);
       
   122         listItem->setData(Qt::UserRole, qVariantFromValue(configurations[i]));
       
   123         listWidget->addItem(listItem);
       
   124     }
       
   125 }
       
   126 
       
   127 void BearerEx::on_updateConfigurationsButton_clicked()
       
   128 {
       
   129     m_NetworkConfigurationManager.updateConfigurations();
       
   130 }
       
   131 
       
   132 void BearerEx::on_updateListButton_clicked()
       
   133 {
       
   134     showConfigurations();
       
   135 }
       
   136 
       
   137 void BearerEx::on_showDetailsButton_clicked()
       
   138 {
       
   139     QListWidgetItem* item = listWidget->currentItem();
       
   140     if (!item) {
       
   141         return;
       
   142     }
       
   143 
       
   144 	QNetworkConfiguration networkConfiguration = qVariantValue<QNetworkConfiguration>(item->data(Qt::UserRole));
       
   145 	DetailedInfoDialog infoDialog(&networkConfiguration,this);
       
   146 	infoDialog.exec();
       
   147 }
       
   148 
       
   149 void BearerEx::on_createSessionButton_clicked()
       
   150 {
       
   151     QListWidgetItem* item = listWidget->currentItem();
       
   152     if (!item) {
       
   153         return;
       
   154     }    
       
   155     QNetworkConfiguration networkConfiguration = qVariantValue<QNetworkConfiguration>(item->data(Qt::UserRole));
       
   156     int newTabIndex = mainTabWidget->count();
       
   157     SessionTab* newTab = new SessionTab(&networkConfiguration,&m_NetworkConfigurationManager,eventListWidget,newTabIndex-1);
       
   158     QString label = QString("S")+QString::number(newTabIndex-1);
       
   159     mainTabWidget->insertTab(newTabIndex,newTab,label);
       
   160     mainTabWidget->setCurrentIndex(newTabIndex);
       
   161 }
       
   162 
       
   163 void BearerEx::on_clearEventListButton_clicked()
       
   164 {
       
   165     eventListWidget->clear();
       
   166 }
       
   167 
       
   168 void BearerEx::configurationAdded(const QNetworkConfiguration& config)
       
   169 {
       
   170     QListWidgetItem* listItem = new QListWidgetItem();
       
   171     listItem->setText(QString("Added: ")+config.name());
       
   172     eventListWidget->addItem(listItem);
       
   173 }
       
   174 
       
   175 void BearerEx::configurationRemoved(const QNetworkConfiguration& config)
       
   176 {
       
   177     QListWidgetItem* listItem = new QListWidgetItem();
       
   178     listItem->setText(QString("Removed: ")+config.name());
       
   179     eventListWidget->addItem(listItem);
       
   180 }
       
   181 
       
   182 void BearerEx::onlineStateChanged(bool isOnline)
       
   183 {
       
   184     QListWidgetItem* listItem = new QListWidgetItem();
       
   185     QFont font = listItem->font();
       
   186     font.setBold(true);
       
   187     listItem->setFont(font);        
       
   188     if (isOnline) {
       
   189         listItem->setText(QString("> Online"));
       
   190     } else {
       
   191         listItem->setText(QString("< Offline"));
       
   192     }
       
   193     eventListWidget->addItem(listItem);
       
   194 }
       
   195 
       
   196 void BearerEx::configurationChanged(const QNetworkConfiguration & config)
       
   197 {
       
   198     QListWidgetItem* listItem = new QListWidgetItem();
       
   199     QString state;
       
   200     switch (config.state())
       
   201     {
       
   202         case QNetworkConfiguration::Undefined:
       
   203             state = "Undef : ";
       
   204             break;
       
   205         case QNetworkConfiguration::Defined:
       
   206             state = "Def : ";
       
   207             break;
       
   208         case QNetworkConfiguration::Discovered:
       
   209             state = "Disc : ";
       
   210             break;
       
   211         case QNetworkConfiguration::Active:
       
   212             state = "Act : ";
       
   213             break;
       
   214     }
       
   215     listItem->setText(state+config.name());
       
   216     eventListWidget->addItem(listItem);
       
   217 }
       
   218 
       
   219 void BearerEx::configurationsUpdateCompleted()
       
   220 {
       
   221     QMessageBox msgBox;
       
   222     msgBox.setStandardButtons(QMessageBox::Close);
       
   223     msgBox.setText("Configurations update completed.");
       
   224     msgBox.exec();
       
   225 }
       
   226 
       
   227 DetailedInfoDialog::DetailedInfoDialog(QNetworkConfiguration* apNetworkConfiguration, QWidget * parent)
       
   228     : QDialog(parent)
       
   229 {
       
   230     setupUi(this);
       
   231 
       
   232     tableWidget->setColumnCount(2);
       
   233     int rowCount = 2;
       
   234     
       
   235     if (apNetworkConfiguration->type() == QNetworkConfiguration::ServiceNetwork) {
       
   236         rowCount = rowCount + apNetworkConfiguration->children().count();
       
   237     }
       
   238 
       
   239 	tableWidget->setRowCount(rowCount);
       
   240 	tableWidget->setColumnWidth(1,250);
       
   241 	tableWidget->setItem(0, 0, new QTableWidgetItem(tr("Name")));
       
   242 	tableWidget->setItem(0, 1, new QTableWidgetItem(apNetworkConfiguration->name()));
       
   243 	tableWidget->setItem(1, 0, new QTableWidgetItem(tr("Id")));
       
   244 	tableWidget->setItem(1, 1, new QTableWidgetItem(apNetworkConfiguration->identifier()));
       
   245     if (apNetworkConfiguration->type() == QNetworkConfiguration::ServiceNetwork) {
       
   246         for (int i=0; i<apNetworkConfiguration->children().count(); i++) {
       
   247             tableWidget->setItem(i+2, 0, new QTableWidgetItem(QString("IAP")+QString::number(i+1)));
       
   248             tableWidget->setItem(i+2, 1, new QTableWidgetItem(apNetworkConfiguration->children()[i].name()));
       
   249         }
       
   250     }
       
   251     
       
   252     tableWidget->setFocusPolicy(Qt::NoFocus);
       
   253 
       
   254 #ifdef Q_OS_SYMBIAN
       
   255     this->showMaximized();
       
   256 #endif
       
   257 }
       
   258 
       
   259 SessionTab::SessionTab(QNetworkConfiguration* apNetworkConfiguration,
       
   260                        QNetworkConfigurationManager* configManager,
       
   261                        QListWidget* eventListWidget,
       
   262                        int index,
       
   263                        BearerEx * parent)
       
   264     : QWidget(parent), m_dataTransferer(0), m_eventListWidget(eventListWidget),
       
   265      m_index(index), m_alrEnabled (false)
       
   266 {
       
   267     setupUi(this);
       
   268 
       
   269     m_ConfigManager = configManager;
       
   270     m_NetworkSession = new QNetworkSession(*apNetworkConfiguration);
       
   271 
       
   272     // Update initial Session state to UI
       
   273     newState(m_NetworkSession->state());
       
   274 
       
   275     connect(m_NetworkSession, SIGNAL(newConfigurationActivated()), this, SLOT(newConfigurationActivated()));
       
   276     connect(m_NetworkSession, SIGNAL(stateChanged(QNetworkSession::State)),
       
   277             this, SLOT(stateChanged(QNetworkSession::State)));
       
   278     connect(m_NetworkSession, SIGNAL(opened()), this, SLOT(opened()));
       
   279     connect(m_NetworkSession, SIGNAL(closed()), this, SLOT(closed()));
       
   280     connect(m_NetworkSession, SIGNAL(error(QNetworkSession::SessionError)), this, SLOT(error(QNetworkSession::SessionError)));
       
   281     
       
   282     if (apNetworkConfiguration->type() == QNetworkConfiguration::InternetAccessPoint) {
       
   283         snapLabel->hide();
       
   284         snapLineEdit->hide();
       
   285         alrButton->hide();
       
   286         iapLineEdit->setText(apNetworkConfiguration->name()+" ("+apNetworkConfiguration->identifier()+")");
       
   287     } else if (apNetworkConfiguration->type() == QNetworkConfiguration::ServiceNetwork) {
       
   288         snapLineEdit->setText(apNetworkConfiguration->name()+" ("+apNetworkConfiguration->identifier()+")");
       
   289     }
       
   290     bearerLineEdit->setText(apNetworkConfiguration->bearerName());
       
   291     sentRecDataLineEdit->setText(QString::number(m_NetworkSession->bytesWritten())+
       
   292                                  QString(" / ")+
       
   293                                  QString::number(m_NetworkSession->bytesReceived()));
       
   294     snapLineEdit->setFocusPolicy(Qt::NoFocus);
       
   295     iapLineEdit->setFocusPolicy(Qt::NoFocus);
       
   296     bearerLineEdit->setFocusPolicy(Qt::NoFocus);
       
   297     sentRecDataLineEdit->setFocusPolicy(Qt::NoFocus);
       
   298     stateLineEdit->setFocusPolicy(Qt::NoFocus);
       
   299 }
       
   300 
       
   301 SessionTab::~SessionTab()
       
   302 {
       
   303     delete m_NetworkSession; m_NetworkSession = 0;
       
   304     delete m_dataTransferer; m_dataTransferer = 0;
       
   305 }
       
   306 
       
   307 void SessionTab::on_createQNetworkAccessManagerButton_clicked()
       
   308 {
       
   309     if (m_dataTransferer) {
       
   310         disconnect(m_dataTransferer, 0, 0, 0);
       
   311         delete m_dataTransferer;
       
   312         m_dataTransferer = 0;
       
   313     }
       
   314     // Create new object according to current selection
       
   315     QString type(comboBox->currentText());
       
   316     if (type == "QNAM") {
       
   317         m_dataTransferer = new DataTransfererQNam(this);
       
   318     } else if (type == "QTcpSocket") {
       
   319         m_dataTransferer = new DataTransfererQTcp(this);
       
   320     } else if (type == "QHttp") {
       
   321         m_dataTransferer = new DataTransfererQHttp(this);
       
   322     } else {
       
   323         qDebug("BearerEx Warning, unknown data transfer object requested, not creating anything.");
       
   324         return;
       
   325     }
       
   326     createQNetworkAccessManagerButton->setText("Recreate");
       
   327     connect(m_dataTransferer, SIGNAL(finished(quint32, qint64, QString)), this, SLOT(finished(quint32, qint64, QString)));
       
   328 }
       
   329 
       
   330 void SessionTab::on_sendRequestButton_clicked()
       
   331 {
       
   332     if (m_dataTransferer) {
       
   333         if (!m_dataTransferer->transferData()) {
       
   334             QMessageBox msgBox;
       
   335             msgBox.setStandardButtons(QMessageBox::Close);
       
   336             msgBox.setText("Data transfer not started. \nVery likely data transfer ongoing.");
       
   337             msgBox.exec();
       
   338         }
       
   339     } else {
       
   340         QMessageBox msgBox;
       
   341         msgBox.setStandardButtons(QMessageBox::Close);
       
   342         msgBox.setText("Data object not created.\nCreate data object first.");
       
   343         msgBox.exec();
       
   344     }
       
   345 }
       
   346 
       
   347 void SessionTab::on_openSessionButton_clicked()
       
   348 {
       
   349     m_NetworkSession->open();
       
   350     if (m_NetworkSession->isOpen()) {
       
   351         newState(m_NetworkSession->state()); 
       
   352     }
       
   353 }
       
   354 
       
   355 void SessionTab::on_closeSessionButton_clicked()
       
   356 {
       
   357     m_NetworkSession->close();
       
   358     if (!m_NetworkSession->isOpen()) {
       
   359         newState(m_NetworkSession->state()); 
       
   360     }
       
   361 }
       
   362 
       
   363 void SessionTab::on_stopConnectionButton_clicked()
       
   364 {
       
   365     m_NetworkSession->stop();
       
   366 }
       
   367 
       
   368 void SessionTab::on_alrButton_clicked()
       
   369 {
       
   370     if (!m_alrEnabled) {
       
   371         connect(m_NetworkSession, SIGNAL(preferredConfigurationChanged(const QNetworkConfiguration&, bool)),
       
   372                 this, SLOT(preferredConfigurationChanged(const QNetworkConfiguration&, bool)));
       
   373         alrButton->setText("Disable ALR");
       
   374         m_alrEnabled = true;
       
   375     } else {
       
   376         disconnect(m_NetworkSession, SIGNAL(preferredConfigurationChanged(const QNetworkConfiguration&, bool)), 0, 0);
       
   377         alrButton->setText("Enable ALR");
       
   378         m_alrEnabled = false;
       
   379     }
       
   380 }
       
   381 
       
   382 void SessionTab::on_deleteSessionButton_clicked()
       
   383 {
       
   384     setWindowTitle("Bearer Example");
       
   385     delete this;
       
   386 }
       
   387 
       
   388 void SessionTab::newConfigurationActivated()
       
   389 {
       
   390     QMessageBox msgBox;
       
   391     msgBox.setText("New configuration activated.");
       
   392     msgBox.setInformativeText("Do you want to accept new configuration?");
       
   393     msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
       
   394     msgBox.setDefaultButton(QMessageBox::Yes);
       
   395     if (msgBox.exec() == QMessageBox::Yes) {
       
   396         m_NetworkSession->accept();
       
   397         iapLineEdit->setText(m_config.name()+" ("+m_config.identifier()+")");
       
   398     } else {
       
   399         m_NetworkSession->reject();
       
   400     }
       
   401 }
       
   402 
       
   403 void SessionTab::preferredConfigurationChanged(const QNetworkConfiguration& config, bool /*isSeamless*/)
       
   404 {
       
   405     m_config =  config;
       
   406     QMessageBox msgBox;
       
   407     msgBox.setText("Roaming to new configuration.");
       
   408     msgBox.setInformativeText("Do you want to migrate to "+config.name()+"?");
       
   409     msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
       
   410     msgBox.setDefaultButton(QMessageBox::Yes);
       
   411     if (msgBox.exec() == QMessageBox::Yes) {
       
   412         m_NetworkSession->migrate();
       
   413     } else {
       
   414         m_NetworkSession->ignore();
       
   415     }
       
   416 }
       
   417 
       
   418 void SessionTab::opened()
       
   419 {
       
   420     QListWidgetItem* listItem = new QListWidgetItem();
       
   421     QFont font = listItem->font();
       
   422     font.setBold(true);
       
   423     listItem->setFont(font);        
       
   424     listItem->setText(QString("S")+QString::number(m_index)+QString(" - ")+QString("Opened"));
       
   425     m_eventListWidget->addItem(listItem);
       
   426     
       
   427     QVariant identifier = m_NetworkSession->sessionProperty("ActiveConfiguration");
       
   428     if (!identifier.isNull()) {
       
   429         QString configId = identifier.toString();
       
   430         QNetworkConfiguration config = m_ConfigManager->configurationFromIdentifier(configId);
       
   431         if (config.isValid()) {
       
   432             iapLineEdit->setText(config.name()+" ("+config.identifier()+")");
       
   433         }
       
   434     }
       
   435     newState(m_NetworkSession->state()); // Update the "(open)"
       
   436 
       
   437     if (m_NetworkSession->configuration().type() == QNetworkConfiguration::UserChoice) {
       
   438         QVariant identifier = m_NetworkSession->sessionProperty("UserChoiceConfiguration");
       
   439         if (!identifier.isNull()) {
       
   440             QString configId = identifier.toString();
       
   441             QNetworkConfiguration config = m_ConfigManager->configurationFromIdentifier(configId);
       
   442             if (config.isValid() && (config.type() == QNetworkConfiguration::ServiceNetwork)) {
       
   443                 snapLineEdit->setText(config.name());
       
   444             }
       
   445         }
       
   446     }
       
   447 }
       
   448 
       
   449 void SessionTab::closed()
       
   450 {
       
   451     QListWidgetItem* listItem = new QListWidgetItem();
       
   452     QFont font = listItem->font();
       
   453     font.setBold(true);
       
   454     listItem->setFont(font);        
       
   455     listItem->setText(QString("S")+QString::number(m_index)+QString(" - ")+QString("Closed"));
       
   456     m_eventListWidget->addItem(listItem);
       
   457 }
       
   458 
       
   459 QString SessionTab::stateString(QNetworkSession::State state)
       
   460 {
       
   461     QString stateString;
       
   462     switch (state)
       
   463     {
       
   464         case QNetworkSession::Invalid:
       
   465             stateString = "Invalid";
       
   466             break;
       
   467         case QNetworkSession::NotAvailable:
       
   468             stateString = "NotAvailable";
       
   469             break;
       
   470         case QNetworkSession::Connecting:
       
   471             stateString = "Connecting";
       
   472             break;
       
   473         case QNetworkSession::Connected:
       
   474             stateString = "Connected";
       
   475             break;
       
   476         case QNetworkSession::Closing:
       
   477             stateString = "Closing";
       
   478             break;
       
   479         case QNetworkSession::Disconnected:
       
   480             stateString = "Disconnected";
       
   481             break;
       
   482         case QNetworkSession::Roaming:
       
   483             stateString = "Roaming";
       
   484             break;
       
   485     }
       
   486     return stateString;
       
   487 }
       
   488 
       
   489 void SessionTab::on_dataObjectChanged(const QString &newObjectType)
       
   490 {
       
   491     qDebug() << "BearerEx SessionTab dataObjectChanged to: " << newObjectType;
       
   492     if (m_dataTransferer) {
       
   493         disconnect(m_dataTransferer, 0, 0, 0);
       
   494         delete m_dataTransferer; m_dataTransferer = 0;
       
   495         qDebug() << "BearerEx SessionTab, previous data object deleted.";
       
   496     }
       
   497     createQNetworkAccessManagerButton->setText("Create");
       
   498 }
       
   499 
       
   500 
       
   501 void SessionTab::stateChanged(QNetworkSession::State state)    
       
   502 {
       
   503     newState(state);
       
   504     
       
   505     QListWidgetItem* listItem = new QListWidgetItem();
       
   506     listItem->setText(QString("S")+QString::number(m_index)+QString(" - ")+stateString(state));
       
   507     m_eventListWidget->addItem(listItem);
       
   508 }
       
   509 
       
   510 void SessionTab::newState(QNetworkSession::State state)
       
   511 {
       
   512     QVariant identifier = m_NetworkSession->sessionProperty("ActiveConfiguration");
       
   513     if (state == QNetworkSession::Connected && !identifier.isNull()) {
       
   514         QString configId = identifier.toString();
       
   515         QNetworkConfiguration config = m_ConfigManager->configurationFromIdentifier(configId);
       
   516         if (config.isValid()) {
       
   517             iapLineEdit->setText(config.name()+" ("+config.identifier()+")");
       
   518             bearerLineEdit->setText(config.bearerName());
       
   519         }
       
   520     } else {
       
   521         bearerLineEdit->setText(m_NetworkSession->configuration().bearerName());
       
   522     }
       
   523 
       
   524     QString active;
       
   525     if (m_NetworkSession->isOpen()) {
       
   526         active = " (open)";
       
   527     }
       
   528     stateLineEdit->setText(stateString(state)+active);
       
   529 }
       
   530 
       
   531 void SessionTab::error(QNetworkSession::SessionError error)
       
   532 {
       
   533     QListWidgetItem* listItem = new QListWidgetItem();
       
   534     QMessageBox msgBox;
       
   535     msgBox.setStandardButtons(QMessageBox::Close);
       
   536     
       
   537     QString errorString;
       
   538     switch (error)
       
   539     {
       
   540         case QNetworkSession::UnknownSessionError:
       
   541             errorString = "UnknownSessionError";
       
   542             break;
       
   543         case QNetworkSession::SessionAbortedError:
       
   544             errorString = "SessionAbortedError";
       
   545             break;
       
   546         case QNetworkSession::RoamingError:
       
   547             errorString = "RoamingError";
       
   548             break;
       
   549         case QNetworkSession::OperationNotSupportedError:
       
   550             errorString = "OperationNotSupportedError";
       
   551             break;
       
   552         case QNetworkSession::InvalidConfigurationError:
       
   553             errorString = "InvalidConfigurationError";
       
   554             break;
       
   555     }
       
   556     listItem->setText(QString("S")+QString::number(m_index)+QString(" - ")+errorString);
       
   557     m_eventListWidget->addItem(listItem);
       
   558     
       
   559     msgBox.setText(errorString);
       
   560     msgBox.exec();
       
   561 }
       
   562 
       
   563 void SessionTab::finished(quint32 errorCode, qint64 dataReceived, QString errorType)
       
   564 {
       
   565     QMessageBox msgBox;
       
   566     msgBox.setStandardButtons(QMessageBox::Close);
       
   567     msgBox.setText(QString("Data transfer completed. \nError code: ") + QString::number((int)errorCode) +
       
   568                    "\nError type: " + errorType +
       
   569                    "\nBytes received: " +
       
   570                    QString::number(dataReceived));
       
   571     msgBox.exec();
       
   572     // Check if the networksession still exists - it may have gone after returning from
       
   573     // the modal dialog (in the case that app has been closed, and deleting QHttp will
       
   574     // trigger the done() invokation).
       
   575     if (m_NetworkSession) {
       
   576         sentRecDataLineEdit->setText(QString::number(m_NetworkSession->bytesWritten())+
       
   577                                      QString(" / ")+
       
   578                                      QString::number(m_NetworkSession->bytesReceived()));
       
   579     } else {
       
   580         sentRecDataLineEdit->setText("Data amounts not available.");
       
   581     }
       
   582 }
       
   583 
       
   584 // End of file
       
   585