1
0

Wire.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include "Main.h"
  2. #include "./subscriptionView.h"
  3. #include "FeedsDialog.h"
  4. #include "Feeds.h"
  5. #include <algorithm>
  6. ChannelList channels;
  7. //CategoryIndex sourceByCategory;
  8. using namespace Nullsoft::Utility;
  9. //LockGuard /*feedGuard, */channelGuard, categoryGuard;
  10. void WireManager::BeginChannelSync()
  11. {
  12. // TODO something better than this =)
  13. // like making 'touched' flags and delete untouched ones
  14. //sources.clear();
  15. //sourceByCategory.clear();
  16. }
  17. void WireManager::NewChannel(const Channel &newChannel)
  18. {
  19. AutoLock lock (channels LOCKNAME("NewChannel"));
  20. for (ChannelList::iterator itr=channels.begin();itr!=channels.end(); itr++)
  21. {
  22. if (*itr == newChannel)
  23. {
  24. itr->UpdateFrom(newChannel);
  25. return;
  26. }
  27. }
  28. channels.push_back(newChannel);
  29. }
  30. void WireManager::EndChannelSync()
  31. {
  32. //SubscriptionView_RefreshChannels(NULL, TRUE);
  33. }
  34. bool ChannelTitleSort(Channel &channel1, Channel &channel2)
  35. {
  36. return (CSTR_LESS_THAN == CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE, channel1.title, -1, channel2.title, -1));
  37. }
  38. void ChannelList::SortByTitle()
  39. {
  40. AutoLock lock (channelGuard LOCKNAME("SortByTitle"));
  41. std::sort(channelList.begin(), channelList.end(), ChannelTitleSort);
  42. }
  43. void ChannelList::push_back(const Channel &channel)
  44. {
  45. channelList.push_back(channel);
  46. }
  47. bool ChannelList::AddChannel(Channel &channel)
  48. {
  49. ChannelList::iterator found;
  50. for (found=channels.begin(); found!=channels.end(); found++)
  51. {
  52. if (!wcscmp(found->url, channel.url))
  53. break;
  54. }
  55. if (found == channels.end()){
  56. channel.needsRefresh=true;
  57. push_back(channel);
  58. SaveChannels(*this);
  59. return true;
  60. }
  61. return false;
  62. }
  63. size_t ChannelList::GetNumPodcasts()
  64. {
  65. return channels.size();
  66. }
  67. ifc_podcast *ChannelList::EnumPodcast(size_t i)
  68. {
  69. if (i < channels.size())
  70. return &channels[i];
  71. else
  72. return 0;
  73. }
  74. #undef CBCLASS
  75. #define CBCLASS ChannelList
  76. START_DISPATCH;
  77. CB(API_PODCASTS_GETNUMPODCASTS, GetNumPodcasts)
  78. CB(API_PODCASTS_ENUMPODCAST, EnumPodcast)
  79. END_DISPATCH;
  80. #undef CBCLASS