pidgin/pidgin

c4acd02fdf73
Parents e393090804c1
Children 170078e728c0
Add a require-password property to PurpleAccount

This will be able to be to set the a user so that an account so that an account
with an optional password will require a password for login.

Testing Done:
Compiled

Bugs closed: PIDGIN-17688

Reviewed at https://reviews.imfreedom.org/r/1876/
--- a/libpurple/account.c Sat Oct 01 04:09:51 2022 -0500
+++ b/libpurple/account.c Sat Oct 01 22:10:59 2022 -0500
@@ -51,6 +51,7 @@
gchar *id;
char *username; /* The username. */
+ gboolean require_password;
char *alias; /* How you appear to yourself. */
char *user_info; /* User information. */
@@ -117,6 +118,7 @@
PROP_0,
PROP_ID,
PROP_USERNAME,
+ PROP_REQUIRE_PASSWORD,
PROP_PRIVATE_ALIAS,
PROP_ENABLED,
PROP_CONNECTION,
@@ -645,6 +647,11 @@
child = purple_xmlnode_new_child(node, "name");
purple_xmlnode_insert_data(child, purple_account_get_username(account), -1);
+ child = purple_xmlnode_new_child(node, "require_password");
+ data = g_strdup_printf("%d", account->require_password);
+ purple_xmlnode_insert_data(child, data, -1);
+ g_clear_pointer(&data, g_free);
+
child = purple_xmlnode_new_child(node, "enabled");
data = g_strdup_printf("%d", account->enabled);
purple_xmlnode_insert_data(child, data, -1);
@@ -708,6 +715,10 @@
case PROP_USERNAME:
purple_account_set_username(account, g_value_get_string(value));
break;
+ case PROP_REQUIRE_PASSWORD:
+ purple_account_set_require_password(account,
+ g_value_get_boolean(value));
+ break;
case PROP_PRIVATE_ALIAS:
purple_account_set_private_alias(account, g_value_get_string(value));
break;
@@ -753,6 +764,10 @@
case PROP_USERNAME:
g_value_set_string(value, purple_account_get_username(account));
break;
+ case PROP_REQUIRE_PASSWORD:
+ g_value_set_boolean(value,
+ purple_account_get_require_password(account));
+ break;
case PROP_PRIVATE_ALIAS:
g_value_set_string(value, purple_account_get_private_alias(account));
break;
@@ -939,6 +954,21 @@
"The username for the account.", NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+ /**
+ * PurpleAccount:require-password:
+ *
+ * Whether or not this account should require a password. This is only used
+ * if the [class@Purple.Protocol] that this account is for allows optional
+ * passwords.
+ *
+ * Since: 3.0.0
+ */
+ properties[PROP_REQUIRE_PASSWORD] = g_param_spec_boolean(
+ "require-password", "Require password",
+ "Whether or not to require a password for this account",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
properties[PROP_PRIVATE_ALIAS] = g_param_spec_string("private-alias",
"Private Alias",
"The private alias for the account.", NULL,
@@ -2369,3 +2399,27 @@
{
_purple_account_set_current_error(account, NULL);
}
+
+void
+purple_account_set_require_password(PurpleAccount *account,
+ gboolean require_password)
+{
+ gboolean old = FALSE;
+
+ g_return_if_fail(PURPLE_IS_ACCOUNT(account));
+
+ old = account->require_password;
+ account->require_password = require_password;
+
+ if(old != require_password) {
+ g_object_notify_by_pspec(G_OBJECT(account),
+ properties[PROP_REQUIRE_PASSWORD]);
+ }
+}
+
+gboolean
+purple_account_get_require_password(PurpleAccount *account) {
+ g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), FALSE);
+
+ return account->require_password;
+}
--- a/libpurple/account.h Sat Oct 01 04:09:51 2022 -0500
+++ b/libpurple/account.h Sat Oct 01 22:10:59 2022 -0500
@@ -1010,6 +1010,31 @@
*/
void purple_account_clear_current_error(PurpleAccount *account);
+/**
+ * purple_account_set_require_password:
+ * @account: The instance.
+ * @require_password: Whether or not this account should require a password.
+ *
+ * For protocols that have an optional password, this settings tells libpurple
+ * that it should look for a password in the [class@Purple.CredentialManager]
+ * or prompt the user if a password can not be found.
+ *
+ * Since: 3.0.0
+ */
+void purple_account_set_require_password(PurpleAccount *account, gboolean require_password);
+
+/**
+ * purple_account_get_require_password:
+ * @account: The instance.
+ *
+ * Gets whether or not @account requires a password.
+ *
+ * Returns: %TRUE if the account requires a password, %FALSE otherwise.
+ *
+ * Since: 3.0.0
+ */
+gboolean purple_account_get_require_password(PurpleAccount *account);
+
G_END_DECLS
#endif /* PURPLE_ACCOUNT_H */
--- a/libpurple/accounts.c Sat Oct 01 04:09:51 2022 -0500
+++ b/libpurple/accounts.c Sat Oct 01 22:10:59 2022 -0500
@@ -309,6 +309,7 @@
char *name = NULL;
char *data;
gboolean enabled = FALSE;
+ gboolean require_password = FALSE;
child = purple_xmlnode_get_child(node, "id");
if(child != NULL) {
@@ -330,6 +331,11 @@
name = purple_xmlnode_get_data(child);
}
+ child = purple_xmlnode_get_child(node, "require_password");
+ if(child != NULL) {
+ require_password = atoi(purple_xmlnode_get_data(child));
+ }
+
child = purple_xmlnode_get_child(node, "enabled");
if(child != NULL) {
enabled = atoi(purple_xmlnode_get_data(child));
@@ -351,6 +357,7 @@
"username", name,
"protocol-id", protocol_id,
"enabled", enabled,
+ "require-password", require_password,
NULL);
g_free(id);