talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit f77e02c92d8b229b8035019462c49c03a0bb8cc9
parent a57e95710c105af765b9dae51db5e9455f80cc47
Author: wwp <subscript@free.fr>
Date:   Mon, 25 Oct 2021 23:38:53 +0200

Subscribe to Webcal: use any URI found in the clipboard.

Diffstat:
Msrc/plugins/vcalendar/vcal_folder.c | 41+++++++++++++++++++++++++++++++++++++++--
1 file changed, 39 insertions(+), 2 deletions(-)

diff --git a/src/plugins/vcalendar/vcal_folder.c b/src/plugins/vcalendar/vcal_folder.c @@ -1,6 +1,6 @@ /* * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2015 Colin Leroy <colin@colino.net> and + * Copyright (C) 1999-2021 Colin Leroy <colin@colino.net> and * the Claws Mail team * * This program is free software; you can redistribute it and/or modify @@ -1958,8 +1958,45 @@ static void subscribe_cal_cb(GtkAction *action, gpointer data) { gchar *uri = NULL; gchar *tmp = NULL; + gchar *clip_text = NULL, *str = NULL; + + clip_text = gtk_clipboard_wait_for_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD)); + + if (clip_text) { + str = clip_text; +#if GLIB_CHECK_VERSION(2,66,0) + GError *error = NULL; + GUri *uri = NULL; + + /* skip any leading white-space */ + while (str && *str && g_ascii_isspace(*str)) + str++; + uri = g_uri_parse(str, G_URI_FLAGS_PARSE_RELAXED, &error); + if (error) { + g_warning("could not parse clipboard text for URI: '%s'", error->message); + g_error_free(error); + } + if (uri) { + gchar* newstr = g_uri_to_string(uri); + + debug_print("URI: '%s' -> '%s'\n", str, newstr ? newstr : "N/A"); + if (newstr) + g_free(newstr); + g_uri_unref(uri); + } else { +#else + if (!is_uri_string(str)) { +#endif + /* if no URL, ignore clipboard text */ + str = NULL; + } + } + + tmp = input_dialog(_("Subscribe to Webcal"), _("Enter the Webcal URL:"), str ? str : ""); + + if (clip_text) + g_free(clip_text); - tmp = input_dialog(_("Subscribe to Webcal"), _("Enter the Webcal URL:"), NULL); if (tmp == NULL) return;