Mercurial > minori
comparison src/gui/pages/seasons.cc @ 327:b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
ToLocalString has also been altered to take in both season
and year because lots of locales actually treat formatting
seasons differently! most notably is Russian which adds a
suffix at the end to notate seasons(??)
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Thu, 13 Jun 2024 01:49:18 -0400 |
parents | 10096c5489e3 |
children | 6b0768158dcd |
comparison
equal
deleted
inserted
replaced
326:10096c5489e3 | 327:b5d6c27c308f |
---|---|
16 #include <QVBoxLayout> | 16 #include <QVBoxLayout> |
17 | 17 |
18 SeasonsPageSearchThread::SeasonsPageSearchThread(QObject* parent) : QThread(parent) { | 18 SeasonsPageSearchThread::SeasonsPageSearchThread(QObject* parent) : QThread(parent) { |
19 } | 19 } |
20 | 20 |
21 void SeasonsPageSearchThread::AddToQueue(Anime::SeriesSeason season, Date::Year year) { | 21 void SeasonsPageSearchThread::AddToQueue(Anime::Season season) { |
22 queue_mutex_.lock(); | 22 queue_mutex_.lock(); |
23 queue_.push({season, year}); | 23 queue_.push(season); |
24 queue_mutex_.unlock(); | 24 queue_mutex_.unlock(); |
25 } | 25 } |
26 | 26 |
27 void SeasonsPageSearchThread::run() { | 27 void SeasonsPageSearchThread::run() { |
28 queue_mutex_.lock(); | 28 queue_mutex_.lock(); |
29 | 29 |
30 while (!queue_.empty() && !isInterruptionRequested()) { | 30 while (!queue_.empty() && !isInterruptionRequested()) { |
31 Season season = queue_.front(); | 31 Anime::Season season = queue_.front(); |
32 | 32 |
33 /* unlock the mutex for a long blocking operation, so items | 33 /* unlock the mutex for a long blocking operation, so items |
34 * can be added without worry */ | 34 * can be added without worry */ |
35 queue_mutex_.unlock(); | 35 queue_mutex_.unlock(); |
36 | 36 |
37 if (Services::GetSeason(season.season, season.year)) | 37 if (Services::GetSeason(season)) |
38 emit ReceivedSeason(season.season, season.year); | 38 emit ReceivedSeason(season); |
39 | 39 |
40 queue_mutex_.lock(); | 40 queue_mutex_.lock(); |
41 | 41 |
42 queue_.pop(); | 42 queue_.pop(); |
43 } | 43 } |
59 if (!buttons || !season_button) | 59 if (!buttons || !season_button) |
60 return; | 60 return; |
61 | 61 |
62 buttons->clear(); | 62 buttons->clear(); |
63 | 63 |
64 for (const auto& id : Anime::db.GetAllAnimeForSeason(season_, year_)) { | 64 for (const auto& id : Anime::db.GetAllAnimeForSeason(season_)) { |
65 QListWidgetItem* item = new QListWidgetItem; | 65 QListWidgetItem* item = new QListWidgetItem; |
66 AnimeButton* button = new AnimeButton(this); | 66 AnimeButton* button = new AnimeButton(this); |
67 button->SetAnime(Anime::db.items[id]); | 67 button->SetAnime(Anime::db.items[id]); |
68 item->setSizeHint(button->sizeHint()); | 68 item->setSizeHint(button->sizeHint()); |
69 buttons->addItem(item); | 69 buttons->addItem(item); |
70 buttons->setItemWidget(item, button); | 70 buttons->setItemWidget(item, button); |
71 } | 71 } |
72 | 72 |
73 season_button->setText(Strings::ToQString(Translate::ToLocalString(season_)) + " " + QString::number(year_)); | 73 season_button->setText(Strings::ToQString(Translate::ToLocalString(season_))); |
74 | 74 |
75 setUpdatesEnabled(true); | 75 setUpdatesEnabled(true); |
76 } | 76 } |
77 | 77 |
78 void SeasonsPage::SetSeason(Anime::SeriesSeason season, Date::Year year) { | 78 void SeasonsPage::SetSeason(Anime::Season season) { |
79 season_ = season; | 79 season_ = season; |
80 year_ = year; | |
81 | 80 |
82 Refresh(); | 81 Refresh(); |
83 } | 82 } |
84 | 83 |
85 SeasonsPage::SeasonsPage(QWidget* parent) : QFrame(parent) { | 84 SeasonsPage::SeasonsPage(QWidget* parent) : QFrame(parent) { |
95 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | 94 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); |
96 toolbar->setIconSize(QSize(16, 16)); | 95 toolbar->setIconSize(QSize(16, 16)); |
97 toolbar->setMovable(false); | 96 toolbar->setMovable(false); |
98 | 97 |
99 { | 98 { |
99 /* currently this is VERY hardcoded to en_US */ | |
100 static constexpr Date::Year last_year = 1960; | 100 static constexpr Date::Year last_year = 1960; |
101 | 101 |
102 auto create_year_menu = [this](QWidget* parent, QMenu* parent_menu, Date::Year year){ | 102 auto create_year_menu = [this](QWidget* parent, QMenu* parent_menu, Date::Year year){ |
103 const QString year_s = QString::number(year); | 103 const QString year_s = QString::number(year); |
104 | 104 |
105 QMenu* menu = new QMenu(year_s, parent); | 105 QMenu* menu = new QMenu(year_s, parent); |
106 for (const auto& season : Anime::SeriesSeasons) { | 106 for (const auto& season : Anime::Season::Names) { |
107 QAction* action = menu->addAction(Strings::ToQString(Translate::ToLocalString(season)) + " " + year_s); | 107 QAction* action = menu->addAction(Strings::ToQString(Translate::ToLocalString(Anime::Season(season, year)))); |
108 connect(action, &QAction::triggered, this, [this, season, year] { | 108 connect(action, &QAction::triggered, this, [this, season, year] { |
109 SetSeason(season, year); | 109 SetSeason({season, year}); |
110 }); | 110 }); |
111 } | 111 } |
112 parent_menu->addMenu(menu); | 112 parent_menu->addMenu(menu); |
113 }; | 113 }; |
114 | 114 |
141 | 141 |
142 toolbar->addSeparator(); | 142 toolbar->addSeparator(); |
143 | 143 |
144 { | 144 { |
145 toolbar->addAction(QIcon(":/icons/16x16/arrow-circle-315.png"), tr("Refresh data"), [this]{ | 145 toolbar->addAction(QIcon(":/icons/16x16/arrow-circle-315.png"), tr("Refresh data"), [this]{ |
146 search_thread_.AddToQueue(season_, year_); | 146 search_thread_.AddToQueue(season_); |
147 if (!search_thread_.isRunning()) | 147 if (!search_thread_.isRunning()) |
148 search_thread_.start(); | 148 search_thread_.start(); |
149 }); | 149 }); |
150 } | 150 } |
151 | 151 |
232 } | 232 } |
233 | 233 |
234 full_layout->setContentsMargins(0, 0, 0, 0); | 234 full_layout->setContentsMargins(0, 0, 0, 0); |
235 full_layout->setSpacing(0); | 235 full_layout->setSpacing(0); |
236 | 236 |
237 connect(&search_thread_, &SeasonsPageSearchThread::ReceivedSeason, this, [this](Anime::SeriesSeason season, Date::Year year) { | 237 connect(&search_thread_, &SeasonsPageSearchThread::ReceivedSeason, this, [this](Anime::Season season) { |
238 if (season == season_ && year == year_) | 238 if (season == season_) |
239 Refresh(); | 239 Refresh(); |
240 }); | 240 }); |
241 | 241 |
242 /* Do NOT move this up in this function, buttons HAS to be initialized */ | 242 /* Do NOT move this up in this function, buttons HAS to be initialized */ |
243 SetSeason(Anime::SeriesSeason::Summer, 2011U); | 243 SetSeason({Anime::Season::Name::Summer, 2011U}); |
244 } | 244 } |