#include "OnLineControl.h" #include "HeaderControl.h" #include "LogControl.h" #include OnlineControl::OnlineControl(wxWindow* parent, std::shared_ptr& clientCore) : wxPanel(parent), clientCore_(clientCore) { Init(); InitCall(); } OnlineControl::~OnlineControl() { } void OnlineControl::SetHeaderControl(HeaderControl* headerControl) { headerControl_ = headerControl; } void OnlineControl::SetLogControl(LogControl* logControl) { logControl_ = logControl; } void OnlineControl::Init() { 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); 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); 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(); 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 lock(mutex_); onLineList_->Clear(); for (auto& info : infoClientVec.vec) { onLineList_->Append(info.id); } logControl_->AddLog(_("Get online list success.")); }