1
0

options_title.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /** (c) Nullsoft, Inc. C O N F I D E N T I A L
  2. ** Filename:
  3. ** Project:
  4. ** Description:
  5. ** Author:
  6. ** Created:
  7. **/
  8. #include "main.h"
  9. #include "resource.h"
  10. #include "options.h"
  11. #include "api.h"
  12. #include <Wininet.h>
  13. #include "language.h"
  14. int atf_changed = 0, old_config_useexttitles = 0;
  15. wchar_t old_config_titlefmt[1024] = {0};
  16. INT_PTR CALLBACK TitleProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  17. {
  18. extern char *g_titlefmt_default;
  19. hi helpinfo[]={
  20. {IDC_USEID5,IDS_P_O_ONPLAY},
  21. {IDC_USEID4,IDS_P_O_ONLOAD},
  22. {IDC_USEID3,IDS_P_O_ONDEM},
  23. {IDC_CONVERT1,IDS_P_O_CONVERT1},
  24. {IDC_CONVERT2,IDS_P_O_CONVERT2},
  25. };
  26. DO_HELP();
  27. switch (uMsg)
  28. {
  29. case WM_INITDIALOG:
  30. atf_changed = 0;
  31. link_startsubclass(hwndDlg, IDC_TAGZ_HELP);
  32. lstrcpynW(old_config_titlefmt,config_titlefmt,1024);
  33. old_config_useexttitles = !!config_useexttitles;
  34. SetDlgItemTextW(hwndDlg,IDC_FORMAT,config_titlefmt);
  35. CheckDlgButton(hwndDlg,IDC_CHECK1,!!config_useexttitles);
  36. CheckDlgButton(hwndDlg,IDC_USEID3,config_riol == 0?1:0);
  37. CheckDlgButton(hwndDlg,IDC_USEID4,config_riol == 1?1:0);
  38. CheckDlgButton(hwndDlg,IDC_USEID6,(config_riol == 4)?1:0);
  39. CheckDlgButton(hwndDlg,IDC_USEID5,(config_riol != 0 && config_riol != 1 && config_riol != 4)?1:0);
  40. CheckDlgButton(hwndDlg,IDC_CONVERT1,(config_fixtitles&1)?1:0);
  41. CheckDlgButton(hwndDlg,IDC_CONVERT2,(config_fixtitles&2)?1:0);
  42. EnableWindow(GetDlgItem(hwndDlg,IDC_TAGZ_DEFAULT),config_useexttitles);
  43. EnableWindow(GetDlgItem(hwndDlg,IDC_FORMAT),config_useexttitles);
  44. EnableWindow(GetDlgItem(hwndDlg,IDC_ATF_INFO),config_useexttitles);
  45. return 0;
  46. case WM_COMMAND:
  47. switch (LOWORD(wParam))
  48. {
  49. case IDC_CHECK1:
  50. config_useexttitles=!!IsDlgButtonChecked(hwndDlg,IDC_CHECK1);
  51. EnableWindow(GetDlgItem(hwndDlg,IDC_TAGZ_DEFAULT),config_useexttitles);
  52. EnableWindow(GetDlgItem(hwndDlg,IDC_FORMAT),config_useexttitles);
  53. EnableWindow(GetDlgItem(hwndDlg,IDC_ATF_INFO),config_useexttitles);
  54. break;
  55. case IDC_TAGZ_HELP:
  56. {
  57. wchar_t dirmask[MAX_PATH] = {0}, lang_code[4] = {0};
  58. lstrcpynW(lang_code, langManager->GetLanguageIdentifier(LANG_LANG_CODE), 3);
  59. // if we're not using a language pack or it reports en-US then use the default
  60. if(!config_langpack[0] || !lang_code[0] || !_wcsicmp(lang_code, L"en"))
  61. {
  62. GetTempPathW(MAX_PATH, dirmask);
  63. PathCombineW(dirmask, dirmask, L"atf.htm");
  64. if (!PathFileExistsW(dirmask))
  65. {
  66. save_local:
  67. DWORD size = 0, written = 0;
  68. HGLOBAL hResource = langManager->LoadResourceFromFile(hMainInstance, hMainInstance, RT_HTML,MAKEINTRESOURCE(IDR_ATF_HTML), &size);
  69. HANDLE hFile = CreateFileW(dirmask, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  70. if (INVALID_HANDLE_VALUE != hFile)
  71. {
  72. WriteFile(hFile, hResource, size, &written, NULL);
  73. CloseHandle(hFile);
  74. }
  75. }
  76. }
  77. else
  78. {
  79. PathCombineW(dirmask, lang_directory, L"atf.htm");
  80. if (!PathFileExistsW(dirmask))
  81. {
  82. goto save_local;
  83. }
  84. }
  85. myOpenURL(hwndDlg, dirmask);
  86. }
  87. break;
  88. case IDC_TAGZ_DEFAULT:
  89. StringCchCopyW(config_titlefmt, sizeof(config_titlefmt)/sizeof(*config_titlefmt), L"[%artist% - ]$if2(%title%,$filepart(%filename%))");
  90. SetDlgItemTextW(hwndDlg,IDC_FORMAT,config_titlefmt);
  91. break;
  92. case IDC_FORMAT:
  93. if (HIWORD(wParam) == EN_CHANGE)
  94. {
  95. GetDlgItemTextW(hwndDlg,IDC_FORMAT,config_titlefmt, sizeof(config_titlefmt)/sizeof(*config_titlefmt) - 1);
  96. config_titlefmt[sizeof(config_titlefmt)/sizeof(*config_titlefmt) - 1]=0;
  97. atf_changed = !!lstrcmpW(old_config_titlefmt,config_titlefmt);
  98. }
  99. break;
  100. case IDC_CONVERT1:
  101. case IDC_CONVERT2:
  102. config_fixtitles = (IsDlgButtonChecked(hwndDlg,IDC_CONVERT1)?1:0)|(IsDlgButtonChecked(hwndDlg,IDC_CONVERT2)?2:0);
  103. break;
  104. case IDC_USEID3:
  105. case IDC_USEID4:
  106. case IDC_USEID5:
  107. case IDC_USEID6:
  108. if (HIWORD(wParam) == BN_CLICKED)
  109. {
  110. config_riol = IsDlgButtonChecked(hwndDlg,IDC_USEID4)?1:2;
  111. if (config_riol==2) {
  112. config_riol = IsDlgButtonChecked(hwndDlg,IDC_USEID3)?0:2;
  113. }
  114. if (config_riol==2) {
  115. config_riol = IsDlgButtonChecked(hwndDlg,IDC_USEID6)?4:2;
  116. }
  117. }
  118. break;
  119. }
  120. return 0;
  121. case WM_DESTROY:
  122. char titleStr[64] = {0};
  123. if(((atf_changed && !!config_useexttitles) || (old_config_useexttitles != config_useexttitles )) &&
  124. MessageBoxA(hwndDlg,getString(IDS_ATF_HAS_CHANGED,NULL,0),
  125. getString(IDS_REFRESH_PLAYLIST_TITLES,titleStr,64),
  126. MB_ICONQUESTION | MB_YESNO) == IDYES)
  127. {
  128. wchar_t ft[FILETITLE_SIZE] = {0};
  129. for (int x = 0; x < PlayList_getlength(); x ++)
  130. {
  131. if (!PlayList_gethidden(x) && !PlayList_hasanycurtain(x))
  132. {
  133. wchar_t fn[FILENAME_SIZE] = {0};
  134. PlayList_getitem(x, fn, ft);
  135. PlayList_setitem(x, fn, PlayList_gettitle(fn, 1));
  136. PlayList_setlastlen(x);
  137. }
  138. }
  139. InvalidateRect(hPLWindow, NULL, FALSE);
  140. }
  141. break;
  142. }
  143. link_handledraw(hwndDlg,uMsg,wParam,lParam);
  144. return 0;
  145. }