diff options
author | Elliott Sales de Andrade <quantum.analyst@gmail.com> | 2022-09-19 04:36:38 -0500 |
---|---|---|
committer | Elliott Sales de Andrade <quantum.analyst@gmail.com> | 2022-09-19 04:36:38 -0500 |
commit | 1b11dfcee74d0d4741fecf07a52d2267adf92b8c (patch) | |
tree | e71bd4cdbc22a75749214746992c8fb469ff1f7c /finch/plugins | |
parent | 7c7330b1a187fc1c55620ce562f4ebf2084af272 (diff) | |
download | pidgin-1b11dfcee74d0d4741fecf07a52d2267adf92b8c.tar.gz |
Convert Finch TinyURL plugin to GSettings
Testing Done:
Compile only.
Reviewed at https://reviews.imfreedom.org/r/1798/
Diffstat (limited to 'finch/plugins')
-rw-r--r-- | finch/plugins/gnttinyurl/gnttinyurl.c | 50 | ||||
-rw-r--r-- | finch/plugins/gnttinyurl/im.pidgin.Finch.plugin.TinyURL.gschema.xml | 20 | ||||
-rw-r--r-- | finch/plugins/gnttinyurl/meson.build | 10 |
3 files changed, 66 insertions, 14 deletions
diff --git a/finch/plugins/gnttinyurl/gnttinyurl.c b/finch/plugins/gnttinyurl/gnttinyurl.c index 90cdc1f993..7f1730b133 100644 --- a/finch/plugins/gnttinyurl/gnttinyurl.c +++ b/finch/plugins/gnttinyurl/gnttinyurl.c @@ -21,9 +21,9 @@ #include <glib.h> #include <libsoup/soup.h> -#define PREFS_BASE "/plugins/gnt/tinyurl" -#define PREF_LENGTH PREFS_BASE "/length" -#define PREF_URL PREFS_BASE "/url" +#define PREFS_SCHEMA "im.pidgin.Finch.plugin.TinyURL" +#define PREF_LENGTH "length" +#define PREF_URL "url" #include <purple.h> @@ -235,6 +235,8 @@ static gboolean writing_msg(PurpleConversation *conv, PurpleMessage *msg, gpoint GString *t; GList *iter, *urls, *next; int c = 0; + GSettings *settings = NULL; + gint min_url_length; if (purple_message_get_flags(msg) & (PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_INVISIBLE)) return FALSE; @@ -245,10 +247,15 @@ static gboolean writing_msg(PurpleConversation *conv, PurpleMessage *msg, gpoint if (!urls) return FALSE; + settings = g_settings_new_with_backend(PREFS_SCHEMA, + purple_core_get_settings_backend()); + min_url_length = g_settings_get_int(settings, PREF_LENGTH); + g_object_unref(settings); + t = g_string_new(g_strdup(purple_message_get_contents(msg))); for (iter = urls; iter; iter = next) { next = iter->next; - if (g_utf8_strlen((char *)iter->data, -1) >= purple_prefs_get_int(PREF_LENGTH)) { + if (g_utf8_strlen((char *)iter->data, -1) >= min_url_length) { int pos, x = 0; gchar *j, *s, *str, *orig; glong len = g_utf8_strlen(iter->data, -1); @@ -300,6 +307,13 @@ process_urls(PurpleConversation *conv, GList *urls) int c; FinchConv *fconv = FINCH_CONV(conv); GntTextView *tv = GNT_TEXT_VIEW(fconv->tv); + GSettings *settings = NULL; + gchar *tinyurl_prefix = NULL; + + settings = g_settings_new_with_backend(PREFS_SCHEMA, + purple_core_get_settings_backend()); + tinyurl_prefix = g_settings_get_string(settings, PREF_URL); + g_object_unref(settings); for (iter = urls, c = 1; iter; iter = iter->next, c++) { int i; @@ -329,9 +343,11 @@ process_urls(PurpleConversation *conv, GList *urls) cbdata->tag = g_strdup_printf("%s%d", "tiny_", tag_num++); cbdata->conv = conv; if (g_ascii_strncasecmp(original_url, "http://", 7) && g_ascii_strncasecmp(original_url, "https://", 8)) { - url = g_strdup_printf("%shttp%%3A%%2F%%2F%s", purple_prefs_get_string(PREF_URL), purple_url_encode(original_url)); + url = g_strdup_printf("%shttp%%3A%%2F%%2F%s", tinyurl_prefix, + purple_url_encode(original_url)); } else { - url = g_strdup_printf("%s%s", purple_prefs_get_string(PREF_URL), purple_url_encode(original_url)); + url = g_strdup_printf("%s%s", tinyurl_prefix, + purple_url_encode(original_url)); } msg = soup_message_new("GET", url); soup_session_queue_message(session, msg, url_fetched, cbdata); @@ -343,6 +359,7 @@ process_urls(PurpleConversation *conv, GList *urls) g_free(url); } g_list_free(urls); + g_free(tinyurl_prefix); } static void @@ -400,6 +417,8 @@ tinyurl_notify_uri(const char *uri) GntWidget *win; SoupMessage *msg; const gchar *tiny_url; + GSettings *settings = NULL; + gchar *tinyurl_prefix = NULL; /* XXX: The following expects that finch_notify_message gets called. This * may not always happen, e.g. when another plugin sets its own @@ -415,14 +434,21 @@ tinyurl_notify_uri(const char *uri) return win; } + settings = g_settings_new_with_backend(PREFS_SCHEMA, + purple_core_get_settings_backend()); + tinyurl_prefix = g_settings_get_string(settings, PREF_URL); + g_object_unref(settings); + if (g_ascii_strncasecmp(uri, "http://", 7) && g_ascii_strncasecmp(uri, "https://", 8)) { - fullurl = g_strdup_printf("%shttp%%3A%%2F%%2F%s", - purple_prefs_get_string(PREF_URL), purple_url_encode(uri)); + fullurl = g_strdup_printf("%shttp%%3A%%2F%%2F%s", tinyurl_prefix, + purple_url_encode(uri)); } else { - fullurl = g_strdup_printf("%s%s", purple_prefs_get_string(PREF_URL), - purple_url_encode(uri)); + fullurl = g_strdup_printf("%s%s", tinyurl_prefix, + purple_url_encode(uri)); } + g_free(tinyurl_prefix); + g_object_set_data_full(G_OBJECT(win), "gnttinyurl-original", g_strdup(uri), g_free); /* Store the SoupMessage and cancel that when the window is destroyed, @@ -485,10 +511,6 @@ tiny_url_load(GPluginPlugin *plugin, GError **error) { session = soup_session_new(); - purple_prefs_add_none(PREFS_BASE); - purple_prefs_add_int(PREF_LENGTH, 30); - purple_prefs_add_string(PREF_URL, "http://tinyurl.com/api-create.php?url="); - g_object_set_data(G_OBJECT(plugin), "notify-uri", ops->notify_uri); ops->notify_uri = tinyurl_notify_uri; diff --git a/finch/plugins/gnttinyurl/im.pidgin.Finch.plugin.TinyURL.gschema.xml b/finch/plugins/gnttinyurl/im.pidgin.Finch.plugin.TinyURL.gschema.xml new file mode 100644 index 0000000000..a286cc21f1 --- /dev/null +++ b/finch/plugins/gnttinyurl/im.pidgin.Finch.plugin.TinyURL.gschema.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<schemalist> + <schema path="/finch/plugins/tinyurl/" id="im.pidgin.Finch.plugin.TinyURL"> + <key name="length" type="i"> + <default>30</default> + <summary>Minimum conversion length</summary> + <description> + Only create TinyURL for URLs of this length or greater. + </description> + </key> + + <key name="url" type="s"> + <default>"http://tinyurl.com/api-create.php?url="</default> + <summary>URL generator prefix</summary> + <description> + TinyURL (or other) address prefix. + </description> + </key> + </schema> +</schemalist> diff --git a/finch/plugins/gnttinyurl/meson.build b/finch/plugins/gnttinyurl/meson.build index 907358795d..bf93f60817 100644 --- a/finch/plugins/gnttinyurl/meson.build +++ b/finch/plugins/gnttinyurl/meson.build @@ -4,4 +4,14 @@ library('gnttinyurl', 'gnttinyurl.c', name_prefix : '', install : true, install_dir : FINCH_PLUGINDIR) +settings_schemas = [ + 'im.pidgin.Finch.plugin.TinyURL.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()) |