Refactor NetworkRequest class

Add followUser and unfollowUser methods to TwitchAccount
This commit is contained in:
Rasmus Karlsson
2018-07-07 11:08:57 +00:00
parent cada32edfd
commit 6a418e6e59
27 changed files with 835 additions and 669 deletions
+58
View File
@@ -0,0 +1,58 @@
#pragma once
#include "common/NetworkWorker.hpp"
#include <QTimer>
#include <cassert>
#include <functional>
#include <memory>
namespace chatterino {
class NetworkTimer
{
std::unique_ptr<QTimer> timer_;
bool started_{};
public:
int timeoutMS_ = -1;
NetworkTimer() = default;
~NetworkTimer() = default;
NetworkTimer(const NetworkTimer &other) = delete;
NetworkTimer &operator=(const NetworkTimer &other) = delete;
NetworkTimer(NetworkTimer &&other) = default;
NetworkTimer &operator=(NetworkTimer &&other) = default;
void start()
{
if (this->timeoutMS_ <= 0) {
return;
}
this->timer_ = std::make_unique<QTimer>();
this->timer_->start(this->timeoutMS_);
this->started_ = true;
}
bool isStarted() const
{
return this->started_;
}
void onTimeout(NetworkWorker *worker, std::function<void()> cb) const
{
if (!this->timer_) {
return;
}
QObject::connect(this->timer_.get(), &QTimer::timeout, worker, cb);
}
};
} // namespace chatterino