ComicImageView now uses an array of ImlibImageList instead of an array of ImlibImage...
[qcomicbook-oblomov] / src / imgarchivesink.h
1 /*
2  * This file is a part of QComicBook.
3  *
4  * Copyright (C) 2005-2006 Pawel Stolowski <yogin@linux.bydg.org>
5  *
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.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY. See GPL for more details.
11  */
12
13 /*! \file imgarchivesink.h */
14
15 #ifndef __IMGARCHIVESINK_H
16 #define __IMGARCHIVESINK_H
17
18 #include <qstring.h>
19 #include <qobject.h>
20 #include <qstringlist.h>
21 #include <qvaluelist.h>
22 #include "imgdirsink.h"
23
24 class QImage;
25 class QProcess;
26
27 namespace QComicBook
28 {
29         //! Comic book archive sink.
30         /*! Allows opening different kind of archives containing image files. */
31         class ImgArchiveSink: public ImgDirSink
32         {
33                 Q_OBJECT
34
35                 public:
36                         enum ArchiveType {
37                                 RAR_ARCHIVE      = 1 << 0,
38                                 ZIP_ARCHIVE      = 1 << 1,
39                                 ACE_ARCHIVE      = 1 << 2,
40                                 TARGZ_ARCHIVE    = 1 << 3,
41                                 TARBZ2_ARCHIVE   = 1 << 4,
42                                 TAR_ARCHIVE      = 1 << 5,
43                                 SEVENZIP_ARCHIVE = 1 << 6,
44                                 UNKNOWN_ARCHIVE  = 1 << 31
45                         };
46
47                         struct ArchiveTypeInfo
48                         {
49                                 ArchiveType type;
50                                 QString name;
51                                 QStringList listopts;
52                                 QStringList extractopts;
53                                 QStringList compressopts;
54                                 QStringList extensions;
55                                 bool reading;
56                                 bool writing;
57                         };
58
59                 protected:
60
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
71
72                         static QValueList<ArchiveTypeInfo> archinfo;
73                         
74                         static int suppopen;
75                         static int suppsave;
76                         static QString openext; ///< supported archives extensions (for open)
77                         static QString saveext; ///< supported archives extensions (for save)
78
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();
86
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);
93                         void init();
94                         virtual void doCleanup();
95                         
96                 protected slots:
97                         void extractExited();
98                         void extractStdoutReady();
99                         void infoStdoutReady();
100                         void infoExited();
101
102                 public:
103                         ImgArchiveSink();
104                         ImgArchiveSink(const QString &path);
105                         ImgArchiveSink(const ImgDirSink &sink);
106                         virtual ~ImgArchiveSink();
107
108                         virtual int open(const QString &path);
109                         virtual void close();
110                         virtual QString getName(int maxlen = 50);
111                         virtual QString getFullName() const;
112
113                         virtual bool supportsNext() const;
114                         virtual QString getNext() const;
115                         virtual QString getPrevious() const;
116
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();
125         };
126 }
127
128 #endif
129