# HG changeset patch
# Node ID 434ab72919d9f42b9329c91e54ec3310242bd2b5
# Parent  46b64a8cbec4999a95f058b7cded30fb4dfc801f
diff --git a/libpurple/purplenotification.c b/libpurple/purplenotification.c
--- a/libpurple/purplenotification.c
+++ b/libpurple/purplenotification.c
@@ -113,22 +113,6 @@
 }
 
 static void
-purple_notification_set_account(PurpleNotification *notification,
-                                PurpleAccount *account)
-{
-	PurpleNotificationPrivate *priv = NULL;
-
-	g_return_if_fail(PURPLE_IS_NOTIFICATION(notification));
-
-	priv = purple_notification_get_instance_private(notification);
-
-	if(g_set_object(&priv->account, account)) {
-		g_object_notify_by_pspec(G_OBJECT(notification),
-		                         properties[PROP_ACCOUNT]);
-	}
-}
-
-static void
 purple_notification_set_data(PurpleNotification *notification, gpointer data) {
 	PurpleNotificationPrivate *priv = NULL;
 
@@ -172,8 +156,10 @@
 		                   purple_notification_get_id(notification));
 		break;
 	case PROP_TYPE:
+		G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 		g_value_set_enum(value,
 		                 purple_notification_get_notification_type(notification));
+		G_GNUC_END_IGNORE_DEPRECATIONS
 		break;
 	case PROP_ACCOUNT:
 		g_value_set_object(value,
@@ -208,8 +194,10 @@
 		                    purple_notification_get_persistent(notification));
 		break;
 	case PROP_DATA:
+		G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 		g_value_set_pointer(value,
 		                    purple_notification_get_data(notification));
+		G_GNUC_END_IGNORE_DEPRECATIONS
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
@@ -301,8 +289,7 @@
 }
 
 static void
