examples/network/qftp/ftpwindow.cpp
changeset 33 3e2da88830cd
parent 30 5dc02b23752f
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
    41 #include <QtGui>
    41 #include <QtGui>
    42 #include <QtNetwork>
    42 #include <QtNetwork>
    43 
    43 
    44 #include "ftpwindow.h"
    44 #include "ftpwindow.h"
    45 
    45 
    46 #ifdef Q_OS_SYMBIAN
       
    47 #include "sym_iap_util.h"
       
    48 #endif
       
    49 
       
    50 FtpWindow::FtpWindow(QWidget *parent)
    46 FtpWindow::FtpWindow(QWidget *parent)
    51     : QDialog(parent), ftp(0)
    47     : QDialog(parent), ftp(0), networkSession(0)
    52 {
    48 {
    53     ftpServerLabel = new QLabel(tr("Ftp &server:"));
    49     ftpServerLabel = new QLabel(tr("Ftp &server:"));
    54     ftpServerLineEdit = new QLineEdit("ftp.qt.nokia.com");
    50     ftpServerLineEdit = new QLineEdit("ftp.qt.nokia.com");
    55     ftpServerLabel->setBuddy(ftpServerLineEdit);
    51     ftpServerLabel->setBuddy(ftpServerLineEdit);
    56 
    52 
   116     mainLayout->addWidget(fileList);
   112     mainLayout->addWidget(fileList);
   117     mainLayout->addWidget(statusLabel);
   113     mainLayout->addWidget(statusLabel);
   118     mainLayout->addWidget(buttonBox);
   114     mainLayout->addWidget(buttonBox);
   119     setLayout(mainLayout);
   115     setLayout(mainLayout);
   120 
   116 
   121 #ifdef Q_OS_SYMBIAN
   117     QNetworkConfigurationManager manager;
   122     bDefaultIapSet = false;
   118     if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) {
   123 #endif
   119         // Get saved network configuration
       
   120         QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
       
   121         settings.beginGroup(QLatin1String("QtNetwork"));
       
   122         const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString();
       
   123         settings.endGroup();
       
   124 
       
   125         // If the saved network configuration is not currently discovered use the system default
       
   126         QNetworkConfiguration config = manager.configurationFromIdentifier(id);
       
   127         if ((config.state() & QNetworkConfiguration::Discovered) !=
       
   128             QNetworkConfiguration::Discovered) {
       
   129             config = manager.defaultConfiguration();
       
   130         }
       
   131 
       
   132         networkSession = new QNetworkSession(config, this);
       
   133         connect(networkSession, SIGNAL(opened()), this, SLOT(enableConnectButton()));
       
   134 
       
   135         connectButton->setEnabled(false);
       
   136         statusLabel->setText(tr("Opening network session."));
       
   137         networkSession->open();
       
   138     }
   124 
   139 
   125     setWindowTitle(tr("FTP"));
   140     setWindowTitle(tr("FTP"));
   126 }
   141 }
   127 
   142 
   128 QSize FtpWindow::sizeHint() const
   143 QSize FtpWindow::sizeHint() const
   131 }
   146 }
   132 
   147 
   133 //![0]
   148 //![0]
   134 void FtpWindow::connectOrDisconnect()
   149 void FtpWindow::connectOrDisconnect()
   135 {
   150 {
   136 #ifdef Q_OS_SYMBIAN
       
   137    if(!bDefaultIapSet) {
       
   138        qt_SetDefaultIap();
       
   139        bDefaultIapSet = true;
       
   140    }
       
   141 #endif
       
   142     if (ftp) {
   151     if (ftp) {
   143         ftp->abort();
   152         ftp->abort();
   144         ftp->deleteLater();
   153         ftp->deleteLater();
   145         ftp = 0;
   154         ftp = 0;
   146 //![0]
   155 //![0]
   375         downloadButton->setEnabled(false);
   384         downloadButton->setEnabled(false);
   376     }
   385     }
   377 }
   386 }
   378 //![14]
   387 //![14]
   379 
   388 
       
   389 void FtpWindow::enableConnectButton()
       
   390 {
       
   391     // Save the used configuration
       
   392     QNetworkConfiguration config = networkSession->configuration();
       
   393     QString id;
       
   394     if (config.type() == QNetworkConfiguration::UserChoice)
       
   395         id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString();
       
   396     else
       
   397         id = config.identifier();
       
   398 
       
   399     QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
       
   400     settings.beginGroup(QLatin1String("QtNetwork"));
       
   401     settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id);
       
   402     settings.endGroup();
       
   403 
       
   404     connectButton->setEnabled(networkSession->isOpen());
       
   405     statusLabel->setText(tr("Please enter the name of an FTP server."));
       
   406 }
       
   407