purplecompat.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * Copyright (C) 2016-2017 Eion Robb
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <purple.h>
  18. #if PURPLE_VERSION_CHECK(3, 0, 0)
  19. #include <http.h>
  20. #endif
  21. #ifndef PURPLE_PLUGINS
  22. #define PURPLE_PLUGINS
  23. #endif
  24. #ifdef _WIN32
  25. #include <win32/win32dep.h>
  26. #endif
  27. // Purple2 compat functions
  28. #if !PURPLE_VERSION_CHECK(3, 0, 0)
  29. #define purple_connection_error purple_connection_error_reason
  30. #define purple_connection_get_protocol purple_connection_get_prpl
  31. #define PURPLE_CONNECTION_CONNECTING PURPLE_CONNECTING
  32. #define PURPLE_CONNECTION_CONNECTED PURPLE_CONNECTED
  33. #define PURPLE_CONNECTION_FLAG_HTML PURPLE_CONNECTION_HTML
  34. #define PURPLE_CONNECTION_FLAG_NO_BGCOLOR PURPLE_CONNECTION_NO_BGCOLOR
  35. #define PURPLE_CONNECTION_FLAG_NO_FONTSIZE PURPLE_CONNECTION_NO_FONTSIZE
  36. #define PURPLE_CONNECTION_FLAG_NO_IMAGES PURPLE_CONNECTION_NO_IMAGES
  37. #define purple_connection_set_flags(pc, f) ((pc)->flags = (f))
  38. #define purple_connection_get_flags(pc) ((pc)->flags)
  39. #define purple_blist_find_group purple_find_group
  40. #define purple_protocol_action_get_connection(action) ((PurpleConnection *) (action)->context)
  41. #define purple_protocol_action_new purple_plugin_action_new
  42. #define purple_protocol_get_id purple_plugin_get_id
  43. #define PurpleProtocolAction PurplePluginAction
  44. #define PurpleProtocolChatEntry struct proto_chat_entry
  45. #define PurpleChatConversation PurpleConvChat
  46. #define PurpleIMConversation PurpleConvIm
  47. #define purple_conversations_find_chat_with_account(id, account) \
  48. PURPLE_CONV_CHAT(purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, id, account))
  49. #define purple_chat_conversation_has_left purple_conv_chat_has_left
  50. #define PurpleConversationUpdateType PurpleConvUpdateType
  51. #define PURPLE_CONVERSATION_UPDATE_UNSEEN PURPLE_CONV_UPDATE_UNSEEN
  52. #define PURPLE_IS_IM_CONVERSATION(conv) (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM)
  53. #define PURPLE_IS_CHAT_CONVERSATION(conv) (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT)
  54. #define PURPLE_CONVERSATION(chatorim) (chatorim == NULL ? NULL : chatorim->conv)
  55. #define PURPLE_IM_CONVERSATION(conv) PURPLE_CONV_IM(conv)
  56. #define PURPLE_CHAT_CONVERSATION(conv) PURPLE_CONV_CHAT(conv)
  57. #define purple_conversation_present_error purple_conv_present_error
  58. #define purple_serv_got_joined_chat(pc, id, name) PURPLE_CONV_CHAT(serv_got_joined_chat(pc, id, name))
  59. static inline PurpleConvChat *
  60. purple_conversations_find_chat(PurpleConnection *pc, int id)
  61. {
  62. PurpleConversation *conv = purple_find_chat(pc, id);
  63. if (conv != NULL) {
  64. return PURPLE_CONV_CHAT(conv);
  65. }
  66. return NULL;
  67. }
  68. #define purple_serv_got_chat_in serv_got_chat_in
  69. #define purple_chat_conversation_add_user purple_conv_chat_add_user
  70. #define purple_chat_conversation_add_users purple_conv_chat_add_users
  71. #define purple_chat_conversation_remove_user purple_conv_chat_remove_user
  72. #define purple_chat_conversation_clear_users purple_conv_chat_clear_users
  73. #define purple_chat_conversation_has_user purple_conv_chat_find_user
  74. #define purple_chat_conversation_rename_user purple_conv_chat_rename_user
  75. #define purple_chat_conversation_get_topic purple_conv_chat_get_topic
  76. #define purple_chat_conversation_set_topic purple_conv_chat_set_topic
  77. #define PurpleChatUserFlags PurpleConvChatBuddyFlags
  78. #define PURPLE_CHAT_USER_NONE PURPLE_CBFLAGS_NONE
  79. #define PURPLE_CHAT_USER_OP PURPLE_CBFLAGS_OP
  80. #define PURPLE_CHAT_USER_FOUNDER PURPLE_CBFLAGS_FOUNDER
  81. #define PURPLE_CHAT_USER_TYPING PURPLE_CBFLAGS_TYPING
  82. #define PURPLE_CHAT_USER_AWAY PURPLE_CBFLAGS_AWAY
  83. #define PURPLE_CHAT_USER_HALFOP PURPLE_CBFLAGS_HALFOP
  84. #define PURPLE_CHAT_USER_VOICE PURPLE_CBFLAGS_VOICE
  85. #define PURPLE_CHAT_USER_TYPING PURPLE_CBFLAGS_TYPING
  86. #define PurpleChatUser PurpleConvChatBuddy
  87. static inline PurpleChatUser *
  88. purple_chat_conversation_find_user(PurpleChatConversation *chat, const char *name)
  89. {
  90. PurpleChatUser *cb = purple_conv_chat_cb_find(chat, name);
  91. if (cb != NULL) {
  92. g_dataset_set_data(cb, "chat", chat);
  93. }
  94. return cb;
  95. }
  96. #define purple_chat_user_get_flags(cb) purple_conv_chat_user_get_flags(g_dataset_get_data((cb), "chat"), (cb)->name)
  97. #define purple_chat_user_set_flags(cb, f) purple_conv_chat_user_set_flags(g_dataset_get_data((cb), "chat"), (cb)->name, (f))
  98. #define purple_chat_user_set_alias(cb, a) (g_free((cb)->alias), (cb)->alias = g_strdup(a))
  99. #define PurpleIMTypingState PurpleTypingState
  100. #define PURPLE_IM_NOT_TYPING PURPLE_NOT_TYPING
  101. #define PURPLE_IM_TYPING PURPLE_TYPING
  102. #define PURPLE_IM_TYPED PURPLE_TYPED
  103. #define purple_conversation_get_connection purple_conversation_get_gc
  104. #define purple_conversation_write_system_message(conv, message, flags) purple_conversation_write((conv), NULL, (message), ((flags) | PURPLE_MESSAGE_SYSTEM), time(NULL))
  105. #define purple_chat_conversation_get_id purple_conv_chat_get_id
  106. #define PURPLE_CMD_FLAG_PROTOCOL_ONLY PURPLE_CMD_FLAG_PRPL_ONLY
  107. #define PURPLE_IS_BUDDY PURPLE_BLIST_NODE_IS_BUDDY
  108. #define PURPLE_IS_CHAT PURPLE_BLIST_NODE_IS_CHAT
  109. #define purple_chat_get_name_only purple_chat_get_name
  110. #define purple_blist_find_buddy purple_find_buddy
  111. #define purple_serv_got_alias serv_got_alias
  112. #define purple_account_set_private_alias purple_account_set_alias
  113. #define purple_account_get_private_alias purple_account_get_alias
  114. #define purple_protocol_got_user_status purple_prpl_got_user_status
  115. #define purple_protocol_got_user_idle purple_prpl_got_user_idle
  116. #define purple_serv_got_im serv_got_im
  117. #define purple_serv_got_typing serv_got_typing
  118. #define purple_conversations_find_im_with_account(name, account) \
  119. PURPLE_CONV_IM(purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, name, account))
  120. #define purple_im_conversation_new(account, from) PURPLE_CONV_IM(purple_conversation_new(PURPLE_CONV_TYPE_IM, account, from))
  121. #define PurpleMessage PurpleConvMessage
  122. #define purple_message_set_time(msg, time) ((msg)->when = (time))
  123. #define purple_conversation_write_message(conv, msg) purple_conversation_write(conv, msg->who, msg->what, msg->flags, msg->when)
  124. static inline PurpleMessage *
  125. purple_message_new_outgoing(const gchar *who, const gchar *contents, PurpleMessageFlags flags)
  126. {
  127. PurpleMessage *message = g_new0(PurpleMessage, 1);
  128. message->who = g_strdup(who);
  129. message->what = g_strdup(contents);
  130. message->flags = flags;
  131. message->when = time(NULL);
  132. return message;
  133. }
  134. static inline void
  135. purple_message_destroy(PurpleMessage *message)
  136. {
  137. g_free(message->who);
  138. g_free(message->what);
  139. g_free(message);
  140. }
  141. #define purple_message_get_recipient(message) (message->who)
  142. #define purple_message_get_contents(message) (message->what)
  143. #if !PURPLE_VERSION_CHECK(2, 12, 0)
  144. #define PURPLE_MESSAGE_REMOTE_SEND 0x10000
  145. #endif
  146. #define purple_account_privacy_deny_add purple_privacy_deny_add
  147. #define purple_account_privacy_deny_remove purple_privacy_deny_remove
  148. #define PurpleHttpConnection PurpleUtilFetchUrlData
  149. #define purple_buddy_set_name purple_blist_rename_buddy
  150. #define purple_request_cpar_from_connection(a) purple_connection_get_account(a), NULL, NULL
  151. #define purple_notify_user_info_add_pair_html purple_notify_user_info_add_pair
  152. #ifdef purple_notify_error
  153. #undef purple_notify_error
  154. #endif
  155. #define purple_notify_error(handle, title, primary, secondary, cpar) \
  156. purple_notify_message((handle), PURPLE_NOTIFY_MSG_ERROR, (title), \
  157. (primary), (secondary), NULL, NULL)
  158. // Kinda gross, since we can technically use the glib mainloop from purple2
  159. #define g_timeout_add_seconds purple_timeout_add_seconds
  160. #define g_timeout_add purple_timeout_add
  161. #define g_source_remove purple_timeout_remove
  162. #define PURPLE_CONNECTION_DISCONNECTED PURPLE_DISCONNECTED
  163. #define PURPLE_CONNECTION_DISCONNECTING 4
  164. #define PURPLE_CONNECTION_CONNECTING PURPLE_CONNECTING
  165. #define PURPLE_CONNECTION_CONNECTED PURPLE_CONNECTED
  166. #define PURPLE_CONNECTION_FLAG_HTML PURPLE_CONNECTION_HTML
  167. #define PURPLE_CONNECTION_FLAG_NO_BGCOLOR PURPLE_CONNECTION_NO_BGCOLOR
  168. #define PURPLE_CONNECTION_FLAG_NO_FONTSIZE PURPLE_CONNECTION_NO_FONTSIZE
  169. #define PURPLE_CONNECTION_FLAG_NO_IMAGES PURPLE_CONNECTION_NO_IMAGES
  170. #define purple_connection_is_disconnecting(c) (purple_connection_get_state(c) == PURPLE_DISCONNECTED || purple_connection_get_state(c) == PURPLE_CONNECTION_DISCONNECTING)
  171. #else
  172. // Purple3 helper functions
  173. #define purple_conversation_set_data(conv, key, value) g_object_set_data(G_OBJECT(conv), key, value)
  174. #define purple_conversation_get_data(conv, key) g_object_get_data(G_OBJECT(conv), key)
  175. #define purple_message_destroy g_object_unref
  176. #define purple_chat_user_set_alias(cb, alias) g_object_set((cb), "alias", (alias), NULL)
  177. #define purple_chat_get_alias(chat) g_object_get_data(G_OBJECT(chat), "alias")
  178. #define purple_protocol_action_get_connection(action) ((action)->connection)
  179. #define PURPLE_TYPE_STRING G_TYPE_STRING
  180. //TODO remove this when dx adds this to the PurpleMessageFlags enum
  181. #define PURPLE_MESSAGE_REMOTE_SEND 0x10000
  182. #endif