--- a/libpurple/meson.build Thu Mar 21 22:18:04 2024 -0500
+++ b/libpurple/meson.build Thu Mar 21 22:20:50 2024 -0500
@@ -39,6 +39,7 @@
'purpleaddcontactrequest.c',
'purpleauthorizationrequest.c',
+ 'purpleauthorizationrequestnotification.c', 'purplechanneljoindetails.c',
@@ -164,6 +165,7 @@
'purpleaccountusersplit.h',
'purpleaddcontactrequest.h',
'purpleauthorizationrequest.h',
+ 'purpleauthorizationrequestnotification.h', 'purplechanneljoindetails.h',
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/purpleauthorizationrequestnotification.c Thu Mar 21 22:20:50 2024 -0500
@@ -0,0 +1,228 @@
+ * 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 + * 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) + * 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 + * 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 <glib/gi18n-lib.h> +#include "purpleauthorizationrequestnotification.h" + PROP_AUTHORIZATION_REQUEST, +static GParamSpec *properties[N_PROPERTIES] = {NULL, 0}; +struct _PurpleAuthorizationRequestNotification { + PurpleNotification parent; + PurpleAuthorizationRequest *authorization_request; +purple_authorization_request_notification_request_changed_cb(GObject *obj, +/****************************************************************************** + *****************************************************************************/ +purple_authorization_request_notification_update(PurpleAuthorizationRequestNotification *auth_notification) + PurpleAccount *account = NULL; + PurpleAuthorizationRequest *request = NULL; + PurpleContactInfo *info = NULL; + PurpleNotification *notification = PURPLE_NOTIFICATION(auth_notification); + const char *alias = NULL; + const char *username = NULL; + request = auth_notification->authorization_request; + account = purple_authorization_request_get_account(request); + info = PURPLE_CONTACT_INFO(account); + username = purple_authorization_request_get_username(request); + alias = purple_authorization_request_get_alias(request); + if(!purple_strempty(alias)) { + title = g_strdup_printf(_("%s (%s) would like to add %s to their" + purple_contact_info_get_username(info)); + title = g_strdup_printf(_("%s would like to add %s to their contact" + purple_contact_info_get_username(info)); + purple_notification_set_title(notification, title); +purple_authorization_request_notification_set_request(PurpleAuthorizationRequestNotification *notification, + PurpleAuthorizationRequest *request) + g_return_if_fail(PURPLE_IS_AUTHORIZATION_REQUEST_NOTIFICATION(notification)); + if(g_set_object(¬ification->authorization_request, request)) { + if(PURPLE_IS_AUTHORIZATION_REQUEST(request)) { + g_signal_connect_object(request, "notify", + G_CALLBACK(purple_authorization_request_notification_request_changed_cb), + purple_authorization_request_notification_update(notification); + g_object_notify_by_pspec(G_OBJECT(notification), + properties[PROP_AUTHORIZATION_REQUEST]); +/****************************************************************************** + *****************************************************************************/ +purple_authorization_request_notification_request_changed_cb(G_GNUC_UNUSED GObject *obj, + G_GNUC_UNUSED GParamSpec *pspec, + purple_authorization_request_notification_update(data); +/****************************************************************************** + * GObject Implementation + *****************************************************************************/ +G_DEFINE_FINAL_TYPE(PurpleAuthorizationRequestNotification, + purple_authorization_request_notification, + PURPLE_TYPE_NOTIFICATION) +purple_authorization_request_notification_finalize(GObject *object) { + PurpleAuthorizationRequestNotification *notification = NULL; + notification = PURPLE_AUTHORIZATION_REQUEST_NOTIFICATION(object); + g_clear_object(¬ification->authorization_request); + G_OBJECT_CLASS(purple_authorization_request_notification_parent_class)->finalize(object); +purple_authorization_request_notification_get_property(GObject *obj, + PurpleAuthorizationRequestNotification *notification = NULL; + notification = PURPLE_AUTHORIZATION_REQUEST_NOTIFICATION(obj); + case PROP_AUTHORIZATION_REQUEST: + g_value_set_object(value, + purple_authorization_request_notification_get_request(notification)); + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); +purple_authorization_request_notification_set_property(GObject *obj, + PurpleAuthorizationRequestNotification *notification = NULL; + notification = PURPLE_AUTHORIZATION_REQUEST_NOTIFICATION(obj); + case PROP_AUTHORIZATION_REQUEST: + purple_authorization_request_notification_set_request(notification, + g_value_get_object(value)); + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); +purple_authorization_request_notification_init(G_GNUC_UNUSED PurpleAuthorizationRequestNotification *notification) +purple_authorization_request_notification_class_init(PurpleAuthorizationRequestNotificationClass *klass) + GObjectClass *obj_class = G_OBJECT_CLASS(klass); + obj_class->finalize = purple_authorization_request_notification_finalize; + obj_class->get_property = purple_authorization_request_notification_get_property; + obj_class->set_property = purple_authorization_request_notification_set_property; + * PurpleAuthorizationRequestNotification:authorization-request: + * The [class@AuthorizationRequest] that this notification was created for. + properties[PROP_AUTHORIZATION_REQUEST] = g_param_spec_object( + "authorization-request", "authorization-request", + "The authorization request this notification is for.", + PURPLE_TYPE_AUTHORIZATION_REQUEST, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + g_object_class_install_properties(obj_class, N_PROPERTIES, properties); +/****************************************************************************** + *****************************************************************************/ +purple_authorization_request_notification_new(PurpleAuthorizationRequest *request) + PurpleAccount *account = NULL; + g_return_val_if_fail(PURPLE_IS_AUTHORIZATION_REQUEST(request), NULL); + account = purple_authorization_request_get_account(request); + PURPLE_TYPE_AUTHORIZATION_REQUEST_NOTIFICATION, + "authorization-request", request, +PurpleAuthorizationRequest * +purple_authorization_request_notification_get_request(PurpleAuthorizationRequestNotification *notification) + g_return_val_if_fail(PURPLE_IS_AUTHORIZATION_REQUEST_NOTIFICATION(notification), + return notification->authorization_request; --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/purpleauthorizationrequestnotification.h Thu Mar 21 22:20:50 2024 -0500
@@ -0,0 +1,83 @@
+ * 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 + * 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) + * 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 + * You should have received a copy of the GNU General Public License along with + * this library; if not, see <https://www.gnu.org/licenses/>. +#if !defined(PURPLE_GLOBAL_HEADER_INSIDE) && !defined(PURPLE_COMPILATION) +# error "only <purple.h> may be included directly" +#ifndef PURPLE_AUTHORIZATION_REQUEST_NOTIFICATION_H +#define PURPLE_AUTHORIZATION_REQUEST_NOTIFICATION_H +#include <glib-object.h> +#include "purpleauthorizationrequest.h" +#include "purplenotification.h" +#include "purpleversion.h" + * PurpleAuthorizationRequestNotification: + * A [class@Notification] for [class@AuthorizationRequest]s. +#define PURPLE_TYPE_AUTHORIZATION_REQUEST_NOTIFICATION (purple_authorization_request_notification_get_type()) +G_DECLARE_FINAL_TYPE(PurpleAuthorizationRequestNotification, + purple_authorization_request_notification, + PURPLE, AUTHORIZATION_REQUEST_NOTIFICATION, + * purple_authorization_request_notification_new: + * @request: The authorization request instance. + * Creates a new [class@Notification] for @request. + * Returns: The new notification. +PurpleNotification *purple_authorization_request_notification_new(PurpleAuthorizationRequest *request); + * purple_authorization_request_notification_get_request: + * @notification: The instance. + * Gets the [class@AuthorizationRequest] for @notification. + * Returns: (transfer none): The authorization request. +PurpleAuthorizationRequest *purple_authorization_request_notification_get_request(PurpleAuthorizationRequestNotification *notification); +#endif /* PURPLE_AUTHORIZATION_REQUEST_NOTIFICATION_H */ --- a/libpurple/tests/meson.build Thu Mar 21 22:18:04 2024 -0500
+++ b/libpurple/tests/meson.build Thu Mar 21 22:20:50 2024 -0500
@@ -2,6 +2,7 @@
+ 'authorization_request_notification', 'create_conversation_details',
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/tests/test_authorization_request_notification.c Thu Mar 21 22:20:50 2024 -0500
@@ -0,0 +1,142 @@
+ * Purple - Internet Messaging Library + * Copyright (C) Pidgin Developers <devel@pidgin.im> + * 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/>. +/****************************************************************************** + *****************************************************************************/ +test_purple_authorization_request_notification_notify_cb(GObject *obj, + G_GNUC_UNUSED GParamSpec *pspec, + g_assert_true(PURPLE_IS_NOTIFICATION(obj)); + *counter = *counter + 1; +/****************************************************************************** + *****************************************************************************/ +test_purple_authorization_request_notification_new(void) { + PurpleAccount *account = NULL; + PurpleAuthorizationRequest *request = NULL; + PurpleNotification *notification = NULL; + account = purple_account_new("test", "test"); + request = purple_authorization_request_new(account, "remote-username"); + notification = purple_authorization_request_notification_new(request); + g_assert_true(PURPLE_IS_NOTIFICATION(notification)); + g_assert_true(PURPLE_IS_AUTHORIZATION_REQUEST_NOTIFICATION(notification)); + g_assert_finalize_object(notification); + g_clear_object(&request); + g_clear_object(&account); +test_purple_authorization_request_notification_properties(void) { + PurpleAccount *account = NULL; + PurpleAuthorizationRequest *request = NULL; + PurpleAuthorizationRequest *request1 = NULL; + PurpleNotification *notification = NULL; + account = purple_account_new("test", "test"); + request = purple_authorization_request_new(account, "username"); + notification = g_object_new( + PURPLE_TYPE_AUTHORIZATION_REQUEST_NOTIFICATION, + "authorization-request", request, + "authorization-request", &request1, + g_assert_true(request1 == request); + g_clear_object(&request1); + g_assert_finalize_object(notification); + g_clear_object(&request); + g_clear_object(&account); +test_purple_authorization_request_notification_updates_title(void) { + PurpleAccount *account = NULL; + PurpleAuthorizationRequest *request = NULL; + PurpleNotification *notification = NULL; + account = purple_account_new("test", "test"); + request = purple_authorization_request_new(account, "remote-username"); + notification = purple_authorization_request_notification_new(request); + g_signal_connect(notification, "notify::title", + G_CALLBACK(test_purple_authorization_request_notification_notify_cb), + g_assert_cmpuint(counter, ==, 0); + purple_authorization_request_set_alias(request, "foo"); + g_assert_cmpuint(counter, ==, 1); + g_assert_finalize_object(notification); + g_clear_object(&request); + g_clear_object(&account); +/****************************************************************************** + *****************************************************************************/ +main(gint argc, gchar *argv[]) { + g_test_init(&argc, &argv, NULL); + g_test_add_func("/request-authorization-notification/new", + test_purple_authorization_request_notification_new); + g_test_add_func("/request-authorization-notification/properties", + test_purple_authorization_request_notification_properties); + g_test_add_func("/request-authorization-notification/updates-title", + test_purple_authorization_request_notification_updates_title); + test_ui_purple_uninit();