diff options
Diffstat (limited to 'examples/network/qftp/ftpwindow.cpp')
-rw-r--r-- | examples/network/qftp/ftpwindow.cpp | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/examples/network/qftp/ftpwindow.cpp b/examples/network/qftp/ftpwindow.cpp index 635b679..f39f9a0 100644 --- a/examples/network/qftp/ftpwindow.cpp +++ b/examples/network/qftp/ftpwindow.cpp @@ -43,12 +43,8 @@ #include "ftpwindow.h" -#ifdef Q_OS_SYMBIAN -#include "sym_iap_util.h" -#endif - FtpWindow::FtpWindow(QWidget *parent) - : QDialog(parent), ftp(0) + : QDialog(parent), ftp(0), networkSession(0) { ftpServerLabel = new QLabel(tr("Ftp &server:")); ftpServerLineEdit = new QLineEdit("ftp.qt.nokia.com"); @@ -118,9 +114,28 @@ FtpWindow::FtpWindow(QWidget *parent) mainLayout->addWidget(buttonBox); setLayout(mainLayout); -#ifdef Q_OS_SYMBIAN - bDefaultIapSet = 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(enableConnectButton())); + + connectButton->setEnabled(false); + statusLabel->setText(tr("Opening network session.")); + networkSession->open(); + } setWindowTitle(tr("FTP")); } @@ -133,12 +148,6 @@ QSize FtpWindow::sizeHint() const //![0] void FtpWindow::connectOrDisconnect() { -#ifdef Q_OS_SYMBIAN - if(!bDefaultIapSet) { - qt_SetDefaultIap(); - bDefaultIapSet = true; - } -#endif if (ftp) { ftp->abort(); ftp->deleteLater(); @@ -377,3 +386,22 @@ void FtpWindow::enableDownloadButton() } //![14] +void FtpWindow::enableConnectButton() +{ + // 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(); + + connectButton->setEnabled(networkSession->isOpen()); + statusLabel->setText(tr("Please enter the name of an FTP server.")); +} + |