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
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
/*
* Copyright (C) 2004 Anders Carlsson <andersca@gnome.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 2, 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include <config.h>
#include "ev-utils.h"
#include "ev-file-helpers.h"
#include <string.h>
#include <glib/gi18n.h>
void
file_chooser_dialog_add_writable_pixbuf_formats (GtkFileChooser *chooser)
{
GSList *pixbuf_formats = NULL;
GSList *iter;
GtkFileFilter *filter;
int i;
filter = gtk_file_filter_new();
gtk_file_filter_set_name (filter, _("By extension"));
g_object_set_data (G_OBJECT(filter), "pixbuf-format", NULL);
gtk_file_chooser_add_filter (chooser, filter);
pixbuf_formats = gdk_pixbuf_get_formats ();
for (iter = pixbuf_formats; iter; iter = iter->next) {
GdkPixbufFormat *format = iter->data;
gchar *description, *name, *extensions;
gchar **extension_list, **mime_types;
if (gdk_pixbuf_format_is_disabled (format) ||
!gdk_pixbuf_format_is_writable (format))
continue;
name = gdk_pixbuf_format_get_description (format);
extension_list = gdk_pixbuf_format_get_extensions (format);
extensions = g_strjoinv (", ", extension_list);
g_strfreev (extension_list);
description = g_strdup_printf ("%s (%s)", name, extensions);
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, description);
g_object_set_data (G_OBJECT (filter), "pixbuf-format", format);
gtk_file_chooser_add_filter (chooser, filter);
g_free (description);
g_free (extensions);
g_free (name);
mime_types = gdk_pixbuf_format_get_mime_types (format);
for (i = 0; mime_types[i] != 0; i++)
gtk_file_filter_add_mime_type (filter, mime_types[i]);
g_strfreev (mime_types);
}
g_slist_free (pixbuf_formats);
}
GdkPixbufFormat*
get_gdk_pixbuf_format_by_extension (gchar *uri)
{
GSList *pixbuf_formats = NULL;
GSList *iter;
int i;
pixbuf_formats = gdk_pixbuf_get_formats ();
for (iter = pixbuf_formats; iter; iter = iter->next) {
gchar **extension_list;
GdkPixbufFormat *format = iter->data;
if (gdk_pixbuf_format_is_disabled (format) ||
!gdk_pixbuf_format_is_writable (format))
continue;
extension_list = gdk_pixbuf_format_get_extensions (format);
for (i = 0; extension_list[i] != 0; i++) {
if (g_str_has_suffix (uri, extension_list[i])) {
g_slist_free (pixbuf_formats);
g_strfreev (extension_list);
return format;
}
}
g_strfreev (extension_list);
}
g_slist_free (pixbuf_formats);
return NULL;
}
|