Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

259 lines
8.0 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All Rights Reserved.
  2. /*************************************************************/
  3. /* Name: pgcallbk.cpp
  4. /* Description:
  5. /*************************************************************/
  6. #include "stdafx.h"
  7. #include "password.h"
  8. #include "COptDlg.h"
  9. const TCHAR g_szPassword[] = TEXT("DVDAdmin.password");
  10. const TCHAR g_szPlayerLevel[] = TEXT("DVDAdmin.rate");
  11. const TCHAR g_szDisableParent[] = TEXT("DVDAdmin.disableParentalControl");
  12. /*************************************************************/
  13. /* Name: GetDvd
  14. /* Description:
  15. /*************************************************************/
  16. HRESULT COptionsDlg::GetDvd(IMSWebDVD** ppDvd) {
  17. return m_pDvd.CopyTo(ppDvd);
  18. }
  19. /*************************************************************/
  20. /* Name: GetDvdAdm
  21. /* Description: Use CComPtr to receive the returned interface,
  22. /* so that reference count will be added and released accordingly
  23. /*************************************************************/
  24. HRESULT COptionsDlg::GetDvdAdm(LPVOID* ppAdmin){
  25. *ppAdmin = NULL;
  26. IDispatch* pDvdAdmDisp;
  27. HRESULT hr = m_pDvd->get_DVDAdm(&pDvdAdmDisp);
  28. if (FAILED(hr)) return NULL;
  29. hr = pDvdAdmDisp->QueryInterface(IID_IMSDVDAdm, (LPVOID*) ppAdmin);
  30. pDvdAdmDisp->Release();
  31. return(hr);
  32. }/* end of function GetDvdAdm */
  33. /*************************************************************/
  34. /* Name: pg_GetLevel
  35. /* Description: return the parental level number
  36. /*************************************************************/
  37. long COptionsDlg::pg_GetLevel(LPTSTR szRate)
  38. {
  39. long lLevel = LEVEL_ADULT;
  40. LPTSTR csStr = LoadStringFromRes(IDS_INI_RATE_G);
  41. if(lstrcmp(szRate, csStr) == 0)
  42. lLevel = LEVEL_G;
  43. delete[] csStr;
  44. csStr = LoadStringFromRes(IDS_INI_RATE_PG);
  45. if(lstrcmp(szRate, csStr) == 0)
  46. lLevel = LEVEL_PG;
  47. delete[] csStr;
  48. csStr = LoadStringFromRes(IDS_INI_RATE_PG13);
  49. if(lstrcmp(szRate, csStr) == 0)
  50. lLevel = LEVEL_PG13;
  51. delete[] csStr;
  52. csStr = LoadStringFromRes(IDS_INI_RATE_R);
  53. if(lstrcmp(szRate, csStr) == 0)
  54. lLevel = LEVEL_R;
  55. delete[] csStr;
  56. csStr = LoadStringFromRes(IDS_INI_RATE_NC17);
  57. if(lstrcmp(szRate, csStr) == 0)
  58. lLevel = LEVEL_NC17;
  59. delete[] csStr;
  60. csStr = LoadStringFromRes(IDS_INI_RATE_ADULT);
  61. if(lstrcmp(szRate, csStr) == 0)
  62. lLevel = LEVEL_ADULT;
  63. delete[] csStr;
  64. return lLevel;
  65. }
  66. /*************************************************************/
  67. /* Name: pg_InitRateList
  68. /* Description: Initialize parental level combo list
  69. /*************************************************************/
  70. HRESULT COptionsDlg::pg_InitRateList(HWND ctlList, long level)
  71. {
  72. ::SendMessage(ctlList, CB_RESETCONTENT, 0, 0);
  73. LPTSTR csStr;
  74. csStr = LoadStringFromRes(IDS_INI_RATE_G);
  75. ::SendMessage(ctlList, CB_INSERTSTRING, (UINT)-1, (LPARAM) csStr);
  76. delete csStr;
  77. csStr = LoadStringFromRes(IDS_INI_RATE_PG);
  78. ::SendMessage(ctlList, CB_INSERTSTRING, (UINT)-1, (LPARAM) csStr);
  79. delete csStr;
  80. csStr = LoadStringFromRes(IDS_INI_RATE_PG13);
  81. ::SendMessage(ctlList, CB_INSERTSTRING, (UINT)-1, (LPARAM) csStr);
  82. delete csStr;
  83. csStr = LoadStringFromRes(IDS_INI_RATE_R);
  84. ::SendMessage(ctlList, CB_INSERTSTRING, (UINT)-1, (LPARAM) csStr);
  85. delete csStr;
  86. csStr = LoadStringFromRes(IDS_INI_RATE_NC17);
  87. ::SendMessage(ctlList, CB_INSERTSTRING, (UINT)-1, (LPARAM) csStr);
  88. delete csStr;
  89. csStr = LoadStringFromRes(IDS_INI_RATE_ADULT);
  90. ::SendMessage(ctlList, CB_INSERTSTRING, (UINT)-1, (LPARAM) csStr);
  91. delete csStr;
  92. switch (level) {
  93. case LEVEL_G:
  94. case LEVEL_G_PG:
  95. SendMessage(ctlList, CB_SETCURSEL, (WPARAM) 0, 0);
  96. break;
  97. case LEVEL_PG:
  98. SendMessage(ctlList, CB_SETCURSEL, (WPARAM) 1, 0);
  99. break;
  100. case LEVEL_PG13:
  101. case LEVEL_PG_R:
  102. SendMessage(ctlList, CB_SETCURSEL, (WPARAM) 2, 0);
  103. break;
  104. case LEVEL_R:
  105. SendMessage(ctlList, CB_SETCURSEL, (WPARAM) 3, 0);
  106. break;
  107. case LEVEL_NC17:
  108. SendMessage(ctlList, CB_SETCURSEL, (WPARAM) 4, 0);
  109. break;
  110. case LEVEL_ADULT:
  111. default:
  112. SendMessage(ctlList, CB_SETCURSEL, (WPARAM) 5, 0);
  113. break;
  114. }
  115. return S_OK;
  116. }
  117. /*************************************************************/
  118. /* Name: pg_OnInitDialog
  119. /* Description: OnInitDialog for the parental control page
  120. /*************************************************************/
  121. HRESULT COptionsDlg::pg_OnInitDialog(HWND hwndDlg)
  122. {
  123. HWND ctlList = ::GetDlgItem(hwndDlg, IDC_COMBO_RATE);
  124. HWND checkBox = ::GetDlgItem(hwndDlg, IDC_DISABLE_PARENT);
  125. if (!IDC_COMBO_RATE || !checkBox)
  126. return S_FALSE;
  127. HRESULT hr = S_OK;
  128. CComPtr<IMSDVDAdm> pDvdAdm;
  129. hr = GetDvdAdm((LPVOID*) &pDvdAdm);
  130. if (FAILED(hr) || !pDvdAdm) return S_FALSE;
  131. long level = 0;
  132. hr = pDvdAdm->GetParentalLevel(&level);
  133. pg_InitRateList(ctlList, level);
  134. BOOL fDisabled = (level == LEVEL_DISABLED);
  135. ::SendMessage(checkBox, BM_SETCHECK, fDisabled, 0);
  136. ::EnableWindow(ctlList, !fDisabled);
  137. return S_OK;
  138. }
  139. /*************************************************************/
  140. /* Name: pg_OnApply
  141. /* Description: Apply the parental control setting changes
  142. /*************************************************************/
  143. HRESULT COptionsDlg::pg_OnApply(HWND hwndDlg)
  144. {
  145. USES_CONVERSION;
  146. HWND ctlList = ::GetDlgItem(hwndDlg, IDC_COMBO_RATE);
  147. HWND checkBox = ::GetDlgItem(hwndDlg, IDC_DISABLE_PARENT);
  148. if (!IDC_COMBO_RATE || !checkBox)
  149. return S_FALSE;
  150. if (!m_pPasswordDlg)
  151. return E_UNEXPECTED;
  152. BOOL disableParent = (BOOL) ::SendMessage(checkBox, BM_GETCHECK, 0, 0);
  153. HRESULT hr = S_OK;
  154. CComPtr<IMSDVDAdm> pDvdAdm;
  155. hr = GetDvdAdm((LPVOID*) &pDvdAdm);
  156. if (FAILED(hr) || !pDvdAdm) return S_FALSE;
  157. // Get the saved settings
  158. long lLevelSaved;
  159. pDvdAdm->GetParentalLevel(&lLevelSaved);
  160. BOOL bChangePG = FALSE;
  161. // Get the selected level in the rate list box
  162. long level = (long) ::SendMessage(ctlList, CB_GETCURSEL, 0, 0) ;
  163. TCHAR szRate[MAX_RATE];
  164. ::SendMessage(ctlList, CB_GETLBTEXT, level, (LPARAM)szRate);
  165. long lLevel = pg_GetLevel(szRate);
  166. // If a different parental level is selected from the saved level
  167. if (!disableParent && lLevel!=lLevelSaved) {
  168. bChangePG = TRUE;
  169. }
  170. // If the disable parental control option is changed from the saved setting
  171. else if (disableParent && lLevelSaved != LEVEL_DISABLED) {
  172. // Set parental level to -1 when parental control is disabled
  173. lLevel = LEVEL_DISABLED;
  174. bChangePG = TRUE;
  175. }
  176. // Get the verified password from the password dialog
  177. LPTSTR szPassword = m_pPasswordDlg->GetPassword();
  178. if (bChangePG) {
  179. try {
  180. HRESULT hr = pDvdAdm->SaveParentalLevel(lLevel, NULL, T2OLE(szPassword));
  181. if (hr == E_ACCESSDENIED){
  182. DVDMessageBox(hwndDlg, IDS_PASSWORD_INCORRECT);
  183. pg_OnInitDialog(hwndDlg);
  184. return hr;
  185. }
  186. // Actually setting the player level
  187. hr = m_pDvd->GetPlayerParentalLevel(&lLevelSaved);
  188. if (lLevel!=lLevelSaved) {
  189. hr = m_pDvd->Stop();
  190. if (FAILED(hr))
  191. throw (hr);
  192. hr = m_pDvd->SelectParentalLevel(lLevel, NULL, T2OLE(szPassword));
  193. if (hr == E_ACCESSDENIED){
  194. DVDMessageBox(hwndDlg, IDS_PASSWORD_INCORRECT);
  195. pg_OnInitDialog(hwndDlg);
  196. return hr;
  197. }
  198. if (FAILED(hr)) {
  199. DVDMessageBox(hwndDlg, IDS_RATE_CHANGE_FAIL);
  200. pg_OnInitDialog(hwndDlg);
  201. return hr;
  202. }
  203. hr = m_pDvd->Play();
  204. if (FAILED(hr))
  205. throw hr;
  206. }
  207. }
  208. catch (HRESULT hrTmp) {
  209. DVDMessageBox(hwndDlg, IDS_STOP_PLAY_FAIL);
  210. pg_OnInitDialog(hwndDlg);
  211. hr = hrTmp;
  212. }
  213. }
  214. return hr;
  215. }