summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw44@gmail.com>2013-08-24 13:13:28 +0800
committerLAN-TW <lantw44@gmail.com>2013-08-24 13:13:28 +0800
commit055e5141c35445c316a1c8f3d34d6c9ad6833a35 (patch)
tree39ef5ebe5ffb965ec2fb0bce7cc0dc7a9896da05
parentdb0d3891b16d9932f4e7234b6db091f65811de5d (diff)
downloadgsoc2013-libgnome-autoar-055e5141c35445c316a1c8f3d34d6c9ad6833a35.tar
gsoc2013-libgnome-autoar-055e5141c35445c316a1c8f3d34d6c9ad6833a35.tar.gz
gsoc2013-libgnome-autoar-055e5141c35445c316a1c8f3d34d6c9ad6833a35.tar.bz2
gsoc2013-libgnome-autoar-055e5141c35445c316a1c8f3d34d6c9ad6833a35.tar.lz
gsoc2013-libgnome-autoar-055e5141c35445c316a1c8f3d34d6c9ad6833a35.tar.xz
gsoc2013-libgnome-autoar-055e5141c35445c316a1c8f3d34d6c9ad6833a35.tar.zst
gsoc2013-libgnome-autoar-055e5141c35445c316a1c8f3d34d6c9ad6833a35.zip
Add functions related to archive formats and filters
-rw-r--r--data/Makefile.am2
-rw-r--r--data/org.gnome.desktop.archives.gschema.xml4
-rw-r--r--gnome-autoar/Makefile.am3
-rw-r--r--gnome-autoar/autoar-create.c117
-rw-r--r--gnome-autoar/autoar-format-filter.c251
-rw-r--r--gnome-autoar/autoar-format-filter.h86
-rw-r--r--gnome-autoar/autoar-pref.c32
-rw-r--r--gnome-autoar/autoar-pref.h43
-rw-r--r--gnome-autoar/autoar.h1
9 files changed, 380 insertions, 159 deletions
diff --git a/data/Makefile.am b/data/Makefile.am
index e5bc336..5208251 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -3,7 +3,7 @@
NULL =
gsettings_ENUM_NAMESPACE = org.gnome.desktop.archives
-gsettings_ENUM_FILES = $(top_srcdir)/gnome-autoar/autoar-pref.h
+gsettings_ENUM_FILES = $(top_srcdir)/gnome-autoar/autoar-format-filter.h
gsettings_SCHEMAS = org.gnome.desktop.archives.gschema.xml
diff --git a/data/org.gnome.desktop.archives.gschema.xml b/data/org.gnome.desktop.archives.gschema.xml
index 27c28a3..68da026 100644
--- a/data/org.gnome.desktop.archives.gschema.xml
+++ b/data/org.gnome.desktop.archives.gschema.xml
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<schema path="/org/gnome/desktop/archives/" id="org.gnome.desktop.archives">
- <key name="default-format" enum="org.gnome.desktop.archives.AutoarPrefFormat">
+ <key name="default-format" enum="org.gnome.desktop.archives.AutoarFormat">
<default>'zip'</default>
<summary>Default file format for new archives (archive creation)</summary>
<description>The default file format used to create new archives.</description>
</key>
- <key name="default-filter" enum="org.gnome.desktop.archives.AutoarPrefFilter">
+ <key name="default-filter" enum="org.gnome.desktop.archives.AutoarFilter">
<default>'none'</default>
<summary>Default filter to create archives (archive creation)</summary>
<description>The default filter used to compress new archives.</description>
diff --git a/gnome-autoar/Makefile.am b/gnome-autoar/Makefile.am
index 0cdc2ed..155032d 100644
--- a/gnome-autoar/Makefile.am
+++ b/gnome-autoar/Makefile.am
@@ -15,12 +15,14 @@ libgnome_autoar_h_sources = \
autoar-common.h \
autoar-create.h \
autoar-extract.h \
+ autoar-format-filter.h \
autoar-pref.h \
$(NULL)
libgnome_autoar_c_sources = \
autoar-common.c \
autoar-create.c \
autoar-extract.c \
+ autoar-format-filter.c \
autoar-pref.c \
$(NULL)
libgnome_autoar_generated_sources = \
@@ -44,6 +46,7 @@ libgnome_autoar_la_CPPFLAGS = \
$(NULL)
libgnome_autoar_la_CFLAGS = \
$(DEPENDENCIES_CFLAGS) \
+ -I$(top_srcdir) \
$(AM_CFLAGS) \
$(NULL)
diff --git a/gnome-autoar/autoar-create.c b/gnome-autoar/autoar-create.c
index c94eb7c..8f72607 100644
--- a/gnome-autoar/autoar-create.c
+++ b/gnome-autoar/autoar-create.c
@@ -1010,10 +1010,8 @@ autoar_create_new (AutoarPref *arpref,
static void
autoar_create_run (AutoarCreate *arcreate)
{
- AutoarPrefFormat format;
- AutoarPrefFilter filter;
- const char *format_extension;
- const char *filter_extension;
+ AutoarFormat format;
+ AutoarFilter filter;
AutoarCreatePrivate *priv;
int i, r;
@@ -1034,100 +1032,12 @@ autoar_create_run (AutoarCreate *arcreate)
format = autoar_pref_get_default_format (priv->arpref);
filter = autoar_pref_get_default_filter (priv->arpref);
- g_return_if_fail (format > 0 && format < AUTOAR_PREF_FORMAT_LAST);
- g_return_if_fail (filter > 0 && filter < AUTOAR_PREF_FILTER_LAST);
+ g_return_if_fail (format > 0 && format < AUTOAR_FORMAT_LAST);
+ g_return_if_fail (filter > 0 && filter < AUTOAR_FILTER_LAST);
archive_write_set_bytes_in_last_block (priv->a, 1);
- switch (filter) {
- case AUTOAR_PREF_FILTER_COMPRESS:
- archive_write_add_filter_compress (priv->a);
- filter_extension = ".Z";
- break;
- case AUTOAR_PREF_FILTER_GZIP:
- archive_write_add_filter_gzip (priv->a);
- filter_extension = ".gz";
- break;
- case AUTOAR_PREF_FILTER_BZIP2:
- archive_write_add_filter_bzip2 (priv->a);
- filter_extension = ".bz2";
- break;
- case AUTOAR_PREF_FILTER_XZ:
- archive_write_add_filter_xz (priv->a);
- filter_extension = ".xz";
- break;
- case AUTOAR_PREF_FILTER_LZMA:
- archive_write_add_filter_lzma (priv->a);
- filter_extension = ".lzma";
- break;
- case AUTOAR_PREF_FILTER_LZIP:
- archive_write_add_filter_lzip (priv->a);
- filter_extension = ".lz";
- break;
- case AUTOAR_PREF_FILTER_LZOP:
- archive_write_add_filter_lzop (priv->a);
- filter_extension = ".lzo";
- break;
- case AUTOAR_PREF_FILTER_GRZIP:
- archive_write_add_filter_grzip (priv->a);
- filter_extension = ".grz";
- break;
- case AUTOAR_PREF_FILTER_LRZIP:
- archive_write_add_filter_lrzip (priv->a);
- filter_extension = ".lrz";
- break;
- case AUTOAR_PREF_FILTER_NONE:
- default:
- filter_extension = "";
- }
-
- switch (format) {
- case AUTOAR_PREF_FORMAT_ZIP:
- archive_write_set_format_zip (priv->a);
- format_extension = ".zip";
- break;
- case AUTOAR_PREF_FORMAT_TAR:
- archive_write_set_format_pax_restricted (priv->a);
- format_extension = ".tar";
- break;
- case AUTOAR_PREF_FORMAT_CPIO:
- archive_write_set_format_cpio (priv->a);
- format_extension = ".cpio";
- break;
- case AUTOAR_PREF_FORMAT_7ZIP:
- archive_write_set_format_7zip (priv->a);
- format_extension = ".7z";
- break;
- case AUTOAR_PREF_FORMAT_AR_BSD:
- archive_write_set_format_ar_bsd (priv->a);
- format_extension = ".a";
- break;
- case AUTOAR_PREF_FORMAT_AR_SVR4:
- archive_write_set_format_ar_svr4 (priv->a);
- format_extension = ".a";
- break;
- case AUTOAR_PREF_FORMAT_CPIO_NEWC:
- archive_write_set_format_cpio_newc (priv->a);
- format_extension = ".cpio";
- break;
- case AUTOAR_PREF_FORMAT_GNUTAR:
- archive_write_set_format_gnutar (priv->a);
- format_extension = ".tar";
- break;
- case AUTOAR_PREF_FORMAT_ISO9660:
- archive_write_set_format_iso9660 (priv->a);
- format_extension = ".iso";
- break;
- case AUTOAR_PREF_FORMAT_PAX:
- archive_write_set_format_pax (priv->a);
- format_extension = ".tar";
- break;
- case AUTOAR_PREF_FORMAT_XAR:
- archive_write_set_format_xar (priv->a);
- format_extension = ".xar";
- break;
- default:
- format_extension = "";
- }
+ archive_write_add_filter (priv->a, autoar_filter_get_filter_libarchive (filter));
+ archive_write_set_format (priv->a, autoar_format_get_format_libarchive (format));
if (g_cancellable_is_cancelled (priv->cancellable)) {
autoar_create_signal_cancelled (arcreate);
@@ -1173,12 +1083,12 @@ autoar_create_run (AutoarCreate *arcreate)
{
char *dest_basename;
+ char *extension;
file_output = g_file_new_for_commandline_arg (priv->output);
+ extension = autoar_format_filter_get_extension (format, filter);
dest_basename = g_strconcat (priv->source_basename_noext,
- format_extension,
- filter_extension,
- NULL);
+ extension, NULL);
file_dest = g_file_get_child (file_output, dest_basename);
for (i = 1; g_file_query_exists (file_dest, priv->cancellable); i++) {
@@ -1188,18 +1098,19 @@ autoar_create_run (AutoarCreate *arcreate)
if (g_cancellable_is_cancelled (priv->cancellable)) {
autoar_create_signal_cancelled (arcreate);
g_object_unref (file_output);
+ g_free (extension);
return;
}
- dest_basename = g_strdup_printf ("%s(%d)%s%s",
+ extension = autoar_format_filter_get_extension (format, filter);
+ dest_basename = g_strdup_printf ("%s(%d)%s",
priv->source_basename_noext,
- i,
- format_extension,
- filter_extension);
+ i, extension);
file_dest = g_file_get_child (file_output, dest_basename);
}
g_free (dest_basename);
+ g_free (extension);
}
{
diff --git a/gnome-autoar/autoar-format-filter.c b/gnome-autoar/autoar-format-filter.c
new file mode 100644
index 0000000..ba886d4
--- /dev/null
+++ b/gnome-autoar/autoar-format-filter.c
@@ -0,0 +1,251 @@
+/* vim: set sw=2 ts=2 sts=2 et: */
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * autoar-format-filter.c
+ * Functions related to archive formats and filters
+ *
+ * Copyright (C) 2013 Ting-Wei Lan
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include "autoar-format-filter.h"
+
+#include <archive.h>
+#include <gio/gio.h>
+#include <glib.h>
+
+typedef struct _AutoarFormatDescription AutoarFormatDescription;
+typedef struct _AutoarFilterDescription AutoarFilterDescription;
+
+struct _AutoarFormatDescription
+{
+ AutoarFormat format;
+ int libarchive_format;
+ char *extension;
+ char *keyword;
+ char *mime_type;
+ char *description;
+};
+
+struct _AutoarFilterDescription
+{
+ AutoarFilter filter;
+ int libarchive_filter;
+ char *extension;
+ char *keyword;
+ char *mime_type;
+ char *description;
+};
+
+static AutoarFormatDescription autoar_format_description[] = {
+ { AUTOAR_FORMAT_ZIP, ARCHIVE_FORMAT_ZIP, "zip", "zip",
+ "application/zip", "Zip archive" },
+ { AUTOAR_FORMAT_TAR, ARCHIVE_FORMAT_TAR_PAX_RESTRICTED, "tar", "tar",
+ "application/x-tar", "Tar archive (restricted pax)" },
+ { AUTOAR_FORMAT_CPIO, ARCHIVE_FORMAT_CPIO_POSIX, "cpio", "cpio",
+ "application/x-cpio", "CPIO archive" },
+ { AUTOAR_FORMAT_7ZIP, ARCHIVE_FORMAT_7ZIP, "7z", "7z-compressed",
+ "application/x-7z-compressed", "7-zip archive" },
+ { AUTOAR_FORMAT_AR_BSD, ARCHIVE_FORMAT_AR_BSD, "a", "ar",
+ "application/x-ar", "AR archive (BSD)" },
+ { AUTOAR_FORMAT_AR_SVR4, ARCHIVE_FORMAT_AR_GNU, "a", "ar",
+ "application/x-ar", "AR archive (SVR4)" },
+ { AUTOAR_FORMAT_CPIO_NEWC, ARCHIVE_FORMAT_CPIO_SVR4_NOCRC, "cpio", "sv4cpio",
+ "application/x-sv4cpio", "SV4 CPIO archive" },
+ { AUTOAR_FORMAT_GNUTAR, ARCHIVE_FORMAT_TAR_GNUTAR, "tar", "tar",
+ "application/x-tar", "Tar archive (GNU tar)" },
+ { AUTOAR_FORMAT_ISO9660, ARCHIVE_FORMAT_ISO9660, "iso", "cd-image",
+ "application/x-cd-image", "Raw CD Image" },
+ { AUTOAR_FORMAT_PAX, ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE, "tar", "tar",
+ "application/x-tar", "Tar archive (pax)" },
+ { AUTOAR_FORMAT_USTAR, ARCHIVE_FORMAT_TAR_USTAR, "tar", "tar",
+ "application/x-tar", "Tar archive (ustar)" },
+ { AUTOAR_FORMAT_XAR, ARCHIVE_FORMAT_XAR, "xar", "xar",
+ "application/x-xar", "Xar archive" }
+};
+
+static AutoarFilterDescription autoar_filter_description[] = {
+ { AUTOAR_FILTER_NONE, ARCHIVE_FILTER_NONE, "", "",
+ "", "" },
+ { AUTOAR_FILTER_COMPRESS, ARCHIVE_FILTER_COMPRESS, "Z", "compress",
+ "application/x-compress", "UNIX-compressed file" },
+ { AUTOAR_FILTER_GZIP, ARCHIVE_FILTER_GZIP, "gz", "gzip",
+ "application/gzip", "Gzip archive" },
+ { AUTOAR_FILTER_BZIP2, ARCHIVE_FILTER_BZIP2, "bz2", "bzip",
+ "application/x-bzip", "Bzip archive" },
+ { AUTOAR_FILTER_XZ, ARCHIVE_FILTER_XZ, "xz", "xz",
+ "application/x-xz", "XZ archive" },
+ { AUTOAR_FILTER_LZMA, ARCHIVE_FILTER_LZMA, "lzma", "lzma",
+ "application/x-lzma", "LZMA archive" },
+ { AUTOAR_FILTER_LZIP, ARCHIVE_FILTER_LZIP, "lz", "lzip",
+ "application/x-lzip", "Lzip archive" },
+ { AUTOAR_FILTER_LZOP, ARCHIVE_FILTER_LZOP, "lzo", "lzop",
+ "application/x-lzop", "LZO archive" },
+ { AUTOAR_FILTER_GRZIP, ARCHIVE_FILTER_GRZIP, "grz", "grzip",
+ "application/x-grzip", "GRZip archive" },
+ { AUTOAR_FILTER_LRZIP, ARCHIVE_FILTER_LRZIP, "lrz", "lrzip",
+ "application/x-lrzip", "Long Range ZIP archive" }
+};
+
+const char*
+autoar_format_get_mime_type (AutoarFormat format)
+{
+ g_return_val_if_fail (format > 0 && format < AUTOAR_FORMAT_LAST, NULL);
+ return autoar_format_description[format - 1].mime_type;
+}
+
+const char*
+autoar_format_get_extension (AutoarFormat format)
+{
+ g_return_val_if_fail (format > 0 && format < AUTOAR_FORMAT_LAST, NULL);
+ return autoar_format_description[format - 1].extension;
+}
+
+const char*
+autoar_format_get_description (AutoarFormat format)
+{
+ g_return_val_if_fail (format > 0 && format < AUTOAR_FORMAT_LAST, NULL);
+ return autoar_format_description[format - 1].description;
+}
+
+int
+autoar_format_get_format_libarchive (AutoarFormat format)
+{
+ g_return_val_if_fail (format > 0 && format < AUTOAR_FORMAT_LAST, -1);
+ return autoar_format_description[format - 1].libarchive_format;
+}
+
+gchar*
+autoar_format_get_description_libarchive (AutoarFormat format)
+{
+ struct archive* a;
+ gchar *str;
+
+ g_return_val_if_fail (format > 0 && format < AUTOAR_FORMAT_LAST, NULL);
+
+ a = archive_write_new ();
+ archive_write_set_format (a, autoar_format_description[format - 1].libarchive_format);
+ str = g_strdup (archive_format_name (a));
+ archive_write_free (a);
+
+ return str;
+}
+
+const char*
+autoar_filter_get_mime_type (AutoarFilter filter)
+{
+ g_return_val_if_fail (filter > 0 && filter < AUTOAR_FILTER_LAST, NULL);
+ return autoar_filter_description[filter - 1].mime_type;
+}
+
+const char*
+autoar_filter_get_extension (AutoarFilter filter)
+{
+ g_return_val_if_fail (filter > 0 && filter < AUTOAR_FILTER_LAST, NULL);
+ return autoar_filter_description[filter - 1].extension;
+}
+
+const char*
+autoar_filter_get_description (AutoarFilter filter)
+{
+ g_return_val_if_fail (filter > 0 && filter < AUTOAR_FILTER_LAST, NULL);
+ return autoar_filter_description[filter - 1].description;
+}
+
+int
+autoar_filter_get_filter_libarchive (AutoarFilter filter)
+{
+ g_return_val_if_fail (filter > 0 && filter < AUTOAR_FILTER_LAST, -1);
+ return autoar_filter_description[filter - 1].libarchive_filter;
+}
+
+gchar*
+autoar_filter_get_description_libarchive (AutoarFilter filter)
+{
+ struct archive *a;
+ gchar *str;
+
+ g_return_val_if_fail (filter > 0 && filter < AUTOAR_FILTER_LAST, NULL);
+
+ a = archive_write_new ();
+ archive_write_add_filter (a, autoar_filter_description[filter - 1].libarchive_filter);
+ str = g_strdup (archive_filter_name (a, 0));
+ archive_write_free (a);
+
+ return str;
+}
+
+gchar*
+autoar_format_filter_get_mime_type (AutoarFormat format,
+ AutoarFilter filter)
+{
+ g_return_val_if_fail (format > 0 && format < AUTOAR_FORMAT_LAST, NULL);
+ g_return_val_if_fail (filter > 0 && filter < AUTOAR_FILTER_LAST, NULL);
+
+ switch (filter) {
+ case AUTOAR_FILTER_NONE:
+ return g_strdup (autoar_format_description[format - 1].mime_type);
+ case AUTOAR_FILTER_COMPRESS:
+ return g_strconcat ("application/x-",
+ autoar_format_description[format - 1].keyword,
+ "z", NULL);
+ case AUTOAR_FILTER_GZIP:
+ return g_strconcat ("application/x-compressed-",
+ autoar_format_description[format - 1].keyword,
+ NULL);
+ default:
+ return g_strconcat ("application/x-",
+ autoar_filter_description[filter - 1].keyword,
+ "-compressed-",
+ autoar_format_description[format - 1].keyword,
+ NULL);
+ }
+}
+
+gchar*
+autoar_format_filter_get_extension (AutoarFormat format,
+ AutoarFilter filter)
+{
+ g_return_val_if_fail (format > 0 && format < AUTOAR_FORMAT_LAST, NULL);
+ g_return_val_if_fail (filter > 0 && filter < AUTOAR_FILTER_LAST, NULL);
+
+ return g_strconcat (".",
+ autoar_format_description[format - 1].extension,
+ autoar_filter_description[filter - 1].extension[0] ? "." : "",
+ autoar_filter_description[filter - 1].extension,
+ NULL);
+}
+
+gchar*
+autoar_format_filter_get_description (AutoarFormat format,
+ AutoarFilter filter)
+{
+ gchar *mime_type;
+ gchar *description;
+
+ g_return_val_if_fail (format > 0 && format < AUTOAR_FORMAT_LAST, NULL);
+ g_return_val_if_fail (filter > 0 && filter < AUTOAR_FILTER_LAST, NULL);
+
+ mime_type = autoar_format_filter_get_mime_type (format, filter);
+ description = g_content_type_get_description (mime_type);
+ g_free (mime_type);
+
+ return description;
+}
diff --git a/gnome-autoar/autoar-format-filter.h b/gnome-autoar/autoar-format-filter.h
new file mode 100644
index 0000000..1a4bbaf
--- /dev/null
+++ b/gnome-autoar/autoar-format-filter.h
@@ -0,0 +1,86 @@
+/* vim: set sw=2 ts=2 sts=2 et: */
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * autoar-format-filter.h
+ * Functions related to archive formats and filters
+ *
+ * Copyright (C) 2013 Ting-Wei Lan
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef AUTOAR_FORMAT_H
+#define AUTOAR_FORMAT_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef enum {
+ AUTOAR_FORMAT_0, /*< skip >*/
+ AUTOAR_FORMAT_ZIP = 1, /* .zip */
+ AUTOAR_FORMAT_TAR, /* .tar, pax_restricted */
+ AUTOAR_FORMAT_CPIO, /* .cpio, odc */
+ AUTOAR_FORMAT_7ZIP, /* .7z */
+ AUTOAR_FORMAT_AR_BSD, /* .a */
+ AUTOAR_FORMAT_AR_SVR4, /* .a */
+ AUTOAR_FORMAT_CPIO_NEWC, /* .cpio, newc */
+ AUTOAR_FORMAT_GNUTAR, /* .tar, gnutar */
+ AUTOAR_FORMAT_ISO9660, /* .iso */
+ AUTOAR_FORMAT_PAX, /* .tar, pax */
+ AUTOAR_FORMAT_USTAR, /* .tar, ustar */
+ AUTOAR_FORMAT_XAR, /* .xar, xar */
+ AUTOAR_FORMAT_LAST /*< skip >*/
+} AutoarFormat;
+
+typedef enum {
+ AUTOAR_FILTER_0, /*< skip >*/
+ AUTOAR_FILTER_NONE = 1,
+ AUTOAR_FILTER_COMPRESS, /* .Z */
+ AUTOAR_FILTER_GZIP, /* .gz */
+ AUTOAR_FILTER_BZIP2, /* .bz2 */
+ AUTOAR_FILTER_XZ, /* .xz */
+ AUTOAR_FILTER_LZMA, /* .lzma */
+ AUTOAR_FILTER_LZIP, /* .lz */
+ AUTOAR_FILTER_LZOP, /* .lzo */
+ AUTOAR_FILTER_GRZIP, /* .grz */
+ AUTOAR_FILTER_LRZIP, /* .lrz */
+ AUTOAR_FILTER_LAST /*< skip >*/
+} AutoarFilter;
+
+const char *autoar_format_get_mime_type (AutoarFormat format);
+const char *autoar_format_get_extension (AutoarFormat format);
+const char *autoar_format_get_description (AutoarFormat format);
+int autoar_format_get_format_libarchive (AutoarFormat format);
+gchar *autoar_format_get_description_libarchive (AutoarFormat format);
+
+const char *autoar_filter_get_mime_type (AutoarFilter filter);
+const char *autoar_filter_get_extension (AutoarFilter filter);
+const char *autoar_filter_get_description (AutoarFilter filter);
+int autoar_filter_get_filter_libarchive (AutoarFilter filter);
+gchar *autoar_filter_get_description_libarchive (AutoarFilter filter);
+
+gchar *autoar_format_filter_get_mime_type (AutoarFormat format,
+ AutoarFilter filter);
+gchar *autoar_format_filter_get_extension (AutoarFormat format,
+ AutoarFilter filter);
+gchar *autoar_format_filter_get_description (AutoarFormat format,
+ AutoarFilter filter);
+
+G_END_DECLS
+
+#endif /* AUTOAR_PREF_H */
diff --git a/gnome-autoar/autoar-pref.c b/gnome-autoar/autoar-pref.c
index fa21e34..6e4c453 100644
--- a/gnome-autoar/autoar-pref.c
+++ b/gnome-autoar/autoar-pref.c
@@ -43,8 +43,8 @@ struct _AutoarPrefPrivate
gboolean modification_enabled;
/* Archive creating preferences */
- AutoarPrefFormat default_format;
- AutoarPrefFilter default_filter;
+ AutoarFormat default_format;
+ AutoarFilter default_filter;
/* Archive extracting preferences */
char **file_name_suffix;
@@ -154,17 +154,17 @@ autoar_pref_set_property (GObject *object,
}
}
-AutoarPrefFormat
+AutoarFormat
autoar_pref_get_default_format (AutoarPref *arpref)
{
- g_return_val_if_fail (AUTOAR_IS_PREF (arpref), AUTOAR_PREF_FORMAT_ZIP);
+ g_return_val_if_fail (AUTOAR_IS_PREF (arpref), AUTOAR_FORMAT_ZIP);
return arpref->priv->default_format;
}
-AutoarPrefFilter
+AutoarFilter
autoar_pref_get_default_filter (AutoarPref *arpref)
{
- g_return_val_if_fail (AUTOAR_IS_PREF (arpref), AUTOAR_PREF_FILTER_NONE);
+ g_return_val_if_fail (AUTOAR_IS_PREF (arpref), AUTOAR_FILTER_NONE);
return arpref->priv->default_filter;
}
@@ -198,10 +198,10 @@ autoar_pref_get_delete_if_succeed (AutoarPref *arpref)
void
autoar_pref_set_default_format (AutoarPref *arpref,
- AutoarPrefFormat format)
+ AutoarFormat format)
{
g_return_if_fail (AUTOAR_IS_PREF (arpref));
- g_return_if_fail (format > 0 && format < AUTOAR_PREF_FORMAT_LAST);
+ g_return_if_fail (format > 0 && format < AUTOAR_FORMAT_LAST);
if (arpref->priv->modification_enabled && format != arpref->priv->default_format)
arpref->priv->modification_flags |= MODIFIED_DEFAULT_FORMAT;
arpref->priv->default_format = format;
@@ -209,10 +209,10 @@ autoar_pref_set_default_format (AutoarPref *arpref,
void
autoar_pref_set_default_filter (AutoarPref *arpref,
- AutoarPrefFilter filter)
+ AutoarFilter filter)
{
g_return_if_fail (AUTOAR_IS_PREF (arpref));
- g_return_if_fail (filter > 0 && filter < AUTOAR_PREF_FILTER_LAST);
+ g_return_if_fail (filter > 0 && filter < AUTOAR_FILTER_LAST);
if (arpref->priv->modification_enabled && filter != arpref->priv->default_filter)
arpref->priv->modification_flags |= MODIFIED_DEFAULT_FILTER;
arpref->priv->default_filter = filter;
@@ -299,8 +299,8 @@ autoar_pref_class_init (AutoarPrefClass *klass)
g_param_spec_enum (KEY_DEFAULT_FORMAT,
"Default format",
"Default file format for new archives",
- AUTOAR_TYPE_PREF_FORMAT,
- AUTOAR_PREF_FORMAT_ZIP,
+ AUTOAR_TYPE_FORMAT,
+ AUTOAR_FORMAT_ZIP,
G_PARAM_READWRITE |
G_PARAM_STATIC_NAME |
G_PARAM_STATIC_NICK |
@@ -310,8 +310,8 @@ autoar_pref_class_init (AutoarPrefClass *klass)
g_param_spec_enum (KEY_DEFAULT_FILTER,
"Default format",
"Default filter to create archives",
- AUTOAR_TYPE_PREF_FORMAT,
- AUTOAR_PREF_FORMAT_ZIP,
+ AUTOAR_TYPE_FORMAT,
+ AUTOAR_FORMAT_ZIP,
G_PARAM_READWRITE |
G_PARAM_STATIC_NAME |
G_PARAM_STATIC_NICK |
@@ -369,8 +369,8 @@ autoar_pref_init (AutoarPref *arpref)
priv->modification_flags = MODIFIED_NONE;
priv->modification_enabled = FALSE;
- priv->default_format = AUTOAR_PREF_FORMAT_ZIP;
- priv->default_filter = AUTOAR_PREF_FILTER_NONE;
+ priv->default_format = AUTOAR_FORMAT_ZIP;
+ priv->default_filter = AUTOAR_FILTER_NONE;
priv->file_name_suffix = NULL;
priv->file_mime_type = NULL;
diff --git a/gnome-autoar/autoar-pref.h b/gnome-autoar/autoar-pref.h
index f10e903..0aadaa3 100644
--- a/gnome-autoar/autoar-pref.h
+++ b/gnome-autoar/autoar-pref.h
@@ -29,42 +29,12 @@
#include <glib-object.h>
#include <gio/gio.h>
+#include <gnome-autoar/autoar-format-filter.h>
+
G_BEGIN_DECLS
#define AUTOAR_PREF_DEFAULT_GSCHEMA_ID "org.gnome.desktop.archives"
-typedef enum {
- AUTOAR_PREF_FORMAT_0, /*< skip >*/
- AUTOAR_PREF_FORMAT_ZIP = 1, /* .zip */
- AUTOAR_PREF_FORMAT_TAR, /* .tar, pax_restricted */
- AUTOAR_PREF_FORMAT_CPIO, /* .cpio, odc */
- AUTOAR_PREF_FORMAT_7ZIP, /* .7z */
- AUTOAR_PREF_FORMAT_AR_BSD, /* .a */
- AUTOAR_PREF_FORMAT_AR_SVR4, /* .a */
- AUTOAR_PREF_FORMAT_CPIO_NEWC, /* .cpio, newc */
- AUTOAR_PREF_FORMAT_GNUTAR, /* .tar, gnutar */
- AUTOAR_PREF_FORMAT_ISO9660, /* .iso */
- AUTOAR_PREF_FORMAT_PAX, /* .tar, pax */
- AUTOAR_PREF_FORMAT_USTAR, /* .tar, ustar */
- AUTOAR_PREF_FORMAT_XAR, /* .xar, xar */
- AUTOAR_PREF_FORMAT_LAST /*< skip >*/
-} AutoarPrefFormat;
-
-typedef enum {
- AUTOAR_PREF_FILTER_0, /*< skip >*/
- AUTOAR_PREF_FILTER_NONE = 1,
- AUTOAR_PREF_FILTER_COMPRESS, /* .Z */
- AUTOAR_PREF_FILTER_GZIP, /* .gz */
- AUTOAR_PREF_FILTER_BZIP2, /* .bz2 */
- AUTOAR_PREF_FILTER_XZ, /* .xz */
- AUTOAR_PREF_FILTER_LZMA, /* .lzma */
- AUTOAR_PREF_FILTER_LZIP, /* .lz */
- AUTOAR_PREF_FILTER_LZOP, /* .lzo */
- AUTOAR_PREF_FILTER_GRZIP, /* .grz */
- AUTOAR_PREF_FILTER_LRZIP, /* .lrz */
- AUTOAR_PREF_FILTER_LAST /*< skip >*/
-} AutoarPrefFilter;
-
#define AUTOAR_TYPE_PREF autoar_pref_get_type ()
#define AUTOAR_PREF(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AUTOAR_TYPE_PREF, AutoarPref))
#define AUTOAR_PREF_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AUTOAR_TYPE_PREF, AutoarPrefClass))
@@ -116,17 +86,17 @@ gboolean autoar_pref_check_mime_type_file (AutoarPref *arpref,
gboolean autoar_pref_check_mime_type_d (AutoarPref *arpref,
const char *mime_type);
-AutoarPrefFormat autoar_pref_get_default_format (AutoarPref *arpref);
-AutoarPrefFilter autoar_pref_get_default_filter (AutoarPref *arpref);
+AutoarFormat autoar_pref_get_default_format (AutoarPref *arpref);
+AutoarFilter autoar_pref_get_default_filter (AutoarPref *arpref);
const char **autoar_pref_get_file_name_suffix (AutoarPref *arpref);
const char **autoar_pref_get_file_mime_type (AutoarPref *arpref);
const char **autoar_pref_get_pattern_to_ignore (AutoarPref *arpref);
gboolean autoar_pref_get_delete_if_succeed (AutoarPref *arpref);
void autoar_pref_set_default_format (AutoarPref *arpref,
- AutoarPrefFormat format);
+ AutoarFormat format);
void autoar_pref_set_default_filter (AutoarPref *arpref,
- AutoarPrefFilter filter);
+ AutoarFilter filter);
void autoar_pref_set_file_name_suffix (AutoarPref *arpref,
const char **strv);
void autoar_pref_set_file_mime_type (AutoarPref *arpref,
@@ -136,7 +106,6 @@ void autoar_pref_set_pattern_to_ignore (AutoarPref *arpref,
void autoar_pref_set_delete_if_succeed (AutoarPref *arpref,
gboolean delete_yes);
-
G_END_DECLS
#endif /* AUTOAR_PREF_H */
diff --git a/gnome-autoar/autoar.h b/gnome-autoar/autoar.h
index 7d030bd..90b9405 100644
--- a/gnome-autoar/autoar.h
+++ b/gnome-autoar/autoar.h
@@ -27,6 +27,7 @@
#define AUTOARHICVE_H
#include <gnome-autoar/autoar-create.h>
+#include <gnome-autoar/autoar-format-filter.h>
#include <gnome-autoar/autoar-extract.h>
#include <gnome-autoar/autoar-pref.h>
/* #include <autoarchive/autoar-ui.h> */