-purple_notification_init(PurpleNotification *notification) {
-	purple_notification_set_id(notification, NULL);
+purple_notification_init(G_GNUC_UNUSED PurpleNotification *notification) {
 }
 
 static void
@@ -316,15 +303,18 @@
 	/**
 	 * PurpleNotification:id:
 	 *
-	 * The ID of the notification. Used for things that need to address it.
-	 * This is auto populated at creation time.
+	 * The ID of the notification.
+	 *
+	 * This used for things that need to address it.
+	 *
+	 * If not set, this will be auto populated at creation time.
 	 *
 	 * Since: 3.0
 	 */
 	properties[PROP_ID] = g_param_spec_string(
 		"id", NULL, NULL,
 		NULL,
-		G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+		G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
 
 	/**
 	 * PurpleNotification:type:
@@ -337,7 +327,8 @@
 		"type", NULL, NULL,
 		PURPLE_TYPE_NOTIFICATION_TYPE,
 		PURPLE_NOTIFICATION_TYPE_UNKNOWN,
-		G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+		G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_DEPRECATED |
+		G_PARAM_STATIC_STRINGS);
 
 	/**
 	 * PurpleNotification:account:
@@ -349,7 +340,7 @@
 	properties[PROP_ACCOUNT] = g_param_spec_object(
 		"account", NULL, NULL,
 		PURPLE_TYPE_ACCOUNT,
-		G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+		G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
 	/**
 	 * PurpleNotification:created-timestamp:
@@ -451,7 +442,8 @@
 	 */
 	properties[PROP_DATA] = g_param_spec_pointer(
 		"data", NULL, NULL,
-		G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+		G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_DEPRECATED |
+		G_PARAM_STATIC_STRINGS);
 
 	/**
 	 * PurpleNotification:data-destroy-func:
@@ -462,7 +454,8 @@
 	 */
 	properties[PROP_DATA_DESTROY_FUNC] = g_param_spec_pointer(
 		"data-destroy-func", NULL, NULL,
-		G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+		G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_DEPRECATED |
+		G_PARAM_STATIC_STRINGS);
 
 	g_object_class_install_properties(obj_class, N_PROPERTIES, properties);
 
@@ -494,12 +487,34 @@
 purple_notification_new(PurpleNotificationType type, PurpleAccount *account,
                         gpointer data, GDestroyNotify data_destroy_func)
 {
-	return g_object_new(PURPLE_TYPE_NOTIFICATION,
+	PurpleNotification *notification = NULL;
+	char *envvar = NULL;
+
+	/* This is temporary until this function gets replaced with the generic one
+	 * below.
+	 */
+	envvar = g_strdup(g_getenv("G_ENABLE_DIAGNOSTIC"));
+	g_unsetenv("G_ENABLE_DIAGNOSTIC");
+
+	notification = g_object_new(PURPLE_TYPE_NOTIFICATION,
 	                    "type", type,
 	                    "account", account,
 	                    "data", data,
 	                    "data-destroy-func", data_destroy_func,
 	                    NULL);
+
+	g_setenv("G_ENABLE_DIAGNOSTIC", envvar, FALSE);
+	g_free(envvar);
+
+	return notification;
+}
+
+PurpleNotification *
+purple_notification_new_generic(const char *id, const char *title) {
+	return g_object_new(PURPLE_TYPE_NOTIFICATION,
+	                    "id", id,
+	                    "title", title,
+	                    NULL);
 }
 
 PurpleNotification *
@@ -523,9 +538,11 @@
 	                     NULL);
 
 	account = purple_authorization_request_get_account(authorization_request);
+	G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 	notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_AUTHORIZATION_REQUEST,
 	                                       account, authorization_request,
 	                                       g_object_unref);
+	G_GNUC_END_IGNORE_DEPRECATIONS
 
 	username = purple_authorization_request_get_username(authorization_request);
 	alias = purple_authorization_request_get_alias(authorization_request);
@@ -552,6 +569,7 @@
 purple_notification_new_from_connection_error(PurpleAccount *account,
                                               PurpleConnectionErrorInfo *info)
 {
+	PurpleConnectionErrorInfo *copy = NULL;
 	PurpleNotification *notification = NULL;
 	PurpleProtocol *protocol = NULL;
 	char *title = NULL;
@@ -560,8 +578,12 @@
 	g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL);
 	g_return_val_if_fail(info != NULL, NULL);
 
+	G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+	copy = purple_connection_error_info_copy(info);
 	notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_CONNECTION_ERROR,
-	                                       account, info, NULL);
+	                                       account, copy,
+	                                       (GDestroyNotify)purple_connection_error_info_free);
+	G_GNUC_END_IGNORE_DEPRECATIONS
 
 	/* Set the title of the notification. */
 	username = purple_account_get_username(account);
@@ -620,6 +642,22 @@
 	return priv->account;
 }
 
+void
+purple_notification_set_account(PurpleNotification *notification,
+                                PurpleAccount *account)
+{
+	PurpleNotificationPrivate *priv = NULL;
+
+	g_return_if_fail(PURPLE_IS_NOTIFICATION(notification));
+
+	priv = purple_notification_get_instance_private(notification);
+
+	if(g_set_object(&priv->account, account)) {
+		g_object_notify_by_pspec(G_OBJECT(notification),
+		                         properties[PROP_ACCOUNT]);
+	}
+}
+
 GDateTime *
 purple_notification_get_created_timestamp(PurpleNotification *notification) {
 	PurpleNotificationPrivate *priv = NULL;
@@ -738,7 +776,6 @@
 		g_object_notify_by_pspec(G_OBJECT(notification),
 		                         properties[PROP_ICON_NAME]);
 	}
-
 }
 
 gboolean
diff --git a/libpurple/purplenotification.h b/libpurple/purplenotification.h
--- a/libpurple/purplenotification.h
+++ b/libpurple/purplenotification.h
@@ -113,8 +113,27 @@
  *
  * Since: 3.0
  */
