editinfo.cpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. #include "main.h"
  2. #include "DeviceView.h"
  3. #include "api__ml_pmp.h"
  4. #include <api/service/waServiceFactory.h>
  5. #include <api/service/svcs/svc_imgload.h>
  6. #include <api/service/svcs/svc_imgwrite.h>
  7. #include <api/memmgr/api_memmgr.h>
  8. #include <tataki/bitmap/bitmap.h>
  9. #include <tataki/canvas/bltcanvas.h>
  10. extern C_ItemList devices;
  11. extern HWND hwndMediaView;
  12. static C_ItemList * editItems;
  13. static Device * editDevice;
  14. typedef struct {
  15. int w;
  16. int h;
  17. ARGB32 * data;
  18. } editinfo_image;
  19. static INT_PTR CALLBACK editInfo_commit_dialogProc(HWND hwnd, UINT uMsg, WPARAM wParam,LPARAM lParam) {
  20. static int i;
  21. switch(uMsg) {
  22. case WM_INITDIALOG:
  23. i=0;
  24. SetWindowText(hwnd,WASABI_API_LNGSTRINGW(IDS_SETTING_METADATA));
  25. SendDlgItemMessage(hwnd,IDC_PROGRESS,PBM_SETRANGE,0,MAKELPARAM(0, editItems->GetSize()));
  26. SetTimer(hwnd,1,5,NULL);
  27. if (FALSE != CenterWindow(hwnd, (HWND)lParam))
  28. SendMessage(hwnd, DM_REPOSITION, 0, 0L);
  29. break;
  30. case WM_TIMER:
  31. if(wParam == 1) {
  32. KillTimer(hwnd,1);
  33. HWND hwndDlg = GetParent(hwnd);
  34. editinfo_image * image = (editinfo_image *)GetWindowLongPtr(hwndDlg,GWLP_USERDATA);
  35. SendDlgItemMessage(hwnd,IDC_PROGRESS,PBM_SETPOS,i,0);
  36. if(i < editItems->GetSize()) {
  37. int metadata_edited=0;
  38. songid_t song=(songid_t)editItems->Get(i);
  39. time_t t; time(&t);
  40. editDevice->setTrackLastUpdated(song,t);
  41. if(IsDlgButtonChecked(hwndDlg,IDC_CHECK_ARTIST)) {
  42. wchar_t blah[512] = {0};
  43. GetDlgItemText(hwndDlg,IDC_EDIT_ARTIST,blah,sizeof(blah)/sizeof(wchar_t)-1);
  44. blah[sizeof(blah)/sizeof(wchar_t)-1]=0;
  45. editDevice->setTrackArtist(song,blah);
  46. metadata_edited++;
  47. }
  48. if(IsDlgButtonChecked(hwndDlg,IDC_CHECK_TITLE)) {
  49. wchar_t blah[512] = {0};
  50. GetDlgItemText(hwndDlg,IDC_EDIT_TITLE,blah,sizeof(blah)/sizeof(wchar_t)-1);
  51. blah[sizeof(blah)/sizeof(wchar_t)-1]=0;
  52. editDevice->setTrackTitle(song,blah);
  53. metadata_edited++;
  54. }
  55. if(IsDlgButtonChecked(hwndDlg,IDC_CHECK_ALBUM)) {
  56. wchar_t blah[512] = {0};
  57. GetDlgItemText(hwndDlg,IDC_EDIT_ALBUM,blah,sizeof(blah)/sizeof(wchar_t)-1);
  58. blah[sizeof(blah)/sizeof(wchar_t)-1]=0;
  59. editDevice->setTrackAlbum(song,blah);
  60. metadata_edited++;
  61. }
  62. if(IsDlgButtonChecked(hwndDlg,IDC_CHECK_GENRE)) {
  63. wchar_t blah[512] = {0};
  64. GetDlgItemText(hwndDlg,IDC_EDIT_GENRE,blah,sizeof(blah)/sizeof(wchar_t)-1);
  65. blah[sizeof(blah)/sizeof(wchar_t)-1]=0;
  66. editDevice->setTrackGenre(song,blah);
  67. metadata_edited++;
  68. }
  69. if(IsDlgButtonChecked(hwndDlg,IDC_CHECK_TRACK)) {
  70. wchar_t blah[64] = {0};
  71. GetDlgItemText(hwndDlg,IDC_EDIT_TRACK,blah,sizeof(blah)/sizeof(wchar_t)-1);
  72. blah[sizeof(blah)/sizeof(wchar_t)-1]=0;
  73. int n=_wtoi(blah);
  74. if (n <= 0) n=-1;
  75. editDevice->setTrackTrackNum(song,n);
  76. metadata_edited++;
  77. }
  78. if(IsDlgButtonChecked(hwndDlg,IDC_CHECK_DISC)) {
  79. wchar_t blah[64] = {0};
  80. GetDlgItemText(hwndDlg,IDC_EDIT_DISC,blah,sizeof(blah)/sizeof(wchar_t)-1);
  81. blah[sizeof(blah)/sizeof(wchar_t)-1]=0;
  82. int n=_wtoi(blah);
  83. if (n <= 0) n=-1;
  84. editDevice->setTrackDiscNum(song,n);
  85. metadata_edited++;
  86. }
  87. if(IsDlgButtonChecked(hwndDlg,IDC_CHECK_YEAR)) {
  88. wchar_t blah[64] = {0};
  89. GetDlgItemText(hwndDlg,IDC_EDIT_YEAR,blah,sizeof(blah)/sizeof(wchar_t)-1);
  90. blah[sizeof(blah)/sizeof(wchar_t)-1]=0;
  91. int n=_wtoi(blah);
  92. if (n <= 0) n=-1;
  93. editDevice->setTrackYear(song,n);
  94. metadata_edited++;
  95. }
  96. if(IsDlgButtonChecked(hwndDlg,IDC_CHECK_ALBUMARTIST)) {
  97. wchar_t blah[512] = {0};
  98. GetDlgItemText(hwndDlg,IDC_EDIT_ALBUMARTIST,blah,sizeof(blah)/sizeof(wchar_t)-1);
  99. blah[sizeof(blah)/sizeof(wchar_t)-1]=0;
  100. editDevice->setTrackAlbumArtist(song,blah);
  101. metadata_edited++;
  102. }
  103. if(IsDlgButtonChecked(hwndDlg,IDC_CHECK_PUBLISHER)) {
  104. wchar_t blah[512] = {0};
  105. GetDlgItemText(hwndDlg,IDC_EDIT_PUBLISHER,blah,sizeof(blah)/sizeof(wchar_t)-1);
  106. blah[sizeof(blah)/sizeof(wchar_t)-1]=0;
  107. editDevice->setTrackPublisher(song,blah);
  108. metadata_edited++;
  109. }
  110. if(IsDlgButtonChecked(hwndDlg,IDC_CHECK_COMPOSER)) {
  111. wchar_t blah[512] = {0};
  112. GetDlgItemText(hwndDlg,IDC_EDIT_COMPOSER,blah,sizeof(blah)/sizeof(wchar_t)-1);
  113. blah[sizeof(blah)/sizeof(wchar_t)-1]=0;
  114. editDevice->setTrackComposer(song,blah);
  115. metadata_edited++;
  116. }
  117. if(IsDlgButtonChecked(hwndDlg,IDC_CHECK_ALBUMART)) {
  118. if(!image) editDevice->setArt(song,NULL,0,0);
  119. else editDevice->setArt(song,image->data,image->w,image->h);
  120. }
  121. if (metadata_edited)
  122. {
  123. editDevice->extraActions(DEVICE_DONE_SETTING, (intptr_t)song,0,0);
  124. }
  125. SetTimer(hwnd,1,5,NULL);
  126. }
  127. else {
  128. editDevice->commitChanges();
  129. EndDialog(hwnd,0);
  130. }
  131. i++;
  132. }
  133. break;
  134. case WM_COMMAND:
  135. if(LOWORD(wParam) == IDC_ABORT) {
  136. editDevice->commitChanges();
  137. EndDialog(hwnd,-1);
  138. }
  139. break;
  140. }
  141. return 0;
  142. }
  143. static ARGB32 * loadImg(const void * data, int len, int *w, int *h) {
  144. FOURCC imgload = svc_imageLoader::getServiceType();
  145. int n = plugin.service->service_getNumServices(imgload);
  146. for(int i=0; i<n; i++) {
  147. waServiceFactory *sf = plugin.service->service_enumService(imgload,i);
  148. if(sf) {
  149. svc_imageLoader * l = (svc_imageLoader*)sf->getInterface();
  150. if(l) {
  151. if(l->testData(data,len)) {
  152. ARGB32* ret = l->loadImage(data,len,w,h);
  153. sf->releaseInterface(l);
  154. return ret;
  155. }
  156. sf->releaseInterface(l);
  157. }
  158. }
  159. }
  160. return NULL;
  161. }
  162. static void * loadFile(const wchar_t * file, int &len) {
  163. len=0;
  164. FILE * f = _wfopen(file,L"rb");
  165. if(!f) return 0;
  166. fseek(f,0,2);
  167. len = ftell(f);
  168. if(!len) {fclose(f); return 0;}
  169. fseek(f,0,0);
  170. void * data = calloc(len, sizeof(void*));
  171. fread(data,len,1,f);
  172. fclose(f);
  173. return data;
  174. }
  175. static ARGB32 * loadImgFromFile(const wchar_t * file, int *w, int *h) {
  176. int len;
  177. void * d = loadFile(file,len);
  178. if(!d) return 0;
  179. ARGB32 * im = loadImg(d,len,w,h);
  180. free(d);
  181. return im;
  182. }
  183. static void * writeImg(const ARGB32 *data, int w, int h, int *length, const wchar_t *ext) {
  184. if(!ext || !*ext) return NULL;
  185. if(*ext == L'.') ext++;
  186. FOURCC imgwrite = svc_imageWriter::getServiceType();
  187. int n = plugin.service->service_getNumServices(imgwrite);
  188. for(int i=0; i<n; i++) {
  189. waServiceFactory *sf = plugin.service->service_enumService(imgwrite,i);
  190. if(sf) {
  191. svc_imageWriter * l = (svc_imageWriter*)sf->getInterface();
  192. if(l) {
  193. if(wcsstr(l->getExtensions(),ext)) {
  194. void* ret = l->convert(data,32,w,h,length);
  195. sf->releaseInterface(l);
  196. return ret;
  197. }
  198. sf->releaseInterface(l);
  199. }
  200. }
  201. }
  202. return NULL;
  203. }
  204. static void writeFile(const wchar_t *file, void * data, int length) {
  205. FILE *f = _wfopen(file,L"wb");
  206. if(!f) return;
  207. fwrite(data,length,1,f);
  208. fclose(f);
  209. }
  210. static void writeImageToFile(ARGB32 * img, int w, int h, const wchar_t *file) {
  211. int length=0;
  212. void * data = writeImg(img,w,h,&length,wcsrchr(file,L'.'));
  213. if(data) {
  214. writeFile(file,data,length);
  215. WASABI_API_MEMMGR->sysFree(data);
  216. }
  217. }
  218. static void enableArt(HWND hwndDlg, bool combo, BOOL enable) {
  219. if(combo) EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_ALBUMART),enable);
  220. EnableWindow(GetDlgItem(hwndDlg,IDC_ARTINFO),enable);
  221. EnableWindow(GetDlgItem(hwndDlg,IDC_PICTUREHOLDER),enable);
  222. EnableWindow(GetDlgItem(hwndDlg,IDC_ART_CHANGE),enable);
  223. EnableWindow(GetDlgItem(hwndDlg,IDC_ART_CLEAR),enable);
  224. }
  225. static int checkEditInfoClick(HWND hwndDlg, POINT p, int item, int check, bool art=false) {
  226. if(!IsWindowEnabled(GetDlgItem(hwndDlg,check))) return 0;
  227. RECT r;
  228. GetWindowRect(GetDlgItem(hwndDlg, item), &r);
  229. ScreenToClient(hwndDlg, (LPPOINT)&r);
  230. ScreenToClient(hwndDlg, (LPPOINT)&r.right);
  231. if (PtInRect(&r, p) && !IsDlgButtonChecked(hwndDlg, check)) {
  232. CheckDlgButton(hwndDlg, check, TRUE);
  233. if(art) enableArt(hwndDlg,false,TRUE);
  234. else EnableWindow(GetDlgItem(hwndDlg, item), TRUE);
  235. EnableWindow(GetDlgItem(hwndDlg, IDOK), TRUE);
  236. PostMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwndDlg, item), TRUE);
  237. return 1;
  238. }
  239. return 0;
  240. }
  241. static HBITMAP getBitmap(const editinfo_image * image, HWND parent) {
  242. BITMAPINFO info={0};
  243. info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  244. info.bmiHeader.biWidth = image->w;
  245. info.bmiHeader.biHeight = -image->h;
  246. info.bmiHeader.biPlanes = 1;
  247. info.bmiHeader.biBitCount = 32;
  248. info.bmiHeader.biCompression = BI_RGB;
  249. HDC dc = GetDC(parent);
  250. HBITMAP bm = CreateCompatibleBitmap(dc,image->w,image->h);
  251. SetDIBits(dc,bm,0,image->h,image->data,&info,DIB_RGB_COLORS);
  252. ReleaseDC(parent,dc);
  253. return bm;
  254. }
  255. static HBITMAP getBitmap(pmpart_t art, Device * dev, HWND parent) {
  256. int w,h;
  257. editDevice->getArtNaturalSize(art,&w,&h);
  258. if(w == 0 || h == 0) return NULL;
  259. ARGB32 * bits = (ARGB32 *)calloc(w * h, sizeof(ARGB32));
  260. if(!bits) return NULL;
  261. editDevice->getArtData(art,bits);
  262. editinfo_image im={w,h,bits};
  263. HBITMAP bm = getBitmap(&im,parent);
  264. free(bits);
  265. return bm;
  266. }
  267. static void setBitmap(const editinfo_image * image, HWND hwndDlg, bool init=false) {
  268. if(!init) {
  269. CheckDlgButton(hwndDlg,IDC_CHECK_ALBUMART,BST_CHECKED);
  270. enableArt(hwndDlg,false,TRUE);
  271. SendMessage(hwndDlg,WM_COMMAND,MAKEWPARAM(IDC_ART_CLEAR,0),0);
  272. }
  273. HQSkinBitmap temp(image->data, image->w, image->h); // wrap into a SkinBitmap (no copying involved)
  274. BltCanvas newImage(90,90);
  275. temp.stretch(&newImage, 0, 0, 90, 90);
  276. editinfo_image i = {90,90,(ARGB32*)newImage.getBits()};
  277. HBITMAP bm = getBitmap(&i,hwndDlg);
  278. HBITMAP bmold = (HBITMAP)SendDlgItemMessage(hwndDlg,IDC_PICTUREHOLDER,STM_SETIMAGE,IMAGE_BITMAP,(LPARAM)bm);
  279. if(bmold) DeleteObject(bmold);
  280. SetWindowLongPtr(hwndDlg,GWLP_USERDATA,(LONG_PTR)image);
  281. wchar_t buf[100] = {0};
  282. wsprintf(buf,L"%dx%d",image->w,image->h);
  283. SetDlgItemText(hwndDlg,IDC_ARTINFO,buf);
  284. }
  285. static void GetSize(HBITMAP bm,int &w, int &h,HWND hwndDlg) {
  286. HDC dc = GetDC(hwndDlg);
  287. BITMAPINFO info={0};
  288. info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  289. GetDIBits(dc,bm,0,0,NULL,&info,DIB_RGB_COLORS);
  290. w = abs(info.bmiHeader.biWidth);
  291. h = abs(info.bmiHeader.biHeight);
  292. ReleaseDC(hwndDlg,dc);
  293. }
  294. static void setBitmap(HBITMAP bm, HWND hwndDlg) {
  295. editinfo_image* image = (editinfo_image*)calloc(1, sizeof(editinfo_image));
  296. GetSize(bm,image->w,image->h,hwndDlg);
  297. image->data = (ARGB32*)WASABI_API_MEMMGR->sysMalloc(sizeof(ARGB32)*image->w*image->h);
  298. BITMAPINFO info={0};
  299. info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  300. info.bmiHeader.biWidth = image->w;
  301. info.bmiHeader.biHeight = -image->h;
  302. info.bmiHeader.biPlanes = 1;
  303. info.bmiHeader.biBitCount = 32;
  304. info.bmiHeader.biCompression = BI_RGB;
  305. HDC dc = GetDC(hwndDlg);
  306. GetDIBits(dc,bm,0,image->h,image->data,&info,DIB_RGB_COLORS);
  307. ReleaseDC(hwndDlg,dc);
  308. setBitmap(image,hwndDlg);
  309. }
  310. static INT_PTR CALLBACK editInfo_dialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam) {
  311. switch(uMsg) {
  312. case WM_INITDIALOG:
  313. {
  314. wchar_t last_artist[2048]=L"", last_title[2048]=L"", last_album[2048]=L"", last_genre[2048]=L"", last_albumartist[2048]=L"", last_publisher[2048]=L"", last_composer[2048]=L"";
  315. pmpart_t last_albumart=NULL;
  316. int last_year=-1, last_track=-1, last_disc=-1;
  317. bool disable_artist=0, disable_title=0, disable_album=0, disable_genre=0, disable_year=0, disable_track=0, disable_disc=0, disable_albumartist=0, disable_publisher=0, disable_composer=0, disable_albumart=0;
  318. int fieldBits = (int)editDevice->extraActions(DEVICE_SUPPORTED_METADATA,0,0,0);
  319. if(!fieldBits) fieldBits = -1;
  320. disable_artist = (fieldBits & SUPPORTS_ARTIST)==0;
  321. disable_title = (fieldBits & SUPPORTS_TITLE)==0;
  322. disable_album = (fieldBits & SUPPORTS_ALBUM)==0;
  323. disable_genre = (fieldBits & SUPPORTS_GENRE)==0;
  324. disable_year = (fieldBits & SUPPORTS_YEAR)==0;
  325. disable_track = (fieldBits & SUPPORTS_TRACKNUM)==0;
  326. disable_disc = (fieldBits & SUPPORTS_DISCNUM)==0;
  327. disable_albumartist = (fieldBits & SUPPORTS_ALBUMARTIST)==0;
  328. disable_publisher = (fieldBits & SUPPORTS_PUBLISHER)==0;
  329. disable_composer = (fieldBits & SUPPORTS_COMPOSER)==0;
  330. disable_albumart = (fieldBits & SUPPORTS_ALBUMART)==0;
  331. EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);
  332. EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_ARTIST),!disable_artist);
  333. EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_TITLE),!disable_title);
  334. EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_ALBUM),!disable_album);
  335. EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_GENRE),!disable_genre);
  336. EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_YEAR),!disable_year);
  337. EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_TRACK),!disable_track);
  338. EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_DISC),!disable_disc);
  339. EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_ALBUMARTIST),!disable_albumartist);
  340. EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_PUBLISHER),!disable_publisher);
  341. EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_COMPOSER),!disable_composer);
  342. EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_ALBUMART),!disable_albumart);
  343. //enableArt(hwndDlg,true,!disable_albumart);
  344. int l=editItems->GetSize();
  345. for(int i=0;i<l;i++) {
  346. wchar_t buf[2048]=L"";
  347. songid_t song=(songid_t)editItems->Get(i);
  348. if(!disable_artist)
  349. {
  350. buf[0]=0;
  351. editDevice->getTrackArtist(song,buf,sizeof(buf)/sizeof(wchar_t));
  352. if(!buf[0]);
  353. else if(!last_artist[0]) lstrcpyn(last_artist,buf,2048);
  354. else if(lstrcmp(buf,last_artist)) disable_artist=true;
  355. }
  356. if(!disable_albumartist)
  357. {
  358. buf[0]=0;
  359. editDevice->getTrackAlbumArtist(song,buf,sizeof(buf)/sizeof(wchar_t));
  360. if(!buf[0]);
  361. else if(!last_albumartist[0]) lstrcpyn(last_albumartist,buf,2048);
  362. else if(lstrcmp(buf,last_albumartist)) disable_albumartist=true;
  363. }
  364. if(!disable_publisher)
  365. {
  366. buf[0]=0;
  367. editDevice->getTrackPublisher(song,buf,sizeof(buf)/sizeof(wchar_t));
  368. if(!buf[0]);
  369. else if(!last_publisher[0]) lstrcpyn(last_publisher,buf,2048);
  370. else if(lstrcmp(buf,last_publisher)) disable_publisher=true;
  371. }
  372. if(!disable_composer)
  373. {
  374. buf[0]=0;
  375. editDevice->getTrackComposer(song,buf,sizeof(buf)/sizeof(wchar_t));
  376. if(!buf[0]);
  377. else if(!last_composer[0]) lstrcpyn(last_composer,buf,2048);
  378. else if(lstrcmp(buf,last_composer)) disable_composer=true;
  379. }
  380. if(!disable_title)
  381. {
  382. buf[0]=0;
  383. editDevice->getTrackTitle(song,buf,sizeof(buf)/sizeof(wchar_t));
  384. if(!buf[0]);
  385. else if(!last_title[0])
  386. lstrcpyn(last_title,buf,2048);
  387. else if(lstrcmp(buf,last_title)) disable_title=true;
  388. }
  389. if(!disable_album)
  390. {
  391. buf[0]=0;
  392. editDevice->getTrackAlbum(song,buf,sizeof(buf)/sizeof(wchar_t));
  393. if(!buf[0]);
  394. else if(!last_album[0]) lstrcpyn(last_album,buf,2048);
  395. else if(lstrcmp(buf,last_album)) disable_album=true;
  396. }
  397. if(!disable_genre)
  398. {
  399. buf[0]=0;
  400. editDevice->getTrackGenre(song,buf,sizeof(buf)/sizeof(wchar_t));
  401. if(!buf[0]);
  402. else if(!last_genre[0]) lstrcpyn(last_genre,buf,2048);
  403. else if(lstrcmp(buf,last_genre)) disable_genre=true;
  404. }
  405. if(!disable_year)
  406. {
  407. int val=editDevice->getTrackYear(song);
  408. if(val <= 0);
  409. else if(last_year==-1) last_year=val;
  410. else if(last_year!=val) disable_year=true;
  411. }
  412. if(!disable_track)
  413. {
  414. int val=editDevice->getTrackTrackNum(song);
  415. if(val <= 0);
  416. else if(last_track==-1) last_track=val;
  417. else if(last_track!=val) disable_track=true;
  418. }
  419. if(!disable_disc)
  420. {
  421. int val=editDevice->getTrackDiscNum(song);
  422. if(val <= 0);
  423. else if(last_disc==-1) last_disc=val;
  424. else if(last_disc!=val) disable_disc=true;
  425. }
  426. if(!disable_albumart)
  427. {
  428. pmpart_t a = editDevice->getArt(song);
  429. if(!a);
  430. else if(!last_albumart) { editDevice->releaseArt(last_albumart); last_albumart = a; }
  431. else if(!editDevice->artIsEqual(a,last_albumart)) { disable_albumart=true; editDevice->releaseArt(a); editDevice->releaseArt(last_albumart); last_albumart=0; }
  432. }
  433. }
  434. if(!disable_artist && last_artist) SetDlgItemText(hwndDlg,IDC_EDIT_ARTIST,last_artist);
  435. if(!disable_albumartist && last_albumartist) SetDlgItemText(hwndDlg,IDC_EDIT_ALBUMARTIST,last_albumartist);
  436. if(!disable_publisher && last_publisher) SetDlgItemText(hwndDlg,IDC_EDIT_PUBLISHER,last_publisher);
  437. if(!disable_composer && last_composer) SetDlgItemText(hwndDlg,IDC_EDIT_COMPOSER,last_composer);
  438. if(!disable_title && last_title) SetDlgItemText(hwndDlg,IDC_EDIT_TITLE,last_title);
  439. if(!disable_album && last_album) SetDlgItemText(hwndDlg,IDC_EDIT_ALBUM,last_album);
  440. if(!disable_genre && last_genre) SetDlgItemText(hwndDlg,IDC_EDIT_GENRE,last_genre);
  441. if(!disable_year && last_year>0) {
  442. wchar_t tmp[64] = {0};
  443. wsprintf(tmp,L"%d",last_year);
  444. SetDlgItemText(hwndDlg,IDC_EDIT_YEAR,tmp);
  445. }
  446. if(!disable_track && last_track>0) {
  447. wchar_t tmp[64] = {0};
  448. wsprintf(tmp,L"%d",last_track);
  449. SetDlgItemText(hwndDlg,IDC_EDIT_TRACK,tmp);
  450. }
  451. if(!disable_disc && last_disc>0) {
  452. wchar_t tmp[64] = {0};
  453. wsprintf(tmp,L"%d",last_disc);
  454. SetDlgItemText(hwndDlg,IDC_EDIT_DISC,tmp);
  455. }
  456. if(!disable_albumart && last_albumart) {
  457. // save copy of image
  458. editinfo_image* image = (editinfo_image*)calloc(1, sizeof(editinfo_image));
  459. editDevice->getArtNaturalSize(last_albumart,&image->w,&image->h);
  460. image->data = (ARGB32*)WASABI_API_MEMMGR->sysMalloc(sizeof(ARGB32)*image->w*image->h);
  461. editDevice->getArtData(last_albumart,image->data);
  462. setBitmap(image,hwndDlg,true);
  463. editDevice->releaseArt(last_albumart);
  464. }
  465. else SetWindowLongPtr(hwndDlg,GWLP_USERDATA,0);
  466. if (FALSE != CenterWindow(hwndDlg, (HWND)lParam))
  467. SendMessage(hwndDlg, DM_REPOSITION, 0, 0L);
  468. }
  469. break;
  470. case WM_LBUTTONDOWN:
  471. {
  472. POINTS p = MAKEPOINTS(lParam);
  473. POINT p2 = {p.x, p.y};
  474. if (checkEditInfoClick(hwndDlg, p2, IDC_EDIT_ARTIST, IDC_CHECK_ARTIST)) break;
  475. if (checkEditInfoClick(hwndDlg, p2, IDC_EDIT_TITLE, IDC_CHECK_TITLE)) break;
  476. if (checkEditInfoClick(hwndDlg, p2, IDC_EDIT_ALBUM, IDC_CHECK_ALBUM)) break;
  477. if (checkEditInfoClick(hwndDlg, p2, IDC_EDIT_TRACK, IDC_CHECK_TRACK)) break;
  478. if (checkEditInfoClick(hwndDlg, p2, IDC_EDIT_DISC, IDC_CHECK_DISC)) break;
  479. if (checkEditInfoClick(hwndDlg, p2, IDC_EDIT_GENRE, IDC_CHECK_GENRE)) break;
  480. if (checkEditInfoClick(hwndDlg, p2, IDC_EDIT_YEAR, IDC_CHECK_YEAR)) break;
  481. if (checkEditInfoClick(hwndDlg, p2, IDC_EDIT_ALBUMARTIST, IDC_CHECK_ALBUMARTIST)) break;
  482. if (checkEditInfoClick(hwndDlg, p2, IDC_EDIT_COMPOSER, IDC_CHECK_COMPOSER)) break;
  483. if (checkEditInfoClick(hwndDlg, p2, IDC_EDIT_PUBLISHER, IDC_CHECK_PUBLISHER)) break;
  484. if (checkEditInfoClick(hwndDlg, p2, IDC_PICTUREHOLDER, IDC_CHECK_ALBUMART,true)) break;
  485. if (checkEditInfoClick(hwndDlg, p2, IDC_ART_CLEAR, IDC_CHECK_ALBUMART,true)) break;
  486. if (checkEditInfoClick(hwndDlg, p2, IDC_ART_CHANGE, IDC_CHECK_ALBUMART,true)) break;
  487. if (checkEditInfoClick(hwndDlg, p2, IDC_ARTINFO, IDC_CHECK_ALBUMART,true)) break;
  488. }
  489. break;
  490. case WM_RBUTTONDOWN:
  491. {
  492. POINTS pts = MAKEPOINTS(lParam);
  493. POINT p = {pts.x, pts.y};
  494. RECT r;
  495. GetWindowRect(GetDlgItem(hwndDlg, IDC_PICTUREHOLDER), &r);
  496. ScreenToClient(hwndDlg, (LPPOINT)&r);
  497. ScreenToClient(hwndDlg, (LPPOINT)&r.right);
  498. if(PtInRect(&r, p)) { // right click on picture holder
  499. extern HMENU m_context_menus;
  500. HMENU menu = GetSubMenu(m_context_menus, 11);
  501. POINT p;
  502. GetCursorPos(&p);
  503. wchar_t artist[256]=L"";
  504. wchar_t album[256]=L"";
  505. GetDlgItemText(hwndDlg,IDC_EDIT_ALBUMARTIST,artist,256);
  506. if(!artist[0])
  507. GetDlgItemText(hwndDlg,IDC_EDIT_ARTIST,artist,256);
  508. GetDlgItemText(hwndDlg,IDC_EDIT_ALBUM,album,256);
  509. bool canpaste=(!!IsClipboardFormatAvailable(CF_DIB));
  510. bool hasimage= (GetWindowLongPtr(hwndDlg,GWLP_USERDATA) != 0);
  511. EnableMenuItem(menu, ID_ARTEDITMENU_PASTE, MF_BYCOMMAND | (canpaste?MF_ENABLED:MF_GRAYED));
  512. EnableMenuItem(menu, ID_ARTEDITMENU_COPY, MF_BYCOMMAND | (hasimage?MF_ENABLED:MF_GRAYED));
  513. EnableMenuItem(menu, ID_ARTEDITMENU_DELETE, MF_BYCOMMAND | (hasimage?MF_ENABLED:MF_GRAYED));
  514. EnableMenuItem(menu, ID_ARTEDITMENU_SAVEAS, MF_BYCOMMAND | (hasimage?MF_ENABLED:MF_GRAYED));
  515. // disabled 30 May 2012 as per email from Tejas w.r.t. to Rovi deal ending
  516. #if 0
  517. bool candownload = (album[0] || artist[0]);
  518. EnableMenuItem(menu, ID_ARTEDITMENU_DOWNLOAD, MF_BYCOMMAND | (candownload?MF_ENABLED:MF_GRAYED));
  519. #else
  520. DeleteMenu(menu, ID_ARTEDITMENU_DOWNLOAD, MF_BYCOMMAND);
  521. #endif
  522. int r = TrackPopupMenu(menu, TPM_RETURNCMD | TPM_RIGHTBUTTON | TPM_LEFTBUTTON, p.x, p.y, 0, hwndDlg, NULL);
  523. switch(r) {
  524. // disabled 30 May 2012 as per email from Tejas w.r.t. to Rovi deal ending
  525. #if 0
  526. case ID_ARTEDITMENU_DOWNLOAD:
  527. {
  528. artFetchData d = {sizeof(d),hwndDlg,artist,album,0};
  529. int r = (int)SendMessage(plugin.hwndWinampParent,WM_WA_IPC,(LPARAM)&d,IPC_FETCH_ALBUMART);
  530. if(r == 0 && d.imgData && d.imgDataLen) // success, save art in correct location
  531. {
  532. int w=0,h=0;
  533. ARGB32* bytes = loadImg(d.imgData,d.imgDataLen,&w,&h);
  534. if(bytes)
  535. {
  536. editinfo_image *image = (editinfo_image *)calloc(1, sizeof(editinfo_image));
  537. image->data = bytes;
  538. image->w = w;
  539. image->h = h;
  540. setBitmap(image,hwndDlg);
  541. }
  542. WASABI_API_MEMMGR->sysFree(d.imgData);
  543. }
  544. }
  545. break;
  546. #endif
  547. case ID_ARTEDITMENU_COPY:
  548. {
  549. if (!OpenClipboard(hwndDlg)) break;
  550. EmptyClipboard();
  551. HBITMAP bm = getBitmap((editinfo_image*)GetWindowLongPtr(hwndDlg,GWLP_USERDATA),hwndDlg);
  552. SetClipboardData(CF_BITMAP,bm);
  553. CloseClipboard();
  554. }
  555. break;
  556. case ID_ARTEDITMENU_PASTE:
  557. {
  558. if (!OpenClipboard(hwndDlg)) break;
  559. HBITMAP bm = (HBITMAP)GetClipboardData(CF_BITMAP);
  560. if(bm) setBitmap(bm,hwndDlg);
  561. CloseClipboard();
  562. }
  563. break;
  564. case ID_ARTEDITMENU_DELETE:
  565. CheckDlgButton(hwndDlg,IDC_CHECK_ALBUMART,BST_CHECKED);
  566. enableArt(hwndDlg,false,TRUE);
  567. SendMessage(hwndDlg,WM_COMMAND,MAKEWPARAM(IDC_ART_CLEAR,0),0);
  568. break;
  569. case ID_ARTEDITMENU_SAVEAS:
  570. {
  571. static int tests_run = 0;
  572. wchar_t file[1024] = {0};
  573. static wchar_t filter[1024] = {0}, *sff = filter;
  574. OPENFILENAME fn = {0};
  575. fn.lStructSize = sizeof(fn);
  576. fn.hwndOwner = hwndDlg;
  577. fn.lpstrFile = file;
  578. fn.nMaxFile = 1020;
  579. if(!tests_run)
  580. {
  581. tests_run = 1;
  582. FOURCC imgload = svc_imageLoader::getServiceType();
  583. int n = plugin.service->service_getNumServices(imgload);
  584. size_t size = 1024;
  585. for (int i = 0, j = 0; i<n; i++)
  586. {
  587. waServiceFactory *sf = plugin.service->service_enumService(imgload,i);
  588. if (sf)
  589. {
  590. svc_imageLoader * l = (svc_imageLoader*)sf->getInterface();
  591. if (l)
  592. {
  593. wchar_t *tests[] = {L"*.jpg",L"*.png",L"*.gif",L"*.bmp"};
  594. for(int i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
  595. {
  596. if (l->isMine(tests[i]))
  597. {
  598. j++;
  599. int len = 0, tests_str[] = {IDS_JPEG_FILE,IDS_PNG_FILE,IDS_GIF_FILE,IDS_BMP_FILE};
  600. WASABI_API_LNGSTRINGW_BUF(tests_str[i],sff,size);
  601. size-=(len = lstrlenW(sff)+1);
  602. sff+=len;
  603. lstrcpynW(sff,tests[i],size);
  604. size-=(len = lstrlenW(sff)+1);
  605. sff+=len;
  606. }
  607. }
  608. sf->releaseInterface(l);
  609. }
  610. }
  611. }
  612. }
  613. fn.lpstrFilter = filter;
  614. fn.Flags = OFN_OVERWRITEPROMPT;
  615. GetSaveFileName(&fn);
  616. int l = wcslen(file);
  617. if(l>4 && file[l-4]==L'.'); // we have an extention
  618. else switch(fn.nFilterIndex) {
  619. case 1: StringCchCat(file, ARRAYSIZE(file), L".jpg"); break;
  620. case 2: StringCchCat(file, ARRAYSIZE(file), L".png"); break;
  621. case 3: StringCchCat(file, ARRAYSIZE(file), L".gif"); break;
  622. case 4: StringCchCat(file, ARRAYSIZE(file), L".bmp"); break;
  623. }
  624. editinfo_image *image = (editinfo_image *)GetWindowLongPtr(hwndDlg,GWLP_USERDATA);
  625. writeImageToFile(image->data,image->w,image->h,file);
  626. }
  627. break;
  628. }
  629. }
  630. }
  631. break;
  632. case WM_COMMAND:
  633. #define HANDLE_CONTROL(item, check) { int enabled = IsDlgButtonChecked(hwndDlg, check); EnableWindow(GetDlgItem(hwndDlg, item), enabled); EnableWindow(GetDlgItem(hwndDlg, IDOK), enabled); }
  634. switch(LOWORD(wParam)) {
  635. case IDC_CHECK_ARTIST: HANDLE_CONTROL(IDC_EDIT_ARTIST, IDC_CHECK_ARTIST); break;
  636. case IDC_CHECK_TITLE: HANDLE_CONTROL(IDC_EDIT_TITLE, IDC_CHECK_TITLE); break;
  637. case IDC_CHECK_ALBUM: HANDLE_CONTROL(IDC_EDIT_ALBUM, IDC_CHECK_ALBUM); break;
  638. case IDC_CHECK_ALBUMARTIST: HANDLE_CONTROL(IDC_EDIT_ALBUMARTIST, IDC_CHECK_ALBUMARTIST); break;
  639. case IDC_CHECK_COMPOSER: HANDLE_CONTROL(IDC_EDIT_COMPOSER, IDC_CHECK_COMPOSER); break;
  640. case IDC_CHECK_PUBLISHER: HANDLE_CONTROL(IDC_EDIT_PUBLISHER, IDC_CHECK_PUBLISHER); break;
  641. case IDC_CHECK_TRACK: HANDLE_CONTROL(IDC_EDIT_TRACK, IDC_CHECK_TRACK); break;
  642. case IDC_CHECK_DISC: HANDLE_CONTROL(IDC_EDIT_DISC, IDC_CHECK_DISC); break;
  643. case IDC_CHECK_GENRE: HANDLE_CONTROL(IDC_EDIT_GENRE, IDC_CHECK_GENRE); break;
  644. case IDC_CHECK_YEAR: HANDLE_CONTROL(IDC_EDIT_YEAR, IDC_CHECK_YEAR); break;
  645. //case IDC_CHECK_COMMENT: HANDLE_CONTROL(IDC_EDIT_COMMENT, IDC_CHECK_COMMENT); break;
  646. //case IDC_CHECK_CATEGORY: HANDLE_CONTROL(IDC_EDIT_CATEGORY, IDC_CHECK_CATEGORY); break;
  647. //case IDC_CHECK_DIRECTOR: HANDLE_CONTROL(IDC_EDIT_DIRECTOR, IDC_CHECK_DIRECTOR); break;
  648. //case IDC_CHECK_PRODUCER: HANDLE_CONTROL(IDC_EDIT_PRODUCER, IDC_CHECK_PRODUCER); break;
  649. //case IDC_CHECK_BPM: HANDLE_CONTROL(IDC_EDIT_BPM, IDC_CHECK_BPM); break;
  650. //case IDC_CHECK_RATING: HANDLE_CONTROL(IDC_COMBO_RATING, IDC_CHECK_RATING); break;
  651. case IDC_CHECK_ALBUMART:
  652. {
  653. int enabled = IsDlgButtonChecked(hwndDlg, IDC_CHECK_ALBUMART);
  654. enableArt(hwndDlg, false, enabled);
  655. EnableWindow(GetDlgItem(hwndDlg, IDOK), enabled);
  656. break;
  657. }
  658. case IDC_ART_CLEAR:
  659. {
  660. editinfo_image* image = (editinfo_image*)GetWindowLongPtr(hwndDlg,GWLP_USERDATA);
  661. if(image) {
  662. if(image->data) WASABI_API_MEMMGR->sysFree(image->data);
  663. free(image);
  664. }
  665. SetDlgItemText(hwndDlg,IDC_ARTINFO,WASABI_API_LNGSTRINGW(IDS_NO_IMAGE));
  666. SetWindowLongPtr(hwndDlg,GWLP_USERDATA,0);
  667. HBITMAP old = (HBITMAP)SendDlgItemMessage(hwndDlg,IDC_PICTUREHOLDER,STM_SETIMAGE,IMAGE_BITMAP,(LPARAM)0);
  668. DeleteObject(old);
  669. }
  670. break;
  671. case IDC_ART_CHANGE:
  672. {
  673. static wchar_t fileExtensionsString[MAX_PATH] = {0};
  674. wchar_t file[1024]=L"";
  675. OPENFILENAME fn = {0};
  676. fn.lStructSize = sizeof(fn);
  677. fn.hwndOwner = hwndDlg;
  678. fn.lpstrFile = file;
  679. fn.nMaxFile = 1024;
  680. if(!fileExtensionsString[0])
  681. {
  682. WASABI_API_LNGSTRINGW_BUF(IDS_IMAGE_FILES,fileExtensionsString,MAX_PATH);
  683. wchar_t *temp=fileExtensionsString+lstrlenW(fileExtensionsString) + 1;
  684. // query the available image loaders and build it against the supported formats
  685. FOURCC imgload = svc_imageLoader::getServiceType();
  686. int n = plugin.service->service_getNumServices(imgload);
  687. for (int i=0; i<n; i++)
  688. {
  689. waServiceFactory *sf = plugin.service->service_enumService(imgload,i);
  690. if (sf)
  691. {
  692. svc_imageLoader * l = (svc_imageLoader*)sf->getInterface();
  693. if (l)
  694. {
  695. wchar_t *tests[] = {L"*.jpg",L"*.png",L"*.gif",L"*.bmp"};
  696. for(int i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
  697. {
  698. if (l->isMine(tests[i]))
  699. {
  700. StringCchCatW(temp,MAX_PATH,tests[i]);
  701. StringCchCatW(temp,MAX_PATH,L";");
  702. }
  703. }
  704. sf->releaseInterface(l);
  705. }
  706. }
  707. }
  708. *(temp = temp + lstrlenW(temp) + 1) = 0;
  709. }
  710. fn.lpstrFilter = fileExtensionsString;
  711. fn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
  712. GetOpenFileName(&fn);
  713. editinfo_image *image = (editinfo_image *)calloc(1, sizeof(editinfo_image));
  714. image->data = loadImgFromFile(file,&image->w,&image->h);
  715. if(!image->data) { free(image); break; }
  716. setBitmap(image,hwndDlg);
  717. }
  718. break;
  719. case IDOK:
  720. {
  721. if(WASABI_API_DIALOGBOXPARAMW(IDD_PROGRESS,hwndDlg,editInfo_commit_dialogProc, (LPARAM)hwndDlg) == 0)
  722. EndDialog(hwndDlg,0);
  723. DeviceView * editDeviceView=NULL;
  724. for(int i=0; i < devices.GetSize(); i++) if(((DeviceView*)devices.Get(i))->dev == editDevice) editDeviceView = (DeviceView*)devices.Get(i);
  725. if(editDeviceView) editDeviceView->DevicePropertiesChanges();
  726. SendMessage(hwndMediaView,WM_USER+2,1,0);
  727. }
  728. break;
  729. case IDCANCEL:
  730. EndDialog(hwndDlg,0);
  731. break;
  732. }
  733. break;
  734. case WM_DESTROY:
  735. {
  736. editinfo_image* image = (editinfo_image*)GetWindowLongPtr(hwndDlg,GWLP_USERDATA);
  737. if(image) {
  738. if(image->data) WASABI_API_MEMMGR->sysFree(image->data);
  739. free(image);
  740. }
  741. SetWindowLongPtr(hwndDlg,GWLP_USERDATA,0);
  742. HBITMAP bmold = (HBITMAP)SendDlgItemMessage(hwndDlg,IDC_PICTUREHOLDER,STM_GETIMAGE,IMAGE_BITMAP,0);
  743. if(bmold) DeleteObject(bmold);
  744. }
  745. break;
  746. }
  747. return FALSE;
  748. }
  749. void editInfo(C_ItemList * items, Device * dev, HWND centerWindow) {
  750. editItems = items;
  751. editDevice = dev;
  752. WASABI_API_DIALOGBOXPARAMW(IDD_EDIT_INFO, plugin.hwndLibraryParent, editInfo_dialogProc, (LPARAM)centerWindow);
  753. }