#include "ftpwindow.h"
#include "ui_ftpwindow.h"
#include "qftp.h"
#include "qurl.h"
#include "QMessageBox"
#include "QFile"
FTPWindow
::FTPWindow(QWidget *parent
) : ui(new Ui::FTPWindow),ftp(0)
{
ui->setupUi(this);
QUrl url
("ftp.qt.nokia.com");
}
FTPWindow::~FTPWindow()
{
delete ui;
}
void FTPWindow
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
void FTPWindow
::addToList(const QUrlInfo &urlInfo
) {
filelist += urlInfo.name();
//QMessageBox::information(this, tr("FTP"),filelist,QMessageBox::Ok);
QFile newfile
("ftpfilenames1.txt");
newfile.write(filelist.toAscii().data());
newfile.write("\r\n");
newfile.close();
}
void FTPWindow::on_Connect_clicked()
{
#ifdef Q_OS_SYMBIAN
if(!bDefaultIapSet) {
qt_SetDefaultIap();
bDefaultIapSet = true;
}
#endif
if (ftp) {
ftp->abort();
ftp->deleteLater();
ftp = 0;
//![0]
#ifndef QT_NO_CURSOR
setCursor(Qt::ArrowCursor);
#endif
return;
}
#ifndef QT_NO_CURSOR
setCursor(Qt::WaitCursor);
#endif
//![1]
connect(ftp, SIGNAL(commandFinished(int,bool)),
this, SLOT(ftpCommandFinished(int,bool)));
connect(ftp,
SIGNAL(listInfo
(QUrlInfo)),
QUrl url
("ftp.qt.nokia.com");
if (!url.
isValid() || url.
scheme().
toLower() != QLatin1String("ftp")) { ftp->connectToHost("ftp.qt.nokia.com", 21);
ftp->login();
} else {
ftp->connectToHost(url.host(), url.port(21));
if (!url.userName().isEmpty())
ftp
->login
(QUrl::fromPercentEncoding(url.
userName().
toLatin1()), url.
password());
else
ftp->login();
if (!url.path().isEmpty())
ftp->cd(url.path());
}
}
void FTPWindow::ftpCommandFinished(int, bool error)
{
#ifndef QT_NO_CURSOR
setCursor(Qt::ArrowCursor);
#endif
if (ftp
->currentCommand
() == QFtp::ConnectToHost) { if (error) {
tr("Unable to connect to the FTP server "
"at %1. Please check that the host "
"name is correct."),
on_Connect_clicked();
return;
}
return;
}
if (ftp
->currentCommand
() == QFtp::Login){ ftp->list(); }
else if (ftp
->currentCommand
() == QFtp::List) {
}
}
#include "ftpwindow.h"
#include "ui_ftpwindow.h"
#include "qftp.h"
#include "qurl.h"
#include "QMessageBox"
#include "QFile"
FTPWindow::FTPWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::FTPWindow),ftp(0)
{
ui->setupUi(this);
QUrl url("ftp.qt.nokia.com");
}
FTPWindow::~FTPWindow()
{
delete ui;
}
void FTPWindow::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void FTPWindow::addToList(const QUrlInfo &urlInfo)
{
QString filelist;
filelist += urlInfo.name();
//QMessageBox::information(this, tr("FTP"),filelist,QMessageBox::Ok);
QFile newfile("ftpfilenames1.txt");
newfile.open(QIODevice::WriteOnly | QIODevice::Append);
newfile.write(filelist.toAscii().data());
newfile.write("\r\n");
newfile.close();
}
void FTPWindow::on_Connect_clicked()
{
#ifdef Q_OS_SYMBIAN
if(!bDefaultIapSet) {
qt_SetDefaultIap();
bDefaultIapSet = true;
}
#endif
if (ftp) {
ftp->abort();
ftp->deleteLater();
ftp = 0;
//![0]
#ifndef QT_NO_CURSOR
setCursor(Qt::ArrowCursor);
#endif
return;
}
#ifndef QT_NO_CURSOR
setCursor(Qt::WaitCursor);
#endif
//![1]
ftp = new QFtp(this);
connect(ftp, SIGNAL(commandFinished(int,bool)),
this, SLOT(ftpCommandFinished(int,bool)));
connect(ftp, SIGNAL(listInfo(QUrlInfo)),
this, SLOT(addToList(QUrlInfo)));
QUrl url("ftp.qt.nokia.com");
if (!url.isValid() || url.scheme().toLower() != QLatin1String("ftp")) {
ftp->connectToHost("ftp.qt.nokia.com", 21);
ftp->login();
} else {
ftp->connectToHost(url.host(), url.port(21));
if (!url.userName().isEmpty())
ftp->login(QUrl::fromPercentEncoding(url.userName().toLatin1()), url.password());
else
ftp->login();
if (!url.path().isEmpty())
ftp->cd(url.path());
}
}
void FTPWindow::ftpCommandFinished(int, bool error)
{
#ifndef QT_NO_CURSOR
setCursor(Qt::ArrowCursor);
#endif
if (ftp->currentCommand() == QFtp::ConnectToHost) {
if (error) {
QMessageBox::information(this, tr("FTP"),
tr("Unable to connect to the FTP server "
"at %1. Please check that the host "
"name is correct."),
QMessageBox::Ok);
on_Connect_clicked();
return;
}
return;
}
if (ftp->currentCommand() == QFtp::Login){
ftp->list(); }
else if (ftp->currentCommand() == QFtp::List) {
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks