pidgin/pidgin

Port credential manager to GSettings

20 months ago, Elliott Sales de Andrade
d8a78f5c982d
Parents 6a4db60af05b
Children 91aacfd62b5f
Port credential manager to GSettings

A simple poc for porting to `GSettings` as credential manager only has one setting.

Testing Done:
Opened Pidgin prefs, changed credential provider and it saved for next re-start.

Reviewed at https://reviews.imfreedom.org/r/1735/
--- a/libpurple/data/im.pidgin.Purple.gschema.xml Sun Sep 11 00:33:00 2022 -0500
+++ b/libpurple/data/im.pidgin.Purple.gschema.xml Sun Sep 11 00:34:53 2022 -0500
@@ -1,5 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<schemalist>
<schema path="/" id="im.pidgin.Purple">
+ <child name="credentials" schema="im.pidgin.Purple.Credentials"/>
+ </schema>
+
+ <schema path="/purple/credentials/" id="im.pidgin.Purple.Credentials">
+ <key name="active-provider" type="s">
+ <default>"noop-provider"</default>
+ <summary>Active credential provider</summary>
+ <description>
+ The credential provider that will be used to save credentials, i.e.,
+ passwords, tokens, etc.
+ </description>
+ </key>
</schema>
</schemalist>
--- a/libpurple/purplecredentialmanager.c Sun Sep 11 00:33:00 2022 -0500
+++ b/libpurple/purplecredentialmanager.c Sun Sep 11 00:34:53 2022 -0500
@@ -128,10 +128,14 @@
PurpleCredentialManager *manager = PURPLE_CREDENTIAL_MANAGER(data);
if(!PURPLE_IS_CREDENTIAL_PROVIDER(manager->active)) {
+ GSettings *settings = NULL;
GError *error = NULL;
- const gchar *id = NULL;
+ gchar *id = NULL;
- id = purple_prefs_get_string("/purple/credentials/active-provider");
+ settings = g_settings_new_with_backend("im.pidgin.Purple.Credentials",
+ purple_core_get_settings_backend());
+ id = g_settings_get_string(settings, "active-provider");
+ g_object_unref(settings);
if(!purple_credential_manager_set_active(manager, id, &error)) {
g_warning("Failed to make %s the active credential provider : %s",
@@ -145,6 +149,7 @@
NULL);
}
+ g_free(id);
g_clear_error(&error);
}
}
@@ -247,11 +252,6 @@
2,
PURPLE_TYPE_CREDENTIAL_PROVIDER,
PURPLE_TYPE_CREDENTIAL_PROVIDER);
-
- /* Add our purple preferences. */
- purple_prefs_add_none("/purple/credentials");
- purple_prefs_add_string("/purple/credentials/active-provider",
- "noop-provider");
}
/******************************************************************************
@@ -354,13 +354,19 @@
* If it is, go ahead and make it the active provider.
*/
if(!PURPLE_IS_CREDENTIAL_PROVIDER(manager->active)) {
- const gchar *wanted = NULL;
+ GSettings *settings = NULL;
+ gchar *wanted = NULL;
- wanted = purple_prefs_get_string("/purple/credentials/active-provider");
+ settings = g_settings_new_with_backend("im.pidgin.Purple.Credentials",
+ purple_core_get_settings_backend());
+ wanted = g_settings_get_string(settings, "active-provider");
if(purple_strequal(wanted, id)) {
purple_credential_manager_set_active(manager, id, error);
}
+
+ g_free(wanted);
+ g_object_unref(settings);
}
return TRUE;
@@ -438,7 +444,12 @@
/* Finally update the preference. */
if(id != NULL) {
- purple_prefs_set_string("/purple/credentials/active-provider", id);
+ GSettings *settings = NULL;
+
+ settings = g_settings_new_with_backend("im.pidgin.Purple.Credentials",
+ purple_core_get_settings_backend());
+ g_settings_set_string(settings, "active-provider", id);
+ g_object_unref(settings);
}
purple_debug_info("credential-manager", "set active provider to '%s'", id);