[balsa] compose-window: Use gtk_selection_data_get_uris()



commit bfa22511f7b5a85179304073d48d2e5de8ea7c23
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Fri Jul 3 11:42:13 2020 -0400

    compose-window: Use gtk_selection_data_get_uris()
    
    Use gtk_selection_data_get_uris() instead of our own code.
    
    * src/sendmsg-window.c (attachments_add), (drag_data_quote):

 ChangeLog            |  7 +++++++
 src/sendmsg-window.c | 56 +++++++++++++---------------------------------------
 2 files changed, 21 insertions(+), 42 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 439ec8b85..490726c83 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2020-07-03  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       compose-window: Use gtk_selection_data_get_uris() instead of our
+       own code.
+
+       * src/sendmsg-window.c (attachments_add), (drag_data_quote):
+
 2020-06-28  Peter Bloomfield  <pbloomfield bellsouth net>
 
        compose-window: Make the "Open" option on the urlref-attachment
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index 9edcd2d20..99b4ded8c 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -2083,31 +2083,6 @@ sw_attach_messages_activated(GSimpleAction * action,
 
 
 /* attachments_add - attachments field D&D callback */
-static GSList*
-uri2gslist(const char *uri_list)
-{
-  GSList *list = NULL;
-
-  while (*uri_list) {
-    char       *linebreak = strchr(uri_list, 13);
-    int        length;
-
-    if (!linebreak || linebreak[1] != '\n')
-        return list;
-
-    length = linebreak - uri_list;
-
-    if (length && uri_list[0] != '#') {
-       gchar *this_uri = g_strndup(uri_list, length);
-
-       if (this_uri)
-           list = g_slist_append(list, this_uri);
-      }
-
-    uri_list = linebreak + 2;
-  }
-  return list;
-}
 
 /* Helper: check if the passed parameter contains a valid RFC 2396 URI (leading
  * & trailing whitespaces allowed). Return a newly allocated string with the
@@ -2179,14 +2154,12 @@ attachments_add(GtkWidget * widget,
         }
         balsa_index_selected_msgnos_free(index, selected);
     } else if (info == TARGET_URI_LIST) {
-        GSList *uri_list =
-            uri2gslist((gchar *)
-                       gtk_selection_data_get_data(selection_data));
-        for (; uri_list; uri_list = g_slist_next(uri_list)) {
-           add_attachment(bsmsg, uri_list->data, FALSE, NULL);
-            g_free(uri_list->data);
-        }
-        g_slist_free(uri_list);
+        gchar **uris, **uri;
+
+        uris = gtk_selection_data_get_uris(selection_data);
+        for (uri = uris; uri != NULL; ++uri)
+           add_attachment(bsmsg, *uri, FALSE, NULL);
+        g_strfreev(uris);
     } else if( info == TARGET_STRING) {
        gchar *url =
             rfc2396_uri((gchar *)
@@ -2757,24 +2730,23 @@ drag_data_quote(GtkWidget * widget,
         balsa_index_selected_msgnos_free(index, selected);
         break;
     case TARGET_URI_LIST: {
-        GSList *uri_list =
-            uri2gslist((gchar *)
-                       gtk_selection_data_get_data(selection_data));
-        for (; uri_list; uri_list = g_slist_next(uri_list)) {
+        gchar **uris, **uri;
+
+        uris = gtk_selection_data_get_uris(selection_data);
+
+        for (uri = uris; uri != NULL; ++uri) {
             /* Since current GtkTextView gets this signal twice for
              * every action (#150141) we need to check for duplicates,
              * which is a good idea anyway. */
-           has_file_attached_t find_file;
+           has_file_attached_t find_file = {*uri, FALSE};
 
-           find_file.name = uri_list->data;
-           find_file.found = FALSE;
             if (bsmsg->tree_view)
                 gtk_tree_model_foreach(BALSA_MSG_ATTACH_MODEL(bsmsg),
                                        has_file_attached, &find_file);
             if (!find_file.found)
-                add_attachment(bsmsg, uri_list->data, FALSE, NULL);
+                add_attachment(bsmsg, *uri, FALSE, NULL);
         }
-        g_slist_free_full(uri_list, g_free);
+        g_strfreev(uris);
     }
         break;
     case TARGET_EMAIL:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]