simplified Image
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
#include "Emotemap.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
// EmoteData::EmoteData(Image *image)
|
||||
// : image1x(image)
|
||||
//{
|
||||
//}
|
||||
|
||||
//// Emotes must have a 1x image to be valid
|
||||
// bool EmoteData::isValid() const
|
||||
//{
|
||||
// return this->image1x != nullptr;
|
||||
//}
|
||||
|
||||
// Image *EmoteData::getImage(float scale) const
|
||||
//{
|
||||
// int quality = getApp()->settings->preferredEmoteQuality;
|
||||
|
||||
// if (quality == 0) {
|
||||
// scale *= getApp()->settings->emoteScale.getValue();
|
||||
// quality = [&] {
|
||||
// if (scale <= 1)
|
||||
// return 1;
|
||||
// if (scale <= 2)
|
||||
// return 2;
|
||||
// return 3;
|
||||
// }();
|
||||
// }
|
||||
|
||||
// Image *_image;
|
||||
// if (quality == 3 && this->image3x != nullptr) {
|
||||
// _image = this->image3x;
|
||||
// } else if (quality >= 2 && this->image2x != nullptr) {
|
||||
// _image = this->image2x;
|
||||
// } else {
|
||||
// _image = this->image1x;
|
||||
// }
|
||||
|
||||
// return _image;
|
||||
//}
|
||||
|
||||
} // namespace chatterino
|
||||
@@ -1,27 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "messages/Image.hpp"
|
||||
#include "util/ConcurrentMap.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
// struct EmoteData {
|
||||
// EmoteData() = default;
|
||||
|
||||
// EmoteData(Image *image);
|
||||
|
||||
// // Emotes must have a 1x image to be valid
|
||||
// bool isValid() const;
|
||||
// Image *getImage(float scale) const;
|
||||
|
||||
// // Link to the emote page i.e.
|
||||
// https://www.frankerfacez.com/emoticon/144722-pajaCringe QString pageLink;
|
||||
|
||||
// Image *image1x = nullptr;
|
||||
// Image *image2x = nullptr;
|
||||
// Image *image3x = nullptr;
|
||||
//};
|
||||
|
||||
// using EmoteMap = ConcurrentMap<QString, EmoteData>;
|
||||
|
||||
} // namespace chatterino
|
||||
+10
-28
@@ -4,19 +4,17 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
// = std::enable_if<std::is_enum<T>::value>::type
|
||||
|
||||
template <typename T, typename Q = typename std::underlying_type<T>::type>
|
||||
class FlagsEnum
|
||||
{
|
||||
public:
|
||||
FlagsEnum()
|
||||
: value(static_cast<T>(0))
|
||||
: value_(static_cast<T>(0))
|
||||
{
|
||||
}
|
||||
|
||||
FlagsEnum(T value)
|
||||
: value(value)
|
||||
: value_(value)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -29,22 +27,22 @@ public:
|
||||
|
||||
bool operator==(const FlagsEnum<T> &other)
|
||||
{
|
||||
return this->value == other.value;
|
||||
return this->value_ == other.value_;
|
||||
}
|
||||
|
||||
bool operator!=(const FlagsEnum &other)
|
||||
{
|
||||
return this->value != other.value;
|
||||
return this->value_ != other.value_;
|
||||
}
|
||||
|
||||
void set(T flag)
|
||||
{
|
||||
reinterpret_cast<Q &>(this->value) |= static_cast<Q>(flag);
|
||||
reinterpret_cast<Q &>(this->value_) |= static_cast<Q>(flag);
|
||||
}
|
||||
|
||||
void unset(T flag)
|
||||
{
|
||||
reinterpret_cast<Q &>(this->value) &= ~static_cast<Q>(flag);
|
||||
reinterpret_cast<Q &>(this->value_) &= ~static_cast<Q>(flag);
|
||||
}
|
||||
|
||||
void set(T flag, bool value)
|
||||
@@ -57,33 +55,17 @@ public:
|
||||
|
||||
bool has(T flag) const
|
||||
{
|
||||
return static_cast<Q>(this->value) & static_cast<Q>(flag);
|
||||
return static_cast<Q>(this->value_) & static_cast<Q>(flag);
|
||||
}
|
||||
|
||||
// bool hasAny(std::initializer_list<T> flags) const
|
||||
//{
|
||||
// for (auto flag : flags) {
|
||||
// if (this->has(flag)) return true;
|
||||
// }
|
||||
// return false;
|
||||
//}
|
||||
|
||||
bool hasAny(FlagsEnum flags) const
|
||||
{
|
||||
return static_cast<Q>(this->value) & static_cast<Q>(flags.value);
|
||||
return static_cast<Q>(this->value_) & static_cast<Q>(flags.value_);
|
||||
}
|
||||
|
||||
// bool hasAll(std::initializer_list<T> flags) const
|
||||
//{
|
||||
// for (auto flag : flags) {
|
||||
// if (!this->has(flag)) return false;
|
||||
// }
|
||||
// return true;
|
||||
//}
|
||||
|
||||
bool hasAll(FlagsEnum<T> flags) const
|
||||
{
|
||||
return (static_cast<Q>(this->value) & static_cast<Q>(flags.value)) &&
|
||||
return (static_cast<Q>(this->value_) & static_cast<Q>(flags.value_)) &&
|
||||
static_cast<Q>(flags->value);
|
||||
}
|
||||
|
||||
@@ -93,7 +75,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
T value;
|
||||
T value_{};
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -19,6 +19,7 @@ struct NetworkData {
|
||||
QNetworkRequest request_;
|
||||
const QObject *caller_ = nullptr;
|
||||
bool useQuickLoadCache_{};
|
||||
bool executeConcurrently{};
|
||||
|
||||
NetworkReplyCreatedCallback onReplyCreated_;
|
||||
NetworkErrorCallback onError_;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "util/DebugCount.hpp"
|
||||
|
||||
#include <QFile>
|
||||
#include <QtConcurrent>
|
||||
#include <cassert>
|
||||
|
||||
namespace chatterino {
|
||||
@@ -80,6 +81,11 @@ void NetworkRequest::setTimeout(int ms)
|
||||
this->timer->timeoutMS_ = ms;
|
||||
}
|
||||
|
||||
void NetworkRequest::setExecuteConcurrently(bool value)
|
||||
{
|
||||
this->data->executeConcurrently = value;
|
||||
}
|
||||
|
||||
void NetworkRequest::makeAuthorizedV5(const QString &clientID,
|
||||
const QString &oauthToken)
|
||||
{
|
||||
@@ -228,7 +234,16 @@ void NetworkRequest::doRequest()
|
||||
NetworkResult result(bytes);
|
||||
|
||||
DebugCount::increase("http request success");
|
||||
data->onSuccess_(result);
|
||||
Log("starting {}", data->request_.url().toString());
|
||||
if (data->onSuccess_) {
|
||||
if (data->executeConcurrently)
|
||||
QtConcurrent::run(
|
||||
[onSuccess = std::move(data->onSuccess_),
|
||||
result = std::move(result)] { onSuccess(result); });
|
||||
else
|
||||
data->onSuccess_(result);
|
||||
}
|
||||
Log("finished {}", data->request_.url().toString());
|
||||
|
||||
reply->deleteLater();
|
||||
};
|
||||
|
||||
@@ -27,19 +27,15 @@ class NetworkRequest
|
||||
bool executed_ = false;
|
||||
|
||||
public:
|
||||
NetworkRequest() = delete;
|
||||
NetworkRequest(const NetworkRequest &other) = delete;
|
||||
NetworkRequest &operator=(const NetworkRequest &other) = delete;
|
||||
|
||||
NetworkRequest(NetworkRequest &&other) = default;
|
||||
NetworkRequest &operator=(NetworkRequest &&other) = default;
|
||||
|
||||
explicit NetworkRequest(
|
||||
const std::string &url,
|
||||
NetworkRequestType requestType = NetworkRequestType::Get);
|
||||
explicit NetworkRequest(
|
||||
QUrl url, NetworkRequestType requestType = NetworkRequestType::Get);
|
||||
|
||||
NetworkRequest(NetworkRequest &&other) = default;
|
||||
NetworkRequest &operator=(NetworkRequest &&other) = default;
|
||||
|
||||
~NetworkRequest();
|
||||
|
||||
void setRequestType(NetworkRequestType newRequestType);
|
||||
@@ -55,6 +51,7 @@ public:
|
||||
void setRawHeader(const char *headerName, const QByteArray &value);
|
||||
void setRawHeader(const char *headerName, const QString &value);
|
||||
void setTimeout(int ms);
|
||||
void setExecuteConcurrently(bool value);
|
||||
void makeAuthorizedV5(const QString &clientID,
|
||||
const QString &oauthToken = QString());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user