21
21
#include <KActionCollection>
22
22
#include <KMessageBox>
23
#include <KPassivePopup>
25
24
#include <KTemporaryFile>
26
25
#include <KToolInvocation>
27
26
#include <KUniqueApplication>
29
28
#include <kio/renamedialog.h>
29
#include <kio/global.h>
30
#include <kjobtrackerinterface.h>
31
32
#include "images.h"
32
33
#include "keyservers.h"
79
82
if (KMessageBox::Cancel == KMessageBox::warningContinueCancel(m_keysmanager,
80
83
i18n("<qt>KGpg will now create a temporary archive file:<br /><b>%1</b> to process the encryption. The file will be deleted after the encryption is finished.</qt>",
81
84
kgpgfoldertmp->fileName()), i18n("Temporary File Creation"), KStandardGuiItem::cont(),
82
KStandardGuiItem::cancel(), QLatin1String( "FolderTmpFile" )))
85
KStandardGuiItem::cancel(), QLatin1String( "FolderTmpFile" ))) {
85
91
dialog = new KgpgSelectPublicKeyDlg(m_keysmanager, m_model, goDefaultKey(), false, droppedUrls);
116
124
void KGpgExternalActions::startFolderEncode()
118
const QStringList selec(dialog->selectedKeys());
119
QStringList encryptOptions(dialog->getCustomOptions().split(QLatin1Char( ' ' ), QString::SkipEmptyParts));
120
bool symetric = dialog->getSymmetric();
126
QStringList selec = dialog->selectedKeys();
127
KGpgEncrypt::EncryptOptions encOptions = KGpgEncrypt::DefaultEncryption;
128
const QStringList encryptOptions = dialog->getCustomOptions().split(QLatin1Char(' '), QString::SkipEmptyParts);
129
if (dialog->getSymmetric()) {
132
Q_ASSERT(!selec.isEmpty());
121
134
QString extension;
123
136
switch (compressionScheme) {
149
162
extension += QLatin1String( ".gpg" );
151
164
if (dialog->getArmor())
152
encryptOptions << QLatin1String( "--armor" );
165
encOptions |= KGpgEncrypt::AsciiArmored;
153
166
if (dialog->getHideId())
154
encryptOptions << QLatin1String( "--throw-keyids" );
156
QString fname(droppedUrls.first().path());
157
if (fname.endsWith(QLatin1Char( '/' )))
158
fname.remove(fname.length() - 1, 1);
160
KUrl encryptedFile(KUrl::fromPath(fname + extension));
167
encOptions |= KGpgEncrypt::HideKeyId;
168
if (dialog->getUntrusted())
169
encOptions |= KGpgEncrypt::AllowUntrustedEncryption;
171
KUrl encryptedFile(KUrl::fromPath(droppedUrls.first().path(KUrl::RemoveTrailingSlash) + extension));
161
172
QFile encryptedFolder(encryptedFile.path());
162
174
if (encryptedFolder.exists()) {
164
175
QPointer<KIO::RenameDialog> over = new KIO::RenameDialog(m_keysmanager, i18n("File Already Exists"), KUrl(), encryptedFile, KIO::M_OVERWRITE);
165
176
if (over->exec() == QDialog::Rejected) {
166
177
dialog->deleteLater();
171
182
encryptedFile = over->newDestUrl();
173
dialog->show(); // strange, but if dialog is hidden, the passive popup is not displayed...
176
pop = new KPassivePopup();
177
pop->setView(i18n("Processing folder compression and encryption"), i18n("Please wait..."), Images::kgpg());
178
pop->setAutoDelete(false);
180
kapp->processEvents();
186
FolderCompressJob *trayinfo = new FolderCompressJob(m_keysmanager, droppedUrls.first(), encryptedFile, kgpgfoldertmp, selec, encryptOptions, encOptions);
187
connect(trayinfo, SIGNAL(result(KJob*)), SLOT(slotFolderFinished(KJob *)));
188
KIO::getJobTracker()->registerJob(trayinfo);
181
191
dialog->accept();
182
192
dialog->deleteLater();
185
KArchive *arch = NULL;
186
switch (compressionScheme) {
188
arch = new KZip(kgpgfoldertmp->fileName());
191
arch = new KTar(kgpgfoldertmp->fileName(), QLatin1String( "application/x-gzip" ));
194
arch = new KTar(kgpgfoldertmp->fileName(), QLatin1String( "application/x-bzip" ));
197
arch = new KTar(kgpgfoldertmp->fileName(), QLatin1String( "application/x-tar" ));
200
arch = new KTar(kgpgfoldertmp->fileName(), QLatin1String( "application/x-xz" ));
206
if (!arch->open(QIODevice::WriteOnly))
208
KMessageBox::sorry(0, i18n("Unable to create temporary file"));
213
arch->addLocalDirectory(droppedUrls.first().path(), droppedUrls.first().fileName());
217
KGpgTextInterface *folderprocess = new KGpgTextInterface(this);
218
connect(folderprocess, SIGNAL(fileEncryptionFinished(KUrl)), SLOT(slotFolderFinished(KUrl)));
219
connect(folderprocess, SIGNAL(errorMessage(QString)), SLOT(slotFolderFinishedError(QString)));
220
folderprocess->encryptFile(selec, KUrl(kgpgfoldertmp->fileName()), encryptedFile, encryptOptions, symetric);
223
void KGpgExternalActions::slotFolderFinished(const KUrl &)
226
delete kgpgfoldertmp;
227
sender()->deleteLater();
230
void KGpgExternalActions::slotFolderFinishedError(const QString &errmsge)
233
delete kgpgfoldertmp;
234
sender()->deleteLater();
235
KMessageBox::sorry(0, errmsge);
194
kgpgfoldertmp = NULL;
197
void KGpgExternalActions::slotFolderFinished(KJob *job)
199
FolderCompressJob *trayinfo = qobject_cast<FolderCompressJob *>(job);
200
Q_ASSERT(trayinfo != NULL);
202
delete kgpgfoldertmp;
203
kgpgfoldertmp = NULL;
204
if (trayinfo->error())
205
KMessageBox::sorry(m_keysmanager, trayinfo->errorString());
238
208
void KGpgExternalActions::busyMessage(const QString &mssge)