# HG changeset patch # User Paper # Date 1713475482 14400 # Node ID f6a756c19bfb70c69b602e6e833de1ee11e49d87 # Parent f31305b9f60ad3a15363f36b11c133b5b8277ab4 anime_list.cc: use mutexes so we don't sex the stack strings.cc: use Qt to convert from HTML to plain text. diff -r f31305b9f60a -r f6a756c19bfb include/gui/pages/anime_list.h --- a/include/gui/pages/anime_list.h Thu Apr 18 16:53:17 2024 -0400 +++ b/include/gui/pages/anime_list.h Thu Apr 18 17:24:42 2024 -0400 @@ -25,6 +25,7 @@ private: AnimeListPage* page_ = nullptr; + std::mutex _queue_mutex; std::queue queue_; }; diff -r f31305b9f60a -r f6a756c19bfb src/core/strings.cc --- a/src/core/strings.cc Thu Apr 18 16:53:17 2024 -0400 +++ b/src/core/strings.cc Thu Apr 18 17:24:42 2024 -0400 @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -148,24 +149,20 @@ /* e.g. "<" for "<" */ void ParseHtmlEntities(std::string& string) { - /* The only one of these I can understand using are the first - * three. why do the rest of these exist? - * - * probably mojibake. - */ const std::unordered_map map = { - {"<", "<" }, - {"&rt;", ">" }, + {"<", "<"}, + {"&rt;", ">"}, {" ", "\xA0"}, - {"&", "&" }, - {""", "\"" }, - {"'", "'" }, - {"¢", "¢" }, - {"£", "£" }, - {"€", "€" }, - {"¥", "¥" }, - {"©", "©" }, - {"®", "®" }, + {"&", "&"}, + {""", "\""}, + {"'", "'"}, + {"¢", "¢"}, + {"£", "£"}, + {"€", "€"}, + {"¥", "¥"}, + {"©", "©"}, + {"®", "®"}, + {"×", "×"}, {"’", "’" } // Haibane Renmei, AniList }; @@ -175,9 +172,17 @@ /* removes stupid HTML stuff */ void TextifySynopsis(std::string& string) { +#if 1 + /* Just let Qt deal with it. */ + QTextDocument text; + text.setHtml(Strings::ToQString(string)); + string = Strings::ToUtf8String(text.toPlainText()); +#else + /* old implementation here... beware of jankiness */ SanitizeLineEndings(string); RemoveHtmlTags(string); ParseHtmlEntities(string); +#endif } /* let Qt handle the heavy lifting of locale shit @@ -273,7 +278,7 @@ std::string BytesToHumanReadableSize(uint64_t bytes, int precision) { #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) /* QLocale in Qt >= 5.10.0 has a function for this */ - return Strings::ToUtf8String(session.config.locale.GetLocale().formattedDataSize(bytes), precision); + return Strings::ToUtf8String(session.config.locale.GetLocale().formattedDataSize(bytes, precision)); #else static const std::unordered_map map = { {1ull << 10, "KiB"}, diff -r f31305b9f60a -r f6a756c19bfb src/gui/pages/anime_list.cc --- a/src/gui/pages/anime_list.cc Thu Apr 18 16:53:17 2024 -0400 +++ b/src/gui/pages/anime_list.cc Thu Apr 18 17:24:42 2024 -0400 @@ -38,17 +38,18 @@ } void AnimeListPageUpdateEntryThread::AddToQueue(int id) { - if (isRunning()) - return; /* don't let us fuck ourselves */ - + const std::lock_guard guard(_queue_mutex); queue_.push(id); } /* processes the queue... */ void AnimeListPageUpdateEntryThread::run() { - while (!queue_.empty() && !isInterruptionRequested()) { - Services::UpdateAnimeEntry(queue_.front()); - queue_.pop(); + { + const std::lock_guard guard(_queue_mutex); + while (!queue_.empty() && !isInterruptionRequested()) { + Services::UpdateAnimeEntry(queue_.front()); + queue_.pop(); + } } page_->Refresh(); } @@ -241,10 +242,8 @@ void AnimeListPage::UpdateAnime(int id) { /* this ought to just add to the thread's buffer. */ - if (update_entry_thread_.isRunning()) { + if (update_entry_thread_.isRunning()) update_entry_thread_.requestInterruption(); - update_entry_thread_.wait(); - } update_entry_thread_.AddToQueue(id); update_entry_thread_.start();