Commit f563737c authored by Rolf Eike Beer's avatar Rolf Eike Beer
Browse files

Implement signing of multiple files from command line at once

BUG:158274

svn path=/trunk/KDE/kdeutils/kgpg/; revision=781561
parent b1cff993
......@@ -28,10 +28,7 @@ public:
GPGProc::GPGProc(QObject *parent)
: KProcess(parent), d(new GPGProcPrivate())
{
QStringList args;
args << "--no-secmem-warning" << "--no-tty";
setProgram(KGpgSettings::gpgBinaryPath(), args);
setOutputChannelMode(OnlyStdoutChannel);
resetProcess();
}
GPGProc::~GPGProc()
......@@ -39,6 +36,18 @@ GPGProc::~GPGProc()
delete d;
}
void
GPGProc::resetProcess()
{
QStringList args;
args << "--no-secmem-warning" << "--no-tty";
setProgram(KGpgSettings::gpgBinaryPath(), args);
setOutputChannelMode(OnlyStdoutChannel);
d->recvbuffer.clear();
disconnect();
}
void GPGProc::start()
{
connect(this, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finished()));
......
......@@ -106,6 +106,11 @@ public:
*/
static QString recode(QByteArray a, const bool colons = true);
/**
* Reset the class to the state it had right after creation
*/
void resetProcess();
signals:
/**
* Emitted when the process is ready for reading.
......
......@@ -439,7 +439,8 @@ void MyView::signDroppedFile()
Options << "--pgp6";
KGpgTextInterface *signFileProcess = new KGpgTextInterface();
signFileProcess->KgpgSignFile(signKeyID, droppedUrl, Options);
signFileProcess->signFilesBlocking(signKeyID, droppedUrls, Options);
delete signFileProcess;
}
void MyView::decryptDroppedFile()
......
......@@ -600,7 +600,7 @@ void KgpgEditor::slotSignFile(const KUrl &url)
KGpgTextInterface *interface = new KGpgTextInterface();
//TODO connect(interface, SIGNAL(...), this, SLOT(slotSignFileFin(KgpgInterface *interface)));
interface->KgpgSignFile(signKeyID, url, Options);
interface->signFiles(signKeyID, url, Options);
}
}
......
......@@ -28,13 +28,17 @@ public:
QString m_signID;
QString m_log;
QStringList m_userIDs;
QStringList m_gpgopts;
QByteArray m_tmpmessage;
QByteArray m_readin;
KUrl m_file;
KUrl::List m_files;
KUrl::List m_errfiles;
void updateIDs(QByteArray txt);
bool symPassphrase();
bool gpgPassphrase();
void signFile(const KUrl &);
};
KGpgTextInterfacePrivate::KGpgTextInterfacePrivate()
......@@ -106,6 +110,20 @@ KGpgTextInterfacePrivate::gpgPassphrase()
return false;
}
void
KGpgTextInterfacePrivate::signFile(const KUrl &file)
{
*m_process << "--command-fd=0" << "-u" << m_signID.simplified().toLocal8Bit();
for (QStringList::ConstIterator it = m_gpgopts.begin(); it != m_gpgopts.end(); ++it)
*m_process << QFile::encodeName(*it);
*m_process << "--output" << QFile::encodeName(file.path() + ".sig");
*m_process << "--detach-sig" << QFile::encodeName(file.path());
m_process->start();
}
KGpgTextInterface::KGpgTextInterface(QObject *parent)
: QObject(parent), d(new KGpgTextInterfacePrivate)
{
......@@ -546,15 +564,51 @@ KGpgTextInterface::verifyfin()
// signatures
void
KGpgTextInterface::KgpgSignFile(const QString &keyID, const KUrl &srcUrl, const QStringList &options)
KGpgTextInterface::signFiles(const QString &keyID, const KUrl::List &srcUrls, const QStringList &options)
{
*d->m_process << "-u" << keyID.simplified().toLocal8Bit();
d->m_files = srcUrls;
d->m_step = 0;
d->m_signID = keyID;
d->m_gpgopts = options;
for (QStringList::ConstIterator it = options.begin(); it != options.end(); ++it)
*d->m_process << QFile::encodeName(*it);
slotSignFile(0);
}
void
KGpgTextInterface::signFilesBlocking(const QString &keyID, const KUrl::List &srcUrls, const QStringList &options)
{
d->m_signID = keyID;
d->m_gpgopts = options;
*d->m_process << "--output" << QFile::encodeName(srcUrl.path() + ".sig");
*d->m_process << "--detach-sig" << QFile::encodeName(srcUrl.path());
for (int i = 0; i < srcUrls.count(); i++) {
d->signFile(srcUrls.at(i));
d->m_process->waitForFinished(-1);
d->m_process->resetProcess();
}
}
void
KGpgTextInterface::slotSignFile(int err)
{
if (err != 0)
d->m_errfiles << d->m_files.at(d->m_step);
d->m_process->resetProcess();
d->signFile(d->m_files.at(d->m_step));
if (++d->m_step == d->m_files.count()) {
connect(d->m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotSignFinished(int)));
} else {
connect(d->m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotSignFile(int)));
}
d->m_process->start();
}
void
KGpgTextInterface::slotSignFinished(int err)
{
if (err != 0)
d->m_errfiles << d->m_files.at(d->m_step - 1);
emit fileSignFinished(this, d->m_errfiles);
}
......@@ -76,6 +76,12 @@ Q_SIGNALS:
void decryptFileStarted(KUrl url);
void decryptFileFinished(int, KGpgTextInterface*);
/**
* Emitted when all files passed to KgpgSignFile() where processed.
* Passes as argument the files that failed.
*/
void fileSignFinished(KGpgTextInterface *, KUrl::List &);
public Q_SLOTS:
/**
* Encrypt text function
......@@ -137,7 +143,8 @@ public Q_SLOTS:
* @param srcUrl Kurl of the file to sign.
* @param options String with the wanted gpg options. ex: "--armor"
*/
void KgpgSignFile(const QString &keyID, const KUrl &srcUrl, const QStringList &options = QStringList());
void signFiles(const QString &keyID, const KUrl::List &srcUrl, const QStringList &options = QStringList());
void signFilesBlocking(const QString &keyID, const KUrl::List &srcUrls, const QStringList &options);
/**Verify file function
* @param sigUrl Kurl of the signature file.
......@@ -180,6 +187,9 @@ private Q_SLOTS:
void decryptFileProcess();
void decryptFileFin();
void slotSignFile(int);
void slotSignFinished(int);
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment