Mercurial > minori
view include/gui/widgets/poster.h @ 390:2d3e10319112
http: optimize HTTP request thread
we don't need a mutex at all, in fact all we need is an atomic
boolean to signify whether the thread is cancelled.
curl options are now for the most part handled by a separate
function to keep them in sync between non-threaded and threaded
implementations
| author | Paper <paper@tflc.us> |
|---|---|
| date | Fri, 07 Nov 2025 07:08:57 -0500 |
| parents | 5912dafc6e28 |
| children |
line wrap: on
line source
#ifndef MINORI_GUI_WIDGETS_POSTER_H_ #define MINORI_GUI_WIDGETS_POSTER_H_ #include <QFrame> #include <QImage> #include "gui/widgets/clickable_label.h" #include "core/http.h" namespace Anime { class Anime; } class GetPosterThread final : public QThread { /* :') */ Q_OBJECT public: GetPosterThread(QObject *parent); void SetId(int id); virtual void run() override; /* Or PvP boss */ signals: void Finished(const QImage &img); private: int id_ = 0; }; class Poster final : public QFrame { Q_OBJECT public: Poster(QWidget* parent = nullptr); Poster(const Anime::Anime& anime, QWidget* parent = nullptr); ~Poster(); void SetAnime(const Anime::Anime& anime); void SetClickable(bool clickable); bool hasHeightForWidth(void) const override; int heightForWidth(int w) const override; protected: void showEvent(QShowEvent*) override; void resizeEvent(QResizeEvent*) override; void ImageDownloadFinished(const QImage& img); void RenderToLabel(); void DownloadPoster(); QSize sizeHint() const override; QSize minimumSizeHint() const override; private: /* stored as a pointer to prevent blocking */ GetPosterThread* get_thread_; QImage img_; QString service_url_; ClickableLabel label_; int id_; bool clickable_ = true; bool need_refresh_ = false; }; #endif // MINORI_GUI_WIDGETS_POSTER_H_
