refactor: Turn link-info into its own element and class (#5178)

This commit is contained in:
nerix
2024-02-18 13:34:00 +01:00
committed by GitHub
parent 42e4559910
commit e130c48f76
22 changed files with 752 additions and 314 deletions
+106
View File
@@ -0,0 +1,106 @@
#include "providers/links/LinkInfo.hpp"
#include "debug/AssertInGuiThread.hpp"
#include <QString>
namespace chatterino {
LinkInfo::LinkInfo(QString url)
: QObject(nullptr)
, originalUrl_(url)
, url_(std::move(url))
, tooltip_(this->url_)
{
}
LinkInfo::~LinkInfo() = default;
LinkInfo::State LinkInfo::state() const
{
return this->state_;
}
QString LinkInfo::url() const
{
return this->url_;
}
QString LinkInfo::originalUrl() const
{
return this->originalUrl_;
}
bool LinkInfo::isPending() const
{
return this->state_ == State::Created;
}
bool LinkInfo::isLoading() const
{
return this->state_ == State::Loading;
}
bool LinkInfo::isLoaded() const
{
return this->state_ > State::Loading;
}
bool LinkInfo::isResolved() const
{
return this->state_ == State::Resolved;
}
bool LinkInfo::hasError() const
{
return this->state_ == State::Errored;
}
bool LinkInfo::hasThumbnail() const
{
return this->thumbnail_ && !this->thumbnail_->url().string.isEmpty();
}
QString LinkInfo::tooltip() const
{
return this->tooltip_;
}
ImagePtr LinkInfo::thumbnail() const
{
return this->thumbnail_;
}
void LinkInfo::setState(State state)
{
assertInGuiThread();
assert(state >= this->state_);
if (this->state_ == state)
{
return;
}
this->state_ = state;
this->stateChanged(state);
}
void LinkInfo::setResolvedUrl(QString resolvedUrl)
{
assertInGuiThread();
this->url_ = std::move(resolvedUrl);
}
void LinkInfo::setTooltip(QString tooltip)
{
assertInGuiThread();
this->tooltip_ = std::move(tooltip);
}
void LinkInfo::setThumbnail(ImagePtr thumbnail)
{
assertInGuiThread();
this->thumbnail_ = std::move(thumbnail);
}
} // namespace chatterino