Playlists.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef NULLSOFT_PLAYLIST_PLAYLISTS_H
  2. #define NULLSOFT_PLAYLIST_PLAYLISTS_H
  3. #include "api_playlists.h"
  4. #include <vector>
  5. #include "../nu/AutoLock.h"
  6. class PlaylistInfo
  7. {
  8. public:
  9. PlaylistInfo();
  10. PlaylistInfo(const wchar_t *_filename, const wchar_t *_title, GUID playlist_guid = INVALID_GUID);
  11. PlaylistInfo(const PlaylistInfo &copy);
  12. wchar_t filename[MAX_PATH];
  13. wchar_t title[1024];
  14. int length; // in seconds
  15. int numItems;
  16. GUID guid;
  17. uint64_t iTunesID; // this is used by ml_impex
  18. int cloud; // this is used by ml_playlists
  19. };
  20. class Playlists : public api_playlists
  21. {
  22. public:
  23. Playlists();
  24. bool DelayLoad();
  25. // api_playlists implementations
  26. void Lock();
  27. void Unlock();
  28. size_t GetIterator();
  29. int Sort(size_t sort_type);
  30. void Flush();
  31. // get information about playlists
  32. size_t GetCount(); // returns number of playlists
  33. const wchar_t *GetFilename(size_t index); // returns API_PLAYLISTS_SUCCESS or API_PLAYLISTS_FAILURE. only valid until you Unlock()
  34. const wchar_t *GetName(size_t index); // returns API_PLAYLISTS_SUCCESS or API_PLAYLISTS_FAILURE. only valid until you Unlock()
  35. GUID GetGUID(size_t index); // retrieves a unique ID which identifies this playlist
  36. int GetPosition(GUID playlist_guid, size_t *index); // retrieves the index where a particular playlist ID lives. returns API_PLAYLISTS_SUCCESS or API_PLAYLISTS_FAILURE
  37. int GetInfo(size_t index, GUID info, void *data, size_t dataLen); // This is for getting "extra" data, see list of GUIDs below. returns API_PLAYLISTS_SUCCESS or API_PLAYLISTS_FAILURE
  38. // manipulating playlists
  39. int MoveBefore(size_t index1, size_t index2); // moves playlist at position index1 to before index2. setting index2 to anything larger than GetCount() moves to end
  40. size_t AddPlaylist(const wchar_t *filename, const wchar_t *playlistName, GUID playlist_guid = INVALID_GUID); // adds a new playlist, returns new index. Generates a GUID if you don't pass third parameter.
  41. size_t AddPlaylist_NoCallback(const wchar_t *filename, const wchar_t *playlistName, GUID playlist_guid = INVALID_GUID);
  42. size_t AddCloudPlaylist(const wchar_t *filename, const wchar_t *playlistName, GUID playlist_guid = INVALID_GUID); // adds a new playlist, returns new index. Generates a GUID if you don't pass third parameter.
  43. int SetGUID(size_t index, GUID playlist_guid); // sets (overrides) a playlist ID. Don't use unless you have some very specific need
  44. int RenamePlaylist(size_t index, const wchar_t *name);
  45. int MovePlaylist(size_t index, const wchar_t *filename); // sets a new filename. NOTE: IT'S UP TO YOU TO PHYSICALLY MOVE/RENAME/CREATE THE NEW FILENAME.
  46. int SetInfo(size_t index, GUID info, void *data, size_t dataLen); // returns API_PLAYLISTS_SUCCESS or API_PLAYLISTS_FAILURE
  47. int RemovePlaylist(size_t index); // removes a particular playlist
  48. int ClearPlaylists(); // [*] clears the entire playlist. Use at your own risk :)
  49. size_t AddPlaylist_internal(const wchar_t *filename, const wchar_t *playlistName, GUID playlist_guid, size_t numItems, size_t length, uint64_t iTunesID, size_t cloud);
  50. // for SPlaylists to use
  51. const PlaylistInfo &GetPlaylistInfo(size_t i);
  52. private:
  53. bool loaded; // whether or not playlists.xml has been loaded
  54. bool triedLoaded; // whether or not we tried to load
  55. bool dirty; // whether a flush should save on Flush()
  56. size_t iterator; // a counter to help clients determine if the list data has changed
  57. typedef std::vector<PlaylistInfo> PlaylistsList;
  58. PlaylistsList playlists;
  59. Nullsoft::Utility::LockGuard playlistsGuard;
  60. RECVS_DISPATCH;
  61. };
  62. #endif