4#include <QCoreApplication> 
    5#include <QLoggingCategory> 
    6#include "BackendFileTransfer.h" 
    8static Q_LOGGING_CATEGORY(log, 
"FileTransfer.Backend")
 
   10class CFileTransferEvent : public QEvent
 
   23    CFileTransferEvent(Command cmd,
 
   24                       const QString& szSrcPath = QString(),
 
   25                       const QString& szDesPath = QString());
 
   28    QString m_szSourcePath;
 
   29    QString m_szDestination;
 
   31    QSharedPointer<CFileTransfer> m_FileTransfer;
 
   34CFileTransferEvent::CFileTransferEvent(Command cmd,
 
   35                                       const QString &szSrcPath,
 
   36                                       const QString &szDesPath)
 
   37    : QEvent(QEvent::Type::User)
 
   39    , m_szSourcePath(szSrcPath)
 
   40    , m_szDestination(szDesPath)
 
   46    , m_pOperate(pOperate)
 
   52    qDebug(log) << Q_FUNC_INFO;
 
   54        m_pPara = m_pOperate->GetParameter();
 
   58CBackendFileTransfer::~CBackendFileTransfer()
 
   60    qDebug(log) << Q_FUNC_INFO;
 
   63bool CBackendFileTransfer::event(QEvent *event)
 
   65    if(event->type() == QEvent::Type::User) {
 
   66        CFileTransferEvent* pEvent = (CFileTransferEvent*)event;
 
   67        switch(pEvent->m_Command) {
 
   68        case CFileTransferEvent::Command::MakeDir:
 
   71                m_pSFTP->MakeDir(pEvent->m_szSourcePath);
 
   74        case CFileTransferEvent::Command::RemoveDir:
 
   77                m_pSFTP->RemoveDir(pEvent->m_szSourcePath);
 
   80        case CFileTransferEvent::Command::RemoveFile:
 
   83                m_pSFTP->RemoveFile(pEvent->m_szSourcePath);
 
   86        case CFileTransferEvent::Command::Rename:
 
   89                m_pSFTP->Rename(pEvent->m_szSourcePath, pEvent->m_szDestination);
 
   92        case CFileTransferEvent::Command::GetDir:
 
   96                m_pSFTP->slotGetDir(pEvent->m_szSourcePath, pEvent->m_pRemoteFileSystem);
 
  100        case CFileTransferEvent::Command::StartFileTransfer:
 
  104                m_pSFTP->slotStartFileTransfer(pEvent->m_FileTransfer);
 
  108        case CFileTransferEvent::Command::StopFileTransfer:
 
  112                m_pSFTP->slotStopFileTransfer(pEvent->m_FileTransfer);
 
  120    return CBackend::event(event);
 
  125    OnInitReturnValue nRet = OnInitReturnValue::Fail;
 
  126    if(m_pPara->GetProtocol() == CParameterFileTransfer::Protocol::SFTP)
 
 
  137        m_pSFTP->deleteLater();
 
 
  149        nRet = m_pSFTP->Process();
 
 
  162                    Qt::DirectConnection);
 
  164    check = connect(
this, SIGNAL(sigGetDir(
CRemoteFileSystem*, QVector<QSharedPointer<CRemoteFileSystem> >, 
bool)),
 
  165                    pForm, SIGNAL(sigGetDir(
CRemoteFileSystem*, QVector<QSharedPointer<CRemoteFileSystem> >, 
bool)));
 
  167    check = connect(pForm, SIGNAL(sigMakeDir(
const QString&)),
 
  168                    this, SLOT(slotMakeDir(
const QString&)));
 
  170    check = connect(pForm, SIGNAL(sigRemoveDir(
const QString&)),
 
  171                    this, SLOT(slotRemoveDir(
const QString&)));
 
  173    check = connect(pForm, SIGNAL(sigRemoveFile(
const QString&)),
 
  174                    this, SLOT(slotRemoveFile(
const QString&)));
 
  176    check = connect(pForm, SIGNAL(sigRename(
const QString&, 
const QString&)),
 
  177                    this, SLOT(slotRename(
const QString&, 
const QString&)));
 
  179    check = connect(pForm, SIGNAL(sigStartFileTransfer(QSharedPointer<CFileTransfer>)),
 
  180                    this, SLOT(slotStartFileTransfer(QSharedPointer<CFileTransfer>)));
 
  182    check = connect(pForm, SIGNAL(sigStopFileTransfer(QSharedPointer<CFileTransfer>)),
 
  183                    this, SLOT(slotStopFileTransfer(QSharedPointer<CFileTransfer>)));
 
  185    check = connect(
this, SIGNAL(sigFileTransferUpdate(QSharedPointer<CFileTransfer>)),
 
  186                    pForm, SLOT(slotFileTransferUpdate(QSharedPointer<CFileTransfer>)));
 
  191CBackendFileTransfer::OnInitReturnValue CBackendFileTransfer::InitSFTP()
 
  197        return OnInitReturnValue::Fail;
 
  199    bool bRet = m_pSFTP->open(QIODevice::ReadWrite);
 
  202        szErr = tr(
"Open SFTP fail.") + m_pSFTP->errorString();
 
  203        qCritical(log) << szErr;
 
  205        return OnInitReturnValue::Fail;
 
  209    return OnInitReturnValue::UseOnProcess;
 
  212void CBackendFileTransfer::slotMakeDir(
const QString &szDir)
 
  214    if(szDir.isEmpty()) 
return;
 
  215    CFileTransferEvent* pEvent = 
new CFileTransferEvent(
 
  216        CFileTransferEvent::Command::MakeDir, szDir);
 
  217    QCoreApplication::postEvent(
this, pEvent);
 
  221void CBackendFileTransfer::slotRemoveDir(
const QString &szDir)
 
  223    if(szDir.isEmpty()) 
return;
 
  224    CFileTransferEvent* pEvent = 
new CFileTransferEvent(
 
  225        CFileTransferEvent::Command::RemoveDir, szDir);
 
  226    QCoreApplication::postEvent(
this, pEvent);
 
  230void CBackendFileTransfer::slotRemoveFile(
const QString &szFile)
 
  232    if(szFile.isEmpty()) 
return;
 
  233    CFileTransferEvent* pEvent = 
new CFileTransferEvent(
 
  234        CFileTransferEvent::Command::RemoveFile, szFile);
 
  235    QCoreApplication::postEvent(
this, pEvent);
 
  239void CBackendFileTransfer::slotRename(
const QString &oldName, 
const QString &newName)
 
  241    if(oldName.isEmpty() && newName.isEmpty()) 
return;
 
  242    CFileTransferEvent* pEvent = 
new CFileTransferEvent(
 
  243        CFileTransferEvent::Command::Rename, oldName, newName);
 
  244    QCoreApplication::postEvent(
this, pEvent);
 
  250    if(!p || p->GetPath().isEmpty())
 
  252    QString szPath = p->GetPath();
 
  253    CFileTransferEvent* pEvent = 
new CFileTransferEvent(
 
  254        CFileTransferEvent::Command::GetDir, szPath);
 
  256    QCoreApplication::postEvent(
this, pEvent);
 
  260void CBackendFileTransfer::slotStartFileTransfer(QSharedPointer<CFileTransfer> f)
 
  263    CFileTransferEvent* pEvent = 
new CFileTransferEvent(
 
  264        CFileTransferEvent::Command::StartFileTransfer);
 
  265    pEvent->m_FileTransfer = f;
 
  266    QCoreApplication::postEvent(
this, pEvent);
 
  270void CBackendFileTransfer::slotStopFileTransfer(QSharedPointer<CFileTransfer> f)
 
  273    CFileTransferEvent* pEvent = 
new CFileTransferEvent(
 
  274        CFileTransferEvent::Command::StopFileTransfer);
 
  275    pEvent->m_FileTransfer = f;
 
  276    QCoreApplication::postEvent(
this, pEvent);
 
virtual OnInitReturnValue OnInit() override
Initialization.
 
virtual int OnClean() override
Clean.
 
virtual int OnProcess() override
Specific operation processing of plug-in.
 
virtual int WakeUp()
Wake up.
 
void sigShowMessageBox(const QString &szTitle, const QString &szMessage, const QMessageBox::Icon &icon=QMessageBox::Information)
Trigger the display of a message dialog (QMessageBox) in the main thread from a background thread wit...
 
void sigRunning()
Emitted when the plugin is successfully started.
 
File transfer operate interface.
 
virtual QWidget * GetViewer() override
Get Viewer.