1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| #include <client.hpp>
Client::Client() : QWidget()
{
QObject::connect(&client, SIGNAL(commandFinished(int, bool)), this, SLOT(slot(int, bool)));
QObject::connect(&client, SIGNAL(commandStarted(int)), this, SLOT(m_commandStarted(int)));
QObject::connect(&client, SIGNAL(dataTransferProgress(qint64, qint64)), this, SLOT(m_dataTransferProgress(qint64, qint64)));
QObject::connect(&client, SIGNAL(done(bool)), this, SLOT(m_done(bool)));
QObject::connect(&client, SIGNAL(listInfo(const QUrlInfo &)), this, SLOT(m_listInfo(const QUrlInfo &)));
QObject::connect(&client, SIGNAL(readyRead()), this, SLOT(m_readyRead()));
//QObject::connect(&client, SIGNAL(stateChanged(int)), this, SLOT(m_stateChanged(int)));
}
void Client::setBar(QProgressBar* bar, QLabel* label)
{
downloadBar = bar;
textDownloadBar = label;
}
void Client::connectToFtp()
{
client.connectToHost("127.0.0.1");// id: 1
client.login("legion","legion");// id: 2
client.list();// id: 3
/*
fileDownloaded.setFileName("INSTALL.txt");
client.get("INSTALL.txt", &fileDownloaded);// id: 4
*/
client.close();// id: 5
}
void Client::m_commandStarted(int)
{
if(client.currentCommand() == QFtp::Get){
fileDownloaded.open(QIODevice::WriteOnly);}
}
void Client::m_dataTransferProgress(qint64 readBytes, qint64 totalBytes)
{
downloadBar->setRange(0,totalBytes);
downloadBar->setValue(readBytes);
}
void Client::m_readyRead()
{
fileDownloaded.write(client.readAll());
}
void Client::m_done(bool value)
{
fileDownloaded.close();
client.close();
textDownloadBar->setText("Done.");
}
void Client::m_listInfo(const QUrlInfo & fichier)
{
textEdit.append(fichier.name());
}
void Client::slot(int id, bool error)
{
QVariant idRecut = id;
if(error){
QString messageErreur = "Une erreur s'est produite à la commande FTP n°" + idRecut.toString() + ". ";
if(client.error() == QFtp::HostNotFound)
messageErreur += "L'hôte FTP n'a pas été trouvé. Impossible d'établir la connexion.";
else if(client.error() == QFtp::ConnectionRefused)
messageErreur += "Le serveur à refusé la connexion. Impossible d'établir la connexion.";
else if(client.error() == QFtp::NotConnected)
messageErreur += "Une commande à été envoyé mais il n'y a pas de connexion avec le serveur.";
else
messageErreur += "Le type de l'erreur est inconnu";
textDownloadBar->setText(messageErreur);
}
} |
Partager