varmgr.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include <precomp.h>
  2. #include "varmgr.h"
  3. #include <api/script/objects/guiobj.h>
  4. #include <api/skin/widgets/group.h>
  5. #include <api/skin/skinparse.h>
  6. #include <api/wac/wac.h>
  7. #include <bfc/parse/pathparse.h>
  8. // for now only translates special text like :componentname etc but in the future
  9. // this will translate xml variables
  10. StringW *PublicVarManager::translate_nocontext(const wchar_t *str)
  11. {
  12. return translate(str, NULL, NULL);
  13. }
  14. //Martin> TODO: Split this method for <include/>, <bitmap/>,... and <text/> objects
  15. StringW *PublicVarManager::translate(const wchar_t *str, GuiObject *o, Container *c)
  16. {
  17. if (str == NULL) return NULL;
  18. //test if @ or : is present
  19. {
  20. const wchar_t *p=str;
  21. int found=0;
  22. while(p && *p && !found) {
  23. wchar_t a=*p++;
  24. if(a==':' || a=='@') found=1;
  25. }
  26. if(!found)
  27. return NULL;
  28. }
  29. // lone> this needs to be a service, but it may slow shit down if we enum too often since this is called for all xml values, so carfull when you add this, lone
  30. #ifdef CUSTOM_VARS
  31. const wchar_t *rpl=NULL;
  32. CUSTOM_VARS(str, rpl);
  33. if (rpl != NULL) return new StringW(rpl);
  34. #endif
  35. const wchar_t *skinname = NULL;
  36. if (WASABI_API_SKIN != NULL)
  37. skinname=WASABI_API_SKIN->getSkinName();
  38. static int in=0;
  39. if (in)
  40. return NULL;
  41. in = 1;
  42. StringW *ret = new StringW(str);
  43. if (skinname)
  44. {
  45. StringW colorThemePath = WASABI_API_APP->path_getAppPath();
  46. colorThemePath.AppendPath(L"ColorThemes");
  47. colorThemePath.AppendPath(skinname);
  48. ret->replace(L"@COLORTHEMESPATH@", colorThemePath);
  49. ret->replace(L"@SKINPATH@", WASABI_API_SKIN->getSkinPath());
  50. ret->replace(L"@SKINSPATH@", WASABI_API_SKIN->getSkinsPath());
  51. ret->replace(L"@APPDATAPATH@", WASABI_API_APP->path_getUserSettingsPath());
  52. //ret->replace(L"@DEFAULTSKINPATH@", StringPathCombine(WASABI_API_SKIN->getSkinsPath(), L"Default")); //Martin> doesn't exist in winamp5, so cut to speed loading
  53. ret->replace(L"@WINAMPPATH@", StringPrintfW(L"%s\\", WASABI_API_APP->path_getAppPath()));
  54. }
  55. #ifdef WASABI_COMPILE_COMPONENTS
  56. ret->replace("@WACDATAPATH@", WASABI_API_APP->path_getComponentDataPath());
  57. #endif
  58. if (!o && !c) { in = 0; return ret; }
  59. //CUT wtf? if (!str) return NULL;
  60. const wchar_t *containerid = NULL;
  61. const wchar_t *groupid = NULL;
  62. const wchar_t *componentName = NULL;
  63. if (o && o->guiobject_getParentGroup())
  64. {
  65. groupid = o->guiobject_getParentGroup()->getGuiObject()->guiobject_getId();
  66. if (o->guiobject_getParentGroup()->getParentContainer())
  67. {
  68. containerid = o->guiobject_getParentGroup()->getParentContainer()->getId();
  69. componentName = o->guiobject_getParentGroup()->getParentContainer()->getName();
  70. }
  71. }
  72. else {
  73. groupid = SkinParser::getCurrentGroupId();
  74. if (c) {
  75. containerid = c->getId();
  76. componentName = /*c->hasComponent() ? api->getComponentName(c->getGUID()) : */c->getName();
  77. } else {
  78. containerid = SkinParser::getCurrentContainerId();
  79. componentName = NULL;
  80. }
  81. }
  82. if (componentName != NULL) {
  83. ret->replace(L":componentname", componentName); // DEPRECATED
  84. ret->replace(L"@COMPONENTNAME@", componentName);
  85. }
  86. if (containerid != NULL) {
  87. ret->replace(L":containerid", containerid); // DEPRECATED
  88. ret->replace(L"@CONTAINERID@", containerid);
  89. }
  90. if (groupid != NULL) {
  91. ret->replace(L":groupid", groupid); // DEPRECATED
  92. ret->replace(L"@GROUPID@",groupid);
  93. }
  94. in = 0;
  95. return ret;
  96. }