libpurple/purpleprotocolcontacts.c

Thu, 07 Aug 2025 21:40:13 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Thu, 07 Aug 2025 21:40:13 -0500
changeset 43302
e7b0bbfec5d5
parent 43296
5eab84f697de
permissions
-rw-r--r--

Add an avatar-for-display property to Purple.ContactInfo

Testing Done:
Ran the tests under valgrind and called in the turtles.

Reviewed at https://reviews.imfreedom.org/r/4086/

/*
 * Purple - Internet Messaging Library
 * Copyright (C) Pidgin Developers <devel@pidgin.im>
 *
 * Purple is the legal property of its developers, whose names are too numerous
 * to list here. Please refer to the COPYRIGHT file distributed with this
 * source distribution.
 *
 * This library 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 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 General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this library; if not, see <https://www.gnu.org/licenses/>.
 */

#include "purpleprotocolcontacts.h"

#include "util.h"

/******************************************************************************
 * GInterface Implementation
 *****************************************************************************/
G_DEFINE_INTERFACE(PurpleProtocolContacts, purple_protocol_contacts,
                   PURPLE_TYPE_PROTOCOL)

static void
purple_protocol_contacts_default_init(G_GNUC_UNUSED PurpleProtocolContactsInterface *iface)
{
}

/******************************************************************************
 * Public API
 *****************************************************************************/
void
purple_protocol_contacts_get_profile_async(PurpleProtocolContacts *protocol_contacts,
                                           PurpleContactInfo *info,
                                           GCancellable *cancellable,
                                           GAsyncReadyCallback callback,
                                           gpointer data)
{
	PurpleProtocolContactsInterface *iface = NULL;

	g_return_if_fail(PURPLE_IS_PROTOCOL_CONTACTS(protocol_contacts));
	g_return_if_fail(PURPLE_IS_CONTACT_INFO(info));

	iface = PURPLE_PROTOCOL_CONTACTS_GET_IFACE(protocol_contacts);
	if(iface != NULL && iface->get_profile_async != NULL) {
		iface->get_profile_async(protocol_contacts, info, cancellable,
		                         callback, data);
	} else {
		g_task_report_new_error(G_OBJECT(protocol_contacts), callback, data,
		                        purple_protocol_contacts_get_profile_async,
		                        PURPLE_PROTOCOL_CONTACTS_DOMAIN, 0,
		                        "%s does not implement get_profile_async",
		                        G_OBJECT_TYPE_NAME(protocol_contacts));
	}
}

char *
purple_protocol_contacts_get_profile_finish(PurpleProtocolContacts *protocol_contacts,
                                            GAsyncResult *result,
                                            GError **error)
{
	PurpleProtocolContactsInterface *iface = NULL;

	g_return_val_if_fail(PURPLE_IS_PROTOCOL_CONTACTS(protocol_contacts), NULL);
	g_return_val_if_fail(G_IS_ASYNC_RESULT(result), NULL);

	if(g_async_result_is_tagged(result,
	                            purple_protocol_contacts_get_profile_async))
	{
		return g_task_propagate_pointer(G_TASK(result), error);
	}

	iface = PURPLE_PROTOCOL_CONTACTS_GET_IFACE(protocol_contacts);
	if(iface != NULL && iface->get_profile_finish != NULL) {
		return iface->get_profile_finish(protocol_contacts, result, error);
	}

	g_warning("purple_protocol_contacts_get_profile_finish without calling "
	          "purple_protocol_contacts_get_profile_async");

	return NULL;
}

GActionGroup *
purple_protocol_contacts_get_actions(PurpleProtocolContacts *protocol_contacts,
                                     PurpleContactInfo *info)
{
	PurpleProtocolContactsInterface *iface = NULL;

	g_return_val_if_fail(PURPLE_IS_PROTOCOL_CONTACTS(protocol_contacts), NULL);
	g_return_val_if_fail(PURPLE_IS_CONTACT_INFO(info), NULL);

	iface = PURPLE_PROTOCOL_CONTACTS_GET_IFACE(protocol_contacts);
	if(iface != NULL && iface->get_actions != NULL) {
		return iface->get_actions(protocol_contacts, info);
	}

	return NULL;
}

GMenuModel *
purple_protocol_contacts_get_menu(PurpleProtocolContacts *protocol_contacts,
                                  PurpleContactInfo *info)
{
	PurpleProtocolContactsInterface *iface = NULL;

	g_return_val_if_fail(PURPLE_IS_PROTOCOL_CONTACTS(protocol_contacts), NULL);
	g_return_val_if_fail(PURPLE_IS_CONTACT_INFO(info), NULL);

	iface = PURPLE_PROTOCOL_CONTACTS_GET_IFACE(protocol_contacts);
	if(iface != NULL && iface->get_menu != NULL) {
		return iface->get_menu(protocol_contacts, info);
	}

	return NULL;
}

mercurial