purplesatori.c

Sun, 10 Aug 2025 23:53:22 +0800

author
Gong Zhile <gongzl@stu.hebust.edu.cn>
date
Sun, 10 Aug 2025 23:53:22 +0800
changeset 3
33a7b189a2c6
parent 0
cc7c1f9d20f7
permissions
-rw-r--r--

Various improvement, Support configuration from UI

/*
 * Purple Satori Plugin - Satori Protocol Plugin for Purple3
 * Copyright (C) 2025 Gong Zhile
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
 */

#include <glib.h>
#include <glib/gi18n-lib.h>

#include <gplugin.h>
#include <gplugin-native.h>

#include <purple.h>

#include "purplesatoriconnection.h"
#include "purplesatoriplugin.h"
#include "purplesatoriprotocol.h"

/******************************************************************************
 * Globals
 *****************************************************************************/
static PurpleProtocol *satori_protocol = NULL;

/******************************************************************************
 * GPlugin Implementation
 *****************************************************************************/
static GPluginPluginInfo *
purple_satori_plugin_query(G_GNUC_UNUSED GError **error) {
	const gchar *authors[] = {
		"Gong Zhile <gongzl@stu.hebust.edu.cn>",
		NULL
	};

	return purple_plugin_info_new(
		"id", "prpl-satori",
		"name", "Satori Protocol Plugin",
		"authors", authors,
		"version", "0.0.1",
		"category", N_("Protocol"),
		"summary", N_("Satori protocol plugin for purple3"),
		"description", N_("Satori protocol plugin for purple3"),
		"website", "https://example.org/",
		"abi-version", PURPLE_ABI_VERSION,
		NULL
        );		
}

static gboolean
purple_satori_plugin_load(GPluginPlugin *plugin, GError **error) {
	PurpleProtocolManager *manager = NULL;

	if(PURPLE_IS_PROTOCOL(satori_protocol)) {
		g_set_error_literal(error, PURPLE_SATORI_DOMAIN, 0,
		                    "plugin was not cleaned up properly");

		return FALSE;
	}

	purple_satori_connection_register(GPLUGIN_NATIVE_PLUGIN(plugin));
	purple_satori_protocol_register(GPLUGIN_NATIVE_PLUGIN(plugin));

	manager = purple_protocol_manager_get_default();

	satori_protocol = purple_satori_protocol_new();
	if (!purple_protocol_manager_add(manager, satori_protocol, error)) {
		g_clear_object(&satori_protocol);
		return FALSE;
	}

	return TRUE;
}

static gboolean
purple_satori_plugin_unload(G_GNUC_UNUSED GPluginPlugin *plugin,
			   G_GNUC_UNUSED gboolean shutdown,
			   GError **error)
{
	PurpleProtocolManager *manager = purple_protocol_manager_get_default();

	if (!PURPLE_IS_PROTOCOL(satori_protocol)) {
		g_set_error_literal(error, PURPLE_SATORI_DOMAIN, 0,
				    "plugin was not setup properly");
		return FALSE;
	}

	if (!purple_protocol_manager_remove(manager, satori_protocol, error)) {
		return FALSE;
	}

	g_clear_object(&satori_protocol);
	return TRUE;
}

GPLUGIN_NATIVE_PLUGIN_DECLARE(purple_satori_plugin)

mercurial