diff --git a/src/common/Common.hpp b/src/common/Common.hpp index fe5acc562..43b954078 100644 --- a/src/common/Common.hpp +++ b/src/common/Common.hpp @@ -1,16 +1,15 @@ #pragma once -#include "common/Aliases.hpp" -#include "common/Outcome.hpp" -#include "common/ProviderId.hpp" - #include #include #include #include - #include +#include "common/Aliases.hpp" +#include "common/Outcome.hpp" +#include "common/ProviderId.hpp" + namespace chatterino { enum class HighlightState { @@ -46,4 +45,14 @@ enum class CopyMode { OnlyTextAndEmotes, }; +struct DeleteLater { + void operator()(QObject *obj) + { + obj->deleteLater(); + } +}; + +template +using QObjectPtr = std::unique_ptr; + } // namespace chatterino diff --git a/src/messages/Image.cpp b/src/messages/Image.cpp index 675e7d156..412727d01 100644 --- a/src/messages/Image.cpp +++ b/src/messages/Image.cpp @@ -1,5 +1,14 @@ #include "messages/Image.hpp" +#include +#include +#include +#include +#include +#include +#include +#include + #include "Application.hpp" #include "common/Common.hpp" #include "common/NetworkRequest.hpp" @@ -11,15 +20,6 @@ #include "util/DebugCount.hpp" #include "util/PostToThread.hpp" -#include -#include -#include -#include -#include -#include -#include -#include - namespace chatterino { namespace detail { // Frames @@ -324,7 +324,7 @@ int Image::width() const assertInGuiThread(); if (auto pixmap = this->frames_->first()) - return pixmap->width() * this->scale_; + return int(pixmap->width() * this->scale_); else return 16; } @@ -369,6 +369,7 @@ void Image::actuallyLoad() if (!shared) return false; + // fourtf: is this the right thing to do? shared->empty_ = true; return true; diff --git a/src/messages/Image.hpp b/src/messages/Image.hpp index 1cd30d81b..7aa184e9d 100644 --- a/src/messages/Image.hpp +++ b/src/messages/Image.hpp @@ -13,7 +13,7 @@ #include #include "common/Aliases.hpp" -#include "common/NullablePtr.hpp" +#include "common/Common.hpp" namespace chatterino { namespace detail { @@ -45,6 +45,7 @@ namespace detail { class Image; using ImagePtr = std::shared_ptr; +/// This class is thread safe. class Image : public std::enable_shared_from_this, boost::noncopyable { public: @@ -72,14 +73,14 @@ private: Image(qreal scale); void setPixmap(const QPixmap &pixmap); - void actuallyLoad(); - Url url_{}; - qreal scale_{1}; - bool empty_{false}; + const Url url_{}; + const qreal scale_{1}; + std::atomic_bool empty_{false}; + + // gui thread only bool shouldLoad_{false}; std::unique_ptr frames_{}; - QObject object_{}; }; } // namespace chatterino diff --git a/src/providers/irc/AbstractIrcServer.hpp b/src/providers/irc/AbstractIrcServer.hpp index 9b17d3012..20d782490 100644 --- a/src/providers/irc/AbstractIrcServer.hpp +++ b/src/providers/irc/AbstractIrcServer.hpp @@ -1,13 +1,13 @@ #pragma once -#include "providers/irc/IrcConnection2.hpp" - #include +#include +#include #include #include -#include -#include +#include "common/Common.hpp" +#include "providers/irc/IrcConnection2.hpp" namespace chatterino { @@ -73,15 +73,8 @@ protected: private: void initConnection(); - struct Deleter { - void operator()(IrcConnection *conn) - { - conn->deleteLater(); - } - }; - - std::unique_ptr writeConnection_ = nullptr; - std::unique_ptr readConnection_ = nullptr; + QObjectPtr writeConnection_ = nullptr; + QObjectPtr readConnection_ = nullptr; QTimer reconnectTimer_; int falloffCounter_ = 1;