+PURPLE_DEPRECATED_FOR(purple_notification_new_generic)
+PurpleNotification *purple_notification_new(PurpleNotificationType type, PurpleAccount *account, gpointer data, GDestroyNotify data_destroy_func);
+
+/**
+ * purple_notification_new_generic:
+ * @id: (nullable): An id for the notification.
+ * @title: (nullable): The title for the notification.
+ *
+ * Creates a new notification with @title.
+ *
+ * If @id is %NULL it will be set to a ran identifier. The @id is used to tell
+ * protocols that the the notification was read/dismissed/whatever. So if you
+ * set the id for that purpose, but sure to set [property@Notification:account]
+ * as well.
+ *
+ * Returns: (transfers full): The new notification.
+ *
+ * Since: 3.0
+ */
 PURPLE_AVAILABLE_IN_3_0
-PurpleNotification *purple_notification_new(PurpleNotificationType type, PurpleAccount *account, gpointer data, GDestroyNotify data_destroy_func);
+PurpleNotification *purple_notification_new_generic(const char *id, const char *title);
 
 /**
  * purple_notification_new_from_add_contact_request:
@@ -152,7 +171,7 @@
 /**
  * purple_notification_new_from_connection_error:
  * @account: The [class@Purple.Account] that had the connection error.
- * @info: The [struct@Purple.ConnectionErrorInfo] for the error.
+ * @info: (transfer none): The [struct@Purple.ConnectionErrorInfo] for the error.
  *
  * Creates a new [class@Purple.Notification] for @account with the @info for
  * the connection. This helper will automatically fill out the notification
@@ -188,7 +207,7 @@
  *
  * Since: 3.0
  */
-PURPLE_AVAILABLE_IN_3_0
+PURPLE_DEPRECATED
 PurpleNotificationType purple_notification_get_notification_type(PurpleNotification *notification);
 
 /**
@@ -205,6 +224,18 @@
 PurpleAccount *purple_notification_get_account(PurpleNotification *notification);
 
 /**
+ * purple_notification_set_account:
+ * @notification: The instance.
+ * @account: (nullable): The new account.
+ *
+ * Sets the account of @notification to @account.
+ *
+ * Since: 3.0
+ */
+PURPLE_AVAILABLE_IN_3_0
+void purple_notification_set_account(PurpleNotification *notification, PurpleAccount *account);
+
+/**
  * purple_notification_get_created_timestamp:
  * @notification: The instance.
  *
@@ -406,7 +437,7 @@
  *
  * Since: 3.0
  */
-PURPLE_AVAILABLE_IN_3_0
+PURPLE_DEPRECATED
 gpointer purple_notification_get_data(PurpleNotification *notification);
 
 /**
diff --git a/libpurple/purplenotificationmanager.c b/libpurple/purplenotificationmanager.c
--- a/libpurple/purplenotificationmanager.c
+++ b/libpurple/purplenotificationmanager.c
@@ -504,7 +504,9 @@
 		/* If the notification's type is connection error, set can_remove to
 		 * the value of the all parameter.
 		 */
+		G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 		type = purple_notification_get_notification_type(notification);
+ 		G_GNUC_END_IGNORE_DEPRECATIONS
 		if(type == PURPLE_NOTIFICATION_TYPE_CONNECTION_ERROR) {
 			can_remove = all;
 		}
diff --git a/libpurple/tests/test_notification.c b/libpurple/tests/test_notification.c
--- a/libpurple/tests/test_notification.c
+++ b/libpurple/tests/test_notification.c
@@ -23,46 +23,19 @@
 #include <purple.h>
 
 /******************************************************************************
- * Callbacks
- *****************************************************************************/
-static void
-test_purple_notification_destroy_data_cb(gpointer data) {
-	guint *counter = data;
-
-	*counter = *counter + 1;
-}
-
-/******************************************************************************
  * Tests
  *****************************************************************************/
 static void
 test_purple_notification_new(void) {
-	PurpleAccount *account1 = NULL;
-	PurpleAccount *account2 = NULL;
 	PurpleNotification *notification = NULL;
-	PurpleNotificationType type = PURPLE_NOTIFICATION_TYPE_UNKNOWN;
 	GDateTime *created_timestamp = NULL;
 	const char *id = NULL;
 
-	account1 = purple_account_new("test", "test");
-
-	notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_GENERIC,
-	                                       account1,
-	                                       NULL,
-	                                       NULL);
+	notification = purple_notification_new_generic(NULL, NULL);
 
 	/* Make sure we got a valid notification. */
 	g_assert_true(PURPLE_IS_NOTIFICATION(notification));
 
