summaryrefslogtreecommitdiff
path: root/finch
diff options
context:
space:
mode:
authorElliott Sales de Andrade <quantum.analyst@gmail.com>2022-09-19 04:39:05 -0500
committerElliott Sales de Andrade <quantum.analyst@gmail.com>2022-09-19 04:39:05 -0500
commit32b622874c97e766548116f6c6eda75113583ce4 (patch)
treef17374be8c6d853a4e077462a48e1d9ef6c364f6 /finch
parent1b11dfcee74d0d4741fecf07a52d2267adf92b8c (diff)
downloadpidgin-32b622874c97e766548116f6c6eda75113583ce4.tar.gz
Convert GntGf plugin to GSettings
Testing Done: Compile only. Reviewed at https://reviews.imfreedom.org/r/1796/
Diffstat (limited to 'finch')
-rw-r--r--finch/plugins/gntgf/gntgf.c104
-rw-r--r--finch/plugins/gntgf/im.pidgin.Finch.plugin.GntGf.gschema.xml53
-rw-r--r--finch/plugins/gntgf/meson.build10
3 files changed, 129 insertions, 38 deletions
diff --git a/finch/plugins/gntgf/gntgf.c b/finch/plugins/gntgf/gntgf.c
index ddebeab888..9651b36634 100644
--- a/finch/plugins/gntgf/gntgf.c
+++ b/finch/plugins/gntgf/gntgf.c
@@ -18,18 +18,17 @@
#include NCURSES_HEADER
-#define PREFS_PREFIX "/plugins/gnt/gntgf"
-#define PREFS_EVENT PREFS_PREFIX "/events"
-#define PREFS_EVENT_SIGNONF PREFS_EVENT "/signonf"
-#define PREFS_EVENT_IM_MSG PREFS_EVENT "/immsg"
-#define PREFS_EVENT_CHAT_MSG PREFS_EVENT "/chatmsg"
-#define PREFS_EVENT_CHAT_NICK PREFS_EVENT "/chatnick"
-#define PREFS_BEEP PREFS_PREFIX "/beep"
+#define PREFS_SCHEMA "im.pidgin.Finch.plugin.GntGf"
+#define PREFS_EVENT_SIGN_ON_OFF "event-sign-on-off"
+#define PREFS_EVENT_IM_MSG "event-im-message"
+#define PREFS_EVENT_CHAT_MSG "event-chat-message"
+#define PREFS_EVENT_CHAT_NICK "event-chat-nick"
+#define PREFS_BEEP "beep"
#define MAX_COLS 3
#ifdef HAVE_X11
-#define PREFS_URGENT PREFS_PREFIX "/urgent"
+#define PREFS_URGENT "urgent"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
@@ -148,21 +147,31 @@ notify(PurpleConversation *conv, const char *fmt, ...)
char *str;
int h, w, i;
va_list args;
+ GSettings *settings = NULL;
- if (purple_prefs_get_bool(PREFS_BEEP))
+ settings = g_settings_new_with_backend(PREFS_SCHEMA,
+ purple_core_get_settings_backend());
+
+ if(g_settings_get_boolean(settings, PREFS_BEEP)) {
beep();
+ }
if (conv != NULL) {
FinchConv *fc = FINCH_CONV(conv);
- if (gnt_widget_has_focus(fc->window))
+ if (gnt_widget_has_focus(fc->window)) {
+ g_object_unref(settings);
return;
+ }
}
#ifdef HAVE_X11
- if (purple_prefs_get_bool(PREFS_URGENT))
+ if(g_settings_get_boolean(settings, PREFS_URGENT)) {
urgent();
+ }
#endif
+ g_clear_object(&settings);
+
window = gnt_vbox_new(FALSE);
gnt_widget_set_transient(window, TRUE);
gnt_widget_set_has_border(window, TRUE);
@@ -213,23 +222,47 @@ notify(PurpleConversation *conv, const char *fmt, ...)
static void
buddy_signed_on(PurpleBuddy *buddy, gpointer null)
{
- if (purple_prefs_get_bool(PREFS_EVENT_SIGNONF))
+ GSettings *settings = NULL;
+
+ settings = g_settings_new_with_backend(PREFS_SCHEMA,
+ purple_core_get_settings_backend());
+
+ if(g_settings_get_boolean(settings, PREFS_EVENT_SIGN_ON_OFF)) {
notify(NULL, _("%s just signed on"), purple_buddy_get_alias(buddy));
+ }
+
+ g_object_unref(settings);
}
static void
buddy_signed_off(PurpleBuddy *buddy, gpointer null)
{
- if (purple_prefs_get_bool(PREFS_EVENT_SIGNONF))
+ GSettings *settings = NULL;
+
+ settings = g_settings_new_with_backend(PREFS_SCHEMA,
+ purple_core_get_settings_backend());
+
+ if(g_settings_get_boolean(settings, PREFS_EVENT_SIGN_ON_OFF)) {
notify(NULL, _("%s just signed off"), purple_buddy_get_alias(buddy));
+ }
+
+ g_object_unref(settings);
}
static void
received_im_msg(PurpleAccount *account, const char *sender, const char *msg,
PurpleIMConversation *im, PurpleMessageFlags flags, gpointer null)
{
- if (purple_prefs_get_bool(PREFS_EVENT_IM_MSG))
+ GSettings *settings = NULL;
+
+ settings = g_settings_new_with_backend(PREFS_SCHEMA,
+ purple_core_get_settings_backend());
+
+ if(g_settings_get_boolean(settings, PREFS_EVENT_IM_MSG)) {
notify(PURPLE_CONVERSATION(im), _("%s sent you a message"), sender);
+ }
+
+ g_object_unref(settings);
}
static void
@@ -238,17 +271,28 @@ received_chat_msg(PurpleAccount *account, const char *sender, const char *msg,
{
const char *nick;
PurpleConversation *conv = PURPLE_CONVERSATION(chat);
+ GSettings *settings = NULL;
nick = purple_chat_conversation_get_nick(chat);
- if (g_utf8_collate(sender, nick) == 0)
+ if (g_utf8_collate(sender, nick) == 0) {
return;
+ }
+
+ settings = g_settings_new_with_backend(PREFS_SCHEMA,
+ purple_core_get_settings_backend());
+
+ if(g_settings_get_boolean(settings, PREFS_EVENT_CHAT_NICK) &&
+ purple_utf8_has_word(msg, nick))
+ {
+ notify(conv, _("%s said your nick in %s"), sender,
+ purple_conversation_get_name(conv));
+ } else if(g_settings_get_boolean(settings, PREFS_EVENT_CHAT_MSG)) {
+ notify(conv, _("%s sent a message in %s"), sender,
+ purple_conversation_get_name(conv));
+ }
- if (purple_prefs_get_bool(PREFS_EVENT_CHAT_NICK) &&
- (purple_utf8_has_word(msg, nick)))
- notify(conv, _("%s said your nick in %s"), sender, purple_conversation_get_name(conv));
- else if (purple_prefs_get_bool(PREFS_EVENT_CHAT_MSG))
- notify(conv, _("%s sent a message in %s"), sender, purple_conversation_get_name(conv));
+ g_object_unref(settings);
}
static struct
@@ -257,7 +301,7 @@ static struct
char *display;
} prefs[] =
{
- {PREFS_EVENT_SIGNONF, N_("Buddy signs on/off")},
+ {PREFS_EVENT_SIGN_ON_OFF, N_("Buddy signs on/off")},
{PREFS_EVENT_IM_MSG, N_("You receive an IM")},
{PREFS_EVENT_CHAT_MSG, N_("Someone speaks in a chat")},
{PREFS_EVENT_CHAT_NICK, N_("Someone says your name in a chat")},
@@ -344,22 +388,6 @@ gnt_gf_query(GError **error)
static gboolean
gnt_gf_load(GPluginPlugin *plugin, GError **error) {
- purple_prefs_add_none("/plugins");
- purple_prefs_add_none("/plugins/gnt");
-
- purple_prefs_add_none("/plugins/gnt/gntgf");
- purple_prefs_add_none(PREFS_EVENT);
-
- purple_prefs_add_bool(PREFS_EVENT_SIGNONF, TRUE);
- purple_prefs_add_bool(PREFS_EVENT_IM_MSG, TRUE);
- purple_prefs_add_bool(PREFS_EVENT_CHAT_MSG, TRUE);
- purple_prefs_add_bool(PREFS_EVENT_CHAT_NICK, TRUE);
-
- purple_prefs_add_bool(PREFS_BEEP, TRUE);
-#ifdef HAVE_X11
- purple_prefs_add_bool(PREFS_URGENT, FALSE);
-#endif
-
purple_signal_connect(purple_blist_get_handle(), "buddy-signed-on", plugin,
G_CALLBACK(buddy_signed_on), NULL);
purple_signal_connect(purple_blist_get_handle(), "buddy-signed-off", plugin,
@@ -385,4 +413,4 @@ gnt_gf_unload(GPluginPlugin *plugin, gboolean shutdown, GError **error) {
return TRUE;
}
-GPLUGIN_NATIVE_PLUGIN_DECLARE(gnt_gf) \ No newline at end of file
+GPLUGIN_NATIVE_PLUGIN_DECLARE(gnt_gf)
diff --git a/finch/plugins/gntgf/im.pidgin.Finch.plugin.GntGf.gschema.xml b/finch/plugins/gntgf/im.pidgin.Finch.plugin.GntGf.gschema.xml
new file mode 100644
index 0000000000..f13987bcba
--- /dev/null
+++ b/finch/plugins/gntgf/im.pidgin.Finch.plugin.GntGf.gschema.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<schemalist>
+
+ <schema path="/finch/plugins/gntgf/" id="im.pidgin.Finch.plugin.GntGf">
+ <key name="event-sign-on-off" type="b">
+ <default>true</default>
+ <summary>Notify buddy sign on/off</summary>
+ <description>
+ Notify with a toaster when a buddy signs on/off.
+ </description>
+ </key>
+
+ <key name="event-im-message" type="b">
+ <default>true</default>
+ <summary>Notify IM message</summary>
+ <description>
+ Notify with a toaster when you receive an IM.
+ </description>
+ </key>
+
+ <key name="event-chat-message" type="b">
+ <default>true</default>
+ <summary>Notify chat message</summary>
+ <description>
+ Notify with a toaster when someone speaks in a chat.
+ </description>
+ </key>
+
+ <key name="event-chat-nick" type="b">
+ <default>true</default>
+ <summary>Notify your nick in chat</summary>
+ <description>
+ Notify with a toaster when someone says your name in a chat.
+ </description>
+ </key>
+
+ <key name="beep" type="b">
+ <default>true</default>
+ <summary>Beep</summary>
+ <description>
+ Also beep when notifying.
+ </description>
+ </key>
+
+ <key name="urgent" type="b">
+ <default>false</default>
+ <summary>Set URGENT flag</summary>
+ <description>
+ Set URGENT flag for the terminal window if X11 is supported.
+ </description>
+ </key>
+ </schema>
+</schemalist>
diff --git a/finch/plugins/gntgf/meson.build b/finch/plugins/gntgf/meson.build
index d731fb620e..9084a8799c 100644
--- a/finch/plugins/gntgf/meson.build
+++ b/finch/plugins/gntgf/meson.build
@@ -10,4 +10,14 @@ if x11.found()
install : true, install_dir : FINCH_PLUGINDIR)
endif
+settings_schemas = [
+ 'im.pidgin.Finch.plugin.GntGf.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('FINCH_PLUGIN_PATH', meson.current_build_dir())