#include "FtpClient.h"
#include "ftpconnect.h"
#include "ftpbookmark.h"
#include "basicdialog.h"
extern QString CheminConf;
FtpClient::FtpClient(QWidget * parent):QMainWindow(parent)
{
setupUi(this);
systemTray = false;
menu = new QMenu(this);
menu->addAction(QPixmap(":pixmaps/hiddenfiles.png"),
tr("&Show Tux'Ftp Client"), this, SLOT(showOrHide()));
menu->addSeparator();
menu->addAction(QPixmap(":pixmaps/exit.png"), tr("&Quit"), qApp,
SLOT(quit()));
trayIcon = new QSystemTrayIcon(this);
trayIcon->setIcon(QIcon(":pixmaps/network.png"));
trayIcon->setToolTip("Tux'Ftp Client");
trayIcon->setContextMenu(menu);
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
trayIcon->show();
connect(quitAction, SIGNAL(triggered(bool)), qApp, SLOT(quit()));
connect(closeConnectAction, SIGNAL(triggered(bool)), this, SLOT(slotDisconnect()));
connect(rapidConnectAction, SIGNAL(triggered(bool)), this, SLOT(slotConnect()));
connect(ShowToolbarConnect, SIGNAL(triggered(bool)), this,
SLOT(slotShowToolbarConnect()));
connect(hideToolbarConnect, SIGNAL(triggered(bool)), this,
SLOT(slotHideToolbarConnect()));
connect(newFolder, SIGNAL(triggered(bool)), this, SLOT(slotNewFolder()));
connect(removeFile, SIGNAL(triggered(bool)), this, SLOT(slotRemoveFile()));
connect(renameFile, SIGNAL(triggered(bool)), this, SLOT(slotRenameFile()));
connect(reloadLocalList, SIGNAL(triggered(bool)), this, SLOT(slotReloadLocalList()));
connect(reloadFtpList, SIGNAL(triggered(bool)), this, SLOT(slotReloadFtpList()));
connect(localPathEdit, SIGNAL(returnPressed()), this,
SLOT(slotLocalPathChanged()));
connect(ShowToolbarFile, SIGNAL(triggered(bool)), this,
SLOT(slotShowToolbarFile()));
connect(ShowToolbarTransfert, SIGNAL(triggered(bool)), this,
SLOT(slotShowToolbarTransfert()));
connect(hideToolbarFile, SIGNAL(triggered(bool)), this, SLOT(slotHideToolbarFile()));
connect(hideToolbarTransfert, SIGNAL(triggered(bool)), this,
SLOT(slotHideToolbarTransfert()));
connect(ftpPathEdit, SIGNAL(returnPressed()), this, SLOT(slotFtpPathChanged()));
connect(uploadButton, SIGNAL(clicked()), this, SLOT(slot_upload()));
connect(downloadButton, SIGNAL(clicked()), this, SLOT(slot_download()));
connect(hiddenFiles, SIGNAL(triggered(bool)), this, SLOT(slotHiddenFiles()));
connect(addFtpAction, SIGNAL(triggered(bool)), this, SLOT(slotAddbookmark()));
verticalSplitter->setStretchFactor(0, 2);
ftp = new MyFtp(ftpList, localList, ftpPathEdit, localPathEdit);
QString headers="Name";
localList->setHeaderLabel(headers);
QVBoxLayout *layout = new QVBoxLayout(transfersGroup);
transfersWidget = new transfers(ftp);
layout->addWidget(transfersWidget);
connect(stopAllTransfertAction, SIGNAL(triggered(bool)), transfersWidget,
SLOT(slotRemoveAllTransfers()));
connect(stopTransferAction, SIGNAL(triggered(bool)), transfersWidget, SLOT(slotRemoveTransfers()));
ShowToolbarConnect->setVisible(false);
ShowToolbarFile->setVisible(false);
ShowToolbarTransfert->setVisible(false);
QLabel *begin = new QLabel(this);
begin->setText(tr("<font color =\"#61b9e2\">Status :</font>"));
statusBar()->addPermanentWidget(begin);
stateLabel = new QLabel(this);
stateLabel->setText(trUtf8("<font color =\"#ff0000\">Disconnect</font>"));
statusBar()->addPermanentWidget(stateLabel);
connectLabel = new QLabel(this);
connectLabel->setPixmap(QPixmap(":/pixmaps/connect_no.png"));
statusBar()->addPermanentWidget(connectLabel);
waitLabel = new QLabel(this);
waitLabel->setPixmap(QPixmap(":/pixmaps/network.png"));
statusBar()->addPermanentWidget(waitLabel);
connect(ftpList, SIGNAL(buttonClicked(QTreeWidgetItem *)),
SLOT(slotFtpSelection(QTreeWidgetItem *)));
connect(localList, SIGNAL(buttonClicked(QTreeWidgetItem *)),
SLOT(slotLocalSelection(QTreeWidgetItem *)));
// connect(transfersWidget->transferListWidget, SIGNAL(buttonClicked(QTreeWidgetItem *)),
// SLOT(slotTransferSelection(QTreeWidgetItem *)));
connect(transfersWidget->transferListWidget, SIGNAL(buttonClicked(QTreeWidgetItem *)),
SLOT(slotTransferSelection(QTreeWidgetItem *)));
connect(ftpList, SIGNAL(doubleClickedOnItem(QTreeWidgetItem *)),
SLOT(slotChangeFtpPath(QTreeWidgetItem *)));
connect(localList, SIGNAL(doubleClickedOnItem(QTreeWidgetItem *)),
SLOT(slotChangeLocalPath(QTreeWidgetItem *)));
connect(ftpList, SIGNAL(rightButtonClicked(QTreeWidgetItem *, QPoint)),
SLOT(slotPopupFtp(QTreeWidgetItem *, QPoint)));
connect(localList,SIGNAL(rightButtonClicked(QTreeWidgetItem *, QPoint)),
SLOT(slotPopupLocal(QTreeWidgetItem *, QPoint)));
connect(ftpList, SIGNAL(startDownloadOrUpload(const QString &)),
SLOT(slotUpload(const QString &)));
connect(localList, SIGNAL(startDownloadOrUpload(const QString &)),
SLOT(slotDownload(const QString &)));
connect(ftp, SIGNAL(downloadFinished(const QString&, int, bool)), SLOT(slotDownloadFinished(const QString&, int, bool)));
connect(ftp, SIGNAL(uploadFinished(const QString&, int, bool)), SLOT(slotUploadFinished(const QString&, int, bool)));
connect(ftp, SIGNAL(stateChanged(int)), SLOT(slotStateChanged(int)));
connect(ftp, SIGNAL(detailledError(const QString &)),
SLOT(slotDetailledError(const QString &)));
connect(ftp, SIGNAL(currentActionChanged(MyFtp::FtpCurrentAction)),
SLOT(slotCurrentActionChanged(MyFtp::FtpCurrentAction)));
(void) new QShortcut(Qt::CTRL + Qt::Key_A, this, SLOT(slotSelectAll()));
(void) new QShortcut(Qt::Key_F5, this, SLOT(slotReloadList()));
}
FtpClient::~FtpClient()
{
delete ftp;
}
void FtpClient::slotConnect()
{
ftpConnect c;
if (c.exec() == QDialog::Rejected)
return;
if (ftp->state() != QFtp::Unconnected && ftp->state() != QFtp::Closing)
slotDisconnect();
QString mode = c.transferMode->currentText();
if (mode != tr("Passive") && mode != tr("Active"))
mode = tr("Passive");
if (c.addbookmark->isChecked())
{
QString ident = c.identifiant->text();
if (ident == "")
ident = c.host->currentText();
if (c.anonymous->isChecked())
ident += " [anonyme]";
list.AddBookmark(ident, c.username->text(),
c.host->currentText(),
c.password->text(), c.port->value(),
mode, c.proxyName->text(), c.proxyPort->value());
}
ftpList->clear();
qDebug()<<mode;
if (mode == tr("Passive"))
ftp->setTransferMode(QFtp::Passive);
else
ftp->setTransferMode(QFtp::Active);
if (c.proxyName->text() != "")
ftp->setProxy(c.proxyName->text(), c.proxyPort->value());
ftp->connectFtp(c.host->currentText(), c.port->value(),
c.username->text(), c.password->text());
}
void FtpClient::slotDisconnect()
{
if (ftp->state() == QFtp::Unconnected)
return;
ftp->disconnectFtp();
}
void FtpClient::slotStateChanged(int state)
{
switch ((QFtp::State) state)
{
case QFtp::Unconnected:
stateLabel->setText(trUtf8("<font color =\"#ff0000\">Disconnected</font>"));
connectLabel->setPixmap(QPixmap(":/pixmaps/connect_no.png"));
ftpList->clear();
transfersWidget->slotRemoveTransfers();
ftp->disconnectFtp();
break;
case QFtp::HostLookup:
stateLabel->setText(trUtf8("<font color =\"blue\">Host_Research</font>"));
break;
case QFtp::Connecting:
stateLabel->setText(tr("<font color =\"blue\">Connection</font>"));
break;
case QFtp::Connected:
stateLabel->setText(trUtf8("<font color =\"blue\">Connected</font>"));
break;
case QFtp::LoggedIn:
stateLabel->setText(tr("<font color =\"green\">Recognized</font