From: Colin Clark Date: Wed, 15 Sep 2021 15:21:18 +0000 (+0100) Subject: Fix #299: File Compression and Archiving X-Git-Tag: v1.7~57 X-Git-Url: http://geeqie.org/cgi-bin/gitweb.cgi?p=geeqie.git;a=commitdiff_plain;h=972819272e9a70e565dbf711239f039cd77e2e6e Fix #299: File Compression and Archiving https://github.com/BestImageViewer/geeqie/issues/299 Create a new file class - Archive. Direct this files of this class to a new plugin to process these files. A folder is created under /tmp and the contents of the archive extracted to that folder. A new Geeqie window is opened, pointing to that folder. --- diff --git a/configure.ac b/configure.ac index e815ff6b..ff6d44d7 100644 --- a/configure.ac +++ b/configure.ac @@ -805,6 +805,7 @@ AC_CONFIG_FILES([ plugins/image-crop/Makefile plugins/random-image/Makefile plugins/lens/Makefile + plugins/open-archive/Makefile geeqie.spec ]) diff --git a/doc/docbook/GuideReferenceStandardPlugins.xml b/doc/docbook/GuideReferenceStandardPlugins.xml index bfbde9ae..89ec41ca 100644 --- a/doc/docbook/GuideReferenceStandardPlugins.xml +++ b/doc/docbook/GuideReferenceStandardPlugins.xml @@ -132,4 +132,15 @@ menu. +
+ Open archive file + + Opens an archive file (of the type .zip, .rar, .cbr, .tar.gz) and extracts the contents into a folder in /tmp. A new Geeqie window is opened in that folder. + + + This item is displayed in the + Plugins + menu. + +
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 5b63d6c9..d6493926 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,5 +1,5 @@ -SUBDIRS = rotate symlink ufraw geocode-parameters export-jpeg tethered-photography camera-import image-crop random-image lens +SUBDIRS = rotate symlink ufraw geocode-parameters export-jpeg tethered-photography camera-import image-crop random-image lens open-archive qq_desktoptemplatedir = $(appdir) qq_desktoptemplate_in_files = template.desktop.in qq_desktoptemplate_DATA = $(qq_desktoptemplate_in_files:.desktop.in=.desktop) diff --git a/plugins/open-archive/Makefile.am b/plugins/open-archive/Makefile.am new file mode 100644 index 00000000..78638316 --- /dev/null +++ b/plugins/open-archive/Makefile.am @@ -0,0 +1,10 @@ +dist_gq_bin_SCRIPTS = geeqie-open-archive + +gq_desktopdir = $(appdir)/applications +gq_desktop_in_files = open-archive.desktop.in +gq_desktop_DATA = $(gq_desktop_in_files:.desktop.in=.desktop) +@INTLTOOL_DESKTOP_RULE@ + +EXTRA_DIST = $(gq_desktop_in_files) +CLEANFILES = $(gq_desktop_DATA) + diff --git a/plugins/open-archive/geeqie-open-archive b/plugins/open-archive/geeqie-open-archive new file mode 100755 index 00000000..d5424331 --- /dev/null +++ b/plugins/open-archive/geeqie-open-archive @@ -0,0 +1,54 @@ +#!/bin/bash + +# Extract the contents of an archive file to a +# temporary folder under /tmp. +# +# Open a new Geeqie window pointing to that folder. + +full_path=$(realpath "$1") +filename=$(basename -- "$1") +extension="${filename#*.}" + +case $extension in + + zip) + if [ $(which unzip > /dev/null; echo $? ) = 0 ] + then + rm --recursive --force "/tmp/geeqie-archive/$full_path" + mkdir --parents "/tmp/geeqie-archive/$full_path" + unzip "$full_path" -d "/tmp/geeqie-archive/$full_path" > /dev/null + geeqie --remote --new-window "/tmp/geeqie-archive/$full_path" + else + zenity --title="Geeqie Open Archive" --info --width=300 --text="Utility unzip is not installed" + fi + ;; + + tar.gz) + if [ $(which tar > /dev/null; echo $? ) = 0 ] + then + rm --recursive --force "/tmp/geeqie-archive/$full_path" + mkdir --parents "/tmp/geeqie-archive/$full_path" + tar --extract --gunzip --directory "/tmp/geeqie-archive/$full_path" --file="$full_path" > /dev/null + geeqie --remote --new-window "/tmp/geeqie-archive/$full_path" + else + zenity --title="Geeqie Open Archive" --info --width=300 --text="Utility tar is not installed" + fi + ;; + + cbr | rar) + if [ $(which unrar > /dev/null; echo $? ) = 0 ] + then + rm --recursive --force rf "/tmp/geeqie-archive/$full_path" + mkdir --parents "/tmp/geeqie-archive/$full_path" + unrar "$full_path" "/tmp/geeqie-archive/$full_path" > /dev/null + geeqie --remote --new-window "/tmp/geeqie-archive/$full_path" + else + zenity --title="Geeqie Open Archive" --info --width=300 --text="Utility unrar is not installed" + fi + ;; + + *) + zenity --title="Geeqie Open Archive" --info --width=300 --text="This is not a known archive file type" + ;; +esac + diff --git a/plugins/open-archive/open-archive.desktop.in b/plugins/open-archive/open-archive.desktop.in new file mode 100644 index 00000000..649199ef --- /dev/null +++ b/plugins/open-archive/open-archive.desktop.in @@ -0,0 +1,16 @@ +[Desktop Entry] +Version=1.0 +Type=Application +_Name=Open archive file + +# call the helper script +Exec=geeqie-open-archive %f + +# Desktop files that are usable only in Geeqie should be marked like this: +Categories=X-Geeqie; +OnlyShowIn=X-Geeqie; + +# It can be made verbose +# X-Geeqie-Verbose=true + +Icon=package-x-generic diff --git a/src/filefilter.c b/src/filefilter.c index d0679116..c0d48424 100644 --- a/src/filefilter.c +++ b/src/filefilter.c @@ -309,6 +309,7 @@ void filter_add_defaults(void) #endif filter_add_if_missing("psd", "Adobe Photoshop Document", ".psd", FORMAT_CLASS_IMAGE, FALSE, FALSE, TRUE); filter_add_if_missing("apng", "Animated Portable Network Graphic", ".apng", FORMAT_CLASS_IMAGE, FALSE, FALSE, TRUE); + filter_add_if_missing("zip", "Archive files", ".zip;.rar;.cbr;tar.gz", FORMAT_CLASS_ARCHIVE, FALSE, FALSE, TRUE); } GList *filter_to_list(const gchar *extensions) @@ -489,6 +490,7 @@ FileFormatClass filter_file_get_class(const gchar *name) if (filter_file_class(name, FORMAT_CLASS_VIDEO)) return FORMAT_CLASS_VIDEO; if (filter_file_class(name, FORMAT_CLASS_COLLECTION)) return FORMAT_CLASS_COLLECTION; if (filter_file_class(name, FORMAT_CLASS_DOCUMENT)) return FORMAT_CLASS_DOCUMENT; + if (filter_file_class(name, FORMAT_CLASS_ARCHIVE)) return FORMAT_CLASS_ARCHIVE; return FORMAT_CLASS_UNKNOWN; } diff --git a/src/icons/Makefile.am b/src/icons/Makefile.am index 9f05bf67..7a6f89f5 100644 --- a/src/icons/Makefile.am +++ b/src/icons/Makefile.am @@ -12,6 +12,7 @@ ICONS_INLINE = \ geeqie_logo.png \ scroller.png \ sheet_broken.png \ + archive_file.png \ sheet_metadata.png \ sheet_unknown.png \ sheet_video.png \ @@ -63,6 +64,7 @@ ICONS_INLINE_PAIRS = \ icon_thumb $(srcdir)/icon_thumb.png \ icon_scroller $(srcdir)/scroller.png \ icon_broken $(srcdir)/sheet_broken.png \ + icon_archive $(srcdir)/archive_file.png \ icon_metadata $(srcdir)/sheet_metadata.png \ icon_unknown $(srcdir)/sheet_unknown.png \ icon_video $(srcdir)/sheet_video.png \ diff --git a/src/icons/archive_file.png b/src/icons/archive_file.png new file mode 100644 index 00000000..8ee49f41 Binary files /dev/null and b/src/icons/archive_file.png differ diff --git a/src/image.c b/src/image.c index 30a4bc18..f73762c4 100644 --- a/src/image.c +++ b/src/image.c @@ -902,6 +902,9 @@ static void image_load_done_cb(ImageLoader *il, gpointer data) case FORMAT_CLASS_DOCUMENT: pixbuf = pixbuf_inline(PIXBUF_INLINE_ICON_PDF); break; + case FORMAT_CLASS_ARCHIVE: + pixbuf = pixbuf_inline(PIXBUF_INLINE_ARCHIVE); + break; default: pixbuf = pixbuf_inline(PIXBUF_INLINE_BROKEN); } diff --git a/src/pixbuf_util.c b/src/pixbuf_util.c index 842396ee..85f58459 100644 --- a/src/pixbuf_util.c +++ b/src/pixbuf_util.c @@ -114,6 +114,7 @@ static PixbufInline inline_pixbuf_data[] = { { PIXBUF_INLINE_COLLECTION, icon_collection }, { PIXBUF_INLINE_ICON, gqview_icon }, { PIXBUF_INLINE_LOGO, geeqie_logo }, + { PIXBUF_INLINE_ARCHIVE, icon_archive }, { PIXBUF_INLINE_ICON_FLOAT, icon_float }, { PIXBUF_INLINE_ICON_THUMB, icon_thumb }, { PIXBUF_INLINE_ICON_BOOK, icon_book }, @@ -299,6 +300,9 @@ GdkPixbuf *pixbuf_fallback(FileData *fd, gint requested_width, gint requested_he case FORMAT_CLASS_DOCUMENT: pixbuf = pixbuf_inline(PIXBUF_INLINE_ICON_PDF); break; + case FORMAT_CLASS_ARCHIVE: + pixbuf = pixbuf_inline(PIXBUF_INLINE_ARCHIVE); + break; default: pixbuf = pixbuf_inline(PIXBUF_INLINE_BROKEN); } diff --git a/src/pixbuf_util.h b/src/pixbuf_util.h index 8aa56846..84508346 100644 --- a/src/pixbuf_util.h +++ b/src/pixbuf_util.h @@ -46,6 +46,7 @@ gboolean pixbuf_scale_aspect(gint req_w, gint req_h, gint old_w, gint old_h, gin #define PIXBUF_INLINE_COLLECTION "collection" #define PIXBUF_INLINE_ICON "icon" #define PIXBUF_INLINE_LOGO "logo" +#define PIXBUF_INLINE_ARCHIVE "archive" #define PIXBUF_INLINE_ICON_FLOAT "icon_float" #define PIXBUF_INLINE_ICON_THUMB "icon_thumb" diff --git a/src/preferences.c b/src/preferences.c index 1a2250d4..47ebd294 100644 --- a/src/preferences.c +++ b/src/preferences.c @@ -119,7 +119,8 @@ gchar *format_class_list[] = { N_("Metadata"), N_("Video"), N_("Collection"), - N_("Document") + N_("Document"), + N_("Archive") }; /* config memory values */ diff --git a/src/remote.c b/src/remote.c index a6b66fab..a10cb6a0 100644 --- a/src/remote.c +++ b/src/remote.c @@ -902,6 +902,9 @@ static void get_filelist(const gchar *text, GIOChannel *channel, gboolean recurs case FORMAT_CLASS_DOCUMENT: out_string = g_string_append(out_string, " Class: Document"); break; + case FORMAT_CLASS_ARCHIVE: + out_string = g_string_append(out_string, " Class: Archive"); + break; case FORMAT_CLASS_UNKNOWN: out_string = g_string_append(out_string, " Class: Unknown"); break; diff --git a/src/typedefs.h b/src/typedefs.h index 10460046..c7387a23 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -154,6 +154,7 @@ typedef enum { FORMAT_CLASS_VIDEO, FORMAT_CLASS_COLLECTION, FORMAT_CLASS_DOCUMENT, + FORMAT_CLASS_ARCHIVE, FILE_FORMAT_CLASSES } FileFormatClass;