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 #include "imgarchiver.h"
15 #include <qapplication.h>
17 using namespace QComicBook;
19 ImgArchiver::ImgArchiver(const ImgDirSink &sink): ImgArchiveSink(sink)
21 pomp = new QProcess(this);
22 connect(pomp, SIGNAL(processExited()), this, SLOT(compressExited()));
23 connect(pomp, SIGNAL(readyReadStdout()), this, SLOT(compressStdoutReady()));
26 ImgArchiver::~ImgArchiver()
31 void ImgArchiver::compressStdoutReady()
33 QByteArray b = pomp->readStdout();
34 for (int i=0; i<b.size(); i++)
37 emit createProgress(cmpcnt, newfilesnum);
38 qApp->processEvents();
41 void ImgArchiver::compressExited()
44 if (pomp->normalExit())
50 void ImgArchiver::doCleanup()
52 if (!tmpcreatpath.isEmpty())
54 QDir dir(tmpcreatpath);
56 // remove temporary files and dirs
57 for (QStringList::const_iterator it = newfiles.begin(); it !=newfiles.end(); ++it)
59 dir.rmdir(tmpcreatpath);
60 tmpcreatpath = QString::null;
64 void ImgArchiver::create(const QString &destname, ArchiveType type, QValueList<int> pages)
69 // match archive type, set subprocess options
70 for (QValueList<ArchiveTypeInfo>::const_iterator it = archinfo.begin(); it!=archinfo.end(); it++)
72 const ArchiveTypeInfo &inf = *it;
75 pomp->setArguments(inf.compressopts);
83 emit createError(SINKERR_NOTSUPPORTED);
87 tmpcreatpath = makeTempDir();
88 pomp->addArgument(destname);
89 pomp->addArgument("*");
92 if (pages.size() < 100)
97 int cnt = 0; //pages counter, used to create file names with new numbering scheme
98 for (QValueList<int>::const_iterator it = pages.begin(); it != pages.end(); it++)
101 QString ext = getKnownImageExtension(getFullFileName(*it));
104 fname.sprintf(fmt, cnt++);
105 fname = tmpcreatpath + "/" + fname + ext;
106 if (symlink(getFullFileName(*it), fname) == 0)
107 newfiles.append(fname);
109 ; //TODO: error handling
113 pomp->setWorkingDirectory(tmpcreatpath);
116 newfilesnum = pages.count();