1
/***************************************************************************
2
packjob.cpp - description
4
copyright : (C) 2009 + by Csaba Karai
5
e-mail : krusader@users.sourceforge.net
6
web site : http://krusader.sourceforge.net
7
---------------------------------------------------------------------------
9
***************************************************************************
13
db dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b.
14
88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D
15
88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY'
16
88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b
17
88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88.
18
YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD
22
***************************************************************************
24
* This program is free software; you can redistribute it and/or modify *
25
* it under the terms of the GNU General Public License as published by *
26
* the Free Software Foundation; either version 2 of the License, or *
27
* (at your option) any later version. *
29
***************************************************************************/
32
#include "krarchandler.h"
33
#include <QtCore/QTimer>
34
#include <QtCore/QDir>
36
#include <kmimetype.h>
38
PackJob::PackJob(const KUrl &srcUrl, const KUrl &destUrl, const QStringList & fileNames, const QString &type, const QMap<QString, QString> &packProps) : AbstractThreadedJob()
40
start(new PackThread(srcUrl, destUrl, fileNames, type, packProps));
43
PackJob * PackJob::createPacker(const KUrl &srcUrl, const KUrl &destUrl, const QStringList & fileNames, const QString &type, const QMap<QString, QString> &packProps)
45
return new PackJob(srcUrl, destUrl, fileNames, type, packProps);
48
PackThread::PackThread(const KUrl &srcUrl, const KUrl &destUrl, const QStringList & fileNames,
49
const QString &type, const QMap<QString, QString> &packProps) :
50
AbstractJobThread(), _sourceUrl(srcUrl), _destUrl(destUrl), _fileNames(fileNames),
51
_type(type), _packProperties(packProps)
56
void PackThread::slotStart()
58
KUrl newSource = downloadIfRemote(_sourceUrl, _fileNames);
59
if (newSource.isEmpty())
62
KIO::filesize_t totalSize = 0;
63
unsigned long totalDirs = 0, totalFiles = 0;
65
calcSpaceLocal(newSource, _fileNames, totalSize, totalDirs, totalFiles);
67
QString arcFile = tempFileIfRemote(_destUrl, _type);
68
QString arcDir = newSource.path(KUrl::RemoveTrailingSlash);
70
setProgressTitle(i18n("Processed files"));
72
QString save = QDir::currentPath();
73
QDir::setCurrent(arcDir);
74
bool result = KRarcHandler::pack(_fileNames, _type, arcFile, totalFiles + totalDirs, _packProperties, observer());
75
QDir::setCurrent(save);
80
sendError(KIO::ERR_INTERNAL, i18n("Error at packing"));
84
if (!uploadTempFiles())
90
TestArchiveJob::TestArchiveJob(const KUrl &srcUrl, const QStringList & fileNames) : AbstractThreadedJob()
92
start(new TestArchiveThread(srcUrl, fileNames));
95
TestArchiveJob * TestArchiveJob::testArchives(const KUrl &srcUrl, const QStringList & fileNames)
97
return new TestArchiveJob(srcUrl, fileNames);
100
TestArchiveThread::TestArchiveThread(const KUrl &srcUrl, const QStringList & fileNames) : AbstractJobThread(),
101
_sourceUrl(srcUrl), _fileNames(fileNames)
105
void TestArchiveThread::slotStart()
107
KUrl newSource = downloadIfRemote(_sourceUrl, _fileNames);
108
if (newSource.isEmpty())
111
for (int i = 0; i < _fileNames.count(); ++i) {
112
QString arcName = _fileNames[ i ];
113
if (arcName.isEmpty())
118
KUrl url = newSource;
119
url.addPath(arcName);
121
QString path = url.path(KUrl::RemoveTrailingSlash);
123
KMimeType::Ptr mt = KMimeType::findByUrl(url);
124
QString mime = mt ? mt->name() : QString();
125
bool encrypted = false;
126
QString type = KRarcHandler::getType(encrypted, path, mime);
128
// check we that archive is supported
129
if (!KRarcHandler::arcSupported(type)) {
130
sendError(KIO::ERR_NO_CONTENT, i18n("%1, unsupported archive type.", arcName));
134
QString password = encrypted ? getPassword(path) : QString();
137
if (!KRarcHandler::test(path, type, password, 0, observer())) {
138
sendError(KIO::ERR_NO_CONTENT, i18n("%1, test failed!", arcName));
143
sendMessage(i18n("Archive tests passed."));
148
UnpackJob::UnpackJob(const KUrl &srcUrl, const KUrl &destUrl, const QStringList & fileNames) : AbstractThreadedJob()
150
start(new UnpackThread(srcUrl, destUrl, fileNames));
153
UnpackJob * UnpackJob::createUnpacker(const KUrl &srcUrl, const KUrl &destUrl, const QStringList & fileNames)
155
return new UnpackJob(srcUrl, destUrl, fileNames);
158
UnpackThread::UnpackThread(const KUrl &srcUrl, const KUrl &destUrl, const QStringList & fileNames) :
159
AbstractJobThread(), _sourceUrl(srcUrl), _destUrl(destUrl), _fileNames(fileNames)
163
void UnpackThread::slotStart()
165
KUrl newSource = downloadIfRemote(_sourceUrl, _fileNames);
166
if (newSource.isEmpty())
169
QString localDest = tempDirIfRemote(_destUrl);
171
for (int i = 0; i < _fileNames.count(); ++i) {
172
QString arcName = _fileNames[ i ];
173
if (arcName.isEmpty())
178
KUrl url = newSource;
179
url.addPath(arcName);
181
QString path = url.path(KUrl::RemoveTrailingSlash);
183
KMimeType::Ptr mt = KMimeType::findByUrl(url);
184
QString mime = mt ? mt->name() : QString();
185
bool encrypted = false;
186
QString type = KRarcHandler::getType(encrypted, path, mime);
188
// check we that archive is supported
189
if (!KRarcHandler::arcSupported(type)) {
190
sendError(KIO::ERR_NO_CONTENT, i18n("%1, unsupported archive type.", arcName));
194
QString password = encrypted ? getPassword(path) : QString();
196
setProgressTitle(i18n("Processed files"));
198
bool result = KRarcHandler::unpack(path, type, password, localDest, observer());
203
sendError(KIO::ERR_INTERNAL, i18n("Error at unpacking"));
208
if (!uploadTempFiles())