ChatProtocolAddOn.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Copyright 2010-2011, Pier Luigi Fiorini. All rights reserved.
  3. * Distributed under the terms of the MIT License.
  4. *
  5. * Authors:
  6. * Andrea Anzani, andrea.anzani@gmail.com
  7. * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
  8. */
  9. #include <Bitmap.h>
  10. #include <Path.h>
  11. #include <libinterface/BitmapUtils.h>
  12. #include "ChatProtocol.h"
  13. #include "ChatProtocolAddOn.h"
  14. ChatProtocolAddOn::ChatProtocolAddOn(image_id image, const char* path, int32 subProto)
  15. :
  16. fImage(image),
  17. fPath(path),
  18. fIcon(NULL),
  19. fProtoIndex(subProto)
  20. {
  21. _Init();
  22. }
  23. status_t
  24. ChatProtocolAddOn::InitCheck() const
  25. {
  26. return fStatus;
  27. }
  28. const char*
  29. ChatProtocolAddOn::Path() const
  30. {
  31. return fPath.String();
  32. }
  33. ChatProtocol*
  34. ChatProtocolAddOn::Protocol() const
  35. {
  36. return ProtocolAt(fProtoIndex);
  37. }
  38. ChatProtocol*
  39. ChatProtocolAddOn::ProtocolAt(int32 i) const
  40. {
  41. ChatProtocol* proto = fGetProtocol(i);
  42. proto->SetAddOnPath(BPath(fPath.String()));
  43. return proto;
  44. }
  45. int32
  46. ChatProtocolAddOn::CountProtocols() const
  47. {
  48. return fCountProtocols();
  49. }
  50. const char*
  51. ChatProtocolAddOn::Signature() const
  52. {
  53. return fSignature.String();
  54. }
  55. const char*
  56. ChatProtocolAddOn::FriendlySignature() const
  57. {
  58. return fFriendlySignature.String();
  59. }
  60. BBitmap*
  61. ChatProtocolAddOn::Icon() const
  62. {
  63. return ReadNodeIcon(fPath, B_LARGE_ICON, true);
  64. }
  65. const char*
  66. ChatProtocolAddOn::ProtoSignature() const
  67. {
  68. ChatProtocol* proto = Protocol();
  69. const char* signature = proto->Signature();
  70. delete proto;
  71. return signature;
  72. }
  73. const char*
  74. ChatProtocolAddOn::ProtoFriendlySignature() const
  75. {
  76. ChatProtocol* proto = Protocol();
  77. const char* signature = proto->FriendlySignature();
  78. delete proto;
  79. return signature;
  80. }
  81. BBitmap*
  82. ChatProtocolAddOn::ProtoIcon() const
  83. {
  84. ChatProtocol* proto = Protocol();
  85. BBitmap* icon = proto->Icon();
  86. delete proto;
  87. return icon;
  88. }
  89. uint32
  90. ChatProtocolAddOn::Version() const
  91. {
  92. return fVersion;
  93. }
  94. void
  95. ChatProtocolAddOn::_Init()
  96. {
  97. const char* (*signature)();
  98. const char* (*friendly_signature)();
  99. uint32 (*version)();
  100. fStatus = B_OK;
  101. if (get_image_symbol(fImage, "protocol_at", B_SYMBOL_TYPE_TEXT,
  102. (void**)&fGetProtocol) != B_OK) {
  103. unload_add_on(fImage);
  104. fStatus = B_ERROR;
  105. return;
  106. }
  107. if (get_image_symbol(fImage, "protocol_count", B_SYMBOL_TYPE_TEXT,
  108. (void**)&fCountProtocols) != B_OK) {
  109. unload_add_on(fImage);
  110. fStatus = B_ERROR;
  111. return;
  112. }
  113. if (get_image_symbol(fImage, "signature", B_SYMBOL_TYPE_TEXT,
  114. (void**)&signature) != B_OK) {
  115. unload_add_on(fImage);
  116. fStatus = B_ERROR;
  117. return;
  118. }
  119. if (get_image_symbol(fImage, "friendly_signature", B_SYMBOL_TYPE_TEXT,
  120. (void**)&friendly_signature) != B_OK) {
  121. unload_add_on(fImage);
  122. fStatus = B_ERROR;
  123. return;
  124. }
  125. if (get_image_symbol(fImage, "version", B_SYMBOL_TYPE_TEXT,
  126. (void**)&version) != B_OK) {
  127. unload_add_on(fImage);
  128. fStatus = B_ERROR;
  129. return;
  130. }
  131. fSignature = signature();
  132. fFriendlySignature = friendly_signature();
  133. fVersion = version();
  134. }