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:
95 m_pSFTP->slotGetDir(pEvent->m_pRemoteFileSystem);
98 case CFileTransferEvent::Command::StartFileTransfer:
102 m_pSFTP->slotStartFileTransfer(pEvent->m_FileTransfer);
106 case CFileTransferEvent::Command::StopFileTransfer:
110 m_pSFTP->slotStopFileTransfer(pEvent->m_FileTransfer);
118 return CBackend::event(event);
123 OnInitReturnValue nRet = OnInitReturnValue::Fail;
124 if(m_pPara->GetProtocol() == CParameterFileTransfer::Protocol::SFTP)
135 m_pSFTP->deleteLater();
147 nRet = m_pSFTP->Process();
160 Qt::DirectConnection);
162 check = connect(
this, SIGNAL(sigGetDir(
CRemoteFileSystem*, QVector<QSharedPointer<CRemoteFileSystem> >,
bool)),
163 pForm, SIGNAL(sigGetDir(
CRemoteFileSystem*, QVector<QSharedPointer<CRemoteFileSystem> >,
bool)));
165 check = connect(pForm, SIGNAL(sigMakeDir(
const QString&)),
166 this, SLOT(slotMakeDir(
const QString&)));
168 check = connect(pForm, SIGNAL(sigRemoveDir(
const QString&)),
169 this, SLOT(slotRemoveDir(
const QString&)));
171 check = connect(pForm, SIGNAL(sigRemoveFile(
const QString&)),
172 this, SLOT(slotRemoveFile(
const QString&)));
174 check = connect(pForm, SIGNAL(sigRename(
const QString&,
const QString&)),
175 this, SLOT(slotRename(
const QString&,
const QString&)));
177 check = connect(pForm, SIGNAL(sigStartFileTransfer(QSharedPointer<CFileTransfer>)),
178 this, SLOT(slotStartFileTransfer(QSharedPointer<CFileTransfer>)));
180 check = connect(pForm, SIGNAL(sigStopFileTransfer(QSharedPointer<CFileTransfer>)),
181 this, SLOT(slotStopFileTransfer(QSharedPointer<CFileTransfer>)));
183 check = connect(
this, SIGNAL(sigFileTransferUpdate(QSharedPointer<CFileTransfer>)),
184 pForm, SLOT(slotFileTransferUpdate(QSharedPointer<CFileTransfer>)));
189CBackendFileTransfer::OnInitReturnValue CBackendFileTransfer::InitSFTP()
195 return OnInitReturnValue::Fail;
197 bool bRet = m_pSFTP->open(QIODevice::ReadWrite);
199 return OnInitReturnValue::Fail;
202 return OnInitReturnValue::UseOnProcess;
205void CBackendFileTransfer::slotMakeDir(
const QString &szDir)
207 if(szDir.isEmpty())
return;
208 CFileTransferEvent* pEvent =
new CFileTransferEvent(
209 CFileTransferEvent::Command::MakeDir, szDir);
210 QCoreApplication::postEvent(
this, pEvent);
214void CBackendFileTransfer::slotRemoveDir(
const QString &szDir)
216 if(szDir.isEmpty())
return;
217 CFileTransferEvent* pEvent =
new CFileTransferEvent(
218 CFileTransferEvent::Command::RemoveDir, szDir);
219 QCoreApplication::postEvent(
this, pEvent);
223void CBackendFileTransfer::slotRemoveFile(
const QString &szFile)
225 if(szFile.isEmpty())
return;
226 CFileTransferEvent* pEvent =
new CFileTransferEvent(
227 CFileTransferEvent::Command::RemoveFile, szFile);
228 QCoreApplication::postEvent(
this, pEvent);
232void CBackendFileTransfer::slotRename(
const QString &oldName,
const QString &newName)
234 if(oldName.isEmpty() && newName.isEmpty())
return;
235 CFileTransferEvent* pEvent =
new CFileTransferEvent(
236 CFileTransferEvent::Command::Rename, oldName, newName);
237 QCoreApplication::postEvent(
this, pEvent);
243 if(!p || p->GetPath().isEmpty())
245 QString szPath = p->GetPath();
246 CFileTransferEvent* pEvent =
new CFileTransferEvent(
247 CFileTransferEvent::Command::GetDir, szPath);
249 QCoreApplication::postEvent(
this, pEvent);
253void CBackendFileTransfer::slotStartFileTransfer(QSharedPointer<CFileTransfer> f)
256 CFileTransferEvent* pEvent =
new CFileTransferEvent(
257 CFileTransferEvent::Command::StartFileTransfer);
258 pEvent->m_FileTransfer = f;
259 QCoreApplication::postEvent(
this, pEvent);
263void CBackendFileTransfer::slotStopFileTransfer(QSharedPointer<CFileTransfer> f)
266 CFileTransferEvent* pEvent =
new CFileTransferEvent(
267 CFileTransferEvent::Command::StopFileTransfer);
268 pEvent->m_FileTransfer = f;
269 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 sigRunning()
Emitted when the plugin is successfully started.
File transfer operate interface.
virtual QWidget * GetViewer() override
Get Viewer.