1
0

wasabiCallback.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "main.h"
  2. #include "./wasabiCallback.h"
  3. #include "./navigation.h"
  4. #include "./service.h"
  5. #include "../replicant/nu/Autowide.h"
  6. WasabiCallback::WasabiCallback()
  7. : ref(1)
  8. {
  9. }
  10. WasabiCallback::~WasabiCallback()
  11. {
  12. }
  13. HRESULT WasabiCallback::CreateInstance(WasabiCallback **instance)
  14. {
  15. if (NULL == instance) return E_POINTER;
  16. *instance = new WasabiCallback();
  17. if (NULL == *instance) return E_OUTOFMEMORY;
  18. return S_OK;
  19. }
  20. size_t WasabiCallback::AddRef()
  21. {
  22. return InterlockedIncrement((LONG*)&ref);
  23. }
  24. size_t WasabiCallback::Release()
  25. {
  26. if (0 == ref)
  27. return ref;
  28. LONG r = InterlockedDecrement((LONG*)&ref);
  29. if (0 == r)
  30. delete(this);
  31. return r;
  32. }
  33. int WasabiCallback::QueryInterface(GUID interface_guid, void **object)
  34. {
  35. return 0;
  36. }
  37. FOURCC WasabiCallback::GetEventType()
  38. {
  39. return SysCallback::BROWSER;
  40. }
  41. int WasabiCallback::Notify(int msg, intptr_t param1, intptr_t param2)
  42. {
  43. switch (msg)
  44. {
  45. case BrowserCallback::ONOPENURL:
  46. return OpenURL(reinterpret_cast<const wchar_t*>(param1), reinterpret_cast<bool *>(param2));
  47. }
  48. return 0;
  49. }
  50. int WasabiCallback::OpenURL(const wchar_t *url, bool *override)
  51. {
  52. WCHAR szTemplate[1024] = L"http://client.winamp.com/nowplaying";
  53. INT cchTemplate = ARRAYSIZE(szTemplate) - 1;
  54. lstrcpynW(szTemplate, AutoWide(g_config->ReadString("nowplayingurl", "http://client.winamp.com/nowplaying")), ARRAYSIZE(szTemplate));
  55. if (NULL != url &&
  56. CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, url, cchTemplate, szTemplate, cchTemplate))
  57. {
  58. if (SUCCEEDED(Navigation_ShowService(SERVICE_ID, url,
  59. NAVFLAG_FORCEACTIVE | NAVFLAG_ENSUREMLVISIBLE | NAVFLAG_ENSUREITEMVISIBLE)))
  60. {
  61. *override = true;
  62. return 1;
  63. }
  64. }
  65. return 0;
  66. }
  67. #define CBCLASS WasabiCallback
  68. START_DISPATCH;
  69. CB(ADDREF, AddRef);
  70. CB(RELEASE, Release);
  71. CB(QUERYINTERFACE, QueryInterface);
  72. CB(SYSCALLBACK_GETEVENTTYPE, GetEventType);
  73. CB(SYSCALLBACK_NOTIFY, Notify);
  74. END_DISPATCH;
  75. #undef CBCLASS