-	/* Check the type. */
-	type = purple_notification_get_notification_type(notification);
-	g_assert_cmpint(PURPLE_NOTIFICATION_TYPE_GENERIC, ==, type);
-
-	/* Verify the account is set properly. */
-	account2 = purple_notification_get_account(notification);
-	g_assert_nonnull(account2);
-	g_assert_true(account1 == account2);
-
 	/* Make sure that the id was generated. */
 	id = purple_notification_get_id(notification);
 	g_assert_nonnull(id);
@@ -76,32 +49,10 @@
 	created_timestamp = purple_notification_get_created_timestamp(notification);
 	g_assert_nonnull(created_timestamp);
 
-	g_clear_object(&account1);
 	g_assert_finalize_object(notification);
 }
 
 static void
-test_purple_notification_destroy_data_func(void) {
-	PurpleNotification *notification = NULL;
-	guint counter = 0;
-
-	/* Create the notification. */
-	notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_GENERIC,
-	                                       NULL,
-	                                       &counter,
-	                                       test_purple_notification_destroy_data_cb);
-
-	/* Sanity check. */
-	g_assert_true(PURPLE_IS_NOTIFICATION(notification));
-
-	/* Unref it to force the destroy callback to be called. */
-	g_assert_finalize_object(notification);
-
-	/* Make sure the callback was called. */
-	g_assert_cmpuint(counter, ==, 1);
-}
-
-static void
 test_purple_notification_properties(void) {
 	PurpleNotification *notification = NULL;
 	GDateTime *created_timestamp = NULL;
@@ -124,7 +75,6 @@
 		"read", TRUE,
 		"subtitle", "subtitle",
 		"title", "title",
-		"type", PURPLE_NOTIFICATION_TYPE_GENERIC,
 		NULL);
 
 	g_assert_true(PURPLE_IS_NOTIFICATION(notification));
@@ -171,8 +121,6 @@
 
 	g_test_add_func("/notification/new",
 	                test_purple_notification_new);
-	g_test_add_func("/notification/destroy-data-func",
-	                test_purple_notification_destroy_data_func);
 	g_test_add_func("/notification/properties",
 	                test_purple_notification_properties);
 
diff --git a/libpurple/tests/test_notification_manager.c b/libpurple/tests/test_notification_manager.c
--- a/libpurple/tests/test_notification_manager.c
+++ b/libpurple/tests/test_notification_manager.c
@@ -67,8 +67,7 @@
 	                 &removed_called);
 
 	/* Create the notification and store its id. */
-	notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_GENERIC,
-	                                       NULL, NULL, NULL);
+	notification = purple_notification_new_generic(NULL, NULL);
 
 	/* Add the notification to the manager. */
 	purple_notification_manager_add(manager, notification);
@@ -103,8 +102,7 @@
 
 		manager = g_object_new(PURPLE_TYPE_NOTIFICATION_MANAGER, NULL);
 
-		notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_GENERIC,
-		                                       NULL, NULL, NULL);
+		notification = purple_notification_new_generic(NULL, NULL);
 
 		purple_notification_manager_add(manager, notification);
 		purple_notification_manager_add(manager, notification);
@@ -134,8 +132,7 @@
 	                 G_CALLBACK(test_purple_notification_manager_increment_cb),
 	                 &removed_called);
 
-	notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_GENERIC,
-	                                       NULL, NULL, NULL);
+	notification = purple_notification_new_generic(NULL, NULL);
 
 	purple_notification_manager_add(manager, notification);
 
@@ -164,8 +161,7 @@
 	g_assert_cmpuint(0, ==, g_list_model_get_n_items(model));
 
 	/* Add a single notification without the account */
