Mercurial > minori
comparison src/gui/widgets/anime_info.cc @ 370:ea3a74ed2ef9
*: hm, last commit wasn't quite finished?
| author | Paper <paper@tflc.us> |
|---|---|
| date | Fri, 25 Jul 2025 10:22:04 -0400 |
| parents | 6b0768158dcd |
| children |
comparison
equal
deleted
inserted
replaced
| 369:47c9f8502269 | 370:ea3a74ed2ef9 |
|---|---|
| 6 #include "gui/widgets/text.h" | 6 #include "gui/widgets/text.h" |
| 7 #include "services/services.h" | 7 #include "services/services.h" |
| 8 #include <QHBoxLayout> | 8 #include <QHBoxLayout> |
| 9 #include <QTextStream> | 9 #include <QTextStream> |
| 10 | 10 |
| 11 AnimeInfoWidgetGetMetadataThread::AnimeInfoWidgetGetMetadataThread(QObject* parent) : QThread(parent) {} | 11 AnimeInfoWidgetGetMetadataThread::AnimeInfoWidgetGetMetadataThread(QObject *parent) : QThread(parent) |
| 12 { | |
| 13 } | |
| 12 | 14 |
| 13 void AnimeInfoWidgetGetMetadataThread::AddToQueue(int id) { | 15 void AnimeInfoWidgetGetMetadataThread::AddToQueue(int id) |
| 16 { | |
| 14 const std::lock_guard<std::mutex> guard(queue_mutex_); | 17 const std::lock_guard<std::mutex> guard(queue_mutex_); |
| 15 queue_.push(id); | 18 queue_.push(id); |
| 16 } | 19 } |
| 17 | 20 |
| 18 /* processes the queue... */ | 21 /* processes the queue... */ |
| 19 void AnimeInfoWidgetGetMetadataThread::run() { | 22 void AnimeInfoWidgetGetMetadataThread::run() |
| 23 { | |
| 20 queue_mutex_.lock(); | 24 queue_mutex_.lock(); |
| 21 while (!queue_.empty() && !isInterruptionRequested()) { | 25 while (!queue_.empty() && !isInterruptionRequested()) { |
| 22 int id = queue_.front(); | 26 int id = queue_.front(); |
| 23 | 27 |
| 24 queue_mutex_.unlock(); | 28 queue_mutex_.unlock(); |
| 34 } | 38 } |
| 35 | 39 |
| 36 /* all widgets share this thread */ | 40 /* all widgets share this thread */ |
| 37 static AnimeInfoWidgetGetMetadataThread get_metadata_thread; | 41 static AnimeInfoWidgetGetMetadataThread get_metadata_thread; |
| 38 | 42 |
| 39 AnimeInfoWidget::AnimeInfoWidget(QWidget* parent) : QWidget(parent) { | 43 AnimeInfoWidget::AnimeInfoWidget(QWidget *parent) : QWidget(parent) |
| 40 QVBoxLayout* layout = new QVBoxLayout(this); | 44 { |
| 45 QVBoxLayout *layout = new QVBoxLayout(this); | |
| 41 | 46 |
| 42 _title.GetHeader().SetText(Strings::Translate("Alternative titles")); | 47 _title.GetHeader().SetText(Strings::Translate("Alternative titles")); |
| 43 layout->addWidget(&_title); | 48 layout->addWidget(&_title); |
| 44 | 49 |
| 45 _details.GetHeader().SetText(Strings::Translate("Details")); | 50 _details.GetHeader().SetText(Strings::Translate("Details")); |
| 46 | 51 |
| 47 const std::vector<std::pair<std::string, std::string>> items = { | 52 const std::vector<std::pair<std::string, std::string>> items = { |
| 48 {Strings::Translate("Type:"), ""}, | 53 {Strings::Translate("Type:"), ""}, |
| 49 {Strings::Translate("Episodes:"), ""}, | 54 {Strings::Translate("Episodes:"), ""}, |
| 50 {Strings::Translate("Status:"), ""}, | 55 {Strings::Translate("Status:"), ""}, |
| 51 {Strings::Translate("Season:"), ""}, | 56 {Strings::Translate("Season:"), ""}, |
| 52 {Strings::Translate("Genres:"), ""}, | 57 {Strings::Translate("Genres:"), ""}, |
| 53 {Strings::Translate("Producers:"), ""}, | 58 {Strings::Translate("Producers:"), ""}, |
| 54 {Strings::Translate("Score:"), ""}, | 59 {Strings::Translate("Score:"), ""}, |
| 55 }; | 60 }; |
| 56 | 61 |
| 57 _details.GetContent().SetData(items); | 62 _details.GetContent().SetData(items); |
| 58 | 63 |
| 59 layout->addWidget(&_details); | 64 layout->addWidget(&_details); |
| 72 | 77 |
| 73 setUpdatesEnabled(true); | 78 setUpdatesEnabled(true); |
| 74 }); | 79 }); |
| 75 } | 80 } |
| 76 | 81 |
| 77 AnimeInfoWidget::AnimeInfoWidget(const Anime::Anime& anime, QWidget* parent) : AnimeInfoWidget(parent) { | 82 AnimeInfoWidget::AnimeInfoWidget(const Anime::Anime &anime, QWidget *parent) : AnimeInfoWidget(parent) |
| 83 { | |
| 78 SetAnime(anime); | 84 SetAnime(anime); |
| 79 } | 85 } |
| 80 | 86 |
| 81 void AnimeInfoWidget::SetAnime(const Anime::Anime& anime) { | 87 void AnimeInfoWidget::SetAnime(const Anime::Anime &anime) |
| 88 { | |
| 82 setUpdatesEnabled(false); | 89 setUpdatesEnabled(false); |
| 83 | 90 |
| 84 id_ = anime.GetId(); | 91 id_ = anime.GetId(); |
| 85 | 92 |
| 86 get_metadata_thread.AddToQueue(id_); | 93 get_metadata_thread.AddToQueue(id_); |
| 97 setUpdatesEnabled(true); | 104 setUpdatesEnabled(true); |
| 98 | 105 |
| 99 updateGeometry(); | 106 updateGeometry(); |
| 100 } | 107 } |
| 101 | 108 |
| 102 void AnimeInfoWidget::RefreshGenres(const Anime::Anime& anime) { | 109 void AnimeInfoWidget::RefreshGenres(const Anime::Anime &anime) |
| 110 { | |
| 103 /* we have to convert ALL of these strings to | 111 /* we have to convert ALL of these strings to |
| 104 * QString because QTextStream sucks and assumes | 112 * QString because QTextStream sucks and assumes |
| 105 * Latin-1 (on Windows?) */ | 113 * Latin-1 (on Windows?) */ |
| 106 const auto genres = anime.GetGenres(); | 114 const auto genres = anime.GetGenres(); |
| 107 const auto producers = anime.GetProducers(); | 115 const auto producers = anime.GetProducers(); |
| 108 | 116 |
| 109 const std::vector<std::pair<std::string, std::string>> items = { | 117 const std::vector<std::pair<std::string, std::string>> items = { |
| 110 {Strings::Translate("Type:"), Translate::ToLocalString(anime.GetFormat())}, | 118 {Strings::Translate("Type:"), Translate::ToLocalString(anime.GetFormat())}, |
| 111 {Strings::Translate("Episodes:"), Strings::ToUtf8String(anime.GetEpisodes())}, | 119 {Strings::Translate("Episodes:"), Strings::ToUtf8String(anime.GetEpisodes())}, |
| 112 {Strings::Translate("Status:"), Translate::ToLocalString(anime.GetAiringStatus())}, | 120 {Strings::Translate("Status:"), Translate::ToLocalString(anime.GetAiringStatus())}, |
| 113 {Strings::Translate("Season:"), Translate::ToLocalString(anime.GetSeason())}, | 121 {Strings::Translate("Season:"), Translate::ToLocalString(anime.GetSeason())}, |
| 114 {Strings::Translate("Genres:"), (genres.size() > 1) ? Strings::Implode(genres, ", ") : "-"}, | 122 {Strings::Translate("Genres:"), (genres.size() > 1) ? Strings::Implode(genres, ", ") : "-"}, |
| 115 {Strings::Translate("Producers:"), (producers.size() > 1) ? Strings::Implode(producers, ", ") : "-"}, | 123 {Strings::Translate("Producers:"), (producers.size() > 1) ? Strings::Implode(producers, ", ") : "-"}, |
| 116 {Strings::Translate("Score:"), Strings::ToUtf8String(anime.GetAudienceScore()) + "%"}, | 124 {Strings::Translate("Score:"), Strings::ToUtf8String(anime.GetAudienceScore()) + "%"}, |
| 117 }; | 125 }; |
| 118 | 126 |
| 119 _details.GetContent().SetData(items); | 127 _details.GetContent().SetData(items); |
| 120 } | 128 } |
