file: get remote file success.
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
#include "ClientCore.h"
|
||||
|
||||
#include <InfoMsg.h>
|
||||
#include <InfoPack.hpp>
|
||||
#include <QDebug>
|
||||
|
||||
ClientCore::ClientCore(QObject* parent) : QObject(parent)
|
||||
@@ -66,6 +64,41 @@ void ClientCore::UseFrame(QSharedPointer<FrameBuffer> frame)
|
||||
qInfo() << QString(tr("own id: %1")).arg(ownID_);
|
||||
break;
|
||||
}
|
||||
case FrameBufferType::FBT_CLI_ANS_DIRFILE: {
|
||||
DirFileInfoVec info = infoUnpack<DirFileInfoVec>(frame->data);
|
||||
fileCall_(info);
|
||||
break;
|
||||
}
|
||||
case FrameBufferType::FBT_CLI_ASK_DIRFILE: {
|
||||
DirFileInfoVec vec;
|
||||
InfoMsg info = infoUnpack<InfoMsg>(frame->data);
|
||||
vec.root = info.msg;
|
||||
if (!localFile_.GetDirFile(info.msg, vec)) {
|
||||
qWarning() << QString(tr("get dir file failed use %1")).arg(info.msg);
|
||||
return;
|
||||
}
|
||||
if (!Send<DirFileInfoVec>(vec, FBT_CLI_ANS_DIRFILE, frame->fid)) {
|
||||
qCritical() << QString(tr("send dir file result failed."));
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FrameBufferType::FBT_CLI_ASK_HOME: {
|
||||
InfoMsg info;
|
||||
info.msg = Util::GetUserHome();
|
||||
auto data = infoPack<InfoMsg>(info);
|
||||
if (!Send<InfoMsg>(info, FBT_CLI_ANS_HOME, frame->fid)) {
|
||||
qCritical() << QString(tr("send home failed."));
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FrameBufferType::FBT_CLI_ANS_HOME: {
|
||||
InfoMsg info = infoUnpack<InfoMsg>(frame->data);
|
||||
qInfo() << QString(tr("home: %1")).arg(info.msg);
|
||||
pathCall_(info.msg);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
qWarning() << QString(tr("unknown frame type: %1")).arg(frame->type);
|
||||
break;
|
||||
@@ -115,6 +148,7 @@ void ClientCore::SetFileCall(const std::function<void(const DirFileInfoVec& file
|
||||
|
||||
void ClientCore::SetRemoteID(const QString& id)
|
||||
{
|
||||
remoteID_ = id;
|
||||
}
|
||||
|
||||
QString ClientCore::GetRemoteID()
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
|
||||
#include <InfoClient.h>
|
||||
#include <InfoDirFile.h>
|
||||
#include <InfoMsg.h>
|
||||
#include <InfoPack.hpp>
|
||||
#include <LocalFile.h>
|
||||
#include <Protocol.h>
|
||||
#include <QDataStream>
|
||||
#include <QHostAddress>
|
||||
@@ -24,6 +27,14 @@ public:
|
||||
void Disconnect();
|
||||
bool Send(QSharedPointer<FrameBuffer> frame);
|
||||
bool Send(const char* data, qint64 len);
|
||||
template <typename T> bool Send(const T& info, FrameBufferType type, const QString& tid)
|
||||
{
|
||||
auto f = QSharedPointer<FrameBuffer>::create();
|
||||
f->tid = tid;
|
||||
f->data = infoPack<T>(info);
|
||||
f->type = type;
|
||||
return Send(f);
|
||||
}
|
||||
|
||||
private:
|
||||
void onReadyRead();
|
||||
@@ -46,6 +57,8 @@ public:
|
||||
QTcpSocket* socket_;
|
||||
QByteArray recvBuffer_;
|
||||
|
||||
LocalFile localFile_;
|
||||
|
||||
std::function<void(const QString& path)> pathCall_;
|
||||
std::function<void(const InfoClientVec& clients)> clientsCall_;
|
||||
std::function<void(const DirFileInfoVec& files)> fileCall_;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "RemoteFile.h"
|
||||
|
||||
#include <InfoPack.hpp>
|
||||
|
||||
#include "LocalFile.h"
|
||||
|
||||
void RemoteFile::setClientCore(ClientCore* cliCore)
|
||||
@@ -13,19 +14,12 @@ void RemoteFile::setClientCore(ClientCore* cliCore)
|
||||
bool RemoteFile::GetHome()
|
||||
{
|
||||
InfoMsg info;
|
||||
auto frame = QSharedPointer<FrameBuffer>::create();
|
||||
frame->data = infoPack(info);
|
||||
frame->type = FBT_CLI_ASK_HOME;
|
||||
frame->tid = cliCore_->GetRemoteID();
|
||||
return cliCore_->Send(frame);
|
||||
return cliCore_->Send<InfoMsg>(info, FBT_CLI_ASK_HOME, cliCore_->GetRemoteID());
|
||||
}
|
||||
|
||||
bool RemoteFile::GetDirFile(const QString& dir)
|
||||
{
|
||||
InfoMsg info;
|
||||
auto frame = QSharedPointer<FrameBuffer>::create();
|
||||
frame->data = infoPack(info);
|
||||
frame->type = FBT_CLI_ASK_DIRFILE;
|
||||
frame->tid = cliCore_->GetRemoteID();
|
||||
return cliCore_->Send(frame);
|
||||
info.msg = dir;
|
||||
return cliCore_->Send<InfoMsg>(info, FBT_CLI_ASK_DIRFILE, cliCore_->GetRemoteID());
|
||||
}
|
||||
Reference in New Issue
Block a user