DeviceView.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #ifndef __DEVICEVIEW_H_
  2. #define __DEVICEVIEW_H_
  3. //#define _WIN32_WINNT 0x0400
  4. #include <windows.h>
  5. #include <windowsx.h>
  6. #include <stdio.h>
  7. #include <shlobj.h>
  8. #include <shellapi.h>
  9. #include "..\..\General\gen_ml/ml.h"
  10. #include "..\..\General\gen_ml/itemlist.h"
  11. #include "..\..\General\gen_ml/childwnd.h"
  12. #include "../winamp/wa_ipc.h"
  13. #include "../winamp/ipc_pe.h"
  14. #include "LinkedQueue.h"
  15. #include "pmp.h"
  16. #include "resource1.h"
  17. #include "config.h"
  18. #include "transfer_thread.h"
  19. #include "api__ml_pmp.h"
  20. #include "..\..\General\gen_ml/ml_ipc_0313.h"
  21. #include <bfc/platform/types.h>
  22. #include "../devices/ifc_device.h"
  23. #include "../devices/ifc_deviceactivity.h"
  24. #include "pmp.h"
  25. #include <bfc/multipatch.h>
  26. #include <vector>
  27. #define COMMITTIMERID 0x2345
  28. extern C_Config * gen_mlconfig;
  29. extern LinkedQueue cloudTransferQueue, cloudFinishedTransfers;
  30. extern int cloudTransferProgress;
  31. extern winampMediaLibraryPlugin plugin;
  32. wchar_t *guessTitles(const wchar_t *filename, int *tracknum,wchar_t **artist, wchar_t **album,wchar_t **title); // free result after using artist, etc
  33. wchar_t* GetDefaultSaveToFolder(wchar_t* path_to_store);
  34. #define AVERAGEBASIS 3
  35. class TransferContext
  36. {
  37. public:
  38. TransferContext() : dev(0), transfer_thread(NULL)
  39. {
  40. numTransfers=0;
  41. start=0;
  42. end=0;
  43. InitializeCriticalSection(&transfer_lock);
  44. killer = CreateEvent(NULL, TRUE, FALSE, 0);
  45. notifier = CreateEvent(NULL, FALSE, FALSE, 0);
  46. paused = 0;
  47. ZeroMemory(&times,sizeof(times));
  48. }
  49. ~TransferContext()
  50. {
  51. DeleteCriticalSection(&transfer_lock);
  52. CloseHandle(killer);
  53. CloseHandle(notifier);
  54. }
  55. void WaitForKill()
  56. {
  57. SetEvent(notifier);
  58. WaitForSingleObject(killer, INFINITE);
  59. }
  60. void DoOneTransfer(HANDLE handle);
  61. bool IsPaused();
  62. void Pause();
  63. void Resume();
  64. static bool IsAllPaused();
  65. static void PauseAll();
  66. static void ResumeAll();
  67. int numTransfers;
  68. int times[AVERAGEBASIS];
  69. time_t start, end;
  70. DeviceView *dev;
  71. volatile size_t paused;
  72. HANDLE killer, notifier;
  73. CRITICAL_SECTION transfer_lock;
  74. ThreadID *transfer_thread;
  75. static volatile size_t paused_all;
  76. };
  77. enum
  78. {
  79. PATCH_IFC_DEVICE,
  80. PATCH_IFC_DEVICEACTIVITY,
  81. };
  82. class DeviceView : public MultiPatch<PATCH_IFC_DEVICE, ifc_device>,
  83. public MultiPatch<PATCH_IFC_DEVICEACTIVITY, ifc_deviceactivity>
  84. {
  85. public://protected:
  86. HNAVITEM treeItem, videoTreeItem, queueTreeItem;
  87. int queueActiveIcon;
  88. int isCloudDevice;
  89. std::vector<HNAVITEM> playlistTreeItems;
  90. LinkedQueue finishedTransfers;
  91. HNAVITEM AddPlaylistNode(int id);
  92. int AddTrackToTransferQueue(DeviceView * device, itemRecordW * item, bool dupeCheck, bool forceDupe=false); // true on success
  93. int AddTrackToTransferQueue(CopyInst * inst);
  94. public:
  95. TransferContext transferContext;
  96. int videoView;
  97. int SyncConnectionDefault;
  98. prefsDlgRecW devPrefsPage;
  99. int currentTransferProgress; // percentage
  100. double transferRate;
  101. int threadKillswitch;
  102. LinkedQueue transferQueue;
  103. bool commitNeeded;
  104. C_Config * config;
  105. Device * dev;
  106. int metadata_fields;
  107. DeviceView(Device *dev);
  108. void SetVideoView(BOOL enabled);
  109. bool GetTransferFromMlSupported(int dataType);
  110. intptr_t TransferFromML(int type,void* data, int unsupportedReturn, int supportedReturn, int playlist=0);
  111. intptr_t TransferFromDrop(HDROP hDrop, int playlist=0);
  112. intptr_t MessageProc(int message_type, intptr_t param1, intptr_t param2, intptr_t param3);
  113. void DevicePropertiesChanges();
  114. int CreatePlaylist(wchar_t * name=NULL, bool silent=false);
  115. void RenamePlaylist(int id);
  116. bool DeletePlaylist(int playlistId, bool deleteFiles, bool verbal);
  117. int AddFileListToTransferQueue(char ** files, int num, int playlist=0);
  118. int AddFileListToTransferQueue(wchar_t ** files, int num, int playlist=0);
  119. int AddItemListToTransferQueue(itemRecordListW * items, int playlist=0);
  120. int AddItemListToTransferQueue(C_ItemList * items, int playlist=0);
  121. void TransferPlaylist(wchar_t * file, wchar_t * name=NULL); // name=NULL when its from the ML and we must find out ourself...
  122. int TransferTracksToPlaylist(C_ItemList *itemRecords, int plid);
  123. void TransferAddCloudPlaylist(wchar_t * file, wchar_t * name0);
  124. int DeleteTracks(C_ItemList * tracks, HWND centerWindow);
  125. void Sync(bool silent = false);
  126. void CloudSync(bool silent = false);
  127. void Autofill();
  128. void Eject();
  129. bool PlayTracks(C_ItemList * tracks, int startPlaybackAt, bool enqueue, bool msgIfImpossible, HWND parent=NULL); // returns false if failed/unsupported
  130. bool PlayPlaylist(int playlistId, bool enqueue, bool msgIfImpossible, HWND parent=NULL);
  131. void CopyTracksToHardDrive(songid_t * tracks, int numTracks);
  132. void CopyTracksToHardDrive(C_ItemList * tracks);
  133. void CopyPlaylistToLibrary(int plnum);
  134. void OnActivityStarted();
  135. void OnActivityChanged();
  136. void OnActivityFinished();
  137. void OnNameChanged(const wchar_t *new_name);
  138. //private:
  139. void RegisterViews(HNAVITEM parent);
  140. void Unregister();
  141. BOOL DisplayDeviceContextMenu(HNAVITEM item, HWND hostWindow, POINT pt);
  142. BOOL DisplayPlaylistContextMenu(int playlistId, HNAVITEM item, HWND hostWindow, POINT pt);
  143. // navigation
  144. BOOL Navigation_IsPlaylistItem(HNAVITEM item, int *playlistId);
  145. HWND Navigation_CreateViewCb(HNAVITEM item, HWND parentWindow);
  146. BOOL Navigation_ShowContextMenuCb(HNAVITEM item, HWND hostWindow, POINT pt);
  147. BOOL Navigation_ClickCb(HNAVITEM item, int actionType, HWND hostWindow);
  148. int Navigation_DropTargetCb(HNAVITEM item, unsigned int dataType, void *data);
  149. BOOL Navigation_TitleEditBeginCb(HNAVITEM item);
  150. BOOL Navigation_TitleEditEndCb(HNAVITEM item, const wchar_t *title);
  151. BOOL Navigation_KeyDownCb(HNAVITEM item, NMTVKEYDOWN *keyData, HWND hwnd);
  152. size_t GetPlaylistName(wchar_t *buffer, size_t bufferSize, int playlistId, const wchar_t *defaultName, BOOL quoteSpaces);
  153. public:
  154. /* ifc_device */
  155. int QueryInterface(GUID interface_guid, void **object);
  156. const char *GetName();
  157. HRESULT GetIcon(wchar_t *buffer, size_t bufferSize, int width, int height);
  158. HRESULT GetDisplayName(wchar_t *buffer, size_t bufferSize);
  159. const char *GetType();
  160. const char *GetDisplayType();
  161. const char *GetConnection();
  162. BOOL GetHidden();
  163. HRESULT GetTotalSpace(uint64_t *size);
  164. HRESULT GetUsedSpace(uint64_t *size);
  165. BOOL GetAttached();
  166. HRESULT Attach(HWND hostWindow);
  167. HRESULT Detach(HWND hostWindow);
  168. HRESULT EnumerateCommands(ifc_devicesupportedcommandenum **enumerator, DeviceCommandContext context);
  169. HRESULT SendCommand(const char *command, HWND hostWindow, ULONG_PTR param);
  170. HRESULT GetCommandFlags(const char *command, DeviceCommandFlags *flags);
  171. HRESULT GetActivity(ifc_deviceactivity **activity);
  172. HRESULT Advise(ifc_deviceevent *handler);
  173. HRESULT Unadvise(ifc_deviceevent *handler);
  174. HWND CreateView(HWND parentWindow);
  175. void SetNavigationItem(void *navigationItem);
  176. HRESULT GetDropSupported(unsigned int dataType);
  177. HRESULT Drop(void *data, unsigned int dataType);
  178. HRESULT SetDisplayName(const wchar_t *displayName, bool force);
  179. HRESULT GetModel(wchar_t *buffer, size_t bufferSize);
  180. HRESULT GetStatus(wchar_t *buffer, size_t bufferSize);
  181. void UpdateActivityState();
  182. void UpdateSpaceInfo(BOOL updateUsedSpace, BOOL notifyChanges);
  183. /* ifc_deviceactivity */
  184. BOOL GetActive();
  185. BOOL GetCancelable();
  186. HRESULT GetProgress(unsigned int *percentCompleted);
  187. HRESULT Activity_GetDisplayName(wchar_t *buffer, size_t bufferMax);
  188. HRESULT Activity_GetStatus(wchar_t *buffer, size_t bufferMax);
  189. HRESULT Cancel(HWND hostWindow);
  190. /* Dispatchable */
  191. size_t AddRef()
  192. {
  193. return InterlockedIncrement((LONG*)&ref_count);
  194. }
  195. size_t Release()
  196. {
  197. if (0 == ref_count)
  198. return ref_count;
  199. LONG r = InterlockedDecrement((LONG*)&ref_count);
  200. if (0 == r)
  201. delete(this);
  202. return r;
  203. }
  204. private:
  205. RECVS_MULTIPATCH;
  206. std::vector<ifc_deviceevent*> event_handlers;
  207. char name[128];
  208. size_t ref_count;
  209. ~DeviceView();
  210. const char *connection_type;
  211. const char *display_type;
  212. BOOL navigationItemCreated;
  213. BOOL activityRunning;
  214. unsigned int currentProgress;
  215. uint64_t usedSpace;
  216. uint64_t totalSpace;
  217. };
  218. #endif