From caf389c4e5ac4178c71076b3b360a73056687596 Mon Sep 17 00:00:00 2001 From: Arjan Molenaar Date: Sun, 14 Jan 2024 09:56:05 +0100 Subject: [PATCH 1/2] macos: Add pixbuf formats similar to mime-types Both mime-type and pixbuf-formats rules use `g_content_type_from_mime_type()` to convert their (mime) types to native UTI types. So it's just enough to convert the file types associated with pixbuf-formats to a NSArray of NSStrings. --- gtk/gtkfilefilter.c | 40 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/gtk/gtkfilefilter.c b/gtk/gtkfilefilter.c index 26e5adb0db..995127cccb 100644 --- a/gtk/gtkfilefilter.c +++ b/gtk/gtkfilefilter.c @@ -770,15 +770,21 @@ NSArray * _gtk_file_filter_get_as_pattern_nsstrings (GtkFileFilter *filter) switch (rule->type) { case FILTER_RULE_MIME_TYPE: + case FILTER_RULE_PIXBUF_FORMATS: { + int i; + // GContentType from GIO use UTI on macOS since glib version 2.51 - NSString *uti_nsstring = [NSString stringWithUTF8String: rule->u.content_types[0]]; - if (uti_nsstring == NULL) + for (i = 0; rule->u.content_types[i] != NULL; i++) { - [array release]; - return NULL; + NSString *uti_nsstring = [NSString stringWithUTF8String: rule->u.content_types[i]]; + if (uti_nsstring == NULL) + { + [array release]; + return NULL; + } + [array addObject:uti_nsstring]; } - [array addObject:uti_nsstring]; } break; @@ -802,30 +808,6 @@ NSArray * _gtk_file_filter_get_as_pattern_nsstrings (GtkFileFilter *filter) [array addObject:pattern_nsstring]; } break; - - case FILTER_RULE_PIXBUF_FORMATS: - { - GSList *formats, *l; - - formats = gdk_pixbuf_get_formats (); - for (l = formats; l; l = l->next) - { - int i; - char **extensions; - - extensions = gdk_pixbuf_format_get_extensions (l->data); - - for (i = 0; extensions[i] != NULL; i++) - { - NSString *extension = [NSString stringWithUTF8String: extensions[i]]; - [extension retain]; - [array addObject:extension]; - } - g_strfreev (extensions); - } - g_slist_free (formats); - break; - } } } return array; From 6d0cef41b46f1b2c645eb0233832e3a787050fa0 Mon Sep 17 00:00:00 2001 From: Arjan Molenaar Date: Sun, 14 Jan 2024 10:10:05 +0100 Subject: [PATCH 2/2] macos: fix memory leak in pattern rule conversion No need to retain the pattern. --- gtk/gtkfilefilter.c | 1 - 1 file changed, 1 deletion(-) diff --git a/gtk/gtkfilefilter.c b/gtk/gtkfilefilter.c index 995127cccb..34be24453c 100644 --- a/gtk/gtkfilefilter.c +++ b/gtk/gtkfilefilter.c @@ -804,7 +804,6 @@ NSArray * _gtk_file_filter_get_as_pattern_nsstrings (GtkFileFilter *filter) char *pattern_c = g_string_free (pattern, FALSE); NSString *pattern_nsstring = [NSString stringWithUTF8String:pattern_c]; g_free (pattern_c); - [pattern_nsstring retain]; [array addObject:pattern_nsstring]; } break;