--- a/libpurple/purpleprotocolcontacts.c Mon May 13 23:28:20 2024 -0500
+++ b/libpurple/purpleprotocolcontacts.c Thu May 16 21:33:15 2024 -0500
@@ -25,6 +25,15 @@
/******************************************************************************
+ * Default Implementations + *****************************************************************************/ +purple_protocol_contacts_default_get_minimum_search_length(G_GNUC_UNUSED PurpleProtocolContacts *protocol_contacts) +/****************************************************************************** * GInterface Implementation
*****************************************************************************/
G_DEFINE_INTERFACE(PurpleProtocolContacts, purple_protocol_contacts,
@@ -33,11 +42,52 @@
purple_protocol_contacts_default_init(G_GNUC_UNUSED PurpleProtocolContactsInterface *iface)
+ iface->get_minimum_search_length = purple_protocol_contacts_default_get_minimum_search_length; /******************************************************************************
*****************************************************************************/
+purple_protocol_contacts_implements_search(PurpleProtocolContacts *protocol_contacts) + PurpleProtocolContactsInterface *iface = NULL; + g_return_val_if_fail(PURPLE_IS_PROTOCOL_CONTACTS(protocol_contacts), + iface = PURPLE_PROTOCOL_CONTACTS_GET_IFACE(protocol_contacts); + if(iface->get_minimum_search_length == NULL) { + if(iface->search_async == NULL) { + if(iface->search_finish == NULL) { +purple_protocol_contacts_get_minimum_search_length(PurpleProtocolContacts *protocol_contacts) + PurpleProtocolContactsInterface *iface = NULL; + g_return_val_if_fail(PURPLE_IS_PROTOCOL_CONTACTS(protocol_contacts), 3); + iface = PURPLE_PROTOCOL_CONTACTS_GET_IFACE(protocol_contacts); + if(iface != NULL && iface->get_minimum_search_length != NULL) { + return iface->get_minimum_search_length(protocol_contacts); purple_protocol_contacts_search_async(PurpleProtocolContacts *protocol_contacts,
--- a/libpurple/purpleprotocolcontacts.h Mon May 13 23:28:20 2024 -0500
+++ b/libpurple/purpleprotocolcontacts.h Thu May 16 21:33:15 2024 -0500
@@ -65,6 +65,7 @@
+ guint (*get_minimum_search_length)(PurpleProtocolContacts *protocol_contacts); void (*search_async)(PurpleProtocolContacts *protocol_contacts, PurpleAccount *account, const char *text, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data);
GListModel *(*search_finish)(PurpleProtocolContacts *protocol_contacts, GAsyncResult *result, GError **error);
@@ -81,6 +82,37 @@
+ * purple_protocol_contacts_implements_search: + * @protocol_contacts: The instance. + * Checks if @protocol_contacts implements + * [vfunc@ProtocolContacts.search_async] and + * [vfunc@ProtocolContacts.search_finish]. + * Returns: %TRUE if the search interface is implemented, otherwise %FALSE. +gboolean purple_protocol_contacts_implements_search(PurpleProtocolContacts *protocol_contacts); + * purple_protocol_contacts_get_minimum_search_length: + * @protocol_contacts: The instance. + * Gets the minimum length of the search term before + * [method@ProtocolContacts.search_async] should be called. + * The default implementation returns 3. + * Returns: The minimum length of the search term. +guint purple_protocol_contacts_get_minimum_search_length(PurpleProtocolContacts *protocol_contacts); * purple_protocol_contacts_search_async:
* @protocol_contacts: The instance.
* @account: The [class@Account] to search under.
--- a/libpurple/tests/test_protocol_contacts.c Mon May 13 23:28:20 2024 -0500
+++ b/libpurple/tests/test_protocol_contacts.c Thu May 16 21:33:15 2024 -0500
@@ -85,6 +85,21 @@
* TestProtocolContactsEmpty Tests
*****************************************************************************/
+test_purple_protocol_contacts_empty_get_minimum_search_length(void) { + PurpleProtocolContacts *protocol = NULL; + guint minimum_search_length = 0; + protocol = g_object_new(test_purple_protocol_contacts_empty_get_type(), + minimum_search_length = purple_protocol_contacts_get_minimum_search_length(protocol); + /* There is a default implementation that returns 3. */ + g_assert_cmpuint(minimum_search_length, ==, 3); + g_assert_finalize_object(protocol); test_purple_protocol_contacts_empty_search_async(void) {
if(g_test_subprocess()) {
PurpleAccount *account = NULL;
@@ -226,6 +241,13 @@
guint get_profile_finish;
+test_purple_protocol_contacts_get_minimum_search_length(PurpleProtocolContacts *protocol_contacts) { + g_assert_true(PURPLE_IS_PROTOCOL_CONTACTS(protocol_contacts)); test_purple_protocol_contacts_search_async(PurpleProtocolContacts *protocol_contacts,
G_GNUC_UNUSED PurpleAccount *account,
@@ -325,6 +347,8 @@
test_purple_protocol_contacts_iface_init(PurpleProtocolContactsInterface *iface) {
+ iface->get_minimum_search_length = + test_purple_protocol_contacts_get_minimum_search_length; iface->search_async = test_purple_protocol_contacts_search_async;
iface->search_finish = test_purple_protocol_contacts_search_finish;
@@ -358,6 +382,21 @@
* TestProtocolContacts search test
*****************************************************************************/
+test_protocol_contacts_search_minimum_length(void) { + PurpleProtocolContacts *protocol = NULL; + guint minimum_search_length = 0; + protocol = g_object_new(test_purple_protocol_contacts_get_type(), NULL); + minimum_search_length = + test_purple_protocol_contacts_get_minimum_search_length(protocol); + g_assert_cmpuint(minimum_search_length, ==, 2); + g_assert_finalize_object(protocol); test_purple_protocol_contacts_search_cb(GObject *obj, GAsyncResult *res,
@@ -576,6 +615,8 @@
loop = g_main_loop_new(NULL, FALSE);
+ g_test_add_func("/protocol-contacts/empty/get-minimum-search-length", + test_purple_protocol_contacts_empty_get_minimum_search_length); g_test_add_func("/protocol-contacts/empty/search-async",
test_purple_protocol_contacts_empty_search_async);
g_test_add_func("/protocol-contacts/empty/search-finish",
@@ -589,6 +630,8 @@
g_test_add_func("/protocol-contacts/empty/get-menu",
test_purple_protocol_contacts_empty_get_menu);
+ g_test_add_func("/protocol-contacts/normal/get-minimum-search-length", + test_protocol_contacts_search_minimum_length); g_test_add_func("/protocol-contacts/normal/search-async-normal",
test_purple_protocol_contacts_search_normal);
g_test_add_func("/protocol-contacts/normal/search-async-error",