diff --git a/delta-connection.c b/delta-connection.c new file mode 100644 index 0000000..605b1fe --- /dev/null +++ b/delta-connection.c @@ -0,0 +1,31 @@ +#include + +#include "delta-connection.h" + +void delta_connection_new(PurpleConnection *pc) +{ + DeltaConnectionData *conn; + + g_assert(purple_connection_get_protocol_data(pc) == NULL); + + conn = g_new0(DeltaConnectionData, 1); + conn->pc = pc; + + purple_connection_set_protocol_data(pc, conn); +} + + +void delta_connection_free(PurpleConnection *pc) +{ + DeltaConnectionData *conn = purple_connection_get_protocol_data(pc); + + g_assert(conn != NULL); + + purple_connection_set_protocol_data(pc, NULL); + + // TODO: free resources as they are added to DeltaConnectionData + + conn->pc = NULL; + + g_free(conn); +} diff --git a/delta-connection.h b/delta-connection.h new file mode 100644 index 0000000..b5f2d5b --- /dev/null +++ b/delta-connection.h @@ -0,0 +1,16 @@ +#ifndef DELTA_CONNECTION_H +#define DELTA_CONNECTION_H + +#include + +struct _PurpleConnection; + +typedef struct _DeltaConnectionData { + struct _PurpleConnection *pc; +} DeltaConnectionData; + +void delta_connection_new(struct _PurpleConnection *pc); +void delta_connection_free(struct _PurpleConnection *pc); + +#endif + diff --git a/libdelta.c b/libdelta.c index 2d8ac05..fff4ef7 100644 --- a/libdelta.c +++ b/libdelta.c @@ -6,12 +6,15 @@ // All from libpurple #include +#include #include #include #include #include #include +#include "delta-connection.h" + #define UNUSED(x) (void)(x) static void @@ -20,16 +23,38 @@ debug(const char *str) purple_debug_info(PLUGIN_ID, str); } -static void -delta_login() +static GList * +delta_status_types(PurpleAccount *acct) { + UNUSED(acct); + GList *types = NULL; + + types = g_list_append(types, purple_status_type_new(PURPLE_STATUS_OFFLINE, "Offline", NULL, TRUE)); + types = g_list_append(types, purple_status_type_new(PURPLE_STATUS_AVAILABLE, "Online", NULL, TRUE)); + + return types; } static void -delta_close() +delta_login(PurpleAccount *acct) { + PurpleConnection *pc = purple_account_get_connection(acct); + delta_connection_new(pc); + + purple_connection_set_state(pc, PURPLE_CONNECTING); + // TODO: attempt to connect! + + pc->flags |= PURPLE_CONNECTION_HTML; +} + +static void +delta_close(PurpleConnection *pc) +{ + // TODO: actually disconnect! + purple_connection_set_state(pc, PURPLE_DISCONNECTED); + delta_connection_free(pc); } // Below the fold is libpurple plumbing. No, I don't understand it either @@ -119,7 +144,7 @@ static PurplePluginProtocolInfo extra_info = NULL, /* list_emblem */ NULL, /* status_text */ NULL, /* tooltip_text */ - NULL, /* status_types */ + delta_status_types, /* status_types */ NULL, /* blist_node_menu */ NULL, /* chat_info */ NULL, /* chat_info_defaults */