ConfigDialog.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. #include "Main.h"
  2. #include "resource.h"
  3. #include "../nu/ListView.h"
  4. #include "FileTypes.h"
  5. #include "AutoChar.h"
  6. W_ListView typeList;
  7. FileTypes::TypeList types;
  8. #define CFGSET(hwnd, code, boolval) CheckDlgButton(hwnd, code, ((boolval)?BST_CHECKED:BST_UNCHECKED))
  9. struct SpeakerSetup
  10. {
  11. int description;
  12. DWORD value;
  13. };
  14. SpeakerSetup speakerList[] =
  15. {
  16. {IDS_STEREO,DSSPEAKER_STEREO},
  17. {IDS_QUADROPHONIC,DSSPEAKER_QUAD},
  18. {IDS_SURROUND,DSSPEAKER_SURROUND},
  19. {IDS_5_1,DSSPEAKER_5POINT1},
  20. {IDS_7_1,DSSPEAKER_7POINT1},
  21. };
  22. void FillFileTypes()
  23. {
  24. typeList.Clear();
  25. long attrCount = types.size();
  26. int pos=0;
  27. for (long i = 0;i < attrCount;i++)
  28. {
  29. typeList.InsertItem(pos, types[i].wtype, 0);
  30. typeList.SetItemText(pos, 1, types[i].description);
  31. pos++;
  32. }
  33. }
  34. void ResetTypes()
  35. {
  36. {
  37. Nullsoft::Utility::AutoLock lock (fileTypes.typeGuard);
  38. types=fileTypes.types;
  39. }
  40. FillFileTypes();
  41. }
  42. void Preferences_Populate(HWND hwndDlg)
  43. {
  44. CFGSET(hwndDlg, IDC_HTTPMETA, config_http_metadata);
  45. /* CFGSET(hwndDlg, IDC_SILENT, !config_no_silent);
  46. CFGSET(hwndDlg, IDC_UNTRUSTED, config_untrusted_ok);
  47. */
  48. CFGSET(hwndDlg, IDC_EXTRA_ASX, config_extra_asx_extensions);
  49. SetDlgItemInt(hwndDlg,IDC_BUFFER_TIME, config_buffer_time, FALSE/*unsigned*/);
  50. SendMessage(GetDlgItem(hwndDlg, IDC_AUDIO_SPEAKER_COUNT), CB_RESETCONTENT, 0, 0);
  51. for (int i = 0;i < sizeof(speakerList)/sizeof(speakerList[0]) ;i++)
  52. {
  53. SendMessage(GetDlgItem(hwndDlg, IDC_AUDIO_SPEAKER_COUNT), CB_ADDSTRING, 0, (LPARAM) WASABI_API_LNGSTRINGW(speakerList[i].description));
  54. if (speakerList[i].value == config_audio_num_channels)
  55. SendMessage(GetDlgItem(hwndDlg, IDC_AUDIO_SPEAKER_COUNT), CB_SETCURSEL, i, 0);
  56. }
  57. ResetTypes();
  58. }
  59. void Preferences_Init(HWND hwndDlg)
  60. {
  61. typeList.setwnd(GetDlgItem(hwndDlg, IDC_TYPELIST));
  62. typeList.AddCol(WASABI_API_LNGSTRINGW(IDS_EXT), 75);
  63. typeList.AddCol(WASABI_API_LNGSTRINGW(IDS_DESCRIPTION), 250);
  64. Preferences_Populate(hwndDlg);
  65. if(config_col1 == -1)
  66. typeList.AutoSizeColumn(0);
  67. else
  68. typeList.SetColumnWidth(0, config_col1);
  69. if(config_col2 == -1)
  70. typeList.AutoSizeColumn(1);
  71. else
  72. typeList.SetColumnWidth(1, config_col2);
  73. if (NULL != WASABI_API_APP)
  74. WASABI_API_APP->DirectMouseWheel_EnableConvertToMouseWheel(typeList.getwnd(), TRUE);
  75. }
  76. void Preferences_TypeRemove(HWND hwndDlg)
  77. {
  78. int next = -1;
  79. do
  80. {
  81. next = typeList.GetNextSelected(next);
  82. if (next != -1)
  83. {
  84. free(types[next].wtype);
  85. types[next].wtype=0;
  86. }
  87. } while (next != -1);
  88. for (FileTypes::TypeList::iterator itr = types.begin(); itr != types.end(); )
  89. {
  90. if (!itr->wtype || !itr->wtype[0])
  91. types.erase(itr);
  92. else
  93. itr++;
  94. }
  95. }
  96. void OnOk(HWND hwndDlg)
  97. {
  98. config_http_metadata=IsDlgButtonChecked(hwndDlg, IDC_HTTPMETA)== BST_CHECKED;
  99. // config_no_silent=IsDlgButtonChecked(hwndDlg, IDC_SILENT) != BST_CHECKED;
  100. // config_untrusted_ok=IsDlgButtonChecked(hwndDlg, IDC_UNTRUSTED)== BST_CHECKED;
  101. config_extra_asx_extensions=IsDlgButtonChecked(hwndDlg, IDC_EXTRA_ASX)== BST_CHECKED;
  102. wchar_t temp[64] = {0};
  103. GetDlgItemText(hwndDlg,IDC_BUFFER_TIME, temp, 64);
  104. int newBufferTime= _wtoi(temp);
  105. if (newBufferTime<1000)
  106. newBufferTime=1000;
  107. if (newBufferTime>60000)
  108. newBufferTime=60000;
  109. config_buffer_time=newBufferTime;
  110. int numChannels=SendMessage(GetDlgItem(hwndDlg, IDC_AUDIO_SPEAKER_COUNT), CB_GETCURSEL, 0, 0);
  111. if (numChannels!=CB_ERR)
  112. config_audio_num_channels = speakerList[numChannels].value;
  113. fileTypes.SetTypes(types);
  114. }
  115. static INT_PTR CALLBACK AddTypeProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  116. {
  117. switch (uMsg)
  118. {
  119. case WM_INITDIALOG:
  120. CFGSET(hwndDlg, IDC_FILEEXTENSION, true);
  121. CFGSET(hwndDlg, IDC_TYPE_AUDIO, true);
  122. break;
  123. case WM_COMMAND:
  124. switch (LOWORD(wParam))
  125. {
  126. case IDC_PROTOCOL:
  127. SetDlgItemText(hwndDlg, IDC_STATIC_TYPE, WASABI_API_LNGSTRINGW(IDS_PROTOCOL));
  128. break;
  129. case IDC_FILEEXTENSION:
  130. SetDlgItemText(hwndDlg, IDC_STATIC_TYPE, WASABI_API_LNGSTRINGW(IDS_EXTENSION));
  131. break;
  132. case IDOK:
  133. {
  134. wchar_t type[MAX_PATH] = {0}, description[1024] = {0};
  135. GetDlgItemText(hwndDlg,IDC_TYPE,type,MAX_PATH);
  136. GetDlgItemText(hwndDlg,IDC_DESCRIPTION,description,1024);
  137. bool isProtocol = IsDlgButtonChecked(hwndDlg, IDC_PROTOCOL)== BST_CHECKED;
  138. int avType = IsDlgButtonChecked(hwndDlg, IDC_TYPE_VIDEO)== BST_CHECKED;
  139. types.push_back(FileType(type, description, isProtocol, avType));
  140. EndDialog(hwndDlg, 0);
  141. }
  142. break;
  143. case IDCANCEL:
  144. EndDialog(hwndDlg, 0);
  145. break;
  146. }
  147. break;
  148. }
  149. return FALSE;
  150. }
  151. void AddType(HWND hwndDlg)
  152. {
  153. WASABI_API_DIALOGBOXW(IDD_ADDTYPE, hwndDlg, AddTypeProc);
  154. }
  155. static size_t editIndex=0;
  156. static INT_PTR CALLBACK EditTypeProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  157. {
  158. switch (uMsg)
  159. {
  160. case WM_INITDIALOG:
  161. SetWindowText(hwndDlg, WASABI_API_LNGSTRINGW(IDS_EDIT_FILE_TYPE));
  162. CFGSET(hwndDlg, IDC_TYPE_AUDIO, (types[editIndex].avType==FileType::AUDIO));
  163. CFGSET(hwndDlg, IDC_TYPE_VIDEO, (types[editIndex].avType==FileType::VIDEO));
  164. CFGSET(hwndDlg, IDC_PROTOCOL, types[editIndex].isProtocol);
  165. CFGSET(hwndDlg, IDC_FILEEXTENSION, !types[editIndex].isProtocol);
  166. SetDlgItemText(hwndDlg,IDC_TYPE, types[editIndex].wtype);
  167. SetDlgItemText(hwndDlg,IDC_DESCRIPTION, types[editIndex].description);
  168. if (types[editIndex].isProtocol)
  169. SetDlgItemText(hwndDlg, IDC_STATIC_TYPE, WASABI_API_LNGSTRINGW(IDS_PROTOCOL));
  170. else
  171. SetDlgItemText(hwndDlg, IDC_STATIC_TYPE, WASABI_API_LNGSTRINGW(IDS_EXTENSION));
  172. break;
  173. case WM_COMMAND:
  174. switch (LOWORD(wParam))
  175. {
  176. case IDC_PROTOCOL:
  177. SetDlgItemText(hwndDlg, IDC_STATIC_TYPE, WASABI_API_LNGSTRINGW(IDS_PROTOCOL));
  178. break;
  179. case IDC_FILEEXTENSION:
  180. SetDlgItemText(hwndDlg, IDC_STATIC_TYPE, WASABI_API_LNGSTRINGW(IDS_EXTENSION));
  181. break;
  182. case IDOK:
  183. {
  184. wchar_t type[MAX_PATH] = {0}, description[1024] = {0};
  185. GetDlgItemText(hwndDlg,IDC_TYPE,type,MAX_PATH);
  186. GetDlgItemText(hwndDlg,IDC_DESCRIPTION,description,1024);
  187. bool isProtocol = IsDlgButtonChecked(hwndDlg, IDC_PROTOCOL)== BST_CHECKED;
  188. types[editIndex].avType = (IsDlgButtonChecked(hwndDlg, IDC_TYPE_VIDEO)== BST_CHECKED);
  189. if(types[editIndex].wtype)free(types[editIndex].wtype);
  190. types[editIndex].wtype = _wcsdup(type);
  191. types[editIndex].isProtocol = isProtocol;
  192. if(types[editIndex].description)free(types[editIndex].description);
  193. types[editIndex].description = _wcsdup(description);
  194. EndDialog(hwndDlg, 0);
  195. }
  196. break;
  197. case IDCANCEL:
  198. EndDialog(hwndDlg, 0);
  199. break;
  200. }
  201. break;
  202. }
  203. return FALSE;
  204. }
  205. void EditType(HWND hwndDlg)
  206. {
  207. editIndex=-1;
  208. do
  209. {
  210. editIndex=typeList.GetNextSelected(editIndex);
  211. if (editIndex != -1)
  212. {
  213. WASABI_API_DIALOGBOXW(IDD_ADDTYPE, hwndDlg, EditTypeProc);
  214. }
  215. else
  216. return;
  217. } while (true);
  218. }
  219. void Advanced_Init(HWND hwndDlg)
  220. {
  221. CFGSET(hwndDlg, IDC_AUDIO_THREAD, config_audio_dedicated_thread);
  222. CFGSET(hwndDlg, IDC_AUDIO_EARLY, config_audio_early);
  223. CFGSET(hwndDlg, IDC_AUDIO_OUTOFORDER, config_audio_outoforder);
  224. CFGSET(hwndDlg, IDC_AUDIO_DROP, config_video_catchup);
  225. CFGSET(hwndDlg, IDC_VIDEO_THREAD, config_video_dedicated_thread);
  226. CFGSET(hwndDlg, IDC_VIDEO_EARLY, config_video_early);
  227. CFGSET(hwndDlg, IDC_VIDEO_OUTOFORDER, config_video_outoforder);
  228. CFGSET(hwndDlg, IDC_VIDEO_NOTIFY, config_video_notifylate);
  229. CFGSET(hwndDlg, IDC_REALTIME, !config_clock);
  230. CFGSET(hwndDlg, IDC_LOWMEMORY, config_lowmemory);
  231. SetDlgItemInt(hwndDlg,IDC_AUDIO_CACHE_FRAMES, config_audio_cache_frames, TRUE/*signed*/);
  232. SetDlgItemInt(hwndDlg,IDC_VIDEO_CACHE_FRAMES, config_video_cache_frames, TRUE);
  233. SetDlgItemInt(hwndDlg,IDC_VIDEO_DROP_THRESHOLD, config_video_drop_threshold, TRUE);
  234. SetDlgItemInt(hwndDlg,IDC_VIDEO_JITTER, config_video_jitter, TRUE);
  235. SetDlgItemInt(hwndDlg,IDC_AUDIO_EARLYPAD, config_audio_early_pad, TRUE);
  236. SetDlgItemInt(hwndDlg,IDC_VIDEO_EARLYPAD, config_video_early_pad,TRUE);
  237. }
  238. void Advanced_OnOK(HWND hwndDlg)
  239. {
  240. config_audio_dedicated_thread=IsDlgButtonChecked(hwndDlg, IDC_AUDIO_THREAD)== BST_CHECKED;
  241. config_audio_early=IsDlgButtonChecked(hwndDlg, IDC_AUDIO_EARLY)== BST_CHECKED;
  242. config_audio_outoforder=IsDlgButtonChecked(hwndDlg, IDC_AUDIO_OUTOFORDER)== BST_CHECKED;
  243. config_video_catchup=IsDlgButtonChecked(hwndDlg, IDC_AUDIO_DROP)== BST_CHECKED;
  244. config_video_dedicated_thread=IsDlgButtonChecked(hwndDlg, IDC_VIDEO_THREAD)== BST_CHECKED;
  245. config_video_early=IsDlgButtonChecked(hwndDlg, IDC_VIDEO_EARLY)== BST_CHECKED;
  246. config_video_outoforder=IsDlgButtonChecked(hwndDlg, IDC_VIDEO_OUTOFORDER)== BST_CHECKED;
  247. config_video_notifylate=IsDlgButtonChecked(hwndDlg, IDC_VIDEO_NOTIFY)== BST_CHECKED;
  248. config_clock=IsDlgButtonChecked(hwndDlg, IDC_REALTIME)!= BST_CHECKED;
  249. config_lowmemory=IsDlgButtonChecked(hwndDlg, IDC_LOWMEMORY)== BST_CHECKED;
  250. wchar_t temp[64] = {0};
  251. GetDlgItemText(hwndDlg,IDC_AUDIO_CACHE_FRAMES, temp, 64);
  252. config_audio_cache_frames = _wtoi(temp);
  253. GetDlgItemText(hwndDlg,IDC_VIDEO_CACHE_FRAMES, temp, 64);
  254. config_video_cache_frames= _wtoi(temp);
  255. GetDlgItemText(hwndDlg,IDC_VIDEO_DROP_THRESHOLD, temp, 64);
  256. config_video_drop_threshold= _wtoi(temp);
  257. GetDlgItemText(hwndDlg,IDC_VIDEO_JITTER, temp, 64);
  258. config_video_jitter= _wtoi(temp);
  259. GetDlgItemText(hwndDlg,IDC_AUDIO_EARLYPAD, temp, 64);
  260. config_audio_early_pad= _wtoi(temp);
  261. GetDlgItemText(hwndDlg,IDC_VIDEO_EARLYPAD, temp, 64);
  262. config_video_early_pad= _wtoi(temp);
  263. }
  264. static INT_PTR CALLBACK AdvancedDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  265. {
  266. switch (uMsg)
  267. {
  268. case WM_INITDIALOG:
  269. Advanced_Init(hwndDlg);
  270. break;
  271. case WM_COMMAND:
  272. switch (LOWORD(wParam))
  273. {
  274. case IDOK:
  275. Advanced_OnOK(hwndDlg);
  276. EndDialog(hwndDlg, 0);
  277. break;
  278. case IDCANCEL:
  279. EndDialog(hwndDlg, 0);
  280. break;
  281. }
  282. break;
  283. }
  284. return 0;
  285. }
  286. void Advanced(HWND hwndDlg)
  287. {
  288. WASABI_API_DIALOGBOXW(IDD_ADVANCED, hwndDlg, AdvancedDialogProc);
  289. }
  290. void Preferences_Default(HWND hwndDlg)
  291. {
  292. if (config_no_video)
  293. {
  294. // TODO: ask the user if they want to enable video support
  295. }
  296. DefaultConfig();
  297. fileTypes.LoadDefaults();
  298. Preferences_Populate(hwndDlg);
  299. }
  300. INT_PTR CALLBACK PreferencesDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  301. {
  302. switch (uMsg)
  303. {
  304. case WM_INITDIALOG:
  305. Preferences_Init(hwndDlg);
  306. break;
  307. case WM_DESTROY:
  308. config_col1 = typeList.GetColumnWidth(0);
  309. config_col2 = typeList.GetColumnWidth(1);
  310. if (NULL != WASABI_API_APP)
  311. WASABI_API_APP->DirectMouseWheel_EnableConvertToMouseWheel(typeList.getwnd(), FALSE);
  312. break;
  313. case WM_COMMAND:
  314. switch (LOWORD(wParam))
  315. {
  316. case IDC_ADVANCED:
  317. Advanced(hwndDlg);
  318. break;
  319. case IDC_DEFAULTTYPE:
  320. Preferences_Default(hwndDlg);
  321. break;
  322. case IDC_ADDTYPE:
  323. AddType(hwndDlg);
  324. FillFileTypes();
  325. break;
  326. case IDC_EDITTYPE:
  327. EditType(hwndDlg);
  328. if(typeList.GetNextSelected(editIndex)!=-1)
  329. FillFileTypes();
  330. break;
  331. case IDC_REMOVETYPE:
  332. Preferences_TypeRemove(hwndDlg);
  333. FillFileTypes();
  334. break;
  335. case IDOK:
  336. OnOk(hwndDlg);
  337. case IDCANCEL:
  338. EndDialog(hwndDlg, 0);
  339. break;
  340. }
  341. break;
  342. }
  343. return 0;
  344. }