pidgin/pidgin

Port join/part hiding plugin to GSettings

20 months ago, Elliott Sales de Andrade
5c008004a1af
Parents 149e5ba1e807
Children 349f2a6eb4a0
Port join/part hiding plugin to GSettings

Also fix a little bit of brace styling.

Testing Done:
Compile and load only.

Reviewed at https://reviews.imfreedom.org/r/1739/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/plugins/joinpart/im.pidgin.Purple.plugin.JoinPart.gschema.xml Mon Sep 12 10:01:28 2022 -0500
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<schemalist>
+ <schema path="/plugins/joinpart/" id="im.pidgin.Purple.plugin.JoinPart">
+ <key name="threshold" type="i">
+ <default>20</default>
+ <range min="0" max="1000"/>
+ <summary>Room size threshold</summary>
+ <description>
+ The number of people that must be in a room for this plugin to have any
+ effect.
+ </description>
+ </key>
+
+ <key name="delay" type="i">
+ <default>10</default>
+ <range min="0" max="480"/><!-- 8 hours maximum -->
+ <summary>Delay</summary>
+ <description>
+ The number of minutes before a person is considered to have stopped
+ being part of active conversation.
+ </description>
+ </key>
+
+ <key name="hide-buddies" type="b">
+ <default>false</default>
+ <summary>Hide buddies</summary>
+ <description>
+ Whether to apply hiding rules to buddies also.
+ </description>
+ </key>
+ </schema>
+</schemalist>
--- a/libpurple/plugins/joinpart/joinpart.c Mon Sep 12 05:08:59 2022 -0500
+++ b/libpurple/plugins/joinpart/joinpart.c Mon Sep 12 10:01:28 2022 -0500
@@ -31,20 +31,18 @@
/* Preferences */
+#define SETTINGS_SCHEMA_ID "im.pidgin.Purple.plugin.JoinPart"
-/* The number of minutes before a person is considered
- * to have stopped being part of active conversation. */
-#define DELAY_PREF "/plugins/core/joinpart/delay"
-#define DELAY_DEFAULT 10
+/* The number of minutes before a person is considered to have stopped being
+ * part of active conversation. */
+#define DELAY_PREF "delay"
-/* The number of people that must be in a room for this
- * plugin to have any effect */
-#define THRESHOLD_PREF "/plugins/core/joinpart/threshold"
-#define THRESHOLD_DEFAULT 20
+/* The number of people that must be in a room for this plugin to have any
+ * effect */
+#define THRESHOLD_PREF "threshold"
/* Hide buddies */
-#define HIDE_BUDDIES_PREF "/plugins/core/joinpart/hide_buddies"
-#define HIDE_BUDDIES_DEFAULT FALSE
+#define HIDE_BUDDIES_PREF "hide-buddies"
struct joinpart_key
{
@@ -61,10 +59,11 @@
static gboolean joinpart_key_equal(const struct joinpart_key *a, const struct joinpart_key *b)
{
- if (a == NULL)
+ if (a == NULL) {
return (b == NULL);
- else if (b == NULL)
+ } else if (b == NULL) {
return FALSE;
+ }
return (a->conv == b->conv) && purple_strequal(a->user, b->user);
}
@@ -80,6 +79,7 @@
static gboolean should_hide_notice(PurpleConversation *conv, const char *name,
GHashTable *users)
{
+ GSettings *settings = NULL;
PurpleChatConversation *chat;
guint threshold;
struct joinpart_key key;
@@ -88,27 +88,37 @@
g_return_val_if_fail(conv != NULL, FALSE);
g_return_val_if_fail(PURPLE_IS_CHAT_CONVERSATION(conv), FALSE);
+ settings = g_settings_new_with_backend(SETTINGS_SCHEMA_ID,
+ purple_core_get_settings_backend());
+
/* If the room is small, don't bother. */
chat = PURPLE_CHAT_CONVERSATION(conv);
- threshold = purple_prefs_get_int(THRESHOLD_PREF);
- if (purple_chat_conversation_get_users_count(chat) < threshold)
+ threshold = g_settings_get_int(settings, THRESHOLD_PREF);
+ if (purple_chat_conversation_get_users_count(chat) < threshold) {
+ g_object_unref(settings);
return FALSE;
+ }
- if (!purple_prefs_get_bool(HIDE_BUDDIES_PREF) &&
- purple_blist_find_buddy(purple_conversation_get_account(conv), name))
+ if (!g_settings_get_boolean(settings, HIDE_BUDDIES_PREF) &&
+ purple_blist_find_buddy(purple_conversation_get_account(conv), name)) {
+ g_object_unref(settings);
return FALSE;
+ }
/* Only show the notice if the user has spoken recently. */
key.conv = conv;
key.user = (gchar *)name;
last_said = g_hash_table_lookup(users, &key);
- if (last_said != NULL)
- {
- int delay = purple_prefs_get_int(DELAY_PREF);
- if (delay > 0 && (*last_said + (delay * 60)) >= time(NULL))
+ if (last_said != NULL) {
+ int delay = g_settings_get_int(settings, DELAY_PREF);
+ if (delay > 0 && (*last_said + (delay * 60)) >= time(NULL)) {
+ g_object_unref(settings);
return FALSE;
+ }
}
+ g_object_unref(settings);
+
return TRUE;
}
@@ -137,13 +147,10 @@
key.conv = conv;
key.user = sender;
last_said = g_hash_table_lookup(users, &key);
- if (last_said != NULL)
- {
+ if (last_said != NULL) {
/* They just said something, so update the time. */
time(last_said);
- }
- else
- {
+ } else {
struct joinpart_key *key2;
key2 = g_new(struct joinpart_key, 1);
@@ -166,8 +173,16 @@
static gboolean clean_users_hash(GHashTable *users)
{
- int delay = purple_prefs_get_int(DELAY_PREF);
- time_t limit = time(NULL) - (60 * delay);
+ GSettings *settings = NULL;
+ gint delay = 0;
+ time_t limit = 0;
+
+ settings = g_settings_new_with_backend(SETTINGS_SCHEMA_ID,
+ purple_core_get_settings_backend());
+ delay = g_settings_get_int(settings, DELAY_PREF);
+ g_object_unref(settings);
+
+ limit = time(NULL) - (60 * delay);
g_hash_table_foreach_remove(users, (GHRFunc)check_expire_time, &limit);
@@ -237,12 +252,6 @@
GHashTable *users;
guint id;
- purple_prefs_add_none("/plugins/core/joinpart");
-
- purple_prefs_add_int(DELAY_PREF, DELAY_DEFAULT);
- purple_prefs_add_int(THRESHOLD_PREF, THRESHOLD_DEFAULT);
- purple_prefs_add_bool(HIDE_BUDDIES_PREF, HIDE_BUDDIES_DEFAULT);
-
users = g_hash_table_new_full((GHashFunc)joinpart_key_hash,
(GEqualFunc)joinpart_key_equal,
(GDestroyNotify)joinpart_key_destroy,
--- a/libpurple/plugins/joinpart/meson.build Mon Sep 12 05:08:59 2022 -0500
+++ b/libpurple/plugins/joinpart/meson.build Mon Sep 12 10:01:28 2022 -0500
@@ -4,4 +4,14 @@
name_prefix : '',
install : true, install_dir : PURPLE_PLUGINDIR)
+settings_schemas = [
+ 'im.pidgin.Purple.plugin.JoinPart.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())