RelayFile/UserInterface/OnLineControl.cxx

81 lines
2.5 KiB
C++
Raw Normal View History

2025-05-08 21:13:36 +08:00
#include "OnLineControl.h"
2025-05-11 21:27:59 +08:00
#include "HeaderControl.h"
#include "LogControl.h"
#include <ClientCore.h>
2025-05-08 21:13:36 +08:00
2025-05-11 21:27:59 +08:00
OnlineControl::OnlineControl(wxWindow* parent, std::shared_ptr<ClientCore>& clientCore) : wxPanel(parent), clientCore_(clientCore)
2025-05-08 21:13:36 +08:00
{
Init();
2025-05-11 21:27:59 +08:00
InitCall();
2025-05-08 21:13:36 +08:00
}
OnlineControl::~OnlineControl()
{
}
2025-05-11 21:27:59 +08:00
void OnlineControl::SetHeaderControl(HeaderControl* headerControl)
{
headerControl_ = headerControl;
}
void OnlineControl::SetLogControl(LogControl* logControl)
{
logControl_ = logControl;
}
void OnlineControl::Init()
{
2025-05-11 21:27:59 +08:00
btnFresh_ = new wxButton(this, wxID_ANY, _("Refresh"));
lbCurState_ = new wxStaticText(this, wxID_ANY, _("Current State => "));
elbCurState_ = new wxStaticText(this, wxID_ANY, _("Disconnected"));
elbCurState_->SetForegroundColour(*wxBLUE);
onLineList_ = new wxListBox(this, wxID_ANY);
lbCurPoint_ = new wxStaticText(this, wxID_ANY, _("Commnunicate Point => "));
elbCurPoint_ = new wxStaticText(this, wxID_ANY, _("None"));
elbCurPoint_->SetForegroundColour(*wxBLUE);
auto* leveSizerA = new wxBoxSizer(wxHORIZONTAL);
leveSizerA->Add(lbCurState_, 0, wxEXPAND | wxALL, gBorder + 1);
leveSizerA->Add(elbCurState_, 0, wxEXPAND | wxALL, gBorder + 1);
2025-05-11 21:27:59 +08:00
auto* leveSizerB = new wxBoxSizer(wxHORIZONTAL);
leveSizerB->Add(lbCurPoint_, 1, wxALL | wxCENTER, gBorder + 1);
leveSizerB->Add(btnFresh_, 0, wxALL | wxCENTER, gBorder + 1);
auto* topSizer = new wxBoxSizer(wxVERTICAL);
topSizer->Add(leveSizerA, 0, wxEXPAND | wxALL, gBorder + 1);
2025-05-11 21:27:59 +08:00
topSizer->Add(leveSizerB, 0, wxALL, gBorder + 1);
topSizer->Add(elbCurPoint_, 0, wxEXPAND | wxALL, gBorder + 1);
topSizer->Add(onLineList_, 1, wxEXPAND | wxALL, gBorder + 1);
SetSizer(topSizer);
Layout();
2025-05-11 21:27:59 +08:00
Bind(wxEVT_BUTTON, &OnlineControl::OnFreshClients, this, btnFresh_->GetId());
}
void OnlineControl::InitCall()
{
clientCore_->ReqOnlineCallback([this](const InfoClientVec& infoClientVec) { OnFreshClientsCall(infoClientVec); });
}
void OnlineControl::OnFreshClients(wxCommandEvent& event)
{
InfoClientVec vec;
if (!clientCore_->ReqOnline()) {
logControl_->AddLog(_("Request Get online list failed."));
return;
}
logControl_->AddLog(_("Request Get online list success."));
}
void OnlineControl::OnFreshClientsCall(const InfoClientVec& infoClientVec)
{
std::unique_lock<std::mutex> lock(mutex_);
onLineList_->Clear();
for (auto& info : infoClientVec.vec) {
onLineList_->Append(info.id);
}
logControl_->AddLog(_("Get online list success."));
}