comparison src/gui/pages/anime_list.cc @ 274:f6a756c19bfb

anime_list.cc: use mutexes so we don't sex the stack strings.cc: use Qt to convert from HTML to plain text.
author Paper <paper@paper.us.eu.org>
date Thu, 18 Apr 2024 17:24:42 -0400
parents f31305b9f60a
children 9a88e1725fd2
comparison
equal deleted inserted replaced
273:f31305b9f60a 274:f6a756c19bfb
36 AnimeListPageUpdateEntryThread::AnimeListPageUpdateEntryThread(AnimeListPage* parent) : QThread(parent) { 36 AnimeListPageUpdateEntryThread::AnimeListPageUpdateEntryThread(AnimeListPage* parent) : QThread(parent) {
37 page_ = parent; 37 page_ = parent;
38 } 38 }
39 39
40 void AnimeListPageUpdateEntryThread::AddToQueue(int id) { 40 void AnimeListPageUpdateEntryThread::AddToQueue(int id) {
41 if (isRunning()) 41 const std::lock_guard<std::mutex> guard(_queue_mutex);
42 return; /* don't let us fuck ourselves */
43
44 queue_.push(id); 42 queue_.push(id);
45 } 43 }
46 44
47 /* processes the queue... */ 45 /* processes the queue... */
48 void AnimeListPageUpdateEntryThread::run() { 46 void AnimeListPageUpdateEntryThread::run() {
49 while (!queue_.empty() && !isInterruptionRequested()) { 47 {
50 Services::UpdateAnimeEntry(queue_.front()); 48 const std::lock_guard<std::mutex> guard(_queue_mutex);
51 queue_.pop(); 49 while (!queue_.empty() && !isInterruptionRequested()) {
50 Services::UpdateAnimeEntry(queue_.front());
51 queue_.pop();
52 }
52 } 53 }
53 page_->Refresh(); 54 page_->Refresh();
54 } 55 }
55 56
56 AnimeListPageSortFilter::AnimeListPageSortFilter(QObject* parent) : QSortFilterProxyModel(parent) { 57 AnimeListPageSortFilter::AnimeListPageSortFilter(QObject* parent) : QSortFilterProxyModel(parent) {
239 tree_view->setColumnHidden(AnimeListPageModel::AL_NOTES, true); 240 tree_view->setColumnHidden(AnimeListPageModel::AL_NOTES, true);
240 } 241 }
241 242
242 void AnimeListPage::UpdateAnime(int id) { 243 void AnimeListPage::UpdateAnime(int id) {
243 /* this ought to just add to the thread's buffer. */ 244 /* this ought to just add to the thread's buffer. */
244 if (update_entry_thread_.isRunning()) { 245 if (update_entry_thread_.isRunning())
245 update_entry_thread_.requestInterruption(); 246 update_entry_thread_.requestInterruption();
246 update_entry_thread_.wait();
247 }
248 247
249 update_entry_thread_.AddToQueue(id); 248 update_entry_thread_.AddToQueue(id);
250 update_entry_thread_.start(); 249 update_entry_thread_.start();
251 } 250 }
252 251