/* * Copyright 2021, Jaidyn Levesque * Copyright 1998-2021, Pidgin/Finch/libpurple contributors * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ #ifndef _PURPLE_APP_H #define _PURPLE_APP_H #include #include #include #include #include #include #include typedef KeyMap StringMap; typedef KeyMap ThreadMap; typedef KeyMap HashMap; const uint32 G_MAIN_LOOP = 'GLml'; const uint32 CHECK_APP = 'Paca'; #define PURPLE_GLIB_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR) #define PURPLE_GLIB_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL) #define PURPLE_UI_ID "cardie" typedef struct _PurpleGLibIOClosure { PurpleInputFunction function; guint result; gpointer data; } PurpleGLibIOClosure; struct _PurpleStatus { PurpleStatusType *type; PurplePresence *presence; gboolean active; GHashTable *attr_values; }; typedef struct _ProtocolInfo { BString name; BString id; BMessage accountTemplate; BMessage roomTemplate; BString iconName; } ProtocolInfo; int main(int argc, char** argv); class PurpleApp : public BApplication { public: PurpleApp(); virtual void MessageReceived(BMessage* msg); void ImMessage(BMessage* msg); void SendMessage(thread_id thread, BMessage msg); void SendMessage(PurpleAccount* account, BMessage msg); HashMap fInviteList; StringMap fUserNicks; // Purple username → Nickname for Cardie private: void _SendSysText(PurpleConversation* conv, const char* text); void _GetProtocolsInfo(); void _SaveProtocolInfo(PurplePlugin* plugin); BMessage _GetAccountTemplate(PurplePluginProtocolInfo* info); BMessage _GetRoomTemplate(PurplePluginProtocolInfo* info); BMessage _GetCommands(PurpleAccount* account); void _ParseAccountTemplate(BMessage* settings); GHashTable* _ParseRoomTemplate(BMessage* msg); PurplePlugin* _PluginFromMessage(BMessage* msg); PurpleConnection* _ConnectionFromMessage(BMessage* msg); PurpleAccount* _AccountFromMessage(BMessage* msg); PurpleConversation* _ConversationFromMessage(BMessage* msg); StringMap fAccounts; // Cardie account name → Purple username ThreadMap fAccountThreads; // Cardie account name → Thread BObjectList fProtocols; GMainLoop* fGloop; }; status_t init_libpurple(); void init_ui_ops(); void init_signals(); // Connection signals static void signal_connection_error(PurpleConnection* gc, PurpleConnectionError err, const gchar* desc); // Account signals static void signal_account_signed_on(PurpleAccount* account); static void signal_account_signed_off(PurpleAccount* account); static void signal_account_disabled(PurpleAccount* account); static void signal_account_error_changed(PurpleAccount* account, const PurpleConnectionErrorInfo* old_error, const PurpleConnectionErrorInfo* current_error); static void signal_account_status_changed(PurpleAccount* account, PurpleStatus* old, PurpleStatus* cur); // Buddy-list signals static void signal_blist_node_added(PurpleBlistNode* node); static void signal_blist_node_removed(PurpleBlistNode* node); static void signal_buddy_status_changed(PurpleBuddy* buddy, PurpleStatus* old_status, PurpleStatus* status); // Conversation signals static void signal_chat_joined(PurpleConversation* conv); static void signal_chat_left(PurpleConversation* conv); static void signal_received_chat_msg(PurpleAccount* account, char* sender, char* message, PurpleConversation* conv, PurpleMessageFlags flags); static void signal_sent_chat_msg(PurpleAccount* account, const char* message, int conv_id); static void signal_sent_im_msg(PurpleAccount* account, const char* receiver, const char* message); static void signal_chat_buddy_joined(PurpleConversation* conv, const char* name, PurpleConvChatBuddyFlags flags, gboolean new_arrival); static void signal_chat_buddy_left(PurpleConversation* conv, const char* name, const char* reason); static void signal_chat_invited(PurpleAccount* account, const char* inviter, const char* chat, const char* message, const GHashTable* components); static void signal_chat_buddy_flags(PurpleConversation* conv, const char* name, PurpleConvChatBuddyFlags oldflags, PurpleConvChatBuddyFlags newflags); // EventLoop ui ops static guint ui_op_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function, gpointer data); // Request ui ops static void* ui_op_request_input(const char* title, const char* primary, const char* secondary, const char* default_value, gboolean multiline, gboolean masked, gchar* hint, const char* ok_text, GCallback ok_cb, const char* cancel_text, GCallback cancel_cb, PurpleAccount* account, const char* who, PurpleConversation* conv, void* user_data); static void* ui_op_request_choice(const char* title, const char* primary, const char* secondary, int default_value, const char* ok_text, GCallback ok_cb, const char* cancel_text, GCallback cancel_cb, PurpleAccount* account, const char* who, PurpleConversation* conv, void* user_data, va_list choices); static void* ui_op_request_action(const char* title, const char* primary, const char* secondary, int default_action, PurpleAccount* account, const char* who, PurpleConversation* conv, void* user_data, size_t action_count, va_list actions); static void* ui_op_request_fields(const char* title, const char* primary, const char* secondary, PurpleRequestFields* fields, const char* ok_text, GCallback ok_cb, const char* cancel_text, GCallback cancel_cb, PurpleAccount* account, const char* who, PurpleConversation* conv, void* user_data); static void* ui_op_request_file(const char* title, const char* filename, gboolean savedialog, GCallback ok_cb, GCallback cancel_cb, PurpleAccount* account, const char* who, PurpleConversation* conv, void* user_data); static void* ui_op_request_folder(const char* title, const char* dirname, GCallback ok_cb, GCallback cancel_cb, PurpleAccount* account, const char* who, PurpleConversation* conv, void* user_data); static void* ui_op_request_action_with_icon(const char* title, const char* primary, const char* secondary, int default_action, PurpleAccount* account, const char* who, PurpleConversation* conv, gconstpointer icon_data, gsize icon_size, void* user_data, size_t action_count, va_list actions); // Notify ui ops static void* ui_op_notify_message(PurpleNotifyMsgType type, const char* title, const char* primary, const char* secondary); // Util bool is_own_user(PurpleAccount* account, const char* name); void send_own_info(PurpleAccount* account); void send_user_role(PurpleConversation* conv, const char* name, PurpleConvChatBuddyFlags flags); PurpleStatusPrimitive cardie_status_to_purple(UserStatus status); UserStatus purple_status_to_cardie(PurpleStatus* status); const char* purple_connection_error_name( const PurpleConnectionErrorInfo* error); const char* purple_cache(); void purple_plugins_add_finddir(directory_which finddir); static gboolean _purple_glib_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data); #endif // _PURPLE_APP_H