You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw-tes3mp/apps/browser/PingHelper.cpp

57 lines
1.3 KiB
C++

//
// Created by koncord on 03.05.17.
//
#include "PingHelper.hpp"
#include "ServerModel.hpp"
#include <QDebug>
#include "PingUpdater.hpp"
void PingHelper::Add(int row, const AddrPair &addrPair)
{
pingUpdater->addServer(row, addrPair);
if (!pingThread->isRunning())
pingThread->start();
}
void PingHelper::Reset()
{
//if (pingThread->isRunning())
Stop();
}
void PingHelper::Stop()
{
emit pingUpdater->stop();
}
void PingHelper::SetModel(QAbstractTableModel *model)
{
this->model = model;
}
void PingHelper::update(int row, unsigned ping)
{
model->setData(model->index(row, ServerData::PING), ping);
}
PingHelper &PingHelper::Get()
{
static PingHelper helper;
return helper;
}
PingHelper::PingHelper() : QObject()
{
pingThread = new QThread;
pingUpdater = new PingUpdater;
pingUpdater->moveToThread(pingThread);
connect(pingThread, SIGNAL(started()), pingUpdater, SLOT(process()));
connect(pingUpdater, SIGNAL(start()), pingThread, SLOT(start()));
connect(pingUpdater, SIGNAL(finished()), pingThread, SLOT(quit()));
connect(this, SIGNAL(stop()), pingUpdater, SLOT(stop()));
//connect(pingUpdater, SIGNAL(finished()), pingUpdater, SLOT(deleteLater()));
connect(pingUpdater, SIGNAL(updateModel(int, unsigned)), this, SLOT(update(int, unsigned)));
}