1
0

Preferences.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include "main.h"
  2. #include "./preferences.h"
  3. #include "../winamp/wa_ipc.h"
  4. #include "./resource.h"
  5. #include "./api__ml_online.h"
  6. #include "./config.h"
  7. #include <windows.h>
  8. #include <shlobj.h>
  9. static prefsDlgRecW preferences;
  10. extern C_Config *g_config;
  11. static INT_PTR CALLBACK Preferences_DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  12. BOOL Preferences_Register()
  13. {
  14. WCHAR szBuffer[256] = {0};
  15. WASABI_API_LNGSTRINGW_BUF(IDS_ONLINE_SERVICES, szBuffer, ARRAYSIZE(szBuffer));
  16. preferences.hInst = WASABI_API_LNG_HINST;
  17. preferences.dlgID = IDD_OMPREF;
  18. preferences.proc = (void *)Preferences_DialogProc;
  19. preferences.name = Plugin_CopyString(szBuffer);
  20. preferences.where = 6; // Media Library
  21. return (BOOL)SENDWAIPC(Plugin_GetWinamp(), IPC_ADD_PREFS_DLGW, &preferences);
  22. }
  23. void Preferences_Unregister()
  24. {
  25. SENDWAIPC(Plugin_GetWinamp(), IPC_REMOVE_PREFS_DLG, &preferences);
  26. }
  27. BOOL Preferences_Show()
  28. {
  29. return (BOOL)SENDWAIPC(Plugin_GetWinamp(), IPC_OPENPREFSTOPAGE, &preferences);
  30. }
  31. static INT_PTR CALLBACK Preferences_DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  32. {
  33. switch(uMsg)
  34. {
  35. case WM_INITDIALOG:
  36. {
  37. CheckDlgButton(hwndDlg,IDC_AUTOSIZE,g_config->ReadInt("AutoSize",1));
  38. char tmp[64] = {0};
  39. wsprintfA(tmp,"%i",g_config->ReadInt("maxbandwidth", MAXBANDWIDTH ));
  40. SetDlgItemTextA(hwndDlg,IDC_RADIO_MAXBW,tmp);
  41. wsprintfA(tmp,"%i",g_config->ReadInt("minbandwidth",1));
  42. SetDlgItemTextA(hwndDlg,IDC_RADIO_MINBW,tmp);
  43. int radiofreq=g_config->ReadInt("radio_upd_freq",0);
  44. CheckDlgButton(hwndDlg,radiofreq==0?IDC_RADIO_HOURLY:radiofreq==1?IDC_RADIO_DAILY:radiofreq==2?IDC_RADIO_WEEKLY:IDC_RADIO_NEVER,BST_CHECKED);
  45. SetDlgItemTextA(hwndDlg, IDC_NOWPLAYINGURL, g_config->ReadString("nowplayingurl",""));
  46. }
  47. break;
  48. case WM_COMMAND:
  49. switch(LOWORD(wParam))
  50. {
  51. case IDC_AUTOSIZE:
  52. g_config->WriteInt("AutoSize",IsDlgButtonChecked(hwndDlg,IDC_AUTOSIZE));
  53. break;
  54. case IDC_RADIO_NEVER:
  55. case IDC_RADIO_DAILY:
  56. case IDC_RADIO_WEEKLY:
  57. case IDC_RADIO_HOURLY:
  58. {
  59. int radiofreq=0;
  60. if(IsDlgButtonChecked(hwndDlg,IDC_RADIO_NEVER)) radiofreq=3;
  61. if(IsDlgButtonChecked(hwndDlg,IDC_RADIO_DAILY)) radiofreq=1;
  62. if(IsDlgButtonChecked(hwndDlg,IDC_RADIO_WEEKLY)) radiofreq=2;
  63. if(IsDlgButtonChecked(hwndDlg,IDC_RADIO_HOURLY)) radiofreq=0;
  64. g_config->WriteInt("radio_upd_freq",radiofreq);
  65. }
  66. break;
  67. case IDC_NOWPLAYINGURL:
  68. if (HIWORD(wParam) == EN_CHANGE)
  69. {
  70. char nowplayingurl[1024] = {0};
  71. GetDlgItemTextA(hwndDlg, IDC_NOWPLAYINGURL, nowplayingurl, ARRAYSIZE(nowplayingurl));
  72. g_config->WriteString("nowplayingurl",nowplayingurl);
  73. }
  74. break;
  75. }
  76. break;
  77. case WM_DESTROY:
  78. {
  79. char tmp[64]={0,};
  80. GetDlgItemTextA(hwndDlg,IDC_RADIO_MAXBW,tmp,sizeof(tmp)-1);
  81. int x = atoi(tmp);
  82. if ( x < 2 ) x = 2;
  83. g_config->WriteInt("maxbandwidth",x);
  84. GetDlgItemTextA(hwndDlg,IDC_RADIO_MINBW,tmp,sizeof(tmp)-1);
  85. int y = atoi(tmp);
  86. if ( y < 1 ) y = 1;
  87. if ( y > x ) y = x-1;
  88. g_config->WriteInt("minbandwidth",y);
  89. }
  90. break;
  91. }
  92. return 0;
  93. }