pidgin/pidgin

Port notification-sound plugin to GSettings

20 months ago, Elliott Sales de Andrade
91aacfd62b5f
Parents d8a78f5c982d
Children 301b7d002cf1
Port notification-sound plugin to GSettings

Not sure about the ID naming scheme, but probably okay.

Testing Done:
Triggered the mute action, and checked that some new time was set in the ini.

Reviewed at https://reviews.imfreedom.org/r/1736/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/plugins/notification-sound/im.pidgin.Purple.plugin.NotificationSound.gschema.xml Sun Sep 11 02:09:40 2022 -0500
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<schemalist>
+ <schema path="/plugins/notification-sound/" id="im.pidgin.Purple.plugin.NotificationSound">
+ <key name="muted" type="b">
+ <default>false</default>
+ <summary>Mute sounds</summary>
+ <description>
+ Whether notification sounds should be muted.
+ </description>
+ </key>
+
+ <key name="mute-until" type="s">
+ <default>''</default>
+ <summary>Mute sounds until date</summary>
+ <description>
+ If notification sounds are muted, then they will be muted until the date
+ in this setting. The string must be a date in ISO8601 format, and will be
+ assumed in UTC if no time zone is specified.
+ </description>
+ </key>
+ </schema>
+</schemalist>
--- a/libpurple/plugins/notification-sound/meson.build Sun Sep 11 00:34:53 2022 -0500
+++ b/libpurple/plugins/notification-sound/meson.build Sun Sep 11 02:09:40 2022 -0500
@@ -8,4 +8,14 @@
install : true, install_dir : PURPLE_PLUGINDIR)
devenv.append('PURPLE_PLUGIN_PATH', meson.current_build_dir())
+
+ settings_schemas = [
+ 'im.pidgin.Purple.plugin.NotificationSound.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))
endif
--- a/libpurple/plugins/notification-sound/notification-sound.c Sun Sep 11 00:34:53 2022 -0500
+++ b/libpurple/plugins/notification-sound/notification-sound.c Sun Sep 11 02:09:40 2022 -0500
@@ -34,9 +34,9 @@
#define PURPLE_NOTIFICATION_SOUND_DOMAIN \
g_quark_from_static_string("purple-notification-sound")
-#define PREF_ROOT "/plugins/core/notification-sound"
-#define PREF_MUTED PREF_ROOT "/muted"
-#define PREF_MUTE_UNTIL PREF_ROOT "/mute_until"
+#define SETTINGS_SCHEMA_ID "im.pidgin.Purple.plugin.NotificationSound"
+#define PREF_MUTED "muted"
+#define PREF_MUTE_UNTIL "mute-until"
/******************************************************************************
* Globals
@@ -50,11 +50,14 @@
*****************************************************************************/
static void
purple_notification_sound_load_prefs(void) {
- const gchar *str_mute_until = NULL;
+ GSettings *settings = NULL;
+ gchar *str_mute_until = NULL;
- muted = purple_prefs_get_bool(PREF_MUTED);
+ settings = g_settings_new_with_backend(SETTINGS_SCHEMA_ID,
+ purple_core_get_settings_backend());
+ muted = g_settings_get_boolean(settings, PREF_MUTED);
- str_mute_until = purple_prefs_get_string(PREF_MUTE_UNTIL);
+ str_mute_until = g_settings_get_string(settings, PREF_MUTE_UNTIL);
if(str_mute_until != NULL && *str_mute_until != '\0') {
GTimeZone *tz = g_time_zone_new_utc();
@@ -62,19 +65,28 @@
g_time_zone_unref(tz);
}
+
+ g_free(str_mute_until);
+ g_object_unref(settings);
}
static void
purple_notification_sound_save_prefs(void) {
- gchar *str_mute_until = NULL;
+ GSettings *settings = NULL;
+
+ settings = g_settings_new_with_backend(SETTINGS_SCHEMA_ID,
+ purple_core_get_settings_backend());
+ g_settings_set_boolean(settings, PREF_MUTED, muted);
if(mute_until != NULL) {
- str_mute_until = g_date_time_format_iso8601(mute_until);
+ gchar *str_mute_until = g_date_time_format_iso8601(mute_until);
+ g_settings_set_string(settings, PREF_MUTE_UNTIL, str_mute_until);
+ g_free(str_mute_until);
+ } else {
+ g_settings_set_string(settings, PREF_MUTE_UNTIL, "");
}
- purple_prefs_set_bool(PREF_MUTED, muted);
- purple_prefs_set_string(PREF_MUTE_UNTIL, str_mute_until);
- g_free(str_mute_until);
+ g_object_unref(settings);
}
static void
@@ -252,10 +264,6 @@
return FALSE;
}
- purple_prefs_add_none(PREF_ROOT);
- purple_prefs_add_string(PREF_MUTE_UNTIL, NULL);
- purple_prefs_add_bool(PREF_MUTED, FALSE);
-
purple_notification_sound_load_prefs();
conv_handle = purple_conversations_get_handle();