-	notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_GENERIC,
-	                                       NULL, NULL, NULL);
+	notification = purple_notification_new_generic(NULL, NULL);
 	purple_notification_manager_add(manager, notification);
 	purple_notification_manager_remove_with_account(manager, account, TRUE);
 	g_assert_cmpuint(1, ==, g_list_model_get_n_items(model));
@@ -173,8 +169,8 @@
 	g_clear_object(&notification);
 
 	/* Add a single notification with the account */
-	notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_GENERIC,
-	                                       account, NULL, NULL);
+	notification = purple_notification_new_generic(NULL, NULL);
+	purple_notification_set_account(notification, account);
 	purple_notification_manager_add(manager, notification);
 	purple_notification_manager_remove_with_account(manager, account, TRUE);
 	g_assert_cmpuint(0, ==, g_list_model_get_n_items(model));
@@ -202,9 +198,8 @@
 
 	/* Add our notifications. */
 	for(int i = 0; pattern[i] >= 0; i++) {
-		notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_GENERIC,
-		                                       accounts[pattern[i]], NULL,
-		                                       NULL);
+		notification = purple_notification_new_generic(NULL, NULL);
+		purple_notification_set_account(notification, accounts[pattern[i]]);
 		purple_notification_manager_add(manager, notification);
 		g_clear_object(&notification);
 	}
@@ -231,6 +226,7 @@
 
 static void
 test_purple_notification_manager_remove_with_account_all(void) {
+	PurpleConnectionErrorInfo *info = NULL;
 	PurpleNotificationManager *manager = NULL;
 	PurpleNotification *notification = NULL;
 	PurpleAccount *account = NULL;
@@ -266,26 +262,27 @@
 	g_assert_cmpuint(0, ==, g_list_model_get_n_items(model));
 
 	/* Add a generic notification with an account. */
-	notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_GENERIC,
-	                                       account, NULL, NULL);
+	notification = purple_notification_new_generic(NULL, NULL);
+	purple_notification_set_account(notification, account);
 	purple_notification_manager_add(manager, notification);
 	g_clear_object(&notification);
 
 	/* Add a connection error notification with the account. */
-	notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_CONNECTION_ERROR,
-	                                       account, NULL, NULL);
+	info = purple_connection_error_info_new(PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
+	                                        "the network is borked.");
+	notification = purple_notification_new_from_connection_error(account, info);
+	purple_connection_error_info_free(info);
 	purple_notification_manager_add(manager, notification);
 	g_clear_object(&notification);
 
 	/* Add a generic notification with the account. */
-	notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_GENERIC,
-	                                       account, NULL, NULL);
+	notification = purple_notification_new_generic(NULL, NULL);
+	purple_notification_set_account(notification, account);
 	purple_notification_manager_add(manager, notification);
 	g_clear_object(&notification);
 
 	/* Add a generic notification without an account. */
-	notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_GENERIC,
-	                                       NULL, NULL, NULL);
+	notification = purple_notification_new_generic(NULL, NULL);
 	purple_notification_manager_add(manager, notification);
 	g_clear_object(&notification);
 
@@ -298,8 +295,10 @@
 
 	/* Make sure that the second item is the connection error. */
 	notification = g_list_model_get_item(G_LIST_MODEL(model), 1);
+	G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 	g_assert_cmpint(purple_notification_get_notification_type(notification),
 	                ==, PURPLE_NOTIFICATION_TYPE_CONNECTION_ERROR);
+	G_GNUC_END_IGNORE_DEPRECATIONS
 	g_clear_object(&notification);
 
 	/* Remove the non-transient notifications for the account. */
@@ -336,10 +335,7 @@
 	                 &unread_count_called);
 
 	/* Create the notification. */
-	notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_GENERIC,
-	                                       NULL,
-	                                       NULL,
-	                                       NULL);
+	notification = purple_notification_new_generic(NULL, NULL);
 
 	purple_notification_manager_add(manager, notification);
 
