Call: Use signal slots uniformly for calling.
This commit is contained in:
@@ -57,7 +57,7 @@ void ClientCore::UseFrame(QSharedPointer<FrameBuffer> frame)
|
|||||||
switch (frame->type) {
|
switch (frame->type) {
|
||||||
case FrameBufferType::FBT_SER_MSG_ASKCLIENTS: {
|
case FrameBufferType::FBT_SER_MSG_ASKCLIENTS: {
|
||||||
InfoClientVec info = infoUnpack<InfoClientVec>(frame->data);
|
InfoClientVec info = infoUnpack<InfoClientVec>(frame->data);
|
||||||
clientsCall_(info);
|
emit sigClients(info);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FrameBufferType::FBT_SER_MSG_YOURID: {
|
case FrameBufferType::FBT_SER_MSG_YOURID: {
|
||||||
@@ -67,7 +67,7 @@ void ClientCore::UseFrame(QSharedPointer<FrameBuffer> frame)
|
|||||||
}
|
}
|
||||||
case FrameBufferType::FBT_CLI_ANS_DIRFILE: {
|
case FrameBufferType::FBT_CLI_ANS_DIRFILE: {
|
||||||
DirFileInfoVec info = infoUnpack<DirFileInfoVec>(frame->data);
|
DirFileInfoVec info = infoUnpack<DirFileInfoVec>(frame->data);
|
||||||
fileCall_(info);
|
emit sigFiles(info);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FrameBufferType::FBT_CLI_ASK_DIRFILE: {
|
case FrameBufferType::FBT_CLI_ASK_DIRFILE: {
|
||||||
@@ -96,14 +96,51 @@ void ClientCore::UseFrame(QSharedPointer<FrameBuffer> frame)
|
|||||||
case FrameBufferType::FBT_CLI_ANS_HOME: {
|
case FrameBufferType::FBT_CLI_ANS_HOME: {
|
||||||
InfoMsg info = infoUnpack<InfoMsg>(frame->data);
|
InfoMsg info = infoUnpack<InfoMsg>(frame->data);
|
||||||
qInfo() << QString(tr("home: %1")).arg(info.msg);
|
qInfo() << QString(tr("home: %1")).arg(info.msg);
|
||||||
pathCall_(info.msg);
|
emit sigPath(info.msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FrameBufferType::FBT_SER_MSG_FORWARD_FAILED: {
|
case FrameBufferType::FBT_SER_MSG_FORWARD_FAILED: {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case FrameBufferType::FBT_CLI_REQ_SEND: {
|
||||||
|
emit sigReqSend(frame);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FrameBufferType::FBT_CLI_REQ_DOWN: {
|
||||||
|
emit sigReqDown(frame);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FrameBufferType::FBT_CLI_TRANS_DONE: {
|
||||||
|
sigTransDone(frame);
|
||||||
|
break;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FrameBufferType::FBT_CLI_CAN_SEND: {
|
||||||
|
sigCanSend(frame);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FrameBufferType::FBT_CLI_CANOT_SEND: {
|
||||||
|
sigCanotSend(frame);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FBT_CLI_CANOT_DOWN: {
|
||||||
|
sigCanotDown(frame);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FBT_CLI_CAN_DOWN: {
|
||||||
|
sigCanDown(frame);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FBT_CLI_FILE_BUFFER: {
|
||||||
|
sigFileBuffer(frame);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FBT_CLI_TRANS_FAILED: {
|
||||||
|
sigTransFailed(frame);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
frameCall_[static_cast<uint32_t>(frame->type)](frame);
|
qCritical() << QString("unknown frame type: %1").arg(frame->type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,31 +176,11 @@ bool ClientCore::Send(const char* data, qint64 len)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientCore::SetClientsCall(const std::function<void(const InfoClientVec& clients)>& call)
|
|
||||||
{
|
|
||||||
clientsCall_ = call;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClientCore::SetPathCall(const std::function<void(const QString& path)>& call)
|
|
||||||
{
|
|
||||||
pathCall_ = call;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClientCore::SetFileCall(const std::function<void(const DirFileInfoVec& files)>& call)
|
|
||||||
{
|
|
||||||
fileCall_ = call;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClientCore::SetRemoteID(const QString& id)
|
void ClientCore::SetRemoteID(const QString& id)
|
||||||
{
|
{
|
||||||
remoteID_ = id;
|
remoteID_ = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientCore::SetFrameCall(FrameBufferType type, const std::function<void(QSharedPointer<FrameBuffer>)>& call)
|
|
||||||
{
|
|
||||||
frameCall_[type] = call;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString ClientCore::GetRemoteID()
|
QString ClientCore::GetRemoteID()
|
||||||
{
|
{
|
||||||
return remoteID_;
|
return remoteID_;
|
||||||
|
|||||||
@@ -67,6 +67,18 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void sigDisconnect();
|
void sigDisconnect();
|
||||||
|
void sigPath(const QString& path);
|
||||||
|
void sigClients(const InfoClientVec& clients);
|
||||||
|
void sigFiles(const DirFileInfoVec& files);
|
||||||
|
void sigReqSend(QSharedPointer<FrameBuffer> frame);
|
||||||
|
void sigReqDown(QSharedPointer<FrameBuffer> frame);
|
||||||
|
void sigTransDone(QSharedPointer<FrameBuffer> frame);
|
||||||
|
void sigCanSend(QSharedPointer<FrameBuffer> frame);
|
||||||
|
void sigCanotSend(QSharedPointer<FrameBuffer> frame);
|
||||||
|
void sigCanotDown(QSharedPointer<FrameBuffer> frame);
|
||||||
|
void sigCanDown(QSharedPointer<FrameBuffer> frame);
|
||||||
|
void sigFileBuffer(QSharedPointer<FrameBuffer> frame);
|
||||||
|
void sigTransFailed(QSharedPointer<FrameBuffer> frame);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onReadyRead();
|
void onReadyRead();
|
||||||
@@ -76,10 +88,6 @@ private:
|
|||||||
void UseFrame(QSharedPointer<FrameBuffer> frame);
|
void UseFrame(QSharedPointer<FrameBuffer> frame);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void SetClientsCall(const std::function<void(const InfoClientVec& clients)>& call);
|
|
||||||
void SetPathCall(const std::function<void(const QString& path)>& call);
|
|
||||||
void SetFileCall(const std::function<void(const DirFileInfoVec& files)>& call);
|
|
||||||
void SetFrameCall(FrameBufferType type, const std::function<void(QSharedPointer<FrameBuffer>)>& call);
|
|
||||||
void SetRemoteID(const QString& id);
|
void SetRemoteID(const QString& id);
|
||||||
QString GetRemoteID();
|
QString GetRemoteID();
|
||||||
QString GetOwnID();
|
QString GetOwnID();
|
||||||
@@ -94,11 +102,6 @@ public:
|
|||||||
QByteArray recvBuffer_;
|
QByteArray recvBuffer_;
|
||||||
|
|
||||||
LocalFile localFile_;
|
LocalFile localFile_;
|
||||||
|
|
||||||
std::function<void(const QString& path)> pathCall_;
|
|
||||||
std::function<void(const InfoClientVec& clients)> clientsCall_;
|
|
||||||
std::function<void(const DirFileInfoVec& files)> fileCall_;
|
|
||||||
|
|
||||||
std::array<std::function<void(QSharedPointer<FrameBuffer>)>, 256> frameCall_;
|
std::array<std::function<void(QSharedPointer<FrameBuffer>)>, 256> frameCall_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -124,8 +127,8 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QString ip_;
|
QString ip_;
|
||||||
qint16 port_;
|
qint16 port_{};
|
||||||
ClientCore* core_;
|
ClientCore* core_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CLIENTCORE_H
|
#endif // CLIENTCORE_H
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
FileTrans::FileTrans(ClientCore* clientCore) : clientCore_(clientCore)
|
FileTrans::FileTrans(ClientCore* clientCore) : clientCore_(clientCore)
|
||||||
{
|
{
|
||||||
RegisterFrameCall();
|
RegisterSignal();
|
||||||
downTask_ = QSharedPointer<DoTransTask>::create();
|
downTask_ = QSharedPointer<DoTransTask>::create();
|
||||||
sendTask_ = QSharedPointer<DoTransTask>::create();
|
sendTask_ = QSharedPointer<DoTransTask>::create();
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,8 @@ void FileTrans::ReqSendFile(const TransTask& task)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!clientCore_->Send<InfoMsg>(info, FBT_CLI_REQ_SEND, task.remoteId)) {
|
auto frame = clientCore_->GetBuffer(info, FBT_CLI_REQ_SEND, task.remoteId);
|
||||||
|
if (!ClientCore::asyncInvoke(clientCore_, [this, frame]() { return clientCore_->Send(frame); })) {
|
||||||
qCritical() << QString(tr("send req send failed: %1")).arg(info.msg);
|
qCritical() << QString(tr("send req send failed: %1")).arg(info.msg);
|
||||||
sendTask_->state = TaskState::STATE_NONE;
|
sendTask_->state = TaskState::STATE_NONE;
|
||||||
sendTask_->file.close();
|
sendTask_->file.close();
|
||||||
@@ -68,7 +69,8 @@ void FileTrans::ReqDownFile(const TransTask& task)
|
|||||||
downTask_->state = TaskState::STATE_NONE;
|
downTask_->state = TaskState::STATE_NONE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!clientCore_->Send<InfoMsg>(info, FBT_CLI_REQ_DOWN, task.remoteId)) {
|
auto frame = clientCore_->GetBuffer(info, FBT_CLI_REQ_DOWN, task.remoteId);
|
||||||
|
if (!ClientCore::asyncInvoke(clientCore_, [this, frame]() { return clientCore_->Send(frame); })) {
|
||||||
qCritical() << QString(tr("send req send failed: %1")).arg(info.msg);
|
qCritical() << QString(tr("send req send failed: %1")).arg(info.msg);
|
||||||
sendTask_->state = TaskState::STATE_NONE;
|
sendTask_->state = TaskState::STATE_NONE;
|
||||||
sendTask_->file.close();
|
sendTask_->file.close();
|
||||||
@@ -97,17 +99,17 @@ qint32 FileTrans::GetDownProgress()
|
|||||||
return per;
|
return per;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileTrans::RegisterFrameCall()
|
void FileTrans::RegisterSignal()
|
||||||
{
|
{
|
||||||
clientCore_->SetFrameCall(FBT_CLI_REQ_SEND, [this](QSharedPointer<FrameBuffer> frame) { fbtReqSend(frame); });
|
connect(clientCore_, &ClientCore::sigReqSend, this, [this](QSharedPointer<FrameBuffer> frame) { fbtReqSend(frame); });
|
||||||
clientCore_->SetFrameCall(FBT_CLI_REQ_DOWN, [this](QSharedPointer<FrameBuffer> frame) { fbtReqDown(frame); });
|
connect(clientCore_, &ClientCore::sigReqDown, this, [this](QSharedPointer<FrameBuffer> frame) { fbtReqDown(frame); });
|
||||||
clientCore_->SetFrameCall(FBT_CLI_TRANS_DONE, [this](QSharedPointer<FrameBuffer> frame) { fbtTransDone(frame); });
|
connect(clientCore_, &ClientCore::sigTransDone, this, [this](QSharedPointer<FrameBuffer> frame) { fbtTransDone(frame); });
|
||||||
clientCore_->SetFrameCall(FBT_CLI_CAN_SEND, [this](QSharedPointer<FrameBuffer> frame) { fbtCanSend(frame); });
|
connect(clientCore_, &ClientCore::sigCanSend, this, [this](QSharedPointer<FrameBuffer> frame) { fbtCanSend(frame); });
|
||||||
clientCore_->SetFrameCall(FBT_CLI_CANOT_SEND, [this](QSharedPointer<FrameBuffer> frame) { fbtCanotSend(frame); });
|
connect(clientCore_, &ClientCore::sigCanotSend, this, [this](QSharedPointer<FrameBuffer> frame) { fbtCanotSend(frame); });
|
||||||
clientCore_->SetFrameCall(FBT_CLI_CANOT_DOWN, [this](QSharedPointer<FrameBuffer> frame) { fbtCanotDown(frame); });
|
connect(clientCore_, &ClientCore::sigCanotDown, this, [this](QSharedPointer<FrameBuffer> frame) { fbtCanotDown(frame); });
|
||||||
clientCore_->SetFrameCall(FBT_CLI_CAN_DOWN, [this](QSharedPointer<FrameBuffer> frame) { fbtCanDown(frame); });
|
connect(clientCore_, &ClientCore::sigCanDown, this, [this](QSharedPointer<FrameBuffer> frame) { fbtCanDown(frame); });
|
||||||
clientCore_->SetFrameCall(FBT_CLI_FILE_BUFFER, [this](QSharedPointer<FrameBuffer> frame) { fbtFileBuffer(frame); });
|
connect(clientCore_, &ClientCore::sigFileBuffer, this, [this](QSharedPointer<FrameBuffer> frame) { fbtFileBuffer(frame); });
|
||||||
clientCore_->SetFrameCall(FBT_CLI_TRANS_FAILED, [this](QSharedPointer<FrameBuffer> frame) { fbtTransFailed(frame); });
|
connect(clientCore_, &ClientCore::sigTransFailed, this, [this](QSharedPointer<FrameBuffer> frame) { fbtTransFailed(frame); });
|
||||||
}
|
}
|
||||||
|
|
||||||
// The other party requests to send, prepare to receive.
|
// The other party requests to send, prepare to receive.
|
||||||
@@ -121,7 +123,8 @@ void FileTrans::fbtReqSend(QSharedPointer<FrameBuffer> frame)
|
|||||||
// recv is single thread recv, judge idle
|
// recv is single thread recv, judge idle
|
||||||
if (downTask_->state == TaskState::STATE_RUNNING) {
|
if (downTask_->state == TaskState::STATE_RUNNING) {
|
||||||
info.msg = QString(tr("busy..."));
|
info.msg = QString(tr("busy..."));
|
||||||
clientCore_->Send<InfoMsg>(info, FBT_CLI_CANOT_SEND, frame->fid);
|
auto f = clientCore_->GetBuffer(info, FBT_CLI_CANOT_SEND, frame->fid);
|
||||||
|
ClientCore::asyncInvoke(clientCore_, [this, f]() { return clientCore_->Send(f); });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,8 +134,9 @@ void FileTrans::fbtReqSend(QSharedPointer<FrameBuffer> frame)
|
|||||||
if (!downTask_->file.open(QIODevice::WriteOnly)) {
|
if (!downTask_->file.open(QIODevice::WriteOnly)) {
|
||||||
info.msg = QString(tr("open file failed: %1")).arg(newerPath);
|
info.msg = QString(tr("open file failed: %1")).arg(newerPath);
|
||||||
qCritical() << info.msg;
|
qCritical() << info.msg;
|
||||||
if (!clientCore_->Send<InfoMsg>(info, FBT_CLI_CANOT_SEND, frame->fid)) {
|
auto f = clientCore_->GetBuffer(info, FBT_CLI_CANOT_SEND, frame->fid);
|
||||||
qCritical() << QString(tr("open recv file:%2 failed, and reply %2 failed.")).arg(info.msg, frame->fid);
|
if (!ClientCore::asyncInvoke(clientCore_, [this, f]() { return clientCore_->Send(f); })) {
|
||||||
|
qCritical() << QString(tr("open recv file:%2 failed, and reply %2 failed.")).arg(info.msg, f->fid);
|
||||||
downTask_->file.close();
|
downTask_->file.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -145,8 +149,7 @@ void FileTrans::fbtReqSend(QSharedPointer<FrameBuffer> frame)
|
|||||||
|
|
||||||
info.msg = QString(tr("open recv file success: %1")).arg(newerPath);
|
info.msg = QString(tr("open recv file success: %1")).arg(newerPath);
|
||||||
auto f = clientCore_->GetBuffer(info, FBT_CLI_CAN_SEND, frame->fid);
|
auto f = clientCore_->GetBuffer(info, FBT_CLI_CAN_SEND, frame->fid);
|
||||||
auto sendRet = ClientCore::asyncInvoke(clientCore_, [this, f]() { return clientCore_->Send(f); });
|
if (!ClientCore::asyncInvoke(clientCore_, [this, f]() { return clientCore_->Send(f); })) {
|
||||||
if (!sendRet) {
|
|
||||||
qCritical() << QString(tr("open recv file:%2 success, but reply %2 failed.")).arg(info.msg, frame->fid);
|
qCritical() << QString(tr("open recv file:%2 success, but reply %2 failed.")).arg(info.msg, frame->fid);
|
||||||
downTask_->file.close();
|
downTask_->file.close();
|
||||||
return;
|
return;
|
||||||
@@ -182,7 +185,8 @@ void FileTrans::fbtTransDone(QSharedPointer<FrameBuffer> frame)
|
|||||||
downTask_->file.close();
|
downTask_->file.close();
|
||||||
downTask_->state = TaskState::STATE_FINISH;
|
downTask_->state = TaskState::STATE_FINISH;
|
||||||
qInfo() << QString(tr("recv file:%1 success.")).arg(downTask_->file.fileName());
|
qInfo() << QString(tr("recv file:%1 success.")).arg(downTask_->file.fileName());
|
||||||
clientCore_->Send<InfoMsg>(info, FBT_CLI_CAN_DOWN, frame->fid);
|
auto f = clientCore_->GetBuffer(info, FBT_CLI_CAN_DOWN, frame->fid);
|
||||||
|
ClientCore::asyncInvoke(clientCore_, [this, f]() { return clientCore_->Send(f); });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
qCritical() << QString(tr("recv file:%1 done sigal, but file not opened.")).arg(info.msg);
|
qCritical() << QString(tr("recv file:%1 done sigal, but file not opened.")).arg(info.msg);
|
||||||
@@ -216,7 +220,8 @@ void FileTrans::fbtFileBuffer(QSharedPointer<FrameBuffer> frame)
|
|||||||
downTask_->state = TaskState::STATE_FAILED;
|
downTask_->state = TaskState::STATE_FAILED;
|
||||||
InfoMsg info;
|
InfoMsg info;
|
||||||
info.msg = downTask_->file.errorString();
|
info.msg = downTask_->file.errorString();
|
||||||
clientCore_->Send<InfoMsg>(info, FBT_CLI_TRANS_FAILED, frame->fid);
|
auto f = clientCore_->GetBuffer(info, FBT_CLI_TRANS_FAILED, frame->fid);
|
||||||
|
ClientCore::asyncInvoke(clientCore_, [this, f]() { return clientCore_->Send(f); });
|
||||||
downTask_->file.close();
|
downTask_->file.close();
|
||||||
}
|
}
|
||||||
downTask_->tranSize += ws;
|
downTask_->tranSize += ws;
|
||||||
@@ -257,21 +262,6 @@ void FileTrans::SendFile(const QSharedPointer<DoTransTask>& task)
|
|||||||
sendThread->run();
|
sendThread->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
QFuture<bool> FileTrans::sendFrameAsync(const QSharedPointer<FrameBuffer>& frame)
|
|
||||||
{
|
|
||||||
auto promise = QSharedPointer<QPromise<bool>>::create();
|
|
||||||
QFuture<bool> future = promise->future();
|
|
||||||
QMetaObject::invokeMethod(
|
|
||||||
clientCore_,
|
|
||||||
[this, frame, promise]() mutable {
|
|
||||||
bool ret = clientCore_->Send(frame);
|
|
||||||
promise->addResult(ret);
|
|
||||||
promise->finish();
|
|
||||||
},
|
|
||||||
Qt::QueuedConnection);
|
|
||||||
return future;
|
|
||||||
}
|
|
||||||
|
|
||||||
SendThread::SendThread(ClientCore* clientCore) : cliCore_(clientCore)
|
SendThread::SendThread(ClientCore* clientCore) : cliCore_(clientCore)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,9 +81,8 @@ private:
|
|||||||
void fbtTransFailed(QSharedPointer<FrameBuffer> frame);
|
void fbtTransFailed(QSharedPointer<FrameBuffer> frame);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void RegisterFrameCall();
|
void RegisterSignal();
|
||||||
void SendFile(const QSharedPointer<DoTransTask>& task);
|
void SendFile(const QSharedPointer<DoTransTask>& task);
|
||||||
QFuture<bool> sendFrameAsync(const QSharedPointer<FrameBuffer>& frame);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSharedPointer<DoTransTask> downTask_;
|
QSharedPointer<DoTransTask> downTask_;
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
#include "RemoteFile.h"
|
#include "RemoteFile.h"
|
||||||
|
|
||||||
#include <InfoPack.hpp>
|
#include <InfoPack.hpp>
|
||||||
|
|
||||||
#include "LocalFile.h"
|
#include "LocalFile.h"
|
||||||
|
|
||||||
|
RemoteFile::RemoteFile(QObject* parent) : DirFileHelper(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void RemoteFile::setClientCore(ClientCore* cliCore)
|
void RemoteFile::setClientCore(ClientCore* cliCore)
|
||||||
{
|
{
|
||||||
cliCore_ = cliCore;
|
cliCore_ = cliCore;
|
||||||
cliCore_->SetPathCall(pathCall_);
|
connect(cliCore_, &ClientCore::sigPath, this, [this](const QString& path) { sigHome(path); });
|
||||||
cliCore_->SetFileCall(fileCall_);
|
connect(cliCore_, &ClientCore::sigFiles, this, [this](const DirFileInfoVec& files) { sigDirFile(files); });
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RemoteFile::GetHome()
|
bool RemoteFile::GetHome()
|
||||||
@@ -21,6 +25,7 @@ bool RemoteFile::GetHome()
|
|||||||
bool RemoteFile::GetDirFile(const QString& dir)
|
bool RemoteFile::GetDirFile(const QString& dir)
|
||||||
{
|
{
|
||||||
InfoMsg info;
|
InfoMsg info;
|
||||||
|
info.msg = dir;
|
||||||
auto frame = cliCore_->GetBuffer(info, FBT_CLI_ASK_DIRFILE, cliCore_->GetRemoteID());
|
auto frame = cliCore_->GetBuffer(info, FBT_CLI_ASK_DIRFILE, cliCore_->GetRemoteID());
|
||||||
return ClientCore::asyncInvoke(cliCore_, [this, frame]() { return cliCore_->Send(frame); });
|
return ClientCore::asyncInvoke(cliCore_, [this, frame]() { return cliCore_->Send(frame); });
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#ifndef REMOTE_FILE_H
|
#ifndef REMOTE_FILE_H
|
||||||
#define REMOTE_FILE_H
|
#define REMOTE_FILE_H
|
||||||
|
|
||||||
#include <InfoMsg.h>
|
#include <InfoMsg.h>
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
class RemoteFile : public DirFileHelper
|
class RemoteFile : public DirFileHelper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RemoteFile() = default;
|
RemoteFile(QObject* parent = nullptr);
|
||||||
~RemoteFile() override = default;
|
~RemoteFile() override = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -20,7 +20,7 @@ public:
|
|||||||
bool GetDirFile(const QString& dir) override;
|
bool GetDirFile(const QString& dir) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ClientCore* cliCore_;
|
ClientCore* cliCore_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // REMOTE_FILE_H
|
#endif // REMOTE_FILE_H
|
||||||
@@ -21,7 +21,7 @@ Connecter::~Connecter()
|
|||||||
void Connecter::SetClientCore(ClientCore* clientCore)
|
void Connecter::SetClientCore(ClientCore* clientCore)
|
||||||
{
|
{
|
||||||
clientCore_ = clientCore;
|
clientCore_ = clientCore;
|
||||||
clientCore_->SetClientsCall([this](const InfoClientVec& clients) { HandleClients(clients); });
|
connect(clientCore_, &ClientCore::sigClients, this, &Connecter::HandleClients);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connecter::SetRemoteCall(const std::function<void(const QString& id)>& call)
|
void Connecter::SetRemoteCall(const std::function<void(const QString& id)>& call)
|
||||||
|
|||||||
@@ -26,13 +26,9 @@ void FileManager::SetModeStr(const QString& modeStr, int type, ClientCore* clien
|
|||||||
ui->lbMode->setText(modeStr);
|
ui->lbMode->setText(modeStr);
|
||||||
if (type == 0) {
|
if (type == 0) {
|
||||||
fileHelper_ = std::make_shared<LocalFile>();
|
fileHelper_ = std::make_shared<LocalFile>();
|
||||||
fileHelper_->registerPathCall([this](const QString& path) { ShowPath(path); });
|
|
||||||
fileHelper_->registerFileCall([this](const DirFileInfoVec& info) { ShowFile(info); });
|
|
||||||
} else {
|
} else {
|
||||||
cliCore_ = clientCore;
|
cliCore_ = clientCore;
|
||||||
auto remotePtr = std::make_shared<RemoteFile>();
|
auto remotePtr = std::make_shared<RemoteFile>();
|
||||||
remotePtr->registerPathCall([this](const QString& path) { ShowPath(path); });
|
|
||||||
remotePtr->registerFileCall([this](const DirFileInfoVec& info) { ShowFile(info); });
|
|
||||||
remotePtr->setClientCore(clientCore);
|
remotePtr->setClientCore(clientCore);
|
||||||
ui->tableWidget->setIsRemote(true);
|
ui->tableWidget->setIsRemote(true);
|
||||||
ui->tableWidget->setOwnIDCall([this]() { return cliCore_->GetOwnID(); });
|
ui->tableWidget->setOwnIDCall([this]() { return cliCore_->GetOwnID(); });
|
||||||
@@ -40,6 +36,9 @@ void FileManager::SetModeStr(const QString& modeStr, int type, ClientCore* clien
|
|||||||
fileHelper_ = remotePtr;
|
fileHelper_ = remotePtr;
|
||||||
}
|
}
|
||||||
ui->tableWidget->setBasePathCall([this]() { return curRoot_; });
|
ui->tableWidget->setBasePathCall([this]() { return curRoot_; });
|
||||||
|
|
||||||
|
connect(fileHelper_.get(), &DirFileHelper::sigHome, this, &FileManager::ShowPath);
|
||||||
|
connect(fileHelper_.get(), &DirFileHelper::sigDirFile, this, &FileManager::ShowFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileManager::SetOtherSideCall(const std::function<QString()>& call)
|
void FileManager::SetOtherSideCall(const std::function<QString()>& call)
|
||||||
@@ -92,6 +91,7 @@ void FileManager::InitMenu(bool remote)
|
|||||||
|
|
||||||
void FileManager::ShowPath(const QString& path)
|
void FileManager::ShowPath(const QString& path)
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker(&cbMut_);
|
||||||
int existingIndex = ui->comboBox->findText(path);
|
int existingIndex = ui->comboBox->findText(path);
|
||||||
if (existingIndex != -1) {
|
if (existingIndex != -1) {
|
||||||
ui->comboBox->removeItem(existingIndex);
|
ui->comboBox->removeItem(existingIndex);
|
||||||
@@ -104,8 +104,8 @@ void FileManager::ShowPath(const QString& path)
|
|||||||
|
|
||||||
void FileManager::ShowFile(const DirFileInfoVec& info)
|
void FileManager::ShowFile(const DirFileInfoVec& info)
|
||||||
{
|
{
|
||||||
QAbstractItemModel* const mdl = ui->tableWidget->model();
|
QMutexLocker locker(&tbMut_);
|
||||||
mdl->removeRows(0, mdl->rowCount());
|
ui->tableWidget->setRowCount(0);
|
||||||
ui->tableWidget->setRowCount(info.vec.size());
|
ui->tableWidget->setRowCount(info.vec.size());
|
||||||
|
|
||||||
for (int i = 0; i < info.vec.size(); ++i) {
|
for (int i = 0; i < info.vec.size(); ++i) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <InfoDirFile.h>
|
#include <InfoDirFile.h>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <Util.h>
|
#include <Util.h>
|
||||||
|
#include <QMutex>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
@@ -45,6 +46,8 @@ private:
|
|||||||
QString curRoot_;
|
QString curRoot_;
|
||||||
QMenu* menu_;
|
QMenu* menu_;
|
||||||
ClientCore* cliCore_;
|
ClientCore* cliCore_;
|
||||||
|
QMutex cbMut_;
|
||||||
|
QMutex tbMut_;
|
||||||
std::shared_ptr<DirFileHelper> fileHelper_;
|
std::shared_ptr<DirFileHelper> fileHelper_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,9 @@ void frelayGUI::ControlLayout()
|
|||||||
void frelayGUI::ControlMsgHander(QtMsgType type, const QMessageLogContext& context, const QString& msg)
|
void frelayGUI::ControlMsgHander(QtMsgType type, const QMessageLogContext& context, const QString& msg)
|
||||||
{
|
{
|
||||||
Q_UNUSED(context);
|
Q_UNUSED(context);
|
||||||
|
if (!logPrint) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case QtDebugMsg:
|
case QtDebugMsg:
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
#include "LocalFile.h"
|
#include "LocalFile.h"
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
|
||||||
|
LocalFile::LocalFile(QObject* parent) : DirFileHelper(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
bool LocalFile::GetHome()
|
bool LocalFile::GetHome()
|
||||||
{
|
{
|
||||||
auto home = Util::GetUserHome();
|
auto home = Util::GetUserHome();
|
||||||
pathCall_(home);
|
emit sigHome(home);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,7 +21,7 @@ bool LocalFile::GetDirFile(const QString& dir)
|
|||||||
if (!GetDirFile(dir, vec)) {
|
if (!GetDirFile(dir, vec)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
fileCall_(vec);
|
emit sigDirFile(vec);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#ifndef LOCALFILE_H
|
#ifndef LOCALFILE_H
|
||||||
#define LOCALFILE_H
|
#define LOCALFILE_H
|
||||||
|
|
||||||
#include <InfoDirFile.h>
|
#include <InfoDirFile.h>
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
class LocalFile : public DirFileHelper
|
class LocalFile : public DirFileHelper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LocalFile() = default;
|
LocalFile(QObject* parent = nullptr);
|
||||||
~LocalFile() override = default;
|
~LocalFile() override = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -109,12 +109,7 @@ QString DirFileHelper::GetErr() const
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirFileHelper::registerPathCall(const std::function<void(const QString& path)>& call)
|
DirFileHelper::DirFileHelper(QObject* parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
pathCall_ = call;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DirFileHelper::registerFileCall(const std::function<void(const DirFileInfoVec& vec)>& call)
|
|
||||||
{
|
|
||||||
fileCall_ = call;
|
|
||||||
}
|
}
|
||||||
10
Util/Util.h
10
Util/Util.h
@@ -22,18 +22,18 @@ class DirFileHelper : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
DirFileHelper() = default;
|
DirFileHelper(QObject* parent = nullptr);
|
||||||
virtual ~DirFileHelper() = default;
|
virtual ~DirFileHelper() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QString GetErr() const;
|
QString GetErr() const;
|
||||||
void registerPathCall(const std::function<void(const QString& path)>& call);
|
|
||||||
void registerFileCall(const std::function<void(const DirFileInfoVec& vec)>& call);
|
signals:
|
||||||
|
void sigHome(const QString& path);
|
||||||
|
void sigDirFile(const DirFileInfoVec& dirFile);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString err_;
|
QString err_;
|
||||||
std::function<void(const QString& path)> pathCall_;
|
|
||||||
std::function<void(const DirFileInfoVec& info)> fileCall_;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual bool GetHome() = 0;
|
virtual bool GetHome() = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user