2 * This file is a part of QComicBook.
4 * Copyright (C) 2005-2006 Pawel Stolowski <yogin@linux.bydg.org>
6 * QComicBook is free software; you can redestribute it and/or modify it
7 * under terms of GNU General Public License by Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY. See GPL for more details.
13 /*! \file imgarchivesink.h */
15 #ifndef __IMGARCHIVESINK_H
16 #define __IMGARCHIVESINK_H
20 #include <qstringlist.h>
21 #include <qvaluelist.h>
22 #include "imgdirsink.h"
29 //! Comic book archive sink.
30 /*! Allows opening different kind of archives containing image files. */
31 class ImgArchiveSink: public ImgDirSink
40 TARGZ_ARCHIVE = 1 << 3,
41 TARBZ2_ARCHIVE = 1 << 4,
43 SEVENZIP_ARCHIVE = 1 << 6,
44 UNKNOWN_ARCHIVE = 1 << 31
47 struct ArchiveTypeInfo
52 QStringList extractopts;
53 QStringList compressopts;
54 QStringList extensions;
61 ArchiveType archivetype; ///< the type of currently opened archive
62 QProcess *pext; ///< extracting process
63 QProcess *pinf; ///< file list extracing process
64 QString archivename; ///< archive file name, without path
65 QString archivepath; ///< full path, including archive name
66 QString tmppath; ///< path to extracted archive
67 QStringList archfiles; ///< list of archive files
68 QStringList archdirs; ///< list of archive dirs
69 int filesnum; ///< number of files gathered from parsing archiver output, used for progress bar
70 int extcnt; ///< extracted files counter for progress bar
72 static QValueList<ArchiveTypeInfo> archinfo;
76 static QString openext; ///< supported archives extensions (for open)
77 static QString saveext; ///< supported archives extensions (for save)
79 static void autoconfRAR();
80 static void autoconfZIP();
81 static void autoconfACE();
82 static void autoconfTARGZ();
83 static void autoconfTARBZ2();
84 static void autoconfTAR();
85 static void autoconf7Z();
87 //! Determines archive type
88 /*! Determines archive type basing on filename extension. As a last effort, if
89 * the check fails, tries to guess archive type basing on well known magic bytes.
90 * @param filename name of the archive, with path */
91 static ArchiveType archiveType(const QString &filename);
92 int extract(const QString &filename, const QString &destdir);
94 virtual void doCleanup();
98 void extractStdoutReady();
99 void infoStdoutReady();
104 ImgArchiveSink(const QString &path);
105 ImgArchiveSink(const ImgDirSink &sink);
106 virtual ~ImgArchiveSink();
108 virtual int open(const QString &path);
109 virtual void close();
110 virtual QString getName(int maxlen = 50);
111 virtual QString getFullName() const;
113 virtual bool supportsNext() const;
114 virtual QString getNext() const;
115 virtual QString getPrevious() const;
117 static void autoconfArchivers();
118 static int supportedArchives();
119 static QValueList<ImgArchiveSink::ArchiveTypeInfo> supportedArchivesInfo();
120 static bool supportsOpen(ArchiveType t);
121 static bool supportsSave(ArchiveType t);
122 static QString supportedOpenExtensions();
123 static QString supportedSaveExtensions();
124 static QString makeTempDir();