1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimppixbuf.c
* Copyright (C) 2005 Michael Natterer <mitch@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include "widgets-types.h"
#include "gimppixbuf.h"
/* local function prototypes */
static gint gimp_pixbuf_format_compare (GdkPixbufFormat *a,
GdkPixbufFormat *b);
/* public functions */
GSList *
gimp_pixbuf_get_formats (void)
{
return g_slist_sort (gdk_pixbuf_get_formats (),
(GCompareFunc) gimp_pixbuf_format_compare);
}
void
gimp_pixbuf_targets_add (GtkTargetList *target_list,
guint info,
gboolean writable)
{
GSList *formats;
GSList *list;
g_return_if_fail (target_list != NULL);
formats = gimp_pixbuf_get_formats ();
for (list = formats; list; list = g_slist_next (list))
{
GdkPixbufFormat *format = list->data;
gchar **mime_types;
gchar **type;
if (writable && ! gdk_pixbuf_format_is_writable (format))
continue;
mime_types = gdk_pixbuf_format_get_mime_types (format);
for (type = mime_types; *type; type++)
{
/* skip Windows ICO as writable format */
if (writable && strcmp (*type, "image/x-icon") == 0)
continue;
gtk_target_list_add (target_list,
gdk_atom_intern (*type, FALSE), 0, info);
}
g_strfreev (mime_types);
}
g_slist_free (formats);
}
void
gimp_pixbuf_targets_remove (GtkTargetList *target_list)
{
GSList *formats;
GSList *list;
g_return_if_fail (target_list != NULL);
formats = gimp_pixbuf_get_formats ();
for (list = formats; list; list = g_slist_next (list))
{
GdkPixbufFormat *format = list->data;
gchar **mime_types;
gchar **type;
mime_types = gdk_pixbuf_format_get_mime_types (format);
for (type = mime_types; *type; type++)
{
gtk_target_list_remove (target_list,
gdk_atom_intern (*type, FALSE));
}
g_strfreev (mime_types);
}
g_slist_free (formats);
}
/* private functions */
static gint
gimp_pixbuf_format_compare (GdkPixbufFormat *a,
GdkPixbufFormat *b)
{
gchar *a_name = gdk_pixbuf_format_get_name (a);
gchar *b_name = gdk_pixbuf_format_get_name (b);
gint retval = 0;
/* move PNG to the front of the list */
if (strcmp (a_name, "png") == 0)
retval = -1;
else if (strcmp (b_name, "png") == 0)
retval = 1;
/* move JPEG to the end of the list */
else if (strcmp (a_name, "jpeg") == 0)
retval = 1;
else if (strcmp (b_name, "jpeg") == 0)
retval = -1;
/* move GIF to the end of the list */
else if (strcmp (a_name, "gif") == 0)
retval = 1;
else if (strcmp (b_name, "gif") == 0)
retval = -1;
g_free (a_name);
g_free (b_name);
return retval;
}
|