Fix #299: File Compression and Archiving
authorColin Clark <colin.clark@cclark.uk>
Wed, 15 Sep 2021 15:21:18 +0000 (16:21 +0100)
committerColin Clark <colin.clark@cclark.uk>
Wed, 15 Sep 2021 15:21:18 +0000 (16:21 +0100)
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.

15 files changed:
configure.ac
doc/docbook/GuideReferenceStandardPlugins.xml
plugins/Makefile.am
plugins/open-archive/Makefile.am [new file with mode: 0644]
plugins/open-archive/geeqie-open-archive [new file with mode: 0755]
plugins/open-archive/open-archive.desktop.in [new file with mode: 0644]
src/filefilter.c
src/icons/Makefile.am
src/icons/archive_file.png [new file with mode: 0644]
src/image.c
src/pixbuf_util.c
src/pixbuf_util.h
src/preferences.c
src/remote.c
src/typedefs.h

index e815ff6..ff6d44d 100644 (file)
@@ -805,6 +805,7 @@ AC_CONFIG_FILES([
     plugins/image-crop/Makefile
     plugins/random-image/Makefile
     plugins/lens/Makefile
+    plugins/open-archive/Makefile
     geeqie.spec
 ])
 
index bfbde9a..89ec41c 100644 (file)
       menu.\r
     </para>\r
   </section>\r
+  <section id="OpenArchive">\r
+    <title>Open archive file</title>\r
+    <para>\r
+      Opens an archive file (of the type .zip, .rar, .cbr, .tar.gz) and extracts the contents into a folder in <code>/tmp</code>. A new Geeqie window is opened in that folder.\r
+    </para>\r
+    <para>\r
+      This item is displayed in the\r
+      <emphasis role="strong">Plugins</emphasis>\r
+      menu.\r
+    </para>\r
+  </section>\r
 </section>\r
index 5b63d6c..d649392 100644 (file)
@@ -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 (file)
index 0000000..7863831
--- /dev/null
@@ -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 (executable)
index 0000000..d542433
--- /dev/null
@@ -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 (file)
index 0000000..649199e
--- /dev/null
@@ -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
index d067911..c0d4842 100644 (file)
@@ -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;
 }
 
index 9f05bf6..7a6f89f 100644 (file)
@@ -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 (file)
index 0000000..8ee49f4
Binary files /dev/null and b/src/icons/archive_file.png differ
index 30a4bc1..f73762c 100644 (file)
@@ -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);
                        }
index 842396e..85f5845 100644 (file)
@@ -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);
                }
index 8aa5684..8450834 100644 (file)
@@ -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"
index 1a2250d..47ebd29 100644 (file)
@@ -119,7 +119,8 @@ gchar *format_class_list[] = {
        N_("Metadata"),
        N_("Video"),
        N_("Collection"),
-       N_("Document")
+       N_("Document"),
+       N_("Archive")
        };
 
 /* config memory values */
index a6b66fa..a10cb6a 100644 (file)
@@ -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;
index 1046004..c7387a2 100644 (file)
@@ -154,6 +154,7 @@ typedef enum {
        FORMAT_CLASS_VIDEO,
        FORMAT_CLASS_COLLECTION,
        FORMAT_CLASS_DOCUMENT,
+       FORMAT_CLASS_ARCHIVE,
        FILE_FORMAT_CLASSES
 } FileFormatClass;