1
0

RatingsCOM.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #include "main.h"
  2. #include "RatingsCOM.h"
  3. #include "config.h"
  4. extern C_Config *g_config;
  5. enum
  6. {
  7. DISP_GETRATING = 0,
  8. DISP_ISEVERYONEALLOWED,
  9. DISP_ISTEENALLOWED,
  10. DISP_ISADULTALLOWED,
  11. DISP_ISXRATEDALLOWED,
  12. DISP_ISNOTRATEDALLOWED,
  13. };
  14. #define CHECK_ID(str, id) if (wcscmp(rgszNames[i], L##str) == 0) { rgdispid[i] = id; continue; }
  15. HRESULT RatingsCOM::GetIDsOfNames(REFIID riid, OLECHAR FAR* FAR* rgszNames, unsigned int cNames, LCID lcid, DISPID FAR* rgdispid)
  16. {
  17. bool unknowns = false;
  18. for (unsigned int i = 0;i != cNames;i++)
  19. {
  20. CHECK_ID("GetRating", DISP_GETRATING);
  21. CHECK_ID("IsEveryoneAllowed", DISP_ISEVERYONEALLOWED);
  22. CHECK_ID("IsTeenAllowed", DISP_ISTEENALLOWED);
  23. CHECK_ID("IsAdultAllowed", DISP_ISADULTALLOWED);
  24. CHECK_ID("IsXRatedAllowed", DISP_ISXRATEDALLOWED);
  25. CHECK_ID("IsNotRatedAllowed", DISP_ISNOTRATEDALLOWED);
  26. rgdispid[i] = DISPID_UNKNOWN;
  27. unknowns = true;
  28. }
  29. if (unknowns)
  30. return DISP_E_UNKNOWNNAME;
  31. else
  32. return S_OK;
  33. }
  34. HRESULT RatingsCOM::GetTypeInfo(unsigned int itinfo, LCID lcid, ITypeInfo FAR* FAR* pptinfo)
  35. {
  36. return E_NOTIMPL;
  37. }
  38. HRESULT RatingsCOM::GetTypeInfoCount(unsigned int FAR * pctinfo)
  39. {
  40. return E_NOTIMPL;
  41. }
  42. HRESULT RatingsCOM::Invoke(DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, EXCEPINFO FAR * pexecinfo, unsigned int FAR *puArgErr)
  43. {
  44. int rating = g_config->ReadInt(L"tvrating", 7);
  45. switch (dispid)
  46. {
  47. case DISP_GETRATING:
  48. VariantInit(pvarResult);
  49. V_VT(pvarResult) = VT_I4;
  50. V_I4(pvarResult) = rating;
  51. return S_OK;
  52. case DISP_ISEVERYONEALLOWED:
  53. VariantInit(pvarResult);
  54. V_VT(pvarResult) = VT_BOOL;
  55. V_BOOL(pvarResult) = (rating & 1) || (rating & 2);
  56. return S_OK;
  57. case DISP_ISTEENALLOWED:
  58. VariantInit(pvarResult);
  59. V_VT(pvarResult) = VT_BOOL;
  60. V_BOOL(pvarResult) = rating & 4;
  61. return S_OK;
  62. case DISP_ISADULTALLOWED:
  63. VariantInit(pvarResult);
  64. V_VT(pvarResult) = VT_BOOL;
  65. V_BOOL(pvarResult) = rating & 8;
  66. return S_OK;
  67. case DISP_ISXRATEDALLOWED:
  68. VariantInit(pvarResult);
  69. V_VT(pvarResult) = VT_BOOL;
  70. V_BOOL(pvarResult) = (rating & 16) || (rating & 32);
  71. return S_OK;
  72. case DISP_ISNOTRATEDALLOWED:
  73. VariantInit(pvarResult);
  74. V_VT(pvarResult) = VT_BOOL;
  75. V_BOOL(pvarResult) = rating & 64 ;
  76. return S_OK;
  77. }
  78. return DISP_E_MEMBERNOTFOUND;
  79. }
  80. STDMETHODIMP RatingsCOM::QueryInterface(REFIID riid, PVOID *ppvObject)
  81. {
  82. if (!ppvObject)
  83. return E_POINTER;
  84. else if (IsEqualIID(riid, IID_IDispatch))
  85. *ppvObject = (IDispatch *)this;
  86. else if (IsEqualIID(riid, IID_IUnknown))
  87. *ppvObject = this;
  88. else
  89. {
  90. *ppvObject = NULL;
  91. return E_NOINTERFACE;
  92. }
  93. AddRef();
  94. return S_OK;
  95. }
  96. ULONG RatingsCOM::AddRef(void)
  97. {
  98. return 0;
  99. }
  100. ULONG RatingsCOM::Release(void)
  101. {
  102. return 0;
  103. }