glodata: add global struct data.
This commit is contained in:
@@ -8,7 +8,7 @@ ClientCore::ClientCore(QObject* parent) : QObject(parent)
|
|||||||
|
|
||||||
void ClientCore::Instance()
|
void ClientCore::Instance()
|
||||||
{
|
{
|
||||||
qDebug() << "Instance() thread:" << QThread::currentThread();
|
//qDebug() << "Instance() thread:" << QThread::currentThread();
|
||||||
socket_ = new QTcpSocket(this);
|
socket_ = new QTcpSocket(this);
|
||||||
connect(socket_, &QTcpSocket::readyRead, this, &ClientCore::onReadyRead);
|
connect(socket_, &QTcpSocket::readyRead, this, &ClientCore::onReadyRead);
|
||||||
connect(socket_, &QTcpSocket::disconnected, this, &ClientCore::onDisconnected);
|
connect(socket_, &QTcpSocket::disconnected, this, &ClientCore::onDisconnected);
|
||||||
@@ -237,7 +237,7 @@ SocketWorker::~SocketWorker()
|
|||||||
|
|
||||||
void SocketWorker::run()
|
void SocketWorker::run()
|
||||||
{
|
{
|
||||||
qDebug() << "SocketWorker thread:" << QThread::currentThread();
|
//qDebug() << "SocketWorker thread:" << QThread::currentThread();
|
||||||
core_->Instance();
|
core_->Instance();
|
||||||
exec();
|
exec();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ void Compare::InitTabWidget()
|
|||||||
ui->tableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
|
ui->tableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
|
||||||
ui->tableWidget->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
|
ui->tableWidget->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);
|
||||||
|
|
||||||
ui->tableWidget->setDragEnabled(true);
|
ui->tableWidget->setDragEnabled(false);
|
||||||
ui->tableWidget->viewport()->setAcceptDrops(true);
|
ui->tableWidget->viewport()->setAcceptDrops(true);
|
||||||
ui->tableWidget->setDropIndicatorShown(true);
|
ui->tableWidget->setDropIndicatorShown(true);
|
||||||
ui->tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
ui->tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
|
|||||||
@@ -27,17 +27,19 @@ void FileManager::SetModeStr(const QString& modeStr, int type, ClientCore* clien
|
|||||||
|
|
||||||
ui->lbMode->setText(modeStr);
|
ui->lbMode->setText(modeStr);
|
||||||
if (type == 0) {
|
if (type == 0) {
|
||||||
|
isRemote_ = false;
|
||||||
fileHelper_ = std::make_shared<LocalFile>();
|
fileHelper_ = std::make_shared<LocalFile>();
|
||||||
} else {
|
} else {
|
||||||
auto remotePtr = std::make_shared<RemoteFile>();
|
auto remotePtr = std::make_shared<RemoteFile>();
|
||||||
remotePtr->setClientCore(clientCore);
|
remotePtr->setClientCore(clientCore);
|
||||||
|
isRemote_ = true;
|
||||||
ui->tableWidget->setIsRemote(true);
|
ui->tableWidget->setIsRemote(true);
|
||||||
fileHelper_ = remotePtr;
|
fileHelper_ = remotePtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->tableWidget->setOwnIDCall([this]() { return cliCore_->GetOwnID(); });
|
ui->tableWidget->setOwnIDCall([this]() { return cliCore_->GetOwnID(); });
|
||||||
ui->tableWidget->setRemoteIDCall([this]() { return cliCore_->GetRemoteID(); });
|
ui->tableWidget->setRemoteIDCall([this]() { return cliCore_->GetRemoteID(); });
|
||||||
ui->tableWidget->setBasePathCall([this]() { return curRoot_; });
|
ui->tableWidget->setBasePathCall([this]() { return GetRoot(); });
|
||||||
|
|
||||||
connect(fileHelper_.get(), &DirFileHelper::sigHome, this, &FileManager::ShowPath);
|
connect(fileHelper_.get(), &DirFileHelper::sigHome, this, &FileManager::ShowPath);
|
||||||
connect(fileHelper_.get(), &DirFileHelper::sigDirFile, this, &FileManager::ShowFile);
|
connect(fileHelper_.get(), &DirFileHelper::sigDirFile, this, &FileManager::ShowFile);
|
||||||
@@ -177,15 +179,33 @@ void FileManager::ShowFile(const DirFileInfoVec& info)
|
|||||||
ui->tableWidget->setItem(i, 4, item);
|
ui->tableWidget->setItem(i, 4, item);
|
||||||
}
|
}
|
||||||
ui->tableWidget->resizeColumnToContents(0);
|
ui->tableWidget->resizeColumnToContents(0);
|
||||||
curRoot_ = info.root;
|
SetRoot(info.root);
|
||||||
ShowPath(curRoot_);
|
ShowPath(GetRoot());
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileManager::SetRoot(const QString& path)
|
||||||
|
{
|
||||||
|
if (isRemote_) {
|
||||||
|
GlobalData::Ins()->SetRemoteRoot(path);
|
||||||
|
} else {
|
||||||
|
GlobalData::Ins()->SetLocalRoot(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString FileManager::GetRoot()
|
||||||
|
{
|
||||||
|
if (isRemote_) {
|
||||||
|
return GlobalData::Ins()->GetRemoteRoot();
|
||||||
|
} else {
|
||||||
|
return GlobalData::Ins()->GetLocalRoot();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileManager::evtHome()
|
void FileManager::evtHome()
|
||||||
{
|
{
|
||||||
auto r = fileHelper_->GetHome();
|
auto r = fileHelper_->GetHome();
|
||||||
auto curPath = ui->comboBox->currentText();
|
auto curPath = ui->comboBox->currentText();
|
||||||
curRoot_ = curPath;
|
SetRoot(curPath);
|
||||||
qDebug() << QString(tr("%1 get home ret:%2").arg(__FUNCTION__).arg(r));
|
qDebug() << QString(tr("%1 get home ret:%2").arg(__FUNCTION__).arg(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,13 +213,13 @@ void FileManager::evtFile()
|
|||||||
{
|
{
|
||||||
auto curPath = ui->comboBox->currentText();
|
auto curPath = ui->comboBox->currentText();
|
||||||
auto r = fileHelper_->GetDirFile(curPath);
|
auto r = fileHelper_->GetDirFile(curPath);
|
||||||
curRoot_ = curPath;
|
SetRoot(curPath);
|
||||||
qDebug() << QString(tr("%1 get files ret:%2").arg(__FUNCTION__).arg(r));
|
qDebug() << QString(tr("%1 get files ret:%2").arg(__FUNCTION__).arg(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileManager::evtUp()
|
void FileManager::evtUp()
|
||||||
{
|
{
|
||||||
QString path(curRoot_);
|
QString path(GetRoot());
|
||||||
QDir dir(path);
|
QDir dir(path);
|
||||||
path = QDir::cleanPath(dir.absolutePath() + "/..");
|
path = QDir::cleanPath(dir.absolutePath() + "/..");
|
||||||
if (path.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
@@ -207,8 +227,8 @@ void FileManager::evtUp()
|
|||||||
}
|
}
|
||||||
auto r = fileHelper_->GetDirFile(path);
|
auto r = fileHelper_->GetDirFile(path);
|
||||||
if (r) {
|
if (r) {
|
||||||
curRoot_ = path;
|
SetRoot(path);
|
||||||
ShowPath(curRoot_);
|
ShowPath(GetRoot());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,7 +246,7 @@ void FileManager::doubleClick(int row, int column)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDir dir(curRoot_);
|
QDir dir(GetRoot());
|
||||||
QString np = dir.filePath(item->text());
|
QString np = dir.filePath(item->text());
|
||||||
fileHelper_->GetDirFile(np);
|
fileHelper_->GetDirFile(np);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ public:
|
|||||||
~FileManager();
|
~FileManager();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
QString GetRoot();
|
||||||
void SetModeStr(const QString& modeStr, int type = 0, ClientCore* clientCore = nullptr);
|
void SetModeStr(const QString& modeStr, int type = 0, ClientCore* clientCore = nullptr);
|
||||||
void SetOtherSideCall(const std::function<QString()>& call);
|
void SetOtherSideCall(const std::function<QString()>& call);
|
||||||
QString GetCurRoot();
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void sigSendTasks(const QVector<TransTask>& tasks);
|
void sigSendTasks(const QVector<TransTask>& tasks);
|
||||||
@@ -35,6 +35,7 @@ private:
|
|||||||
void ShowPath(const QString& path);
|
void ShowPath(const QString& path);
|
||||||
void ShowFile(const DirFileInfoVec& info);
|
void ShowFile(const DirFileInfoVec& info);
|
||||||
void doubleClick(int row, int column);
|
void doubleClick(int row, int column);
|
||||||
|
void SetRoot(const QString& path);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void evtHome();
|
void evtHome();
|
||||||
@@ -42,8 +43,8 @@ private:
|
|||||||
void evtUp();
|
void evtUp();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool isRemote_;
|
||||||
Ui::FileManager* ui;
|
Ui::FileManager* ui;
|
||||||
QString curRoot_;
|
|
||||||
QMenu* menu_;
|
QMenu* menu_;
|
||||||
ClientCore* cliCore_;
|
ClientCore* cliCore_;
|
||||||
QMutex cbMut_;
|
QMutex cbMut_;
|
||||||
|
|||||||
@@ -17,12 +17,31 @@ CpTableWidget::~CpTableWidget()
|
|||||||
|
|
||||||
void CpTableWidget::dropEvent(QDropEvent* event)
|
void CpTableWidget::dropEvent(QDropEvent* event)
|
||||||
{
|
{
|
||||||
|
if (!event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist")) {
|
||||||
|
event->ignore();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QByteArray encoded = event->mimeData()->data("application/x-qabstractitemmodeldatalist");
|
||||||
|
QDataStream stream(&encoded, QIODevice::ReadOnly);
|
||||||
|
|
||||||
|
QList<QTableWidgetItem*> draggedItems;
|
||||||
|
while (!stream.atEnd()) {
|
||||||
|
int row, col;
|
||||||
|
QMap<int, QVariant> roleData;
|
||||||
|
stream >> row >> col >> roleData;
|
||||||
|
if (col != 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CpTableWidget::dragEnterEvent(QDragEnterEvent* event)
|
void CpTableWidget::dragEnterEvent(QDragEnterEvent* event)
|
||||||
{
|
{
|
||||||
|
if (event->mimeData()->hasFormat("application/x-qabstractitemmodeldatalist")) {
|
||||||
|
event->acceptProposedAction();
|
||||||
|
} else {
|
||||||
|
event->ignore();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,11 +27,6 @@ void CustomTableWidget::setBasePathCall(const std::function<QString()>& call)
|
|||||||
basePathCall_ = call;
|
basePathCall_ = call;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FileManager::GetCurRoot()
|
|
||||||
{
|
|
||||||
return curRoot_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CustomTableWidget::setOwnIDCall(const std::function<QString()>& call)
|
void CustomTableWidget::setOwnIDCall(const std::function<QString()>& call)
|
||||||
{
|
{
|
||||||
oidCall_ = call;
|
oidCall_ = call;
|
||||||
|
|||||||
@@ -47,9 +47,9 @@ void frelayGUI::InitControl()
|
|||||||
remoteFile_ = new FileManager(this);
|
remoteFile_ = new FileManager(this);
|
||||||
|
|
||||||
localFile_->SetModeStr(tr("Local:"), 0, clientCore_);
|
localFile_->SetModeStr(tr("Local:"), 0, clientCore_);
|
||||||
localFile_->SetOtherSideCall([this]() { return remoteFile_->GetCurRoot(); });
|
localFile_->SetOtherSideCall([this]() { return remoteFile_->GetRoot(); });
|
||||||
remoteFile_->SetModeStr(tr("Remote:"), 1, clientCore_);
|
remoteFile_->SetModeStr(tr("Remote:"), 1, clientCore_);
|
||||||
remoteFile_->SetOtherSideCall([this]() { return localFile_->GetCurRoot(); });
|
remoteFile_->SetOtherSideCall([this]() { return localFile_->GetRoot(); });
|
||||||
|
|
||||||
tabWidget_ = new QTabWidget(this);
|
tabWidget_ = new QTabWidget(this);
|
||||||
|
|
||||||
|
|||||||
@@ -128,3 +128,31 @@ QString DirFileHelper::GetErr() const
|
|||||||
DirFileHelper::DirFileHelper(QObject* parent) : QObject(parent)
|
DirFileHelper::DirFileHelper(QObject* parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GlobalData* GlobalData::Ins()
|
||||||
|
{
|
||||||
|
static GlobalData instance;
|
||||||
|
return &instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalData::SetLocalRoot(const QString& root)
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&mutex_);
|
||||||
|
LocalRoot_ = root;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GlobalData::SetRemoteRoot(const QString& root)
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&mutex_);
|
||||||
|
RemoteRoot_ = root;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString GlobalData::GetLocalRoot() const
|
||||||
|
{
|
||||||
|
return LocalRoot_;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString GlobalData::GetRemoteRoot() const
|
||||||
|
{
|
||||||
|
return RemoteRoot_;
|
||||||
|
}
|
||||||
22
Util/Util.h
22
Util/Util.h
@@ -2,8 +2,30 @@
|
|||||||
#define UTIL_H
|
#define UTIL_H
|
||||||
|
|
||||||
#include <InfoDirFile.h>
|
#include <InfoDirFile.h>
|
||||||
|
#include <QMutex>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
class GlobalData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static GlobalData* Ins();
|
||||||
|
~GlobalData() = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void SetLocalRoot(const QString& root);
|
||||||
|
void SetRemoteRoot(const QString& root);
|
||||||
|
QString GetLocalRoot() const;
|
||||||
|
QString GetRemoteRoot() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
GlobalData() = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
QMutex mutex_;
|
||||||
|
QString LocalRoot_;
|
||||||
|
QString RemoteRoot_;
|
||||||
|
};
|
||||||
|
|
||||||
class Util : public QObject
|
class Util : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|||||||
Reference in New Issue
Block a user