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-06-27 16:46:38 -05:00
|
|
|
typedef KeyMap<BString, BString> Accounts; // Cardie username → Purple username
|
|
|
|
typedef KeyMap<BString, thread_id> AccountThreads; // Purple username → Thread
|
2021-07-01 19:49:39 -05:00
|
|
|
typedef KeyMap<BString, GHashTable*> GHashList;
|
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-06-24 12:22:34 -05:00
|
|
|
BMessage settingsTemplate;
|
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-01 19:49:39 -05:00
|
|
|
GHashList fInviteList;
|
|
|
|
|
2021-06-23 23:57:27 -05:00
|
|
|
private:
|
|
|
|
void _GetProtocolsInfo();
|
2021-06-24 12:22:34 -05:00
|
|
|
void _SaveProtocolInfo(PurplePlugin* plugin);
|
2021-06-26 20:40:39 -05:00
|
|
|
|
2021-06-24 12:22:34 -05:00
|
|
|
BMessage _ParseProtoOptions(PurplePluginProtocolInfo* info);
|
2021-06-26 20:40:39 -05:00
|
|
|
void _ParseCardieSettings(BMessage* settings);
|
|
|
|
|
|
|
|
PurplePlugin* _PluginFromMessage(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-06-26 20:40:39 -05:00
|
|
|
Accounts fAccounts;
|
2021-06-27 16:46:38 -05:00
|
|
|
AccountThreads fAccountThreads;
|
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-06-28 12:13:24 -05:00
|
|
|
|
|
|
|
// Util
|
|
|
|
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 guint _purple_glib_input_add(gint fd,
|
|
|
|
PurpleInputCondition condition,
|
|
|
|
PurpleInputFunction function, gpointer data);
|
|
|
|
static gboolean _purple_glib_io_invoke(GIOChannel *source,
|
|
|
|
GIOCondition condition, gpointer data);
|
2021-06-23 23:57:27 -05:00
|
|
|
|
|
|
|
#endif // _PURPLE_APP_H
|