summaryrefslogtreecommitdiff
path: root/src/evbp-mime.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/evbp-mime.c')
-rw-r--r--src/evbp-mime.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/evbp-mime.c b/src/evbp-mime.c
new file mode 100644
index 0000000..1394990
--- /dev/null
+++ b/src/evbp-mime.c
@@ -0,0 +1,88 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "evbp-mime.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <evince-document.h>
+
+static const struct {
+ const gchar *mime;
+ const gchar *exts;
+} mime_suffix[] = {
+ { "application/postscript", "ps" },
+ { "application/x-bzpostscript", "ps.bz2" },
+ { "application/x-gzpostscript", "ps.gz" },
+ { "image/x-eps", "eps,epsi,epsf" },
+ { "image/x-bzeps", "eps.bz2,epsi.bz2,epsf.bz2" },
+ { "image/x-gzeps", "eps.gz,epsi.gz,epsf.gz" },
+ { "image/tiff", "tif,tiff" },
+ { "application/pdf", "pdf" },
+ { "application/x-bzpdf", "pdf.bz2" },
+ { "application/x-gzpdf", "pdf.gz" },
+ { "application/x-ext-pdf", "pdf" },
+ { "application/x-dvi", "dvi" },
+ { "application/x-bzdvi", "dvi.bz2" },
+ { "application/x-gzdvi", "dvi.gz" },
+ { "application/x-cbr", "cbr" },
+ { "application/x-cbz", "cbz" },
+ { "application/x-cb7", "cb7" },
+ { "application/x-cbt", "cbt" },
+ { "image/vnd.djvu", "djvu,djv" },
+};
+static const int n_mime_suffix = sizeof(mime_suffix) / sizeof(mime_suffix[0]);
+
+static const gchar *
+get_suffix(const gchar *type)
+{
+ int i;
+
+ for (i = 0; i < n_mime_suffix; i++)
+ if (strcmp(type, mime_suffix[i].mime) == 0)
+ return mime_suffix[i].exts;
+ return "";
+}
+
+static void
+add_one_mime(EvTypeInfo *type, gpointer udata)
+{
+ GString *mime_desc = udata;
+ const gchar **mime;
+ const gchar *suffix;
+
+ for (mime = type->mime_types; *mime; mime++) {
+ suffix = get_suffix(*mime);
+ if (!suffix)
+ continue;
+ g_string_append_printf(mime_desc, "%s%s:%s:%s",
+ (mime_desc->len > 0) ? ";" : "",
+ *mime, suffix, type->desc);
+ }
+}
+
+static GString *
+build_mime_description(GList *types)
+{
+ GString *mimes = g_string_new(NULL);
+
+ g_list_foreach(types, (GFunc)add_one_mime, mimes);
+ return mimes;
+}
+
+GString *
+evbp_get_mime_description(void)
+{
+ GList *types;
+ GString *mimes;
+
+ types = ev_backends_manager_get_all_types_info();
+ mimes = build_mime_description(types);
+
+ g_list_foreach(types, (GFunc)g_free, NULL);
+ g_list_free(types);
+
+ return mimes;
+}