void SearchDialog::AddAnimeToList(int anime_id) { auto anime_item = AnimeDatabase.FindItem(anime_id); if (anime_item) { int i = list_.GetItemCount(); list_.InsertItem(i, anime_item->IsInList() ? 1 : 0, StatusToIcon(anime_item->GetAiringStatus()), 0, nullptr, anime_item->GetTitle().c_str(), static_cast<LPARAM>(anime_item->GetId())); list_.SetItem(i, 1, anime::TranslateType(anime_item->GetType()).c_str()); list_.SetItem(i, 2, anime::TranslateNumber(anime_item->GetEpisodeCount()).c_str()); list_.SetItem(i, 3, anime::TranslateScore(anime_item->GetScore()).c_str()); list_.SetItem(i, 4, anime::TranslateDateToSeasonString(anime_item->GetDateStart()).c_str()); } }
void TorrentDialog::RefreshList() { if (!IsWindow()) return; Feed* feed = Aggregator.Get(kFeedCategoryLink); if (!feed) return; // Disable drawing list_.SetRedraw(FALSE); // Clear list list_.DeleteAllItems(); // Add items for (auto it = feed->items.begin(); it != feed->items.end(); ++it) { // Skip item if it was discarded and hidden if (it->state == kFeedItemDiscardedHidden) continue; std::wstring title, number, video; int group = kTorrentCategoryAnime; int icon = StatusToIcon(anime::kUnknownStatus); if (it->category == L"Batch" || InStr(it->title, L"Vol.") > -1) { group = kTorrentCategoryBatch; } if (!IsNumeric(it->episode_data.number)) { if (it->episode_data.format.empty() || anime::IsEpisodeRange(it->episode_data.number)) { group = kTorrentCategoryBatch; } else { group = kTorrentCategoryOther; } } auto anime_item = AnimeDatabase.FindItem(it->episode_data.anime_id); if (anime_item) { icon = StatusToIcon(anime_item->GetAiringStatus()); title = anime_item->GetTitle(); } else if (!it->episode_data.title.empty()) { title = it->episode_data.title; } else { group = kTorrentCategoryOther; title = it->title; } std::vector<int> numbers; anime::SplitEpisodeNumbers(it->episode_data.number, numbers); number = anime::JoinEpisodeNumbers(numbers); if (!it->episode_data.version.empty()) { number += L"v" + it->episode_data.version; } video = it->episode_data.video_type; if (!it->episode_data.resolution.empty()) { if (!video.empty()) video += L" "; video += it->episode_data.resolution; } int index = list_.InsertItem(it - feed->items.begin(), group, icon, 0, NULL, title.c_str(), reinterpret_cast<LPARAM>(&(*it))); list_.SetItem(index, 1, number.c_str()); list_.SetItem(index, 2, it->episode_data.group.c_str()); list_.SetItem(index, 3, it->episode_data.file_size.c_str()); list_.SetItem(index, 4, video.c_str()); list_.SetItem(index, 5, it->description.c_str()); list_.SetItem(index, 6, it->episode_data.file.c_str()); list_.SetCheckState(index, it->state == kFeedItemSelected); } // Redraw list_.SetRedraw(TRUE); list_.RedrawWindow(nullptr, nullptr, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN); }
bool EvaluateCondition(const FeedFilterCondition& condition, const FeedItem& item) { bool is_numeric = false; std::wstring element; std::wstring value = ReplaceVariables(condition.value, item.episode_data); auto anime = AnimeDatabase.FindItem(item.episode_data.anime_id); switch (condition.element) { case kFeedFilterElement_File_Title: element = item.title; break; case kFeedFilterElement_File_Category: element = item.category; break; case kFeedFilterElement_File_Description: element = item.description; break; case kFeedFilterElement_File_Link: element = item.link; break; case kFeedFilterElement_Meta_Id: if (anime) element = ToWstr(anime->GetId()); is_numeric = true; break; case kFeedFilterElement_Episode_Title: element = item.episode_data.title; break; case kFeedFilterElement_Meta_DateStart: if (anime) element = anime->GetDateStart(); break; case kFeedFilterElement_Meta_DateEnd: if (anime) element = anime->GetDateEnd(); break; case kFeedFilterElement_Meta_Episodes: if (anime) element = ToWstr(anime->GetEpisodeCount()); is_numeric = true; break; case kFeedFilterElement_Meta_Status: if (anime) element = ToWstr(anime->GetAiringStatus()); is_numeric = true; break; case kFeedFilterElement_Meta_Type: if (anime) element = ToWstr(anime->GetType()); is_numeric = true; break; case kFeedFilterElement_User_Status: if (anime) element = ToWstr(anime->GetMyStatus()); is_numeric = true; break; case kFeedFilterElement_Episode_Number: element = ToWstr(anime::GetEpisodeHigh(item.episode_data.number)); is_numeric = true; break; case kFeedFilterElement_Episode_Version: element = item.episode_data.version; if (element.empty()) element = L"1"; is_numeric = true; break; case kFeedFilterElement_Local_EpisodeAvailable: if (anime) element = ToWstr(anime->IsEpisodeAvailable( anime::GetEpisodeHigh(item.episode_data.number))); is_numeric = true; break; case kFeedFilterElement_Episode_Group: element = item.episode_data.group; break; case kFeedFilterElement_Episode_VideoResolution: element = item.episode_data.resolution; break; case kFeedFilterElement_Episode_VideoType: element = item.episode_data.video_type; break; } switch (condition.op) { case kFeedFilterOperator_Equals: if (is_numeric) { if (IsEqual(value, L"True")) return ToInt(element) == TRUE; return ToInt(element) == ToInt(value); } else { if (condition.element == kFeedFilterElement_Episode_VideoResolution) { return anime::TranslateResolution(element) == anime::TranslateResolution(condition.value); } else { return IsEqual(element, value); } } case kFeedFilterOperator_NotEquals: if (is_numeric) { if (IsEqual(value, L"True")) return ToInt(element) == TRUE; return ToInt(element) != ToInt(value); } else { if (condition.element == kFeedFilterElement_Episode_VideoResolution) { return anime::TranslateResolution(element) != anime::TranslateResolution(condition.value); } else { return !IsEqual(element, value); } } case kFeedFilterOperator_IsGreaterThan: if (is_numeric) { return ToInt(element) > ToInt(value); } else { if (condition.element == kFeedFilterElement_Episode_VideoResolution) { return anime::TranslateResolution(element) > anime::TranslateResolution(condition.value); } else { return CompareStrings(element, condition.value) > 0; } } case kFeedFilterOperator_IsGreaterThanOrEqualTo: if (is_numeric) { return ToInt(element) >= ToInt(value); } else { if (condition.element == kFeedFilterElement_Episode_VideoResolution) { return anime::TranslateResolution(element) >= anime::TranslateResolution(condition.value); } else { return CompareStrings(element, condition.value) >= 0; } } case kFeedFilterOperator_IsLessThan: if (is_numeric) { return ToInt(element) < ToInt(value); } else { if (condition.element == kFeedFilterElement_Episode_VideoResolution) { return anime::TranslateResolution(element) < anime::TranslateResolution(condition.value); } else { return CompareStrings(element, condition.value) < 0; } } case kFeedFilterOperator_IsLessThanOrEqualTo: if (is_numeric) { return ToInt(element) <= ToInt(value); } else { if (condition.element == kFeedFilterElement_Episode_VideoResolution) { return anime::TranslateResolution(element) <= anime::TranslateResolution(condition.value); } else { return CompareStrings(element, condition.value) <= 0; } } case kFeedFilterOperator_BeginsWith: return StartsWith(element, value); case kFeedFilterOperator_EndsWith: return EndsWith(element, value); case kFeedFilterOperator_Contains: return InStr(element, value, 0, true) > -1; case kFeedFilterOperator_NotContains: return InStr(element, value, 0, true) == -1; } return false; }
void TorrentDialog::RefreshList() { if (!IsWindow()) return; Feed* feed = Aggregator.Get(FEED_CATEGORY_LINK); if (!feed) return; // Hide list to avoid visual defects and gain performance list_.Hide(); list_.DeleteAllItems(); // Add items for (auto it = feed->items.begin(); it != feed->items.end(); ++it) { // Skip item if it was discarded and hidden if (it->state == FEEDITEM_DISCARDED_HIDDEN) continue; wstring title, number, video; int group = TORRENT_ANIME, icon = StatusToIcon(0); if (it->category == L"Batch" || InStr(it->title, L"Vol.") > -1) { group = TORRENT_BATCH; } if (!IsNumeric(it->episode_data.number)) { if (it->episode_data.format.empty() || IsEpisodeRange(it->episode_data.number)) { group = TORRENT_BATCH; } else { group = TORRENT_OTHER; } } auto anime_item = AnimeDatabase.FindItem(it->episode_data.anime_id); if (anime_item) { icon = StatusToIcon(anime_item->GetAiringStatus()); title = anime_item->GetTitle(); } else if (!it->episode_data.title.empty()) { title = it->episode_data.title; } else { group = TORRENT_OTHER; title = it->title; } vector<int> numbers; SplitEpisodeNumbers(it->episode_data.number, numbers); number = JoinEpisodeNumbers(numbers); if (!it->episode_data.version.empty()) { number += L"v" + it->episode_data.version; } video = it->episode_data.video_type; if (!it->episode_data.resolution.empty()) { if (!video.empty()) video += L" "; video += it->episode_data.resolution; } int index = list_.InsertItem(it - feed->items.begin(), group, icon, 0, NULL, title.c_str(), reinterpret_cast<LPARAM>(&(*it))); list_.SetItem(index, 1, number.c_str()); list_.SetItem(index, 2, it->episode_data.group.c_str()); list_.SetItem(index, 3, it->episode_data.file_size.c_str()); list_.SetItem(index, 4, video.c_str()); list_.SetItem(index, 5, it->description.c_str()); list_.SetItem(index, 6, it->episode_data.file.c_str()); list_.SetCheckState(index, it->state == FEEDITEM_SELECTED); } // Show again list_.Show(); // Set title wstring title = L"Torrents"; if (!feed->title.empty()) { title = feed->title; } else if (!feed->link.empty()) { win32::Url url(feed->link); title += L" (" + url.Host + L")"; } if (!feed->description.empty()) { title += L" - " + feed->description; } SetText(title.c_str()); }