annotate src/gui/widgets/anime_info.cc @ 351:c844f8bb87ce

gui/theme: add xsettings backend this also adds newly-necessary endianness methods in core/endian.h which just so happen to be constexpr as well
author Paper <paper@paper.us.eu.org>
date Sun, 14 Jul 2024 23:23:56 -0400
parents 6b0768158dcd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
1 #include "gui/widgets/anime_info.h"
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
2 #include "core/anime.h"
320
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
3 #include "core/anime_db.h"
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
4 #include "core/strings.h"
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
5 #include "gui/translate/anime.h"
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
6 #include "gui/widgets/text.h"
320
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
7 #include "services/services.h"
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
8 #include <QHBoxLayout>
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
9 #include <QTextStream>
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
10
320
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
11 AnimeInfoWidgetGetMetadataThread::AnimeInfoWidgetGetMetadataThread(QObject* parent) : QThread(parent) {}
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
12
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
13 void AnimeInfoWidgetGetMetadataThread::AddToQueue(int id) {
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
14 const std::lock_guard<std::mutex> guard(queue_mutex_);
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
15 queue_.push(id);
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
16 }
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
17
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
18 /* processes the queue... */
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
19 void AnimeInfoWidgetGetMetadataThread::run() {
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
20 queue_mutex_.lock();
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
21 while (!queue_.empty() && !isInterruptionRequested()) {
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
22 int id = queue_.front();
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
23
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
24 queue_mutex_.unlock();
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
25
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
26 if (Services::RetrieveAnimeMetadata(id))
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
27 emit NeedRefresh(id);
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
28
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
29 queue_mutex_.lock();
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
30
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
31 queue_.pop();
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
32 }
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
33 queue_mutex_.unlock();
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
34 }
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
35
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
36 /* all widgets share this thread */
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
37 static AnimeInfoWidgetGetMetadataThread get_metadata_thread;
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
38
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
39 AnimeInfoWidget::AnimeInfoWidget(QWidget* parent) : QWidget(parent) {
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
40 QVBoxLayout* layout = new QVBoxLayout(this);
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
41
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
42 _title.GetHeader().SetText(Strings::Translate("Alternative titles"));
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
43 layout->addWidget(&_title);
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
44
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
45 _details.GetHeader().SetText(Strings::Translate("Details"));
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
46
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
47 const std::vector<std::pair<std::string, std::string>> items = {
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
48 {Strings::Translate("Type:"), ""},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
49 {Strings::Translate("Episodes:"), ""},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
50 {Strings::Translate("Status:"), ""},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
51 {Strings::Translate("Season:"), ""},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
52 {Strings::Translate("Genres:"), ""},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
53 {Strings::Translate("Producers:"), ""},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
54 {Strings::Translate("Score:"), ""},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
55 };
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
56
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
57 _details.GetContent().SetData(items);
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
58
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
59 layout->addWidget(&_details);
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
60
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
61 _synopsis.GetHeader().SetText(Strings::Translate("Synopsis"));
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
62 layout->addWidget(&_synopsis);
320
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
63
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
64 layout->addStretch();
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
65
320
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
66 /* ... */
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
67 connect(&get_metadata_thread, &AnimeInfoWidgetGetMetadataThread::NeedRefresh, this, [this](int id) {
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
68 setUpdatesEnabled(false);
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
69
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
70 if (id == id_)
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
71 RefreshGenres(Anime::db.items[id]);
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
72
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
73 setUpdatesEnabled(true);
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
74 });
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
75 }
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
76
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
77 AnimeInfoWidget::AnimeInfoWidget(const Anime::Anime& anime, QWidget* parent) : AnimeInfoWidget(parent) {
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
78 SetAnime(anime);
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
79 }
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
80
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
81 void AnimeInfoWidget::SetAnime(const Anime::Anime& anime) {
320
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
82 setUpdatesEnabled(false);
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
83
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
84 id_ = anime.GetId();
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
85
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
86 get_metadata_thread.AddToQueue(id_);
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
87 if (!get_metadata_thread.isRunning())
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
88 get_metadata_thread.start();
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
89
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
90 /* alt titles */
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
91 _title.GetContent().SetText(Strings::Implode(anime.GetTitleSynonyms(), ", "));
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
92
320
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
93 RefreshGenres(anime);
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
94
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
95 _synopsis.GetContent().SetText(anime.GetSynopsis());
320
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
96
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
97 setUpdatesEnabled(true);
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
98
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
99 updateGeometry();
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
100 }
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
101
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
102 void AnimeInfoWidget::RefreshGenres(const Anime::Anime& anime) {
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
103 /* we have to convert ALL of these strings to
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
104 * QString because QTextStream sucks and assumes
320
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
105 * Latin-1 (on Windows?) */
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
106 const auto genres = anime.GetGenres();
320
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
107 const auto producers = anime.GetProducers();
1b5c04268d6a services/kitsu: ACTUALLY finish GetAnimeList
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
108
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
109 const std::vector<std::pair<std::string, std::string>> items = {
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
110 {Strings::Translate("Type:"), Translate::ToLocalString(anime.GetFormat())},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
111 {Strings::Translate("Episodes:"), Strings::ToUtf8String(anime.GetEpisodes())},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
112 {Strings::Translate("Status:"), Translate::ToLocalString(anime.GetAiringStatus())},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
113 {Strings::Translate("Season:"), Translate::ToLocalString(anime.GetSeason())},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
114 {Strings::Translate("Genres:"), (genres.size() > 1) ? Strings::Implode(genres, ", ") : "-"},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
115 {Strings::Translate("Producers:"), (producers.size() > 1) ? Strings::Implode(producers, ", ") : "-"},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
116 {Strings::Translate("Score:"), Strings::ToUtf8String(anime.GetAudienceScore()) + "%"},
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
117 };
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
118
348
6b0768158dcd text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents: 327
diff changeset
119 _details.GetContent().SetData(items);
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
120 }