2
* Copyright (C) 2011 Rolf Eike Beer <kde@opensource.sf-tec.de>
5
/***************************************************************************
7
* This program is free software; you can redistribute it and/or modify *
8
* it under the terms of the GNU General Public License as published by *
9
* the Free Software Foundation; either version 2 of the License, or *
10
* (at your option) any later version. *
12
***************************************************************************/
14
#include "foldercompressjob.h"
22
#include <KTemporaryFile>
25
#include "transactions/kgpgencrypt.h"
27
FolderCompressJob::FolderCompressJob(QObject *parent, const KUrl &source, const KUrl &dest, KTemporaryFile *tempfile, const QStringList &keys, const QStringList &options, const KGpgEncrypt::EncryptOptions encOptions)
29
m_description(i18n("Processing folder compression and encryption")),
35
m_encOptions(encOptions)
39
FolderCompressJob::~FolderCompressJob()
44
FolderCompressJob::start()
46
emit description(this, m_description, qMakePair(i18nc("State of operation as in status", "State"), i18nc("Job is started up", "Startup")));
47
QTimer::singleShot(0, this, SLOT(doWork()));
51
FolderCompressJob::doWork()
53
KArchive *arch = NULL;
54
int compressionScheme = 0;
55
switch (compressionScheme) {
57
arch = new KZip(m_tempfile->fileName());
60
arch = new KTar(m_tempfile->fileName(), QLatin1String( "application/x-gzip" ));
63
arch = new KTar(m_tempfile->fileName(), QLatin1String( "application/x-bzip" ));
66
arch = new KTar(m_tempfile->fileName(), QLatin1String( "application/x-tar" ));
69
arch = new KTar(m_tempfile->fileName(), QLatin1String( "application/x-xz" ));
75
if (!arch->open(QIODevice::WriteOnly)) {
76
setError(UserDefinedError);
77
setErrorText(i18n("Unable to create temporary file"));
83
arch->addLocalDirectory(m_source.path(), m_source.fileName());
89
QDir outPath = m_source.path();
92
m_options << QLatin1String("--output") << QDir::toNativeSeparators(outPath.path() + QDir::separator()) + m_dest.fileName();
94
emit description(this, m_description, qMakePair(i18nc("State of operation as in status", "State"),
95
i18nc("Status message 'Encrypting <filename>' (operation starts)", "Encrypting %1", m_dest.path())));
98
KGpgEncrypt *enc = new KGpgEncrypt(this, m_keys, KUrl::List(m_tempfile->fileName()), m_encOptions, m_options);
99
connect(enc, SIGNAL(done(int)), SLOT(slotEncryptionDone(int)));
104
FolderCompressJob::slotEncryptionDone(int result)
106
sender()->deleteLater();
108
if ((result != KGpgTransaction::TS_OK) && (result != KGpgTransaction::TS_USER_ABORTED)) {
109
setError(UserDefinedError + 1);
110
setErrorText(i18n("The encryption failed with error code %1", result));
111
emit description(this, m_description, qMakePair(i18nc("State of operation as in status", "State"), i18n("Encryption failed.")));
113
emit description(this, m_description, qMakePair(i18nc("State of operation as in status", "State"),
114
i18nc("Status message 'Encrypted <filename>' (operation was completed)", "Encrypted %1", m_dest.path())));
120
#include "foldercompressjob.moc"