LRESULT TorrentDialog::OnNotify(int idCtrl, LPNMHDR pnmh) { Feed* feed = Aggregator.Get(kFeedCategoryLink); if (!feed) return 0; // ListView control if (idCtrl == IDC_LIST_TORRENT) { switch (pnmh->code) { // Column click case LVN_COLUMNCLICK: { LPNMLISTVIEW lplv = (LPNMLISTVIEW)pnmh; int order = 1; if (lplv->iSubItem == list_.GetSortColumn()) order = list_.GetSortOrder() * -1; switch (lplv->iSubItem) { // Episode case 1: list_.Sort(lplv->iSubItem, order, ui::kListSortNumber, ui::ListViewCompareProc); break; // File size case 3: list_.Sort(lplv->iSubItem, order, ui::kListSortFileSize, ui::ListViewCompareProc); break; // Other columns default: list_.Sort(lplv->iSubItem, order, ui::kListSortDefault, ui::ListViewCompareProc); break; } break; } // Check/uncheck case LVN_ITEMCHANGED: { if (!list_.IsVisible()) break; LPNMLISTVIEW pnmv = reinterpret_cast<LPNMLISTVIEW>(pnmh); if (pnmv->uOldState != 0 && (pnmv->uNewState == 0x1000 || pnmv->uNewState == 0x2000)) { int checked_count = 0; for (int i = 0; i < list_.GetItemCount(); i++) { if (list_.GetCheckState(i)) checked_count++; } if (checked_count == 1) { DlgMain.ChangeStatus(L"Marked 1 torrent."); } else { DlgMain.ChangeStatus(L"Marked " + ToWstr(checked_count) + L" torrents."); } FeedItem* feed_item = reinterpret_cast<FeedItem*>(list_.GetItemParam(pnmv->iItem)); if (feed_item) { bool checked = list_.GetCheckState(pnmv->iItem) == TRUE; feed_item->state = checked ? kFeedItemSelected : kFeedItemDiscardedNormal; } } break; } // Double click case NM_DBLCLK: { if (list_.GetSelectedCount() > 0) { LPNMITEMACTIVATE lpnmitem = reinterpret_cast<LPNMITEMACTIVATE>(pnmh); if (lpnmitem->iItem == -1) break; FeedItem* feed_item = reinterpret_cast<FeedItem*>(list_.GetItemParam(lpnmitem->iItem)); if (feed_item) feed->Download(feed_item->index); } break; } // Right click case NM_RCLICK: { LPNMITEMACTIVATE lpnmitem = reinterpret_cast<LPNMITEMACTIVATE>(pnmh); if (lpnmitem->iItem == -1) break; FeedItem* feed_item = reinterpret_cast<FeedItem*>(list_.GetItemParam(lpnmitem->iItem)); if (feed_item) { std::wstring answer = ui::Menus.Show(GetWindowHandle(), 0, 0, L"TorrentListRightClick"); if (answer == L"DownloadTorrent") { feed->Download(feed_item->index); } else if (answer == L"Info") { auto anime_id = feed_item->episode_data.anime_id; if (anime_id) { ShowDlgAnimeInfo(anime_id); } else { ExecuteAction(L"SearchAnime(" + feed_item->episode_data.title + L")"); } } else if (answer == L"DiscardTorrent") { feed_item->state = kFeedItemDiscardedNormal; list_.SetCheckState(lpnmitem->iItem, FALSE); Aggregator.file_archive.push_back(feed_item->title); } else if (answer == L"DiscardTorrents") { auto anime_item = AnimeDatabase.FindItem(feed_item->episode_data.anime_id); if (anime_item) { for (int i = 0; i < list_.GetItemCount(); i++) { feed_item = reinterpret_cast<FeedItem*>(list_.GetItemParam(i)); if (feed_item && feed_item->episode_data.anime_id == anime_item->GetId()) { feed_item->state = kFeedItemDiscardedNormal; list_.SetCheckState(i, FALSE); } } Aggregator.filter_manager.AddFilter( kFeedFilterActionDiscard, kFeedFilterMatchAll, kFeedFilterOptionDefault, true, L"Discard \"" + anime_item->GetTitle() + L"\""); Aggregator.filter_manager.filters.back().AddCondition( kFeedFilterElement_Meta_Id, kFeedFilterOperator_Equals, ToWstr(anime_item->GetId())); } } else if (answer == L"SelectFansub") { int anime_id = feed_item->episode_data.anime_id; std::wstring group_name = feed_item->episode_data.group; if (anime::IsValidId(anime_id) && !group_name.empty()) { for (int i = 0; i < list_.GetItemCount(); i++) { feed_item = reinterpret_cast<FeedItem*>(list_.GetItemParam(i)); if (feed_item && !IsEqual(feed_item->episode_data.group, group_name)) { feed_item->state = kFeedItemDiscardedNormal; list_.SetCheckState(i, FALSE); } } anime::SetFansubFilter(anime_id, group_name); } } else if (answer == L"MoreTorrents") { Search(Settings[taiga::kTorrent_Discovery_SearchUrl], feed_item->episode_data.title); } else if (answer == L"SearchService") { ExecuteAction(L"SearchAnime(" + feed_item->episode_data.title + L")"); } } break; } // Custom draw case NM_CUSTOMDRAW: { LPNMLVCUSTOMDRAW pCD = reinterpret_cast<LPNMLVCUSTOMDRAW>(pnmh); switch (pCD->nmcd.dwDrawStage) { case CDDS_PREPAINT: return CDRF_NOTIFYITEMDRAW; case CDDS_ITEMPREPAINT: return CDRF_NOTIFYSUBITEMDRAW; case CDDS_PREERASE: case CDDS_ITEMPREERASE: return CDRF_NOTIFYPOSTERASE; case CDDS_ITEMPREPAINT | CDDS_SUBITEM: { // Alternate background color if ((pCD->nmcd.dwItemSpec % 2) && !list_.IsGroupViewEnabled()) pCD->clrTextBk = ChangeColorBrightness(GetSysColor(COLOR_WINDOW), -0.03f); FeedItem* feed_item = reinterpret_cast<FeedItem*>(pCD->nmcd.lItemlParam); if (feed_item) { if (Taiga.debug_mode) { // Change background color switch (feed_item->state) { case kFeedItemDiscardedNormal: case kFeedItemDiscardedInactive: case kFeedItemDiscardedHidden: pCD->clrTextBk = ui::kColorLightRed; break; case kFeedItemSelected: pCD->clrTextBk = ui::kColorLightGreen; break; default: pCD->clrTextBk = GetSysColor(COLOR_WINDOW); break; } } // Change text color if (feed_item->state == kFeedItemDiscardedInactive) { pCD->clrText = GetSysColor(COLOR_GRAYTEXT); } else if (feed_item->episode_data.new_episode) { pCD->clrText = GetSysColor(pCD->iSubItem == 1 ? COLOR_HIGHLIGHT : COLOR_WINDOWTEXT); } } return CDRF_NOTIFYPOSTPAINT; } } } } } return 0; }
LRESULT TorrentDialog::OnNotify(int idCtrl, LPNMHDR pnmh) { Feed* feed = Aggregator.Get(FEED_CATEGORY_LINK); if (!feed) return 0; // ListView control if (idCtrl == IDC_LIST_TORRENT) { switch (pnmh->code) { // Column click case LVN_COLUMNCLICK: { LPNMLISTVIEW lplv = (LPNMLISTVIEW)pnmh; int order = 1; if (lplv->iSubItem == list_.GetSortColumn()) order = list_.GetSortOrder() * -1; switch (lplv->iSubItem) { // Episode case 1: list_.Sort(lplv->iSubItem, order, LIST_SORTTYPE_NUMBER, ListViewCompareProc); break; // File size case 3: list_.Sort(lplv->iSubItem, order, LIST_SORTTYPE_FILESIZE, ListViewCompareProc); break; // Other columns default: list_.Sort(lplv->iSubItem, order, LIST_SORTTYPE_DEFAULT, ListViewCompareProc); break; } break; } // Check/uncheck case LVN_ITEMCHANGED: { if (!list_.IsVisible()) break; LPNMLISTVIEW pnmv = reinterpret_cast<LPNMLISTVIEW>(pnmh); if (pnmv->uOldState != 0 && (pnmv->uNewState == 0x1000 || pnmv->uNewState == 0x2000)) { int checked_count = 0; for (int i = 0; i < list_.GetItemCount(); i++) { if (list_.GetCheckState(i)) checked_count++; } if (checked_count == 1) { MainDialog.ChangeStatus(L"Marked 1 torrent."); } else { MainDialog.ChangeStatus(L"Marked " + ToWstr(checked_count) + L" torrents."); } FeedItem* feed_item = reinterpret_cast<FeedItem*>(list_.GetItemParam(pnmv->iItem)); if (feed_item) { bool checked = list_.GetCheckState(pnmv->iItem) == TRUE; feed_item->state = checked ? FEEDITEM_SELECTED : FEEDITEM_DISCARDED_NORMAL; } } break; } // Double click case NM_DBLCLK: { if (list_.GetSelectedCount() > 0) { LPNMITEMACTIVATE lpnmitem = reinterpret_cast<LPNMITEMACTIVATE>(pnmh); if (lpnmitem->iItem == -1) break; FeedItem* feed_item = reinterpret_cast<FeedItem*>(list_.GetItemParam(lpnmitem->iItem)); if (feed_item) { feed->Download(feed_item->index); } } break; } // Right click case NM_RCLICK: { LPNMITEMACTIVATE lpnmitem = reinterpret_cast<LPNMITEMACTIVATE>(pnmh); if (lpnmitem->iItem == -1) break; FeedItem* feed_item = reinterpret_cast<FeedItem*>(list_.GetItemParam(lpnmitem->iItem)); if (feed_item) { wstring answer = UI.Menus.Show(m_hWindow, 0, 0, L"TorrentListRightClick"); if (answer == L"DownloadTorrent") { feed->Download(feed_item->index); } else if (answer == L"Info") { auto anime_id = feed_item->episode_data.anime_id; if (anime_id) { ExecuteAction(L"Info", 0, anime_id); } else { ExecuteAction(L"SearchAnime(" + feed_item->episode_data.title + L")"); } } else if (answer == L"DiscardTorrent") { feed_item->state = FEEDITEM_DISCARDED_NORMAL; list_.SetCheckState(lpnmitem->iItem, FALSE); Aggregator.file_archive.push_back(feed_item->title); } else if (answer == L"DiscardTorrents") { auto anime_item = AnimeDatabase.FindItem(feed_item->episode_data.anime_id); if (anime_item) { for (int i = 0; i < list_.GetItemCount(); i++) { feed_item = reinterpret_cast<FeedItem*>(list_.GetItemParam(i)); if (feed_item && feed_item->episode_data.anime_id == anime_item->GetId()) { feed_item->state = FEEDITEM_DISCARDED_NORMAL; list_.SetCheckState(i, FALSE); } } Aggregator.filter_manager.AddFilter( FEED_FILTER_ACTION_DISCARD, FEED_FILTER_MATCH_ALL, FEED_FILTER_OPTION_DEFAULT, true, L"Discard \"" + anime_item->GetTitle() + L"\""); Aggregator.filter_manager.filters.back().AddCondition( FEED_FILTER_ELEMENT_META_ID, FEED_FILTER_OPERATOR_EQUALS, ToWstr(anime_item->GetId())); } } else if (answer == L"SelectFansub") { int anime_id = feed_item->episode_data.anime_id; wstring group_name = feed_item->episode_data.group; if (anime_id > anime::ID_UNKNOWN && !group_name.empty()) { for (int i = 0; i < list_.GetItemCount(); i++) { feed_item = reinterpret_cast<FeedItem*>(list_.GetItemParam(i)); if (feed_item && !IsEqual(feed_item->episode_data.group, group_name)) { feed_item->state = FEEDITEM_DISCARDED_NORMAL; list_.SetCheckState(i, FALSE); } } anime::SetFansubFilter(anime_id, group_name); } } else if (answer == L"MoreTorrents") { Search(Settings.RSS.Torrent.search_url, feed_item->episode_data.title); } else if (answer == L"SearchMAL") { ExecuteAction(L"SearchAnime(" + feed_item->episode_data.title + L")"); } } break; } // Custom draw case NM_CUSTOMDRAW: { LPNMLVCUSTOMDRAW pCD = reinterpret_cast<LPNMLVCUSTOMDRAW>(pnmh); switch (pCD->nmcd.dwDrawStage) { case CDDS_PREPAINT: return CDRF_NOTIFYITEMDRAW; case CDDS_ITEMPREPAINT: return CDRF_NOTIFYSUBITEMDRAW; case CDDS_PREERASE: case CDDS_ITEMPREERASE: return CDRF_NOTIFYPOSTERASE; case CDDS_ITEMPREPAINT | CDDS_SUBITEM: { // Alternate background color if ((pCD->nmcd.dwItemSpec % 2) && !list_.IsGroupViewEnabled()) pCD->clrTextBk = ChangeColorBrightness(GetSysColor(COLOR_WINDOW), -0.03f); FeedItem* feed_item = reinterpret_cast<FeedItem*>(pCD->nmcd.lItemlParam); if (feed_item) { #ifdef _DEBUG // Change background color switch (feed_item->state) { case FEEDITEM_DISCARDED_NORMAL: case FEEDITEM_DISCARDED_INACTIVE: case FEEDITEM_DISCARDED_HIDDEN: pCD->clrTextBk = theme::COLOR_LIGHTRED; break; case FEEDITEM_SELECTED: pCD->clrTextBk = theme::COLOR_LIGHTGREEN; break; default: pCD->clrTextBk = GetSysColor(COLOR_WINDOW); break; } #endif // Change text color if (feed_item->state == FEEDITEM_DISCARDED_INACTIVE) { pCD->clrText = GetSysColor(COLOR_GRAYTEXT); } else if (feed_item->episode_data.new_episode) { pCD->clrText = GetSysColor(pCD->iSubItem == 1 ? COLOR_HIGHLIGHT : COLOR_WINDOWTEXT); } } return CDRF_NOTIFYPOSTPAINT; } } } } } return 0; }