PlaylistsCB.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include "main.h"
  2. #include "PlaylistsCB.h"
  3. using namespace Nullsoft::Utility;
  4. static UINT_PTR refreshTimer;
  5. void CALLBACK RefreshPlaylistsCallback(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
  6. {
  7. if (idEvent == 777)
  8. {
  9. KillTimer(plugin.hwndWinampParent, idEvent);
  10. refreshTimer = 0;
  11. RefreshPlaylistsList();
  12. }
  13. }
  14. int PlaylistsCB::notify(int msg, intptr_t param1, intptr_t param2)
  15. {
  16. switch (msg)
  17. {
  18. case api_playlists::PLAYLIST_ADDED:
  19. {
  20. AutoLockT<api_playlists> lock(AGAVE_API_PLAYLISTS); // should already be locked, but can't hurt
  21. size_t newIndex = static_cast<size_t>(param1);
  22. PlaylistInfo playlist(newIndex);
  23. if (playlist.Valid())
  24. {
  25. // TODO: check where newIndex is, so we can insert into the middle of the list if necessary
  26. /* TODO: maybe stuff this in Set/GetInfo somewhere
  27. if (makeTree)
  28. */
  29. MakeTree(playlist);
  30. if (refreshTimer) KillTimer(plugin.hwndWinampParent, refreshTimer);
  31. refreshTimer = SetTimer(plugin.hwndWinampParent, 777, 250, RefreshPlaylistsCallback);
  32. if (!param2) AGAVE_API_PLAYLISTS->Flush(); // REVIEW: save immediately? or only at the end?
  33. }
  34. return 1;
  35. }
  36. break;
  37. case api_playlists::PLAYLIST_REMOVED_PRE:
  38. {
  39. AutoLockT<api_playlists> lock(AGAVE_API_PLAYLISTS); // should already be locked, but can't hurt
  40. size_t index = static_cast<size_t>(param1),
  41. count = AGAVE_API_PLAYLISTS->GetCount();
  42. PlaylistInfo info(index);
  43. if (info.Valid())
  44. {
  45. // is a number of cases where this just seems to fail and so we revert to manually
  46. // parsing the playlists tree inorder to find and remove the expected playlist by
  47. // the index of the playlist (since we don't alter the order, this should be safe)
  48. if (!info.treeId)
  49. {
  50. INT_PTR id = mediaLibrary.GetChildId(playlistsTreeId);
  51. if (id)
  52. {
  53. for (size_t i = 0; i < count; i++)
  54. {
  55. if (i == index)
  56. {
  57. mediaLibrary.RemoveTreeItem(id);
  58. break;
  59. }
  60. if (!(id = mediaLibrary.GetNextId(id))) break;
  61. }
  62. }
  63. }
  64. else
  65. mediaLibrary.RemoveTreeItem(info.treeId);
  66. tree_to_guid_map.erase(info.treeId);
  67. }
  68. return 1;
  69. }
  70. break;
  71. case api_playlists::PLAYLIST_REMOVED_POST:
  72. {
  73. if (refreshTimer) KillTimer(plugin.hwndWinampParent, refreshTimer);
  74. refreshTimer = SetTimer(plugin.hwndWinampParent, 777, 250, RefreshPlaylistsCallback);
  75. return 1;
  76. }
  77. break;
  78. case api_playlists::PLAYLIST_RENAMED:
  79. {
  80. AutoLockT<api_playlists> lock(AGAVE_API_PLAYLISTS); // should already be locked, but can't hurt
  81. // tell the media library to rename the treeview node
  82. size_t index = static_cast<size_t>(param1);
  83. PlaylistInfo playlist(index);
  84. if (playlist.Valid())
  85. {
  86. mediaLibrary.RenameTreeId(playlist.treeId, playlist.GetName());
  87. }
  88. return 1;
  89. }
  90. break;
  91. case api_playlists::PLAYLIST_SAVED:
  92. if (param2 != (intptr_t)&uniqueAddress)
  93. {
  94. AutoLockT<api_playlists> lock(AGAVE_API_PLAYLISTS); // should already be locked, but can't hurt
  95. size_t index = static_cast<size_t>(param1);
  96. playlist_ReloadGUID(AGAVE_API_PLAYLISTS->GetGUID(index));
  97. }
  98. break;
  99. case api_playlists::PLAYLIST_FLUSH_REQUEST:
  100. if (param2 != (intptr_t)&uniqueAddress)
  101. {
  102. AutoLockT<api_playlists> lock(AGAVE_API_PLAYLISTS); // should already be locked, but can't hurt
  103. size_t index = static_cast<size_t>(param1);
  104. playlist_SaveGUID(AGAVE_API_PLAYLISTS->GetGUID(index));
  105. }
  106. break;
  107. }
  108. return 0;
  109. }
  110. #define CBCLASS PlaylistsCB
  111. START_DISPATCH;
  112. CB(SYSCALLBACK_GETEVENTTYPE, getEventType);
  113. CB(SYSCALLBACK_NOTIFY, notify);
  114. END_DISPATCH;
  115. #undef CBCLASS