pidgin/pidgin

Port psychic plugin to GSettings

20 months ago, Elliott Sales de Andrade
9ccd10c82e07
Parents 349f2a6eb4a0
Children d57c56146156
Port psychic plugin to GSettings

Also fixes indent in `buddy_typing_cb`, but not in the rest of the file.

Testing Done:
Compile and load only.

Reviewed at https://reviews.imfreedom.org/r/1741/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/plugins/psychic/im.pidgin.Purple.plugin.Psychic.gschema.xml Mon Sep 12 10:03:45 2022 -0500
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<schemalist>
+ <schema path="/plugins/psychic/" id="im.pidgin.Purple.plugin.Psychic">
+ <key name="buddies-only" type="b">
+ <default>false</default>
+ <summary>Buddies only</summary>
+ <description>
+ Only enable for users on the buddy list.
+ </description>
+ </key>
+
+ <key name="show-notice" type="b">
+ <default>true</default>
+ <summary>Show notice in conversations</summary>
+ <description>
+ Display notification message in conversations.
+ </description>
+ </key>
+
+ <key name="activate-online" type="b">
+ <default>true</default>
+ <summary>Online only</summary>
+ <description>
+ Disable when away.
+ </description>
+ </key>
+
+ <key name="raise-conv" type="b">
+ <default>false</default>
+ <summary>Raise conversation</summary>
+ <description>
+ Raise psychic conversations when opened.
+ </description>
+ </key>
+ </schema>
+</schemalist>
--- a/libpurple/plugins/psychic/meson.build Mon Sep 12 10:02:35 2022 -0500
+++ b/libpurple/plugins/psychic/meson.build Mon Sep 12 10:03:45 2022 -0500
@@ -4,4 +4,14 @@
name_prefix : '',
install : true, install_dir : PURPLE_PLUGINDIR)
+settings_schemas = [
+ 'im.pidgin.Purple.plugin.Psychic.gschema.xml',
+]
+
+install_data(settings_schemas, install_dir: schemas_dir)
+gnome.post_install(glib_compile_schemas: true)
+
+# Compile the schemas in the current directory; this is only useful for testing
+gnome.compile_schemas(depend_files: files(settings_schemas))
+
devenv.append('PURPLE_PLUGIN_PATH', meson.current_build_dir())
--- a/libpurple/plugins/psychic/psychic.c Mon Sep 12 10:02:35 2022 -0500
+++ b/libpurple/plugins/psychic/psychic.c Mon Sep 12 10:03:45 2022 -0500
@@ -32,60 +32,69 @@
#define PLUGIN_AUTHORS { "Christopher O'Brien <siege@preoccupied.net>", NULL }
-#define PREFS_BASE "/plugins/core/psychic"
-#define PREF_BUDDIES PREFS_BASE "/buddies_only"
-#define PREF_NOTICE PREFS_BASE "/show_notice"
-#define PREF_STATUS PREFS_BASE "/activate_online"
-#define PREF_RAISE PREFS_BASE "/raise_conv"
+#define SETTINGS_SCHEMA_ID "im.pidgin.Purple.plugin.Psychic"
+#define PREF_BUDDIES "buddies-only"
+#define PREF_NOTICE "show-notice"
+#define PREF_STATUS "activate-online"
+#define PREF_RAISE "raise-conv"
static void
buddy_typing_cb(PurpleAccount *acct, const char *name, void *data) {
- PurpleConversation *im;
- PurpleConversationManager *manager;
+ GSettings *settings = NULL;
+ PurpleConversation *im;
+ PurpleConversationManager *manager;
- if(purple_prefs_get_bool(PREF_STATUS) &&
- ! purple_status_is_available(purple_account_get_active_status(acct))) {
- purple_debug_info("psychic", "not available, doing nothing\n");
- return;
- }
+ settings = g_settings_new_with_backend(SETTINGS_SCHEMA_ID,
+ purple_core_get_settings_backend());
- if(purple_prefs_get_bool(PREF_BUDDIES) &&
- ! purple_blist_find_buddy(acct, name)) {
- purple_debug_info("psychic", "not in blist, doing nothing\n");
- return;
- }
+ if(g_settings_get_boolean(settings, PREF_STATUS) &&
+ !purple_status_is_available(purple_account_get_active_status(acct))) {
+ purple_debug_info("psychic", "not available, doing nothing");
+ g_object_unref(settings);
+ return;
+ }
- if(FALSE == purple_account_privacy_check(acct, name)) {
- purple_debug_info("psychic", "user %s is blocked\n", name);
- return;
- }
+ if(g_settings_get_boolean(settings, PREF_BUDDIES) &&
+ !purple_blist_find_buddy(acct, name)) {
+ purple_debug_info("psychic", "not in blist, doing nothing");
+ g_object_unref(settings);
+ return;
+ }
+
+ if(!purple_account_privacy_check(acct, name)) {
+ purple_debug_info("psychic", "user %s is blocked", name);
+ g_object_unref(settings);
+ return;
+ }
- manager = purple_conversation_manager_get_default();
- im = purple_conversation_manager_find_im(manager, acct, name);
- if(! im) {
- purple_debug_info("psychic", "no previous conversation exists\n");
- im = purple_im_conversation_new(acct, name);
+ manager = purple_conversation_manager_get_default();
+ im = purple_conversation_manager_find_im(manager, acct, name);
+ if(im == NULL) {
+ purple_debug_info("psychic", "no previous conversation exists");
+ im = purple_im_conversation_new(acct, name);
- if(purple_prefs_get_bool(PREF_RAISE)) {
- purple_conversation_present(im);
- }
-
- if(purple_prefs_get_bool(PREF_NOTICE)) {
+ if(g_settings_get_boolean(settings, PREF_RAISE)) {
+ purple_conversation_present(im);
+ }
- /* This is a quote from Star Wars. You should probably not
- translate it literally. If you can't find a fitting cultural
- reference in your language, consider translating something
- like this instead: "You feel a new message coming." */
- purple_conversation_write_system_message(im,
- _("You feel a disturbance in the force..."),
- PURPLE_MESSAGE_NO_LOG | PURPLE_MESSAGE_ACTIVE_ONLY);
- }
+ if(g_settings_get_boolean(settings, PREF_NOTICE)) {
+ /* This is a quote from Star Wars. You should probably not
+ translate it literally. If you can't find a fitting cultural
+ reference in your language, consider translating something
+ like this instead: "You feel a new message coming." */
+ purple_conversation_write_system_message(
+ im,
+ _("You feel a disturbance in the force..."),
+ PURPLE_MESSAGE_NO_LOG | PURPLE_MESSAGE_ACTIVE_ONLY);
+ }
- /* Necessary because we may be creating a new conversation window. */
- purple_im_conversation_set_typing_state(PURPLE_IM_CONVERSATION(im),
- PURPLE_IM_TYPING);
- }
+ /* Necessary because we may be creating a new conversation window. */
+ purple_im_conversation_set_typing_state(PURPLE_IM_CONVERSATION(im),
+ PURPLE_IM_TYPING);
+ }
+
+ g_object_unref(settings);
}
@@ -144,11 +153,6 @@
void *convs_handle;
- purple_prefs_add_none(PREFS_BASE);
- purple_prefs_add_bool(PREF_BUDDIES, FALSE);
- purple_prefs_add_bool(PREF_NOTICE, TRUE);
- purple_prefs_add_bool(PREF_STATUS, TRUE);
-
convs_handle = purple_conversations_get_handle();
purple_signal_connect(convs_handle, "buddy-typing", plugin,