2021-06-23 23:57:27 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
|
|
|
|
* 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
|
2021-06-24 12:22:34 -05:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301, USA.
|
2021-06-23 23:57:27 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _PURPLE_APP_H
|
|
|
|
#define _PURPLE_APP_H
|
|
|
|
|
|
|
|
#include <libpurple/purple.h>
|
|
|
|
|
|
|
|
#include <Application.h>
|
Reorganize settings directory, custom purple paths
The settings file-hierarchy has been changed a bit:
* Cardie/
* preferences
* Accounts/
* Cache/
* Accounts/
* Add-Ons/
`Cardie/Protocols` is now `Cardie/Accounts`, and the cache directory
has been split into two. `Cache/Accounts/` is for account-specific
cached data (e.g., cached roster icons, data, etc.), and
`Cache/Protocols` is for protocol-wide settings/data.
For purple, this will be used as the user's libpurple directory,
which has been moved from the default of `~/.purple` (yikes!)
Some plugin search-paths have been given to purple, too― lib
directories + "/purple2/", and Cardie/Cache/Add-Ons/purple/plugins/.
2021-06-30 20:29:30 -05:00
|
|
|
#include <FindDirectory.h>
|
2021-06-23 23:57:27 -05:00
|
|
|
#include <ObjectList.h>
|
|
|
|
#include <StringList.h>
|
|
|
|
|
2021-06-26 20:40:39 -05:00
|
|
|
#include <libsupport/KeyMap.h>
|
2021-06-27 20:42:37 -05:00
|
|
|
#include <AppConstants.h>
|
2021-06-26 20:40:39 -05:00
|
|
|
|
2021-06-23 23:57:27 -05:00
|
|
|
|
2021-07-07 20:44:11 -05:00
|
|
|
typedef KeyMap<BString, BString> StringMap;
|
|
|
|
typedef KeyMap<BString, thread_id> ThreadMap;
|
|
|
|
typedef KeyMap<BString, GHashTable*> HashMap;
|
2021-06-23 23:57:27 -05:00
|
|
|
|
2021-06-27 16:46:38 -05:00
|
|
|
const uint32 G_MAIN_LOOP = 'GLml';
|
2021-06-27 17:33:09 -05:00
|
|
|
const uint32 CHECK_APP = 'Paca';
|
2021-06-26 20:40:39 -05:00
|
|
|
|
|
|
|
|
2021-06-23 23:57:27 -05:00
|
|
|
#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)
|
2021-06-27 16:46:38 -05:00
|
|
|
#define PURPLE_UI_ID "cardie"
|
2021-06-23 23:57:27 -05:00
|
|
|
|
|
|
|
|
|
|
|
typedef struct _PurpleGLibIOClosure {
|
|
|
|
PurpleInputFunction function;
|
|
|
|
guint result;
|
|
|
|
gpointer data;
|
|
|
|
} PurpleGLibIOClosure;
|
|
|
|
|
2021-06-27 20:42:37 -05:00
|
|
|
struct _PurpleStatus
|
|
|
|
{
|
|
|
|
PurpleStatusType *type;
|
|
|
|
PurplePresence *presence;
|
|
|
|
|
|
|
|
gboolean active;
|
|
|
|
GHashTable *attr_values;
|
|
|
|
};
|
|
|
|
|
2021-06-23 23:57:27 -05:00
|
|
|
typedef struct _ProtocolInfo {
|
|
|
|
BString name;
|
|
|
|
BString id;
|
2021-07-04 11:31:32 -05:00
|
|
|
BMessage accountTemplate;
|
|
|
|
BMessage roomTemplate;
|
2021-07-07 15:02:59 -05:00
|
|
|
BString iconName;
|
2021-06-23 23:57:27 -05:00
|
|
|
} ProtocolInfo;
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv);
|
|
|
|
|
|
|
|
|
|
|
|
class PurpleApp : public BApplication {
|
|
|
|
public:
|
|
|
|
PurpleApp();
|
2021-06-27 17:33:09 -05:00
|
|
|
|
2021-06-23 23:57:27 -05:00
|
|
|
virtual void MessageReceived(BMessage* msg);
|
2021-06-27 20:42:37 -05:00
|
|
|
void ImMessage(BMessage* msg);
|
|
|
|
|
2021-06-27 16:46:38 -05:00
|
|
|
void SendMessage(thread_id thread, BMessage msg);
|
|
|
|
void SendMessage(PurpleAccount* account, BMessage msg);
|
2021-06-23 23:57:27 -05:00
|
|
|
|
2021-07-07 20:44:11 -05:00
|
|
|
HashMap fInviteList;
|
|
|
|
StringMap fUserNicks; // Purple username → Nickname for Cardie
|
2021-07-01 19:49:39 -05:00
|
|
|
|
2021-06-23 23:57:27 -05:00
|
|
|
private:
|
2021-07-06 14:13:10 -05:00
|
|
|
void _SendSysText(PurpleConversation* conv, const char* text);
|
|
|
|
|
2021-06-23 23:57:27 -05:00
|
|
|
void _GetProtocolsInfo();
|
2021-06-24 12:22:34 -05:00
|
|
|
void _SaveProtocolInfo(PurplePlugin* plugin);
|
2021-06-26 20:40:39 -05:00
|
|
|
|
2021-07-04 11:31:32 -05:00
|
|
|
BMessage _GetAccountTemplate(PurplePluginProtocolInfo* info);
|
|
|
|
BMessage _GetRoomTemplate(PurplePluginProtocolInfo* info);
|
2021-07-05 23:56:59 -05:00
|
|
|
BMessage _GetCommands(PurpleAccount* account);
|
2021-07-04 11:31:32 -05:00
|
|
|
|
|
|
|
void _ParseAccountTemplate(BMessage* settings);
|
2021-07-05 12:42:20 -05:00
|
|
|
GHashTable* _ParseRoomTemplate(BMessage* msg);
|
2021-06-26 20:40:39 -05:00
|
|
|
|
|
|
|
PurplePlugin* _PluginFromMessage(BMessage* msg);
|
2021-07-05 12:42:20 -05:00
|
|
|
PurpleConnection* _ConnectionFromMessage(BMessage* msg);
|
2021-06-27 16:46:38 -05:00
|
|
|
PurpleAccount* _AccountFromMessage(BMessage* msg);
|
2021-06-28 12:51:50 -05:00
|
|
|
PurpleConversation* _ConversationFromMessage(BMessage* msg);
|
2021-06-23 23:57:27 -05:00
|
|
|
|
2021-07-07 20:44:11 -05:00
|
|
|
StringMap fAccounts; // Cardie account name → Purple username
|
|
|
|
ThreadMap fAccountThreads; // Cardie account name → Thread
|
2021-06-23 23:57:27 -05:00
|
|
|
BObjectList<ProtocolInfo> fProtocols;
|
2021-06-27 16:46:38 -05:00
|
|
|
|
|
|
|
GMainLoop* fGloop;
|
2021-06-23 23:57:27 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-06-28 12:13:24 -05:00
|
|
|
status_t init_libpurple();
|
|
|
|
void init_ui_ops();
|
|
|
|
void init_signals();
|
2021-06-27 16:46:38 -05:00
|
|
|
|
|
|
|
// Connection signals
|
2021-06-28 12:13:24 -05:00
|
|
|
static void signal_connection_error(PurpleConnection* gc,
|
|
|
|
PurpleConnectionError err, const gchar* desc);
|
2021-06-23 23:57:27 -05:00
|
|
|
|
2021-06-27 20:42:37 -05:00
|
|
|
// Account signals
|
2021-06-28 12:13:24 -05:00
|
|
|
static void signal_account_signed_on(PurpleAccount* account);
|
|
|
|
static void signal_account_status_changed(PurpleAccount* account,
|
|
|
|
PurpleStatus* old, PurpleStatus* cur);
|
|
|
|
|
2021-07-01 18:34:56 -05:00
|
|
|
// Buddy-list signals
|
|
|
|
static void signal_blist_node_added(PurpleBlistNode* node);
|
|
|
|
static void signal_blist_node_removed(PurpleBlistNode* node);
|
|
|
|
|
2021-06-28 12:13:24 -05:00
|
|
|
// 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);
|
2021-06-28 12:51:50 -05:00
|
|
|
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);
|
2021-06-29 15:20:27 -05:00
|
|
|
static void signal_chat_buddy_joined(PurpleConversation* conv,
|
|
|
|
const char* name, PurpleConvChatBuddyFlags flags,
|
|
|
|
gboolean new_arrival);
|
2021-07-01 19:49:39 -05:00
|
|
|
static void signal_chat_invited(PurpleAccount* account,
|
|
|
|
const char* inviter, const char* chat,
|
|
|
|
const char* message, const GHashTable* components);
|
2021-07-06 12:08:51 -05:00
|
|
|
static void signal_chat_buddy_flags(PurpleConversation* conv,
|
|
|
|
const char* name, PurpleConvChatBuddyFlags oldflags,
|
|
|
|
PurpleConvChatBuddyFlags newflags);
|
2021-06-28 12:13:24 -05:00
|
|
|
|
2021-07-06 00:56:16 -05:00
|
|
|
// EventLoop ui ops
|
|
|
|
static guint ui_op_input_add(gint fd,
|
|
|
|
PurpleInputCondition condition,
|
|
|
|
PurpleInputFunction function, gpointer data);
|
|
|
|
|
2021-06-28 12:13:24 -05:00
|
|
|
// Util
|
2021-07-07 20:44:11 -05:00
|
|
|
bool is_own_user(PurpleAccount* account, const char* name);
|
|
|
|
|
|
|
|
void send_own_info(PurpleAccount* account);
|
2021-07-06 12:08:51 -05:00
|
|
|
void send_user_role(PurpleConversation* conv,
|
|
|
|
const char* name, PurpleConvChatBuddyFlags flags);
|
2021-07-07 20:44:11 -05:00
|
|
|
|
2021-06-28 12:13:24 -05:00
|
|
|
PurpleStatusPrimitive cardie_status_to_purple(UserStatus status);
|
|
|
|
UserStatus purple_status_to_cardie(PurpleStatus* status);
|
|
|
|
|
Reorganize settings directory, custom purple paths
The settings file-hierarchy has been changed a bit:
* Cardie/
* preferences
* Accounts/
* Cache/
* Accounts/
* Add-Ons/
`Cardie/Protocols` is now `Cardie/Accounts`, and the cache directory
has been split into two. `Cache/Accounts/` is for account-specific
cached data (e.g., cached roster icons, data, etc.), and
`Cache/Protocols` is for protocol-wide settings/data.
For purple, this will be used as the user's libpurple directory,
which has been moved from the default of `~/.purple` (yikes!)
Some plugin search-paths have been given to purple, too― lib
directories + "/purple2/", and Cardie/Cache/Add-Ons/purple/plugins/.
2021-06-30 20:29:30 -05:00
|
|
|
const char* purple_cache();
|
|
|
|
void purple_plugins_add_finddir(directory_which finddir);
|
|
|
|
|
2021-06-28 12:13:24 -05:00
|
|
|
static gboolean _purple_glib_io_invoke(GIOChannel *source,
|
|
|
|
GIOCondition condition, gpointer data);
|
2021-06-23 23:57:27 -05:00
|
|
|
|
|
|
|
#endif // _PURPLE_APP_H
|